View Javadoc

1   /*
2    * Copyright 2007-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwe.p2elv2;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  /**
26   * @author Marco Ruiz
27   * @since Aug 19, 2008
28   */
29  public class PVarValue<VALUE_TYPE extends Serializable> implements Serializable {
30  	
31  	protected VALUE_TYPE value;
32  	protected transient Map<PProcessorType, List<PProcessor>> processors = new HashMap<PProcessorType, List<PProcessor>>();
33  	
34  	public PVarValue(VALUE_TYPE value) {
35  		this(value, null, null);
36      }
37  	
38  	public PVarValue(VALUE_TYPE value, PProcessor preProcessor, PProcessor postProcessor) {
39  	    for (PProcessorType procType : PProcessorType.values()) processors.put(procType, new ArrayList<PProcessor>());
40  
41  	    this.value = value;
42  	    
43  	    if (preProcessor != null)  getProcessors(PProcessorType.PRE).add(preProcessor);
44  	    if (postProcessor != null) getProcessors(PProcessorType.POST).add(postProcessor);
45      }
46  	
47  	public Object getVTLModel() {
48      	return value;
49      }
50  	
51  	public List<PProcessor> getProcessors(PProcessorType procType) {
52  		if (processors == null) processors = new HashMap<PProcessorType, List<PProcessor>>();
53      	List<PProcessor> result = processors.get(procType);
54      	if (result == null) {
55      		result = new ArrayList<PProcessor>();
56      		processors.put(procType, result);
57      	}
58  		return result;
59      }
60  	
61  	public String toString() {
62  		return value.toString();
63  	}
64  	
65  	@Override
66      public int hashCode() {
67  	    final int prime = 31;
68  	    int result = 1;
69  	    result = prime * result + ((value == null) ? 0 : value.hashCode());
70  	    return result;
71      }
72  
73  	@Override
74      public boolean equals(Object obj) {
75  	    if (this == obj)
76  		    return true;
77  	    if (obj == null)
78  		    return false;
79  	    if (getClass() != obj.getClass())
80  		    return false;
81  	    final PVarValue other = (PVarValue) obj;
82  	    if (value == null) {
83  		    if (other.value != null)
84  			    return false;
85  	    } else if (!value.equals(other.value))
86  		    return false;
87  	    return true;
88      }
89  }
90