예제 #1
0
  @Test
  public void testNullOperations() throws Exception {
    Value nullv = ValueFactory.createNullValue();
    Value numv = ValueFactory.createValue(4d);
    Value strv = ValueFactory.createValue("s");
    Value falsev = numv.less(numv);
    Value truev = numv.equals(numv);

    assertTrue(nullv.multiply(numv).isNull());
    assertTrue(numv.multiply(nullv).isNull());
    assertTrue(nullv.sum(numv).isNull());
    assertTrue(numv.sum(nullv).isNull());

    assertTrue(strv.matches(nullv).isNull());
    assertTrue(nullv.matches(strv).isNull());
    assertTrue(falsev.or(nullv).isNull());
    assertTrue(nullv.or(falsev).isNull());
    assertTrue(truev.and(nullv).isNull());
    assertTrue(nullv.and(truev).isNull());
    assertTrue(numv.greaterEqual(nullv).isNull());
    assertTrue(numv.equals(nullv).isNull());
    assertTrue(numv.notEquals(nullv).isNull());
    assertTrue(numv.less(nullv).isNull());
    assertTrue(numv.lessEqual(nullv).isNull());
    assertTrue(nullv.greaterEqual(numv).isNull());
    assertTrue(nullv.equals(numv).isNull());
    assertTrue(nullv.notEquals(numv).isNull());
    assertTrue(nullv.less(numv).isNull());
    assertTrue(nullv.lessEqual(numv).isNull());
  }
예제 #2
0
  private GeoRaster checkRasterMetadataIO(GeoRaster grSource) {
    Value v = ValueFactory.createValue(grSource);
    Value v2 = ValueFactory.createValue(v.getType(), v.getBytes());
    GeoRaster gr = v2.getAsRaster();
    assertEquals(gr.getMetadata(), grSource.getMetadata());

    return gr;
  }
예제 #3
0
 @Test
 public void testValueCollectionConversion() throws Exception {
   Value value =
       ValueFactory.createValue(
           new Value[] {ValueFactory.createValue(2d), ValueFactory.createValue("hello")});
   Set<Integer> set = new HashSet<Integer>();
   set.add(13);
   checkConversions(value, set);
 }
예제 #4
0
 @Test
 public void testDecimalDigits() throws Exception {
   assertEquals(((NumericValue) ValueFactory.createValue(2.3d)).getDecimalDigitsCount(), 1);
   assertEquals(((NumericValue) ValueFactory.createValue(2d)).getDecimalDigitsCount(), 0);
   assertEquals(((NumericValue) ValueFactory.createValue(23)).getDecimalDigitsCount(), 0);
   assertEquals(((NumericValue) ValueFactory.createValue(2.030f)).getDecimalDigitsCount(), 2);
   assertEquals(
       ((NumericValue) ValueFactory.createValue(2.00000000002d)).getDecimalDigitsCount(), 11);
 }
예제 #5
0
 /**
  * DOCUMENT ME!
  *
  * @throws IncompatibleTypesException DOCUMENT ME!
  */
 @Test
 public void testStringValueEquals() throws IncompatibleTypesException {
   Value v1 = ValueFactory.createValue("hola");
   Value v2 = ValueFactory.createValue("hola");
   Value v3 = ValueFactory.createValue("holA");
   assertTrue((v1.equals(v2)).getAsBoolean());
   assertFalse((v1.equals(v3)).getAsBoolean());
   assertFalse((v2.equals(v3)).getAsBoolean());
 }
예제 #6
0
 /** We must be able to transform specialized collections to GeometryCollectionValues */
 @Test
 public void testGeometryCollectionConversions() throws Exception {
   Value val =
       ValueFactory.createValue(
           gf.createMultiPoint(
               new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(1, 2, 3)}));
   assertTrue(val instanceof DefaultMultiPointValue);
   Value val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(4, 2, 3)}),
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(5, 6, 9), new Coordinate(5, 7, 1)})
               }));
   assertTrue(val instanceof DefaultMultiLineStringValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(0, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(0, 3, 0)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(10, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(10, 3, 0)
                         }),
                     null)
               }));
   assertTrue(val instanceof DefaultMultiPolygonValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
 }
예제 #7
0
  @Test
  public void testBooleanComparisons() throws Exception {
    Value v1 = ValueFactory.createValue(true);
    Value v2 = ValueFactory.createValue(false);

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v2.compareTo(v2), 0);

    assertEquals(v1.compareTo(v2), 1);
    assertEquals(v2.compareTo(v1), -1);
  }
예제 #8
0
 @Test
 public void testValuesTypes() throws Exception {
   assertEquals(ValueFactory.createValue(false).getType(), Type.BOOLEAN);
   assertEquals(ValueFactory.createValue(new byte[] {2, 3}).getType(), Type.BINARY);
   assertEquals(ValueFactory.createValue(new Date()).getType(), Type.DATE);
   assertEquals(ValueFactory.createValue(3.0d).getType(), Type.DOUBLE);
   assertEquals(ValueFactory.createValue(3.5f).getType(), Type.FLOAT);
   assertEquals(ValueFactory.createValue(4).getType(), Type.INT);
   assertEquals(ValueFactory.createValue(4L).getType(), Type.LONG);
   assertEquals(ValueFactory.createValue("").getType(), Type.STRING);
   assertEquals(ValueFactory.createValue(new Time(1)).getType(), Type.TIME);
   assertEquals(ValueFactory.createValue(new Timestamp(1)).getType(), Type.TIMESTAMP);
 }
예제 #9
0
 /**
  * Test created to check that we effectively retrieve a good representation of empty
  * multipolygons. indeed, a NullPointerException used to happen...
  *
  * @throws Exception
  */
 @Test
 public void testGeometryCollectionStringRepresentation() throws Exception {
   GeometryCollection mp = gf.createMultiPolygon(new Polygon[] {});
   Value val = ValueFactory.createValue(mp);
   String str = val.toString();
   assertEquals(str, "MULTIPOLYGON EMPTY");
   Polygon poly = gf.createPolygon(gf.createLinearRing(new Coordinate[] {}), new LinearRing[] {});
   assertTrue(poly.isEmpty());
   mp =
       gf.createMultiPolygon(
           new Polygon[] {
             poly,
           });
   val = ValueFactory.createValue(mp);
   str = val.toString();
   assertNotNull(str);
   Polygon polyBis =
       gf.createPolygon(
           gf.createLinearRing(
               new Coordinate[] {
                 new Coordinate(0, 0, 0),
                 new Coordinate(1, 1, 0),
                 new Coordinate(3, 4, 0),
                 new Coordinate(0, 0, 0),
               }),
           new LinearRing[] {});
   mp = gf.createMultiPolygon(new Polygon[] {poly, polyBis});
   val = ValueFactory.createValue(mp);
   str = val.toString();
   assertNotNull(str);
   GeometryCollection coll =
       gf.createGeometryCollection(
           new Geometry[] {
             gf.createPolygon(gf.createLinearRing(new Coordinate[] {}), new LinearRing[] {}),
             gf.createPolygon(
                 gf.createLinearRing(
                     new Coordinate[] {
                       new Coordinate(0, 0, 0),
                       new Coordinate(1, 1, 0),
                       new Coordinate(3, 4, 0),
                       new Coordinate(0, 0, 0),
                     }),
                 new LinearRing[] {})
           });
   mp = gf.createGeometryCollection(new Geometry[] {poly, coll, polyBis});
   val = ValueFactory.createValue(mp);
   str = val.toString();
   assertNotNull(str);
 }
예제 #10
0
 @Test
 public void testTimestampValueConversion() throws Exception {
   Value value = ValueFactory.createValue(new Timestamp(System.currentTimeMillis()));
   Set<Integer> set = new HashSet<Integer>();
   set.add(12);
   checkConversions(value, set);
 }
예제 #11
0
 @Test
 public void testStringValueConversion() throws Exception {
   Value value = ValueFactory.createValue("gdms");
   Set<Integer> set = new HashSet<Integer>();
   set.add(10);
   checkConversions(value, set);
 }
예제 #12
0
 @Test
 public void testGeometryValueConversion() throws Exception {
   Value value = ValueFactory.createValue(Geometries.getMultiPoint3D());
   Set<Integer> set = new HashSet<Integer>();
   set.add(6);
   checkConversions(value, set);
 }
예제 #13
0
 @Test
 public void testDateValueConversion() throws Exception {
   Value value = ValueFactory.createValue(new Date());
   Set<Integer> set = new HashSet<Integer>();
   set.add(3);
   checkConversions(value, set);
 }
예제 #14
0
 @Test
 public void testBooleanValueConversion() throws Exception {
   Value value = ValueFactory.createValue(false);
   Set<Integer> set = new HashSet<Integer>();
   set.add(1);
   checkConversions(value, set);
 }
예제 #15
0
 @Test
 public void testBinaryValueConversion() throws Exception {
   Value binary = ValueFactory.createValue(new byte[] {3, 5, 7});
   Set<Integer> set = new HashSet<Integer>();
   set.add(0);
   checkConversions(binary, set);
 }
  /**
   * Time a multi-threaded access to a cache.
   *
   * @return the timing stopwatch
   */
  private <V> StopWatch timeMultiThreaded(
      String id, final Map<Integer, V> map, ValueFactory<V> factory) throws InterruptedException {

    StopWatch stopWatch = new StopWatch(id);
    for (int i = 0; i < 500; i++) {
      map.put(i, factory.newValue(i));
    }
    Thread[] threads = new Thread[30];
    stopWatch.start("Running threads");
    for (int threadIndex = 0; threadIndex < threads.length; threadIndex++) {
      threads[threadIndex] =
          new Thread("Cache access thread " + threadIndex) {
            @Override
            public void run() {
              for (int j = 0; j < 1000; j++) {
                for (int i = 0; i < 1000; i++) {
                  map.get(i);
                }
              }
            }
          };
    }
    for (Thread thread : threads) {
      thread.start();
    }

    for (Thread thread : threads) {
      if (thread.isAlive()) {
        thread.join(2000);
      }
    }
    stopWatch.stop();
    return stopWatch;
  }
예제 #17
0
 @Test
 public void testNullValueConversion() throws Exception {
   Value value = ValueFactory.createNullValue();
   Set<Integer> set = new HashSet<Integer>();
   for (int i = 0; i < 14; i++) {
     set.add(i);
   }
   checkConversions(value, set);
 }
예제 #18
0
 @Test
 public void testShortValueConversion() throws Exception {
   Value value = ValueFactory.createValue(Short.MAX_VALUE);
   Set<Integer> set = new HashSet<Integer>();
   set.add(2);
   set.add(4);
   set.add(5);
   set.add(7);
   set.add(8);
   set.add(9);
   checkConversions(value, set);
 }
예제 #19
0
  @Test
  public void testNumericValueComparisons() throws Exception {

    Value v1 = ValueFactory.createValue(1);
    Value v2 = ValueFactory.createValue(18);
    Value v3 = ValueFactory.createValue(-5d);
    Value v4 = ValueFactory.createValue(100d);
    Value v5 = ValueFactory.createValue(18f);

    // same value
    assertEquals(v1.compareTo(v1), 0);

    // opposite comparisons
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);

    // different types
    assertEquals(v1.compareTo(v3), 1);
    assertEquals(v2.compareTo(v4), -1);
    assertEquals(v2.compareTo(v5), 0);
  }
예제 #20
0
  @Test
  public void testArrayValue() throws Exception {
    Value[] v = new Value[7];

    for (int i = 0; i < v.length; i++) {
      v[i] = ValueFactory.createValue(i);
    }

    ValueCollection av = ValueFactory.createValue(v);

    for (int i = 0; i < v.length; i++) {
      v[i] = ValueFactory.createValue(i);
    }

    ValueCollection av2 = ValueFactory.createValue(v);

    assertTrue((av.equals(av2)).getAsBoolean());
    assertEquals(av.hashCode(), av2.hashCode());

    for (int i = 0; i < 7; i++) {
      assertTrue((av.get(i).equals(ValueFactory.createValue(i))).getAsBoolean());
    }
  }
예제 #21
0
  @Test
  public void testTimeValuesComparisons() throws Exception {
    DateFormat dateInstance = new SimpleDateFormat("yyyy/MM/dd");
    Value v1 = ValueFactory.createValue(dateInstance.parse("2002/11/21"));
    Value v2 = ValueFactory.createValue(dateInstance.parse("2010/01/11"));

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);

    v1 = ValueFactory.createValue(Time.valueOf("18:01:59"));
    v2 = ValueFactory.createValue(Time.valueOf("23:00:05"));

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);

    v1 = ValueFactory.createValue(Timestamp.valueOf("2002-11-21 18:01:59"));
    v2 = ValueFactory.createValue(Timestamp.valueOf("2010-01-11 23:00:05"));

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);
  }
예제 #22
0
 @Test
 public void testGeometryConversions() throws Exception {
   // Let's test with a PointValue
   Value pt = ValueFactory.createValue(gf.createPoint(new Coordinate(0, 0, 0)));
   assertTrue(pt instanceof DefaultPointValue);
   Value mpt = pt.toType(Type.MULTIPOINT);
   assertTrue(mpt instanceof DefaultMultiPointValue);
   Value gpt = pt.toType(Type.GEOMETRY);
   assertTrue(gpt instanceof DefaultPointValue);
   Value gcpt = pt.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(gcpt instanceof DefaultGeometryCollectionValue);
   assertFalse(gcpt instanceof DefaultMultiPointValue);
   // We shall not be able to cast to a Line or a Polygon.
   try {
     gcpt = pt.toType(Type.POLYGON);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   try {
     gcpt = pt.toType(Type.LINESTRING);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   // LineString time!!!
   pt =
       ValueFactory.createValue(
           gf.createLineString(
               new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(0, 1, 0)}));
   assertTrue(pt instanceof DefaultLineStringValue);
   mpt = pt.toType(Type.MULTILINESTRING);
   assertTrue(mpt instanceof DefaultMultiLineStringValue);
   gpt = pt.toType(Type.GEOMETRY);
   assertTrue(gpt instanceof DefaultLineStringValue);
   gcpt = pt.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(gcpt instanceof DefaultGeometryCollectionValue);
   assertFalse(gcpt instanceof DefaultMultiPointValue);
   // We shall not be able to cast to a Line or a Polygon.
   try {
     gcpt = pt.toType(Type.POLYGON);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   try {
     gcpt = pt.toType(Type.POINT);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   // Let's test with a PolygonValue
   pt =
       ValueFactory.createValue(
           gf.createPolygon(
               gf.createLinearRing(
                   new Coordinate[] {
                     new Coordinate(0, 0, 0),
                     new Coordinate(0, 1, 0),
                     new Coordinate(1, 1, 0),
                     new Coordinate(0, 0, 0)
                   }),
               null));
   assertTrue(pt instanceof DefaultPolygonValue);
   mpt = pt.toType(Type.MULTIPOLYGON);
   assertTrue(mpt instanceof DefaultMultiPolygonValue);
   gpt = pt.toType(Type.GEOMETRY);
   assertTrue(gpt instanceof DefaultPolygonValue);
   gcpt = pt.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(gcpt instanceof DefaultGeometryCollectionValue);
   assertFalse(gcpt instanceof DefaultMultiPolygonValue);
   // We shall not be able to cast to a Line or a Polygon.
   try {
     gcpt = pt.toType(Type.POINT);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   try {
     gcpt = pt.toType(Type.LINESTRING);
     fail();
   } catch (IncompatibleTypesException i) {
   }
 }
예제 #23
0
  /**
   * DOCUMENT ME!
   *
   * @throws Exception DOCUMENT ME!
   */
  @Test
  public void testCreateByType() throws Exception {
    assertTrue(
        (ValueFactory.createValueByType("1", Type.LONG).equals(ValueFactory.createValue(1L)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("true", Type.BOOLEAN)
                .equals(ValueFactory.createValue(true)))
            .getAsBoolean());
    assertTrue(
        (ValueFactory.createValueByType("false", Type.BOOLEAN)
                .equals(ValueFactory.createValue(false)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("carajo", Type.STRING)
                .equals(ValueFactory.createValue("carajo")))
            .getAsBoolean());

    Calendar c = Calendar.getInstance();

    // month is 0-based
    c.set(1980, 8, 5, 0, 0, 0);
    c.set(Calendar.MILLISECOND, 0);

    assertTrue(
        (ValueFactory.createValueByType(d.toString(), Type.DATE)
                .equals(ValueFactory.createValue(d)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType(
                    NumberFormat.getNumberInstance(Locale.ROOT).format(1.1), Type.DOUBLE)
                .equals(ValueFactory.createValue(1.1d)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("1", Type.INT).equals(ValueFactory.createValue(1)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType(
                    NumberFormat.getNumberInstance(Locale.ROOT).format(1.1), Type.FLOAT)
                .equals(ValueFactory.createValue(1.1f)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("1", Type.SHORT).equals(ValueFactory.createValue(1)))
            .getAsBoolean());

    assertTrue(
        (ValueFactory.createValueByType("1", Type.BYTE).equals(ValueFactory.createValue(1)))
            .getAsBoolean());

    byte[] array = new byte[] {(byte) 255, (byte) 160, (byte) 7};
    assertTrue(
        (ValueFactory.createValueByType("FFA007", Type.BINARY)
                .equals(ValueFactory.createValue(array)))
            .getAsBoolean());

    c.set(1970, 0, 1, 22, 45, 00);
    c.set(Calendar.MILLISECOND, 0);

    Time t = new Time(c.getTime().getTime());
    assertTrue(
        (ValueFactory.createValueByType(
                    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(t), Type.TIME)
                .equals(ValueFactory.createValue(t)))
            .getAsBoolean());

    c.set(1970, 0, 1, 22, 45, 20);
    c.set(Calendar.MILLISECOND, 2345);

    Timestamp ts = new Timestamp(c.getTime().getTime());
    assertTrue(
        (ValueFactory.createValueByType(ts.toString(), Type.TIMESTAMP)
                .equals(ValueFactory.createValue(ts)))
            .getAsBoolean());
  }
예제 #24
0
  /** Tests the NullValues operations */
  @Test
  public void testNullValueOperations() throws Exception {
    Value n = ValueFactory.createNullValue();

    ValueCollection b = ValueFactory.createValue(new Value[0]);
    assertTrue((b.equals(n)).isNull());
    assertTrue(b.notEquals(n).isNull());

    Value v = ValueFactory.createValue(true);
    v.and(n);
    v.or(n);
    // SQL UNKNOWN
    assertNull((v.equals(n)).getAsBoolean());
    assertNull((v.notEquals(n)).getAsBoolean());

    Value i = ValueFactory.createValue(1);
    i.equals(n);
    i.notEquals(n);
    assertTrue((i.less(n)).isNull());
    assertTrue((i.lessEqual(n)).isNull());
    assertTrue((i.greater(n)).isNull());
    assertTrue((i.greaterEqual(n)).isNull());

    Value s = ValueFactory.createValue("test");
    assertTrue((s.equals(n)).isNull());
    assertTrue((s.notEquals(n)).isNull());
    assertTrue((s.less(n)).isNull());
    assertTrue((s.lessEqual(n)).isNull());
    assertTrue((s.greater(n)).isNull());
    assertTrue((s.greaterEqual(n)).isNull());
    s.matches(n);

    Value d = ValueFactory.createValue(new Date());
    assertTrue((d.equals(n)).isNull());
    assertTrue((d.notEquals(n)).isNull());
    assertTrue((d.less(n)).isNull());
    assertTrue((d.lessEqual(n)).isNull());
    assertTrue((d.greater(n)).isNull());
    assertTrue((d.greaterEqual(n)).isNull());

    Value t = ValueFactory.createValue(new Time(12));
    assertTrue((t.equals(n)).isNull());
    assertTrue((t.notEquals(n)).isNull());
    assertTrue((t.less(n)).isNull());
    assertTrue((t.lessEqual(n)).isNull());
    assertTrue((t.greater(n)).isNull());
    assertTrue((t.greaterEqual(n)).isNull());

    Value ts = ValueFactory.createValue(new Timestamp(12));
    assertTrue((ts.equals(n)).isNull());
    assertTrue((ts.notEquals(n)).isNull());
    assertTrue((ts.less(n)).isNull());
    assertTrue((ts.lessEqual(n)).isNull());
    assertTrue((ts.greater(n)).isNull());
    assertTrue((ts.greaterEqual(n)).isNull());

    assertTrue((n.equals(n)).isNull());
    assertTrue((n.notEquals(n)).isNull());
    assertTrue((n.less(n)).isNull());
    assertTrue((n.lessEqual(n)).isNull());
    assertTrue((n.greater(n)).isNull());
    assertTrue((n.greaterEqual(n)).isNull());
    n.matches(n);
  }
예제 #25
0
  @Test
  public void testValueCollectionComparisons() {
    ValueCollection v1 =
        ValueFactory.createValue(
            new Value[] {ValueFactory.createValue(18), ValueFactory.createValue("abc")});
    ValueCollection v2 =
        ValueFactory.createValue(
            new Value[] {ValueFactory.createValue(18), ValueFactory.createValue("acc")});
    ValueCollection v3 =
        ValueFactory.createValue(
            new Value[] {ValueFactory.createValue(19), ValueFactory.createValue("abc")});
    ValueCollection v4 =
        ValueFactory.createValue(
            new Value[] {ValueFactory.createValue(-12), ValueFactory.createValue("abc")});

    assertEquals(0, v1.compareTo(v1));
    assertEquals(1, v2.compareTo(v1));
    assertEquals(-1, v1.compareTo(v3));
    assertEquals(1, v1.compareTo(v4));

    assertTrue(v1.less(v2).getAsBoolean());
    assertTrue(v2.lessEqual(v2).getAsBoolean());
    assertTrue(v3.greater(v2).getAsBoolean());
    assertTrue(v4.greaterEqual(v4).getAsBoolean());
    assertTrue(v3.greaterEqual(v4).getAsBoolean());
  }
예제 #26
0
  @Test
  public void testToStringFromStringCoherente() throws Exception {
    Value v = ValueFactory.createValue(1300.5566d);
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.DOUBLE))).getAsBoolean());

    v = ValueFactory.createValue(13.5f);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.FLOAT))).getAsBoolean());

    v = ValueFactory.createValue(1300L);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.LONG))).getAsBoolean());

    v = ValueFactory.createValue(false);
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.BOOLEAN))).getAsBoolean());

    v = ValueFactory.createValue("hola");
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.STRING))).getAsBoolean());

    Calendar c = Calendar.getInstance();

    // month is 0-based
    c.set(1980, 8, 5, 0, 0, 0);
    c.set(Calendar.MILLISECOND, 0);

    v = ValueFactory.createValue(d);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.DATE))).getAsBoolean());

    v = ValueFactory.createValue(15);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.INT))).getAsBoolean());

    v = ValueFactory.createValue((short) 13);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.SHORT))).getAsBoolean());

    v = ValueFactory.createValue((byte) 5);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.BYTE))).getAsBoolean());

    v = ValueFactory.createValue(new byte[] {4, 5, 7, 8, 3, 8});
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.BINARY))).getAsBoolean());

    c.set(1970, 0, 1, 22, 45, 20);
    c.set(Calendar.MILLISECOND, 0);

    Time t = new Time(c.getTime().getTime());
    v = ValueFactory.createValue(t);
    assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.TIME))).getAsBoolean());

    v = ValueFactory.createValue(new Timestamp(2465));
    assertTrue(
        (v.equals(ValueFactory.createValueByType(v.toString(), Type.TIMESTAMP))).getAsBoolean());
  }
예제 #27
0
  @Test
  public void test3DGeoms() throws Exception {
    Coordinate[] coords2D =
        new Coordinate[] {
          new Coordinate(10, 10, 10),
          new Coordinate(40, 10, 10),
          new Coordinate(40, 40, 10),
          new Coordinate(10, 40, 10),
          new Coordinate(10, 10, 10),
        };
    Coordinate[] coords3D =
        new Coordinate[] {
          new Coordinate(10, 10),
          new Coordinate(40, 10),
          new Coordinate(40, 40),
          new Coordinate(10, 40),
          new Coordinate(10, 10),
        };

    Value p1 = ValueFactory.createValue(gf.createPoint(new Coordinate(10, 10, 10)));
    Value p2 = ValueFactory.createValue(gf.createPoint(new Coordinate(10, 10)));
    checkDifferent(p1, p2);

    LineString l1 = gf.createLineString(coords2D);
    p1 = ValueFactory.createValue(l1);
    LineString l2 = gf.createLineString(coords3D);
    p2 = ValueFactory.createValue(l2);
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiPoint(coords2D));
    p2 = ValueFactory.createValue(gf.createMultiPoint(coords3D));
    checkDifferent(p1, p2);

    Polygon pol1 = gf.createPolygon(gf.createLinearRing(coords2D), null);
    p1 = ValueFactory.createValue(pol1);
    Polygon pol2 = gf.createPolygon(gf.createLinearRing(coords3D), null);
    p2 = ValueFactory.createValue(pol2);
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiLineString(new LineString[] {l1}));
    p2 = ValueFactory.createValue(gf.createMultiLineString(new LineString[] {l2}));
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiPolygon(new Polygon[] {pol1}));
    p2 = ValueFactory.createValue(gf.createMultiPolygon(new Polygon[] {pol2}));
    checkDifferent(p1, p2);
  }
예제 #28
0
 @Test(expected = ParseException.class)
 public void testEmptyStringIsNotValidGeometry() throws Exception {
   ValueFactory.createValueByType("", Type.GEOMETRY);
 }
예제 #29
0
 private void checkIO(Value v) throws IncompatibleTypesException {
   Value v2 = ValueFactory.createValue(v.getType(), v.getBytes());
   assertTrue((v2.equals(v)).getAsBoolean());
 }
예제 #30
0
 //
 // public void testValueConversion() throws Exception {
 // Value intValue = ValueFactory.createValue(3);
 // Value doubleValue = ValueFactory.createValue(3.5d);
 // Value stringValue = ValueFactory.createValue("12");
 // Value boolStringValue = ValueFactory.createValue("false");
 // Value booleanValue = ValueFactory.createValue(true);
 // long longValue = System.currentTimeMillis();
 // Value timeValue = ValueFactory.createValue(new Time(longValue));
 // Value dateValue = ValueFactory.createValue(new Date(longValue));
 //
 // checkToString(intType, stringType, intValue);
 // checkToString(intType, doubleType, intValue);
 // checkToString(doubleType, stringType, doubleValue);
 // checkToString(stringType, intType, stringValue);
 // checkToString(stringType, booleanType, boolStringValue);
 // checkToString(booleanType, stringType, booleanValue);
 //
 // BooleanValue bv =  dateValue.toType(
 // timeType.getTypeCode()).equals(timeValue);
 // assertTrue(bv.getAsBoolean());
 // }
 //
 // private void checkToString(Type firstType, Type secondType, Value value)
 // throws IncompatibleTypesException {
 // Value newValue = value.toType(secondType.getTypeCode()).toType(
 // firstType.getTypeCode());
 // assertEquals(( newValue,value));
 // }
 @Test
 public void testValuesIO() throws Exception {
   Value v;
   v = ValueFactory.createValue(false);
   checkIO(v);
   v = ValueFactory.createValue(new byte[] {2, 3, 6});
   checkIO(v);
   v = ValueFactory.createValue(new Date());
   checkIO(v);
   v = ValueFactory.createValue((short) 32700);
   checkIO(v);
   v = ValueFactory.createValue(421359827);
   checkIO(v);
   v = ValueFactory.createValue(1080131636);
   checkIO(v);
   v = ValueFactory.createValue(3.0975525d);
   checkIO(v);
   v = ValueFactory.createValue(3.52345f);
   checkIO(v);
   v = ValueFactory.createValue(8223372036854780000L);
   checkIO(v);
   v = ValueFactory.createValue("asdg");
   checkIO(v);
   v = ValueFactory.createValue(new Time(1));
   checkIO(v);
   v = ValueFactory.createValue(new Timestamp(1));
   checkIO(v);
   v = ValueFactory.createValue(new GeometryFactory().createPoint(new Coordinate(10, 10, 10)));
   checkIO(v);
   v = ValueFactory.createValue(new GeometryFactory().createPoint(new Coordinate(10, 10)));
   checkIO(v);
 }