Example usage for com.google.common.base Functions compose

List of usage examples for com.google.common.base Functions compose

Introduction

In this page you can find the example usage for com.google.common.base Functions compose.

Prototype

public static <A, B, C> Function<A, C> compose(Function<B, C> g, Function<A, ? extends B> f) 

Source Link

Document

Returns the composition of two functions.

Usage

From source file:com.sk89q.worldedit.world.biome.Biomes.java

/**
 * Find a biome that matches the given input name.
 *
 * @param biomes a list of biomes//from w  w w .  java 2  s.c om
 * @param name the name to test
 * @param registry a biome registry
 * @return a biome or null
 */
@Nullable
public static BaseBiome findBiomeByName(Collection<BaseBiome> biomes, String name, BiomeRegistry registry) {
    checkNotNull(biomes);
    checkNotNull(name);
    checkNotNull(registry);

    Function<String, ? extends Number> compare = new LevenshteinDistance(name, false,
            LevenshteinDistance.STANDARD_CHARS);
    WeightedChoice<BaseBiome> chooser = new WeightedChoice<BaseBiome>(
            Functions.compose(compare, new BiomeName(registry)), 0);
    for (BaseBiome biome : biomes) {
        chooser.consider(biome);
    }
    Optional<Choice<BaseBiome>> choice = chooser.getChoice();
    if (choice.isPresent() && choice.get().getScore() <= 1) {
        return choice.get().getValue();
    } else {
        return null;
    }
}

From source file:org.nickelproject.nickel.dataflow.Collector.java

public static <S, T, X, Y, V> Collector<S, V> create(final Function<S, T> preFunctor,
        final Collector<T, Y> collector, final Function<Y, V> postFunctor) {
    @SuppressWarnings("unchecked")
    final CollectorBase<T, X, Y> wrapped = (CollectorBase<T, X, Y>) collector.collectorBase;
    final Function<S, X> newPreFunction = Functions.compose(wrapped.preFunctor, preFunctor);
    final Function<X, V> newPostFunction = Functions.compose(postFunctor, wrapped.postFunctor);
    return new Collector<S, V>(new CollectorBase<S, X, V>(newPreFunction, wrapped.reducer, newPostFunction));
}

From source file:com.google.cloud.bigtable.hbase.adapters.read.DefaultReadHooks.java

/** {@inheritDoc} */
@Override/* w w  w.jav a2s .  c om*/
public void composePreSendHook(Function<ReadRowsRequest, ReadRowsRequest> newHook) {
    preSendHook = Functions.compose(newHook, preSendHook);
}

From source file:com.eucalyptus.auth.ws.EuareRequestLoggingFilter.java

private static Iterable<String> buildActionNVPs(final String action) {
    return Iterables.unmodifiableIterable(Iterables.transform(Arrays.asList(OperationParameter.values()),
            Functions.compose(Strings.append("=" + action), Functions.toStringFunction())));
}

From source file:pl.nort.dayoneevernote.transformer.NoteTransformerBeansConfig.java

@Bean
public Function<Note, Note> defaultTransformerChain() {
    Function<Note, Note> extractDateFromTitle = new ExtractDateFromTitleTransformer(
            "[1-2][0-9]{3}/[01][0-9]/[0-3][0-9]", "yyyy/MM/dd");

    Function<Note, Note> dropTitle = new DropTitleTransformer();

    Function<Note, Note> shiftHours = new ShiftDateTransformer(19);

    return Functions.compose(shiftHours, Functions.compose(dropTitle, extractDateFromTitle));
}

From source file:com.github.jonross.seq4j.Fns.java

/** @see Functions#compose(Function, Function) */
public static <A, B, C> Function<A, C> compose(Function<B, C> g, Function<A, ? extends B> f) {
    return Functions.compose(g, f);
}

From source file:org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConfiguration.java

void setFields(Map<String, Field> fields) {
    Function<Field, String> getName = new Function<Field, String>() {
        public String apply(Field item) {
            return item.getName();
        }//from  w  w  w .  j a  v  a 2  s . co m
    };
    Function<String, String> comparatorFunction = Functions.compose(getName, Functions.forMap(fields));
    Ordering<String> comparator = Ordering.natural().onResultOf(comparatorFunction);
    this.fields = ImmutableSortedMap.copyOf(fields, comparator);
}

From source file:org.nickelproject.util.sources.S3MultiFileSource.java

public static RecordSource getS3MultiFileSource(final String bucketName, final String key,
        final RecordDataType schema) {
    return new RecordSource(Sources.concat(Sources.transform(getS3BucketEntries(bucketName, key),
            Functions.compose(asCsvRecords(schema), s3InputStream(bucketName)))), schema);
}

From source file:edu.harvard.med.screensaver.model.libraries.LibraryPlate.java

public LibraryPlate(Integer plateNumber, Library library, Set<AssayPlate> assayPlates) {
    super(plateNumber);

    _library = library;// w w w.  j  av a 2 s.c  o m
    _assayPlateCount = assayPlates.size();
    Iterable<AssayPlate> assayPlatesUniqueAttempts = Iterables.filter(assayPlates, AssayPlate.IsFirstReplicate);
    _copiesScreened = Sets
            .newTreeSet(Iterables.transform(Iterables.filter(assayPlates, AssayPlate.HasLibraryScreening),
                    Functions.compose(Plate.ToCopy, AssayPlate.ToPlate)));
    _libraryScreenings = Sets.newTreeSet(
            Iterables.filter(Iterables.transform(assayPlatesUniqueAttempts, AssayPlate.ToLibraryScreening),
                    Predicates.notNull()));
    if (!_libraryScreenings.isEmpty()) {
        _firstDateScreened = _libraryScreenings.first().getDateOfActivity();
        _lastDateScreened = _libraryScreenings.last().getDateOfActivity();
    }
    SortedSet<AdministrativeActivity> dataLoadings = Sets.newTreeSet(Iterables.filter(
            Iterables.transform(assayPlatesUniqueAttempts, AssayPlate.ToScreenResultDataLoading),
            Predicates.notNull()));
    _dataLoadingCount = dataLoadings.size();
    if (_dataLoadingCount > 0) {
        _firstDateDataLoaded = dataLoadings.first().getDateOfActivity();
        _lastDateDataLoaded = dataLoadings.last().getDateOfActivity();
    }
}

From source file:com.persinity.ndt.dbagent.relational.impl.ClogMountFunctor.java

@Override
public Function<RelDb, RelDb> apply(final String tableName) {
    final String clogTableName = schema.getClogTableName(tableName);
    final String sqlCreate = strategy.createTable(clogTableName, schema.getClogTableCols(tableName),
            SchemaInfo.COL_GID);//  w w  w  .  ja  va2 s  .co  m
    final RelFunc clogCreate = new RelFunc(sqlCreate);

    final String sqlIndex = strategy.createIndex(clogTableName, SchemaInfo.COL_TID);
    final RelFunc clogIndex = new RelFunc(sqlIndex);

    final Function<RelDb, RelDb> clogFunc = Functions.compose(clogIndex, clogCreate);
    return clogFunc;
}