1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 public primitive class Value { 25 char char_v; 26 byte byte_v; 27 boolean boolean_v; 28 int int_v; 29 short short_v; 30 long long_v; 31 double double_v; 32 float float_v; 33 Number number_v; 34 Point point_v; 35 Point.ref point_ref; 36 Object ref_v; 37 38 Value(char c, boolean z, byte b, int x, short y, long l, float f, double d, Number number, Point p, Object o) { 39 char_v = c; 40 byte_v = b; 41 boolean_v = z; 42 int_v = x; 43 short_v = y; 44 long_v = l; 45 float_v = f; 46 double_v = d; 47 number_v = number; 48 point_v = p; 49 point_ref = null; 50 ref_v = o; 51 } 52 Value(char c, boolean z, byte b, int x, short y, long l, float f, double d, Number number, Point p, Point.ref pref, Object o) { 53 char_v = c; 54 byte_v = b; 55 boolean_v = z; 56 int_v = x; 57 short_v = y; 58 long_v = l; 59 float_v = f; 60 double_v = d; 61 number_v = number; 62 point_v = p; 63 point_ref = pref; 64 ref_v = o; 65 } 66 static class Builder { 67 private char c; 68 private byte b; 69 private boolean z; 70 private int i; 71 private short s; 72 private long l; 73 private double d; 74 private float f; 75 private Number n; 76 private Point p = Point.makePoint(0,0); 77 private Point.ref pref; 78 private Object ref; 79 80 public Builder() {} 81 Builder setChar(char c) { 82 this.c = c; 83 return this; 84 } 85 Builder setByte(byte b) { 86 this.b = b; 87 return this; 88 } 89 Builder setBoolean(boolean z) { 90 this.z = z; 91 return this; 92 } 93 Builder setInt(int i) { 94 this.i = i; 95 return this; 96 } 97 Builder setShort(short s) { 98 this.s = s; 99 return this; 100 } 101 Builder setLong(long l) { 102 this.l = l; 103 return this; 104 } 105 Builder setDouble(double d) { 106 this.d = d; 107 return this; 108 } 109 Builder setFloat(float f) { 110 this.f = f; 111 return this; 112 } 113 Builder setNumber(Number n) { 114 this.n = n; 115 return this; 116 } 117 Builder setPoint(Point p) { 118 this.p = p; 119 return this; 120 } 121 Builder setPointRef(Point p) { 122 this.pref = p; 123 return this; 124 } 125 Builder setReference(Object o) { 126 this.ref = o; 127 return this; 128 } 129 Value build() { 130 return new Value(c, z, b, i, s, l, f, d, n, p, pref, ref); 131 } 132 } 133 134 interface Number { 135 default int intValue() { 136 throw new UnsupportedOperationException(); 137 } 138 default short shortValue() { 139 throw new UnsupportedOperationException(); 140 } 141 142 static IntValue intValue(int i) { 143 return new IntValue(i); 144 } 145 146 static ShortValue shortValue(short s) { 147 return new ShortValue(s); 148 } 149 } 150 151 static primitive class IntValue implements Number { 152 int i; 153 IntValue(int i) { 154 this.i = i; 155 } 156 public int intValue() { 157 return i; 158 } 159 } 160 161 static primitive class ShortValue implements Number { 162 short s; 163 ShortValue(short s) { 164 this.s = s; 165 } 166 public short shortValue() { 167 return s; 168 } 169 } 170 171 static class IntNumber implements Number { 172 final int i; 173 public IntNumber(int i) { 174 this.i = i; 175 } 176 177 public int intValue() { 178 return i; 179 } 180 181 @Override 182 public String toString() { 183 return Integer.toString(i); 184 } 185 } 186 }