下面列出了com.google.common.collect.Table#cellSet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
/**
* 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;
}
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;
}
@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;
}
@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;
}
@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;
}
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;
}
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;
}
}
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;
}
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());
}
}
/**
* 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();
}
}
@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();
}
}
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();
}