public void testSerialization_identity() { Converter<String, String> identityConverter = Converter.identity(); SerializableTester.reserializeAndAssert(identityConverter); }
public void testIdentityConverter() { Converter<String, String> stringIdentityConverter = Converter.identity(); assertSame(stringIdentityConverter, stringIdentityConverter.reverse()); assertSame(STR_TO_LONG, stringIdentityConverter.andThen(STR_TO_LONG)); assertSame(STR_VAL, stringIdentityConverter.convert(STR_VAL)); assertSame(STR_VAL, stringIdentityConverter.reverse().convert(STR_VAL)); assertEquals("Converter.identity()", stringIdentityConverter.toString()); assertSame(Converter.identity(), Converter.identity()); }
static ConverterProvider identityForNull(ConverterProvider provider) { return jtx -> { final Converter<?, ?> converter = provider.getConverter(jtx); return converter != null ? converter : Converter.identity(); }; } }
static ConverterProvider identityForNull(ConverterProvider provider) { return jtx -> { final Converter<?, ?> converter = provider.getConverter(jtx); return converter != null ? converter : Converter.identity(); }; } }
@Override public NavigableMapConverter<?, ?, ?, ?> getConverter(JTransaction jtx) { Converter<?, ?> keyConverter = this.keyField.getConverter(jtx); Converter<?, ?> valueConverter = this.valueField.getConverter(jtx); if (keyConverter == null && valueConverter == null) return null; if (keyConverter == null) keyConverter = Converter.<Object>identity(); if (valueConverter == null) valueConverter = Converter.<Object>identity(); return this.createConverter(keyConverter, valueConverter); }
@Override public NavigableMapConverter<?, ?, ?, ?> getConverter(JTransaction jtx) { Converter<?, ?> keyConverter = this.keyField.getConverter(jtx); Converter<?, ?> valueConverter = this.valueField.getConverter(jtx); if (keyConverter == null && valueConverter == null) return null; if (keyConverter == null) keyConverter = Converter.<Object>identity(); if (valueConverter == null) valueConverter = Converter.<Object>identity(); return this.createConverter(keyConverter, valueConverter); }
@Override public <K, V> Converter<?, ?> caseMapField(MapField<K, V> field) { Converter keyConverter = field.getKeyField().visit(this); Converter valueConverter = field.getValueField().visit(this); if (keyConverter != null || valueConverter != null) { if (keyConverter == null) keyConverter = Converter.identity(); if (valueConverter == null) valueConverter = Converter.identity(); return new NavigableMapConverter(keyConverter, valueConverter); } return null; }
@Override public <K, V> Converter<?, ?> caseMapField(MapField<K, V> field) { Converter keyConverter = field.getKeyField().visit(this); Converter valueConverter = field.getValueField().visit(this); if (keyConverter != null || valueConverter != null) { if (keyConverter == null) keyConverter = Converter.identity(); if (valueConverter == null) valueConverter = Converter.identity(); return new NavigableMapConverter(keyConverter, valueConverter); } return null; }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object toIndex(JTransaction jtx) { return new ConvertedIndex2(jtx.tx.queryListElementIndex(this.storageId), this.getConverter(jtx), jtx.referenceConverter, Converter.identity()); }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object toIndex(JTransaction jtx) { return new ConvertedIndex2(jtx.tx.queryListElementIndex(this.storageId), this.getConverter(jtx), jtx.referenceConverter, Converter.identity()); }
public void testSerialization_identity() { Converter<String, String> identityConverter = Converter.identity(); SerializableTester.reserializeAndAssert(identityConverter); }
public void testIdentityConverter() { Converter<String, String> stringIdentityConverter = Converter.identity(); assertSame(stringIdentityConverter, stringIdentityConverter.reverse()); assertSame(STR_TO_LONG, stringIdentityConverter.andThen(STR_TO_LONG)); assertSame(STR_VAL, stringIdentityConverter.convert(STR_VAL)); assertSame(STR_VAL, stringIdentityConverter.reverse().convert(STR_VAL)); assertEquals("Converter.identity()", stringIdentityConverter.toString()); assertSame(Converter.identity(), Converter.identity()); }
/** * Get the composite index on a list field that includes list indicies. * * @param targetType type containing the indexed field; may also be any super-type (e.g., an interface type), * as long as {@code fieldName} is not ambiguous among all sub-types * @param fieldName name of the indexed field; must include {@code "element"} sub-field name (e.g., {@code "mylist.element"}) * @param valueType the Java type corresponding to list elements * @param <V> Java type corresponding to the indexed list's element field * @param <T> Java type containing the field * @return read-only, real-time view of field values, objects having that value in the field, and corresponding list indicies * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V, T> Index2<V, T, Integer> queryListElementIndex(Class<T> targetType, String fieldName, Class<V> valueType) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo(new IndexQueryInfoKey(fieldName, false, targetType, valueType)); if (!(info.indexInfo instanceof ListElementIndexInfo)) throw new IllegalArgumentException("field `" + fieldName + "' is not a list element sub-field"); final ListElementIndexInfo indexInfo = (ListElementIndexInfo)info.indexInfo; final CoreIndex2<?, ObjId, Integer> index = info.applyFilters(this.tx.queryListElementIndex(indexInfo.storageId)); final Converter<?, ?> valueConverter = indexInfo.getConverter(this).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex2(index, valueConverter, targetConverter, Converter.<Integer>identity()); }
/** * Get the composite index on a list field that includes list indicies. * * @param targetType type containing the indexed field; may also be any super-type (e.g., an interface type), * as long as {@code fieldName} is not ambiguous among all sub-types * @param fieldName name of the indexed field; must include {@code "element"} sub-field name (e.g., {@code "mylist.element"}) * @param valueType the Java type corresponding to list elements * @param <V> Java type corresponding to the indexed list's element field * @param <T> Java type containing the field * @return read-only, real-time view of field values, objects having that value in the field, and corresponding list indicies * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V, T> Index2<V, T, Integer> queryListElementIndex(Class<T> targetType, String fieldName, Class<V> valueType) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo(new IndexQueryInfoKey(fieldName, false, targetType, valueType)); if (!(info.indexInfo instanceof ListElementIndexInfo)) throw new IllegalArgumentException("field `" + fieldName + "' is not a list element sub-field"); final ListElementIndexInfo indexInfo = (ListElementIndexInfo)info.indexInfo; final CoreIndex2<?, ObjId, Integer> index = info.applyFilters(this.tx.queryListElementIndex(indexInfo.storageId)); final Converter<?, ?> valueConverter = indexInfo.getConverter(this).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex2(index, valueConverter, targetConverter, Converter.<Integer>identity()); }
/** * Get all instances of the given type, grouped according to schema version. * * @param type any Java type; use {@link Object Object.class} to return all database objects * @param <T> containing Java type * @return mapping from schema version to objects having that version * @throws IllegalArgumentException if {@code type} is null * @throws StaleTransactionException if this transaction is no longer usable */ public <T> NavigableMap<Integer, NavigableSet<T>> queryVersion(Class<T> type) { Preconditions.checkArgument(type != null, "null type"); CoreIndex<Integer, ObjId> index = this.tx.queryVersion(); final KeyRanges keyRanges = this.jdb.keyRangesFor(type); if (!keyRanges.isFull()) index = index.filter(1, keyRanges); return new ConvertedNavigableMap<Integer, NavigableSet<T>, Integer, NavigableSet<ObjId>>(index.asMap(), Converter.<Integer>identity(), new NavigableSetConverter<T, ObjId>(new ReferenceConverter<T>(this, type))); }
/** * Get all instances of the given type, grouped according to schema version. * * @param type any Java type; use {@link Object Object.class} to return all database objects * @param <T> containing Java type * @return mapping from schema version to objects having that version * @throws IllegalArgumentException if {@code type} is null * @throws StaleTransactionException if this transaction is no longer usable */ public <T> NavigableMap<Integer, NavigableSet<T>> queryVersion(Class<T> type) { Preconditions.checkArgument(type != null, "null type"); CoreIndex<Integer, ObjId> index = this.tx.queryVersion(); final KeyRanges keyRanges = this.jdb.keyRangesFor(type); if (!keyRanges.isFull()) index = index.filter(1, keyRanges); return new ConvertedNavigableMap<Integer, NavigableSet<T>, Integer, NavigableSet<ObjId>>(index.asMap(), Converter.<Integer>identity(), new NavigableSetConverter<T, ObjId>(new ReferenceConverter<T>(this, type))); }
sColumns.add(new CheckBoxColumn<String, String, String>(Converter.<String>identity())); sColumns.add(new PropertyColumn<String, String>(new ResourceModel("orule"), "")); sColumns.add(new SecurityRightsColumn(OrientPermission.EXECUTE));