@Test public void testMap() throws Exception { Mapper<Object, Integer> mapper = ClassBasedMapper.<Object, Integer>builder() .addMapper(Float.class, Math::round) .addMapper(String.class, Integer::parseInt) .build(); assertEquals(new Integer(1), mapper.map(new Float(1.2))); assertEquals(new Integer(3), mapper.map("3")); }
@Override public R map(@NonNull final T object) { Mapper<T, ? extends R> mapper = locator.get(object.getClass()); Preconditions.checkState(mapper != null, "No mapper found for type " + object.getClass()); return mapper.map(object); }
ClassBasedMapper implements Mapper<T, R> { @Override public R map(@NonNull final T object) { Mapper<T, ? extends R> mapper = locator.get(object.getClass()); Preconditions.checkState(mapper != null, "No mapper found for type " + object.getClass()); return mapper.map(object); } }
ClassBasedMapper implements Mapper<T, R> { @Override public R map(@NonNull final T object) { Mapper<T, ? extends R> mapper = locator.get(object.getClass()); Preconditions.checkState(mapper != null, "No mapper found for type " + object.getClass()); return mapper.map(object); }  }
ClassBasedMapper implements Mapper<T, R> { @Override public R map(@NonNull final T object) { Mapper<T, ? extends R> mapper = locator.get(object.getClass()); Preconditions.checkState(mapper != null, "No mapper found for type " + object.getClass()); return mapper.map(object); }  static ClassBasedMapper.Builder<T, R> builder(); @Override R map(@NonNull final T object); }
ClassBasedMapper implements Mapper<T, R> { @Override public R map(@NonNull final T object) { Mapper<T, ? extends R> mapper = locator.get(object.getClass()); Preconditions.checkState(mapper != null, "No mapper found for type " + object.getClass()); return mapper.map(object); }  static ClassBasedMapper.Builder<T, R> builder(); @Override R map(@NonNull final T object);  }