List of usage examples for com.google.common.collect Table values
Collection<V> values();
From source file:org.opendaylight.groupbasedpolicy.util.SubjectResolverUtils.java
/** * Choose the set of subjects that in scope for each possible set of * endpoint conditions/*from www. jav a2s .co m*/ */ // TODO Li msunal do we really need contractMatches to be a type Table<EgKey, EgKey, List<ContractMatch>> // it should be sufficient to be just List<ContractMatch> static Table<EgKey, EgKey, Policy> selectSubjects(Table<EgKey, EgKey, List<ContractMatch>> contractMatches, Map<EgKey, Set<ConditionSet>> egConditions) { // TODO: Note that it's possible to further simplify the resulting // policy // in the case of things like repeated rules, condition sets that // cover other condition sets, etc. This would be a good thing to do // at some point Table<EgKey, EgKey, Policy> policy = HashBasedTable.create(); for (List<ContractMatch> matches : contractMatches.values()) { for (ContractMatch match : matches) { List<Clause> clauses = match.contract.getClause(); if (clauses == null) continue; List<Subject> subjectList = match.contract.getSubject(); if (subjectList == null) continue; EgKey ckey = new EgKey(match.consumerTenant.getId(), match.consumer.getId()); EgKey pkey = new EgKey(match.providerTenant.getId(), match.provider.getId()); Policy existing = policy.get(ckey, pkey); HashMap<SubjectName, Subject> subjects = new HashMap<>(); for (Subject s : subjectList) { subjects.put(s.getName(), s); } Table<EndpointConstraint, EndpointConstraint, List<Subject>> subjectMap = HashBasedTable.create(); for (Clause clause : clauses) { if (clause.getSubjectRefs() != null && clauseMatchesByGroupReqAndCapConstraints(clause, match)) { ConditionSet consCSet = buildConsConditionSet(clause); addConditionSet(ckey, consCSet, egConditions); EndpointConstraint consEpConstraint = new EndpointConstraint(consCSet, clause.getConsumerMatchers() == null ? null : clause.getConsumerMatchers().getEndpointIdentificationConstraints()); ConditionSet provCSet = buildProvConditionSet(clause); addConditionSet(pkey, provCSet, egConditions); EndpointConstraint provEpConstraint = new EndpointConstraint(provCSet, clause.getProviderMatchers() == null ? null : clause.getProviderMatchers().getEndpointIdentificationConstraints()); List<Subject> clauseSubjects = subjectMap.get(consEpConstraint, provEpConstraint); if (clauseSubjects == null) { clauseSubjects = new ArrayList<>(); subjectMap.put(consEpConstraint, provEpConstraint, clauseSubjects); } for (SubjectName sn : clause.getSubjectRefs()) { Subject s = subjects.get(sn); if (s != null) clauseSubjects.add(s); } } } policy.put(ckey, pkey, resolvePolicy(match.contractTenant, match.contract, existing, subjectMap)); } } return policy; }
From source file:com.robomwm.CapturePointClaims.region.RegionManager.java
public Set<Region> getRegions(Player player) { Set<Region> regionsToReturn = new HashSet<>(); for (Table<Integer, Integer, Region> world : worldCache.values()) { for (Region region : world.values()) { if (region.getOwner() != null && region.getOwner().getPlayer() == player) regionsToReturn.add(region); }/* w ww.j av a 2 s . c om*/ } return regionsToReturn; }
From source file:com.robomwm.CapturePointClaims.region.RegionManager.java
public Set<Region> getRegions(Clan clan) { Set<Region> regionsToReturn = new HashSet<>(); for (Table<Integer, Integer, Region> world : worldCache.values()) { for (Region region : world.values()) { if (region.getOwner() != null && instance.getClanManager() .getClanByPlayerUniqueId(region.getOwner().getUniqueId()) == clan) regionsToReturn.add(region); }/*ww w. j a v a 2 s . c o m*/ } return regionsToReturn; }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.aggregation.aggregationstrategy.TopNAggregation_Score.java
@Override public List<RankedPhrase> aggregatePhrases(Table<String, Integer, Double> phraseSegmentTable) { List<RankedPhrase> rankedPhrases = new ArrayList<RankedPhrase>(); Map<Integer, Map<String, Double>> columnMap = phraseSegmentTable.columnMap(); int maxRank = phraseSegmentTable.rowKeySet().size(); double maxScore = maximum(phraseSegmentTable.values()); for (Map<String, Double> column : columnMap.values()) { int baseRank = maxRank; for (Entry<String, Double> entry : sortByValue(column)) { double normalizedOldScore = entry.getValue() / maxScore; double newScore = baseRank-- + normalizedOldScore; rankedPhrases.add(new RankedPhrase(entry.getKey(), newScore)); }// ww w . j av a2 s .c o m } return rankedPhrases; }
From source file:co.cask.cdap.internal.app.runtime.flow.FlowUtils.java
/** * Configures all queues being used in a flow. * * @return A Multimap from flowletId to QueueName where the flowlet is a consumer of. *//*from www .j a v a 2 s . c o m*/ public static Multimap<String, QueueName> configureQueue(Program program, FlowSpecification flowSpec, StreamAdmin streamAdmin, QueueAdmin queueAdmin, TransactionExecutorFactory txExecutorFactory) { // Generate all queues specifications Id.Application appId = Id.Application.from(program.getNamespaceId(), program.getApplicationId()); Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecs = new SimpleQueueSpecificationGenerator( appId).create(flowSpec); // For each queue in the flow, gather all consumer groups information Multimap<QueueName, ConsumerGroupConfig> queueConfigs = HashMultimap.create(); // Loop through each flowlet and generate the map from consumer flowlet id to queue ImmutableSetMultimap.Builder<String, QueueName> resultBuilder = ImmutableSetMultimap.builder(); for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) { String flowletId = entry.getKey(); for (QueueSpecification queueSpec : Iterables.concat(queueSpecs.column(flowletId).values())) { resultBuilder.put(flowletId, queueSpec.getQueueName()); } } // For each queue, gather all consumer groups. for (QueueSpecification queueSpec : Iterables.concat(queueSpecs.values())) { QueueName queueName = queueSpec.getQueueName(); queueConfigs.putAll(queueName, getAllConsumerGroups(program, flowSpec, queueName, queueSpecs)); } try { // Configure each stream consumer in the Flow. Also collects all queue configurers. final List<ConsumerGroupConfigurer> groupConfigurers = Lists.newArrayList(); for (Map.Entry<QueueName, Collection<ConsumerGroupConfig>> entry : queueConfigs.asMap().entrySet()) { LOG.info("Queue config for {} : {}", entry.getKey(), entry.getValue()); if (entry.getKey().isStream()) { Map<Long, Integer> configs = Maps.newHashMap(); for (ConsumerGroupConfig config : entry.getValue()) { configs.put(config.getGroupId(), config.getGroupSize()); } streamAdmin.configureGroups(entry.getKey().toStreamId(), configs); } else { groupConfigurers.add(new ConsumerGroupConfigurer(queueAdmin.getQueueConfigurer(entry.getKey()), entry.getValue())); } } // Configure queue transactionally try { Transactions.createTransactionExecutor(txExecutorFactory, groupConfigurers) .execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { for (ConsumerGroupConfigurer configurer : groupConfigurers) { configurer.configure(); } } }); } finally { for (ConsumerGroupConfigurer configurer : groupConfigurers) { Closeables.closeQuietly(configurer); } } return resultBuilder.build(); } catch (Exception e) { LOG.error("Failed to configure queues", e); throw Throwables.propagate(e); } }
From source file:com.garethahealy.camelmapstruct.converter.MapStructTypeConverter.java
private String findMethodName(Class<?> from, Class<?> to) throws IllegalAccessException { String methodName;/* w w w . j av a 2 s . c om*/ Table<Class<?>, Class<?>, String> resolved = configuration.getResolvedMappingMethods(); if (resolved.containsRow(from) && resolved.containsColumn(to)) { methodName = resolved.get(from, to); } else { String innerMessage = "Did'nt find method on mapper " + mapper.getClass().getCanonicalName() + " that container a parameter of " + from.getCanonicalName() + "; Found possible matches: " + StringUtils.join(resolved.values(), ", "); LOG.error(innerMessage); throw new IllegalAccessException(innerMessage); } return methodName; }
From source file:com.github.rinde.rinsim.ui.renderers.WarehouseRenderer.java
private void drawConnections() { // filter connections to avoid double work for bidirectional roads final Table<Point, Point, Connection<?>> filteredConnections = filterConnections(); adapter.setForegroundSysCol(SWT.COLOR_DARK_GRAY); adapter.setBackgroundSysCol(SWT.COLOR_DARK_GRAY); // draw connections for (final Connection<?> e : filteredConnections.values()) { // draw arrows if (!graph.hasConnection(e.to(), e.from()) && drawOneWayStreetArrows) { if (PointUtil.length(e) > SHORT_CONNECTION_LENGTH * vehicleLength) { final Point start1 = PointUtil.on(e, vehicleLength); final Point end1 = PointUtil.on(e, vehicleLength + arrowDimensions.y * 2); adapter.drawArrow(start1, end1, arrowDimensions.x, arrowDimensions.y); final Point start2 = PointUtil.on(e.to(), e.from(), vehicleLength + arrowDimensions.y * 2); final Point end2 = PointUtil.on(e.to(), e.from(), vehicleLength); adapter.drawArrow(start2, end2, arrowDimensions.x, arrowDimensions.y); } else { final double center = PointUtil.length(e) / 2d; final Point start1 = PointUtil.on(e, center - arrowDimensions.y); final Point end1 = PointUtil.on(e, center + arrowDimensions.y); adapter.drawArrow(start1, end1, arrowDimensions.x, arrowDimensions.y); }//from ww w.j a v a 2s. c o m } adapter.setForegroundSysCol(SWT.COLOR_GRAY); adapter.setBackgroundSysCol(SWT.COLOR_GRAY); final double length = PointUtil.length(e); final Point a = PointUtil.perp(e, vehicleLength, halfRoadWidth); final Point b = PointUtil.perp(e, length - vehicleLength, halfRoadWidth); adapter.drawLine(a, b); final Point c = PointUtil.perp(e, vehicleLength, -halfRoadWidth); final Point d = PointUtil.perp(e, length - vehicleLength, -halfRoadWidth); adapter.drawLine(c, d); } }
From source file:co.cask.cdap.internal.app.AbstractInMemoryProgramRunner.java
protected Table<String, Integer, ProgramController> startPrograms(Program program, RunId runId, ProgramOptions options, ProgramRunnerFactory.Type type, int numInstances) { Table<String, Integer, ProgramController> components = HashBasedTable.create(); try {/* w w w . j a va 2 s .c o m*/ startComponent(program, program.getName(), numInstances, runId, options, components, type); } catch (Throwable t) { LOG.error("Failed to start all program instances", t); try { // Need to stop all started components Futures.successfulAsList(Iterables.transform(components.values(), new Function<ProgramController, ListenableFuture<?>>() { @Override public ListenableFuture<?> apply(ProgramController controller) { return controller.stop(); } })).get(); throw Throwables.propagate(t); } catch (Exception e) { LOG.error("Failed to stop all program instances upon startup failure.", e); throw Throwables.propagate(e); } } return components; }
From source file:co.cask.cdap.internal.app.runtime.service.InMemoryServiceRunner.java
private Table<String, Integer, ProgramController> createRunnables(Program program, RunId runId, ServiceSpecification serviceSpec) { Table<String, Integer, ProgramController> runnables = HashBasedTable.create(); try {//from w w w . ja v a 2 s . c o m for (Map.Entry<String, RuntimeSpecification> entry : serviceSpec.getRunnables().entrySet()) { int instanceCount = entry.getValue().getResourceSpecification().getInstances(); for (int instanceId = 0; instanceId < instanceCount; instanceId++) { runnables.put(entry.getKey(), instanceId, startRunnable(program, createRunnableOptions(entry.getKey(), instanceId, instanceCount, runId))); } } } catch (Throwable t) { // Need to stop all started runnable here. try { Futures.successfulAsList(Iterables.transform(runnables.values(), new Function<ProgramController, ListenableFuture<ProgramController>>() { @Override public ListenableFuture<ProgramController> apply(ProgramController input) { return input.stop(); } })).get(); } catch (Exception e) { LOG.error("Failed to stop all the runnables"); } throw Throwables.propagate(t); } return runnables; }
From source file:co.cask.tigon.internal.app.runtime.flow.FlowProgramRunner.java
/** * Starts all flowlets in the flow program. * @param program Program to run/* w w w. ja va2 s. c om*/ * @param flowSpec The {@link FlowSpecification}. * @return A {@link com.google.common.collect.Table} with row as flowlet id, column as instance id, * cell as the {@link ProgramController} for the flowlet. */ private Table<String, Integer, ProgramController> createFlowlets(Program program, RunId runId, FlowSpecification flowSpec) { Table<String, Integer, ProgramController> flowlets = HashBasedTable.create(); try { for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) { int instanceCount = entry.getValue().getInstances(); for (int instanceId = 0; instanceId < instanceCount; instanceId++) { flowlets.put(entry.getKey(), instanceId, startFlowlet(program, createFlowletOptions(entry.getKey(), instanceId, instanceCount, runId))); } } } catch (Throwable t) { try { // Need to stop all started flowlets Futures.successfulAsList(Iterables.transform(flowlets.values(), new Function<ProgramController, ListenableFuture<?>>() { @Override public ListenableFuture<?> apply(ProgramController controller) { return controller.stop(); } })).get(); } catch (Exception e) { LOG.error("Fail to stop all flowlets on failure."); } throw Throwables.propagate(t); } return flowlets; }