下面列出了com.google.common.collect.Table#size ( ) 实例代码,或者点击链接到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);
}
private void cleanPullLogAndCheckpoint() {
final Table<String, String, PullLog> pullLogs = storage.allPullLogs();
if (pullLogs == null || pullLogs.size() == 0) return;
// delete all pull log without max pulled message sequence
for (final String groupAndSubject : pullLogs.columnKeySet()) {
final GroupAndSubject gs = GroupAndSubject.parse(groupAndSubject);
final long maxPulledMessageSequence = storage.getMaxPulledMessageSequence(gs.getSubject(), gs.getGroup());
if (maxPulledMessageSequence == -1) {
for (final Map.Entry<String, PullLog> entry : pullLogs.column(groupAndSubject).entrySet()) {
final String consumerId = entry.getKey();
LOG.info("remove pull log. subject: {}, group: {}, consumerId: {}", gs.getSubject(), gs.getGroup(), consumerId);
storage.destroyPullLog(gs.getSubject(), gs.getGroup(), consumerId);
}
}
}
}
@Override
public Point create() {
Composite parent = getParent();
Table<ToolTipString, ToolTipString, ToolTipString> model = getModel();
if (parent == null || model.size() == 0) {
// avoid displaying empty tool tips.
return null;
}
setupControl(parent);
ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setExpandHorizontal(true);
setupControl(scrolledComposite);
Composite composite = new Composite(scrolledComposite, SWT.NONE);
fComposite = composite;
composite.setLayout(new GridLayout(3, false));
setupControl(composite);
Set<ToolTipString> rowKeySet = model.rowKeySet();
for (ToolTipString row : rowKeySet) {
Set<Entry<ToolTipString, ToolTipString>> entrySet = model.row(row).entrySet();
for (Entry<ToolTipString, ToolTipString> entry : entrySet) {
Label nameLabel = new Label(composite, SWT.NO_FOCUS);
nameLabel.setText(entry.getKey().toString());
setupControl(nameLabel);
Label separator = new Label(composite, SWT.NO_FOCUS | SWT.SEPARATOR | SWT.VERTICAL);
GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gd.heightHint = nameLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
separator.setLayoutData(gd);
setupControl(separator);
Label valueLabel = new Label(composite, SWT.NO_FOCUS);
valueLabel.setText(entry.getValue().toString());
setupControl(valueLabel);
}
}
scrolledComposite.setContent(composite);
Point preferredSize = computePreferredSize();
scrolledComposite.setMinSize(preferredSize.x, preferredSize.y);
return preferredSize;
}
@Override
public boolean hasSingleElement(final Table<?, ?, ?> table) {
return table.size() == 1;
}