1 package org.djunits.value.vfloat.vector; 2 3 import java.util.List; 4 import java.util.SortedMap; 5 6 import org.djunits.unit.ElectricalPotentialUnit; 7 import org.djunits.value.StorageType; 8 import org.djunits.value.ValueException; 9 import org.djunits.value.vfloat.scalar.FloatElectricalPotential; 10 11 /** 12 * Immutable Float FloatElectricalPotentialVector, a vector of values with a ElectricalPotentialUnit. 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 FloatElectricalPotentialVector extends AbstractFloatVectorRel<ElectricalPotentialUnit, 23 FloatElectricalPotentialVector, MutableFloatElectricalPotentialVector, FloatElectricalPotential> 24 { 25 /** */ 26 private static final long serialVersionUID = 20151109L; 27 28 /** 29 * Construct a new Relative Immutable Float FloatElectricalPotentialVector. 30 * @param values float[]; the values of the entries in the new Relative Immutable Float FloatElectricalPotentialVector 31 * @param unit ElectricalPotentialUnit; the unit of the new Relative Immutable Float FloatElectricalPotentialVector 32 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 33 * @throws ValueException when values is null 34 */ 35 public FloatElectricalPotentialVector(final float[] values, final ElectricalPotentialUnit unit, 36 final StorageType storageType) throws ValueException 37 { 38 super(values, unit, storageType); 39 } 40 41 /** 42 * Construct a new Relative Immutable Float FloatElectricalPotentialVector. 43 * @param values List<Float>; the values of the entries in the new Relative Immutable Float 44 * FloatElectricalPotentialVector 45 * @param unit ElectricalPotentialUnit; the unit of the new Relative Immutable Float FloatElectricalPotentialVector 46 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 47 * @throws ValueException when values is null 48 */ 49 public FloatElectricalPotentialVector(final List<Float> values, final ElectricalPotentialUnit unit, 50 final StorageType storageType) throws ValueException 51 { 52 super(values, unit, storageType); 53 } 54 55 /** 56 * Construct a new Relative Immutable Float FloatElectricalPotentialVector. 57 * @param values FloatElectricalPotential[]; the values of the entries in the new Relative Immutable Float 58 * FloatElectricalPotentialVector 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 FloatElectricalPotentialVector(final FloatElectricalPotential[] values, final StorageType storageType) 63 throws ValueException 64 { 65 super(values, storageType); 66 } 67 68 /** 69 * Construct a new Relative Immutable Float FloatElectricalPotentialVector. 70 * @param values List<FloatElectricalPotential>; the values of the entries in the new Relative Immutable Float 71 * FloatElectricalPotentialVector 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 FloatElectricalPotentialVector(final List<FloatElectricalPotential> values, final StorageType storageType) 76 throws ValueException 77 { 78 super(values, storageType); 79 } 80 81 /** 82 * Construct a new Relative Immutable Float FloatElectricalPotentialVector. 83 * @param values SortedMap<Integer, FloatElectricalPotential>; the values of the entries in the new Relative Sparse 84 * Mutable Float FloatElectricalPotentialVector 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 FloatElectricalPotentialVector(final SortedMap<Integer, FloatElectricalPotential> 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 FloatElectricalPotentialVector. 97 * @param values SortedMap<Integer, Float>; the map of indexes to values of the Relative Sparse Mutable Float 98 * FloatElectricalPotentialVector 99 * @param unit ElectricalPotentialUnit; the unit of the new Relative Sparse Mutable Float FloatElectricalPotentialVector 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 FloatElectricalPotentialVector(final SortedMap<Integer, Float> values, final ElectricalPotentialUnit 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 ElectricalPotentialUnit; the unit 113 */ 114 FloatElectricalPotentialVector(final FloatVectorData data, final ElectricalPotentialUnit unit) 115 { 116 super(data, unit); 117 } 118 119 /** {@inheritDoc} */ 120 @Override 121 protected final FloatElectricalPotentialVector instantiateType(final FloatVectorData dvd, 122 final ElectricalPotentialUnit unit) 123 { 124 return new FloatElectricalPotentialVector(dvd, unit); 125 } 126 127 /** {@inheritDoc} */ 128 @Override 129 protected final MutableFloatElectricalPotentialVector instantiateMutableType(final FloatVectorData dvd, 130 final ElectricalPotentialUnit unit) 131 { 132 return new MutableFloatElectricalPotentialVector(dvd, unit); 133 } 134 135 /** {@inheritDoc} */ 136 @Override 137 protected final FloatElectricalPotential instantiateScalar(final float value, final ElectricalPotentialUnit unit) 138 { 139 return new FloatElectricalPotential(value, unit); 140 } 141 142 /** {@inheritDoc} */ 143 @Override 144 public final FloatElectricalPotentialVector toDense() 145 { 146 return this.data.isDense() ? (FloatElectricalPotentialVector) this : instantiateType(this.data.toDense(), getUnit()); 147 } 148 149 /** {@inheritDoc} */ 150 @Override 151 public final FloatElectricalPotentialVector toSparse() 152 { 153 return this.data.isSparse() ? (FloatElectricalPotentialVector) this : instantiateType(this.data.toSparse(), getUnit()); 154 } 155 156 /** 157 * Return an array of FloatElectricalPotential Scalars from this vector. 158 * @return FloatElectricalPotential[]; an array of FloatElectricalPotential Scalars from this vector 159 * @throws RuntimeException wrapping a ValueException on error getting one of the values 160 */ 161 public FloatElectricalPotential[] toArray() 162 { 163 FloatElectricalPotential[] array = new FloatElectricalPotential[size()]; 164 for (int i = 0; i < size(); i++) 165 { 166 try 167 { 168 array[i] = get(i); 169 } 170 catch (ValueException exception) 171 { 172 throw new RuntimeException(exception); 173 } 174 } 175 return array; 176 } 177 178 }