mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-119 removed the use of " public <K, V> SharedHashMap<K, V> create(File file, Class<K> kClass, Class<V> vClass) "
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2014 Higher Frequency Trading
|
||||
* <p/>
|
||||
* http://www.higherfrequencytrading.com
|
||||
* <p/>
|
||||
* 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
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p/>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package net.openhft.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public interface CollectionView<K, V, E> {
|
||||
|
||||
AbstractVanillaSharedMap<K, V> getMap();
|
||||
|
||||
/**
|
||||
* Removes all of the elements from this view, by removing all the mappings from the map backing this
|
||||
* view.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
int size();
|
||||
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
// implementations below rely on concrete classes supplying these
|
||||
// abstract methods
|
||||
|
||||
/**
|
||||
* Returns an iterator over the elements in this collection.
|
||||
*
|
||||
* <p>The returned iterator is <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
|
||||
*
|
||||
* @return an iterator over the elements in this collection
|
||||
*/
|
||||
Iterator<E> iterator();
|
||||
|
||||
boolean contains(Object o);
|
||||
|
||||
boolean remove(Object o);
|
||||
|
||||
static final String oomeMsg = "Required array size too large";
|
||||
|
||||
Object[] toArray();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T> T[] toArray(T[] a);
|
||||
|
||||
/**
|
||||
* Returns a string representation of this collection. The string representation consists of the string
|
||||
* representations of the collection's elements in the order they are returned by its iterator, enclosed
|
||||
* in square brackets ({@code "[]"}). Adjacent elements are separated by the characters {@code ", "}
|
||||
* (comma and space). Elements are converted to strings as by {@link String#valueOf(Object)}.
|
||||
*
|
||||
* @return a string representation of this collection
|
||||
*/
|
||||
String toString();
|
||||
|
||||
boolean containsAll(Collection<?> c);
|
||||
|
||||
boolean removeAll(Collection<?> c);
|
||||
|
||||
boolean retainAll(Collection<?> c);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public interface ConcurrentMapLamdadSupport<K, V> {
|
||||
*
|
||||
* @return the set view
|
||||
*/
|
||||
AbstractVanillaSharedMap.KeySetView<K, V> keySet();
|
||||
net.openhft.collections.KeySetView<K, V> keySet();
|
||||
|
||||
|
||||
long mappingCount();
|
||||
|
||||
@@ -27,7 +27,8 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public interface KeySetView<K, V> extends Collection<K>, java.io.Serializable, Set<K> {
|
||||
public interface KeySetView<K, V> extends Collection<K>, java.io.Serializable, Set<K>, CollectionView<K, V,
|
||||
K> {
|
||||
/**
|
||||
* Returns the default mapped value for additions, or {@code null} if additions are not supported.
|
||||
*
|
||||
|
||||
@@ -84,7 +84,7 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
|
||||
* Base class for views.
|
||||
*/
|
||||
abstract static class CollectionView<K, V, E>
|
||||
implements Collection<E>, java.io.Serializable {
|
||||
implements Collection<E>, net.openhft.collections.CollectionView<K, V, E>, java.io.Serializable {
|
||||
private static final long serialVersionUID = 7249069246763182397L;
|
||||
final AbstractVanillaSharedMap<K, V> map;
|
||||
|
||||
@@ -452,6 +452,7 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
|
||||
return new KeySetView<K, V>(this, mappedValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A view of a ConcurrentHashMap as a {@link Set} of keys, in which additions may optionally be enabled by
|
||||
* mapping to a common value. This class cannot be directly instantiated. See {@link #keySet() keySet()},
|
||||
@@ -462,6 +463,7 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
|
||||
*/
|
||||
public static class KeySetView<K, V> extends CollectionView<K, V, K>
|
||||
implements Set<K>, java.io.Serializable, net.openhft.collections.KeySetView<K, V> {
|
||||
|
||||
private static final long serialVersionUID = 7249069246763182397L;
|
||||
private final V value;
|
||||
|
||||
@@ -1639,7 +1641,11 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
|
||||
return putVal(key, value, false);
|
||||
}
|
||||
|
||||
V putVal(K key, V value, boolean replaceIfPresent) {
|
||||
V putVal(K key, V value, boolean onlyIfAbsent) {
|
||||
return put0(key, value, !onlyIfAbsent);
|
||||
}
|
||||
|
||||
V put0(K key, V value, boolean replaceIfPresent) {
|
||||
super.putVal(key, value, replaceIfPresent);
|
||||
checkKey(key);
|
||||
checkValue(value);
|
||||
@@ -2731,7 +2737,6 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
|
||||
}
|
||||
|
||||
|
||||
|
||||
Entry<K, V> nextSegmentEntry() {
|
||||
while (segmentIndex >= 0) {
|
||||
if (segmentPositions.isEmpty()) {
|
||||
|
||||
@@ -25,6 +25,7 @@ package net.openhft.chronicle.map;/*
|
||||
/*import junit.framework.Test;
|
||||
import junit.framework.TestSuite;*/
|
||||
|
||||
import net.openhft.collections.KeySetView;
|
||||
import net.openhft.collections.SharedHashMapBuilder;
|
||||
import net.openhft.collections.jrs166.JSR166TestCase;
|
||||
import org.junit.Test;
|
||||
@@ -111,7 +112,7 @@ public class ChronicleMap8Test extends JSR166TestCase {
|
||||
* Returns a new map from Integers 1-5 to Strings "A"-"E".
|
||||
*/
|
||||
private static ConcurrentHashMap map5ConcurrentHashMap() {
|
||||
ConcurrentHashMap<Integer,String> map = new ConcurrentHashMap<Integer,String>(5);
|
||||
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<Integer, String>(5);
|
||||
assertTrue(map.isEmpty());
|
||||
map.put(one, "A");
|
||||
map.put(two, "B");
|
||||
@@ -305,15 +306,15 @@ public class ChronicleMap8Test extends JSR166TestCase {
|
||||
*/
|
||||
@Test
|
||||
public void testKeySetAddRemove() {
|
||||
ChronicleMap map = map5();
|
||||
Set set1 = map.keySet();
|
||||
Set set2 = map.keySet(true);
|
||||
ChronicleMap<Integer, String> map = map5();
|
||||
final KeySetView<Integer, String> set1 = map.keySet();
|
||||
final KeySetView<Integer, String> set2 = map.keySet("true");
|
||||
set2.add(six);
|
||||
assertTrue(((ConcurrentHashMap.KeySetView) set2).getMap() == map);
|
||||
assertTrue(((ConcurrentHashMap.KeySetView) set1).getMap() == map);
|
||||
assertTrue(set2.getMap() == map);
|
||||
assertTrue(set1.getMap() == map);
|
||||
assertEquals(set2.size(), map.size());
|
||||
assertEquals(set1.size(), map.size());
|
||||
assertTrue((Boolean) map.get(six));
|
||||
assertTrue((Boolean.parseBoolean(map.get(six))));
|
||||
assertTrue(set1.contains(six));
|
||||
assertTrue(set2.contains(six));
|
||||
set2.remove(six);
|
||||
@@ -398,8 +399,6 @@ public class ChronicleMap8Test extends JSR166TestCase {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* KeySetView.getMappedValue returns the map's mapped value
|
||||
*/
|
||||
@@ -413,38 +412,39 @@ public class ChronicleMap8Test extends JSR166TestCase {
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
|
||||
final net.openhft.collections.KeySetView set = map.keySet("1");
|
||||
final net.openhft.collections.KeySetView set = map.keySet("A");
|
||||
|
||||
set.add(one);
|
||||
set.add(six);
|
||||
set.add(seven);
|
||||
assertTrue(set.getMappedValue() == "1");
|
||||
assertTrue(map.get(one) != "1");
|
||||
assertTrue(map.get(six) == "1");
|
||||
assertTrue(map.get(seven) == "1");
|
||||
assertTrue(set.getMappedValue().equals("A"));
|
||||
assertTrue(map.get(one).equals("A"));
|
||||
assertTrue(map.get(six).equals("A"));
|
||||
assertTrue(map.get(seven).equals("A"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConcurrentHashMapGetMappedValue() {
|
||||
ConcurrentHashMap map = map5ConcurrentHashMap();
|
||||
assertNull(map.keySet().getMappedValue());
|
||||
try {
|
||||
map.keySet(null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
/* @Test
|
||||
public void testConcurrentHashMapGetMappedValue() {
|
||||
ConcurrentHashMap map = map5ConcurrentHashMap();
|
||||
assertNull(map.keySet().getMappedValue());
|
||||
try {
|
||||
map.keySet(null);
|
||||
shouldThrow();
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
|
||||
final ConcurrentHashMap.KeySetView set = map.keySet("1");
|
||||
final ConcurrentHashMap.KeySetView set = map.keySet("A");
|
||||
|
||||
set.add(one);
|
||||
set.add(six);
|
||||
set.add(seven);
|
||||
assertTrue(set.getMappedValue() == "1");
|
||||
assertTrue(map.get(one) != "1");
|
||||
assertTrue(map.get(six) == "1");
|
||||
assertTrue(map.get(seven) == "1");
|
||||
}
|
||||
set.add(one);
|
||||
set.add(six);
|
||||
set.add(seven);
|
||||
assertTrue(set.getMappedValue() == "A");
|
||||
assertTrue(map.get(one) == "A");
|
||||
assertTrue(map.get(six) == "A");
|
||||
assertTrue(map.get(seven) == "A");
|
||||
}
|
||||
*/
|
||||
void checkSpliteratorCharacteristics(Spliterator<?> sp,
|
||||
int requiredCharacteristics) {
|
||||
assertEquals(requiredCharacteristics,
|
||||
|
||||
Reference in New Issue
Block a user