本文整理汇总了Java中io.vavr.collection.HashMap类的典型用法代码示例。如果您正苦于以下问题:Java HashMap类的具体用法?Java HashMap怎么用?Java HashMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashMap类属于io.vavr.collection包,在下文中一共展示了HashMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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()
)
))
);
}
示例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);
}
}
示例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()
));
}
示例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;
}
示例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, "")
)
);
}
示例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);
}
示例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()
);
}
示例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
));
}
示例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);
}
示例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()))
));
}
示例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");
}
示例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");
}
示例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);
}
示例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)));
}