com.google.common.base.Converter.andThen()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(257)

本文整理了Java中com.google.common.base.Converter.andThen()方法的一些代码示例,展示了Converter.andThen()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Converter.andThen()方法的具体详情如下:
包路径:com.google.common.base.Converter
类名称:Converter
方法名:andThen

Converter.andThen介绍

[英]Returns a converter whose convert method applies secondConverter to the result of this converter. Its reverse method applies the converters in reverse order.

The returned converter is serializable if this converter and secondConverterare.
[中]返回一个转换器,其转换方法将secondConverter应用于此转换器的结果。其反向方法以相反的顺序应用转换器。
如果此转换器和第二个转换器为,则返回的转换器可序列化。

代码示例

代码示例来源:origin: google/guava

public void testAndThen() {
 Converter<StringWrapper, String> first =
   new Converter<StringWrapper, String>() {
    @Override
    protected String doForward(StringWrapper object) {
     return object.value;
    }
    @Override
    protected StringWrapper doBackward(String object) {
     return new StringWrapper(object);
    }
    @Override
    public String toString() {
     return "StringWrapper";
    }
   };
 Converter<StringWrapper, Long> converter = first.andThen(STR_TO_LONG);
 assertEquals(LONG_VAL, converter.convert(new StringWrapper(STR_VAL)));
 assertEquals(STR_VAL, converter.reverse().convert(LONG_VAL).value);
 assertEquals("StringWrapper.andThen(string2long)", converter.toString());
 assertEquals(first.andThen(STR_TO_LONG), first.andThen(STR_TO_LONG));
}

代码示例来源:origin: google/guava

public void testSerialization_andThen() {
 Converter<String, Long> converterA = Longs.stringConverter();
 Converter<Long, String> reverseConverter = Longs.stringConverter().reverse();
 Converter<String, String> composedConverter = converterA.andThen(reverseConverter);
 SerializableTester.reserializeAndAssert(composedConverter);
}

代码示例来源: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: org.fcrepo/fcrepo-kernel-modeshape

private void setTranslationChain() {
  for (final Converter<String, String> t : minimalTranslationChain) {
    forward = forward.andThen(t);
  }
  for (final Converter<String, String> t : Lists.reverse(minimalTranslationChain)) {
    reverse = reverse.andThen(t.reverse());
  }
}

代码示例来源:origin: org.fcrepo/fcrepo-http-commons

private void setTranslationChain(final List<Converter<String, String>> chained) {
  translationChain = chained;
  for (final Converter<String, String> t : translationChain) {
    forward = forward.andThen(t);
  }
  for (final Converter<String, String> t : Lists.reverse(translationChain)) {
    reverse = reverse.andThen(t.reverse());
  }
}

代码示例来源:origin: com.google.guava/guava-tests

public void testAndThen() {
 Converter<StringWrapper, String> first = new Converter<StringWrapper, String>() {
  @Override protected String doForward(StringWrapper object) {
   return object.value;
  }
  @Override protected StringWrapper doBackward(String object) {
   return new StringWrapper(object);
  }
  @Override public String toString() {
   return "StringWrapper";
  }
 };
 Converter<StringWrapper, Long> converter = first.andThen(STR_TO_LONG);
 assertEquals(LONG_VAL, converter.convert(new StringWrapper(STR_VAL)));
 assertEquals(STR_VAL, converter.reverse().convert(LONG_VAL).value);
 assertEquals("StringWrapper.andThen(string2long)", converter.toString());
 assertEquals(first.andThen(STR_TO_LONG), first.andThen(STR_TO_LONG));
}

代码示例来源:origin: com.google.guava/guava-tests

public void testSerialization_andThen() {
 Converter<String, Long> converterA = Longs.stringConverter();
 Converter<Long, String> reverseConverter = Longs.stringConverter().reverse();
 Converter<String, String> composedConverter = converterA.andThen(reverseConverter);
 SerializableTester.reserializeAndAssert(composedConverter);
}

代码示例来源: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());
}

相关文章