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

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

Introduction

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

Prototype


@SuppressWarnings("unchecked")
public static <E> Function<E, E> identity() 

Source Link

Document

Returns the identity function.

Usage

From source file:org.lenskit.data.entities.Entities.java

/**
 * Create a projection function that maps entities to a new view.
 * @param viewClass The target view class type.
 * @param <E> The entity type./*from   www  . j a  va  2  s. c om*/
 * @return A function that will project entities.
 */
@SuppressWarnings("unchecked")
public static <E extends Entity> Function<Entity, E> projection(final Class<E> viewClass) {
    if (viewClass.equals(Entity.class)) {
        return (Function) Functions.identity();
    } else {
        return new Function<Entity, E>() {
            @Nullable
            @Override
            public E apply(@Nullable Entity input) {
                assert input != null;
                return project(input, viewClass);
            }
        };
    }
}

From source file:com.metamx.druid.query.metadata.SegmentMetadataQueryQueryToolChest.java

@Override
public Function<SegmentAnalysis, SegmentAnalysis> makeMetricManipulatorFn(SegmentMetadataQuery query,
        MetricManipulationFn fn) {
    return Functions.identity();
}

From source file:org.apache.druid.query.metadata.SegmentMetadataQueryQueryToolChest.java

@Override
public Function<SegmentAnalysis, SegmentAnalysis> makePreComputeManipulatorFn(SegmentMetadataQuery query,
        MetricManipulationFn fn) {
    return Functions.identity();
}

From source file:org.apache.cassandra.db.lifecycle.View.java

static Function<View, View> updateLiveSet(final Set<SSTableReader> remove, final Iterable<SSTableReader> add) {
    if (remove.isEmpty() && Iterables.isEmpty(add))
        return Functions.identity();
    return new Function<View, View>() {
        public View apply(View view) {
            Map<SSTableReader, SSTableReader> sstableMap = replace(view.sstablesMap, remove, add);
            return new View(view.liveMemtables, view.flushingMemtables, sstableMap, view.compacting,
                    SSTableIntervalTree.build(sstableMap.keySet()));
        }/*from  w w  w. j  a v a  2 s.c  o m*/
    };
}

From source file:org.apache.druid.query.groupby.orderby.DefaultLimitSpec.java

@Override
public Function<Sequence<Row>, Sequence<Row>> build(List<DimensionSpec> dimensions,
        List<AggregatorFactory> aggs, List<PostAggregator> postAggs, Granularity granularity,
        boolean sortByDimsFirst) {
    // Can avoid re-sorting if the natural ordering is good enough.

    boolean sortingNeeded = dimensions.size() < columns.size();

    final Set<String> aggAndPostAggNames = Sets.newHashSet();
    for (AggregatorFactory agg : aggs) {
        aggAndPostAggNames.add(agg.getName());
    }// w  ww . j  a v a2 s .c  o m
    for (PostAggregator postAgg : postAggs) {
        aggAndPostAggNames.add(postAgg.getName());
    }

    if (!sortingNeeded) {
        for (int i = 0; i < columns.size(); i++) {
            final OrderByColumnSpec columnSpec = columns.get(i);

            if (aggAndPostAggNames.contains(columnSpec.getDimension())) {
                sortingNeeded = true;
                break;
            }

            final ValueType columnType = getOrderByType(columnSpec, dimensions);
            final StringComparator naturalComparator;
            if (columnType == ValueType.STRING) {
                naturalComparator = StringComparators.LEXICOGRAPHIC;
            } else if (ValueType.isNumeric(columnType)) {
                naturalComparator = StringComparators.NUMERIC;
            } else {
                sortingNeeded = true;
                break;
            }

            if (columnSpec.getDirection() != OrderByColumnSpec.Direction.ASCENDING
                    || !columnSpec.getDimensionComparator().equals(naturalComparator)
                    || !columnSpec.getDimension().equals(dimensions.get(i).getOutputName())) {
                sortingNeeded = true;
                break;
            }
        }
    }

    if (!sortingNeeded) {
        // If granularity is ALL, sortByDimsFirst doesn't change the sorting order.
        sortingNeeded = !granularity.equals(Granularities.ALL) && sortByDimsFirst;
    }

    if (!sortingNeeded) {
        return isLimited() ? new LimitingFn(limit) : Functions.identity();
    }

    // Materialize the Comparator first for fast-fail error checking.
    final Ordering<Row> ordering = makeComparator(dimensions, aggs, postAggs, sortByDimsFirst);

    if (isLimited()) {
        return new TopNFunction(ordering, limit);
    } else {
        return new SortingFn(ordering);
    }
}

From source file:com.google.devtools.build.skydoc.SkydocMain.java

/**
 * Evaluates/interprets the skylark file at the given input source using a fake build API and
 * collects information about all rule definitions made in that file.
 *
 * @param parserInputSource the input source representing the input skylark file
 * @param ruleInfoMap a map builder to be populated with rule definition information for
 *     named rules. Keys are exported names of rules, and values are their {@link RuleInfo}
 *     rule descriptions. For example, 'my_rule = rule(...)' has key 'my_rule'
 * @param unexportedRuleInfos a list builder to be populated with rule definition information
 *     for rules which were not exported as top level symbols
 * @throws InterruptedException if evaluation is interrupted
 *///from  www  .  j  ava2s.c o m
// TODO(cparsons): Evaluate load statements recursively.
public void eval(ParserInputSource parserInputSource, ImmutableMap.Builder<String, RuleInfo> ruleInfoMap,
        ImmutableList.Builder<RuleInfo> unexportedRuleInfos) throws InterruptedException {
    List<RuleInfo> ruleInfoList = new ArrayList<>();

    BuildFileAST buildFileAST = BuildFileAST.parseSkylarkFile(parserInputSource, eventHandler);

    Environment env = createEnvironment(eventHandler, globalFrame(ruleInfoList),
            /* imports= */ ImmutableMap.of());

    if (!buildFileAST.exec(env, eventHandler)) {
        throw new RuntimeException("Error loading file");
    }

    env.mutability().freeze();

    Map<BaseFunction, RuleInfo> ruleFunctions = ruleInfoList.stream()
            .collect(Collectors.toMap(RuleInfo::getIdentifierFunction, Functions.identity()));

    for (Entry<String, Object> envEntry : env.getGlobals().getBindings().entrySet()) {
        if (ruleFunctions.containsKey(envEntry.getValue())) {
            ruleInfoMap.put(envEntry.getKey(), ruleFunctions.get(envEntry.getValue()));
            ruleFunctions.remove(envEntry.getValue());
        }
    }

    unexportedRuleInfos.addAll(ruleFunctions.values());
}

From source file:com.eucalyptus.util.CollectionUtils.java

/**
 * Unchecked cast function./*  w  ww . j  ava  2s  .co m*/
 *
 * @param target The type to cast to
 * @param <F> The source type
 * @param <T> The result type
 * @return A function that casts to the given type
 * @see Predicates#instanceOf(Class)
 * @see Iterables#filter(Iterable, Class)
 */
public static <F, T> Function<F, T> cast(final Class<T> target) {
    //noinspection unchecked
    return (Function<F, T>) Functions.identity();
}

From source file:bear.context.AbstractContext.java

public AbstractContext convertAndPutConst(String name, String value, Class<?> type) {
    Function<String, ?> converter;

    if (type == null) {
        converter = Functions.identity();
    } else {/*from www . j a v a 2 s.c om*/
        converter = getConverter(type);
    }

    Preconditions.checkNotNull(converter,
            "converter not found for type: " + (type == null ? null : type.getSimpleName()));

    return putConst(name, converter.apply(value));
}

From source file:com.facebook.buck.rules.SourcePathResolver.java

/**
 * Resolved the logical names for a group of SourcePath objects into a map, throwing an
 * error on duplicates./* w  w  w.  java  2  s  .c o m*/
 */
public ImmutableMap<String, SourcePath> getSourcePathNames(BuildTarget target, String parameter,
        Iterable<SourcePath> sourcePaths) {
    return getSourcePathNames(target, parameter, sourcePaths, Functions.identity());
}

From source file:com.github.errantlinguist.latticevisualiser.LatticeVisualiser.java

/**
 * Creates an {@link ImmutableSet} of non-word labels from a given infile.
 * //from w w w.  j a  v a  2s.c  om
 * @param infile
 *            The {@link File} to read.
 * @return An {@link ImmutableSet} of symbols representing non-word labels.
 * @throws IOException
 *             If the input {@link File} object does not refer to a valid
 *             file or another I/O error occurs.
 * @throws com.github.errantlinguist.parsers.ParseException
 *             If there is an error parsing the contents of the file.
 */
private static ImmutableSet<String> readNonwordLabelSet(final File infile)
        throws IOException, com.github.errantlinguist.parsers.ParseException {
    final Function<String, String> identityFunction = Functions.identity();
    final ImmutableSetFileParser<String> fileParser = new ImmutableSetFileParser<String>(identityFunction);
    final FileLineReader<String, ImmutableSet<String>> fileReader = fileParser.createFileReader();

    final ImmutableSet<String> nonwords = fileReader.readFile(infile);
    return nonwords;
}