Search in sources :

Example 1 with Cloner

use of org.apache.sis.internal.util.Cloner in project sis by apache.

the class SparseFeature method clone.

/**
 * Returns a copy of this feature
 * This method clones also all {@linkplain Cloneable cloneable} property instances in this feature,
 * but not necessarily property values. Whether the property values are cloned or not (i.e. whether
 * the clone operation is <cite>deep</cite> or <cite>shallow</cite>) depends on the behavior or
 * property {@code clone()} methods.
 *
 * @return a clone of this attribute.
 * @throws CloneNotSupportedException if this feature can not be cloned, typically because
 *         {@code clone()} on a property instance failed.
 */
@Override
@SuppressWarnings("unchecked")
public SparseFeature clone() throws CloneNotSupportedException {
    final SparseFeature clone = (SparseFeature) super.clone();
    clone.properties = (HashMap<Integer, Object>) clone.properties.clone();
    switch(clone.valuesKind) {
        default:
            throw new AssertionError(clone.valuesKind);
        case CORRUPTED:
            throw new CorruptedObjectException(clone.getName());
        // Nothing to do.
        case VALUES:
            break;
        case PROPERTIES:
            {
                final Cloner cloner = new Cloner();
                for (final Map.Entry<Integer, Object> entry : clone.properties.entrySet()) {
                    final Property property = (Property) entry.getValue();
                    if (property instanceof Cloneable) {
                        entry.setValue(cloner.clone(property));
                    }
                }
                break;
            }
    }
    return clone;
}
Also used : CorruptedObjectException(org.apache.sis.util.CorruptedObjectException) Cloner(org.apache.sis.internal.util.Cloner)

Example 2 with Cloner

use of org.apache.sis.internal.util.Cloner in project sis by apache.

the class CharacteristicMap method clone.

/**
 * Returns a copy of this map. Characteristics are also cloned.
 *
 * @return a copy of this map.
 */
@Override
public CharacteristicMap clone() throws CloneNotSupportedException {
    final CharacteristicMap clone = (CharacteristicMap) super.clone();
    AbstractAttribute<?>[] c = clone.characterizedBy;
    if (c != null) {
        clone.characterizedBy = c = c.clone();
        final Cloner cloner = new Cloner();
        for (int i = 0; i < c.length; i++) {
            final AbstractAttribute<?> attribute = c[i];
            if (attribute instanceof Cloneable) {
                c[i] = (AbstractAttribute<?>) cloner.clone(attribute);
            }
        }
    }
    return clone;
}
Also used : Cloner(org.apache.sis.internal.util.Cloner)

Example 3 with Cloner

use of org.apache.sis.internal.util.Cloner in project sis by apache.

the class DenseFeature method clone.

/**
 * Returns a copy of this feature
 * This method clones also all {@linkplain Cloneable cloneable} property instances in this feature,
 * but not necessarily property values. Whether the property values are cloned or not (i.e. whether
 * the clone operation is <cite>deep</cite> or <cite>shallow</cite>) depends on the behavior or
 * property {@code clone()} methods.
 *
 * @return a clone of this attribute.
 * @throws CloneNotSupportedException if this feature can not be cloned, typically because
 *         {@code clone()} on a property instance failed.
 */
@Override
public DenseFeature clone() throws CloneNotSupportedException {
    final DenseFeature clone = (DenseFeature) super.clone();
    clone.properties = clone.properties.clone();
    if (clone.properties instanceof Property[]) {
        final Property[] p = (Property[]) clone.properties;
        final Cloner cloner = new Cloner();
        for (int i = 0; i < p.length; i++) {
            final Property property = p[i];
            if (property instanceof Cloneable) {
                p[i] = (Property) cloner.clone(property);
            }
        }
    }
    return clone;
}
Also used : Cloner(org.apache.sis.internal.util.Cloner)

Aggregations

Cloner (org.apache.sis.internal.util.Cloner)3 CorruptedObjectException (org.apache.sis.util.CorruptedObjectException)1