View Javadoc

1   package org.xvsm.selectors;
2   
3   import java.util.Properties;
4   
5   import org.xvsm.core.Entry;
6   
7   /***
8    * @author Christian Schreiber, Michael Proestler
9    * 
10   */
11  public class LindaSelector extends Selector {
12  
13  	/***
14  	 * 
15  	 */
16  	private static final long serialVersionUID = 7619634649348256334L;
17  	/***
18  	 * Template of the LindaSelector.<br>
19  	 * The selector will match any entry base on this template.
20  	 */
21  	private Entry template;
22  
23  	/***
24  	 * Constructor with default count 1.
25  	 * 
26  	 * @param template
27  	 *            the template, against which the selector tries to match.
28  	 */
29  	public LindaSelector(Entry template) {
30  		this(1, template);
31  
32  	}
33  
34  	/***
35  	 * Default Constructor.
36  	 */
37  	public LindaSelector() {
38  
39  	}
40  
41  	/***
42  	 * Constructor with count as parameter.
43  	 * 
44  	 * @param count
45  	 *            the count of the selector.
46  	 * @param template
47  	 *            the template, against which the selector tries to match.
48  	 * 
49  	 */
50  	public LindaSelector(int count, Entry template) {
51  		super(count);
52  		this.template = template;
53  	}
54  
55  	/***
56  	 * Get the template of this LindaSelector.
57  	 * 
58  	 * @return the template
59  	 */
60  	public Entry getTemplate() {
61  		return template;
62  	}
63  
64  	/***
65  	 * Set the template of this LindaSelector.
66  	 * 
67  	 * @param template
68  	 *            the template to set
69  	 */
70  	public void setTemplate(Entry template) {
71  		this.template = template;
72  	}
73  
74  	/***
75  	 * {@inheritDoc}
76  	 */
77  	@Override
78  	public Properties getProperties() {
79  		Properties props = new Properties();
80  		if (this.getTemplate() != null) {
81  			props.put("Template", this.getTemplate());
82  		}
83  		return props;
84  	}
85  
86  	/***
87  	 * {@inheritDoc}
88  	 */
89  	@Override
90  	public void setProperties(Properties properties) {
91  		this.setTemplate((Entry) properties.get("Template"));
92  	}
93  
94  	/***
95  	 * {@inheritDoc}
96  	 */
97  	@Override
98  	public int hashCode() {
99  		final int prime = 31;
100 		int result = 1;
101 		result = prime * result
102 				+ ((template == null) ? 0 : template.hashCode());
103 		return result;
104 	}
105 
106 	/***
107 	 * {@inheritDoc}
108 	 */
109 	@Override
110 	public boolean equals(Object obj) {
111 		if (this == obj)
112 			return true;
113 		if (obj == null)
114 			return false;
115 		if (getClass() != obj.getClass())
116 			return false;
117 		final LindaSelector other = (LindaSelector) obj;
118 		if (template == null) {
119 			if (other.template != null)
120 				return false;
121 		} else if (!template.equals(other.template))
122 			return false;
123 		return true;
124 	}
125 
126 	/***
127 	 * {@inheritDoc}
128 	 */
129 	public String toString() {
130 		return "LindaSelector: " + this.getTemplate();
131 	}
132 }