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


Java Function类代码示例

本文整理汇总了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];
        }
    });
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:18,代码来源:ItemMultiTexture.java

示例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();
    }}));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:ElasticMappingSet.java

示例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();
  }
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:FuturesTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:TestTreeRegistryTest.java

示例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);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:ModelPathSuggestionProvider.java

示例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);
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:DrmScriptWrapper.java

示例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();
}
 
开发者ID:vulnersCom,项目名称:burp-vulners-scanner,代码行数:20,代码来源:PathIssue.java

示例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);
        }
    });
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:21,代码来源:DefaultPactResolver.java

示例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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:TransactionProxy.java

示例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);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:17,代码来源:CassandraBaseTimeseriesDao.java

示例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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:25,代码来源:DefaultOvsdbClient.java

示例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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:19,代码来源:DefaultTaskOutputs.java

示例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;
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:21,代码来源:FetchTaskProcessor.java

示例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();
  }
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:20,代码来源:FuturesTest.java

示例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);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:11,代码来源:AbstractNetwork.java


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