com.google.common.base.Function.apply()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中com.google.common.base.Function.apply()方法的一些代码示例,展示了Function.apply()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function.apply()方法的具体详情如下:
包路径:com.google.common.base.Function
类名称:Function
方法名:apply

Function.apply介绍

[英]Returns the result of applying this function to input. This method is generally expected, but not absolutely required, to have the following properties:

  • Its execution does not cause any observable side effects.
  • The computation is consistent with equals; that is, Objects#equal (a, b) implies that Objects.equal(function.apply(a),.
    [中]返回将此函数应用于输入的结果。该方法通常具有以下特性,但并非绝对必需:
    *其执行不会造成任何明显的副作用。
    *计算结果与等式一致;也就是说,对象#equal(a,b)意味着对象。相等(函数。应用(a),。

代码示例

代码示例来源:origin: google/guava

@Override
public V load(K key) {
 return computingFunction.apply(checkNotNull(key));
}

代码示例来源:origin: apache/incubator-druid

@Override
@Nullable
public String apply(@Nullable String value)
{
 return extractionFunction.apply(value);
}

代码示例来源:origin: google/guava

/**
 * Returns an immutable map whose keys are the distinct elements of {@code keys} and whose value
 * for each key was computed by {@code valueFunction}. The map's iteration order is the order of
 * the first appearance of each key in {@code keys}.
 *
 * <p>When there are multiple instances of a key in {@code keys}, it is unspecified whether {@code
 * valueFunction} will be applied to more than one instance of that key and, if it is, which
 * result will be mapped to that key in the returned map.
 *
 * @throws NullPointerException if any element of {@code keys} is {@code null}, or if {@code
 *     valueFunction} produces {@code null} for any key
 * @since 14.0
 */
public static <K, V> ImmutableMap<K, V> toMap(
  Iterator<K> keys, Function<? super K, V> valueFunction) {
 checkNotNull(valueFunction);
 // Using LHM instead of a builder so as not to fail on duplicate keys
 Map<K, V> builder = newLinkedHashMap();
 while (keys.hasNext()) {
  K key = keys.next();
  builder.put(key, valueFunction.apply(key));
 }
 return ImmutableMap.copyOf(builder);
}

代码示例来源:origin: apache/incubator-druid

Interval interval = intervalFunction.apply(object.getObject());
VersionType version = versionFunction.apply(object.getObject());
Map<VersionType, TimelineEntry> exists = allTimelineEntries.get(interval);
TimelineEntry entry;
 TreeMap<VersionType, TimelineEntry> versionEntry = new TreeMap<>(versionComparator);
 versionEntry.put(version, entry);
 allTimelineEntries.put(interval, versionEntry);
} else {
 entry = exists.get(version);
  exists.put(version, entry);
 } else {
  PartitionHolder<ObjectType> partitionHolder = entry.getPartitionHolder();

代码示例来源:origin: spotify/helios

public static <K extends Comparable<K>, V> void printMap(final PrintStream out, final String name,
                             final Function<V, String> transform,
                             final Map<K, V> values) {
 out.print(name);
 boolean first = true;
 for (final K key : Ordering.natural().sortedCopy(values.keySet())) {
  if (!first) {
   out.print(Strings.repeat(" ", name.length()));
  }
  final V value = values.get(key);
  out.printf("%s=%s%n", key, transform.apply(value));
  first = false;
 }
 if (first) {
  out.println();
 }
}

代码示例来源:origin: google/guava

public void testForMapWildCardWithDefault() {
 Map<String, Integer> map = Maps.newHashMap();
 map.put("One", 1);
 map.put("Three", 3);
 Number number = Double.valueOf(42);
 Function<String, Number> function = Functions.forMap(map, number);
 assertEquals(1, function.apply("One").intValue());
 assertEquals(number, function.apply("Two"));
 assertEquals(3L, function.apply("Three").longValue());
}

代码示例来源:origin: apache/incubator-druid

@Nullable
 @Override
 public Row apply(Row input)
 {
  Row preRow = preCompute.apply(input);
  if (preRow instanceof MapBasedRow) {
   MapBasedRow preMapRow = (MapBasedRow) preRow;
   Map<String, Object> event = new HashMap<>(preMapRow.getEvent());
   for (String dim : optimizedDims) {
    final Object eventVal = event.get(dim);
    event.put(dim, extractionFnMap.get(dim).apply(eventVal));
   }
   return new MapBasedRow(preMapRow.getTimestamp(), event);
  } else {
   return preRow;
  }
 }
};

代码示例来源:origin: robolectric/robolectric

@Nullable
private <C extends ComponentInfo> C removeComponent(
  ComponentName componentName,
 filtersMap.remove(componentName);
 String packageName = componentName.getPackageName();
 PackageInfo packageInfo = packageInfos.get(packageName);
 if (packageInfo == null) {
  return null;
 C[] components = componentArrayInPackage.apply(packageInfo);
 if (components == null) {
  return null;

代码示例来源:origin: com.atlassian.stash.plugins/stash-source-annotation-support

@Nullable
public File getDataFile(@Nonnull String url) {
  checkNotNull(url, "url");
  String name = metadata.files.get(url);
  return name != null ? toFileInCache().apply(name) : null;
}

代码示例来源:origin: com.atlassian.jira/jira-api

/** Actual cache loading function. */
  @Override
  public Object apply(final CacheKey input)
  {
    final Function<String, Object> propertyAccessFunction = classBasedHandlers.get(input.ofClass);
    Preconditions.checkNotNull(propertyAccessFunction);
    final Object result = propertyAccessFunction.apply(input.key);
    return result == null ? NULL_VALUE : result;
  }
}));

代码示例来源:origin: apache/incubator-druid

@Before
public void setUp() throws Exception
{
 String className = getClass().getName();
 Map<String, Pair<StorageAdapter, Closeable>> adaptersForClass = adapterCache.get().get(className);
 if (adaptersForClass == null) {
  adaptersForClass = new HashMap<>();
  adapterCache.get().put(className, adaptersForClass);
 }
 Pair<StorageAdapter, Closeable> pair = adaptersForClass.get(testName);
 if (pair == null) {
  pair = finisher.apply(
    indexBuilder.tmpDir(temporaryFolder.newFolder()).rows(rows)
  );
  adaptersForClass.put(testName, pair);
 }
 this.adapter = pair.lhs;
}

代码示例来源:origin: robolectric/robolectric

throw new IllegalArgumentException("Component needs a name");
PackageInfo packageInfo = packageInfos.get(packageName);
if (packageInfo == null) {
 packageInfo = new PackageInfo();
 packageInfo.applicationInfo = newComponent.applicationInfo;
 installPackage(packageInfo);
 packageInfo = packageInfos.get(packageName);
C[] components = componentArrayInPackage.apply(packageInfo);
if (components == null) {
 @SuppressWarnings("unchecked")

代码示例来源:origin: apache/incubator-druid

final List<Object> nodeValue = Lists.newArrayListWithExpectedSize(node.size());
 for (final JsonNode subnode : node) {
  final Object subnodeValue = valueFunction.apply(subnode);
  if (subnodeValue != null) {
   nodeValue.add(subnodeValue);
 map.put(StringUtils.toLowerCase(key), nodeValue); // difference from JSONParser parse()
} else {
 final Object nodeValue = valueFunction.apply(node);
 if (nodeValue != null) {
  map.put(StringUtils.toLowerCase(key), nodeValue); // difference from JSONParser parse()

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public Shelf getShelf(long shelfId) throws StatusException {
 synchronized (lock) {
  @Nullable Shelf shelf = shelfInfoToShelf.apply(shelves.get(shelfId));
  if (shelf == null) {
   throw Status.NOT_FOUND
     .withDescription("Unknown shelf ID")
     .asException();
  }
  return shelf;
 }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns an immutable map whose keys are the distinct elements of {@code keys} and whose value
 * for each key was computed by {@code valueFunction}. The map's iteration order is the order of
 * the first appearance of each key in {@code keys}.
 *
 * <p>When there are multiple instances of a key in {@code keys}, it is unspecified whether {@code
 * valueFunction} will be applied to more than one instance of that key and, if it is, which
 * result will be mapped to that key in the returned map.
 *
 * @throws NullPointerException if any element of {@code keys} is {@code null}, or if {@code
 *     valueFunction} produces {@code null} for any key
 * @since 14.0
 */
public static <K, V> ImmutableMap<K, V> toMap(
  Iterator<K> keys, Function<? super K, V> valueFunction) {
 checkNotNull(valueFunction);
 // Using LHM instead of a builder so as not to fail on duplicate keys
 Map<K, V> builder = newLinkedHashMap();
 while (keys.hasNext()) {
  K key = keys.next();
  builder.put(key, valueFunction.apply(key));
 }
 return ImmutableMap.copyOf(builder);
}

代码示例来源:origin: google/guava

@Override
public void forEach(Consumer<? super T> action) {
 checkNotNull(action);
 fromIterable.forEach((F f) -> action.accept(function.apply(f)));
}

代码示例来源:origin: apache/incubator-druid

@Nullable
 @Override
 public String apply(@Nullable String dimValue)
 {
  final String retval = NullHandling.emptyToNullIfNeeded(extractionFunction.apply(dimValue));
  return retval == null
      ? FunctionalExtraction.this.replaceMissingValueWith
      : retval;
 }
};

代码示例来源:origin: linkedin/indextank-engine

public V apply(K key) {
    if (!cache.containsKey(key)) {
      cache.put(key, function.apply(key));
    }
    return cache.get(key);
  }
};

代码示例来源:origin: apache/incubator-druid

@Override
public Object compute(Map<String, Object> values)
{
 // Maps.transformEntries is lazy, will only finalize values we actually read.
 final Map<String, Object> finalizedValues = Maps.transformEntries(
   values,
   (String k, Object v) -> {
    final Function<Object, Object> finalizer = finalizers.get(k);
    return finalizer != null ? finalizer.apply(v) : v;
   }
 );
 return parsed.eval(Parser.withMap(finalizedValues)).value();
}

代码示例来源:origin: apache/incubator-druid

ShardSpec shard = converter.apply(obj);
boolean include = true;
   filterDomain.put(dimension, optFilterRangeSet.get());

相关文章