Java Reference
In-Depth Information
public void setSuffixes( Set<Object> suffixes) {
this.suffixes = suffixes;
}
...
}
To define a property of java.util.Set type, use the <set> tag to define the elements in the same way
as a list.
<bean id="sequenceGenerator"
class="com.apress.springenterpriserecipes.sequence.SequenceGenerator">
...
<property name="suffixes">
<set>
<value>A</value>
<bean class="java.net.URL">
<constructor-arg value="http" />
<constructor-arg value=" www.apress.com" />
<constructor-arg value="/" />
</bean>
<null />
</set>
</property>
</bean>
Although there's not an order concept in the original set semantics, Spring preserves the order of
your elements by using java.util.LinkedHashSet , an implementation of the java.util.Set interface
that does preserve element order.
Maps and Properties
A map is a table that stores its entries in key/value pairs. You can get a particular value from a map by its
key, and also iterate the map entries with a for-each loop. Both the keys and values of a map can be of
arbitrary type. Equality between keys is also determined by the equals() method. For example, you can
modify your sequence generator to accept a java.util.Map collection that contains suffixes with keys.
package com.apress.springenterpriserecipes.sequence;
...
public class SequenceGenerator {
...
private Map<Object, Object> suffixes;
public void setSuffixes( Map<Object, Object> suffixes) {
this.suffixes = suffixes;
}
public synchronized String getSequence() {
StringBuffer buffer = new StringBuffer();
...
for (Map.Entry entry : suffixes.entrySet()) {
buffer.append("-");
buffer.append(entry.getKey());
Search WWH ::




Custom Search