/** * Goes through the children, and searches for a duplicator 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 src The object to be duplicated. * * @return A deep copy of the original object. * * @throws IllegalAttributeException For any attribute errors. * @throws IllegalArgumentException If the object could not be duplicated. */ public Object duplicate(Object src) throws IllegalAttributeException { for (int i = 0; i < children.length; i++) { try { return children[i].duplicate(src); } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be duplicated :("); }
/** * Goes through the children, and searches for a duplicator 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 src The object to be duplicated. * * @return A deep copy of the original object. * * @throws IllegalAttributeException For any attribute errors. * @throws IllegalArgumentException If the object could not be duplicated. */ public Object duplicate(Object src) throws IllegalAttributeException { for (int i = 0; i < children.length; i++) { try { return children[i].duplicate(src); } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be duplicated :("); }
public Object duplicate(Object src) throws IllegalAttributeException { if(src instanceof List){ List in,out; in = (List)src; out = new LinkedList(); if(in.size() == children.length){ for(int i=0;i<children.length;i++){ out.add(i, children[i].duplicate(in.get(i))); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.size()+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
public Object duplicate(Object src) throws IllegalAttributeException { if(src instanceof List){ List in,out; in = (List)src; out = new LinkedList(); if(in.size() == children.length){ for(int i=0;i<children.length;i++){ out.add(i, children[i].duplicate(in.get(i))); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.size()+" 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 duplicate(Object src) throws IllegalAttributeException { if(src instanceof Set){ Object[] in; in = ((Set)src).toArray(); Set out = new HashSet(in.length); if(in.length == children.length){ for(int i=0;i<children.length;i++){ out.add( children[i].duplicate(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 duplicate(Object src) throws IllegalAttributeException { if(src instanceof Set){ Object[] in; in = ((Set)src).toArray(); Set out = new HashSet(in.length); if(in.length == children.length){ for(int i=0;i<children.length;i++){ out.add( children[i].duplicate(in[i])); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * @see org.geotools.data.FeatureReader#next() */ public Feature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IOException("FeatureReader has been closed"); } Feature next = reader.next(); String id = next.getID(); Object[] attributes = new Object[types.length]; String xpath; for (int i = 0; i < types.length; i++) { xpath = types[i].getName(); if(clone) attributes[i] = types[i].duplicate(next.getAttribute(xpath)); else attributes[i] = next.getAttribute(xpath); } return featureType.create(attributes, id); }
public Feature duplicate(Feature original) throws IllegalAttributeException{ if( original == null ) return null; FeatureType featureType = original.getFeatureType(); if (!featureType.equals(this)) { throw new IllegalAttributeException("Feature type " + featureType + " does not match " + this); } String id = original.getID(); int numAtts = featureType.getAttributeCount(); Object attributes[] = new Object[numAtts]; for (int i = 0; i < numAtts; i++) { AttributeType curAttType = getAttributeType(i); attributes[i] = curAttType.duplicate(original.getAttribute(i)); } return featureType.create(attributes, id ); } /**
/** * Creates duplicate of feature adjusted to the provided featureType. * * @param featureType FeatureType requested * @param feature Origional Feature from DataStore * * @return An instance of featureType based on feature * * @throws IllegalAttributeException If opperation could not be performed */ public static Feature reType(FeatureType featureType, Feature feature) throws IllegalAttributeException { FeatureType origional = feature.getFeatureType(); if (featureType.equals(origional)) { return featureType.duplicate(feature); } String id = feature.getID(); int numAtts = featureType.getAttributeCount(); Object[] attributes = new Object[numAtts]; String xpath; for (int i = 0; i < numAtts; i++) { AttributeType curAttType = featureType.getAttributeType(i); xpath = curAttType.getName(); attributes[i] = curAttType.duplicate(feature.getAttribute(xpath)); } return featureType.create(attributes, id); }