예제 #1
0
 public double get(int col, int row) {
   if (row >= rows.size()) {
     return 0;
   } else {
     DoubleList cols = (DoubleList) rows.get(row);
     if (col >= cols.size()) return 0;
     else return cols.get(col);
   }
 }
 public void testSingletonDoubleList() {
   DoubleList list = DoubleCollections.singletonDoubleList((double) 17);
   assertEquals(1, list.size());
   assertEquals(17, list.get(0), (double) 0);
   try {
     list.add((double) 18);
     fail("Expected UnsupportedOperationException");
   } catch (UnsupportedOperationException e) {
     // expected
   }
 }
예제 #3
0
 /**
  * Constructs directional survey data from the specified file. The file is in Excel CSV
  * (comma-delimited) format.
  *
  * @param fileName file containing directional survey data.
  */
 public Data(String fileName) {
   try {
     FileInputStream fis = new FileInputStream(fileName);
     Scanner s = new Scanner(fis);
     long id = -1;
     DoubleList zl = new DoubleList();
     DoubleList tl = new DoubleList();
     DoubleList pl = new DoubleList();
     while (s.hasNextLine()) {
       String line = s.nextLine();
       String[] fields = line.split(",");
       if (fields.length < 4) continue;
       long idline = WellLog.idFromString(fields[0]);
       if (idline < 0) continue;
       if (id < 0) {
         id = idline;
       } else if (id != idline || !s.hasNextLine()) {
         DirectionalSurvey ds = new DirectionalSurvey();
         ds.id = id;
         ds.z = zl.trim();
         ds.t = tl.trim();
         ds.p = pl.trim();
         if (id == 490252304800L) { // Swap theta,phi for this survey!
           double[] temp = ds.t;
           ds.t = ds.p;
           ds.p = temp;
         }
         ds.n = ds.z.length;
         _data.put(id, ds);
         id = idline;
         zl = new DoubleList();
         tl = new DoubleList();
         pl = new DoubleList();
       }
       zl.add(Double.parseDouble(fields[1]));
       tl.add(Double.parseDouble(fields[2]));
       pl.add(Double.parseDouble(fields[3]));
     }
     s.close();
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
예제 #4
0
 private void resizeCols(int row, int col) {
   DoubleList cols = (DoubleList) rows.get(row);
   while (cols.size() <= col) cols.add(0);
 }
예제 #5
0
 public void set(int col, int row, double value) {
   resizeRows(row);
   resizeCols(row, col);
   DoubleList cols = (DoubleList) rows.get(row);
   cols.set(col, value);
 }