src/share/classes/javax/imageio/metadata/IIOMetadataFormatImpl.java
Print this page
rev 9293 : 8034998: Fix raw and unchecked lint warnings in javax.imageio
Reviewed-by:
*** 88,118 ****
private String resourceBaseName = this.getClass().getName() + "Resources";
private String rootName;
// Element name (String) -> Element
! private HashMap elementMap = new HashMap();
class Element {
String elementName;
int childPolicy;
int minChildren = 0;
int maxChildren = 0;
// Child names (Strings)
! List childList = new ArrayList();
// Parent names (Strings)
! List parentList = new ArrayList();
// List of attribute names in the order they were added
! List attrList = new ArrayList();
// Attr name (String) -> Attribute
! Map attrMap = new HashMap();
! ObjectValue objectValue;
}
class Attribute {
String attrName;
--- 88,118 ----
private String resourceBaseName = this.getClass().getName() + "Resources";
private String rootName;
// Element name (String) -> Element
! private HashMap<String, Element> elementMap = new HashMap<>();
class Element {
String elementName;
int childPolicy;
int minChildren = 0;
int maxChildren = 0;
// Child names (Strings)
! List<String> childList = new ArrayList<>();
// Parent names (Strings)
! List<String> parentList = new ArrayList<>();
// List of attribute names in the order they were added
! List<String> attrList = new ArrayList<>();
// Attr name (String) -> Attribute
! Map<String, Attribute> attrMap = new HashMap<>();
! ObjectValue<?> objectValue;
}
class Attribute {
String attrName;
*** 120,151 ****
int dataType;
boolean required;
String defaultValue = null;
// enumeration
! List enumeratedValues;
// range
String minValue;
String maxValue;
// list
int listMinLength;
int listMaxLength;
}
! class ObjectValue {
int valueType = VALUE_NONE;
! Class classType = null;
! Object defaultValue = null;
// Meaningful only if valueType == VALUE_ENUMERATION
! List enumeratedValues = null;
// Meaningful only if valueType == VALUE_RANGE
! Comparable minValue = null;
! Comparable maxValue = null;
// Meaningful only if valueType == VALUE_LIST
int arrayMinLength = 0;
int arrayMaxLength = 0;
}
--- 120,152 ----
int dataType;
boolean required;
String defaultValue = null;
// enumeration
! List<String> enumeratedValues;
// range
String minValue;
String maxValue;
// list
int listMinLength;
int listMaxLength;
}
! class ObjectValue<T> {
int valueType = VALUE_NONE;
! // ? extends T So that ObjectValue<Object> can take Class<?>
! Class<? extends T> classType = null;
! T defaultValue = null;
// Meaningful only if valueType == VALUE_ENUMERATION
! List<? extends T> enumeratedValues = null;
// Meaningful only if valueType == VALUE_RANGE
! Comparable<? super T> minValue = null;
! Comparable<? super T> maxValue = null;
// Meaningful only if valueType == VALUE_LIST
int arrayMinLength = 0;
int arrayMaxLength = 0;
}
*** 270,280 ****
*/
private Element getElement(String elementName, boolean mustAppear) {
if (mustAppear && (elementName == null)) {
throw new IllegalArgumentException("element name is null!");
}
! Element element = (Element)elementMap.get(elementName);
if (mustAppear && (element == null)) {
throw new IllegalArgumentException("No such element: " +
elementName);
}
return element;
--- 271,281 ----
*/
private Element getElement(String elementName, boolean mustAppear) {
if (mustAppear && (elementName == null)) {
throw new IllegalArgumentException("element name is null!");
}
! Element element = elementMap.get(elementName);
if (mustAppear && (element == null)) {
throw new IllegalArgumentException("No such element: " +
elementName);
}
return element;
*** 285,295 ****
}
// Utility method for locating an attribute
private Attribute getAttribute(String elementName, String attrName) {
Element element = getElement(elementName);
! Attribute attr = (Attribute)element.attrMap.get(attrName);
if (attr == null) {
throw new IllegalArgumentException("No such attribute \"" +
attrName + "\"!");
}
return attr;
--- 286,296 ----
}
// Utility method for locating an attribute
private Attribute getAttribute(String elementName, String attrName) {
Element element = getElement(elementName);
! Attribute attr = element.attrMap.get(attrName);
if (attr == null) {
throw new IllegalArgumentException("No such attribute \"" +
attrName + "\"!");
}
return attr;
*** 406,418 ****
* @param elementName the name of the element to be removed.
*/
protected void removeElement(String elementName) {
Element element = getElement(elementName, false);
if (element != null) {
! Iterator iter = element.parentList.iterator();
while (iter.hasNext()) {
! String parentName = (String)iter.next();
Element parent = getElement(parentName, false);
if (parent != null) {
parent.childList.remove(elementName);
}
}
--- 407,419 ----
* @param elementName the name of the element to be removed.
*/
protected void removeElement(String elementName) {
Element element = getElement(elementName, false);
if (element != null) {
! Iterator<String> iter = element.parentList.iterator();
while (iter.hasNext()) {
! String parentName = iter.next();
Element parent = getElement(parentName, false);
if (parent != null) {
parent.childList.remove(elementName);
}
}
*** 512,522 ****
throw new IllegalArgumentException("enumeratedValues == null!");
}
if (enumeratedValues.size() == 0) {
throw new IllegalArgumentException("enumeratedValues is empty!");
}
! Iterator iter = enumeratedValues.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o == null) {
throw new IllegalArgumentException
("enumeratedValues contains a null!");
--- 513,523 ----
throw new IllegalArgumentException("enumeratedValues == null!");
}
if (enumeratedValues.size() == 0) {
throw new IllegalArgumentException("enumeratedValues is empty!");
}
! Iterator<String> iter = enumeratedValues.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o == null) {
throw new IllegalArgumentException
("enumeratedValues contains a null!");
*** 679,689 ****
*/
protected void addBooleanAttribute(String elementName,
String attrName,
boolean hasDefaultValue,
boolean defaultValue) {
! List values = new ArrayList();
values.add("TRUE");
values.add("FALSE");
String dval = null;
if (hasDefaultValue) {
--- 680,690 ----
*/
protected void addBooleanAttribute(String elementName,
String attrName,
boolean hasDefaultValue,
boolean defaultValue) {
! List<String> values = new ArrayList<>();
values.add("TRUE");
values.add("FALSE");
String dval = null;
if (hasDefaultValue) {
*** 738,748 ****
Class<T> classType,
boolean required,
T defaultValue)
{
Element element = getElement(elementName);
! ObjectValue obj = new ObjectValue();
obj.valueType = VALUE_ARBITRARY;
obj.classType = classType;
obj.defaultValue = defaultValue;
element.objectValue = obj;
--- 739,749 ----
Class<T> classType,
boolean required,
T defaultValue)
{
Element element = getElement(elementName);
! ObjectValue<T> obj = new ObjectValue<>();
obj.valueType = VALUE_ARBITRARY;
obj.classType = classType;
obj.defaultValue = defaultValue;
element.objectValue = obj;
*** 791,812 ****
throw new IllegalArgumentException("enumeratedValues == null!");
}
if (enumeratedValues.size() == 0) {
throw new IllegalArgumentException("enumeratedValues is empty!");
}
! Iterator iter = enumeratedValues.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o == null) {
throw new IllegalArgumentException("enumeratedValues contains a null!");
}
if (!classType.isInstance(o)) {
throw new IllegalArgumentException("enumeratedValues contains a value not of class classType!");
}
}
! ObjectValue obj = new ObjectValue();
obj.valueType = VALUE_ENUMERATION;
obj.classType = classType;
obj.defaultValue = defaultValue;
obj.enumeratedValues = enumeratedValues;
--- 792,813 ----
throw new IllegalArgumentException("enumeratedValues == null!");
}
if (enumeratedValues.size() == 0) {
throw new IllegalArgumentException("enumeratedValues is empty!");
}
! Iterator<? extends T> iter = enumeratedValues.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o == null) {
throw new IllegalArgumentException("enumeratedValues contains a null!");
}
if (!classType.isInstance(o)) {
throw new IllegalArgumentException("enumeratedValues contains a value not of class classType!");
}
}
! ObjectValue<T> obj = new ObjectValue<>();
obj.valueType = VALUE_ENUMERATION;
obj.classType = classType;
obj.defaultValue = defaultValue;
obj.enumeratedValues = enumeratedValues;
*** 852,862 ****
Comparable<? super T> maxValue,
boolean minInclusive,
boolean maxInclusive)
{
Element element = getElement(elementName);
! ObjectValue obj = new ObjectValue();
obj.valueType = VALUE_RANGE;
if (minInclusive) {
obj.valueType |= VALUE_RANGE_MIN_INCLUSIVE_MASK;
}
if (maxInclusive) {
--- 853,863 ----
Comparable<? super T> maxValue,
boolean minInclusive,
boolean maxInclusive)
{
Element element = getElement(elementName);
! ObjectValue<T> obj = new ObjectValue<>();
obj.valueType = VALUE_RANGE;
if (minInclusive) {
obj.valueType |= VALUE_RANGE_MIN_INCLUSIVE_MASK;
}
if (maxInclusive) {
*** 893,903 ****
protected void addObjectValue(String elementName,
Class<?> classType,
int arrayMinLength,
int arrayMaxLength) {
Element element = getElement(elementName);
! ObjectValue obj = new ObjectValue();
obj.valueType = VALUE_LIST;
obj.classType = classType;
obj.arrayMinLength = arrayMinLength;
obj.arrayMaxLength = arrayMaxLength;
--- 894,904 ----
protected void addObjectValue(String elementName,
Class<?> classType,
int arrayMinLength,
int arrayMaxLength) {
Element element = getElement(elementName);
! ObjectValue<Object> obj = new ObjectValue<>();
obj.valueType = VALUE_LIST;
obj.classType = classType;
obj.arrayMinLength = arrayMinLength;
obj.arrayMaxLength = arrayMaxLength;
*** 960,973 ****
* accessed via the applet class loader. So first try the context
* class loader to locate the resource bundle.
* If that throws MissingResourceException, then try the
* system class loader.
*/
! ClassLoader loader = (ClassLoader)
java.security.AccessController.doPrivileged(
! new java.security.PrivilegedAction() {
! public Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
ResourceBundle bundle = null;
--- 961,974 ----
* accessed via the applet class loader. So first try the context
* class loader to locate the resource bundle.
* If that throws MissingResourceException, then try the
* system class loader.
*/
! ClassLoader loader =
java.security.AccessController.doPrivileged(
! new java.security.PrivilegedAction<ClassLoader>() {
! public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});
ResourceBundle bundle = null;
*** 1035,1055 ****
public String[] getChildNames(String elementName) {
Element element = getElement(elementName);
if (element.childPolicy == CHILD_POLICY_EMPTY) {
return null;
}
! return (String[])element.childList.toArray(new String[0]);
}
// Attributes
public String[] getAttributeNames(String elementName) {
Element element = getElement(elementName);
! List names = element.attrList;
String[] result = new String[names.size()];
! return (String[])names.toArray(result);
}
public int getAttributeValueType(String elementName, String attrName) {
Attribute attr = getAttribute(elementName, attrName);
return attr.valueType;
--- 1036,1056 ----
public String[] getChildNames(String elementName) {
Element element = getElement(elementName);
if (element.childPolicy == CHILD_POLICY_EMPTY) {
return null;
}
! return element.childList.toArray(new String[0]);
}
// Attributes
public String[] getAttributeNames(String elementName) {
Element element = getElement(elementName);
! List<String> names = element.attrList;
String[] result = new String[names.size()];
! return names.toArray(result);
}
public int getAttributeValueType(String elementName, String attrName) {
Attribute attr = getAttribute(elementName, attrName);
return attr.valueType;
*** 1077,1090 ****
if (attr.valueType != VALUE_ENUMERATION) {
throw new IllegalArgumentException
("Attribute not an enumeration!");
}
! List values = attr.enumeratedValues;
! Iterator iter = values.iterator();
String[] result = new String[values.size()];
! return (String[])values.toArray(result);
}
public String getAttributeMinValue(String elementName, String attrName) {
Attribute attr = getAttribute(elementName, attrName);
if (attr.valueType != VALUE_RANGE &&
--- 1078,1090 ----
if (attr.valueType != VALUE_ENUMERATION) {
throw new IllegalArgumentException
("Attribute not an enumeration!");
}
! List<String> values = attr.enumeratedValues;
String[] result = new String[values.size()];
! return values.toArray(result);
}
public String getAttributeMinValue(String elementName, String attrName) {
Attribute attr = getAttribute(elementName, attrName);
if (attr.valueType != VALUE_RANGE &&
*** 1168,1251 ****
Locale locale) {
Element element = getElement(elementName);
if (attrName == null) {
throw new IllegalArgumentException("attrName == null!");
}
! Attribute attr = (Attribute)element.attrMap.get(attrName);
if (attr == null) {
throw new IllegalArgumentException("No such attribute!");
}
String key = elementName + "/" + attrName;
return getResource(key, locale);
}
! private ObjectValue getObjectValue(String elementName) {
Element element = getElement(elementName);
! ObjectValue objv = element.objectValue;
if (objv == null) {
throw new IllegalArgumentException("No object within element " +
elementName + "!");
}
return objv;
}
public int getObjectValueType(String elementName) {
Element element = getElement(elementName);
! ObjectValue objv = element.objectValue;
if (objv == null) {
return VALUE_NONE;
}
return objv.valueType;
}
public Class<?> getObjectClass(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
return objv.classType;
}
public Object getObjectDefaultValue(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
return objv.defaultValue;
}
public Object[] getObjectEnumerations(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
if (objv.valueType != VALUE_ENUMERATION) {
throw new IllegalArgumentException("Not an enumeration!");
}
! List vlist = objv.enumeratedValues;
Object[] values = new Object[vlist.size()];
return vlist.toArray(values);
}
public Comparable<?> getObjectMinValue(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
if ((objv.valueType & VALUE_RANGE) != VALUE_RANGE) {
throw new IllegalArgumentException("Not a range!");
}
return objv.minValue;
}
public Comparable<?> getObjectMaxValue(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
if ((objv.valueType & VALUE_RANGE) != VALUE_RANGE) {
throw new IllegalArgumentException("Not a range!");
}
return objv.maxValue;
}
public int getObjectArrayMinLength(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
if (objv.valueType != VALUE_LIST) {
throw new IllegalArgumentException("Not a list!");
}
return objv.arrayMinLength;
}
public int getObjectArrayMaxLength(String elementName) {
! ObjectValue objv = getObjectValue(elementName);
if (objv.valueType != VALUE_LIST) {
throw new IllegalArgumentException("Not a list!");
}
return objv.arrayMaxLength;
}
--- 1168,1251 ----
Locale locale) {
Element element = getElement(elementName);
if (attrName == null) {
throw new IllegalArgumentException("attrName == null!");
}
! Attribute attr = element.attrMap.get(attrName);
if (attr == null) {
throw new IllegalArgumentException("No such attribute!");
}
String key = elementName + "/" + attrName;
return getResource(key, locale);
}
! private ObjectValue<?> getObjectValue(String elementName) {
Element element = getElement(elementName);
! ObjectValue<?> objv = element.objectValue;
if (objv == null) {
throw new IllegalArgumentException("No object within element " +
elementName + "!");
}
return objv;
}
public int getObjectValueType(String elementName) {
Element element = getElement(elementName);
! ObjectValue<?> objv = element.objectValue;
if (objv == null) {
return VALUE_NONE;
}
return objv.valueType;
}
public Class<?> getObjectClass(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
return objv.classType;
}
public Object getObjectDefaultValue(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
return objv.defaultValue;
}
public Object[] getObjectEnumerations(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
if (objv.valueType != VALUE_ENUMERATION) {
throw new IllegalArgumentException("Not an enumeration!");
}
! List<?> vlist = objv.enumeratedValues;
Object[] values = new Object[vlist.size()];
return vlist.toArray(values);
}
public Comparable<?> getObjectMinValue(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
if ((objv.valueType & VALUE_RANGE) != VALUE_RANGE) {
throw new IllegalArgumentException("Not a range!");
}
return objv.minValue;
}
public Comparable<?> getObjectMaxValue(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
if ((objv.valueType & VALUE_RANGE) != VALUE_RANGE) {
throw new IllegalArgumentException("Not a range!");
}
return objv.maxValue;
}
public int getObjectArrayMinLength(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
if (objv.valueType != VALUE_LIST) {
throw new IllegalArgumentException("Not a list!");
}
return objv.arrayMinLength;
}
public int getObjectArrayMaxLength(String elementName) {
! ObjectValue<?> objv = getObjectValue(elementName);
if (objv.valueType != VALUE_LIST) {
throw new IllegalArgumentException("Not a list!");
}
return objv.arrayMaxLength;
}