1 package org.djunits.value.vfloat.vector; 2 3 import java.util.List; 4 import java.util.SortedMap; 5 6 import org.djunits.unit.LengthUnit; 7 import org.djunits.value.StorageType; 8 import org.djunits.value.ValueException; 9 import org.djunits.value.vfloat.scalar.FloatLength; 10 11 /** 12 * Relative FloatLength Vector. 13 * <p> 14 * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 15 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>. 16 * <p> 17 * $LastChangedDate: 2015-09-29 14:14:28 +0200 (Tue, 29 Sep 2015) $, @version $Revision: 73 $, by $Author: pknoppers $, initial 18 * version Sep 5, 2015 <br> 19 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 20 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 21 */ 22 public class FloatLengthVector 23 extends AbstractFloatVectorRel<LengthUnit, FloatLengthVector, MutableFloatLengthVector, FloatLength> 24 { 25 /** */ 26 private static final long serialVersionUID = 20151006L; 27 28 /** 29 * Construct a new Relative Immutable FloatLengthVector. 30 * @param values float[]; the values of the entries in the new Relative Immutable FloatLengthVector 31 * @param unit LengthUnit; the unit of the new Relative Immutable FloatLengthVector 32 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 33 * @throws ValueException when values is null 34 */ 35 public FloatLengthVector(final float[] values, final LengthUnit unit, final StorageType storageType) throws ValueException 36 { 37 super(values, unit, storageType); 38 } 39 40 /** 41 * Construct a new Relative Immutable FloatLengthVector. 42 * @param values List<Float>; the values of the entries in the new Relative Immutable FloatLengthVector 43 * @param unit LengthUnit; the unit of the new Relative Immutable FloatLengthVector 44 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 45 * @throws ValueException when values is null 46 */ 47 public FloatLengthVector(final List<Float> values, final LengthUnit unit, final StorageType storageType) 48 throws ValueException 49 { 50 super(values, unit, storageType); 51 } 52 53 /** 54 * Construct a new Relative Immutable FloatLengthVector. 55 * @param values FloatLength[]; the values of the entries in the new Relative Immutable FloatLengthVector 56 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 57 * @throws ValueException when values has zero entries 58 */ 59 public FloatLengthVector(final FloatLength[] values, final StorageType storageType) throws ValueException 60 { 61 super(values, storageType); 62 } 63 64 /** 65 * Construct a new Relative Immutable FloatLengthVector. 66 * @param values List<FloatLength>; the values of the entries in the new Relative Immutable FloatLengthVector 67 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 68 * @throws ValueException when values has zero entries 69 */ 70 public FloatLengthVector(final List<FloatLength> values, final StorageType storageType) throws ValueException 71 { 72 super(values, storageType); 73 } 74 75 /** 76 * Construct a new Relative Immutable FloatLengthVector. 77 * @param values SortedMap<Integer, FloatLength>; the values of the entries in the new Relative Sparse Mutable 78 * FloatLengthVector 79 * @param length int; the size of the vector 80 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 81 * @throws ValueException when values has zero entries 82 */ 83 public FloatLengthVector(final SortedMap<Integer, FloatLength> values, final int length, final StorageType storageType) 84 throws ValueException 85 { 86 super(values, length, storageType); 87 } 88 89 /** 90 * Construct a new Relative Immutable FloatLengthVector. 91 * @param values SortedMap<Integer, Float>; the map of indexes to values of the Relative Sparse Mutable 92 * FloatLengthVector 93 * @param unit LengthUnit; the unit of the new Relative Sparse Mutable FloatLengthVector 94 * @param length int; the size of the vector 95 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 96 * @throws ValueException when values is null 97 */ 98 public FloatLengthVector(final SortedMap<Integer, Float> values, final LengthUnit unit, final int length, 99 final StorageType storageType) throws ValueException 100 { 101 super(values, unit, length, storageType); 102 } 103 104 /** 105 * Construct a new Relative Immutable FloatLengthVector. 106 * @param data FloatVectorData; an internal data object 107 * @param unit LengthUnit; the unit 108 */ 109 FloatLengthVector(final FloatVectorData data, final LengthUnit unit) 110 { 111 super(data, unit); 112 } 113 114 /** {@inheritDoc} */ 115 @Override 116 protected final FloatLengthVector instantiateType(final FloatVectorData dvd, final LengthUnit unit) 117 { 118 return new FloatLengthVector(dvd, unit); 119 } 120 121 /** {@inheritDoc} */ 122 @Override 123 protected final MutableFloatLengthVector instantiateMutableType(final FloatVectorData dvd, final LengthUnit unit) 124 { 125 return new MutableFloatLengthVector(dvd, unit); 126 } 127 128 /** {@inheritDoc} */ 129 @Override 130 protected final FloatLength instantiateScalar(final float value, final LengthUnit unit) 131 { 132 return new FloatLength(value, unit); 133 } 134 135 /** {@inheritDoc} */ 136 @Override 137 public final FloatLengthVector toDense() 138 { 139 return this.data.isDense() ? (FloatLengthVector) this : instantiateType(this.data.toDense(), getUnit()); 140 } 141 142 /** {@inheritDoc} */ 143 @Override 144 public final FloatLengthVector toSparse() 145 { 146 return this.data.isSparse() ? (FloatLengthVector) this : instantiateType(this.data.toSparse(), getUnit()); 147 } 148 149 /** 150 * Return an array of FloatLength Scalars from this vector. 151 * @return FloatLength[]; an array of FloatLength Scalars from this vector 152 * @throws RuntimeException wrapping a ValueException on error getting one of the values 153 */ 154 public FloatLength[] toArray() 155 { 156 FloatLength[] array = new FloatLength[size()]; 157 for (int i = 0; i < size(); i++) 158 { 159 try 160 { 161 array[i] = get(i); 162 } 163 catch (ValueException exception) 164 { 165 throw new RuntimeException(exception); 166 } 167 } 168 return array; 169 } 170 171 }