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.nmdp.service.epitope.EpitopeServiceTestData.java

public static Function<String, String> getTestGlStringFilter() {
    return Functions.identity();
}

From source file:com.eucalyptus.entities.Transactions.java

public static <T> List<T> filter(T search, Predicate<? super T> condition) throws TransactionException {
    Function<T, T> f = Functions.identity();
    return filteredTransform(search, condition, f);
}

From source file:com.eucalyptus.entities.Transactions.java

public static <T> List<T> filter(final T search, final Predicate<? super T> condition,
        final Criterion criterion, final Map<String, String> aliases) throws TransactionException {
    Function<T, T> f = Functions.identity();
    return filteredTransform(search, criterion, aliases, condition, f);
}

From source file:net.derquinse.common.jaxrs.PathSegments.java

/**
 * Returns a new transformer that inserts this segments at the beginning of the provided path.
 * @return The requested transformer.//from   www. j a va 2  s.com
 */
public Function<PathSegments, PathSegments> inserter() {
    if (isEmpty()) {
        return Functions.identity();
    }
    return new Inserter();
}

From source file:org.apache.druid.query.groupby.GroupByQueryQueryToolChest.java

@Override
public Function<Row, Row> makePreComputeManipulatorFn(final GroupByQuery query, final MetricManipulationFn fn) {
    if (MetricManipulatorFns.identity().equals(fn)) {
        return Functions.identity();
    }/*from  w  w w  .  ja  va  2  s .  c om*/

    return new Function<Row, Row>() {
        @Override
        public Row apply(Row input) {
            if (input instanceof MapBasedRow) {
                final MapBasedRow inputRow = (MapBasedRow) input;
                final Map<String, Object> values = Maps.newHashMap(inputRow.getEvent());
                for (AggregatorFactory agg : query.getAggregatorSpecs()) {
                    values.put(agg.getName(), fn.manipulate(agg, inputRow.getEvent().get(agg.getName())));
                }
                return new MapBasedRow(inputRow.getTimestamp(), values);
            }
            return input;
        }
    };
}

From source file:com.google.devtools.build.lib.rules.android.DexArchiveAspect.java

/**
 * Runs Jars in {@link JavaRuntimeJarProvider} through desugaring action if flag is set and adds
 * the result to {@code result}. Note that this cannot happen in a separate aspect because aspects
 * don't see providers added by other aspects executed on the same target.
 *//*from   w  w w. j  a v  a 2 s .  c  om*/
private Function<Artifact, Artifact> desugarJarsIfRequested(ConfiguredTarget base, RuleContext ruleContext,
        ConfiguredAspect.Builder result) {
    if (!getAndroidConfig(ruleContext).desugarJava8()) {
        return Functions.identity();
    }
    Map<Artifact, Artifact> newlyDesugared = new HashMap<>();
    if (JavaCommon.isNeverLink(ruleContext)) {
        result.addProvider(AndroidRuntimeJarProvider.NEVERLINK);
        return Functions.forMap(newlyDesugared);
    }
    AndroidRuntimeJarProvider.Builder desugaredJars = new AndroidRuntimeJarProvider.Builder()
            .addTransitiveProviders(collectPrerequisites(ruleContext, AndroidRuntimeJarProvider.class));
    JavaRuntimeJarProvider jarProvider = base.getProvider(JavaRuntimeJarProvider.class);
    if (jarProvider != null) {
        // These are all transitive hjars of dependencies and hjar of the jar itself
        NestedSet<Artifact> compileTimeClasspath = base.getProvider(JavaCompilationArgsProvider.class) // aspect definition requires this
                .getRecursiveJavaCompilationArgs().getCompileTimeJars();
        // For android_* targets we need to honor their bootclasspath (nicer in general to do so)
        ImmutableList<Artifact> bootclasspath = getBootclasspath(base, ruleContext);

        boolean basenameClash = checkBasenameClash(jarProvider.getRuntimeJars());
        for (Artifact jar : jarProvider.getRuntimeJars()) {
            Artifact desugared = createDesugarAction(ruleContext, basenameClash, jar, bootclasspath,
                    compileTimeClasspath);
            newlyDesugared.put(jar, desugared);
            desugaredJars.addDesugaredJar(jar, desugared);
        }
    }
    result.addProvider(desugaredJars.build());
    return Functions.forMap(newlyDesugared);
}

From source file:net.derquinse.common.jaxrs.PathSegments.java

/**
 * Returns a new transformer that appends this segments to the provided path.
 * @return The requested transformer.//from w ww.ja  v  a2  s  .  c  o  m
 */
public Function<PathSegments, PathSegments> appender() {
    if (isEmpty()) {
        return Functions.identity();
    }
    return new Appender();
}

From source file:com.google.devtools.build.lib.rules.android.AndroidBinaryMobileInstall.java

private static Artifact getStubDex(RuleContext ruleContext, JavaSemantics javaSemantics, boolean split)
        throws InterruptedException {
    String attribute = split ? "$incremental_split_stub_application" : "$incremental_stub_application";

    TransitiveInfoCollection dep = ruleContext.getPrerequisite(attribute, Mode.TARGET);
    if (dep == null) {
        ruleContext.attributeError(attribute, "Stub application cannot be found");
        return null;
    }/*from  w  ww .jav a  2s.co  m*/

    JavaCompilationArgsProvider provider = JavaInfo.getProvider(JavaCompilationArgsProvider.class, dep);
    if (provider == null) {
        ruleContext.attributeError(attribute, "'" + dep.getLabel() + "' should be a Java target");
        return null;
    }

    JavaTargetAttributes attributes = new JavaTargetAttributes.Builder(javaSemantics)
            .addRuntimeClassPathEntries(provider.getJavaCompilationArgs().getRuntimeJars()).build();

    Function<Artifact, Artifact> desugaredJars = Functions.identity();
    if (AndroidCommon.getAndroidConfig(ruleContext).desugarJava8()) {
        desugaredJars = AndroidBinary
                .collectDesugaredJarsFromAttributes(ruleContext, ImmutableList.of(attribute)).build()
                .collapseToFunction();
    }
    Artifact stubDeployJar = getMobileInstallArtifact(ruleContext,
            split ? "split_stub_deploy.jar" : "stub_deploy.jar");
    new DeployArchiveBuilder(javaSemantics, ruleContext).setOutputJar(stubDeployJar).setAttributes(attributes)
            .setDerivedJarFunction(desugaredJars)
            .setCheckDesugarDeps(AndroidCommon.getAndroidConfig(ruleContext).checkDesugarDeps()).build();

    Artifact stubDex = getMobileInstallArtifact(ruleContext,
            split ? "split_stub_application/classes.dex" : "stub_application/classes.dex");
    AndroidCommon.createDexAction(ruleContext, stubDeployJar, stubDex, ImmutableList.<String>of(), false, null);

    return stubDex;
}

From source file:org.opencms.workplace.tools.modules.CmsCloneModuleThread.java

/**
 * Adjusts the module configuration file and the formatter configurations.<p>
 *
 * @param targetModule the target module
 * @param resTypeMap the resource type mapping
 *
 * @throws CmsException if something goes wrong
 * @throws UnsupportedEncodingException if the file content could not be read with the determined encoding
 *//*from  w  w w . j a va 2  s .  c om*/
private void adjustConfigs(CmsModule targetModule, Map<I_CmsResourceType, I_CmsResourceType> resTypeMap)
        throws CmsException, UnsupportedEncodingException {

    String modPath = CmsWorkplace.VFS_PATH_MODULES + targetModule.getName() + "/";
    CmsObject cms = getCms();
    if (((m_cloneInfo.getSourceNamePrefix() != null) && (m_cloneInfo.getTargetNamePrefix() != null))
            || !m_cloneInfo.getSourceNamePrefix().equals(m_cloneInfo.getTargetNamePrefix())) {
        // replace resource type names in formatter configurations
        List<CmsResource> resources = cms.readResources(modPath, CmsResourceFilter.requireType(OpenCms
                .getResourceManager().getResourceType(CmsFormatterConfigurationCache.TYPE_FORMATTER_CONFIG)));
        String source = "<Type><!\\[CDATA\\[" + m_cloneInfo.getSourceNamePrefix();
        String target = "<Type><!\\[CDATA\\[" + m_cloneInfo.getTargetNamePrefix();
        Function<String, String> replaceType = new ReplaceAll(source, target);

        for (CmsResource resource : resources) {
            transformResource(resource, replaceType);
        }
        resources.clear();
    }

    // replace resource type names in module configuration
    try {
        CmsResource config = cms.readResource(modPath + CmsADEManager.CONFIG_FILE_NAME, CmsResourceFilter
                .requireType(OpenCms.getResourceManager().getResourceType(CmsADEManager.MODULE_CONFIG_TYPE)));
        Function<String, String> substitution = Functions.identity();
        // compose the substitution functions from simple substitution functions for each type

        for (Map.Entry<I_CmsResourceType, I_CmsResourceType> mapping : resTypeMap.entrySet()) {
            substitution = Functions.compose(
                    new ReplaceAll(mapping.getKey().getTypeName(), mapping.getValue().getTypeName()),
                    substitution);
        }

        // Either replace prefix in or prepend it to the folder name value

        Function<String, String> replaceFolderName = new ReplaceAll(
                "(<Folder>[ \n]*<Name><!\\[CDATA\\[)(" + m_cloneInfo.getSourceNamePrefix() + ")?",
                "$1" + m_cloneInfo.getTargetNamePrefix());
        substitution = Functions.compose(replaceFolderName, substitution);
        transformResource(config, substitution);
    } catch (CmsVfsResourceNotFoundException e) {
        LOG.info(e.getLocalizedMessage(), e);
    }
}

From source file:com.eucalyptus.compute.vpc.VpcWorkflow.java

/**
 * WARNING, route states here must be consistent with those calculated in NetworkInfoBroadcasts
 *///from   w w  w  . j a  v  a  2 s  . co  m
private void routeStateCheck() {
    final List<RouteKey> keysToProcess = routesToCheck.stream().limit(500).collect(Collectors.toList());
    routesToCheck.removeAll(keysToProcess);
    for (final RouteKey routeKey : keysToProcess) {
        try (final TransactionResource tx = Entities.transactionFor(RouteTable.class)) {
            final RouteTable routeTable = routeTables.lookupByName(null, routeKey.getRouteTableId(),
                    Functions.identity());
            final java.util.Optional<Route> routeOptional = routeTable.getRoutes().stream()
                    .filter(route -> route.getDestinationCidr().equals(routeKey.getCidr())).findFirst();
            if (routeOptional.isPresent()) {
                final Route route = routeOptional.get();
                Route.State newState = route.getState();
                if (route.getInternetGatewayId() != null) { // Internet gateway route
                    try {
                        final InternetGateway internetGateway = internetGateways.lookupByName(null,
                                route.getInternetGatewayId(), Functions.identity());
                        newState = internetGateway.getVpc() != null ? Route.State.active
                                : Route.State.blackhole;
                    } catch (final VpcMetadataNotFoundException e) {
                        newState = Route.State.blackhole;
                    }
                } else if (route.getNatGatewayId() != null) { // NAT gateway route
                    try {
                        final NatGateway natGateway = natGateways.lookupByName(null, route.getNatGatewayId(),
                                Functions.identity());
                        newState = natGateway.getState() == NatGateway.State.available ? Route.State.active
                                : Route.State.blackhole;
                    } catch (final VpcMetadataNotFoundException e) {
                        newState = Route.State.blackhole;
                    }
                } else if (route.getNetworkInterfaceId() != null) { // NAT instance route
                    try {
                        final NetworkInterface eni = networkInterfaces.lookupByName(null,
                                route.getNetworkInterfaceId(), Functions.identity());
                        if (!eni.isAttached()) {
                            if (route.getInstanceId() != null || route.getInstanceAccountNumber() != null) {
                                route.setInstanceId(null);
                                route.setInstanceAccountNumber(null);
                                routeTable.updateTimeStamps();
                            }
                            newState = Route.State.blackhole;
                        } else {
                            if (!eni.getInstance().getInstanceId().equals(route.getInstanceId())) {
                                route.setInstanceId(eni.getInstance().getInstanceId());
                                route.setInstanceAccountNumber(eni.getInstance().getOwnerAccountNumber());
                                routeTable.updateTimeStamps();
                            }
                            newState = VmInstance.VmState.RUNNING.apply(eni.getInstance()) ? Route.State.active
                                    : Route.State.blackhole;
                        }
                    } catch (final VpcMetadataNotFoundException e) {
                        if (route.getInstanceId() != null) {
                            route.setInstanceId(null);
                            route.setInstanceAccountNumber(null);
                            routeTable.updateTimeStamps();
                        }
                        newState = Route.State.blackhole;
                    }
                } // else local route, always active
                if (route.getState() != newState) {
                    route.setState(newState);
                    routeTable.updateTimeStamps();
                }
            }
            tx.commit();
        } catch (final VpcMetadataNotFoundException e) {
            logger.debug("Route table not found checking route state for " + routeKey);
        } catch (Exception e) {
            if (PersistenceExceptions.isStaleUpdate(e)) {
                logger.debug("Conflict checking route state for " + routeKey + " (will retry)");
            } else {
                logger.error("Error checking route state for " + routeKey, e);
            }
        }
    }
}