/** * Goes through the children, and searches for a parser that works. This * method searches in the order in which the children are specified ... * please keep this in mind when creating these objects if you care about * precedence. * * @param value The object to parse. * * @return The object parsed into the appropriate form for the Attribute. * * @throws IllegalArgumentException If the object could not be parsed by * any of the child attribute Types. */ public Object parse(Object value) throws IllegalArgumentException { for (int i = 0; i < children.length; i++) { try { return children[i].parse(value); } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be parsed :("); }
public Object parse(Object value) throws IllegalArgumentException { if(value instanceof Object[]){ Object[] in, out; in = (Object[])value; out = new Object[in.length]; if(in.length == children.length){ for(int i=0;i<children.length;i++){ out[i] = children[i].parse(in[i]); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
public Object parse(Object value) throws IllegalArgumentException { if(value instanceof Object[]){ Object[] in, out; in = (Object[])value; out = new Object[in.length]; if(in.length == children.length){ for(int i=0;i<children.length;i++){ out[i] = children[i].parse(in[i]); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * Goes through the children, and searches for a parser that works. This * method searches in the order in which the children are specified ... * please keep this in mind when creating these objects if you care about * precedence. * * @param value The object to parse. * * @return The object parsed into the appropriate form for the Attribute. * * @throws IllegalArgumentException If the object could not be parsed by * any of the child attribute Types. */ public Object parse(Object value) throws IllegalArgumentException { for (int i = 0; i < children.length; i++) { try { return children[i].parse(value); } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be parsed :("); }
/** * This method is unstable ... and does not yet check validity well. * TODO make this method robust * * This method assumes the Objects are in the order of the attributes. * In the future, this should be implemented with a bubble sort type * algorithm for testing each object vs each child. Bubble sort is * recommended as the sample size is typically less than 25 elements, * and the operation takes O(n*n) time. */ public Object parse(Object value) throws IllegalArgumentException { if(value instanceof Set){ Object[] in; in = ((Set)value).toArray(); Set out = new HashSet(in.length); if(in.length == children.length){ for(int i=0;i<children.length;i++){ out.add(children[i].parse(in[i])); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * This method is unstable ... and does not yet check validity well. * TODO make this method robust * * This method assumes the Objects are in the order of the attributes. * In the future, this should be implemented with a bubble sort type * algorithm for testing each object vs each child. Bubble sort is * recommended as the sample size is typically less than 25 elements, * and the operation takes O(n*n) time. */ public Object parse(Object value) throws IllegalArgumentException { if(value instanceof Set){ Object[] in; in = ((Set)value).toArray(); Set out = new HashSet(in.length); if(in.length == children.length){ for(int i=0;i<children.length;i++){ out.add(children[i].parse(in[i])); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * DOCUMENT ME! * * @param type DOCUMENT ME! * @param fid DOCUMENT ME! * @param text DOCUMENT ME! * * @return DOCUMENT ME! * * @throws IllegalAttributeException DOCUMENT ME! */ public static Feature parse(FeatureType type, String fid, String[] text) throws IllegalAttributeException { Object[] attributes = new Object[text.length]; for (int i = 0; i < text.length; i++) { attributes[i] = type.getAttributeType(i).parse(text[i]); } return type.create(attributes, fid); }
value = attType.parse(stringValue);
/** * Sets the attribute at position to val. * * @param position the index of the attribute to set. * @param val the new value to give the attribute at position. * * @throws IllegalAttributeException if the passed in val does not validate * against the AttributeType at that position. */ public void setAttribute(int position, Object val) throws IllegalAttributeException { AttributeType type = schema.getAttributeType(position); try { if ((val == null) && !type.isNillable()) val = type.createDefaultValue(); Object parsed = type.parse(val); type.validate(parsed); setAttributeValue(position, parsed); } catch (IllegalArgumentException iae) { throw new IllegalAttributeException(type, val, iae); } }
Object parsed = type.parse(val); type.validate(parsed); setAttributeValue(index, wrapInList(parsed));
Object parsed = type.parse(val); type.validate(parsed); super.setAttribute(index, wrapInList(parsed));