下面列出了com.google.common.collect.Maps#newIdentityHashMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static List<LibraryDependencyImpl> convertLibraryInfoIntoDependency(
@NonNull List<LibInfo> libInfos,
@NonNull Multimap<LibraryDependency, VariantDependencies> reverseMap) {
List<LibraryDependencyImpl> list = Lists.newArrayListWithCapacity(libInfos.size());
// since the LibInfos is a graph and the previous "foundLibraries" map ensure we reuse
// instance where applicable, we'll create a map to keep track of what we have already
// converted.
Map<LibInfo, LibraryDependencyImpl> convertedMap = Maps.newIdentityHashMap();
for (LibInfo libInfo : libInfos) {
list.add(convertLibInfo(libInfo, reverseMap, convertedMap));
}
return list;
}
public PulsarClientImpl(ClientConfigurationData conf, EventLoopGroup eventLoopGroup, ConnectionPool cnxPool)
throws PulsarClientException {
if (conf == null || isBlank(conf.getServiceUrl()) || eventLoopGroup == null) {
throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration");
}
this.eventLoopGroup = eventLoopGroup;
setAuth(conf);
this.conf = conf;
this.clientClock = conf.getClock();
conf.getAuthentication().start();
this.cnxPool = cnxPool;
externalExecutorProvider = new ExecutorProvider(conf.getNumListenerThreads(), getThreadFactory("pulsar-external-listener"));
if (conf.getServiceUrl().startsWith("http")) {
lookup = new HttpLookupService(conf, eventLoopGroup);
} else {
lookup = new BinaryProtoLookupService(this, conf.getServiceUrl(), conf.getListenerName(), conf.isUseTls(), externalExecutorProvider.getExecutor());
}
timer = new HashedWheelTimer(getThreadFactory("pulsar-timer"), 1, TimeUnit.MILLISECONDS);
producers = Maps.newIdentityHashMap();
consumers = Maps.newIdentityHashMap();
state.set(State.Open);
}
private Map<TemplateType, JSType> inferTemplateTypesFromParameters(
FunctionType fnType, Node call) {
if (fnType.getTemplateTypeMap().getTemplateKeys().isEmpty()) {
return Collections.emptyMap();
}
Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap();
Node callTarget = call.getFirstChild();
if (NodeUtil.isGet(callTarget)) {
Node obj = callTarget.getFirstChild();
maybeResolveTemplatedType(
fnType.getTypeOfThis(),
getJSType(obj),
resolvedTypes);
}
if (call.hasMoreThanOneChild()) {
maybeResolveTemplateTypeFromNodes(
fnType.getParameters(),
call.getChildAtIndex(1).siblings(),
resolvedTypes);
}
return resolvedTypes;
}
@Test
public void testCanonicalTaskConfigs() {
IScheduledTask a = createTask("a");
IScheduledTask b = createTask("a");
IScheduledTask c = createTask("a");
saveTasks(a, b, c);
Set<IScheduledTask> inserted = ImmutableSet.of(a, b, c);
Set<ITaskConfig> storedConfigs = FluentIterable.from(fetchTasks(Query.unscoped()))
.transform(Tasks::getConfig)
.toSet();
assertEquals(
FluentIterable.from(inserted).transform(Tasks::getConfig).toSet(),
storedConfigs);
Map<ITaskConfig, ITaskConfig> identityMap = Maps.newIdentityHashMap();
for (ITaskConfig stored : storedConfigs) {
identityMap.put(stored, stored);
}
assertEquals(
ImmutableMap.of(Tasks.getConfig(a), Tasks.getConfig(a)),
identityMap);
}
@Override
public CompletableFuture<Boolean> prepare(TransactionLog<MapUpdate<K, byte[]>> transactionLog) {
Map<PartitionId, List<MapUpdate<K, byte[]>>> updatesGroupedByMap = Maps.newIdentityHashMap();
transactionLog.records().forEach(update -> {
updatesGroupedByMap.computeIfAbsent(getPartition(update.key()), k -> Lists.newLinkedList()).add(update);
});
Map<PartitionId, TransactionLog<MapUpdate<K, byte[]>>> transactionsByMap =
Maps.transformValues(updatesGroupedByMap, list -> new TransactionLog<>(transactionLog.transactionId(), transactionLog.version(), list));
return Futures.allOf(transactionsByMap.entrySet()
.stream()
.map(e -> getProxyClient().applyOn(e.getKey(), service -> service.prepare(e.getValue()))
.thenApply(v -> v == PrepareResult.OK || v == PrepareResult.PARTIAL_FAILURE))
.collect(Collectors.toList()))
.thenApply(list -> list.stream().reduce(Boolean::logicalAnd).orElse(true));
}
@Override
public CompletableFuture<Boolean> prepare(TransactionLog<SetUpdate<String>> transactionLog) {
Map<PartitionId, List<SetUpdate<String>>> updatesGroupedBySet = Maps.newIdentityHashMap();
transactionLog.records().forEach(update -> {
updatesGroupedBySet.computeIfAbsent(getProxyClient().getPartitionId(update.element()), k -> Lists.newLinkedList()).add(update);
});
Map<PartitionId, TransactionLog<SetUpdate<String>>> transactionsBySet =
Maps.transformValues(updatesGroupedBySet, list -> new TransactionLog<>(transactionLog.transactionId(), transactionLog.version(), list));
return Futures.allOf(transactionsBySet.entrySet()
.stream()
.map(e -> getProxyClient().applyOn(e.getKey(), service -> service.prepare(e.getValue()))
.thenApply(v -> v == PrepareResult.OK || v == PrepareResult.PARTIAL_FAILURE))
.collect(Collectors.toList()))
.thenApply(list -> list.stream().reduce(Boolean::logicalAnd).orElse(true));
}
private Map<TemplateType, JSType> inferTemplateTypesFromParameters(
FunctionType fnType, Node call) {
if (fnType.getTemplateKeys().isEmpty()) {
return Collections.emptyMap();
}
Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap();
Node callTarget = call.getFirstChild();
if (NodeUtil.isGet(callTarget)) {
Node obj = callTarget.getFirstChild();
maybeResolveTemplatedType(
fnType.getTypeOfThis(),
getJSType(obj),
resolvedTypes);
}
if (call.hasMoreThanOneChild()) {
maybeResolveTemplateTypeFromNodes(
fnType.getParameters(),
call.getChildAtIndex(1).siblings(),
resolvedTypes);
}
return resolvedTypes;
}
protected Map<EObject, IEObjectDescription> createEObject2ExportedEObjectsMap(
Iterable<IEObjectDescription> exportedObjects) {
Map<EObject, IEObjectDescription> uri2exportedEObjects = Maps.newIdentityHashMap();
for (IEObjectDescription eObjectDescription : exportedObjects) {
uri2exportedEObjects.put(eObjectDescription.getEObjectOrProxy(), eObjectDescription);
}
return uri2exportedEObjects;
}
/**
* Creates a new trace configuration which enables all tracing <b>except</b> for the given event types.
*
* @param excludedTraceClasses
* event types to disable tracing for
* @return trace configuration, never {@code null}
*/
@SafeVarargs
static TraceConfiguration enableAllExcept(final Class<? extends TraceEvent>... excludedTraceClasses) {
Map<Class<? extends TraceEvent>, Boolean> excludedTraceClassMap = Maps.newIdentityHashMap();
for (Class<? extends TraceEvent> traceClass : excludedTraceClasses) {
excludedTraceClassMap.put(traceClass, Boolean.TRUE);
}
return c -> !excludedTraceClassMap.containsKey(c);
}
/**
* Creates a new trace configuration which enables tracing <b>only</b> for the given event types.
*
* @param includedTraceClasses
* event types to enable tracing for
* @return trace configuration, never {@code null}
*/
@SafeVarargs
static TraceConfiguration enableOnly(final Class<? extends TraceEvent>... includedTraceClasses) {
Map<Class<? extends TraceEvent>, Boolean> includedTraceClassMap = Maps.newIdentityHashMap();
for (Class<? extends TraceEvent> traceClass : includedTraceClasses) {
includedTraceClassMap.put(traceClass, Boolean.TRUE);
}
return includedTraceClassMap::containsKey;
}
/**
* Returns the location and type of all the variables.
*
* @return
*/
public Map<ASTNode, String> getVariableTypesAtPosition() {
final Map<ASTNode, String> variableTypes = Maps.newIdentityHashMap();
for (final Entry<Integer, List<ASTNode>> variableBinding : resolver.getVariableBinding()
.entrySet()) {
Integer bindingId = variableBinding.getKey();
final String varType = checkNotNull(resolver.getVariableTypes()
.get(bindingId));
for (final ASTNode node : variableBinding.getValue()) {
variableTypes.put(node, varType);
}
}
return variableTypes;
}
public Map<ASTNode, ASTNode> getVariableDependencies() {
final Map<ASTNode, ASTNode> variableTypes = Maps.newIdentityHashMap();
for (final Entry<Integer, List<ASTNode>> variableBinding : resolver.getVariableBinding()
.entrySet()) {
Integer bindingId = variableBinding.getKey();
final ASTNode parent = resolver.getVariableDeclarationBinding().get(bindingId);
for (final ASTNode node : variableBinding.getValue()) {
variableTypes.put(node, parent);
}
}
return variableTypes;
}
/**
* Returns the locations where a type is mentioned and its actual
* fully qualified type name.
*
* @return
*/
public Map<ASTNode, String> getTypesAtPosition() {
final Map<ASTNode, String> nodeTypes = Maps.newIdentityHashMap();
for (final Entry<ASTNode, String> typeBinding : resolver.getNodeTypeBinding()
.entrySet()) {
if (!typeBinding.getValue().contains("<")) {
nodeTypes.put(typeBinding.getKey(), typeBinding.getValue());
}
}
return nodeTypes;
}
public TsConditionEraser(TblColRef tsColumn, TupleFilter root) {
this.tsColumn = tsColumn;
this.root = root;
this.isInTopLevelANDs = Maps.newIdentityHashMap();
}
public TimeConditionLiteralsReplacer(TupleFilter root) {
this.dateCompareTupleChildren = Maps.newIdentityHashMap();
}
private IndividualTranslator() {
this.individualCache=Maps.newIdentityHashMap();
}
/**
* @param counterType type of counter
*/
public BasicCounters(@Nonnull Class<T> counterType)
{
cache = Maps.newIdentityHashMap();
this.counterType = counterType;
}
private ShapeIndividualCache() {
this.cache=Maps.newIdentityHashMap();
}
public RenderCrop(BlockCrop block) {
super(block, new TileEntityCrop(), false, true, false);
this.cropQuads = Maps.newIdentityHashMap();
}
public Map<K, V> newInstance() { return Maps.newIdentityHashMap(); }