本文整理了Java中com.google.common.base.Converter.identity()
方法的一些代码示例,展示了Converter.identity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Converter.identity()
方法的具体详情如下:
包路径:com.google.common.base.Converter
类名称:Converter
方法名:identity
[英]Returns a serializable converter that always converts or reverses an object to itself.
[中]返回可序列化转换器,该转换器始终将对象转换或反转为自身。
代码示例来源:origin: google/guava
public void testSerialization_identity() {
Converter<String, String> identityConverter = Converter.identity();
SerializableTester.reserializeAndAssert(identityConverter);
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: io.permazen/permazen-main
static ConverterProvider identityForNull(ConverterProvider provider) {
return jtx -> {
final Converter<?, ?> converter = provider.getConverter(jtx);
return converter != null ? converter : Converter.identity();
};
}
}
代码示例来源:origin: org.jsimpledb/jsimpledb-main
static ConverterProvider identityForNull(ConverterProvider provider) {
return jtx -> {
final Converter<?, ?> converter = provider.getConverter(jtx);
return converter != null ? converter : Converter.identity();
};
}
}
代码示例来源:origin: io.permazen/permazen-main
@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);
}
代码示例来源:origin: org.jsimpledb/jsimpledb-main
@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);
}
代码示例来源:origin: org.jsimpledb/jsimpledb-main
@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;
}
代码示例来源:origin: io.permazen/permazen-main
@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;
}
代码示例来源:origin: org.jsimpledb/jsimpledb-main
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object toIndex(JTransaction jtx) {
return new ConvertedIndex2(jtx.tx.queryListElementIndex(this.storageId),
this.getConverter(jtx), jtx.referenceConverter, Converter.identity());
}
代码示例来源:origin: io.permazen/permazen-main
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object toIndex(JTransaction jtx) {
return new ConvertedIndex2(jtx.tx.queryListElementIndex(this.storageId),
this.getConverter(jtx), jtx.referenceConverter, Converter.identity());
}
代码示例来源:origin: com.google.guava/guava-tests
public void testSerialization_identity() {
Converter<String, String> identityConverter = Converter.identity();
SerializableTester.reserializeAndAssert(identityConverter);
}
代码示例来源:origin: com.google.guava/guava-tests
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());
}
代码示例来源:origin: io.permazen/permazen-main
/**
* 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());
}
代码示例来源:origin: org.jsimpledb/jsimpledb-main
/**
* 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());
}
代码示例来源:origin: io.permazen/permazen-main
/**
* 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)));
}
代码示例来源:origin: org.jsimpledb/jsimpledb-main
/**
* 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)));
}
代码示例来源:origin: OrienteerBAP/Orienteer
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));
内容来源于网络,如有侵权,请联系作者删除!