Exemplo n.º 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());
  }
Exemplo n.º 2
0
  /**
   * @see
   *     com.hardcode.gdbms.engine.instruction.Operations#equals(com.hardcode.gdbms.engine.values.Value)
   */
  public Value equals(Value value) throws IncompatibleTypesException {
    if (value instanceof NullValue) {
      return ValueFactory.createValue(false);
    }

    return ValueFactory.createValue(this.value.equals(value.toString()));
  }
  Map<String, Object> getValues(
      Individual ind,
      OntModel displayOntModel,
      OntModel assertionModel,
      Map<String, Object> baseValues) {
    if (ind == null) return Collections.emptyMap();

    /* Figure out what ValueFactories are specified in the display ontology for this individual. */
    Set<ValueFactory> valueFactories = new HashSet<ValueFactory>();
    displayOntModel.enterCriticalSection(Model.READ);
    StmtIterator stmts = ind.listProperties(DisplayVocabulary.REQUIRES_VALUES);
    try {
      while (stmts.hasNext()) {
        Statement stmt = stmts.nextStatement();
        RDFNode obj = stmt.getObject();
        valueFactories.addAll(getValueFactory(obj, displayOntModel));
      }
    } finally {
      stmts.close();
      displayOntModel.leaveCriticalSection();
    }

    /* Get values from the ValueFactories. */
    HashMap<String, Object> values = new HashMap<String, Object>();
    values.putAll(baseValues);
    for (ValueFactory vf : valueFactories) {
      values.putAll(vf.getValues(assertionModel, values));
    }
    return values;
  }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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());
 }
Exemplo n.º 8
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);
  }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
 /** Returns the concatenation of the two values. */
 @Override
 public Value concatenate(Value v) {
   if (v instanceof StringVal) {
     return ValueFactory.create(str + " " + v.toString());
   } else if (v instanceof DoubleVal) {
     return ValueFactory.create(str + " " + v.toString());
   } else if (v instanceof NoneVal) {
     return this;
   } else {
     log.warning("cannot concatenate " + this + " and " + v);
     return ValueFactory.noneValue;
   }
 }
Exemplo n.º 11
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);
 }
Exemplo n.º 12
0
 /**
  * BNode factory
  *
  * @return BNode a blank node
  */
 public BNode bnode() {
   try {
     RepositoryConnection con = therepository.getConnection();
     try {
       ValueFactory vf = con.getValueFactory();
       return vf.createBNode();
     } finally {
       con.close();
     }
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Exemplo n.º 13
0
 /**
  * UR Iref factory
  *
  * @param uri to build
  * @return URI resource
  */
 public URI URIref(String uri) {
   try {
     RepositoryConnection con = therepository.getConnection();
     try {
       ValueFactory vf = con.getValueFactory();
       return vf.createURI(uri);
     } finally {
       con.close();
     }
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Exemplo n.º 14
0
 /**
  * Insert Triple/Statement into graph
  *
  * @param s subject uriref
  * @param p predicate uriref
  * @param o value object (URIref or Literal)
  */
 public void add(URI s, URI p, Value o) {
   try {
     RepositoryConnection con = therepository.getConnection();
     try {
       ValueFactory myFactory = con.getValueFactory();
       Statement st = myFactory.createStatement(s, p, o);
       con.add(st);
     } finally {
       con.close();
     }
   } catch (Exception e) {
     // handle exception
   }
 }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
 @Test
 public void testBooleanValueConversion() throws Exception {
   Value value = ValueFactory.createValue(false);
   Set<Integer> set = new HashSet<Integer>();
   set.add(1);
   checkConversions(value, set);
 }
Exemplo n.º 20
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);
 }
Exemplo n.º 21
0
  /**
   * @see
   *     com.hardcode.gdbms.engine.instruction.Operations#lessEqual(com.hardcode.gdbms.engine.values.BooleanValue)
   */
  public Value lessEqual(Value value) throws IncompatibleTypesException {
    if (value instanceof NullValue) {
      return ValueFactory.createValue(false);
    }

    return new BooleanValue(this.value.compareTo(value.toString()) <= 0);
  }
Exemplo n.º 22
0
 @Test
 public void testStringValueConversion() throws Exception {
   Value value = ValueFactory.createValue("gdms");
   Set<Integer> set = new HashSet<Integer>();
   set.add(10);
   checkConversions(value, set);
 }
Exemplo n.º 23
0
 public ReferenceValue referenceArrayLoad(IntegerValue indexValue, ValueFactory valueFactory) {
   return type == null
       ? ValueFactory.REFERENCE_VALUE_NULL
       : !ClassUtil.isInternalArrayType(type)
           ? ValueFactory.REFERENCE_VALUE_JAVA_LANG_OBJECT_MAYBE_NULL
           : valueFactory.createValue(type.substring(1), referencedClass, true).referenceValue();
 }
  /**
   * 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;
  }
Exemplo n.º 25
0
  public static IList project(IList rel1, int... fields) {
    IListWriter w = ValueFactory.getInstance().listWriter();

    for (IValue v : rel1) {
      w.append(((ITuple) v).select(fields));
    }

    return w.done();
  }
Exemplo n.º 26
0
 /**
  * Literal factory
  *
  * @param s the literal value
  * @param typeuri uri representing the type (generally xsd)
  * @return Literal type
  */
 public org.openrdf.model.Literal Literal(String s, URI typeuri) {
   try {
     RepositoryConnection con = therepository.getConnection();
     try {
       ValueFactory vf = con.getValueFactory();
       if (typeuri == null) {
         return vf.createLiteral(s);
       } else {
         return vf.createLiteral(s, typeuri);
       }
     } finally {
       con.close();
     }
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Exemplo n.º 27
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);
 }
Exemplo n.º 28
0
 public Value eval(RCvalue args) throws EvalException {
   if (args.size() != 2) throw new EvalException("usage: reduce(polygon, errtol])");
   PolygonValue pv1 = (PolygonValue) args.value(0);
   PolygonValue pv2 = (PolygonValue) args.value(1);
   boolean isContain = pv1.polygon().contains(pv2.polygon());
   double contain = 0;
   if (isContain) {
     contain = 1; // we don't have a boolean factory now.
   }
   return ValueFactory.create(contain);
 }
Exemplo n.º 29
0
 private Comparison stringComparisonConstraint(
     DynamicOperand operand,
     String valueOperandShouldBe,
     QueryObjectModelFactory qomFactory,
     ValueFactory valueFactory)
     throws RepositoryException {
   return qomFactory.comparison(
       operand,
       QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO,
       qomFactory.literal(valueFactory.createValue(valueOperandShouldBe, PropertyType.STRING)));
 }
Exemplo n.º 30
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);
  }