List of usage examples for com.google.common.collect Table get
V get(@Nullable Object rowKey, @Nullable Object columnKey);
From source file:com.ggvaidya.scinames.complexquery.ComplexQueryViewController.java
private TableColumn<NameCluster, String> createColumnFromPrecalc(String colName, Table<NameCluster, String, Set<String>> precalc) { TableColumn<NameCluster, String> column = new TableColumn<>(colName); column.cellValueFactoryProperty().set((TableColumn.CellDataFeatures<NameCluster, String> cdf) -> { NameCluster nc = cdf.getValue(); // There might be columns found in some dataset but not in others // so we detect those cases here and put in "NA"s instead. String output = "NA"; if (precalc.contains(nc, colName)) output = precalc.get(nc, colName).stream().collect(Collectors.joining("; ")); return new ReadOnlyStringWrapper(output); });//from ww w . jav a 2 s .com column.setPrefWidth(100.0); column.setEditable(false); return column; }
From source file:org.expretio.maven.plugins.capnp.CapnProtoMojo.java
private void doHandleNativesDependency() throws MojoExecutionException { String classifier;/* w w w. jav a 2s . c om*/ if (nativeDependencyClassifier.equals(AUTO_CLASSIFIER_DEFAULT)) { Table<String, String, String> indexTable = HashBasedTable.create(); try { XMLConfiguration index = new XMLConfiguration(); index.load(resolve(createNativesIndexArtifact())); for (HierarchicalConfiguration indexEntry : index.configurationsAt("entry")) { String osName = indexEntry.getString("os-name"); String archNames = indexEntry.getString("arch-names"); String mavenClassifier = indexEntry.getString("maven-classifier"); for (String archName : Splitter.on(',').omitEmptyStrings().trimResults().split(archNames)) { indexTable.put(osName.toUpperCase(), getCanonicalArchitecture(archName), mavenClassifier); } } classifier = indexTable.get(JavaPlatform.getCurrentOs().toString(), getCanonicalArchitecture(JavaPlatform.getCurrentArch())); } catch (Exception e) { throw new NativesManagerException(e); } } else { classifier = nativeDependencyClassifier; } nativesManager.addResourceUrl(resolve(createNativesArtifact(classifier))); }
From source file:org.apache.sentry.cli.tools.SentryConfigToolIndexer.java
private void convertINIToSentryServiceCmds(String component, String service, String requestorName, Configuration conf, SentryGenericServiceClient client, String policyFile, boolean validate, boolean importPolicy, boolean checkCompat) throws Exception { //instantiate a file providerBackend for parsing LOGGER.info("Reading policy file at: " + policyFile); SimpleFileProviderBackend policyFileBackend = new SimpleFileProviderBackend(conf, policyFile); ProviderBackendContext context = new ProviderBackendContext(); context.setValidators(IndexerPrivilegeModel.getInstance().getPrivilegeValidators()); policyFileBackend.initialize(context); if (validate) { validatePolicy(policyFileBackend); }//w w w .j a v a 2 s . c o m if (checkCompat) { checkCompat(policyFileBackend); } //import the relations about group,role and privilege into the DB store Set<String> roles = Sets.newHashSet(); Table<String, String, Set<String>> groupRolePrivilegeTable = policyFileBackend.getGroupRolePrivilegeTable(); GenericPrivilegeConverter converter = new GenericPrivilegeConverter(component, service, false); for (String groupName : groupRolePrivilegeTable.rowKeySet()) { for (String roleName : groupRolePrivilegeTable.columnKeySet()) { if (!roles.contains(roleName)) { LOGGER.info(dryRunMessage(importPolicy) + "Creating role: " + roleName.toLowerCase(Locale.US)); if (importPolicy) { client.createRoleIfNotExist(requestorName, roleName, component); } roles.add(roleName); } Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName); if (privileges == null) { continue; } LOGGER.info(dryRunMessage(importPolicy) + "Adding role: " + roleName.toLowerCase(Locale.US) + " to group: " + groupName); if (importPolicy) { client.grantRoleToGroups(requestorName, roleName, component, Sets.newHashSet(groupName)); } for (String permission : privileges) { String action = null; for (String authorizable : AUTHORIZABLE_SPLITTER.trimResults().split(permission)) { KeyValue kv = new KeyValue(authorizable); String key = kv.getKey(); String value = kv.getValue(); if ("action".equalsIgnoreCase(key)) { action = value; } } // Service doesn't support not specifying action if (action == null) { permission += "->action=" + Action.ALL; } LOGGER.info(dryRunMessage(importPolicy) + "Adding permission: " + permission + " to role: " + roleName.toLowerCase(Locale.US)); if (importPolicy) { client.grantPrivilege(requestorName, roleName, component, converter.fromString(permission)); } } } } }
From source file:mtsar.processors.answer.KOSAggregator.java
private Map<Integer, Double> converge(Table<Integer, Integer, Short> graph, int kMax) { final RealDistribution distribution = new NormalDistribution(1, 1); Table<Integer, Integer, Double> ys = HashBasedTable.create(graph.rowKeySet().size(), graph.columnKeySet().size()); for (final Table.Cell<Integer, Integer, Short> cell : graph.cellSet()) { ys.put(cell.getRowKey(), cell.getColumnKey(), distribution.sample()); }/* ww w.ja va 2 s.c o m*/ for (int k = 1; k <= kMax; k++) { final Table<Integer, Integer, Double> xs = tasksUpdate(graph, ys); if (k < kMax) ys = workersUpdate(graph, xs); } final Map<Integer, Double> estimations = new HashMap<>(); for (final Integer taskId : graph.rowKeySet()) { double sumProduct = 0.0; final Map<Integer, Double> workers = ys.row(taskId); for (final Map.Entry<Integer, Double> worker : workers.entrySet()) { sumProduct += graph.get(taskId, worker.getKey()) * worker.getValue(); } estimations.put(taskId, sumProduct); } return estimations; }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
@FXML private void displayComparisonStats(ActionEvent e) { Dataset ds1 = dataset1ComboBox.getValue(); Dataset ds2 = dataset2ComboBox.getValue(); Table<String, Dataset, String> precalc = getComparisonStats(ds1, ds2); ObservableList<TableColumn> cols = comparisonTableView.getColumns(); cols.clear();/*from ww w . jav a 2 s .co m*/ TableColumn<String, String> rowName = new TableColumn<>(""); rowName.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(cvf.getValue())); cols.add(rowName); for (Dataset ds : Arrays.asList(ds1, ds2)) { TableColumn<String, String> datasetCol = new TableColumn<>(ds.getName()); datasetCol.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(precalc.get(cvf.getValue(), ds))); cols.add(datasetCol); } // The "items" here are just the rows we've calculated. comparisonTableView.setItems(getComparisonStatRowHeaders()); }
From source file:com.lyndir.omicron.cli.view.MapView.java
@Override protected void drawForeground(final Screen screen) { super.drawForeground(screen); Optional<IGameController> gameController = OmicronCLI.get().getGameController(); if (!gameController.isPresent()) return;/*from w w w . j a v a 2s . c om*/ Optional<IPlayer> localPlayerOptional = OmicronCLI.get().getLocalPlayer(); if (!localPlayerOptional.isPresent()) return; IPlayer localPlayer = localPlayerOptional.get(); // Create an empty grid. Size levelSize = gameController.get().getGame().getLevel(getLevelType()).getSize(); Table<Integer, Integer, ITile> grid = HashBasedTable.create(levelSize.getHeight(), levelSize.getWidth()); // Iterate observable tiles and populate the grid. localPlayer.observableTiles().forEach(tile -> { Vec2 coordinate = positionToMapCoordinate(tile.getPosition()); grid.put(coordinate.getY(), coordinate.getX(), tile); }); // Draw grid in view. Box contentBox = getContentBoxOnScreen(); for (int screenX = contentBox.getLeft(); screenX <= contentBox.getRight(); ++screenX) for (int screenY = contentBox.getTop(); screenY <= contentBox.getBottom(); ++screenY) { int tileY = screenY - contentBox.getTop() + getOffset().getY(); int tileX = screenX - contentBox.getLeft() + getOffset().getX(); if (!levelSize.isInBounds(Vec2.create(tileX, tileY))) continue; ITile tile = grid.get(tileY, tileX); Maybe<? extends IGameObject> contents; Terminal.Color bgColor = getBackgroundColor(); if (tile == null) contents = Maybe.empty(); else { contents = tile.getContents(); bgColor = levelTypeColors.get(tile.getLevel().getType()); for (final ResourceType resourceType : ResourceType.values()) { Maybe<Integer> resourceQuantity = tile.getResourceQuantity(resourceType); if (resourceQuantity.presence() == Maybe.Presence.PRESENT) bgColor = resourceTypeColors.get(resourceType); } } screen.putString(screenX + (screenY % 2 == 0 ? 0 : 1), screenY, contents.presence() == Maybe.Presence.PRESENT ? contents.get().getType().getTypeName().substring(0, 1) : " ", getMapColor(), bgColor, ScreenCharacterStyle.Bold); // Draw off-screen warning labels. } Inset offScreen = new Inset(Math.max(0, getOffset().getY()), Math.max(0, levelSize.getWidth() - contentBox.getSize().getWidth() - getOffset().getX() + 1), Math.max(0, levelSize.getHeight() - contentBox.getSize().getHeight() - getOffset().getY() - 1), Math.max(0, getOffset().getX())); int centerX = contentBox.getLeft() + (levelSize.getWidth() - offScreen.getHorizontal()) / 2 - getOffset().getX() + offScreen.getLeft(); int centerY = contentBox.getTop() + (levelSize.getHeight() - offScreen.getVertical()) / 2 - getOffset().getY() + offScreen.getTop(); centerX = Math.min(contentBox.getRight() - 3, Math.max(contentBox.getLeft(), centerX)); centerY = Math.min(contentBox.getBottom() - 1, Math.max(contentBox.getTop() + 1, centerY)); if (offScreen.getTop() > 0) screen.putString(centerX, contentBox.getTop(), // String.format("%+d", offScreen.getTop()), getInfoTextColor(), getInfoBackgroundColor()); if (offScreen.getRight() > 0) { String label = String.format("%+d", offScreen.getRight()); screen.putString(contentBox.getRight() - label.length(), centerY, // label, getInfoTextColor(), getInfoBackgroundColor()); } if (offScreen.getBottom() > 0) screen.putString(centerX, contentBox.getBottom(), // String.format("%+d", offScreen.getBottom()), getInfoTextColor(), getInfoBackgroundColor()); if (offScreen.getLeft() > 0) screen.putString(contentBox.getLeft(), centerY, // String.format("%+d", offScreen.getLeft()), getInfoTextColor(), getInfoBackgroundColor()); }
From source file:org.apache.sentry.binding.hive.authz.SentryConfigTool.java
public void importPolicy() throws Exception { final String requestorUserName = "hive"; SimpleFileProviderBackend policyFileBackend; SentryPolicyServiceClient client;//from ww w . j a v a 2s . co m policyFileBackend = new SimpleFileProviderBackend(getAuthzConf(), getAuthzConf().get(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar())); ProviderBackendContext context = new ProviderBackendContext(); context.setAllowPerDatabase(true); policyFileBackend.initialize(context); client = SentryServiceClientFactory.create(getAuthzConf()); Set<String> roles = new HashSet<String>(); for (TSentryRole sentryRole : client.listRoles(requestorUserName)) { roles.add(sentryRole.getRoleName()); } Table<String, String, Set<String>> groupRolePrivilegeTable = policyFileBackend.getGroupRolePrivilegeTable(); for (String groupName : groupRolePrivilegeTable.rowKeySet()) { for (String roleName : groupRolePrivilegeTable.columnKeySet()) { if (!roles.contains(roleName)) { client.createRole(requestorUserName, roleName); System.out.println(String.format("CREATE ROLE %s;", roleName)); roles.add(roleName); } Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName); if (privileges == null) { continue; } client.grantRoleToGroup(requestorUserName, groupName, roleName); System.out.println(String.format("GRANT ROLE %s TO GROUP %s;", roleName, groupName)); for (String permission : privileges) { String server = null; String database = null; String table = null; String column = null; String uri = null; String action = AccessConstants.ALL; for (String authorizable : PolicyFileConstants.AUTHORIZABLE_SPLITTER.trimResults() .split(permission)) { KeyValue kv = new KeyValue(authorizable); DBModelAuthorizable a = DBModelAuthorizables.from(kv); if (a == null) { action = kv.getValue(); continue; } switch (a.getAuthzType()) { case Server: server = a.getName(); break; case Db: database = a.getName(); break; case Table: case View: table = a.getName(); break; case URI: uri = a.getName(); break; case Column: column = a.getName(); break; default: break; } } if (uri != null) { System.out.println(String.format("# server=%s", server)); System.out.println(String.format("GRANT ALL ON URI %s TO ROLE %s;", uri, roleName)); client.grantURIPrivilege(requestorUserName, roleName, server, uri); } else if (column != null && !AccessConstants.ALL.equals(column)) { System.out.println(String.format("# server=%s, database=%s", server, database)); System.out.println(String.format("GRANT %s (%s) ON TABLE %s TO ROLE %s;", "*".equals(action) ? "ALL" : action.toUpperCase(), column, table, roleName)); client.grantColumnPrivilege(requestorUserName, roleName, server, database, table, column, action); } else if (table != null && !AccessConstants.ALL.equals(table)) { System.out.println(String.format("# server=%s, database=%s", server, database)); System.out.println(String.format("GRANT %s ON TABLE %s TO ROLE %s;", "*".equals(action) ? "ALL" : action.toUpperCase(), table, roleName)); client.grantTablePrivilege(requestorUserName, roleName, server, database, table, action); } else if (database != null && !AccessConstants.ALL.equals(database)) { System.out.println(String.format("# server=%s", server)); System.out.println(String.format("GRANT %s ON DATABASE %s TO ROLE %s;", "*".equals(action) ? "ALL" : action.toUpperCase(), database, roleName)); client.grantDatabasePrivilege(requestorUserName, roleName, server, database, action); } else if (server != null) { System.out.println(String.format("GRANT ALL ON SERVER %s TO ROLE %s;", server, roleName)); client.grantServerPrivilege(requestorUserName, roleName, server, action); } else { System.out.println(String.format("No grant for permission %s", permission)); } } } } }
From source file:org.broad.igv.sam.AlignmentPacker.java
/** * Allocates each alignment to the rows such that there is no overlap. * * @param intervalList The order of this list determines how alignments will be packed * Each {@code AlignmentInterval} must have alignments sorted by start position * @param renderOptions//from w w w . j a v a2s .c o m */ public PackedAlignments packAlignments(List<AlignmentInterval> intervalList, AlignmentTrack.RenderOptions renderOptions) { if (renderOptions == null) renderOptions = new AlignmentTrack.RenderOptions(); LinkedHashMap<String, List<Row>> packedAlignments = new LinkedHashMap<String, List<Row>>(); boolean pairAlignments = renderOptions.isViewPairs() || renderOptions.isPairedArcView(); // if (iter == null || !iter.hasNext()) { // return new PackedAlignments(intervalList, packedAlignments, renderOptions); // } if (renderOptions.groupByOption == null) { List<Row> alignmentRows = new ArrayList<Row>(10000); packAlignmentInterval(intervalList, pairAlignments, alignmentRows); packedAlignments.put("", alignmentRows); } else { // Separate alignments into groups. Table<String, Integer, List<Alignment>> groupedAlignments = HashBasedTable.create(); for (int intervalIndex = 0; intervalIndex < intervalList.size(); intervalIndex++) { AlignmentInterval interval = intervalList.get(intervalIndex); Iterator<Alignment> iter = interval.getAlignmentIterator(); while (iter.hasNext()) { Alignment alignment = iter.next(); String groupKey = getGroupValue(alignment, renderOptions); if (groupKey == null) { groupKey = NULL_GROUP_VALUE; } List<Alignment> groupList = groupedAlignments.get(groupKey, intervalIndex); if (groupList == null) { groupList = new ArrayList<Alignment>(1000); groupedAlignments.put(groupKey, intervalIndex, groupList); } groupList.add(alignment); } } // Now alphabetize (sort) and pack the groups List<String> keys = new ArrayList<String>(groupedAlignments.rowKeySet()); Comparator<String> groupComparator = getGroupComparator(renderOptions.groupByOption); Collections.sort(keys, groupComparator); for (String key : keys) { List<Row> alignmentRows = new ArrayList<Row>(10000); Map<Integer, List<Alignment>> group = groupedAlignments.row(key); pack(group, pairAlignments, alignmentRows); packedAlignments.put(key, alignmentRows); } //Put null valued group at end List<Row> alignmentRows = new ArrayList<Row>(10000); Map<Integer, List<Alignment>> group = groupedAlignments.row(NULL_GROUP_VALUE); pack(group, pairAlignments, alignmentRows); packedAlignments.put("", alignmentRows); } return new PackedAlignments(intervalList, packedAlignments, renderOptions); }
From source file:com.ggvaidya.scinames.ui.DataReconciliatorController.java
private TableColumn<String, String> createColumnFromPrecalc(String colName, Table<String, String, Set<String>> precalc) { TableColumn<String, String> column = new TableColumn<>(colName); column.cellValueFactoryProperty().set((TableColumn.CellDataFeatures<String, String> cdf) -> { String clusterID = cdf.getValue(); // There might be columns found in some dataset but not in others // so we detect those cases here and put in "NA"s instead. String output = "NA"; if (precalc.contains(clusterID, colName)) output = precalc.get(clusterID, colName).stream().collect(Collectors.joining("; ")); return new ReadOnlyStringWrapper(output); });//from www . jav a2 s . com column.setPrefWidth(100.0); column.setEditable(false); return column; }
From source file:co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator.java
/** * Given a {@link FlowSpecification}.//from w w w.ja va2 s . c o m * * @param input {@link FlowSpecification} * @return A {@link Table} */ @Override public Table<Node, String, Set<QueueSpecification>> create(FlowSpecification input) { Table<Node, String, Set<QueueSpecification>> table = HashBasedTable.create(); String flow = input.getName(); Map<String, FlowletDefinition> flowlets = input.getFlowlets(); // Iterate through connections of a flow. for (FlowletConnection connection : input.getConnections()) { final String source = connection.getSourceName(); final String target = connection.getTargetName(); final Node sourceNode = new Node(connection.getSourceType(), source); Set<QueueSpecification> queueSpec; if (connection.getSourceType() == FlowletConnection.Type.FLOWLET) { queueSpec = generateQueueSpecification(appId, flow, connection, flowlets.get(target).getInputs(), flowlets.get(source).getOutputs()); } else { queueSpec = generateQueueSpecification(appId, flow, connection, flowlets.get(target).getInputs(), ImmutableMap.<String, Set<Schema>>of(connection.getSourceName(), ImmutableSet.of(STREAM_EVENT_SCHEMA))); } Set<QueueSpecification> queueSpecifications = table.get(sourceNode, target); if (queueSpecifications == null) { queueSpecifications = Sets.newHashSet(); table.put(sourceNode, target, queueSpecifications); } queueSpecifications.addAll(queueSpec); } return table; }