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