1 package org.djunits.value.storage;
2
3 import java.io.Serializable;
4
5 import org.djutils.exceptions.Throw;
6
7 /**
8 * StorageInterface.java.
9 * <p>
10 * Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
12 * </p>
13 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
14 * @param <T> the vector or matrix data type
15 */
16 public abstract class Storage<T extends Storage<T>> implements Cloneable, Serializable
17 {
18 /** ... */
19 private static final long serialVersionUID = 20191018L;
20
21 /** the data type. */
22 private final StorageType storageType;
23
24 /**
25 * Construct a new Data store.
26 * @param storageType StorageType; the data type
27 */
28 public Storage(final StorageType storageType)
29 {
30 Throw.whenNull(storageType, "storage type cannot be null");
31 this.storageType = storageType;
32 }
33
34 /**
35 * Return the StorageType (DENSE, SPARSE, etc.) for the stored indexed value.
36 * @return the StorageType (DENSE, SPARSE, etc.) for the stored indexed value
37 */
38 public final StorageType getStorageType()
39 {
40 return this.storageType;
41 }
42
43 /**
44 * Is this indexed value dense?
45 * @return boolean; true if the data storage type is dense; false if the data storage type is not dense
46 */
47 public final boolean isDense()
48 {
49 return this.storageType.equals(StorageType.DENSE);
50 }
51
52 /**
53 * Is this indexed value sparse?
54 * @return boolean; true if the data storage type is sparse; false if the data storage type is not sparse
55 */
56 public final boolean isSparse()
57 {
58 return this.storageType.equals(StorageType.SPARSE);
59 }
60
61 /**
62 * Compute and return the number of non-zero cells in this indexed value.
63 * @return int; the number of non-zero cells
64 */
65 public abstract int cardinality();
66
67 /**
68 * Create and return a deep copy of the data.
69 * @return T; a deep copy of the data
70 */
71 public abstract T copy();
72
73 }