/hazelcast-documentation/src/main/docbook/manual/content/dds/MultiMap.xml
https://bitbucket.org/gabral6_gmailcom/hazelcast · XML · 57 lines · 35 code · 7 blank · 15 comment · 0 complexity · 497d57f0f4718568307b3a2b5e542e46 MD5 · raw file
- <?xml version='1.0' encoding='UTF-8'?>
- <!--
- ~ Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
- <sect1 xml:id="MultiMap" version='5.0' xmlns='http://docbook.org/ns/docbook'
- xmlns:xi="http://www.w3.org/2001/XInclude"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd
- http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd">
- <title>Distributed MultiMap</title>
- <para>
- <literal>MultiMap</literal>
- is a specialized map where you can associate a key with multiple values.
- Just like any other distributed data structure implementation in Hazelcast,
- <literal>MultiMap</literal>
- is distributed/partitioned and thread-safe.
- <programlisting language="java"><![CDATA[import com.hazelcast.core.MultiMap;
- import com.hazelcast.core.Hazelcast;
- import java.util.Collection;
- import com.hazelcast.config.Config;
- Config cfg = new Config();
- HazelcastInstance hz = Hazelcast.newHazelcastInstance(cfg);
- // a multimap to hold <customerId, Order> pairs
- MultiMap<String, Order> mmCustomerOrders = hz.getMultiMap("customerOrders");
- mmCustomerOrders.put("1", new Order ("iPhone", 340));
- mmCustomerOrders.put("1", new Order ("MacBook", 1200));
- mmCustomerOrders.put("1", new Order ("iPod", 79));
- // get orders of the customer with customerId 1.
- Collection<Order> colOrders = mmCustomerOrders.get ("1");
- for (Order order : colOrders) {
- // process order
- }
- // remove specific key/value pair
- boolean removed = mmCustomerOrders.remove("1", new Order ("iPhone", 340));
- ]]></programlisting>
- </para>
- </sect1>