PageRenderTime 27ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast-client/src/main/java/com/hazelcast/client/MultiMapEntryIterator.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 56 lines | 34 code | 7 blank | 15 comment | 11 complexity | ad8b9a80c58174a75b54d25e305bfa14 MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.client;
18
19import com.hazelcast.core.Instance;
20import com.hazelcast.impl.base.Values;
21
22import java.util.Iterator;
23import java.util.Map;
24
25public class MultiMapEntryIterator extends MapEntryIterator {
26    private volatile Iterator currentValueIterator;
27    private volatile Object lastKey;
28    protected volatile Map.Entry lastMultiMapEntry;
29
30    public MultiMapEntryIterator(Iterator it, EntryHolder proxy, Instance.InstanceType instanceType) {
31        super(it, proxy, instanceType);
32    }
33
34    public boolean hasNext() {
35        if (currentValueIterator == null) {
36            return it.hasNext();
37        }
38        return currentValueIterator.hasNext() || it.hasNext();
39    }
40
41    public Map.Entry next() {
42        if (currentValueIterator == null || !currentValueIterator.hasNext()) {
43            lastKey = it.next();
44            Values value = (Values) proxy.get(lastKey);
45            if (value == null) {
46                return next();
47            }
48            currentValueIterator = value.iterator();
49        }
50        if (currentValueIterator == null || !currentValueIterator.hasNext()) {
51            return next();
52        }
53        lastMultiMapEntry = new MapEntry(lastKey, currentValueIterator.next(), proxy);
54        return lastMultiMapEntry;
55    }
56}