Java Code Examples for com.google.common.base.Functions#compose()

The following examples show how to use com.google.common.base.Functions#compose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisStoreImpl.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Function} to retrieve a particular field value from a {@code redis-cli info}
 * command.
 * 
 * @param field the info field to retrieve and convert
 * @return a new function that converts a {@link SshPollValue} to an {@link Integer}
 */
private static Function<SshPollValue, Integer> infoFunction(final String field) {
    return Functions.compose(new Function<String, Integer>() {
        @Override
        public Integer apply(@Nullable String input) {
            Optional<String> line = Iterables.tryFind(Splitter.on('\n').split(input), Predicates.containsPattern(field + ":"));
            if (line.isPresent()) {
                String data = line.get().trim();
                int colon = data.indexOf(":");
                return Integer.parseInt(data.substring(colon + 1));
            } else {
                throw new IllegalStateException("Data for field "+field+" not found: "+input);
            }
        }
    }, SshValueFunctions.stdout());
}
 
Example 2
Source File: HiveDifferences.java    From circus-train with Apache License 2.0 5 votes vote down vote up
public HiveDifferences build() {
  checkNotNull(diffListener, "diffListener is required");
  checkNotNull(comparatorRegistry, "comparatorRegistry is required");
  checkNotNull(sourceConfiguration, "sourceConfiguration is required");
  checkNotNull(sourceTable, "sourceTable is required");
  checkNotNull(sourcePartitionIterator, "sourcePartitionIterable is required");
  if (replicaTable.isPresent() && !replicaPartitionFetcher.isPresent()) {
    throw new IllegalStateException("replicaPartitionFetcher is required if replicaTable exists");
  }
  if (checksumFunction == null) {
    checksumFunction = Functions.compose(new PathDigest(), new PathToPathMetadata(sourceConfiguration));
  }
  return new HiveDifferences(comparatorRegistry, diffListener, sourceTable, sourcePartitionIterator, replicaTable,
      replicaPartitionFetcher, checksumFunction, partitionLimit);
}
 
Example 3
Source File: SummarizeDocScores2016.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private Map<String, SystemScores> writeSummaryLinkingScores(
    final Collection<String> focusSystemSubmissionNames,
    final ImmutableMap<String, SystemScores> systemNameToScores,
    final ImmutableSetMultimap<String, String> teamsToSystems, final Writer out)
    throws IOException {
  final Map<String, SystemScores> teamScores =
      Maps.filterKeys(systemNameToScores, in(focusSystemSubmissionNames));

  final Function<SystemScores, PercentileComputer.Percentiles> EXTRACT_LINKING_BOOTSTRAP_SCORES =
      Functions.compose(
          SummarizeDocScores2016.<String, PercentileComputer.Percentiles>getFunction("F1"),
          Functions.compose(SystemConditionScoresFunctions.linkPercentiles(), SystemScoresFunctions
              .withRealis()));

  final Function<SystemScores, Double> EXTRACT_LINKING_BOOTSTRAP_MEDIAN =
      Functions.compose(RecklessMedianFunction.INSTANCE, EXTRACT_LINKING_BOOTSTRAP_SCORES);
  final Ordering<SystemScores> BY_BOOTSTRAP_MEDIAN_LINKING_SCORE =
      Ordering.natural().onResultOf(EXTRACT_LINKING_BOOTSTRAP_MEDIAN);

  final ImmutableMap.Builder<String, SystemScores> linkScoresToPrint = ImmutableMap.builder();
  linkScoresToPrint.putAll(teamScores);

  final Optional<Map<Integer, PercentileComputer.Percentiles>> medianScores;
  if (teamsToSystems.keySet().size() > 3) {
    medianScores = Optional.of(Maps.transformValues(
        findMedianSystemsBy(systemNameToScores, teamsToSystems, EXTRACT_LINKING_BOOTSTRAP_MEDIAN),
        EXTRACT_LINKING_BOOTSTRAP_SCORES));
  } else {
    medianScores = Optional.absent();
  }

  linkScoresToPrint.put("Max", BY_BOOTSTRAP_MEDIAN_LINKING_SCORE.max(systemNameToScores.values()));
  printBootstrapScoresChart(linkScoresToPrint.build(), EXTRACT_LINKING_BOOTSTRAP_SCORES,
      medianScores, out);
  return teamScores;
}
 
Example 4
Source File: EREAligner.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private static ImmutableList<ResponseToEREAlignmentRule> createResponseMatchingStrategy(
    Optional<CoreNLPDocument> coreNLPDoc) {
  final ImmutableList.Builder<ResponseToEREAlignmentRule> ret = ImmutableList.builder();

  // if a CoreNLP analysis is available, we can use it to compute heads for both system and ERE
  // objects.
  final Function<Response, OffsetRange<CharOffset>> responseComputedHead;
  final Function<CandidateAlignmentTarget, OffsetRange<CharOffset>> ereComputedHead;
  if (coreNLPDoc.isPresent()) {
    final CoreNLPHeadExtractor coreNLPHeadExtractor = CoreNLPHeadExtractor.of(coreNLPDoc.get());
    responseComputedHead = Functions.compose(coreNLPHeadExtractor, CasExtractor.INSTANCE);
    ereComputedHead = Functions.compose(coreNLPHeadExtractor, ERE_HEAD_IF_DECLARED);
  } else {
    responseComputedHead = CasExtractor.INSTANCE;
    ereComputedHead = ERE_HEAD_IF_DECLARED;
  }

  ret.addAll(ImmutableList.of(
      // response CAS matches ERE extent exactly
      new SpansMatchExactly(CasExtractor.INSTANCE, offsets()),
      // response CAS matches ERE declared head exactly
      new SpansMatchExactly(CasExtractor.INSTANCE, ERE_HEAD_IF_DECLARED),
      // response CAS matches ERE computed head exactly
      new SpansMatchExactly(CasExtractor.INSTANCE, ereComputedHead),
      // response CAS head matches ERE extent exactly
      new SpansMatchExactly(responseComputedHead, offsets()),
      // response CAS head matches ERE declared head exactly
      new SpansMatchExactly(responseComputedHead, ERE_HEAD_IF_DECLARED),
      // response CAS head matches ERE computed head exactly
      new SpansMatchExactly(responseComputedHead, ereComputedHead),
      // finally we do a more aggressive alignment attempt by containment
      new ContainmentSpanChecker(CasExtractor.INSTANCE, responseComputedHead)
  ));
  return ret.build();
}
 
Example 5
Source File: CircusTrain.java    From circus-train with Apache License 2.0 4 votes vote down vote up
@Profile({ Modules.REPLICATION })
@Bean
Function<Path, String> checksumFunction(HiveConf sourceHiveConf) {
  return Functions.compose(new PathDigest(), new PathToPathMetadata(sourceHiveConf));
}
 
Example 6
Source File: Functionals.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** applies f1 to the input, then the result of that is passed to f2 (note opposite semantics to {@link Functions#compose(Function, Function)} */ 
public static <A,B,C> Function<A,C> chain(final Function<A,? extends B> f1, final Function<B,C> f2) {
    return Functions.compose(f2, f1);
}
 
Example 7
Source File: CollectionFunctionals.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static <K> Function<Map<K, ?>, Integer> mapSize(Integer valueIfNull) {
    return Functions.compose(CollectionFunctionals.sizeFunction(valueIfNull), CollectionFunctionals.<K>keys());
}