1 29 package net.sourceforge.groboutils.pmti.v1.defimpl; 30 31 import net.sourceforge.groboutils.pmti.v1.IListAttribute; 32 import net.sourceforge.groboutils.pmti.v1.IAttributeInfo; 33 34 import java.util.Enumeration ; 35 import java.util.NoSuchElementException ; 36 37 38 45 public class DefaultListAttribute implements IListAttribute 46 { 47 private Object [] obj; 49 private IAttributeInfo info; 50 51 52 public DefaultListAttribute( Object [] o, IAttributeInfo i ) 53 { 54 if (i == null) 55 { 56 throw new IllegalArgumentException ("no null arguments"); 57 } 58 this.obj = copyObj( o ); 59 this.info = i; 60 } 61 62 63 64 67 public Object getValue() 68 { 69 return getValues(); 70 } 71 72 73 76 public IAttributeInfo getInfo() 77 { 78 return this.info; 79 } 80 81 82 86 public Enumeration getValues() 87 { 88 return new ArrayEnum( this.obj ); 90 } 91 92 93 96 public int getValueCount() 97 { 98 return this.obj.length; 99 } 100 101 102 105 public boolean containsValue( Object value ) 106 { 107 for (int i = 0; i < this.obj.length; ++i) 108 { 109 Object o = this.obj[i]; 110 if (value == null) 111 { 112 if (o == null) 113 { 114 return true; 115 } 116 } 117 else 118 if (value.equals( o )) 119 { 120 return true; 121 } 122 } 123 return false; 124 } 125 126 127 128 private Object [] copyObj( Object [] o ) 129 { 130 if (o == null) 131 { 132 throw new IllegalArgumentException ("no null arguments"); 133 } 134 Object ret[] = new Object [ o.length ]; 135 System.arraycopy( o, 0, ret, 0, o.length ); 136 return ret; 137 } 138 139 140 private static class ArrayEnum implements Enumeration 141 { 142 private Object vals[]; 143 private int index; 144 public ArrayEnum( Object o[] ) 145 { 146 this.vals = o; 147 this.index = 0; 148 } 149 150 151 public boolean hasMoreElements() 152 { 153 return (this.index < this.vals.length); 154 } 155 156 157 public Object nextElement() 158 { 159 if (this.index >= this.vals.length) 160 { 161 throw new NoSuchElementException (); 162 } 163 Object ret = this.vals[ this.index ]; 164 ++this.index; 165 return ret; 166 } 167 } 168 } 169 170 | Popular Tags |