List of usage examples for com.google.common.collect Table row
Map<C, V> row(R rowKey);
From source file:co.turnus.profiling.util.ProfilingWeightsEstimator.java
public ProfilingWeights estimate(ProfilingData data) { ProfilingFactory f = ProfilingFactory.eINSTANCE; ProfilingWeights netWeights = f.createProfilingWeights(); netWeights.setNetwork(data.getNetwork()); Table<Actor, Action, ActionProfilingData> table = data.asTable(); double networkCost = estimateNetworkCost(data); for (Actor actor : table.rowKeySet()) { ActorProfilingWeights actorWeights = f.createActorProfilingWeights(); actorWeights.setActor(actor);/*from w w w . j a va2 s . c o m*/ double actorCost = 0; for (Entry<Action, ActionProfilingData> actionEntry : table.row(actor).entrySet()) { ActionProfilingData aData = actionEntry.getValue(); ActionProfilingWeights actionWeights = f.createActionProfilingWeights(); actionWeights.setAction(actionEntry.getKey()); EMap<Operator, StatisticalData> opsMap = aData.getOperatorsCall(); int samples = opsMap.size(); double mean = 0; double min = 0; double max = 0; double sum = 0; if (samples > 0) { min = Double.MAX_VALUE; max = Double.MIN_VALUE; for (Entry<Operator, StatisticalData> entry : opsMap.entrySet()) { double c = operatorsWeightMap.get(entry.getKey()); sum += c * entry.getValue().getMean(); min = FastMath.min(min, c * entry.getValue().getMin()); max = FastMath.max(max, c * entry.getValue().getMax()); } mean = sum / samples; } // set clock cycles actionWeights.setClockcycles(mean); actionWeights.setClockcyclesMin(min); actionWeights.setClockcyclesMax(max); // set workload actionWeights.setWorkload(sum / networkCost * 100); actorCost += sum; // finally, add it to the list actorWeights.getActionsWeights().add(actionWeights); } // set workload actorWeights.setWorkload(actorCost / networkCost * 100); // finally, add it to the list netWeights.getActorsWeights().add(actorWeights); } return netWeights; }
From source file:no.ssb.vtl.script.operations.join.AbstractJoinOperation.java
/** * Ensure sorted.//from w w w . j av a 2 s.c o m */ protected Stream<DataPoint> sortIfNeeded(Dataset dataset, Order order) { // Adjust the order to the structure. Order.Builder adjustedOrder = Order.create(dataset.getDataStructure()); Table<Component, Dataset, Component> mapping = getComponentMapping(); for (Map.Entry<Component, Order.Direction> orderEntry : order.entrySet()) { Map<Dataset, Component> rowMapping = mapping.row(orderEntry.getKey()); if (!rowMapping.containsKey(dataset)) continue; Component component = rowMapping.get(dataset); if (component.isIdentifier()) { Order.Direction direction = orderEntry.getValue(); adjustedOrder.put(component, direction); } } return dataset.getData(adjustedOrder.build()) .orElseGet(() -> dataset.getData().sorted(adjustedOrder.build())); }
From source file:org.sonar.server.measure.ws.SearchHistoryResponseFactory.java
private UnaryOperator<SearchHistoryResponse.Builder> addMeasures() { Map<Integer, MetricDto> metricsById = result.getMetrics().stream() .collect(MoreCollectors.uniqueIndex(MetricDto::getId)); Map<String, SnapshotDto> analysesByUuid = result.getAnalyses().stream() .collect(MoreCollectors.uniqueIndex(SnapshotDto::getUuid)); Table<MetricDto, SnapshotDto, MeasureDto> measuresByMetricByAnalysis = HashBasedTable .create(result.getMetrics().size(), result.getAnalyses().size()); result.getMeasures().forEach(m -> measuresByMetricByAnalysis.put(metricsById.get(m.getMetricId()), analysesByUuid.get(m.getAnalysisUuid()), m)); return response -> { result.getMetrics().stream().peek(metric -> measure.clear()).map(addMetric()) .map(metric -> addValues(measuresByMetricByAnalysis.row(metric)).apply(metric)) .forEach(metric -> response.addMeasures(measure)); return response; };/* w w w . j a v a 2 s.c o m*/ }
From source file:com.netflix.spinnaker.fiat.permissions.RedisPermissionsRepository.java
@Override public Map<String, UserPermission> getAllByRoles(List<String> anyRoles) { if (anyRoles == null) { return getAllById(); } else if (anyRoles.isEmpty()) { val unrestricted = get(UNRESTRICTED); if (unrestricted.isPresent()) { val map = new HashMap<String, UserPermission>(); map.put(UNRESTRICTED, unrestricted.get()); return map; }/*from w w w .ja va 2s .co m*/ return new HashMap<>(); } try (Jedis jedis = jedisSource.getJedis()) { Pipeline p = jedis.pipelined(); List<Response<Set<String>>> responses = anyRoles.stream().map(role -> p.smembers(roleKey(role))) .collect(Collectors.toList()); p.sync(); Set<String> dedupedUsernames = responses.stream().flatMap(response -> response.get().stream()) .collect(Collectors.toSet()); dedupedUsernames.add(UNRESTRICTED); Table<String, ResourceType, Response<Map<String, String>>> responseTable = getAllFromRedis( dedupedUsernames); if (responseTable == null) { return new HashMap<>(0); } RawUserPermission rawUnrestricted = new RawUserPermission(responseTable.row(UNRESTRICTED)); UserPermission unrestrictedUser = getUserPermission(UNRESTRICTED, rawUnrestricted); return dedupedUsernames.stream().map(userId -> { RawUserPermission rawUser = new RawUserPermission(responseTable.row(userId)); return getUserPermission(userId, rawUser); }).collect(Collectors.toMap(UserPermission::getId, permission -> permission.merge(unrestrictedUser))); } }
From source file:org.eclipse.viatra.query.runtime.base.core.EMFBaseIndexMetaStore.java
/** * Maintains subtype hierarchy// w w w . j a v a 2 s. c o m * * @param subClassKey * EClass or String id of subclass * @param superClassKey * EClass or String id of superclass */ private void maintainTypeHierarhyInternal(final Object subClassKey, final Object superClassKey) { // update observed class and instance listener tables according to new subtype information Map<Object, IndexingLevel> allObservedClasses = navigationHelper.getAllObservedClassesInternal(); if (allObservedClasses.containsKey(superClassKey)) { // we know that there are no known subtypes of subClassKey at this point, so a single insert should suffice allObservedClasses.put(subClassKey, allObservedClasses.get(superClassKey)); } final Table<Object, InstanceListener, Set<EClass>> instanceListeners = navigationHelper .peekInstanceListeners(); if (instanceListeners != null) { // table already constructed for (final Entry<InstanceListener, Set<EClass>> entry : instanceListeners.row(superClassKey) .entrySet()) { final InstanceListener listener = entry.getKey(); for (final EClass subscriptionType : entry.getValue()) { navigationHelper.addInstanceListenerInternal(listener, subscriptionType, subClassKey); } } } // update subtype maps Set<Object> subTypes = subTypeMap.computeIfAbsent(superClassKey, k -> new HashSet<>()); subTypes.add(subClassKey); Set<Object> superTypes = superTypeMap.computeIfAbsent(subClassKey, k -> new HashSet<>()); superTypes.add(superClassKey); }
From source file:su.opencode.shuffler.RenamingVisitor.java
protected List<String> generateNameList(Table<String, String, Double> chainTable) { List<String> result = new ArrayList<String>(); String current = ""; while (result.isEmpty() || !"".equals(current)) { Map<String, Double> probs = chainTable.row(current); if (probs.isEmpty()) { current = ""; } else {/*from w w w . j a v a 2s.c om*/ Iterator<Map.Entry<String, Double>> i = probs.entrySet().iterator(); double rnd = ThreadLocalRandom.current().nextDouble(); double sum = 0; Map.Entry<String, Double> e = null; while (i.hasNext() && rnd > sum) { e = i.next(); sum += e.getValue(); } current = e == null ? "" : e.getKey(); result.add(current); } } return result; }
From source file:mtsar.processors.answer.KOSAggregator.java
private Table<Integer, Integer, Double> tasksUpdate(Table<Integer, Integer, Short> graph, Table<Integer, Integer, Double> ys) { final Table<Integer, Integer, Double> xs = HashBasedTable.create(graph.rowKeySet().size(), graph.columnKeySet().size()); for (final Table.Cell<Integer, Integer, Short> cell : graph.cellSet()) { double sumProduct = 0.0; final int taskId = cell.getRowKey(), workerId = cell.getColumnKey(); final Map<Integer, Short> workers = graph.row(taskId); for (final Map.Entry<Integer, Short> worker : workers.entrySet()) { if (worker.getKey() == workerId) continue; sumProduct += worker.getValue() * ys.get(taskId, worker.getKey()); }/*from ww w . ja v a 2 s . co m*/ xs.put(taskId, workerId, sumProduct); } return xs; }
From source file:com.netflix.spinnaker.fiat.permissions.RedisPermissionsRepository.java
@Override public Map<String, UserPermission> getAllById() { Table<String, ResourceType, Response<Map<String, String>>> responseTable = getAllFromRedis(); if (responseTable == null) { return new HashMap<>(0); }/*from www. ja v a 2s .co m*/ Map<String, UserPermission> allById = new HashMap<>(responseTable.rowKeySet().size()); RawUserPermission rawUnrestricted = new RawUserPermission(responseTable.row(UNRESTRICTED)); UserPermission unrestrictedUser = getUserPermission(UNRESTRICTED, rawUnrestricted); for (String userId : responseTable.rowKeySet()) { RawUserPermission rawUser = new RawUserPermission(responseTable.row(userId)); UserPermission permission = getUserPermission(userId, rawUser); allById.put(userId, permission.merge(unrestrictedUser)); } return allById; }
From source file:com.android.builder.internal.SymbolWriter.java
public void write() throws IOException { Splitter splitter = Splitter.on('.'); Iterable<String> folders = splitter.split(mPackageName); File file = new File(mOutFolder); for (String folder : folders) { file = new File(file, folder); }/* w ww.j ava 2 s . c om*/ file.mkdirs(); file = new File(file, SdkConstants.FN_RESOURCE_CLASS); Closer closer = Closer.create(); try { BufferedWriter writer = closer.register(Files.newWriter(file, Charsets.UTF_8)); writer.write("/* AUTO-GENERATED FILE. DO NOT MODIFY.\n"); writer.write(" *\n"); writer.write(" * This class was automatically generated by the\n"); writer.write(" * aapt tool from the resource data it found. It\n"); writer.write(" * should not be modified by hand.\n"); writer.write(" */\n"); writer.write("package "); writer.write(mPackageName); writer.write(";\n\npublic final class R {\n"); Table<String, String, SymbolEntry> symbols = getAllSymbols(); Table<String, String, SymbolEntry> values = mValues.getSymbols(); Set<String> rowSet = symbols.rowKeySet(); List<String> rowList = Lists.newArrayList(rowSet); Collections.sort(rowList); for (String row : rowList) { writer.write("\tpublic static final class "); writer.write(row); writer.write(" {\n"); Map<String, SymbolEntry> rowMap = symbols.row(row); Set<String> symbolSet = rowMap.keySet(); ArrayList<String> symbolList = Lists.newArrayList(symbolSet); Collections.sort(symbolList); for (String symbolName : symbolList) { // get the matching SymbolEntry from the values Table. SymbolEntry value = values.get(row, symbolName); if (value != null) { writer.write("\t\tpublic static final "); writer.write(value.getType()); writer.write(" "); writer.write(value.getName()); writer.write(" = "); writer.write(value.getValue()); writer.write(";\n"); } } writer.write("\t}\n"); } writer.write("}\n"); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
From source file:com.rackspacecloud.blueflood.io.astyanax.AstyanaxWriter.java
public void writeMetadata(Table<Locator, String, String> metaTable) throws ConnectionException { ColumnFamily cf = CassandraModel.CF_METRICS_METADATA; Timer.Context ctx = Instrumentation.getBatchWriteTimerContext(CassandraModel.CF_METRICS_METADATA_NAME); MutationBatch batch = keyspace.prepareMutationBatch(); try {/*from w ww . ja va 2 s . c o m*/ for (Locator locator : metaTable.rowKeySet()) { Map<String, String> metaRow = metaTable.row(locator); ColumnListMutation<String> mutation = batch.withRow(cf, locator); for (Map.Entry<String, String> meta : metaRow.entrySet()) { mutation.putColumn(meta.getKey(), meta.getValue(), StringMetadataSerializer.get(), null); } } try { batch.execute(); } catch (ConnectionException e) { Instrumentation.markWriteError(e); log.error("Connection exception persisting metadata", e); throw e; } } finally { ctx.stop(); } }