SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
AbstractDataReader.java
1/*
2 * Class: AbstractDataReader
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author David Munger
9 * @since August 2009
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.util.io;
26
27import java.io.IOException;
28import java.util.Map;
29import java.util.HashMap;
30
36public abstract class AbstractDataReader implements DataReader {
37
41
45 public String readString(String label) throws IOException {
46 return readField(label).asString();
47 }
48
52 public int readInt(String label) throws IOException {
53 return readField(label).asInt();
54 }
55
59 public float readFloat(String label) throws IOException {
60 return readField(label).asFloat();
61 }
62
66 public double readDouble(String label) throws IOException {
67 return readField(label).asDouble();
68 }
69
73
77
82 public String[] readStringArray(String label) throws IOException {
83 return readField(label).asStringArray();
84 }
85
90 public int[] readIntArray(String label) throws IOException {
91 return readField(label).asIntArray();
92 }
93
98 public float[] readFloatArray(String label) throws IOException {
99 return readField(label).asFloatArray();
100 }
101
106 public double[] readDoubleArray(String label) throws IOException {
107 return readField(label).asDoubleArray();
108 }
109
113
117
122 public String[][] readStringArray2D(String label) throws IOException {
123 return readField(label).asStringArray2D();
124 }
125
130 public int[][] readIntArray2D(String label) throws IOException {
131 return readField(label).asIntArray2D();
132 }
133
138 public float[][] readFloatArray2D(String label) throws IOException {
139 return readField(label).asFloatArray2D();
140 }
141
146 public double[][] readDoubleArray2D(String label) throws IOException {
147 return readField(label).asDoubleArray2D();
148 }
149
153
157
163 public Map<String, DataField> readAllNextFields() throws IOException {
164
165 HashMap<String, DataField> fields = new HashMap<String, DataField>();
166
167 int iAnonymous = 0;
168
169 while (dataPending()) {
170
171 DataField data = readNextField();
172
173 String key = data.getLabel();
174 if (key == null)
175 key = String.format("_data%02d_", ++iAnonymous);
176 fields.put(key, data);
177
178 }
179
180 return fields;
181 }
182
188 public Map<String, DataField> readAllFields() throws IOException {
189 reset();
190 return readAllNextFields();
191 }
192
193}
194
This abstract class implements shared functionality for data readers.
float[] readFloatArray(String label)
Reads first field labeled as label and returns its value as a one-dimensional array of float’s.
double[][] readDoubleArray2D(String label)
Reads first field labeled as label and returns its value as a two-dimensional array of double’s.
Map< String, DataField > readAllNextFields()
Reads all remaining fields in the file and returns a hashmap indexed by field labels.
double readDouble(String label)
Reads first field labeled as label and returns its double value.
float[][] readFloatArray2D(String label)
Reads first field labeled as label and returns its value as a two-dimensional array of float’s.
float readFloat(String label)
Reads first field labeled as label and returns its float value.
double[] readDoubleArray(String label)
Reads first field labeled as label and returns its value as a one-dimensional array of double’s.
String[][] readStringArray2D(String label)
Reads first field labeled as label and returns its value as a two-dimensional array of String’s.
String[] readStringArray(String label)
Reads first field labeled as label and returns its value as a one-dimensional array of String’s.
int[] readIntArray(String label)
Reads first field labeled as label and returns its value as a one-dimensional array of int’s.
String readString(String label)
Reads first field labeled as label and returns its String value.
int readInt(String label)
Reads first field labeled as label and returns its int value.
int[][] readIntArray2D(String label)
Reads first field labeled as label and returns its value as a two-dimensional array of int’s.
Map< String, DataField > readAllFields()
Reads all fields in the file and returns a hashmap indexed by field labels.
This class represents a data field from a file read by an instance of a class implementing DataReader...
String getLabel()
Returns the field label (or name).
double[][] asDoubleArray2D()
Returns the value as two-dimensional double array or null if it is not of type double[][].
int[] asIntArray()
Returns the value as one-dimensional int array or null if it is not of type int[].
double asDouble()
Returns the value as double or 0 if it is not of type double See isDouble.
String asString()
Returns the value as String, or null if it is not of type String.
double[] asDoubleArray()
Returns the value as one-dimensional double array or null if it is not of type double[].
float asFloat()
Returns the value as float or 0 if it is not of type float See isFloat.
String[] asStringArray()
Returns the value as one-dimensional String array or null if it is not of type String[].
float[][] asFloatArray2D()
Returns the value as two-dimensional float array or null if it is not of type float[][].
int[][] asIntArray2D()
Returns the value as two-dimensional int array or null if it is not of type int[][].
int asInt()
Returns the value as int or 0 if it is not of type int See isInt.
String[][] asStringArray2D()
Returns the value as two-dimensional String array or null if it is not of type String[][].
float[] asFloatArray()
Returns the value as one-dimensional float array or null if it is not of type float[].
DataField readNextField()
Reads the next available field.
boolean dataPending()
Returns true if there remains data to be read.
void reset()
Resets the reader to its initial state, i.e.
DataField readField(String label)
Reads the first field labeled as label.