当前位置: 首页>>代码示例>>Java>>正文


Java SimpleImmutableEntry类代码示例

本文整理汇总了Java中java.util.AbstractMap.SimpleImmutableEntry的典型用法代码示例。如果您正苦于以下问题:Java SimpleImmutableEntry类的具体用法?Java SimpleImmutableEntry怎么用?Java SimpleImmutableEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleImmutableEntry类属于java.util.AbstractMap包,在下文中一共展示了SimpleImmutableEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: flattenYamlTree

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
/**
 * Flatten yaml tree structure.
 *
 * @param entry {@link Entry} of yaml tree.
 * @return {@link Stream} of entries
 */
private static Stream<Entry<String, Object>> flattenYamlTree(Entry<?, ?> entry) {
    String key = entry.getKey().toString();
    Object value = entry.getValue();
    if (value instanceof Map) {
        Map<?, ?> valueAsMap = (Map<?, ?>) value;
        return valueAsMap.entrySet().stream()
                .flatMap(YamlResourceBundle::flattenYamlTree)
                .map(e -> new SimpleImmutableEntry<>(key + "." + e.getKey(), e.getValue()));
    } else if (value instanceof List) {
        List<?> valueAsList = (List<?>) value;
        value = valueAsList.stream().toArray(String[]::new);
        AtomicInteger index = new AtomicInteger();
        return Stream.concat(
                Stream.of(new SimpleImmutableEntry<>(key, value)),
                valueAsList.stream()
                        .map(v -> new SimpleImmutableEntry<>(key + "[" + index.getAndIncrement() + "]", v))
        );
    }
    return Stream.of(new SimpleImmutableEntry<>(key, value));
}
 
开发者ID:tastybento,项目名称:bskyblock,代码行数:27,代码来源:YamlResourceBundle.java

示例2: createSinkHandlers

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"}) // Can't get specific generic types for new SinkHandler
private Entry<Set<SinkHandler<?, ?>>, Set<SinkHandler<?, ?>>> createSinkHandlers(final Class<?> before, final ChainTransform<?, ?> transform,
    final Class<?> after, final Set<DataSink> targets) {
    final Set<SinkHandler<?, ?>> beforeTransform = new HashSet<>();
    final Set<SinkHandler<?, ?>> afterTransform = new HashSet<>();
    for(final DataSink sink : targets) {
        final ChainTransform<?, ?> fromBefore = getBestTransform(before, sink.accepts());
        final ChainTransform<?, ?> fromAfter = getBestTransform(after, sink.accepts());

        if(fromBefore != null && fromAfter != null) {
            if(fromBefore.cost() < fromAfter.cost()) {
                beforeTransform.add(new SinkHandler(sink, fromBefore, fromBefore.from(), fromBefore.to()));
            } else {
                afterTransform.add(new SinkHandler(sink, fromAfter, fromAfter.from(), fromAfter.to()));
            }
        } else if(fromBefore != null) {
            beforeTransform.add(new SinkHandler(sink, fromBefore, fromBefore.from(), fromBefore.to()));
        } else if(fromAfter != null) {
            afterTransform.add(new SinkHandler(sink, fromAfter, fromAfter.from(), fromAfter.to()));
        }
    }
    return new SimpleImmutableEntry<>(beforeTransform, afterTransform);
}
 
开发者ID:meraki-analytics,项目名称:datapipelines-java,代码行数:24,代码来源:DataPipeline.java

示例3: getSimilarMovies

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
/**
 * 产生类似电影推荐
 * @throws Exception
 */
public List<String> getSimilarMovies(String movieId)throws Exception{
    int numTopNRanks = numRecs < 0 ? 10 : numRecs;
    int itemIdx = rateDao.getItemId(movieId);
    List<String> recommendationList = new ArrayList<String>();
    for (int u = 0,um = trainMatrix.numColumns();u<um;u++){
        if(u!=itemIdx){
            double score = Sims.pcc(trainMatrix.getColumns(u),trainMatrix.getColumns(itemIdx));
            List<Map.Entry<Integer, Double>> itemScores = new ArrayList<>();
            itemScores.add(new SimpleImmutableEntry<Integer,Double>(itemIdx,score));
            itemScores = Lists.sortListTopK(itemScores, true, numTopNRanks);
            List<Integer> rankedItems = new ArrayList<>(itemScores.size());
            for (Map.Entry<Integer, Double> kv : itemScores) {
                Integer item = kv.getKey();
                rankedItems.add(item);
            }
            for (int i = 0; i < rankedItems.size()&&i<10; i++) {
                recommendationList.add(rateDao.getItemId(rankedItems.get(i)));
            }
        }
    }
    return recommendationList;
}
 
开发者ID:xiaojieliu7,项目名称:MicroServiceProject,代码行数:27,代码来源:Recommender.java

示例4: getTree

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:DateTimeFormatterBuilder.java

示例5: getOldKey

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
/**
 * Find the old key by traversing the forward map in case of in-place update modification If not
 * found it means the value object was modified with same value. So oldKey is same as newKey.
 * 
 * @return oldKey
 */
private Object getOldKey(Object newKey, RegionEntry entry) throws TypeMismatchException {
  for (Object mapEntry : valueToEntriesMap.entrySet()) {
    Object regionEntries = ((SimpleImmutableEntry) mapEntry).getValue();
    Object indexKey = ((SimpleImmutableEntry) mapEntry).getKey();
    // if more than one index key maps to the same RegionEntry that
    // means there has been an in-place modification
    if (TypeUtils.compare(indexKey, newKey, CompiledComparison.TOK_NE).equals(Boolean.TRUE)) {
      if (regionEntries instanceof RegionEntry && regionEntries.equals(entry)) {
        return indexKey;
      } else if (regionEntries instanceof Collection) {
        Collection coll = (Collection) regionEntries;
        if (coll.contains(entry)) {
          return indexKey;
        }
      }
    }
  }
  return newKey;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:MemoryIndexStore.java

示例6: convert

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
/**
 * Null-safely convert between two maps by applying a function to each key and value. A predicate is also specified to filter
 * the results, in case the mapping function were to generate duplicate keys, etc.
 */
public static <T1, T2, U1, U2> Map<U1, U2> convert(Map<T1, T2> toConvert,
                                                   Function<? super T1, ? extends U1> keyConverter,
                                                   Function<? super T2, ? extends U2> valueConverter,
                                                   BiPredicate<U1, U2> resultFilter) {
    if (toConvert == null) {
        return null;
    }

    Map<U1, U2> result = toConvert.entrySet().stream()
                                  .map(e -> new SimpleImmutableEntry<>(keyConverter.apply(e.getKey()),
                                                                       valueConverter.apply(e.getValue())))
                                  .filter(p -> resultFilter.test(p.getKey(), p.getValue()))
                                  .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
    return Collections.unmodifiableMap(result);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:TypeConverter.java

示例7: signVerifyInValueTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void signVerifyInValueTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 5, false), new Value(new byte[] {6})));

  MutableEntry signed;
  Entry<Key,Value> verified;

  EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
  EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));

  signed = new MutableEntry(signer.sign(entry.toEntry(), true));
  assertThat("row should not have changed", signed.row, is(entry.row));
  assertThat("colFamily should not have changed", signed.colF, is(entry.colF));
  assertThat("colQualifier should not have changed", signed.colQ, is(entry.colQ));
  assertThat("colVisibility should not have changed", signed.colVis, is(entry.colVis));
  assertThat("timestamp should not have changed", signed.timestamp, is(entry.timestamp));
  assertThat("delete should not have changed", signed.delete, is(entry.delete));
  assertThat("value should have changed", signed.value, is(not(entry.value)));

  verified = verifier.verify(signed.toEntry());
  assertThat("original and verified records are the same.", verified, Matchers.equalTo(entry.toEntry()));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:24,代码来源:EntrySignerTest.java

示例8: signVerifyInSeparateTableTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void signVerifyInSeparateTableTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 5, false), new Value(new byte[] {6})));

  MutableEntry signed;
  Entry<Key,Value> verified;

  EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
  EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));

  signed = new MutableEntry(signer.sign(entry.toEntry(), true));
  assertThat("row should not have changed", signed.row, is(entry.row));
  assertThat("colFamily should not have changed", signed.colF, is(entry.colF));
  assertThat("colQualifier should not have changed", signed.colQ, is(entry.colQ));
  assertThat("colVisibility should not have changed", signed.colVis, is(entry.colVis));
  assertThat("timestamp should not have changed", signed.timestamp, is(entry.timestamp));
  assertThat("delete should not have changed", signed.delete, is(entry.delete));
  assertThat("value should have changed", signed.value, is(not(entry.value)));

  verified = verifier.verify(entry.toEntry(), signed.toEntry());
  assertThat("original and verified records are the same.", verified, Matchers.equalTo(entry.toEntry()));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:24,代码来源:EntrySignerTest.java

示例9: hasNoTimestampTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void hasNoTimestampTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 0, false), new Value(new byte[] {6})));
  MutableEntry signed;

  EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
  EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));

  try {
    signed = new MutableEntry(signer.sign(entry.toEntry(), true));
    signed.timestamp = 1000L;
    verifier.verify(signed.toEntry());
    fail("changing the timestamp should cause the signature to fail");
  } catch (SignatureException e) { /* expected */}

  signed = new MutableEntry(signer.sign(entry.toEntry(), false));
  signed.timestamp = 1000L;
  verifier.verify(signed.toEntry());
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:21,代码来源:EntrySignerTest.java

示例10: badSignatureTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void badSignatureTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 0, false), new Value(new byte[] {6})));
  Entry<Key,Value> signed;

  // Sign to value;
  EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
  EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));

  signed = signer.sign(entry.toEntry(), true);
  entry.value = new byte[] {7};

  try {
    verifier.verify(entry.toEntry(), signed);
    fail("bad signature should thrown an exception");
  } catch (SignatureException e) { /* expected */}
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:19,代码来源:EntrySignerTest.java

示例11: internalUnprocessedTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void internalUnprocessedTest() throws Exception {
  EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
  EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));

  List<Entry<Key,Value>> entries = new ArrayList<>();
  byte[] row = new byte[] {1};
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(row, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false,
      false), new Value(new byte[] {4}));

  entries.add(signer.sign(entry, true));
  SignedInlineScannerIterator iterator = new SignedInlineScannerIterator(entries.iterator(), verifier);

  iterator.next();
  assertThat("unprocessed item is correct", iterator.unprocessed(), Matchers.equalTo(entries.get(0)));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:17,代码来源:SignedIteratorTest.java

示例12: externalUnprocessedTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void externalUnprocessedTest() throws Exception {
  EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
  EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));

  List<Entry<Key,Value>> entries = new ArrayList<>();
  List<Entry<Key,Value>> signedEntries = new ArrayList<>();

  byte[] row = new byte[] {1};
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(row, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false,
      false), new Value(new byte[] {4}));

  entries.add(entry);
  signedEntries.add(signer.sign(entry, true));

  SignedExternalScannerIterator iterator = new SignedExternalScannerIterator(entries.iterator(), signedEntries.iterator(), verifier, true);

  iterator.next();
  assertThat("unprocessed item is correct", iterator.unprocessed(), Matchers.equalTo(entries.get(0)));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:21,代码来源:SignedIteratorTest.java

示例13: hasNextTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void hasNextTest() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  entries.add(encryptor.encrypt(entry));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), encryptor, Collections.singletonList(new Range()),
      new TreeSet<Column>());

  assertThat("has next item", iterator.hasNext(), is(true));
  assertThat("has next item", iterator.hasNext(), is(true));
  iterator.next();
  assertThat("does not have a next item", iterator.hasNext(), is(false));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:18,代码来源:EncryptedScannerIteratorTest.java

示例14: nextTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void nextTest() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  entries.add(encryptor.encrypt(entry));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), encryptor, Collections.singletonList(new Range()),
      new TreeSet<Column>());
  assertThat("next item is correct", iterator.next(), Matchers.equalTo(entry));

  try {
    iterator.next();
    fail("no items should be left");
  } catch (NoSuchElementException e) { /* expected */}
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:19,代码来源:EncryptedScannerIteratorTest.java

示例15: matchRangeTest

import java.util.AbstractMap.SimpleImmutableEntry; //导入依赖的package包/类
@Test
public void matchRangeTest() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0,
      false, false), new Value(new byte[] {4}));
  Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7}, "secret".getBytes(Utils.VISIBILITY_CHARSET),
      0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), new EntryEncryptor(getConfig("config.ini"), KEYS),
      Collections.singletonList(new Range()), new TreeSet<>());
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(2));

  iterator = new EncryptedScannerIterator(entries.iterator(), new EntryEncryptor(getConfig("config.ini"), KEYS), new ArrayList<Range>(),
      new TreeSet<Column>());
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(2));

  iterator = getIteratorForRange(entries, (byte) 1);
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(1));

  iterator = getIteratorForRange(entries, (byte) 3);
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(0));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:27,代码来源:EncryptedScannerIteratorTest.java


注:本文中的java.util.AbstractMap.SimpleImmutableEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。