Java Code Examples for com.google.common.collect.Table#cellSet()

The following examples show how to use com.google.common.collect.Table#cellSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapConfig.java    From qconfig with MIT License 6 votes vote down vote up
private static Map<String, String> parseTable(String data, boolean trimValue) throws IOException {
    if (data == null) {
        return ImmutableMap.of();
    }

    TableConfig.TableParser parser;
    if (trimValue) {
        parser = TableConfig.TRIM_PARSER;
    } else {
        parser = TableConfig.NOT_TRIM_PARSER;
    }

    Table<String, String, String> table = parser.parse(data);
    Map<String, String> map = new LinkedHashMap<String, String>(table.size());
    for (Table.Cell<String, String, String> cell : table.cellSet()) {
        map.put(generateKey(cell.getRowKey(), cell.getColumnKey()), cell.getValue());
    }
    return ImmutableMap.copyOf(map);
}
 
Example 2
Source File: YarnTwillRunnerService.java    From twill with Apache License 2.0 6 votes vote down vote up
/**
 * Renews the {@link SecureStore} for all the running applications.
 *
 * @param liveApps set of running applications that need to have secure store renewal
 * @param renewer the {@link SecureStoreRenewer} for renewal
 * @param mergeCredentials {@code true} to merge with existing credentials
 * @return a {@link Multimap} containing the application runs that were failed to have secure store renewed
 */
private Multimap<String, RunId> renewSecureStore(Table<String, RunId, YarnTwillController> liveApps,
                                                 SecureStoreRenewer renewer, boolean mergeCredentials) {
  Multimap<String, RunId> failureRenews = HashMultimap.create();

  // Renew the secure store for each running application
  for (Table.Cell<String, RunId, YarnTwillController> liveApp : liveApps.cellSet()) {
    String application = liveApp.getRowKey();
    RunId runId = liveApp.getColumnKey();
    YarnTwillController controller = liveApp.getValue();

    try {
      renewer.renew(application, runId, new YarnSecureStoreWriter(application, runId, controller, mergeCredentials));
    } catch (Exception e) {
      LOG.warn("Failed to renew secure store for {}:{}", application, runId, e);
      failureRenews.put(application, runId);
    }
  }

  return failureRenews;
}
 
Example 3
Source File: ParallelCorpusReader.java    From EasySRL with Apache License 2.0 6 votes vote down vote up
private static Collection<SRLParse> getPropbankSection(final String section) throws IOException {
	final Table<String, Integer, TreebankParse> PTB = new PennTreebank().readCorpus(WSJ);
	final Table<String, Integer, SRLParse> srlParses = SRLParse.parseCorpus(PTB,
			Util.readFileLineByLine(new File(PROPBANK, "prop.txt")),
			USING_NOMBANK ? Util.readFileLineByLine(NOMBANK) : null);

	final Table<String, Integer, SRLParse> goldParses = TreeBasedTable.create();
	for (final Cell<String, Integer, TreebankParse> cell : PTB.cellSet()) {

		// Propbank files skip sentences with no SRL deps. Add a default
		// empty parse for all sentences.
		goldParses.put(cell.getRowKey(), cell.getColumnKey(), new SRLParse(cell.getValue().getWords()));
	}
	goldParses.putAll(srlParses);

	final Collection<SRLParse> result = new ArrayList<>();
	for (final Cell<String, Integer, SRLParse> entry : goldParses.cellSet()) {
		if (entry.getRowKey().startsWith("wsj_" + section)) {
			result.add(entry.getValue());
		}
	}
	return result;
}
 
Example 4
Source File: FoldableTree.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Table<?, ASTNode, ArrayList<String>> performOp(final FoldableNode fn,
		final Table<?, ASTNode, ArrayList<String>> prev) {

	// Check if ASTNode has a FoldableNode parent
	// If so, add it to a child FoldableNode (along with its terms)
	for (final Table.Cell<?, ASTNode, ArrayList<String>> cell : prev.cellSet()) {

		if (cell.getColumnKey() == fn.node) {
			final FoldableNode fnChild = new FoldableNode((ASTNode) cell.getRowKey());
			fnChild.addTerms(cell.getValue());
			fn.addChild(fnChild);
		}
	}
	return prev;
}
 
Example 5
Source File: SparseTableTestCase.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
protected MathTable<Integer> getTable(boolean orientation, int dimension, Table<Integer, Integer, Integer> data) {
    SparseTable<Integer> table = new SparseTable<>(orientation, dimension, dimension, new Int2ObjectAVLTreeMap<>());
    for (Cell<Integer, Integer, Integer> cell : data.cellSet()) {
        table.setValue(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
    }
    return table;
}
 
Example 6
Source File: DenseTableTestCase.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
protected MathTable<Integer> getTable(boolean orientation, int dimension, Table<Integer, Integer, Integer> data) {
    DenseTable<Integer> table = new DenseTable<>(orientation, dimension, dimension, new Integer[dimension * dimension]);
    for (Cell<Integer, Integer, Integer> cell : data.cellSet()) {
        table.setValue(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
    }
    return table;
}
 
Example 7
Source File: IDEALRunner.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isInErrorState(WeightedForwardQuery<TransitionFunction> key, ForwardBoomerangResults<TransitionFunction> forwardBoomerangResults) {
    Table<Statement, Val, TransitionFunction> objectDestructingStatements = forwardBoomerangResults.asStatementValWeightTable();
    for(Table.Cell<Statement,Val,TransitionFunction> c : objectDestructingStatements.cellSet()){
        for(ITransition t : c.getValue().values()){
            if(t.to() != null){
                if(t.to().isErrorState()){
                    return true;
                }
            }
        }

    }
  return false;
}
 
Example 8
Source File: ParserAStar.java    From easyccg with MIT License 5 votes vote down vote up
private SeenRules(File file) throws IOException {   
  if (file == null) {
    seen = null;
    numberOfSeenCategories = 0;
  } else if (!file.exists()) {
    System.err.println("No 'seenRules' file available for model. Allowing all CCG-legal rules.");
    seen = null;
    numberOfSeenCategories = 0;
  } else {
    Table<Category, Category, Boolean> tab = HashBasedTable.create();
    int maxID = 0;
    for (String line : Util.readFile(file)) {
      // Assumes the file has the format:
      // cat1 cat2
      if (!line.startsWith("#") && !line.isEmpty()) {
        String[] fields = line.split(" ");
        Category left = Category.valueOf(fields[0]);
        Category right = Category.valueOf(fields[1]);
        maxID = Math.max(left.getID(), maxID);
        maxID = Math.max(right.getID(), maxID);
        tab.put(simplify(left), simplify(right), true);
      }
    }
    
    seen = new boolean[maxID + 1][maxID + 1];
    for (Cell<Category, Category, Boolean> entry : tab.cellSet()) {
      seen[entry.getRowKey().getID()][entry.getColumnKey().getID()] = true;
    }
    numberOfSeenCategories = seen.length;
  }
}
 
Example 9
Source File: CustomCrossSourceStatementReactorBuilder.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public @NonNull CustomCrossSourceStatementReactorBuilder addAllVersionSpecificSupports(
        final ModelProcessingPhase phase,
        final Table<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificSupports) {
    final StatementSupportBundle.Builder stmtBundleBuilder = reactorSupportBundles.get(phase);
    for (final Cell<YangVersion, QName, StatementSupport<?, ?, ?>> cell : versionSpecificSupports.cellSet()) {
        stmtBundleBuilder.addVersionSpecificSupport(cell.getRowKey(), cell.getValue());
    }
    return this;
}
 
Example 10
Source File: SimpleFileProviderBackend.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private void mergeResult(Table<String, String, Set<String>> groupRolePrivilegeTableTemp) {
  for (Cell<String, String, Set<String>> cell : groupRolePrivilegeTableTemp.cellSet()) {
    String groupName = cell.getRowKey();
    String roleName = cell.getColumnKey();
    Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName);
    if (privileges == null) {
      privileges = new HashSet<String>();
      groupRolePrivilegeTable.put(groupName, roleName, privileges);
    }
    privileges.addAll(cell.getValue());
  }
}
 
Example 11
Source File: DAbstractMetricsRW.java    From blueflood with Apache License 2.0 5 votes vote down vote up
/**
 * Fetches a {@link com.rackspacecloud.blueflood.types.Points} object for a
 * particular locator and rollupType from the specified column family and
 * range
 *
 * @param locator
 * @param rollupType
 * @param range
 * @param columnFamilyName
 * @return
 */
@Override
public Points getDataToRollup(final Locator locator,
                              RollupType rollupType,
                              Range range,
                              String columnFamilyName) throws IOException {
    Timer.Context ctx = Instrumentation.getReadTimerContext(columnFamilyName);
    try {
        // read the rollup object from the proper IO class
        DAbstractMetricIO io = getIO( rollupType.name().toLowerCase(), CassandraModel.getGranularity( columnFamilyName ) );

        Table<Locator, Long, Object> locatorTimestampRollup = io.getRollupsForLocator( locator, columnFamilyName, range );

        Points points = new Points();
        for (Table.Cell<Locator, Long, Object> cell : locatorTimestampRollup.cellSet()) {
            points.add( createPoint( cell.getColumnKey(), cell.getValue()));
        }
        return points;
    } catch( Exception e ) {

        Instrumentation.markReadError();
        LOG.error( String.format( "Unable to read locator=%s rolluptype=%s columnFamilyName=%s for rollup",
                locator, rollupType.name(), columnFamilyName ), e );

        throw new IOException( e );
    }
    finally {
        ctx.stop();
    }
}
 
Example 12
Source File: DMetadataIO.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Override
public void putAll( Table<Locator, String, String> meta ) throws IOException {

    Timer.Context ctx = Instrumentation.getWriteTimerContext( CassandraModel.CF_METRICS_METADATA_NAME );

    Session session = DatastaxIO.getSession();

    Map<Locator, ResultSetFuture> futures = new HashMap<Locator, ResultSetFuture>();

    try {
        for( Table.Cell<Locator, String, String> cell : meta.cellSet() ) {

            BoundStatement bound = putValue.bind( cell.getRowKey().toString(), cell.getColumnKey(), serDes.serialize( cell.getValue() ) );

            futures.put( cell.getRowKey(), session.executeAsync( bound ) );
        }

        for( Map.Entry<Locator, ResultSetFuture> future : futures.entrySet() ) {

            try {
                ResultSet result = future.getValue().getUninterruptibly();
                LOG.trace( "result.size=" + result.all().size() );
            }
            catch (Exception e ){

                Instrumentation.markWriteError();
                LOG.error( String.format( "error writing to metrics_metadata for %s", future.getKey()), e );
            }
        }
    }
    finally {
        ctx.stop();
    }
}
 
Example 13
Source File: IDESolver.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
protected Set<Cell<N, D, EdgeFunction<V>>> endSummary(N sP, D d3) {
	Table<N, D, EdgeFunction<V>> map = endSummary.get(sP, d3);
	if(map==null) return Collections.emptySet();
	return map.cellSet();
}