Java Code Examples for com.google.common.collect.Maps#immutableEntry()

The following examples show how to use com.google.common.collect.Maps#immutableEntry() . 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: AstyanaxTableDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
@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();
        }
    };
}
 
Example 2
Source File: ShardIndexQueryTable.java    From datawave with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: BinanceDexApiNodeClientImpl.java    From java-sdk with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 4
Source File: Util.java    From qconfig with MIT License 6 votes vote down vote up
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);
}
 
Example 5
Source File: NetFlowV9Parser.java    From graylog-plugin-netflow with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: StarlarkRepositoryContext.java    From bazel with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: Settings.java    From BHBot with GNU General Public License v3.0 5 votes vote down vote up
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);

        }
    }
}
 
Example 9
Source File: ConfigServiceImpl.java    From qconfig with MIT License 5 votes vote down vote up
@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()));
}
 
Example 10
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: ArmeriaRetrofitBuilder.java    From armeria with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 12
Source File: ApplyQueueServiceImpl.java    From qconfig with MIT License 5 votes vote down vote up
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();
}
 
Example 13
Source File: ReflectionThriftUnionCodec.java    From drift with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: DocumentMetadata.java    From datawave with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source File: MetricsListener.java    From circus-train with Apache License 2.0 4 votes vote down vote up
private Entry<String, Long> bytesReplicated(String target, Metrics metrics) {
  return Maps.immutableEntry(DotJoiner.join(target, "bytes_replicated"), metrics.getBytesReplicated());
}
 
Example 16
Source File: ConfigServiceImpl.java    From qconfig with MIT License 4 votes vote down vote up
@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);
}
 
Example 17
Source File: TestAccumuloStorage.java    From spork with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 18
Source File: DocumentProjection.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
public Entry<Key,Document> apply(Entry<Key,Document> from) {
    Document returnDoc = trim(from.getValue());
    
    return Maps.immutableEntry(from.getKey(), returnDoc);
}
 
Example 19
Source File: TestSegmentRecoveryComparator.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static Map.Entry<AsyncLogger, PrepareRecoveryResponseProto> makeEntry(
    PrepareRecoveryResponseProto proto) {
  return Maps.immutableEntry(Mockito.mock(AsyncLogger.class), proto);
}
 
Example 20
Source File: KeyAdjudicator.java    From datawave with Apache License 2.0 4 votes vote down vote up
@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());
}