1 56 57 package org.jfree.chart.axis; 58 59 import java.io.Serializable ; 60 import java.util.ArrayList ; 61 import java.util.Collections ; 62 import java.util.List ; 63 64 68 public class TickUnits implements TickUnitSource, Cloneable , Serializable { 69 70 71 private static final long serialVersionUID = 1134174035901467545L; 72 73 74 private List tickUnits; 75 76 79 public TickUnits() { 80 this.tickUnits = new ArrayList (); 81 } 82 83 90 public void add(TickUnit unit) { 91 92 if (unit == null) { 93 throw new NullPointerException ("Null 'unit' argument."); 94 } 95 this.tickUnits.add(unit); 96 Collections.sort(this.tickUnits); 97 98 } 99 100 107 public int size() { 108 return this.tickUnits.size(); 109 } 110 111 120 public TickUnit get(int pos) { 121 return (TickUnit) this.tickUnits.get(pos); 122 } 123 124 131 public TickUnit getLargerTickUnit(TickUnit unit) { 132 133 int index = Collections.binarySearch(this.tickUnits, unit); 134 if (index >= 0) { 135 index = index + 1; 136 } 137 else { 138 index = -index; 139 } 140 141 return (TickUnit) this.tickUnits.get( 142 Math.min(index, this.tickUnits.size() - 1) 143 ); 144 145 } 146 147 155 public TickUnit getCeilingTickUnit(TickUnit unit) { 156 157 int index = Collections.binarySearch(this.tickUnits, unit); 158 if (index >= 0) { 159 return (TickUnit) this.tickUnits.get(index); 160 } 161 else { 162 index = -(index + 1); 163 return (TickUnit) this.tickUnits.get( 164 Math.min(index, this.tickUnits.size() - 1) 165 ); 166 } 167 168 } 169 170 178 public TickUnit getCeilingTickUnit(double size) { 179 return getCeilingTickUnit(new NumberTickUnit(size, null)); 180 } 181 182 190 public Object clone() throws CloneNotSupportedException { 191 TickUnits clone = (TickUnits) super.clone(); 192 clone.tickUnits = new java.util.ArrayList (this.tickUnits); 193 return clone; 194 } 195 196 203 public boolean equals(Object object) { 204 if (object == null) { 205 return false; 206 } 207 if (object == this) { 208 return true; 209 } 210 if (object instanceof TickUnits) { 211 TickUnits tu = (TickUnits) object; 212 return tu.tickUnits.equals(this.tickUnits); 213 } 214 return false; 215 } 216 217 } 218 | Popular Tags |