1 17 18 19 20 package org.apache.fop.traits; 21 22 28 public class MinOptMax implements java.io.Serializable , Cloneable { 29 30 31 public int min; 32 public int opt; 33 public int max; 34 35 38 public MinOptMax() { 39 this(0); 40 } 41 42 47 public MinOptMax(int val) { 48 this(val, val, val); 49 } 50 51 58 public MinOptMax(int min, int opt, int max) { 59 this.min = min; 61 this.opt = opt; 62 this.max = max; 63 } 64 65 70 public MinOptMax(MinOptMax op) { 71 this.min = op.min; 72 this.opt = op.opt; 73 this.max = op.max; 74 } 75 76 80 public Object clone() { 81 try { 82 return super.clone(); 83 } catch (CloneNotSupportedException ex) { 84 return null; 86 } 87 } 88 89 95 public static MinOptMax subtract(MinOptMax op1, MinOptMax op2) { 96 return new MinOptMax(op1.min - op2.max, op1.opt - op2.opt, 97 op1.max - op2.min); 98 } 99 100 106 public static MinOptMax add(MinOptMax op1, MinOptMax op2) { 107 return new MinOptMax(op1.min + op2.min, op1.opt + op2.opt, 108 op1.max + op2.max); 109 } 110 111 117 public static MinOptMax multiply(MinOptMax op1, double mult) { 118 return new MinOptMax((int)(op1.min * mult), 120 (int)(op1.opt * mult), (int)(op1.max * mult)); 121 } 122 123 127 public void add(MinOptMax op) { 128 min += op.min; 129 opt += op.opt; 130 max += op.max; 131 } 132 133 139 public void add(int min, int opt, int max) { 140 this.min += min; 141 this.opt += opt; 142 this.max += max; 143 } 145 146 150 public void add(int len) { 151 this.min += len; 152 this.opt += len; 153 this.max += len; 154 } 155 156 157 161 public void subtract(MinOptMax op) { 162 min -= op.max; 163 opt -= op.opt; 164 max -= op.min; 165 } 166 167 168 public boolean isNonZero() { 169 return (min != 0 || max != 0); 170 } 171 172 173 public boolean isElastic() { 174 return (min != opt || opt != max); 175 } 176 177 178 public String toString() { 179 StringBuffer sb = new StringBuffer (); 180 sb.append("MinOptMax[min="); 181 if (min != opt) { 182 sb.append(min).append("; "); 183 } 184 sb.append("opt="); 185 if (opt != max) { 186 sb.append(opt).append("; "); 187 } 188 sb.append("max=").append(max); 189 sb.append("]"); 190 return sb.toString(); 191 } 192 } 193 194 | Popular Tags |