package org.djunits.value.vfloat.vector; import java.util.List; import java.util.SortedMap; import javax.annotation.Generated; import org.djunits.Throw; import org.djunits.unit.*; import org.djunits.unit.si.SIDimensions; import org.djunits.unit.util.UnitRuntimeException; import org.djunits.value.ValueRuntimeException; import org.djunits.value.storage.StorageType; import org.djunits.value.vdouble.scalar.SIScalar; import org.djunits.value.vfloat.scalar.*; import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel; import org.djunits.value.vfloat.vector.*; import org.djunits.value.vfloat.vector.base.AbstractFloatVectorRel; import org.djunits.value.vfloat.vector.base.FloatVector; import org.djunits.value.vfloat.vector.data.FloatVectorData; /** * Easy access methods for the generic Relative SI FloatVector. *

* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.
* All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @author Alexander Verbraeck * @author Peter Knoppers */ @Generated(value = "GenerateDJUNIT") public class FloatSIVector extends AbstractFloatVectorRel { /** */ private static final long serialVersionUID = 20150901L; /** * Construct a new Relative Float SIVector. * @param values float[]; the values of the entries in the new Relative Float SIVector * @param unit SIUnit; the unit of the new Relative Float SIVector * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) * @return SIVector; the SIVector of the given unit * @throws ValueRuntimeException when values is null */ public static FloatSIVector instantiate(final float[] values, final SIUnit unit, final StorageType storageType) throws ValueRuntimeException { return new FloatSIVector(FloatVectorData.instantiate(values, unit.getScale(), storageType), unit); } /** * Construct a new Relative Float SIVector. * @param values List<Float>; the values of the entries in the new Relative Float SIVector * @param unit SIUnit; the unit of the new Relative Float SIVector * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) * @return SIVector; the SIVector of the given unit * @throws ValueRuntimeException when values is null */ public static FloatSIVector instantiate(final List values, final SIUnit unit, final StorageType storageType) throws ValueRuntimeException { return new FloatSIVector(FloatVectorData.instantiate(values, unit.getScale(), storageType), unit); } /** * Construct a new Relative Float SIVector. * @param values SortedMap<Integer, Float>; the map of indexes to values of the Relative Sparse Float SIVector * @param length int; the size of the vector * @param unit SIUnit; the unit of the new Relative Sparse Float SIVector * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) * @return SIVector; the SIVector of the given unit * @throws ValueRuntimeException when values is null */ public static FloatSIVector instantiate(final SortedMap values, final int length, final SIUnit unit, final StorageType storageType) throws ValueRuntimeException { return new FloatSIVector(FloatVectorData.instantiate(values, length, unit.getScale(), storageType), unit); } /** * @param data FloatVectorData; an internal data object * @param unit SIUnit; the unit */ public FloatSIVector(final FloatVectorData data, final SIUnit unit) { super(data, unit); } /** {@inheritDoc} */ @Override public Class getScalarClass() { return FloatSIScalar.class; } /** * Returns an SIVector based on an array of values and the textual representation of the unit. * @param value float[]; the values to use * @param unitString String; the textual representation of the unit * @param storageType StorageType; the storage type to use * @return SIVector; the vector representation of the values in their unit * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect * @throws NullPointerException when the unitString argument is null */ public static FloatSIVector of(final float[] value, final String unitString, final StorageType storageType) { Throw.whenNull(value, "Error parsing SIVector: value is null"); Throw.whenNull(unitString, "Error parsing SIVector: unitString is null"); Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSIVector: empty unitString"); Throw.whenNull(storageType, "Error parsing SIVector: storageType is null"); try { SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString)); if (unit != null) { return FloatSIVector.instantiate(value, unit, storageType); } } catch (Exception exception) { throw new IllegalArgumentException("Error parsing SIUnit from " + unitString, exception); } throw new IllegalArgumentException("Error parsing SIVector with unit " + unitString); } /** * Returns an SIVector based on an array of values and the textual representation of the unit. * @param valueList List<Float>; the values to use * @param unitString String; the textual representation of the unit * @param storageType StorageType; the storage type to use * @return SIVector; the vector representation of the values in their unit * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect * @throws NullPointerException when the unitString argument is null */ public static FloatSIVector of(final List valueList, final String unitString, final StorageType storageType) { Throw.whenNull(valueList, "Error parsing SIVector: valueList is null"); Throw.whenNull(unitString, "Error parsing SIVector: unitString is null"); Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSIVector: empty unitString"); Throw.whenNull(storageType, "Error parsing SIVector: storageType is null"); try { SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString)); if (unit != null) { return FloatSIVector.instantiate(valueList, unit, storageType); } } catch (Exception exception) { throw new IllegalArgumentException("Error parsing SIUnit from " + unitString, exception); } throw new IllegalArgumentException("Error parsing SIVector with unit " + unitString); } /** * Returns an SIVector based on a (sparse) map of values and the textual representation of the unit. * @param valueMap SortedMap<Integer, Float>; the values to use * @param unitString String; the textual representation of the unit * @param length int; the size of the vector * @param storageType StorageType; the storage type to use * @return SIVector; the vector representation of the values in their unit * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect * @throws NullPointerException when the unitString argument is null */ public static FloatSIVector of(final SortedMap valueMap, final String unitString, final int length, final StorageType storageType) { Throw.whenNull(valueMap, "Error parsing SIVector: valueMap is null"); Throw.whenNull(unitString, "Error parsing SIVector: unitString is null"); Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSIVector: empty unitString"); Throw.whenNull(storageType, "Error parsing SIVector: storageType is null"); try { SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString)); if (unit != null) { return FloatSIVector.instantiate(valueMap, length, unit, storageType); } } catch (Exception exception) { throw new IllegalArgumentException("Error parsing SIUnit from " + unitString, exception); } throw new IllegalArgumentException("Error parsing SIVector with unit " + unitString); } /** {@inheritDoc} */ @Override public FloatSIVector instantiateVector(final FloatVectorData fvd, final SIUnit unit) { return new FloatSIVector(fvd, unit); } /** {@inheritDoc} */ @Override public FloatSIScalar instantiateScalarSI(final float valueSI, final SIUnit unit) { return new FloatSIScalar(valueSI, unit); } /**********************************************************************************/ /******************************** 'CAST AS' METHODS *******************************/ /**********************************************************************************/ /** * Return the current vector transformed to a vector in the given unit. Of course the SI dimensionality has to match, * otherwise the vector cannot be transformed. The compiler will check the alignment between the return value and the unit. * @param displayUnit KU; the unit in which the vector needs to be expressed * @return V; the vector that has been transformed into the right vector type and unit * @param the unit type * @param the scalar type * @param the vector type */ public final , S extends AbstractFloatScalarRel, V extends AbstractFloatVectorRel> V as(final U displayUnit) { Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(displayUnit.getQuantity().getSiDimensions())), UnitRuntimeException.class, "SIVector with unit %s cannot be converted to a FloatVector with unit %s", getDisplayUnit(), displayUnit); V result = FloatVector.instantiate(this.data, displayUnit.getStandardUnit()); result.setDisplayUnit(displayUnit); return result; } %%ASMETHODS%% }