00001 package edu.tum.cs.srldb.datadict;
00002
00003 import java.io.Serializable;
00004
00005 import edu.tum.cs.srldb.datadict.domain.BooleanDomain;
00006 import edu.tum.cs.srldb.datadict.domain.DiscardedDomain;
00007 import edu.tum.cs.srldb.datadict.domain.Domain;
00008 import kdl.prox3.dbmgr.DataTypeEnum;
00009
00010 public class DDAttribute implements Cloneable, Serializable {
00011 private static final long serialVersionUID = 1L;
00012 protected String name;
00013 protected Domain domain;
00017 protected boolean doClustering;
00018 protected Integer numClusters;
00022 protected boolean discarded;
00026 protected DDItem owner;
00027
00028 protected DDAttribute(String name) {
00029 this.name = name;
00030 this.domain = null;
00031 this.doClustering = false;
00032 this.numClusters = null;
00033 this.discarded = false;
00034 this.owner = null;
00035 }
00036
00037 public DDAttribute(String name, Domain domain) {
00038 this(name);
00039 this.domain = domain;
00040 }
00041
00042 public DDAttribute(String name, Domain domain, boolean doClustering) {
00043 this(name, domain);
00044 this.doClustering = doClustering;
00045 }
00046
00051 public void setClustering(boolean doClustering) {
00052 this.doClustering = doClustering;
00053 }
00054
00055 public void setClustering(Integer numClusters) {
00056 this.doClustering = true;
00057 this.numClusters = numClusters;
00058 }
00059
00060 public String getName() {
00061 return name;
00062 }
00063
00064 public DataTypeEnum getType() {
00065 return domain.getType();
00066 }
00067
00068 public boolean requiresClustering() {
00069 return doClustering;
00070 }
00071
00072 public Integer getNumClusters() {
00073 return numClusters;
00074 }
00075
00076 public Domain getDomain() {
00077 return domain;
00078 }
00079
00080 public boolean isBoolean() {
00081 return domain instanceof BooleanDomain;
00082 }
00083
00091 public void discard() {
00092 discarded = true;
00093 domain = DiscardedDomain.getInstance();
00094 }
00095
00096 public boolean isDiscarded() {
00097 return this.discarded;
00098 }
00099
00100 public DDAttribute clone() {
00101 try {
00102 return (DDAttribute)super.clone();
00103 }
00104 catch (CloneNotSupportedException e) { return null; }
00105 }
00106
00107 public void setName(String name) {
00108 this.name = name;
00109 }
00110
00111 public void setDomain(Domain domain) {
00112 this.domain = domain;
00113 }
00114
00115 public void setOwner(DDItem item) throws DDException {
00116 if(owner == null || item == null)
00117 owner = item;
00118 else
00119 throw new DDException("Error: Cannot add attribute " + this.getName() + " to more than one item; previously added to " + this.owner.getName());
00120 }
00121
00122 public DDItem getOwner() {
00123 return owner;
00124 }
00125
00126 public String toString() {
00127 return String.format("DDAttribute:%s[domain=%s/size=%d, discarded=%s, clustering=%s/%s]", name, domain.getClass().getSimpleName(), domain.getValues().length, Boolean.toString(discarded), Boolean.toString(doClustering), numClusters == null ? "auto" : numClusters.toString());
00128 }
00129 }