1
2
3
4 package net.sf.bddbddb.order;
5
6 import java.util.Collection;
7 import java.util.Iterator;
8 import java.util.LinkedList;
9 import net.sf.bddbddb.Attribute;
10
11 /***
12 * AttribToDomainTranslator
13 *
14 * @author jwhaley
15 * @version $Id: AttribToDomainTranslator.java 364 2004-10-31 14:13:49Z joewhaley $
16 */
17 public class AttribToDomainTranslator implements OrderTranslator {
18
19 public static final AttribToDomainTranslator INSTANCE =
20 new AttribToDomainTranslator();
21
22 /***
23 *
24 */
25 private AttribToDomainTranslator() { }
26
27
28
29
30 public Order translate(Order o) {
31 LinkedList result = new LinkedList();
32 for (Iterator i = o.iterator(); i.hasNext(); ) {
33 Object a = i.next();
34 if (a instanceof Collection) {
35 Collection result2 = new LinkedList();
36 for (Iterator j = ((Collection) a).iterator(); j.hasNext(); ) {
37 Attribute a2 = (Attribute) j.next();
38 result2.add(a2.getDomain());
39 }
40 if (result2.size() > 1) {
41 result.add(result2);
42 } else if (!result2.isEmpty()) {
43 result.add(result2.iterator().next());
44 }
45 } else {
46 Attribute b = (Attribute) a;
47 result.add(b.getDomain());
48 }
49 }
50 return new Order(result);
51 }
52 }