144 private int privatekey;
145
146 /**
147 * Construct a key using the indicated private key. Each
148 * subclass of Key maintains its own unique domain of integer
149 * keys. No two objects with the same integer key and of the
150 * same specific subclass can be constructed. An exception
151 * will be thrown if an attempt is made to construct another
152 * object of a given class with the same integer key as a
153 * pre-existing instance of that subclass of Key.
154 * @param privatekey the specified key
155 */
156 protected Key(int privatekey) {
157 this.privatekey = privatekey;
158 recordIdentity(this);
159 }
160
161 /**
162 * Returns true if the specified object is a valid value
163 * for this Key.
164 * @param val the <code>Object</code> to test for validity
165 * @return <code>true</code> if <code>val</code> is valid;
166 * <code>false</code> otherwise.
167 */
168 public abstract boolean isCompatibleValue(Object val);
169
170 /**
171 * Returns the private integer key that the subclass
172 * instantiated this Key with.
173 * @return the private integer key that the subclass
174 * instantiated this Key with.
175 */
176 protected final int intKey() {
177 return privatekey;
178 }
179
180 /**
181 * The hash code for all Key objects will be the same as the
182 * system identity code of the object as defined by the
183 * System.identityHashCode() method.
184 */
185 public final int hashCode() {
186 return super.hashCode();
502 * Text antialiasing hint value -- request that text be displayed
503 * optimised for an LCD display with subpixel organisation from display
504 * top to bottom of B,G,R such that the vertical subpixel resolution is
505 * three times that of the full pixel vertical resolution (VBGR).
506 * Vertical orientation is very uncommon and probably mainly useful
507 * for a physically rotated display.
508 * Selecting this hint for displays with one of the other LCD subpixel
509 * configurations will likely result in unfocused text.
510 * See {@link #VALUE_TEXT_ANTIALIAS_LCD_HRGB},
511 * for more information on when this hint is applied.
512 *
513 * @see #KEY_TEXT_ANTIALIASING
514 * @since 1.6
515 */
516 public static final Object VALUE_TEXT_ANTIALIAS_LCD_VBGR =
517 SunHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR;
518
519
520 /**
521 * LCD text contrast rendering hint key.
522 * The value is an <code>Integer</code> object which is used as a text
523 * contrast adjustment when used in conjunction with an LCD text
524 * anti-aliasing hint such as
525 * {@link #VALUE_TEXT_ANTIALIAS_LCD_HRGB}.
526 * <ul>
527 * <li>Values should be a positive integer in the range 100 to 250.
528 * <li>A lower value (eg 100) corresponds to higher contrast text when
529 * displaying dark text on a light background.
530 * <li>A higher value (eg 200) corresponds to lower contrast text when
531 * displaying dark text on a light background.
532 * <li>A typical useful value is in the narrow range 140-180.
533 * <li>If no value is specified, a system or implementation default value
534 * will be applied.
535 * </ul>
536 * The default value can be expected to be adequate for most purposes,
537 * so clients should rarely need to specify a value for this hint unless
538 * they have concrete information as to an appropriate value.
539 * A higher value does not mean a higher contrast, in fact the opposite
540 * is true.
541 * The correction is applied in a similar manner to a gamma adjustment
542 * for non-linear perceptual luminance response of display systems, but
1011 */
1012 public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT =
1013 SunHints.VALUE_RESOLUTION_VARIANT_DPI_FIT;
1014
1015 /**
1016 * Constructs a new object with keys and values initialized
1017 * from the specified Map object which may be null.
1018 * @param init a map of key/value pairs to initialize the hints
1019 * or null if the object should be empty
1020 */
1021 public RenderingHints(Map<Key,?> init) {
1022 if (init != null) {
1023 hintmap.putAll(init);
1024 }
1025 }
1026
1027 /**
1028 * Constructs a new object with the specified key/value pair.
1029 * @param key the key of the particular hint property
1030 * @param value the value of the hint property specified with
1031 * <code>key</code>
1032 */
1033 public RenderingHints(Key key, Object value) {
1034 hintmap.put(key, value);
1035 }
1036
1037 /**
1038 * Returns the number of key-value mappings in this
1039 * <code>RenderingHints</code>.
1040 *
1041 * @return the number of key-value mappings in this
1042 * <code>RenderingHints</code>.
1043 */
1044 public int size() {
1045 return hintmap.size();
1046 }
1047
1048 /**
1049 * Returns <code>true</code> if this
1050 * <code>RenderingHints</code> contains no key-value mappings.
1051 *
1052 * @return <code>true</code> if this
1053 * <code>RenderingHints</code> contains no key-value mappings.
1054 */
1055 public boolean isEmpty() {
1056 return hintmap.isEmpty();
1057 }
1058
1059 /**
1060 * Returns {@code true} if this {@code RenderingHints}
1061 * contains a mapping for the specified key.
1062 *
1063 * @param key key whose presence in this
1064 * {@code RenderingHints} is to be tested.
1065 * @return {@code true} if this {@code RenderingHints}
1066 * contains a mapping for the specified key.
1067 * @exception ClassCastException if the key can not
1068 * be cast to {@code RenderingHints.Key}
1069 */
1070 public boolean containsKey(Object key) {
1071 return hintmap.containsKey((Key) key);
1072 }
1073
1074 /**
1075 * Returns true if this RenderingHints maps one or more keys to the
1076 * specified value.
1077 * More formally, returns <code>true</code> if and only
1078 * if this <code>RenderingHints</code>
1079 * contains at least one mapping to a value <code>v</code> such that
1080 * <pre>
1081 * (value==null ? v==null : value.equals(v))
1082 * </pre>.
1083 * This operation will probably require time linear in the
1084 * <code>RenderingHints</code> size for most implementations
1085 * of <code>RenderingHints</code>.
1086 *
1087 * @param value value whose presence in this
1088 * <code>RenderingHints</code> is to be tested.
1089 * @return <code>true</code> if this <code>RenderingHints</code>
1090 * maps one or more keys to the specified value.
1091 */
1092 public boolean containsValue(Object value) {
1093 return hintmap.containsValue(value);
1094 }
1095
1096 /**
1097 * Returns the value to which the specified key is mapped.
1098 * @param key a rendering hint key
1099 * @return the value to which the key is mapped in this object or
1100 * {@code null} if the key is not mapped to any value in
1101 * this object.
1102 * @exception ClassCastException if the key can not
1103 * be cast to {@code RenderingHints.Key}
1104 * @see #put(Object, Object)
1105 */
1106 public Object get(Object key) {
1107 return hintmap.get((Key) key);
1108 }
1109
1122 * @exception ClassCastException if the key can not
1123 * be cast to {@code RenderingHints.Key}
1124 * @exception IllegalArgumentException if the
1125 * {@link Key#isCompatibleValue(java.lang.Object)
1126 * Key.isCompatibleValue()}
1127 * method of the specified key returns false for the
1128 * specified value
1129 * @see #get(Object)
1130 */
1131 public Object put(Object key, Object value) {
1132 if (!((Key) key).isCompatibleValue(value)) {
1133 throw new IllegalArgumentException(value+
1134 " incompatible with "+
1135 key);
1136 }
1137 return hintmap.put((Key) key, value);
1138 }
1139
1140 /**
1141 * Adds all of the keys and corresponding values from the specified
1142 * <code>RenderingHints</code> object to this
1143 * <code>RenderingHints</code> object. Keys that are present in
1144 * this <code>RenderingHints</code> object, but not in the specified
1145 * <code>RenderingHints</code> object are not affected.
1146 * @param hints the set of key/value pairs to be added to this
1147 * <code>RenderingHints</code> object
1148 */
1149 public void add(RenderingHints hints) {
1150 hintmap.putAll(hints.hintmap);
1151 }
1152
1153 /**
1154 * Clears this <code>RenderingHints</code> object of all key/value
1155 * pairs.
1156 */
1157 public void clear() {
1158 hintmap.clear();
1159 }
1160
1161 /**
1162 * Removes the key and its corresponding value from this
1163 * {@code RenderingHints} object. This method does nothing if the
1164 * key is not in this {@code RenderingHints} object.
1165 * @param key the rendering hints key that needs to be removed
1166 * @exception ClassCastException if the key can not
1167 * be cast to {@code RenderingHints.Key}
1168 * @return the value to which the key had previously been mapped in this
1169 * {@code RenderingHints} object, or {@code null}
1170 * if the key did not have a mapping.
1171 */
1172 public Object remove(Object key) {
1173 return hintmap.remove((Key) key);
1174 }
1185 * @exception IllegalArgumentException some aspect
1186 * of a key or value in the specified {@code Map}
1187 * prevents it from being stored in
1188 * this {@code RenderingHints}.
1189 */
1190 public void putAll(Map<?,?> m) {
1191 // ## javac bug?
1192 //if (m instanceof RenderingHints) {
1193 if (RenderingHints.class.isInstance(m)) {
1194 //hintmap.putAll(((RenderingHints) m).hintmap);
1195 for (Map.Entry<?,?> entry : m.entrySet())
1196 hintmap.put(entry.getKey(), entry.getValue());
1197 } else {
1198 // Funnel each key/value pair through our protected put method
1199 for (Map.Entry<?,?> entry : m.entrySet())
1200 put(entry.getKey(), entry.getValue());
1201 }
1202 }
1203
1204 /**
1205 * Returns a <code>Set</code> view of the Keys contained in this
1206 * <code>RenderingHints</code>. The Set is backed by the
1207 * <code>RenderingHints</code>, so changes to the
1208 * <code>RenderingHints</code> are reflected in the <code>Set</code>,
1209 * and vice-versa. If the <code>RenderingHints</code> is modified
1210 * while an iteration over the <code>Set</code> is in progress,
1211 * the results of the iteration are undefined. The <code>Set</code>
1212 * supports element removal, which removes the corresponding
1213 * mapping from the <code>RenderingHints</code>, via the
1214 * <code>Iterator.remove</code>, <code>Set.remove</code>,
1215 * <code>removeAll</code> <code>retainAll</code>, and
1216 * <code>clear</code> operations. It does not support
1217 * the <code>add</code> or <code>addAll</code> operations.
1218 *
1219 * @return a <code>Set</code> view of the keys contained
1220 * in this <code>RenderingHints</code>.
1221 */
1222 public Set<Object> keySet() {
1223 return hintmap.keySet();
1224 }
1225
1226 /**
1227 * Returns a <code>Collection</code> view of the values
1228 * contained in this <code>RenderingHints</code>.
1229 * The <code>Collection</code> is backed by the
1230 * <code>RenderingHints</code>, so changes to
1231 * the <code>RenderingHints</code> are reflected in
1232 * the <code>Collection</code>, and vice-versa.
1233 * If the <code>RenderingHints</code> is modified while
1234 * an iteration over the <code>Collection</code> is
1235 * in progress, the results of the iteration are undefined.
1236 * The <code>Collection</code> supports element removal,
1237 * which removes the corresponding mapping from the
1238 * <code>RenderingHints</code>, via the
1239 * <code>Iterator.remove</code>,
1240 * <code>Collection.remove</code>, <code>removeAll</code>,
1241 * <code>retainAll</code> and <code>clear</code> operations.
1242 * It does not support the <code>add</code> or
1243 * <code>addAll</code> operations.
1244 *
1245 * @return a <code>Collection</code> view of the values
1246 * contained in this <code>RenderingHints</code>.
1247 */
1248 public Collection<Object> values() {
1249 return hintmap.values();
1250 }
1251
1252 /**
1253 * Returns a <code>Set</code> view of the mappings contained
1254 * in this <code>RenderingHints</code>. Each element in the
1255 * returned <code>Set</code> is a <code>Map.Entry</code>.
1256 * The <code>Set</code> is backed by the <code>RenderingHints</code>,
1257 * so changes to the <code>RenderingHints</code> are reflected
1258 * in the <code>Set</code>, and vice-versa. If the
1259 * <code>RenderingHints</code> is modified while
1260 * while an iteration over the <code>Set</code> is in progress,
1261 * the results of the iteration are undefined.
1262 * <p>
1263 * The entrySet returned from a <code>RenderingHints</code> object
1264 * is not modifiable.
1265 *
1266 * @return a <code>Set</code> view of the mappings contained in
1267 * this <code>RenderingHints</code>.
1268 */
1269 public Set<Map.Entry<Object,Object>> entrySet() {
1270 return Collections.unmodifiableMap(hintmap).entrySet();
1271 }
1272
1273 /**
1274 * Compares the specified <code>Object</code> with this
1275 * <code>RenderingHints</code> for equality.
1276 * Returns <code>true</code> if the specified object is also a
1277 * <code>Map</code> and the two <code>Map</code> objects represent
1278 * the same mappings. More formally, two <code>Map</code> objects
1279 * <code>t1</code> and <code>t2</code> represent the same mappings
1280 * if <code>t1.keySet().equals(t2.keySet())</code> and for every
1281 * key <code>k</code> in <code>t1.keySet()</code>,
1282 * <pre>
1283 * (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k)))
1284 * </pre>.
1285 * This ensures that the <code>equals</code> method works properly across
1286 * different implementations of the <code>Map</code> interface.
1287 *
1288 * @param o <code>Object</code> to be compared for equality with
1289 * this <code>RenderingHints</code>.
1290 * @return <code>true</code> if the specified <code>Object</code>
1291 * is equal to this <code>RenderingHints</code>.
1292 */
1293 public boolean equals(Object o) {
1294 if (o instanceof RenderingHints) {
1295 return hintmap.equals(((RenderingHints) o).hintmap);
1296 } else if (o instanceof Map) {
1297 return hintmap.equals(o);
1298 }
1299 return false;
1300 }
1301
1302 /**
1303 * Returns the hash code value for this <code>RenderingHints</code>.
1304 * The hash code of a <code>RenderingHints</code> is defined to be
1305 * the sum of the hashCodes of each <code>Entry</code> in the
1306 * <code>RenderingHints</code> object's entrySet view. This ensures that
1307 * <code>t1.equals(t2)</code> implies that
1308 * <code>t1.hashCode()==t2.hashCode()</code> for any two <code>Map</code>
1309 * objects <code>t1</code> and <code>t2</code>, as required by the general
1310 * contract of <code>Object.hashCode</code>.
1311 *
1312 * @return the hash code value for this <code>RenderingHints</code>.
1313 * @see java.util.Map.Entry#hashCode()
1314 * @see Object#hashCode()
1315 * @see Object#equals(Object)
1316 * @see #equals(Object)
1317 */
1318 public int hashCode() {
1319 return hintmap.hashCode();
1320 }
1321
1322 /**
1323 * Creates a clone of this <code>RenderingHints</code> object
1324 * that has the same contents as this <code>RenderingHints</code>
1325 * object.
1326 * @return a clone of this instance.
1327 */
1328 @SuppressWarnings("unchecked")
1329 public Object clone() {
1330 RenderingHints rh;
1331 try {
1332 rh = (RenderingHints) super.clone();
1333 if (hintmap != null) {
1334 rh.hintmap = (HashMap<Object,Object>) hintmap.clone();
1335 }
1336 } catch (CloneNotSupportedException e) {
1337 // this shouldn't happen, since we are Cloneable
1338 throw new InternalError(e);
1339 }
1340
1341 return rh;
1342 }
1343
1344 /**
1345 * Returns a rather long string representation of the hashmap
1346 * which contains the mappings of keys to values for this
1347 * <code>RenderingHints</code> object.
1348 * @return a string representation of this object.
1349 */
1350 public String toString() {
1351 if (hintmap == null) {
1352 return getClass().getName() + "@" +
1353 Integer.toHexString(hashCode()) +
1354 " (0 hints)";
1355 }
1356
1357 return hintmap.toString();
1358 }
1359 }
|
144 private int privatekey;
145
146 /**
147 * Construct a key using the indicated private key. Each
148 * subclass of Key maintains its own unique domain of integer
149 * keys. No two objects with the same integer key and of the
150 * same specific subclass can be constructed. An exception
151 * will be thrown if an attempt is made to construct another
152 * object of a given class with the same integer key as a
153 * pre-existing instance of that subclass of Key.
154 * @param privatekey the specified key
155 */
156 protected Key(int privatekey) {
157 this.privatekey = privatekey;
158 recordIdentity(this);
159 }
160
161 /**
162 * Returns true if the specified object is a valid value
163 * for this Key.
164 * @param val the {@code Object} to test for validity
165 * @return {@code true} if {@code val} is valid;
166 * {@code false} otherwise.
167 */
168 public abstract boolean isCompatibleValue(Object val);
169
170 /**
171 * Returns the private integer key that the subclass
172 * instantiated this Key with.
173 * @return the private integer key that the subclass
174 * instantiated this Key with.
175 */
176 protected final int intKey() {
177 return privatekey;
178 }
179
180 /**
181 * The hash code for all Key objects will be the same as the
182 * system identity code of the object as defined by the
183 * System.identityHashCode() method.
184 */
185 public final int hashCode() {
186 return super.hashCode();
502 * Text antialiasing hint value -- request that text be displayed
503 * optimised for an LCD display with subpixel organisation from display
504 * top to bottom of B,G,R such that the vertical subpixel resolution is
505 * three times that of the full pixel vertical resolution (VBGR).
506 * Vertical orientation is very uncommon and probably mainly useful
507 * for a physically rotated display.
508 * Selecting this hint for displays with one of the other LCD subpixel
509 * configurations will likely result in unfocused text.
510 * See {@link #VALUE_TEXT_ANTIALIAS_LCD_HRGB},
511 * for more information on when this hint is applied.
512 *
513 * @see #KEY_TEXT_ANTIALIASING
514 * @since 1.6
515 */
516 public static final Object VALUE_TEXT_ANTIALIAS_LCD_VBGR =
517 SunHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR;
518
519
520 /**
521 * LCD text contrast rendering hint key.
522 * The value is an {@code Integer} object which is used as a text
523 * contrast adjustment when used in conjunction with an LCD text
524 * anti-aliasing hint such as
525 * {@link #VALUE_TEXT_ANTIALIAS_LCD_HRGB}.
526 * <ul>
527 * <li>Values should be a positive integer in the range 100 to 250.
528 * <li>A lower value (eg 100) corresponds to higher contrast text when
529 * displaying dark text on a light background.
530 * <li>A higher value (eg 200) corresponds to lower contrast text when
531 * displaying dark text on a light background.
532 * <li>A typical useful value is in the narrow range 140-180.
533 * <li>If no value is specified, a system or implementation default value
534 * will be applied.
535 * </ul>
536 * The default value can be expected to be adequate for most purposes,
537 * so clients should rarely need to specify a value for this hint unless
538 * they have concrete information as to an appropriate value.
539 * A higher value does not mean a higher contrast, in fact the opposite
540 * is true.
541 * The correction is applied in a similar manner to a gamma adjustment
542 * for non-linear perceptual luminance response of display systems, but
1011 */
1012 public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT =
1013 SunHints.VALUE_RESOLUTION_VARIANT_DPI_FIT;
1014
1015 /**
1016 * Constructs a new object with keys and values initialized
1017 * from the specified Map object which may be null.
1018 * @param init a map of key/value pairs to initialize the hints
1019 * or null if the object should be empty
1020 */
1021 public RenderingHints(Map<Key,?> init) {
1022 if (init != null) {
1023 hintmap.putAll(init);
1024 }
1025 }
1026
1027 /**
1028 * Constructs a new object with the specified key/value pair.
1029 * @param key the key of the particular hint property
1030 * @param value the value of the hint property specified with
1031 * {@code key}
1032 */
1033 public RenderingHints(Key key, Object value) {
1034 hintmap.put(key, value);
1035 }
1036
1037 /**
1038 * Returns the number of key-value mappings in this
1039 * {@code RenderingHints}.
1040 *
1041 * @return the number of key-value mappings in this
1042 * {@code RenderingHints}.
1043 */
1044 public int size() {
1045 return hintmap.size();
1046 }
1047
1048 /**
1049 * Returns {@code true} if this
1050 * {@code RenderingHints} contains no key-value mappings.
1051 *
1052 * @return {@code true} if this
1053 * {@code RenderingHints} contains no key-value mappings.
1054 */
1055 public boolean isEmpty() {
1056 return hintmap.isEmpty();
1057 }
1058
1059 /**
1060 * Returns {@code true} if this {@code RenderingHints}
1061 * contains a mapping for the specified key.
1062 *
1063 * @param key key whose presence in this
1064 * {@code RenderingHints} is to be tested.
1065 * @return {@code true} if this {@code RenderingHints}
1066 * contains a mapping for the specified key.
1067 * @exception ClassCastException if the key can not
1068 * be cast to {@code RenderingHints.Key}
1069 */
1070 public boolean containsKey(Object key) {
1071 return hintmap.containsKey((Key) key);
1072 }
1073
1074 /**
1075 * Returns true if this RenderingHints maps one or more keys to the
1076 * specified value.
1077 * More formally, returns {@code true} if and only
1078 * if this {@code RenderingHints}
1079 * contains at least one mapping to a value {@code v} such that
1080 * <pre>
1081 * (value==null ? v==null : value.equals(v))
1082 * </pre>.
1083 * This operation will probably require time linear in the
1084 * {@code RenderingHints} size for most implementations
1085 * of {@code RenderingHints}.
1086 *
1087 * @param value value whose presence in this
1088 * {@code RenderingHints} is to be tested.
1089 * @return {@code true} if this {@code RenderingHints}
1090 * maps one or more keys to the specified value.
1091 */
1092 public boolean containsValue(Object value) {
1093 return hintmap.containsValue(value);
1094 }
1095
1096 /**
1097 * Returns the value to which the specified key is mapped.
1098 * @param key a rendering hint key
1099 * @return the value to which the key is mapped in this object or
1100 * {@code null} if the key is not mapped to any value in
1101 * this object.
1102 * @exception ClassCastException if the key can not
1103 * be cast to {@code RenderingHints.Key}
1104 * @see #put(Object, Object)
1105 */
1106 public Object get(Object key) {
1107 return hintmap.get((Key) key);
1108 }
1109
1122 * @exception ClassCastException if the key can not
1123 * be cast to {@code RenderingHints.Key}
1124 * @exception IllegalArgumentException if the
1125 * {@link Key#isCompatibleValue(java.lang.Object)
1126 * Key.isCompatibleValue()}
1127 * method of the specified key returns false for the
1128 * specified value
1129 * @see #get(Object)
1130 */
1131 public Object put(Object key, Object value) {
1132 if (!((Key) key).isCompatibleValue(value)) {
1133 throw new IllegalArgumentException(value+
1134 " incompatible with "+
1135 key);
1136 }
1137 return hintmap.put((Key) key, value);
1138 }
1139
1140 /**
1141 * Adds all of the keys and corresponding values from the specified
1142 * {@code RenderingHints} object to this
1143 * {@code RenderingHints} object. Keys that are present in
1144 * this {@code RenderingHints} object, but not in the specified
1145 * {@code RenderingHints} object are not affected.
1146 * @param hints the set of key/value pairs to be added to this
1147 * {@code RenderingHints} object
1148 */
1149 public void add(RenderingHints hints) {
1150 hintmap.putAll(hints.hintmap);
1151 }
1152
1153 /**
1154 * Clears this {@code RenderingHints} object of all key/value
1155 * pairs.
1156 */
1157 public void clear() {
1158 hintmap.clear();
1159 }
1160
1161 /**
1162 * Removes the key and its corresponding value from this
1163 * {@code RenderingHints} object. This method does nothing if the
1164 * key is not in this {@code RenderingHints} object.
1165 * @param key the rendering hints key that needs to be removed
1166 * @exception ClassCastException if the key can not
1167 * be cast to {@code RenderingHints.Key}
1168 * @return the value to which the key had previously been mapped in this
1169 * {@code RenderingHints} object, or {@code null}
1170 * if the key did not have a mapping.
1171 */
1172 public Object remove(Object key) {
1173 return hintmap.remove((Key) key);
1174 }
1185 * @exception IllegalArgumentException some aspect
1186 * of a key or value in the specified {@code Map}
1187 * prevents it from being stored in
1188 * this {@code RenderingHints}.
1189 */
1190 public void putAll(Map<?,?> m) {
1191 // ## javac bug?
1192 //if (m instanceof RenderingHints) {
1193 if (RenderingHints.class.isInstance(m)) {
1194 //hintmap.putAll(((RenderingHints) m).hintmap);
1195 for (Map.Entry<?,?> entry : m.entrySet())
1196 hintmap.put(entry.getKey(), entry.getValue());
1197 } else {
1198 // Funnel each key/value pair through our protected put method
1199 for (Map.Entry<?,?> entry : m.entrySet())
1200 put(entry.getKey(), entry.getValue());
1201 }
1202 }
1203
1204 /**
1205 * Returns a {@code Set} view of the Keys contained in this
1206 * {@code RenderingHints}. The Set is backed by the
1207 * {@code RenderingHints}, so changes to the
1208 * {@code RenderingHints} are reflected in the {@code Set},
1209 * and vice-versa. If the {@code RenderingHints} is modified
1210 * while an iteration over the {@code Set} is in progress,
1211 * the results of the iteration are undefined. The {@code Set}
1212 * supports element removal, which removes the corresponding
1213 * mapping from the {@code RenderingHints}, via the
1214 * {@code Iterator.remove}, {@code Set.remove},
1215 * {@code removeAll retainAll}, and
1216 * {@code clear} operations. It does not support
1217 * the {@code add} or {@code addAll} operations.
1218 *
1219 * @return a {@code Set} view of the keys contained
1220 * in this {@code RenderingHints}.
1221 */
1222 public Set<Object> keySet() {
1223 return hintmap.keySet();
1224 }
1225
1226 /**
1227 * Returns a {@code Collection} view of the values
1228 * contained in this {@code RenderingHints}.
1229 * The {@code Collection} is backed by the
1230 * {@code RenderingHints}, so changes to
1231 * the {@code RenderingHints} are reflected in
1232 * the {@code Collection}, and vice-versa.
1233 * If the {@code RenderingHints} is modified while
1234 * an iteration over the {@code Collection} is
1235 * in progress, the results of the iteration are undefined.
1236 * The {@code Collection} supports element removal,
1237 * which removes the corresponding mapping from the
1238 * {@code RenderingHints}, via the
1239 * {@code Iterator.remove},
1240 * {@code Collection.remove}, {@code removeAll},
1241 * {@code retainAll} and {@code clear} operations.
1242 * It does not support the {@code add} or
1243 * {@code addAll} operations.
1244 *
1245 * @return a {@code Collection} view of the values
1246 * contained in this {@code RenderingHints}.
1247 */
1248 public Collection<Object> values() {
1249 return hintmap.values();
1250 }
1251
1252 /**
1253 * Returns a {@code Set} view of the mappings contained
1254 * in this {@code RenderingHints}. Each element in the
1255 * returned {@code Set} is a {@code Map.Entry}.
1256 * The {@code Set} is backed by the {@code RenderingHints},
1257 * so changes to the {@code RenderingHints} are reflected
1258 * in the {@code Set}, and vice-versa. If the
1259 * {@code RenderingHints} is modified while
1260 * while an iteration over the {@code Set} is in progress,
1261 * the results of the iteration are undefined.
1262 * <p>
1263 * The entrySet returned from a {@code RenderingHints} object
1264 * is not modifiable.
1265 *
1266 * @return a {@code Set} view of the mappings contained in
1267 * this {@code RenderingHints}.
1268 */
1269 public Set<Map.Entry<Object,Object>> entrySet() {
1270 return Collections.unmodifiableMap(hintmap).entrySet();
1271 }
1272
1273 /**
1274 * Compares the specified {@code Object} with this
1275 * {@code RenderingHints} for equality.
1276 * Returns {@code true} if the specified object is also a
1277 * {@code Map} and the two {@code Map} objects represent
1278 * the same mappings. More formally, two {@code Map} objects
1279 * {@code t1} and {@code t2} represent the same mappings
1280 * if {@code t1.keySet().equals(t2.keySet())} and for every
1281 * key {@code k} in {@code t1.keySet()},
1282 * <pre>
1283 * (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k)))
1284 * </pre>.
1285 * This ensures that the {@code equals} method works properly across
1286 * different implementations of the {@code Map} interface.
1287 *
1288 * @param o {@code Object} to be compared for equality with
1289 * this {@code RenderingHints}.
1290 * @return {@code true} if the specified {@code Object}
1291 * is equal to this {@code RenderingHints}.
1292 */
1293 public boolean equals(Object o) {
1294 if (o instanceof RenderingHints) {
1295 return hintmap.equals(((RenderingHints) o).hintmap);
1296 } else if (o instanceof Map) {
1297 return hintmap.equals(o);
1298 }
1299 return false;
1300 }
1301
1302 /**
1303 * Returns the hash code value for this {@code RenderingHints}.
1304 * The hash code of a {@code RenderingHints} is defined to be
1305 * the sum of the hashCodes of each {@code Entry} in the
1306 * {@code RenderingHints} object's entrySet view. This ensures that
1307 * {@code t1.equals(t2)} implies that
1308 * {@code t1.hashCode()==t2.hashCode()} for any two {@code Map}
1309 * objects {@code t1} and {@code t2}, as required by the general
1310 * contract of {@code Object.hashCode}.
1311 *
1312 * @return the hash code value for this {@code RenderingHints}.
1313 * @see java.util.Map.Entry#hashCode()
1314 * @see Object#hashCode()
1315 * @see Object#equals(Object)
1316 * @see #equals(Object)
1317 */
1318 public int hashCode() {
1319 return hintmap.hashCode();
1320 }
1321
1322 /**
1323 * Creates a clone of this {@code RenderingHints} object
1324 * that has the same contents as this {@code RenderingHints}
1325 * object.
1326 * @return a clone of this instance.
1327 */
1328 @SuppressWarnings("unchecked")
1329 public Object clone() {
1330 RenderingHints rh;
1331 try {
1332 rh = (RenderingHints) super.clone();
1333 if (hintmap != null) {
1334 rh.hintmap = (HashMap<Object,Object>) hintmap.clone();
1335 }
1336 } catch (CloneNotSupportedException e) {
1337 // this shouldn't happen, since we are Cloneable
1338 throw new InternalError(e);
1339 }
1340
1341 return rh;
1342 }
1343
1344 /**
1345 * Returns a rather long string representation of the hashmap
1346 * which contains the mappings of keys to values for this
1347 * {@code RenderingHints} object.
1348 * @return a string representation of this object.
1349 */
1350 public String toString() {
1351 if (hintmap == null) {
1352 return getClass().getName() + "@" +
1353 Integer.toHexString(hashCode()) +
1354 " (0 hints)";
1355 }
1356
1357 return hintmap.toString();
1358 }
1359 }
|