Skip to content

Commit

Permalink
Revert ConsistentTreeMap to String keys only to ensure ordering is pr…
Browse files Browse the repository at this point in the history
…operly maintained.
  • Loading branch information
kuujo committed Dec 5, 2017
1 parent 540c4c1 commit 25e6bda
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 264 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/io/atomix/PrimitiveTypes.java
Expand Up @@ -107,11 +107,10 @@ public static <K, V> ConsistentMapType<K, V> map() {
/**
* Returns a new consistent tree map type.
*
* @param <K> the key type
* @param <V> the value type
* @return a new consistent tree map type
*/
public static <K, V> ConsistentTreeMapType<K, V> treeMap() {
public static <V> ConsistentTreeMapType<V> treeMap() {
return ConsistentTreeMapType.instance();
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/atomix/PrimitivesService.java
Expand Up @@ -68,7 +68,7 @@ default <V> DocumentTreeBuilder<V> documentTreeBuilder(String name) {
* @param <V> value type
* @return builder for a async consistent tree map
*/
default <K, V> ConsistentTreeMapBuilder<K, V> consistentTreeMapBuilder(String name) {
default <V> ConsistentTreeMapBuilder<V> consistentTreeMapBuilder(String name) {
return primitiveBuilder(name, PrimitiveTypes.treeMap());
}

Expand Down
47 changes: 24 additions & 23 deletions core/src/main/java/io/atomix/map/AsyncConsistentTreeMap.java
Expand Up @@ -16,9 +16,9 @@

package io.atomix.map;

import io.atomix.primitive.PrimitiveType;
import io.atomix.PrimitiveTypes;
import io.atomix.map.impl.BlockingConsistentTreeMap;
import io.atomix.primitive.PrimitiveType;
import io.atomix.utils.time.Versioned;

import java.util.Map;
Expand All @@ -29,7 +29,7 @@
/**
* API for a distributed tree map implementation.
*/
public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> {
public interface AsyncConsistentTreeMap<V> extends AsyncConsistentMap<String, V> {

@Override
default PrimitiveType primitiveType() {
Expand All @@ -41,14 +41,14 @@ default PrimitiveType primitiveType() {
*
* @return the key or null if none exist
*/
CompletableFuture<K> firstKey();
CompletableFuture<String> firstKey();

/**
* Return the highest key in the map.
*
* @return the key or null if none exist
*/
CompletableFuture<K> lastKey();
CompletableFuture<String> lastKey();

/**
* Returns the entry associated with the least key greater than or equal to
Expand All @@ -57,7 +57,7 @@ default PrimitiveType primitiveType() {
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> ceilingEntry(K key);
CompletableFuture<Map.Entry<String, Versioned<V>>> ceilingEntry(String key);

/**
* Returns the entry associated with the greatest key less than or equal
Expand All @@ -66,90 +66,90 @@ default PrimitiveType primitiveType() {
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> floorEntry(K key);
CompletableFuture<Map.Entry<String, Versioned<V>>> floorEntry(String key);

/**
* Returns the entry associated with the least key greater than key.
*
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> higherEntry(K key);
CompletableFuture<Map.Entry<String, Versioned<V>>> higherEntry(String key);

/**
* Returns the entry associated with the largest key less than key.
*
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> lowerEntry(K key);
CompletableFuture<Map.Entry<String, Versioned<V>>> lowerEntry(String key);

/**
* Return the entry associated with the lowest key in the map.
*
* @return the entry or null if none exist
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> firstEntry();
CompletableFuture<Map.Entry<String, Versioned<V>>> firstEntry();

/**
* Return the entry associated with the highest key in the map.
*
* @return the entry or null if none exist
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> lastEntry();
CompletableFuture<Map.Entry<String, Versioned<V>>> lastEntry();

/**
* Return and remove the entry associated with the lowest key.
*
* @return the entry or null if none exist
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> pollFirstEntry();
CompletableFuture<Map.Entry<String, Versioned<V>>> pollFirstEntry();

/**
* Return and remove the entry associated with the highest key.
*
* @return the entry or null if none exist
*/
CompletableFuture<Map.Entry<K, Versioned<V>>> pollLastEntry();
CompletableFuture<Map.Entry<String, Versioned<V>>> pollLastEntry();

/**
* Return the entry associated with the greatest key less than key.
*
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<K> lowerKey(K key);
CompletableFuture<String> lowerKey(String key);

/**
* Return the highest key less than or equal to key.
*
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<K> floorKey(K key);
CompletableFuture<String> floorKey(String key);

/**
* Return the lowest key greater than or equal to key.
*
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<K> ceilingKey(K key);
CompletableFuture<String> ceilingKey(String key);

/**
* Return the lowest key greater than key.
*
* @param key the key
* @return the entry or null if no suitable key exists
*/
CompletableFuture<K> higherKey(K key);
CompletableFuture<String> higherKey(String key);

/**
* Returns a navigable set of the keys in this map.
*
* @return a navigable key set (this may be empty)
*/
CompletableFuture<NavigableSet<K>> navigableKeySet();
CompletableFuture<NavigableSet<String>> navigableKeySet();

/**
* Returns a navigable map containing the entries from the original map
Expand All @@ -165,16 +165,17 @@ default PrimitiveType primitiveType() {
* @return a navigable map containing entries in the specified range (this
* may be empty)
*/
CompletableFuture<NavigableMap<K, V>> subMap(K upperKey,
K lowerKey,
boolean inclusiveUpper,
boolean inclusiveLower);
CompletableFuture<NavigableMap<String, V>> subMap(
String upperKey,
String lowerKey,
boolean inclusiveUpper,
boolean inclusiveLower);

default ConsistentTreeMap<K, V> asTreeMap() {
default ConsistentTreeMap<V> asTreeMap() {
return asTreeMap(DEFAULT_OPERATION_TIMEOUT_MILLIS);
}

default ConsistentTreeMap<K, V> asTreeMap(long timeoutMillis) {
default ConsistentTreeMap<V> asTreeMap(long timeoutMillis) {
return new BlockingConsistentTreeMap<>(this, timeoutMillis);
}

Expand Down
43 changes: 22 additions & 21 deletions core/src/main/java/io/atomix/map/ConsistentTreeMap.java
Expand Up @@ -16,8 +16,8 @@

package io.atomix.map;

import io.atomix.primitive.PrimitiveType;
import io.atomix.PrimitiveTypes;
import io.atomix.primitive.PrimitiveType;
import io.atomix.utils.time.Versioned;

import java.util.Map;
Expand All @@ -27,7 +27,7 @@
/**
* Tree map interface counterpart to {@link AsyncConsistentTreeMap}.
*/
public interface ConsistentTreeMap<K, V> extends ConsistentMap<K, V> {
public interface ConsistentTreeMap<V> extends ConsistentMap<String, V> {

@Override
default PrimitiveType primitiveType() {
Expand All @@ -39,113 +39,113 @@ default PrimitiveType primitiveType() {
*
* @return the key or null if none exist
*/
K firstKey();
String firstKey();

/**
* Returns the highest key in the map.
*
* @return the key or null if none exist
*/
K lastKey();
String lastKey();

/**
* Returns the entry associated with the least key greater than or equal to the key.
*
* @param key the key
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> ceilingEntry(K key);
Map.Entry<String, Versioned<V>> ceilingEntry(String key);

/**
* Returns the entry associated with the greatest key less than or equal to key.
*
* @param key the key
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> floorEntry(K key);
Map.Entry<String, Versioned<V>> floorEntry(String key);

/**
* Returns the entry associated with the lest key greater than key.
*
* @param key the key
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> higherEntry(K key);
Map.Entry<String, Versioned<V>> higherEntry(String key);

/**
* Returns the entry associated with the largest key less than key.
*
* @param key the key
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> lowerEntry(K key);
Map.Entry<String, Versioned<V>> lowerEntry(String key);

/**
* Returns the entry associated with the lowest key in the map.
*
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> firstEntry();
Map.Entry<String, Versioned<V>> firstEntry();

/**
* Returns the entry associated with the highest key in the map.
*
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> lastEntry();
Map.Entry<String, Versioned<V>> lastEntry();

/**
* Returns and removes the entry associated with the lowest key.
*
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> pollFirstEntry();
Map.Entry<String, Versioned<V>> pollFirstEntry();

/**
* Returns and removes the entry associated with the highest key.
*
* @return the entry or null
*/
Map.Entry<K, Versioned<V>> pollLastEntry();
Map.Entry<String, Versioned<V>> pollLastEntry();

/**
* Returns the entry associated with the greatest key less than key.
*
* @param key the key
* @return the entry or null
*/
K lowerKey(K key);
String lowerKey(String key);

/**
* Returns the entry associated with the highest key less than or equal to key.
*
* @param key the key
* @return the entry or null
*/
K floorKey(K key);
String floorKey(String key);

/**
* Returns the lowest key greater than or equal to key.
*
* @param key the key
* @return the key or null
*/
K ceilingKey(K key);
String ceilingKey(String key);

/**
* Returns the lowest key greater than key.
*
* @param key the key
* @return the key or null
*/
K higherKey(K key);
String higherKey(String key);

/**
* Returns a navigable set of the keys in this map.
*
* @return a navigable key set
*/
NavigableSet<K> navigableKeySet();
NavigableSet<String> navigableKeySet();

/**
* Returns a navigable map containing the entries from the original map
Expand All @@ -161,9 +161,10 @@ default PrimitiveType primitiveType() {
* @return a navigable map containing entries in the specified range (this
* may be empty)
*/
NavigableMap<K, V> subMap(K upperKey,
K lowerKey,
boolean inclusiveUpper,
boolean inclusiveLower);
NavigableMap<String, V> subMap(
String upperKey,
String lowerKey,
boolean inclusiveUpper,
boolean inclusiveLower);

}
Expand Up @@ -16,12 +16,12 @@

package io.atomix.map;

import io.atomix.PrimitiveTypes;
import io.atomix.primitive.Consistency;
import io.atomix.primitive.DistributedPrimitiveBuilder;
import io.atomix.primitive.Persistence;
import io.atomix.primitive.PrimitiveProtocol;
import io.atomix.primitive.Replication;
import io.atomix.PrimitiveTypes;
import io.atomix.protocols.backup.MultiPrimaryProtocol;
import io.atomix.protocols.raft.RaftProtocol;
import io.atomix.protocols.raft.ReadConsistency;
Expand All @@ -31,8 +31,8 @@
/**
* Builder for {@link ConsistentTreeMap}.
*/
public abstract class ConsistentTreeMapBuilder<K, V>
extends DistributedPrimitiveBuilder<ConsistentTreeMapBuilder<K, V>, ConsistentTreeMap<K, V>, AsyncConsistentTreeMap<K, V>> {
public abstract class ConsistentTreeMapBuilder<V>
extends DistributedPrimitiveBuilder<ConsistentTreeMapBuilder<V>, ConsistentTreeMap<V>, AsyncConsistentTreeMap<V>> {

public ConsistentTreeMapBuilder(String name) {
super(PrimitiveTypes.treeMap(), name);
Expand Down Expand Up @@ -100,7 +100,7 @@ private PrimitiveProtocol newMultiPrimaryProtocol(Consistency consistency, Repli
}

@Override
public ConsistentTreeMap<K, V> build() {
public ConsistentTreeMap<V> build() {
return buildAsync().asTreeMap();
}
}

0 comments on commit 25e6bda

Please sign in to comment.