{
30 |
31 | /**
32 | * Constructs a new entry with the given key and given value.
33 | *
34 | * @param key the key for the entry, may be null
35 | * @param value the value for the entry, may be null
36 | */
37 | protected AbstractMapEntry(final K key, final V value) {
38 | super(key, value);
39 | }
40 |
41 | // Map.Entry interface
42 | //-------------------------------------------------------------------------
43 | /**
44 | * Sets the value stored in this Map.Entry
.
45 | *
46 | * This Map.Entry
is not connected to a Map, so only the
47 | * local data is changed.
48 | *
49 | * @param value the new value
50 | * @return the previous value
51 | */
52 | @Override
53 | public V setValue(final V value) {
54 | return super.setValue(value);
55 | }
56 |
57 | /**
58 | * Compares this Map.Entry
with another Map.Entry
.
59 | *
60 | * Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)}
61 | *
62 | * @param obj the object to compare to
63 | * @return true if equal key and value
64 | */
65 | @Override
66 | public boolean equals(final Object obj) {
67 | if (obj == this) {
68 | return true;
69 | }
70 | if (obj instanceof Map.Entry == false) {
71 | return false;
72 | }
73 | final Map.Entry, ?> other = (Map.Entry, ?>) obj;
74 | return
75 | (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
76 | (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
77 | }
78 |
79 | /**
80 | * Gets a hashCode compatible with the equals method.
81 | *
82 | * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}
83 | *
84 | * @return a suitable hash code
85 | */
86 | @Override
87 | public int hashCode() {
88 | return (getKey() == null ? 0 : getKey().hashCode()) ^
89 | (getValue() == null ? 0 : getValue().hashCode());
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/core/src/main/java/io/rx_cache/internal/cache/memory/apache/DefaultMapEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.rx_cache.internal.cache.memory.apache;
19 |
20 | import java.util.Map;
21 |
22 |
23 | /**
24 | * A restricted implementation of {@link java.util.Map.Entry Map.Entry} that prevents
25 | * the {@link java.util.Map.Entry Map.Entry} contract from being broken.
26 | *
27 | * @since 3.0
28 | * @version $Id: DefaultMapEntry.java 1533984 2013-10-20 21:12:51Z tn $
29 | */
30 | public final class DefaultMapEntry extends AbstractMapEntry {
31 |
32 | /**
33 | * Constructs a new entry with the specified key and given value.
34 | *
35 | * @param key the key for the entry, may be null
36 | * @param value the value for the entry, may be null
37 | */
38 | public DefaultMapEntry(final K key, final V value) {
39 | super(key, value);
40 | }
41 |
42 | /**
43 | * Constructs a new entry from the specified KeyValue
.
44 | *
45 | * @param pair the pair to copy, must not be null
46 | * @throws NullPointerException if the entry is null
47 | */
48 | public DefaultMapEntry(final KeyValue extends K, ? extends V> pair) {
49 | super(pair.getKey(), pair.getValue());
50 | }
51 |
52 | /**
53 | * Constructs a new entry from the specified Map.Entry
.
54 | *
55 | * @param entry the entry to copy, must not be null
56 | * @throws NullPointerException if the entry is null
57 | */
58 | public DefaultMapEntry(final Map.Entry extends K, ? extends V> entry) {
59 | super(entry.getKey(), entry.getValue());
60 | }
61 |
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/core/src/main/java/io/rx_cache/internal/cache/memory/apache/EmptyIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.rx_cache.internal.cache.memory.apache;
19 |
20 | import java.util.Iterator;
21 |
22 | /**
23 | * Provides an implementation of an empty iterator.
24 | *
25 | * This class provides an implementation of an empty iterator.
26 | * This class provides for binary compatibility between Commons Collections
27 | * 2.1.1 and 3.1 due to issues with IteratorUtils
.
28 | *
29 | * @since 2.1.1 and 3.1
30 | * @version $Id: EmptyIterator.java 1543955 2013-11-20 21:23:53Z tn $
31 | */
32 | public class EmptyIterator extends AbstractEmptyIterator implements ResettableIterator {
33 |
34 | /**
35 | * Singleton instance of the iterator.
36 | * @since 3.1
37 | */
38 | @SuppressWarnings("rawtypes")
39 | public static final ResettableIterator RESETTABLE_INSTANCE = new EmptyIterator