List of usage examples for com.google.common.base Functions identity
@SuppressWarnings("unchecked") public static <E> Function<E, E> identity()
From source file:brooklyn.util.collections.Jsonya.java
/** as {@link #newInstanceTranslating(Function)} using an identity function * (functionally equivalent to {@link #newInstance()} but explicit about it */ public static Navigator<MutableMap<Object, Object>> newInstanceLiteral() { return newInstanceTranslating(Functions.identity()); }
From source file:com.facebook.buck.io.MoreFiles.java
/** * Recursively copies all files under {@code fromPath} to {@code toPath}. *///from ww w. j a v a 2 s. c o m public static void copyRecursively(final Path fromPath, final Path toPath) throws IOException { copyRecursively(fromPath, toPath, Functions.identity()); }
From source file:com.facebook.buck.io.file.MostFiles.java
/** Recursively copies all files under {@code fromPath} to {@code toPath}. */ public static void copyRecursively(Path fromPath, Path toPath) throws IOException { copyRecursively(fromPath, toPath, Functions.identity()); }
From source file:com.facebook.buck.android.ProguardTranslatorFactory.java
private Function<String, String> createFunction(boolean isForObfuscation) { if (!rawMap.isPresent()) { return Functions.identity(); }// www. ja va 2s . c om ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (Map.Entry<String, String> entry : rawMap.get().entrySet()) { String original = entry.getKey().replace('.', '/'); String obfuscated = entry.getValue().replace('.', '/'); builder.put(isForObfuscation ? original : obfuscated, isForObfuscation ? obfuscated : original); } final Map<String, String> map = builder.build(); return new Function<String, String>() { @Nullable @Override public String apply(@Nullable String input) { Preconditions.checkNotNull(input); String mapped = map.get(input); if (mapped != null) { return mapped; } else { return input; } } }; }
From source file:com.facebook.buck.io.MoreFiles.java
/** * Recursively copies all files under {@code fromPath} to {@code toPath}. *///w w w. j a v a 2 s . c o m public static void copyRecursivelyWithFilter(final Path fromPath, final Path toPath, final Function<Path, Boolean> filter) throws IOException { copyRecursively(fromPath, toPath, Functions.identity(), filter); }
From source file:se.softhouse.common.guavaextensions.Functions2.java
/** * Creates a {@link Function} that applies {@code valueTransformer} to each value of the * input {@link Map} and puts them in a new , immutable, map and returns it. */// w w w. j a va 2 s . com @Nonnull public static <K, V> Function<Map<K, V>, Map<K, V>> mapValueTransformer(Function<V, V> valueTransformer) { if (valueTransformer == Functions.identity()) return Functions.identity(); return new MapValueTransformer<K, V>(valueTransformer); }
From source file:com.isotrol.impe3.api.DeviceInPortal.java
/** * Returns the default transformer.//from w ww . ja v a2s.com * @return The default transformer. */ public Function<PathSegments, PathSegments> getTransformer() { switch (use) { case NONE: return Functions.identity(); case FIRST_SEGMENT: return PathSegmentsTransformers.insert(segment()); case LAST_SEGMENT: return PathSegmentsTransformers.append(segment()); case EXTENSION: return PathSegmentsTransformers.extension(name); default: throw new AssertionError(); } }
From source file:io.druid.extension.lucene.LuceneQueryToolChest.java
@Override public Function<Result<LuceneQueryResultValue>, Result<LuceneQueryResultValue>> makePreComputeManipulatorFn( final LuceneDruidQuery query, final MetricManipulationFn fn) { return Functions.identity(); }
From source file:io.druid.query.scan.ScanQueryQueryToolChest.java
@Override public Function<ScanResultValue, ScanResultValue> makePreComputeManipulatorFn(ScanQuery query, MetricManipulationFn fn) { return Functions.identity(); }
From source file:com.romeikat.datamessie.core.statistics.app.shared.LocalStatisticsManager.java
@Override public StatisticsDto getStatistics(final long projectId, final Integer numberOfDays) { final StatisticsDto dto = new StatisticsDto(); final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(sessionFactory); final Collection<Long> sourceIds = sourceDao.getIds(sessionProvider.getStatelessSession(), projectId, (Boolean) null);/*from w ww . j a va2 s . c o m*/ LocalDate to; LocalDate from; to = LocalDate.now(); from = to.minusDays(ObjectUtils.defaultIfNull(numberOfDays, 0) - 1); final Function<LocalDate, LocalDate> transformDateFunction = Functions.identity(); final StatisticsSparseTable baseStatistics = getBaseStatistics(sessionProvider.getStatelessSession(), sourceIds, from, to); // All documents DocumentProcessingState[] states = DocumentProcessingState .getWithout(DocumentProcessingState.TECHNICAL_ERROR, DocumentProcessingState.TO_BE_DELETED); GetNumberOfDocumentsFunction getNumberOfDocumentsFunction = new GetNumberOfDocumentsFunction(states); final SparseSingleTable<Long, LocalDate, Long> allDocumentsStatistics = statisticsService.getStatistics( baseStatistics, sourceIds, from, to, transformDateFunction, getNumberOfDocumentsFunction); final Function<Pair<Long, Long>, Long> mergeFunction = new Function<Pair<Long, Long>, Long>() { @Override public Long apply(final Pair<Long, Long> from) { return from.getLeft() + from.getRight(); } }; final Long allDocuments = allDocumentsStatistics.mergeAllValues(mergeFunction); dto.setAllDocuments(allDocuments); // Downloaded documents states = DocumentProcessingState.getWithout(DocumentProcessingState.DOWNLOAD_ERROR, DocumentProcessingState.REDIRECTING_ERROR, DocumentProcessingState.TECHNICAL_ERROR); getNumberOfDocumentsFunction = new GetNumberOfDocumentsFunction(states); final SparseSingleTable<Long, LocalDate, Long> downloadedDocumentsStatistics = statisticsService .getStatistics(baseStatistics, sourceIds, from, to, transformDateFunction, getNumberOfDocumentsFunction); final Long downloadedDocuments = downloadedDocumentsStatistics.mergeAllValues(mergeFunction); dto.setDownloadedDocuments(downloadedDocuments); // Preprocessed documents getNumberOfDocumentsFunction = new GetNumberOfDocumentsFunction( DocumentProcessingState.getWith(DocumentProcessingState.STEMMED)); final SparseSingleTable<Long, LocalDate, Long> preprocessedDocumentsStatistics = statisticsService .getStatistics(baseStatistics, sourceIds, from, to, transformDateFunction, getNumberOfDocumentsFunction); final Long preprocessedDocuments = preprocessedDocumentsStatistics.mergeAllValues(mergeFunction); dto.setPreprocessedDocuments(preprocessedDocuments); // Download success final Double downloadSuccess; if (downloadedDocuments == null || allDocuments == null || allDocuments == 0) { downloadSuccess = null; } else { downloadSuccess = (double) downloadedDocuments / (double) allDocuments; } dto.setDownloadSuccess(downloadSuccess); // Preprocessing success getNumberOfDocumentsFunction = new GetNumberOfDocumentsFunction( DocumentProcessingState.getWith(DocumentProcessingState.CLEANED, DocumentProcessingState.CLEANING_ERROR, DocumentProcessingState.STEMMED)); final SparseSingleTable<Long, LocalDate, Long> preprocessingAttemtedDocumentsStatistics = statisticsService .getStatistics(baseStatistics, sourceIds, from, to, transformDateFunction, getNumberOfDocumentsFunction); final Long preprocessingAttemtedDocuments = preprocessingAttemtedDocumentsStatistics .mergeAllValues(mergeFunction); final Double preprocessingSuccess; if (preprocessedDocuments == null || preprocessingAttemtedDocuments == null || preprocessingAttemtedDocuments == 0) { preprocessingSuccess = null; } else { preprocessingSuccess = (double) preprocessedDocuments / (double) preprocessingAttemtedDocuments; } dto.setPreprocessingSuccess(preprocessingSuccess); // Documents to be preprocessed getNumberOfDocumentsFunction = new GetNumberOfDocumentsFunction( DocumentProcessingState.getWith(DocumentProcessingState.DOWNLOADED, DocumentProcessingState.REDIRECTED, DocumentProcessingState.CLEANED)); final SparseSingleTable<Long, LocalDate, Long> documentsToBePreprocessedStatistics = statisticsService .getStatistics(baseStatistics, sourceIds, from, to, transformDateFunction, getNumberOfDocumentsFunction); final Long documentsToBePreprocessed = documentsToBePreprocessedStatistics.mergeAllValues(mergeFunction); dto.setDocumentsToBePreprocessed(documentsToBePreprocessed); // Done sessionProvider.closeStatelessSession(); return dto; }