private void readVersion2(final ObjectInput in) throws IOException { // read in the #of declarations. final int ndecls = LongPacker.unpackInt(in); // read in the #of values. final int nvalues = LongPacker.unpackInt(in); // read in the checksum. final long checksumActual = in.readLong(); // The namespace of the KB instance. final String namespace = in.readUTF(); // Note: The value factory uses the namespace of the KB instance! valueFactory = BigdataValueFactoryImpl.getInstance(namespace); // Initialize the vocabulary. init(ndecls, nvalues); // decls = new LinkedHashSet<VocabularyDecl>(ndecls); // // // allocate the map with sufficient capacity. // val2iv = new LinkedHashMap<Value, BigdataValue>(nvalues); // iv2val = new LinkedHashMap<IV, BigdataValue>(nvalues); // // for (int i = 0; i < ndecls; i++) { // // final String className = in.readUTF(); // // try { // // final Class<?> cls = Class.forName(className); // // if (!VocabularyDecl.class.isAssignableFrom(cls)) // throw new IOException(className); // // final VocabularyDecl decl = (VocabularyDecl) cls.newInstance(); // // decls.add(decl); // // } catch (InstantiationException e) { // // throw new IOException(e); // // } catch (IllegalAccessException e) { // // throw new IOException(e); // // } catch (ClassNotFoundException e) { // // throw new IOException(e); // // } // // } // // addAllDecls(); if (ndecls != decls.size()) { /* * This indicates a versioning problem with the vocabulary * declaration classes. */ throw new IOException(); } if (nvalues != val2iv.size()) { /* * This indicates a versioning problem with the vocabulary * declaration classes. */ throw new VocabularyVersioningException(); } // compute a checksum on the hash codes of the URIs. long checksum = 0; for (Value value : val2iv.keySet()) { checksum += value.hashCode(); } if (checksum != checksumActual) { /* * This indicates a versioning problem with the vocabulary * declaration classes. */ throw new VocabularyVersioningException(); } generateIVs(); }
/** Test math operations such as +, -, *, /, MIN and MAX over the datatype. */ @SuppressWarnings({"unchecked", "rawtypes"}) public void testMath() { final BigdataValueFactory vf = BigdataValueFactoryImpl.getInstance(getName() + UUID.randomUUID()); final MockTermIdFactory termIdFactory = new MockTermIdFactory(); final CompressedTimestampExtension<BigdataValue> ext = new CompressedTimestampExtension<BigdataValue>( new IDatatypeURIResolver() { @Override public BigdataURI resolve(final URI uri) { final BigdataURI buri = vf.createURI(uri.stringValue()); buri.setIV(termIdFactory.newTermId(VTE.URI)); return buri; } }); final BigdataValue bvZero = vf.createLiteral("0", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV zero = ext.createIV(bvZero); zero.setValue(bvZero); final BigdataValue bfOne = vf.createLiteral("1", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV one = ext.createIV(bfOne); one.setValue(bfOne); final BigdataValue bfTen = vf.createLiteral("10", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV ten = ext.createIV(bfTen); ten.setValue(bfTen); final BigdataValue bfTwenty = vf.createLiteral("20", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV twenty = ext.createIV(bfTwenty); twenty.setValue(bfTwenty); final NumericIV<BigdataLiteral, ?> result10a_int_act = MathUtility.literalMath(zero, ten, MathOp.PLUS); final NumericIV<BigdataLiteral, ?> result10b_int_act = MathUtility.literalMath(twenty, ten, MathOp.MINUS); final NumericIV<BigdataLiteral, ?> result10c_int_act = MathUtility.literalMath(ten, one, MathOp.MULTIPLY); final NumericIV<BigdataLiteral, ?> result10d_dec_act = MathUtility.literalMath(ten, one, MathOp.DIVIDE); final NumericIV<BigdataLiteral, ?> result10e_int_act = MathUtility.literalMath(ten, twenty, MathOp.MIN); final NumericIV<BigdataLiteral, ?> result10f_int_act = MathUtility.literalMath(twenty, ten, MathOp.MIN); final NumericIV<BigdataLiteral, ?> result20a_int_act = MathUtility.literalMath(ten, ten, MathOp.PLUS); final NumericIV<BigdataLiteral, ?> result20b_int_act = MathUtility.literalMath(ten, twenty, MathOp.MAX); final NumericIV<BigdataLiteral, ?> result20c_int_act = MathUtility.literalMath(twenty, ten, MathOp.MAX); final XSDIntegerIV<?> result10_int = new XSDIntegerIV<>(new BigInteger("10")); final XSDDecimalIV<?> result10_dec = new XSDDecimalIV<>(new BigDecimal(new BigInteger("10"))); final XSDIntegerIV<?> result20_int = new XSDIntegerIV<>(new BigInteger("20")); assertEquals(result10_int, result10a_int_act); assertEquals(result10_int, result10b_int_act); assertEquals(result10_int, result10c_int_act); assertEquals(result10_dec, result10d_dec_act); assertEquals(result10_int, result10e_int_act); assertEquals(result10_int, result10f_int_act); assertEquals(result20_int, result20a_int_act); assertEquals(result20_int, result20b_int_act); assertEquals(result20_int, result20c_int_act); }
/** * Ctor used by {@link AbstractTripleStore#create()}. * * @param database The database. */ protected BaseVocabulary(final String namespace) { if (namespace == null) throw new IllegalArgumentException(); this.valueFactory = BigdataValueFactoryImpl.getInstance(namespace); }