当前位置: 首页>>代码示例>>Java>>正文


Java Function.apply方法代码示例

本文整理汇总了Java中java.util.function.Function.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Function.apply方法的具体用法?Java Function.apply怎么用?Java Function.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.function.Function的用法示例。


在下文中一共展示了Function.apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: zipper

import java.util.function.Function; //导入方法依赖的package包/类
/**
 * Zipper
 *
 * @param object
 * @param <K>
 * @param <V>
 * @param <E>
 * @return
 */
static <K, V, E> ConcurrentMap<K, V> zipper(
        final Collection<E> object,
        final Function<E, K> keyFn,
        final Function<E, V> valueFn
) {
    final ConcurrentMap<K, V> ret = new ConcurrentHashMap<>();
    if (0 < object.size()) {
        for (final E item : object) {
            if (null != item) {
                final K key = keyFn.apply(item);
                final V value = valueFn.apply(item);
                if (null != key && null != value) {
                    ret.put(key, value);
                }
            }
        }
    }
    return ret;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:29,代码来源:Pond.java

示例2: createDownloadFile

import java.util.function.Function; //导入方法依赖的package包/类
private byte[] createDownloadFile(Function<File, File> action) {
    Path tmpDir = null;

    try {
        tmpDir = createTempDir();

        if (logger.isDebugEnabled()) {
            logger.debug("Generating project in temporary directory " + tmpDir.toFile());
        }

        File download = action.apply(tmpDir.toFile());
        return fileToByteArray(download);
    } catch(Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (tmpDir != null) {
            if (!FileSystemUtils.deleteRecursively(tmpDir.toFile())) {
                logger.warn("Unable to delete temporary directory " + tmpDir.toFile());
            }
        }
    }
}
 
开发者ID:bmuschko,项目名称:gradle-initializr,代码行数:23,代码来源:DefaultGradleInitializrService.java

示例3: fetchAll

import java.util.function.Function; //导入方法依赖的package包/类
@SafeVarargs
public final <T extends WithId<T>> ListResult<T> fetchAll(Class<T> model, Function<ListResult<T>, ListResult<T>>... operators) {

    ListResult<T> result;
    if (getDataAccessObject(model) != null) {
        result = doWithDataAccessObject(model, d -> d.fetchAll());
    } else {
        Kind kind = Kind.from(model);
        Map<String, T> cache = caches.getCache(kind.getModelName());
        result = ListResult.of(cache.values());
    }

    if (operators == null) {
        return result;
    }

    for (Function<ListResult<T>, ListResult<T>> operator : operators) {
        result = operator.apply(result);
    }
    return result;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:22,代码来源:DataManager.java

示例4: travel

import java.util.function.Function; //导入方法依赖的package包/类
public static <T, R> void travel(Function<T, R> func, List<Iterator<T>> iterators) {
    for (Iterator<T> it : iterators) {
        while(it.hasNext()) {
            func.apply(it.next());
        }
    }

}
 
开发者ID:yuantiku,项目名称:ytk-learn,代码行数:9,代码来源:DataUtils.java

示例5: walkContext

import java.util.function.Function; //导入方法依赖的package包/类
private <T> Collection<T> walkContext(Function<ApplicationContext, T> contextProcessor) {
	final List<T> result = new LinkedList<>();
	ApplicationContext currentContext = applicationContext;
	while (currentContext != null) {
		T processingResult = contextProcessor.apply(currentContext);
		currentContext = currentContext.getParent();

		result.add(processingResult);
	}

	return result;
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:13,代码来源:ApplicationContextWalker.java

示例6: toLabeledReference

import java.util.function.Function; //导入方法依赖的package包/类
public static <T extends Enum> LabeledReference toLabeledReference(T obj, Function<T, String> nameMapper) {
    if (obj != null) {
        return new LabeledReference(obj.toString(), nameMapper.apply(obj));
    } else {
        return null;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:8,代码来源:Utils.java

示例7: leave

import java.util.function.Function; //导入方法依赖的package包/类
static Map<Object,Object> leave(IInterceptor interceptor, Map<Object,Object> context) {
    Function<Map<Object,Object>,Map<Object,Object>> lFn = (interceptor != null) ? interceptor.getLeave() : null;
    if (lFn != null) {
        return lFn.apply(context);
    } else {
        return context;
    }
}
 
开发者ID:ohpauleez,项目名称:dais,代码行数:9,代码来源:IInterceptor.java

示例8: applyCompareAndSay

import java.util.function.Function; //导入方法依赖的package包/类
private static Supplier<String> applyCompareAndSay(int i, Function<Integer, Double> func, Predicate<Double> compare, String message){
    Supplier<String> supplier = new Supplier<String>() {
        public String get() {
            double v = func.apply(i);
            return (compare.test(v)? v + " is " : v + " is not ") + message;
        }
    };
    return supplier;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:10,代码来源:Chapter04Functional.java

示例9: computeModuleIfAbsent

import java.util.function.Function; //导入方法依赖的package包/类
@CheckForNull
private String computeModuleIfAbsent(
        @NonNull FileObject root,
        @NonNull final Function<FileObject,String> provider) {
    final Pair<Pair<Reference<FileObject>,File>,String> entry = modNameCache.get();
    FileObject owner;
    String modName;
    if (entry == null ||
            (owner = entry.first().first().get()) == null ||
            !owner.equals(root)) {
        modName = provider.apply(root);
        final File modInfo = Optional.ofNullable(FileUtil.toFile(root))
                .map((rf) -> new File(rf, String.format("%s.%s", FileObjects.MODULE_INFO, FileObjects.JAVA)))   //NOI18N
                .orElse(null);
        final Pair<Pair<Reference<FileObject>,File>,String> newEntry = Pair.of(
                Pair.of(new WeakReference<>(root), modInfo),
                modName);
        if (modNameCache.compareAndSet(entry, newEntry)) {
            if (entry != null && entry.first().second() != null) {
                FileUtil.removeFileChangeListener(this, entry.first().second());
            }
            if (newEntry.first().second() != null) {
                FileUtil.addFileChangeListener(this, newEntry.first().second());
            }
        }
        LOG.log(Level.FINE, "modNameCache updated: {0}", modName);  //NOI18N
    } else {
        modName = entry.second();
    }
    return modName;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:ModuleOraculum.java

示例10: tryGetValue

import java.util.function.Function; //导入方法依赖的package包/类
private<T> T tryGetValue(Function<Double, T> cast) {
	if (excelCell != null) {
		if (excelCell.getCellTypeEnum() == CellType.FORMULA) {
			excelCell.setCellType(CellType.NUMERIC);
		}
		if(excelCell.getCellTypeEnum() == CellType.NUMERIC) {
			return cast.apply(excelCell.getNumericCellValue());
		}
	}
	return null;
}
 
开发者ID:Coreoz,项目名称:Windmill,代码行数:12,代码来源:ExcelCell.java

示例11: filterNumbersWithFunction

import java.util.function.Function; //导入方法依赖的package包/类
public List<Integer> filterNumbersWithFunction(final List<Integer> numbers,
    Function<Integer, Boolean> function) {
    List<Integer> filteredNumbers = new ArrayList<>();
    for (Integer number : numbers) {
        if (function.apply(number)) {
            filteredNumbers.add(number);
        }
    }
    return filteredNumbers; 
}
 
开发者ID:PacktPublishing,项目名称:Java-9-with-JShell,代码行数:11,代码来源:example12_03.java

示例12: convertBday

import java.util.function.Function; //导入方法依赖的package包/类
public Date convertBday(long bdayLong){
	Function<Long, Date> bday = Date::new;
	return bday.apply(bdayLong);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:5,代码来源:EmployeeDataService.java

示例13: map

import java.util.function.Function; //导入方法依赖的package包/类
public <V1> Tuple1<V1> map(Function<Tuple1<T1>, Tuple1<V1>> function) {
    return function.apply(this);
}
 
开发者ID:leonchen83,项目名称:redis-cluster-watchdog,代码行数:4,代码来源:Tuple1.java

示例14: generateEvents

import java.util.function.Function; //导入方法依赖的package包/类
private static void generateEvents(String brokers, String topicName, String eventType, long numEvents)
    throws UnsupportedEncodingException, InterruptedException {
  Properties props = new Properties();
  props.put("bootstrap.servers", brokers);
  props.put("retries", 100);
  props.put("batch.size", 16384);
  props.put("key.serializer", ByteArraySerializer.class.getCanonicalName());
  props.put("value.serializer", ByteArraySerializer.class.getCanonicalName());

  Function<Integer, Pair<String, byte[]>> eventGenerator;
  if (eventType.toLowerCase().contains(PAGEVIEW_EVENTTYPE)) {
    eventGenerator = GenerateKafkaEvents::generatePageViewEvent;
  } else {
    eventGenerator = GenerateKafkaEvents::generateProfileChangeEvent;
  }

  boolean doSleep = false;
  // sleep only when the events have to be produced continuously.
  if (numEvents == Long.MAX_VALUE) {
    doSleep = true;
  }

  try (Producer<byte[], byte[]> producer = new KafkaProducer<>(props)) {
    for (int index = 0; index < numEvents; index++) {
      final int finalIndex = 0;
      Pair<String, byte[]> record = eventGenerator.apply(index);
      producer.send(new ProducerRecord<>(topicName, record.getLeft().getBytes("UTF-8"), record.getRight()),
          (metadata, exception) -> {
            if (exception == null) {
              LOG.info("send completed for event {} at offset {}", finalIndex, metadata.offset());
            } else {
              throw new RuntimeException("Failed to send message.", exception);
            }
          });
      System.out.println(String.format("Published event %d to topic %s", index, topicName));
      if (doSleep) {
        Thread.sleep(1000);
      }
    }

    producer.flush();
  }
}
 
开发者ID:srinipunuru,项目名称:samza-sql-tools,代码行数:44,代码来源:GenerateKafkaEvents.java

示例15: andThen

import java.util.function.Function; //导入方法依赖的package包/类
default <V> TripleFunction<A, B, C, V> andThen(Function<? super R, ? extends V> after) {
    Objects.requireNonNull(after);
    return (a, b, c) -> after.apply(apply(a, b, c));
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:5,代码来源:TripleFunction.java


注:本文中的java.util.function.Function.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。