List of usage examples for com.google.common.base Converter reverse
Converter reverse
To view the source code for com.google.common.base Converter reverse.
Click Source Link
From source file:org.fcrepo.kernel.modeshape.identifiers.NodeResourceConverter.java
/** * Get a converter that can transform a Node to a Resource * @param c the given node/*from w w w .java2s.c o m*/ * @return the converter that can transform a node to resource */ public static Converter<Node, Resource> nodeToResource(final Converter<Resource, FedoraResource> c) { return nodeConverter.andThen(c.reverse()); }
From source file:com.iamcontent.device.io.analog.calibrate.CalibratedAnalogIO.java
private static Converter<Double, Double> reverse(Converter<Double, Double> calibration) { return calibration == null ? null : calibration.reverse(); }
From source file:be.nbb.demetra.dotstat.DotStatAccessor.java
private static List<DbSetId> getAllSeries(SdmxConnection conn, FlowRef flowRef, DbSetId ref) throws IOException { Converter<DbSetId, Key> converter = getConverter(conn.getDataStructure(flowRef), ref); Key colKey = converter.convert(ref); try (TsCursor<Key, IOException> cursor = DotStatUtil.getAllSeries(conn, flowRef, colKey)) { ImmutableList.Builder<DbSetId> result = ImmutableList.builder(); while (cursor.nextSeries()) { result.add(converter.reverse().convert(cursor.getKey())); }//from w w w . ja va 2s.co m return result.build(); } }
From source file:be.nbb.demetra.dotstat.DotStatAccessor.java
private static List<DbSeries> getAllSeriesWithData(SdmxConnection conn, FlowRef flowRef, DbSetId ref) throws IOException { Converter<DbSetId, Key> converter = getConverter(conn.getDataStructure(flowRef), ref); Key colKey = converter.convert(ref); try (TsCursor<Key, IOException> cursor = DotStatUtil.getAllSeriesWithData(conn, flowRef, colKey)) { ImmutableList.Builder<DbSeries> result = ImmutableList.builder(); while (cursor.nextSeries()) { result.add(new DbSeries(converter.reverse().convert(cursor.getKey()), cursor.getData())); }/*from w ww. j a v a 2s. c om*/ return result.build(); } }
From source file:com.ibm.common.activitystreams.internal.EnumAdapter.java
/** * Constructor for EnumAdapter./* w w w . j a v a2 s .c o m*/ * @param _enumClass Class<E> * @param c Converter<String,E> */ public EnumAdapter(Class<E> _enumClass, Converter<String, E> c) { super(); this.des = toUpper.andThen(c); this.ser = c.reverse().andThen(toLower); }
From source file:org.fcrepo.kernel.impl.rdf.impl.PrefixingIdentifierTranslator.java
private void setTranslationChain() { for (final Converter<String, String> t : minimalTranslationChain) { forward = forward.andThen(t);/*from w w w .j a v a 2 s.co m*/ } for (final Converter<String, String> t : Lists.reverse(minimalTranslationChain)) { reverse = reverse.andThen(t.reverse()); } }
From source file:com.google.errorprone.bugpatterns.CanonicalDuration.java
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { Api api;//from ww w . j a v a2 s. co m if (JAVA_TIME_MATCHER.matches(tree, state)) { api = Api.JAVA; } else if (JODA_MATCHER.matches(tree, state)) { api = Api.JODA; } else { return NO_MATCH; } if (tree.getArguments().size() != 1) { // TODO(cushon): ofSeconds w/ nano adjustment? return NO_MATCH; } Tree arg = getOnlyElement(tree.getArguments()); if (!(arg instanceof LiteralTree)) { // don't inline constants return NO_MATCH; } Number constValue = constValue(arg, Number.class); if (constValue == null) { return NO_MATCH; } long value = constValue.longValue(); if (value == 0) { switch (api) { case JODA: ExpressionTree receiver = getReceiver(tree); SuggestedFix fix; if (receiver == null) { // static import of the method fix = SuggestedFix.builder().addImport(api.getDurationFullyQualifiedName()) .replace(tree, "Duration.ZERO").build(); } else { fix = SuggestedFix.replace(state.getEndPosition(getReceiver(tree)), state.getEndPosition(tree), ".ZERO"); } return buildDescription(tree) .setMessage("Duration can be expressed more clearly without units, as Duration.ZERO") .addFix(fix).build(); case JAVA: // don't rewrite e.g. `ofMillis(0)` to `ofDays(0)` return NO_MATCH; } throw new AssertionError(api); } MethodSymbol sym = getSymbol(tree); if (!METHOD_NAME_TO_UNIT.containsKey(sym.getSimpleName().toString())) { return NO_MATCH; } TemporalUnit unit = METHOD_NAME_TO_UNIT.get(sym.getSimpleName().toString()); if (Objects.equals(BANLIST.get(unit), value)) { return NO_MATCH; } Duration duration = Duration.of(value, unit); // Iterate over all possible units from largest to smallest (days to nanos) until we find the // largest unit that can be used to exactly express the duration. for (Map.Entry<ChronoUnit, Converter<Duration, Long>> entry : CONVERTERS.entrySet()) { ChronoUnit nextUnit = entry.getKey(); if (unit.equals(nextUnit)) { // We reached the original unit, no simplification is possible. break; } Converter<Duration, Long> converter = entry.getValue(); long nextValue = converter.convert(duration); if (converter.reverse().convert(nextValue).equals(duration)) { // We reached a larger than original unit that precisely expresses the duration, rewrite to // use it instead. String name = FACTORIES.get(api, nextUnit); String replacement = String.format("%s(%d%s)", name, nextValue, nextValue == ((int) nextValue) ? "" : "L"); ExpressionTree receiver = getReceiver(tree); if (receiver == null) { // static import of the method SuggestedFix fix = SuggestedFix.builder() .addStaticImport(api.getDurationFullyQualifiedName() + "." + name) .replace(tree, replacement).build(); return describeMatch(tree, fix); } else { return describeMatch(tree, SuggestedFix.replace(state.getEndPosition(receiver), state.getEndPosition(tree), "." + replacement)); } } } return NO_MATCH; }
From source file:org.fcrepo.http.commons.api.rdf.HttpResourceConverter.java
private void setTranslationChain(final List<Converter<String, String>> chained) { translationChain = chained;// w ww .j a va2s . co m 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()); } }