1 /*
2 * Copyright 2010 Ange Optimization ApS
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package eu.simuline.octave.type;
17
18 import eu.simuline.octave.type.matrix.AbstractGenericMatrix;
19
20 import it.unimi.dsi.fastutil.longs.LongArrayList;
21
22 /**
23 * Represents a matrix of ints.
24 */
25 public final class OctaveLong
26 extends AbstractGenericMatrix<long[], LongArrayList> {
27
28 /**
29 * Create new matrix.
30 *
31 * @param size
32 */
33 // used by reader
34 public OctaveLong(final int... size) {
35 super(size);
36 }
37
38 /**
39 * Constructor that reuses the input data.
40 *
41 * @param data
42 * @param size
43 */
44 // used by shallowCopy, end user, tests
45 public OctaveLong(final long[] data, final int... size) {
46 super(data, size);
47 }
48
49 // superfluous?
50 /**
51 * Copy constructor.
52 *
53 * @param o
54 */
55 public OctaveLongctaveLong.html#OctaveLong">OctaveLong(final OctaveLong o) {
56 super(o);
57 }
58
59
60
61 protected final LongArrayList newL(final int size) {
62 LongArrayList list = new LongArrayList(size);
63 list.size(size);
64 return list;
65 }
66
67 protected final int initL(long[] data, final int size) {
68 this.dataL = new LongArrayList(data);
69 this.dataL.size(size);
70 return data.length;
71 }
72
73 protected long[] getDataA() {
74 return this.dataL.elements();
75 }
76
77 /**
78 * Set the value resizing by need.
79 *
80 * @param value
81 * @param pos
82 * @see #setPlain(long, int)
83 */
84 public final void set(final long value, final int... pos) {
85 resizeUp(pos);
86 setPlain(value, pos2ind(pos));
87 }
88
89 /**
90 * Set the value assuming resize is not necessary.
91 *
92 * @param value
93 * @param pos
94 * @see #set(long, int[])
95 */
96 public final void setPlain(final long value, final int pos) {
97 this.dataL.set(pos, value);
98 }
99
100 // api-docs inherited from AbstractGenericMatrix
101 public final void setPlain(final String value, final int pos) {
102 this.dataL.set(pos, Long.parseLong(value.trim()));
103 }
104
105 /**
106 * Get the value.
107 *
108 * @param pos
109 * @return value at pos
110 */
111 public final long get(final int... pos) {
112 return this.dataL.getLong(pos2ind(pos));
113 }
114
115 // api-docs inherited from AbstractGenericMatrix
116 public final String getPlainString(int pos) {
117 return Long.toString(this.dataL.getLong(pos));
118 }
119
120
121
122 @Override
123 public OctaveLong shallowCopy() {
124 return new OctaveLong(this);
125 }
126
127 }