package nl.tudelft.simulation.introspection; import java.lang.reflect.Array; import java.util.Collection; /** * A default Property implementation that provides a standard way to handle composite values. *
* Copyright (c) 2002-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *
* @author Peter Jacobs * @author Alexander Verbraeck * @author Niels Lang. * @since 1.5 */ public abstract class AbstractProperty implements Property { /** * Basic 'setValue' implementation. It is checked whether this property contains a composite value. If so, the * composite value of this property is updated. Composite values are expected to be supplied as a {see * java.util.Collection}. If needed, array conversion takes place. If the property is not composite, the * value-setting is delegated to the 'setRegularValue' method. * @see nl.tudelft.simulation.introspection.Property#setValue(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public void setValue(final Object value) { if (!this.isCollection()) { this.setRegularValue(value); return; } if (!(value instanceof Collection)) { throw new IllegalArgumentException(this + " - assign Collection values to composite properties"); } if (this.getType().isArray()) { Object[] array = (Object[]) Array.newInstance(getType().getComponentType(), 0); this.setRegularValue(((Collection>) value).toArray(array)); } else { synchronized (this.getInstance()) { Collection