1 13 package com.tonbeller.jpivot.olap.mdxparse; 14 15 import java.util.ArrayList ; 16 import java.util.Iterator ; 17 18 21 public class CompoundId implements Exp { 22 23 private ArrayList names = new ArrayList (); 24 25 30 public CompoundId(String name, boolean isKey) { 31 names.add(new NamePart(name, isKey)); 32 } 33 34 public CompoundId(String name) { 35 this(name, false); 36 } 37 38 public void append(String name, boolean isKey) { 39 names.add(new NamePart(name, isKey)); 40 } 41 42 public void append(String name) { 43 names.add(new NamePart(name, false)); 44 } 45 46 public String [] toStringArray() { 47 String [] ret = new String [names.size()]; 48 int i = 0; 49 for (Iterator iter = names.iterator(); iter.hasNext();) { 50 NamePart np = (NamePart) iter.next(); 51 ret[i++] = np.name; 52 } 53 54 return ret; 55 } 56 57 private class NamePart { 58 private String name; 59 private boolean isKey; 60 protected NamePart(String name, boolean isKey) { 61 this.name = name; 62 this.isKey = isKey; 63 } 64 } 65 66 70 public String toMdx() { 71 String str = ""; 72 boolean isFollow = false; 73 for (Iterator iter = names.iterator(); iter.hasNext();) { 74 NamePart np = (NamePart) iter.next(); 75 if (isFollow) 76 str += "."; 77 isFollow = true; 78 str += np.name; 79 } 80 81 return str; 82 } 83 84 private CompoundId(){ 85 } 87 88 92 public Object clone() { 93 CompoundId cloned = new CompoundId(); 94 for (Iterator iter = names.iterator(); iter.hasNext();) { 95 NamePart np = (NamePart) iter.next(); 96 cloned.append(np.name, np.isKey); 97 } 98 return cloned; 99 } 100 101 104 public void accept(ExpVisitor visitor) { 105 visitor.visitCompoundId(this); 106 } 107 108 } 110 | Popular Tags |