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

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

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

Converter.reverse介绍

[英]Returns the reversed view of this converter, which converts this.convert(a) back to a value roughly equivalent to a.

The returned converter is serializable if this converter is.

Note: you should not override this method. It is non-final for legacy reasons.
[中]返回此转换器的反向视图,该视图将转换此。将(a)转换回大致等于a的值。
如果此转换器是可序列化的,则返回的转换器是可序列化的。
注意:不应重写此方法。由于遗留原因,它不是最终版本。

代码示例

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

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

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

public void testStringConverter_reverse() {
 Converter<String, Integer> converter = Ints.stringConverter();
 assertEquals("1", converter.reverse().convert(1));
 assertEquals("0", converter.reverse().convert(0));
 assertEquals("-1", converter.reverse().convert(-1));
 assertEquals("255", converter.reverse().convert(0xff));
 assertEquals("255", converter.reverse().convert(0xFF));
 assertEquals("-255", converter.reverse().convert(-0xFF));
 assertEquals("438", converter.reverse().convert(0666));
}

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

public void testStringConverter_reverse() {
 Converter<String, Long> converter = Longs.stringConverter();
 assertEquals("1", converter.reverse().convert(1L));
 assertEquals("0", converter.reverse().convert(0L));
 assertEquals("-1", converter.reverse().convert(-1L));
 assertEquals("255", converter.reverse().convert(0xffL));
 assertEquals("255", converter.reverse().convert(0xFFL));
 assertEquals("-255", converter.reverse().convert(-0xFFL));
 assertEquals("438", converter.reverse().convert(0666L));
}

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

public void testStringConverter_reverse() {
 Converter<String, Short> converter = Shorts.stringConverter();
 assertEquals("1", converter.reverse().convert((short) 1));
 assertEquals("0", converter.reverse().convert((short) 0));
 assertEquals("-1", converter.reverse().convert((short) -1));
 assertEquals("255", converter.reverse().convert((short) 0xff));
 assertEquals("255", converter.reverse().convert((short) 0xFF));
 assertEquals("-255", converter.reverse().convert((short) -0xFF));
 assertEquals("438", converter.reverse().convert((short) 0666));
}

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

public void testStringConverter_reverse() {
 Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
 assertEquals("CHEETO", converter.reverse().convert(TestEnum.CHEETO));
 assertEquals("HONDA", converter.reverse().convert(TestEnum.HONDA));
 assertEquals("POODLE", converter.reverse().convert(TestEnum.POODLE));
}

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

@GwtIncompatible // Double.toString returns different value in GWT.
public void testStringConverter_reverse() {
 Converter<String, Double> converter = Doubles.stringConverter();
 assertEquals("1.0", converter.reverse().convert(1.0));
 assertEquals("0.0", converter.reverse().convert(0.0));
 assertEquals("-1.0", converter.reverse().convert(-1.0));
 assertEquals("1000000.0", converter.reverse().convert(1e6));
 assertEquals("1.0E-6", converter.reverse().convert(1e-6));
}

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

@GwtIncompatible // Float.toString returns different value in GWT.
public void testStringConverter_reverse() {
 Converter<String, Float> converter = Floats.stringConverter();
 assertEquals("1.0", converter.reverse().convert(1.0f));
 assertEquals("0.0", converter.reverse().convert(0.0f));
 assertEquals("-1.0", converter.reverse().convert(-1.0f));
 assertEquals("1000000.0", converter.reverse().convert(1e6f));
 assertEquals("1.0E-6", converter.reverse().convert(1e-6f));
}

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

void check() {
  runTester();
  @SuppressWarnings("unchecked") // We are checking it anyway
  Converter<String, Integer> defaultConverter =
    (Converter<String, Integer>) getDefaultParameterValue(0);
  assertEquals(Integer.valueOf(0), defaultConverter.convert("anything"));
  assertEquals("", defaultConverter.reverse().convert(123));
  assertNull(defaultConverter.convert(null));
  assertNull(defaultConverter.reverse().convert(null));
 }
}

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

public void testConverterToBackward() {
 assertEquals("FOO_BAR", UPPER_UNDERSCORE.converterTo(UPPER_CAMEL).reverse().convert("FooBar"));
 assertEquals("FOO_BAR", UPPER_UNDERSCORE.converterTo(LOWER_CAMEL).reverse().convert("fooBar"));
 assertEquals("FooBar", UPPER_CAMEL.converterTo(UPPER_UNDERSCORE).reverse().convert("FOO_BAR"));
 assertEquals("fooBar", LOWER_CAMEL.converterTo(UPPER_UNDERSCORE).reverse().convert("FOO_BAR"));
}

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

public void testAsConverter_inverse() throws Exception {
 ImmutableBiMap<String, Integer> biMap =
   ImmutableBiMap.of(
     "one", 1,
     "two", 2);
 Converter<String, Integer> converter = Maps.asConverter(biMap);
 for (Entry<String, Integer> entry : biMap.entrySet()) {
  assertSame(entry.getKey(), converter.reverse().convert(entry.getValue()));
 }
}

代码示例来源: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 testConverter() {
 assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
 assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));
 Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
 assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
}

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

public void testNullIsNotPassedThrough() {
 Converter<String, String> nullsAreHandled = sillyConverter(true);
 assertEquals("forward", nullsAreHandled.convert("foo"));
 assertEquals(null, nullsAreHandled.convert(null));
 assertEquals("backward", nullsAreHandled.reverse().convert("foo"));
 assertEquals(null, nullsAreHandled.reverse().convert(null));
}

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

public void testNullIsPassedThrough() {
 Converter<String, String> nullsArePassed = sillyConverter(false);
 assertEquals("forward", nullsArePassed.convert("foo"));
 assertEquals("forward", nullsArePassed.convert(null));
 assertEquals("backward", nullsArePassed.reverse().convert("foo"));
 assertEquals("backward", nullsArePassed.reverse().convert(null));
}

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

public void testStringConverter_nullConversions() {
 Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
 assertNull(converter.convert(null));
 assertNull(converter.reverse().convert(null));
}

代码示例来源: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: google/guava

public void testAsConverter_nullConversions() throws Exception {
 ImmutableBiMap<String, Integer> biMap =
   ImmutableBiMap.of(
     "one", 1,
     "two", 2);
 Converter<String, Integer> converter = Maps.asConverter(biMap);
 assertNull(converter.convert(null));
 assertNull(converter.reverse().convert(null));
}

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

public void testStringConverter_nullConversions() {
 assertNull(Shorts.stringConverter().convert(null));
 assertNull(Shorts.stringConverter().reverse().convert(null));
}

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

public void testConverter_nullConversions() {
 for (CaseFormat outer : CaseFormat.values()) {
  for (CaseFormat inner : CaseFormat.values()) {
   assertNull(outer.converterTo(inner).convert(null));
   assertNull(outer.converterTo(inner).reverse().convert(null));
  }
 }
}

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

public void testStringConverter_convert() {
 Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
 assertEquals(TestEnum.CHEETO, converter.convert("CHEETO"));
 assertEquals(TestEnum.HONDA, converter.convert("HONDA"));
 assertEquals(TestEnum.POODLE, converter.convert("POODLE"));
 assertNull(converter.convert(null));
 assertNull(converter.reverse().convert(null));
}

相关文章