本文整理汇总了Java中io.vavr.collection.HashMap类的典型用法代码示例。如果您正苦于以下问题:Java HashMap类的具体用法?Java HashMap怎么用?Java HashMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashMap类属于io.vavr.collection包,在下文中一共展示了HashMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: diff
import io.vavr.collection.HashMap; //导入依赖的package包/类
public static Map<Phase, Vector<Patch>> diff(Option<VNode> a, Option<VNode> b) {
if (!a.isEmpty() && b.isEmpty()) {
LOG.error("Tried to remove root node");
return HashMap.empty();
}
final Map<Phase, Vector<Patch>> patches;
if (a.isEmpty()) {
patches = b.isEmpty() ? HashMap.empty() : HashMap.of(Phase.STRUCTURE, Vector.of(new UpdateRootPatch(b.get())));
} else {
patches = doDiff(Vector.empty(), a.get(), b.get());
}
LOG.trace("Diff:\na:\n{}\nb:\n{}\nresult:\n{}", a, b, patches);
return patches;
}
开发者ID:netopyr,项目名称:reduxfx,代码行数:17,代码来源:Differ.java
示例2: diffAttributes
import io.vavr.collection.HashMap; //导入依赖的package包/类
private static Map<Phase, Vector<Patch>> diffAttributes(Vector<Object> path, VNode a, VNode b) {
final Map<String, VProperty> removedProperties = a.getProperties().removeAll(b.getProperties().keySet()).map((key, value) -> Tuple.of(key, Factory.property(value.getPhase(), key)));
final Map<String, VProperty> updatedProperties = b.getProperties().filter(propertyB -> !Option.of(propertyB._2).equals(a.getProperties().get(propertyB._1)));
final Map<VEventType, Option<VEventHandler>> removedEventHandlers = a.getEventHandlers().removeAll(b.getEventHandlers().keySet()).map((key, value) -> Tuple.of(key, Option.none()));
final Map<VEventType, Option<VEventHandler>> updatedEventHandlers = b.getEventHandlers().filter(handlerB -> !Objects.equals(Option.of(handlerB._2), a.getEventHandlers().get(handlerB._1))).map((key, value) -> Tuple.of(key, Option.of(value)));
final Map<VEventType, Option<VEventHandler>> diffEventHandlers = removedEventHandlers.merge(updatedEventHandlers);
return removedProperties.merge(updatedProperties)
.groupBy(tuple -> tuple._2.getPhase())
.map((phase, properties) ->
Tuple.of(phase, Vector.of(
new AttributesPatch(
path,
properties,
phase == Phase.DEFAULT ? diffEventHandlers : HashMap.empty()
)
))
);
}
开发者ID:netopyr,项目名称:reduxfx,代码行数:21,代码来源:Differ.java
示例3: DC
import io.vavr.collection.HashMap; //导入依赖的package包/类
public DC(final String name, final int httpPort, Map<String,Integer> remotes) {
this.name = name;
config = ConfigFactory.parseMap(HashMap.<String,Object>
of("clustering.port", clusteringPort)
.put("clustering.seed-port", clusteringPort)
.put("ts-reaktive.replication.local-datacenter.name", name)
.put("ts-reaktive.replication.local-datacenter.host", "localhost")
.put("ts-reaktive.replication.local-datacenter.port", httpPort)
.put("ts-reaktive.replication.cassandra.keyspace", "replication_" + name)
.put("cassandra-journal.port", CassandraLauncher.randomPort())
.put("clustering.name", name)
.put("cassandra-journal.keyspace", name) // each datacenter is in its own cassandra keyspace
.merge(
HashMap.ofEntries(remotes.map(r -> Tuple.of("ts-reaktive.replication.remote-datacenters." + r._1 + ".url", "ws://localhost:" + r._2)))
)
.toJavaMap()
).withFallback(ConfigFactory.parseResources("com/tradeshift/reaktive/replication/ReplicationIntegrationSpec.conf")).withFallback(ConfigFactory.defaultReference()).resolve();
system = ActorSystem.create(config.getString("clustering.name"), config);
shardRegion = ReplicatedTestActor.sharding.shardRegion(system);
new AkkaPersistence(system).awaitPersistenceInit();
try {
System.out.println("*** AWAITING");
Replication.get(system).start(TestEvent.class, shardRegion).toCompletableFuture().get(30, TimeUnit.SECONDS);
System.out.println("*** DONE");
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
}
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:33,代码来源:ReplicationIntegrationSpec.java
示例4: SharedActorSystemSpec
import io.vavr.collection.HashMap; //导入依赖的package包/类
public SharedActorSystemSpec() {
super(ConfigFactory.parseMap(HashMap
.of("ts-reaktive.replication.local-datacenter.name","local")
.put("ts-reaktive.replication.event-classifiers.\"com.tradeshift.reaktive.replication.TestData$TestEvent\"", TestEventClassifier.class.getName())
.toJavaMap()
));
}
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:8,代码来源:SharedActorSystemSpec.java
示例5: getValidSubTags
import io.vavr.collection.HashMap; //导入依赖的package包/类
private Map<QName,XSParticle> getValidSubTags(XSElementDeclaration elmt) {
if (!(elmt.getTypeDefinition() instanceof XSComplexTypeDefinition)) {
return HashMap.empty();
}
XSComplexTypeDefinition type = (XSComplexTypeDefinition) elmt.getTypeDefinition();
if (type.getParticle() == null || !(type.getParticle().getTerm() instanceof XSModelGroup)) {
return HashMap.empty();
}
XSModelGroup group = (XSModelGroup) type.getParticle().getTerm();
if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE && group.getCompositor() != XSModelGroup.COMPOSITOR_CHOICE) {
return HashMap.empty();
}
// We don't care whether it's SEQUENCE or CHOICE, we only want to know what are the valid sub-elements at this level.
XSObjectList particles = group.getParticles();
Map<QName,XSParticle> content = HashMap.empty();
for (int j = 0; j < particles.getLength(); j++) {
XSParticle sub = (XSParticle) particles.get(j);
if (sub.getTerm() instanceof XSElementDeclaration) {
XSElementDeclaration term = (XSElementDeclaration) sub.getTerm();
content = content.put(new QName(term.getNamespace(), term.getName()), sub);
}
}
return content;
}
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:28,代码来源:XMLToJSON.java
示例6: create
import io.vavr.collection.HashMap; //导入依赖的package包/类
public static AppState create() {
return new AppState(Project.create(),
HashMap.ofEntries(
Tuple.of(TextFieldID.SPRINT_TITLE, ""),
Tuple.of(TextFieldID.STORY_TITLE, "")
)
);
}
开发者ID:netopyr,项目名称:reduxfx,代码行数:9,代码来源:AppState.java
示例7: diffSingleChildMaps
import io.vavr.collection.HashMap; //导入依赖的package包/类
private static Map<Phase, Vector<Patch>> diffSingleChildMaps(Vector<Object> path, VNode oldNode, VNode newNode) {
final Map<String, Option<VNode>> oldChildren = oldNode.getSingleChildMap();
final Map<String, Option<VNode>> newChildren = newNode.getSingleChildMap();
final Map<Phase, Vector<Patch>> updatedChildren = oldChildren
.filter(oldChild -> newChildren.containsKey(oldChild._1))
.map(oldChild -> Tuple.of(oldChild._1, oldChild._2, newChildren.get(oldChild._1).get()))
.map(tuple -> {
final String key = tuple._1;
final Option<VNode> oldValue = tuple._2;
final Option<VNode> newValue = tuple._3;
if (oldValue.isEmpty() && newValue.isEmpty()) {
return HashMap.<Phase, Vector<Patch>>empty();
}
if (newValue.isEmpty()) {
return HashMap.of(Phase.STRUCTURE, Vector.<Patch>of(new SetSingleChildPatch(path, key, Option.none())));
}
if (oldValue.isEmpty() || !oldValue.get().getNodeClass().equals(newValue.get().getNodeClass())) {
return HashMap.of(Phase.STRUCTURE, Vector.<Patch>of(new SetSingleChildPatch(path, key, newValue)));
}
return doDiff(path.append(key), oldValue.get(), newValue.get());
})
.fold(HashMap.empty(), (map1, map2) -> map1.merge(map2, Vector::appendAll));
final Seq<Patch> removedChildren = oldChildren.removeAll(newChildren.keySet())
.map(tuple -> new SetSingleChildPatch(path, tuple._1, Option.none()));
final Seq<Patch> addedChildren = newChildren.removeAll(oldChildren.keySet())
.map(tuple -> new SetSingleChildPatch(path, tuple._1, tuple._2));
return updatedChildren
.merge(HashMap.of(Phase.STRUCTURE, removedChildren.toVector()), Vector::appendAll)
.merge(HashMap.of(Phase.STRUCTURE, addedChildren.toVector()), Vector::appendAll);
}
开发者ID:netopyr,项目名称:reduxfx,代码行数:34,代码来源:Differ.java
示例8: node
import io.vavr.collection.HashMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <B extends VNode> B node(Object typeKey, Supplier<B> factory) {
return (B) nodeCache.get(
Tuple.of(typeKey, HashMap.empty(), HashMap.empty(), HashMap.empty(), HashMap.empty()),
tuple -> factory.get()
);
}
开发者ID:netopyr,项目名称:reduxfx,代码行数:8,代码来源:Factory.java
示例9: testExportsRateLimiterMetrics
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testExportsRateLimiterMetrics() {
// Given
final CollectorRegistry registry = new CollectorRegistry();
final RateLimiter rateLimiter = RateLimiter.ofDefaults("foo");
RateLimiterExports.ofIterable("boo_rate_limiter", singletonList(rateLimiter)).register(registry);
final Supplier<Map<String, Double>> values = () -> HashSet
.of("available_permissions", "waiting_threads")
.map(param ->
Tuple.of(param, registry.getSampleValue(
"boo_rate_limiter",
new String[]{"name", "param"},
new String[]{"foo", param})))
.toMap(t -> t);
// When
final Map<String, Double> initialValues = values.get();
// Then
assertThat(initialValues).isEqualTo(HashMap.of(
"available_permissions", 50.0,
"waiting_threads", 0.0
));
}
开发者ID:resilience4j,项目名称:resilience4j,代码行数:30,代码来源:RateLimiterExportsTest.java
示例10: test1
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void test1() throws IOException {
Map<Object, Object> vavrObject = emptyMap().put("1", 2);
java.util.Map<Object, Object> javaObject = new java.util.HashMap<>();
javaObject.put("1", 2);
String json = mapper().writer().writeValueAsString(vavrObject);
Assert.assertEquals(genJsonMap(javaObject), json);
Map<?, ?> restored = (Map<?, ?>) mapper().readValue(json, clz());
Assert.assertEquals(restored, vavrObject);
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:13,代码来源:MapTest.java
示例11: testWithOption
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testWithOption() throws Exception {
verifySerialization(typeReferenceWithOption(), List.of(
Tuple.of(emptyMap().put("1", Option.some(1)), genJsonMap(HashMap.of("1", 1).toJavaMap())),
Tuple.of(emptyMap().put("1", Option.none()), genJsonMap(HashMap.of("1", null).toJavaMap()))
));
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:8,代码来源:MapTest.java
示例12: testJaxbXmlSerialization
import io.vavr.collection.HashMap; //导入依赖的package包/类
public void testJaxbXmlSerialization() throws IOException {
java.util.Map<String, String> javaInit = new java.util.HashMap<>();
javaInit.put("key1", "1");
javaInit.put("key2", "2");
Map<String, String> slangInit = this.<String, String>emptyMap().put("key1", "1").put("key2", "2");
ObjectMapper mapper = xmlMapperJaxb();
String javaJson = mapper.writeValueAsString(new JaxbXmlSerializeJavaUtil().init(javaInit));
String slangJson = mapper.writeValueAsString(new JaxbXmlSerializeVavr().init(slangInit));
Assert.assertEquals(javaJson, slangJson);
JaxbXmlSerializeVavr restored = mapper.readValue(slangJson, JaxbXmlSerializeVavr.class);
Assert.assertEquals(restored.transitTypes.get("key1").get(), "1");
Assert.assertEquals(restored.transitTypes.get("key2").get(), "2");
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:14,代码来源:MapTest.java
示例13: testXmlSerialization
import io.vavr.collection.HashMap; //导入依赖的package包/类
public void testXmlSerialization() throws IOException {
java.util.Map<String, String> javaInit = new java.util.HashMap<>();
javaInit.put("key1", "1");
javaInit.put("key2", "2");
Map<String, String> slangInit = this.<String, String>emptyMap().put("key1", "1").put("key2", "2");
ObjectMapper mapper = xmlMapper();
String javaJson = mapper.writeValueAsString(new XmlSerializeJavaUtil().init(javaInit));
String slangJson = mapper.writeValueAsString(new XmlSerializeVavr().init(slangInit));
Assert.assertEquals(javaJson, slangJson);
XmlSerializeVavr restored = mapper.readValue(slangJson, XmlSerializeVavr.class);
Assert.assertEquals(restored.transitTypes.get("key1").get(), "1");
Assert.assertEquals(restored.transitTypes.get("key2").get(), "2");
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:14,代码来源:MapTest.java
示例14: test1
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void test1() throws IOException {
Multimap<Object, Object> vavrObject = emptyMap().put("1", 2).put("2", 3).put("2", 4);
java.util.Map<Object, List<Object>> javaObject = new java.util.HashMap<>();
javaObject.put("1", Collections.singletonList(2));
List<Object> list = new ArrayList<>();
Collections.addAll(list, 3, 4);
javaObject.put("2", list);
String json = mapper().writer().writeValueAsString(vavrObject);
Assert.assertEquals(genJsonMap(javaObject), json);
Multimap<?, ?> restored = (Multimap<?, ?>) mapper().readValue(json, clz());
Assert.assertEquals(restored, vavrObject);
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:16,代码来源:MultimapTest.java
示例15: testWithOption
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testWithOption() throws Exception {
Multimap<String, Option<Integer>> multimap = this.<String, Option<Integer>>emptyMap().put("1", Option.some(1)).put("1", Option.none());
String json = genJsonMap(HashMap.of("1", asList(1, null)).toJavaMap());
verifySerialization(typeReferenceWithOption(), io.vavr.collection.List.of(Tuple.of(multimap, json)));
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:8,代码来源:MultimapTest.java
示例16: test3
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void test3() throws IOException {
java.util.Map<String, String> javaHMap = new java.util.HashMap<>();
javaHMap.put("1", "2");
List<?> src = List.of(javaHMap);
List<?> restored = mapper().readValue(mapper().writer().writeValueAsString(src), List.class);
Assert.assertEquals(restored, src);
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:9,代码来源:MixedTest.java
示例17: testHashMap
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testHashMap() throws Exception {
HashMap<String, A> src = HashMap.of("a", new B("a", "b"));
String json = MAPPER.writeValueAsString(new HashMapPojo().setValue(src));
Assert.assertEquals(json, "{\"value\":{\"a\":{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}}}");
HashMapPojo pojo = MAPPER.readValue(json, HashMapPojo.class);
HashMap<String, A> restored = pojo.getValue();
Assert.assertTrue(restored.get("a").get() instanceof B);
Assert.assertEquals(restored.get("a").get().a, "a");
Assert.assertEquals(((B) restored.get("a").get()).b, "b");
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:12,代码来源:ExtFieldsPojoTest.java
示例18: testHashMapOfString
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testHashMapOfString() throws Exception {
Integer src00 = 1;
String src01 = "A";
Tuple2<Integer, String> src0 = Tuple.of(src00, src01);
HashMap<Integer, String> src = HashMap.ofEntries(src0);
String json = MAPPER.writeValueAsString(new ParameterizedHashMapPojo<>(src));
Assert.assertEquals(json, "{\"value\":{\"1\":\"A\"}}");
ParameterizedHashMapPojo<java.lang.Integer, java.lang.String> restored =
MAPPER.readValue(json, new TypeReference<ParameterizedHashMapPojo<java.lang.Integer, java.lang.String>>(){});
Assert.assertEquals(src, restored.getValue());
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:13,代码来源:ParameterizedPojoTest.java
示例19: testHashMapOfTuple
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testHashMapOfTuple() throws Exception {
Integer src00 = 1;
String src010 = "A";
String src011 = "B";
Tuple2<String, String> src01 = Tuple.of(src010, src011);
Tuple2<Integer, Tuple2<String, String>> src0 = Tuple.of(src00, src01);
HashMap<Integer, Tuple2<String, String>> src = HashMap.ofEntries(src0);
String json = MAPPER.writeValueAsString(new ParameterizedHashMapPojo<>(src));
Assert.assertEquals(json, "{\"value\":{\"1\":[\"A\",\"B\"]}}");
ParameterizedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
MAPPER.readValue(json, new TypeReference<ParameterizedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
Assert.assertEquals(src, restored.getValue());
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:15,代码来源:ParameterizedPojoTest.java
示例20: testHashMapOfString
import io.vavr.collection.HashMap; //导入依赖的package包/类
@Test
public void testHashMapOfString() throws Exception {
Integer src00 = 1;
String src01 = "A";
Tuple2<Integer, String> src0 = Tuple.of(src00, src01);
HashMap<Integer, String> src = HashMap.ofEntries(src0);
String json = MAPPER.writeValueAsString(new HashMapOfString().setValue(src));
Assert.assertEquals(json, "{\"value\":{\"1\":\"A\"}}");
HashMapOfString restored = MAPPER.readValue(json, HashMapOfString.class);
Assert.assertEquals(src, restored.getValue());
}
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:12,代码来源:SimplePojoTest.java
注:本文中的io.vavr.collection.HashMap类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论