本文整理汇总了Java中com.google.common.base.Function类的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于com.google.common.base包,在下文中一共展示了Function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ItemMultiTexture
import com.google.common.base.Function; //导入依赖的package包/类
public ItemMultiTexture(Block block, Block block2, final String[] namesByMeta)
{
this(block, block2, new Function<ItemStack, String>()
{
public String apply(ItemStack p_apply_1_)
{
int i = p_apply_1_.getMetadata();
if (i < 0 || i >= namesByMeta.length)
{
i = 0;
}
return namesByMeta[i];
}
});
}
示例2: filterToType
import com.google.common.base.Function; //导入依赖的package包/类
public ElasticIndex filterToType(String name){
List<ElasticMapping> filtered = new ArrayList<>();
for(ElasticMapping m : mappings){
for(String namePiece : name.split(",")){
if(m.getName().equals(namePiece)){
filtered.add(m);
}
}
}
if(filtered.isEmpty()){
return null;
}
return new ElasticIndex(name, ImmutableList.<String>of(), FluentIterable.from(filtered).uniqueIndex(new Function<ElasticMapping, String>(){
@Override
public String apply(ElasticMapping input) {
return input.getName();
}}));
}
示例3: testMakeChecked_listenersRunOnCancel
import com.google.common.base.Function; //导入依赖的package包/类
@GwtIncompatible // makeChecked
public void testMakeChecked_listenersRunOnCancel() throws Exception {
SettableFuture<String> future = SettableFuture.create();
CheckedFuture<String, TestException> checked = makeChecked(
future, new Function<Exception, TestException>() {
@Override
public TestException apply(Exception from) {
throw new NullPointerException();
}
});
ListenableFutureTester tester = new ListenableFutureTester(checked);
tester.setUp();
future.cancel(true); // argument is ignored
tester.testCancelledFuture();
tester.tearDown();
}
示例4: newTestTree
import com.google.common.base.Function; //导入依赖的package包/类
private TestTree newTestTree(final String sessionId, final String... testIds) {
final List<TestSuite> testSuites = newArrayList(transform(newHashSet(testIds),
new Function<String, TestSuite>() {
@Override
public TestSuite apply(String testId) {
final TestSuite suite = new TestSuite("TestSuite_for_Test_" + testId);
final TestCase testCase = new TestCase(
new ID(testId),
"testClassName_" + testId,
"origin_" + testId + "name_" + testId + "_0.0.0",
"name_" + testId,
"displayName_" + testId,
URI.createURI("testURI_" + testId));
suite.setTestCases(singletonList(testCase));
return suite;
}
}));
return new TestTree(new ID(sessionId), testSuites);
}
示例5: transform
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public List<ModelPath> transform(final ModelPath unavailable) {
Iterable<Suggestion> suggestions = Iterables.transform(availablePaths, new Function<ModelPath, Suggestion>() {
public Suggestion apply(ModelPath available) {
int distance = StringUtils.getLevenshteinDistance(unavailable.toString(), available.toString());
boolean suggest = distance <= Math.min(3, unavailable.toString().length() / 2);
if (suggest) {
return new Suggestion(distance, available);
} else {
// avoid excess creation of Suggestion objects
return null;
}
}
});
suggestions = Iterables.filter(suggestions, REMOVE_NULLS);
List<Suggestion> sortedSuggestions = CollectionUtils.sort(suggestions);
return CollectionUtils.collect(sortedSuggestions, Suggestion.EXTRACT_PATH);
}
示例6: setContentOwners
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public void setContentOwners(List<DrmPartyScriptType> contentOwners)
{
changed = true;
owners = contentOwners;
List<Party> partyContentOwners = Lists
.newArrayList(Lists.transform(contentOwners, new Function<DrmPartyScriptType, Party>()
{
@Override
public Party apply(DrmPartyScriptType drmPartyScriptType)
{
DefaultDrmPartyScriptType scriptParty = ((DefaultDrmPartyScriptType) drmPartyScriptType);
scriptParty.setOwnerSettings(DefaultDrmSettingsScriptType.this);
return scriptParty.getWrapped();
}
}));
settings.setContentOwners(partyContentOwners);
}
示例7: getSeverity
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public String getSeverity() {
Collection<Double> scores = Collections2.transform(
vulnerabilities, new Function<Vulnerability, Double>() {
@Override
public Double apply(Vulnerability vulnerability) {
return vulnerability.getCvssScore();
}
}
);
Double maxValue = Ordering.natural().max(scores);
if (maxValue > 7) {
return ScanIssueSeverity.HIGH.getName();
} else if (maxValue > 4) {
return ScanIssueSeverity.MEDIUM.getName();
}
return ScanIssueSeverity.LOW.getName();
}
示例8: resolvePacts
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public List<Pact> resolvePacts(final PactDefinition pactDefinition, final ObjectStringConverter jsonConverter) throws Exception {
if (!StringUtils.isEmpty(pactDefinition.localPactFilePath())) {
String pactJson = loadPactFile(pactDefinition.localPactFilePath());
Pact pact = Pact.parse(pactJson, jsonConverter);
pact.setDisplayVersion("local");
pact.setDisplayName(pactDefinition.consumer() + "-local");
return singletonList(pact);
}
return transform(getPactVersionsToRun(pactDefinition), new Function<String, Pact>() {
@Override
public Pact apply(String version) {
return resolvePact(pactDefinition, version, jsonConverter);
}
});
}
示例9: readAllData
import com.google.common.base.Function; //导入依赖的package包/类
private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readAllData() {
final Set<String> allShardNames = txContextFactory.getActorContext().getConfiguration().getAllShardNames();
final Collection<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>> futures =
new ArrayList<>(allShardNames.size());
for (String shardName : allShardNames) {
futures.add(singleShardRead(shardName, YangInstanceIdentifier.EMPTY));
}
final ListenableFuture<List<Optional<NormalizedNode<?, ?>>>> listFuture = Futures.allAsList(futures);
final ListenableFuture<Optional<NormalizedNode<?, ?>>> aggregateFuture;
aggregateFuture = Futures.transform(listFuture,
(Function<List<Optional<NormalizedNode<?, ?>>>, Optional<NormalizedNode<?, ?>>>) input -> {
try {
return NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY, input,
txContextFactory.getActorContext().getSchemaContext(),
txContextFactory.getActorContext().getDatastoreContext().getLogicalStoreType());
} catch (DataValidationFailedException e) {
throw new IllegalArgumentException("Failed to aggregate", e);
}
}, MoreExecutors.directExecutor());
return MappingCheckedFuture.create(aggregateFuture, ReadFailedException.MAPPER);
}
示例10: findAllAsync
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public ListenableFuture<List<TsKvEntry>> findAllAsync(EntityId entityId, List<TsKvQuery> queries) {
List<ListenableFuture<List<TsKvEntry>>> futures = queries.stream().map(query -> findAllAsync(entityId, query)).collect(Collectors.toList());
return Futures.transform(Futures.allAsList(futures), new Function<List<List<TsKvEntry>>, List<TsKvEntry>>() {
@Nullable
@Override
public List<TsKvEntry> apply(@Nullable List<List<TsKvEntry>> results) {
if (results == null || results.isEmpty()) {
return null;
}
return results.stream()
.flatMap(List::stream)
.collect(Collectors.toList());
}
}, readResultsProcessingExecutor);
}
示例11: transactConfig
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public ListenableFuture<List<OperationResult>> transactConfig(String dbName,
List<Operation> operations) {
if (dbName == null) {
return null;
}
DatabaseSchema dbSchema = schema.get(dbName);
if (dbSchema != null) {
Function<List<JsonNode>, List<OperationResult>> rowFunction = (input -> {
log.info("Get ovsdb operation result");
List<OperationResult> result = FromJsonUtil
.jsonNodeToOperationResult(input, operations);
if (result == null) {
log.debug("The operation result is null");
return null;
}
return result;
});
return Futures.transform(transact(dbSchema, operations),
rowFunction);
}
return null;
}
示例12: getFileProperties
import com.google.common.base.Function; //导入依赖的package包/类
@Override
public SortedSet<TaskOutputFilePropertySpec> getFileProperties() {
if (fileProperties == null) {
TaskPropertyUtils.ensurePropertiesHaveNames(filePropertiesInternal);
Iterator<TaskOutputFilePropertySpec> flattenedProperties = Iterators.concat(Iterables.transform(filePropertiesInternal, new Function<TaskPropertySpec, Iterator<? extends TaskOutputFilePropertySpec>>() {
@Override
public Iterator<? extends TaskOutputFilePropertySpec> apply(TaskPropertySpec propertySpec) {
if (propertySpec instanceof CompositeTaskOutputPropertySpec) {
return ((CompositeTaskOutputPropertySpec) propertySpec).resolveToOutputProperties();
} else {
return Iterators.singletonIterator((TaskOutputFilePropertySpec) propertySpec);
}
}
}).iterator());
fileProperties = TaskPropertyUtils.collectFileProperties("output", flattenedProperties);
}
return fileProperties;
}
示例13: unPackSipNode
import com.google.common.base.Function; //导入依赖的package包/类
private Object unPackSipNode(Object object) {
if (object == null) {
return null;
}
if (object instanceof SIPNode) {
return handleSingleSipNode((SIPNode) object);
}
if (object instanceof Collection) {
return Collections2.transform((Collection) object, new Function<Object, Object>() {
@Override
public Object apply(Object input) {
if (!(input instanceof SIPNode)) {
return input;
}
return handleSingleSipNode((SIPNode) input);
}
});
}
return object;
}
示例14: testMakeChecked_listenersRunOnceCompleted
import com.google.common.base.Function; //导入依赖的package包/类
@GwtIncompatible // makeChecked
public void testMakeChecked_listenersRunOnceCompleted() throws Exception {
SettableFuture<String> future = SettableFuture.create();
CheckedFuture<String, TestException> checked = makeChecked(
future, new Function<Exception, TestException>() {
@Override
public TestException apply(Exception from) {
throw new NullPointerException();
}
});
ListenableFutureTester tester = new ListenableFutureTester(checked);
tester.setUp();
future.set(DATA1);
tester.testCompletedFuture(DATA1);
tester.tearDown();
}
示例15: edgeIncidentNodesMap
import com.google.common.base.Function; //导入依赖的package包/类
private static <N, E> Map<E, EndpointPair<N>> edgeIncidentNodesMap(final Network<N, E> network) {
Function<E, EndpointPair<N>> edgeToIncidentNodesFn =
new Function<E, EndpointPair<N>>() {
@Override
public EndpointPair<N> apply(E edge) {
return network.incidentNodes(edge);
}
};
return Maps.asMap(network.edges(), edgeToIncidentNodesFn);
}