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

The following examples show how to use com.google.common.base.Functions#identity() . 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: DurableStorageTest.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Test
public void testMutateTasks() throws Exception {
  String taskId = "fred";
  Function<IScheduledTask, IScheduledTask> mutation = Functions.identity();
  Optional<IScheduledTask> mutated = Optional.of(task("a", ScheduleStatus.STARTING));
  new AbstractMutationFixture() {
    @Override
    protected void setupExpectations() throws Exception {
      storageUtil.expectWrite();
      expect(storageUtil.taskStore.mutateTask(taskId, mutation)).andReturn(mutated);
      expectPersist(Op.saveTasks(new SaveTasks(ImmutableSet.of(mutated.get().newBuilder()))));
    }

    @Override
    protected void performMutations(MutableStoreProvider storeProvider) {
      assertEquals(mutated, storeProvider.getUnsafeTaskStore().mutateTask(taskId, mutation));
    }
  }.run();
}
 
Example 2
Source File: ProguardTranslatorFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
private Function<String, String> createFunction(
    final boolean isForObfuscation, final boolean isNullable) {
  if (!rawMap.isPresent()) {
    return Functions.identity();
  }

  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);
  }
  Map<String, String> map = builder.build();

  return input -> {
    String mapped = map.get(input);
    if (isNullable || mapped != null) {
      return mapped;
    } else {
      return input;
    }
  };
}
 
Example 3
Source File: ImportSystemOutputToAnnotationStore.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private static Function<DocumentSystemOutput, DocumentSystemOutput> getSystemOutputFilter(
    Parameters params) {
  final Function<DocumentSystemOutput, DocumentSystemOutput> filter;
  if (params.getBoolean("importOnlyBestAnswers")) {
    filter = KeepBestJustificationOnly.asFunctionOnSystemOutput();
    log.info("Importing only responses the scorer would select");
  } else {
    filter = Functions.identity();
    log.info("Importing all responses");
  }
  return filter;
}
 
Example 4
Source File: DependentConfiguration.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private void validate() {
    checkNotNull(source, "Entity source");
    checkNotNull(sensor, "Sensor");
    if (readiness == null) readiness = JavaGroovyEquivalents.groovyTruthPredicate();
    if (postProcess == null) postProcess = (Function) Functions.identity();
}
 
Example 5
Source File: TextReplacerContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TextSegmentSet<ITextReplacement> createTextReplacementsSet() {
	return new ArrayListTextSegmentSet<ITextReplacement>(Functions.<ITextReplacement>identity(),
			new Function<ITextReplacement, String>() {
				@Override
				public String apply(ITextReplacement input) {
					return input.getReplacementText();
				}
			}, getDocument().getRequest().isEnableDebugTracing());
}
 
Example 6
Source File: DurableStorageTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaveAndMutateTasksNoCoalesceUniqueIds() throws Exception {
  String taskId = "fred";
  Function<IScheduledTask, IScheduledTask> mutation = Functions.identity();
  Set<IScheduledTask> saved = ImmutableSet.of(task("b", ScheduleStatus.INIT));
  Optional<IScheduledTask> mutated = Optional.of(task("a", ScheduleStatus.PENDING));

  new AbstractMutationFixture() {
    @Override
    protected void setupExpectations() throws Exception {
      storageUtil.expectWrite();
      storageUtil.taskStore.saveTasks(saved);

      // Nested transaction with result.
      expect(storageUtil.taskStore.mutateTask(taskId, mutation)).andReturn(mutated);

      // Resulting stream operation.
      expectPersist(Op.saveTasks(new SaveTasks(
              ImmutableSet.<ScheduledTask>builder()
                  .addAll(IScheduledTask.toBuildersList(saved))
                  .add(mutated.get().newBuilder())
                  .build())));
    }

    @Override
    protected void performMutations(MutableStoreProvider storeProvider) {
      storeProvider.getUnsafeTaskStore().saveTasks(saved);
      assertEquals(mutated, storeProvider.getUnsafeTaskStore().mutateTask(taskId, mutation));
    }
  }.run();
}
 
Example 7
Source File: LoadMaterializationHandler.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void refreshMetadata(final ReflectionGoal goal, final Materialization materialization) {
  final List<ReflectionField> sortedFields =
    Optional.fromNullable(goal.getDetails().getSortFieldList()).or(ImmutableList.<ReflectionField>of());

  final Function<DatasetConfig, DatasetConfig> datasetMutator;
  if (sortedFields.isEmpty()) {
    datasetMutator = Functions.identity();
  } else {
    datasetMutator = new Function<DatasetConfig, DatasetConfig>() {
      @Override
      public DatasetConfig apply(DatasetConfig datasetConfig) {
        if (datasetConfig.getReadDefinition() == null) {
          logger.warn("Trying to set sortColumnList on a datasetConfig that doesn't contain a read definition");
        } else {
          final List<String> sortColumnsList = FluentIterable.from(sortedFields)
            .transform(new Function<ReflectionField, String>() {
              @Override
              public String apply(ReflectionField field) {
                return field.getName();
              }
            })
            .toList();
          datasetConfig.getReadDefinition().setSortColumnsList(sortColumnsList);
        }
        return datasetConfig;
      }
    };
  }

  context.getCatalogService()
      .getCatalog(MetadataRequestOptions.of(SchemaConfig.newBuilder(SystemUser.SYSTEM_USERNAME).build()))
      .createDataset(new NamespaceKey(getMaterializationPath(materialization)), datasetMutator);
}
 
Example 8
Source File: SequentialActionList.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Builder addAction(StatefulAction action, @Nullable Function<ActionContext, ActionContext> wrapper) {
   Preconditions.checkNotNull(action, "action may not be null");
   if(wrapper == null) {
      wrapper = Functions.<ActionContext>identity();
   }
   actions.add(new Entry(actions.size(), action, wrapper));
   return this;
}
 
Example 9
Source File: ActionList.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Builder addAction(Action action, @Nullable Function<ActionContext, ActionContext> wrapper) {
   Preconditions.checkNotNull(action, "action may not be null");
   if(wrapper == null) {
      wrapper = Functions.<ActionContext>identity();
   }
   actions.add(new Entry(action, wrapper));
   return this;
}
 
Example 10
Source File: KVMutation.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void consolidate() {
    super.consolidate(ENTRY2KEY_FCT, Functions.identity());
}
 
Example 11
Source File: KVMutation.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean isConsolidated() {
    return super.isConsolidated(ENTRY2KEY_FCT, Functions.identity());
}
 
Example 12
Source File: AccumuloFieldIndexIterable.java    From datawave with Apache License 2.0 4 votes vote down vote up
public AccumuloFieldIndexIterable(NestedIterator<Key> tree) {
    this.tree = tree;
    this.func = Functions.identity();
}
 
Example 13
Source File: DriverPredicates.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public static <T> AttributeMatchBuilder<T, Predicate<AttributeMap>> attribute(AttributeKey<T> key) {
   return new AttributeMatchBuilder<T, Predicate<AttributeMap>>(key, Functions.<Predicate<AttributeMap>>identity());
}
 
Example 14
Source File: KVMutation.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public void consolidate() {
    super.consolidate(ENTRY2KEY_FCT, Functions.<StaticBuffer>identity());
}
 
Example 15
Source File: KVMutation.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isConsolidated() {
    return super.isConsolidated(ENTRY2KEY_FCT, Functions.<StaticBuffer>identity());
}
 
Example 16
Source File: ValueCopyAction.java    From OpenModsLib with MIT License 4 votes vote down vote up
public static <T> ValueCopyAction<T, T> create(Object trigger, IValueProvider<T> provider, IValueReceiver<T> receiver) {
	return new ValueCopyAction<>(trigger, provider, receiver, Functions.<T> identity());
}
 
Example 17
Source File: AndroidBinaryMobileInstall.java    From bazel with Apache License 2.0 4 votes vote down vote up
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, TransitionMode.TARGET);
  if (dep == null) {
    ruleContext.attributeError(attribute, "Stub application cannot be found");
    return null;
  }

  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.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;
}
 
Example 18
Source File: TimeWeightedDeltaEnricher.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated since 0.12.0; use {@link EnricherSpec}
 */
@Deprecated
public TimeWeightedDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double> target, int unitMillis) {
    this(producer, source, target, unitMillis, Functions.<Double>identity());
}
 
Example 19
Source File: ValueCopyAction.java    From OpenModsLib with MIT License 4 votes vote down vote up
public static <T> ValueCopyAction<T, T> create(IValueProvider<T> provider, IValueReceiver<T> receiver) {
	return new ValueCopyAction<>(provider, provider, receiver, Functions.<T> identity());
}
 
Example 20
Source File: AnswerableExtractorAligner.java    From tac-kbp-eal with MIT License 4 votes vote down vote up
public static <AnswerableType> AnswerableExtractorAligner<AnswerableType, AnswerableType, AnswerableType> forIdentityMapping() {
  return new AnswerableExtractorAligner<AnswerableType, AnswerableType, AnswerableType>(
      Functions.<AnswerableType>identity(), Functions.<AnswerableType>identity());
}