下面列出了com.google.common.collect.Maps#immutableEntry ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Iterator<Map.Entry<String, MaintenanceOp>> listMaintenanceOps() {
final Iterator<Map<String, Object>> tableIter =
_backingStore.scan(_systemTable, null, LimitCounter.max(), ReadConsistency.STRONG);
final Supplier<List<TableEventDatacenter>> tableEventDatacenterSupplier = Suppliers.memoize(this::getTableEventDatacenters);
return new AbstractIterator<Map.Entry<String, MaintenanceOp>>() {
@Override
protected Map.Entry<String, MaintenanceOp> computeNext() {
while (tableIter.hasNext()) {
TableJson json = new TableJson(tableIter.next());
MaintenanceOp op = getNextMaintenanceOp(json, false/*don't expose task outside this class*/, tableEventDatacenterSupplier);
if (op != null) {
return Maps.immutableEntry(json.getTable(), op);
}
}
return endOfData();
}
};
}
@Override
public Entry<Key,Value> next() {
if (closed) {
return null;
}
if (hasNext()) {
Entry<Key,Value> cur = this.currentEntry;
this.currentEntry = null;
if (this.reverseIndex) {
Text term = new Text((new StringBuilder(cur.getKey().getRow().toString())).reverse().toString());
cur = Maps.immutableEntry(new Key(term, cur.getKey().getColumnFamily(), cur.getKey().getColumnQualifier(), cur.getKey()
.getColumnVisibility(), cur.getKey().getTimestamp()), cur.getValue());
}
return cur;
}
return null;
}
@Override
public AtomicSwap getSwapByID(String swapID){
try {
Map.Entry swapIdEntry = Maps.immutableEntry("SwapID", swapID);
String requestData = "0x" + Hex.toHexString(EncodeUtils.toJsonStringSortKeys(swapIdEntry).getBytes());
JsonRpcResponse<ABCIQueryResult> rpcResponse = BinanceDexApiClientGenerator.executeSync(binanceDexNodeApi.getSwapByID(requestData));
checkRpcResult(rpcResponse);
ABCIQueryResult.Response response = rpcResponse.getResult().getResponse();
if (response.getCode() != null) {
BinanceDexApiError binanceDexApiError = new BinanceDexApiError();
binanceDexApiError.setCode(response.getCode());
binanceDexApiError.setMessage(response.getLog());
throw new BinanceDexApiException(binanceDexApiError);
}
String swapJson = new String(response.getValue());
return EncodeUtils.toObjectFromJsonString(swapJson, AtomicSwap.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Map.Entry<File, Feature> parse(String file, boolean trimValue) {
String name = file;
String group = null;
long version = -1;
int idx = file.indexOf('#');
if (idx != -1) {
group = file.substring(0, idx);
name = file = file.substring(idx + 1);
}
idx = file.indexOf(':');
if (idx != -1) {
name = file.substring(0, idx);
version = Numbers.toLong(file.substring(idx + 1), -1);
}
Feature fe = Feature.create().minimumVersion(version).autoReload(true).setTrimValue(trimValue).build();
return Maps.immutableEntry(new File(group, name), fe);
}
private Map.Entry<PathFragment, Path> getRemotePathFromLabel(Label label)
throws EvalException, InterruptedException {
Path localPath = getPathFromLabel(label).getPath();
PathFragment remotePath =
label.getPackageIdentifier().getSourceRoot().getRelative(label.getName());
return Maps.immutableEntry(remotePath, localPath);
}
@Override
@Nullable
public Entry<Key,Document> apply(@Nullable Entry<Key,Document> input) {
Key origKey = input.getKey();
Document d = input.getValue();
d.invalidateMetadata();
Key k = new Key(origKey.getRow(), origKey.getColumnFamily(), origKey.getColumnQualifier(), d.getColumnVisibility(), d.getTimestamp());
return Maps.immutableEntry(k, d);
}
public ReflectionThriftUnionCodec(ThriftCodecManager manager, ThriftStructMetadata metadata)
{
super(manager, metadata);
ThriftFieldMetadata idField = getOnlyElement(metadata.getFields(FieldKind.THRIFT_UNION_ID));
this.idField = Maps.immutableEntry(idField, manager.getCodec(idField.getThriftType()));
requireNonNull(this.idField.getValue(), () -> "No codec for ID field found: " + idField);
this.metadataMap = uniqueIndex(metadata.getFields(), ThriftFieldMetadata::getId);
}
private String templateProcess(CandidateDTO dto, Optional<Map.Entry<String, String>> originTemplate) {
if (isTemplateFile(dto)) {
if (originTemplate.isPresent()) {
Map.Entry<String, String> templateEntry = Maps
.immutableEntry(dto.getTemplateGroup(), dto.getTemplate());
checkTemplateChanged(originTemplate.get(), templateEntry);
}
Optional<String> newData = fileTemplateService.processTemplateValue(dto);
if (newData.isPresent()) {
return newData.get();
}
}
return dto.getData();
}
@Override
public WebClient apply(SessionProtocol protocol, Endpoint endpoint) {
final Map.Entry<SessionProtocol, Endpoint> key = Maps.immutableEntry(protocol, endpoint);
final WebClient webClient =
cache.get(key, unused -> nonBaseClientFactory.apply(protocol, endpoint));
checkState(webClient != null, "nonBaseClientFactory returned null.");
return webClient;
}
private Map.Entry<Long, byte[]> getTimeRegion(byte[] key) {
int offset = REGION_TIME_KEY_PREFIX.length;
long time = getInvertedTime(Bytes.toLong(key, offset));
offset += Bytes.SIZEOF_LONG;
byte[] regionName = Bytes.copy(key, offset, key.length - offset);
return Maps.immutableEntry(time, regionName);
}
@Override
public Map.Entry<QFile, ChecksumData<String>> findConfig(QFileFactory qFileFactory, VersionData<ConfigMeta> configId) throws ConfigNotFoundException {
Optional<QFile> qFile = qFileFactory.create(configId.getData(), cacheConfigInfoService);
if (!qFile.isPresent()) {
logger.warn("findConfig未能从内存缓存中找到配置文件的元信息, meta[{}]", configId.getData());
throw new ConfigNotFoundException();
}
return Maps.immutableEntry(qFile.get(), qFile.get().findConfig(configId.getVersion()));
}
private void setDifficultyFailsafe(String... failSafes) {
this.difficultyFailsafe.clear();
// We only support Trial and Gauntlets and Expedition, so we do sanity checks here only settings the right letters t, g, e
String pattern = "([tge]):([\\d]+)(:([\\d]+))?";
Pattern r = Pattern.compile(pattern);
for (String f : failSafes) {
f = f.trim();
Matcher m = r.matcher(f);
if (m.find()) {
int minimumDifficulty;
if (m.group(4) != null) {
minimumDifficulty = Integer.parseInt(m.group(4));
} else {
if ("e".equals(m.group(1))) {
minimumDifficulty = 5;
} else {
minimumDifficulty = 1;
}
}
Map.Entry<Integer, Integer> entry = Maps.immutableEntry(Integer.parseInt(m.group(2)), minimumDifficulty);
difficultyFailsafe.put(m.group(1), entry);
}
}
}
private Map.Entry<Long, byte[]> getTimeRegion(byte[] key) {
int offset = REGION_TIME_KEY_PREFIX.length;
long time = getInvertedTime(Bytes.toLong(key, offset));
offset += Bytes.SIZEOF_LONG;
byte[] regionName = Bytes.copy(key, offset, key.length - offset);
return Maps.immutableEntry(time, regionName);
}
public static Map.Entry<Integer, byte[]> parseOptionTemplateShallow(ByteBuf bb) {
final int start = bb.readerIndex();
int length = bb.readUnsignedShort();
final int templateId = bb.readUnsignedShort();
int optionScopeLength = bb.readUnsignedShort();
int optionLength = bb.readUnsignedShort();
int p = bb.readerIndex();
int endOfScope = p + optionScopeLength;
int endOfOption = endOfScope + optionLength;
int endOfTemplate = p - 10 + length;
while (bb.readerIndex() < endOfScope) {
int scopeType = bb.readUnsignedShort();
int scopeLength = bb.readUnsignedShort();
}
// skip padding
bb.readerIndex(endOfScope);
while (bb.readerIndex() < endOfOption) {
int optType = bb.readUnsignedShort();
int optLength = bb.readUnsignedShort();
}
// skip padding
bb.readerIndex(endOfTemplate);
final byte[] bytes = ByteBufUtil.getBytes(bb, start, bb.readerIndex() - start);
return Maps.immutableEntry(templateId, bytes);
}
@Override
public Entry<Key,T> apply(Entry<Key,T> entry) {
final Key entryKey = entry.getKey();
return Maps.immutableEntry(new Key(entryKey.getRow(), entryKey.getColumnFamily(), colQualRef, entryKey.getColumnVisibility(), entryKey.getTimestamp()),
entry.getValue());
}
private static Map.Entry<AsyncLogger, PrepareRecoveryResponseProto> makeEntry(
PrepareRecoveryResponseProto proto) {
return Maps.immutableEntry(Mockito.mock(AsyncLogger.class), proto);
}
@Override
public Entry<Key,Document> apply(Entry<Key,Document> from) {
Document returnDoc = trim(from.getValue());
return Maps.immutableEntry(from.getKey(), returnDoc);
}
@Test
public void testWriteMapWithColFamWithColon() throws IOException,
ParseException {
AccumuloStorage storage = new AccumuloStorage("col:");
Map<String, Object> map = Maps.newHashMap();
map.put("mapcol1", "mapval1");
map.put("mapcol2", "mapval2");
map.put("mapcol3", "mapval3");
map.put("mapcol4", "mapval4");
Tuple t = TupleFactory.getInstance().newTuple(2);
t.set(0, "row");
t.set(1, map);
Collection<Mutation> mutations = storage.getMutations(t);
Assert.assertEquals(1, mutations.size());
Mutation m = mutations.iterator().next();
Assert.assertTrue("Rows not equal",
Arrays.equals(m.getRow(), ((String) t.get(0)).getBytes()));
List<ColumnUpdate> colUpdates = m.getUpdates();
Assert.assertEquals(4, colUpdates.size());
Map<Entry<String, String>, String> expectations = Maps.newHashMap();
expectations.put(Maps.immutableEntry("col", "mapcol1"), "mapval1");
expectations.put(Maps.immutableEntry("col", "mapcol2"), "mapval2");
expectations.put(Maps.immutableEntry("col", "mapcol3"), "mapval3");
expectations.put(Maps.immutableEntry("col", "mapcol4"), "mapval4");
for (ColumnUpdate update : colUpdates) {
Entry<String, String> key = Maps.immutableEntry(
new String(update.getColumnFamily()),
new String(update.getColumnQualifier()));
String value = new String(update.getValue());
Assert.assertTrue("Did not find expected key: " + key,
expectations.containsKey(key));
String actual = expectations.remove(key);
Assert.assertEquals(value, actual);
}
Assert.assertTrue("Did not find all expectations",
expectations.isEmpty());
}
@Override
public Map.Entry<VersionData<ConfigMeta>, JsonNode> getJsonDiffToLastPublish(ConfigMeta meta, String data) {
VersionData<String> oldVersionData = getCurrentPublishedData(meta);
ObjectNode node = getJsonNode(oldVersionData.getData());
return Maps.immutableEntry(new VersionData<>(oldVersionData.getVersion(), meta), node);
}
private Entry<String, Long> bytesReplicated(String target, Metrics metrics) {
return Maps.immutableEntry(DotJoiner.join(target, "bytes_replicated"), metrics.getBytesReplicated());
}