-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed dedicated Entry<K,V> interface, since Map.Entry<K,V> is already sufficient. Added missing JavaDoc.
- Loading branch information
1 parent
a58251c
commit e605185
Showing
9 changed files
with
455 additions
and
44 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
src/main/java/org/springframework/data/keyvalue/core/AdapterBackedKeyValueStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* 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. | ||
*/ | ||
package org.springframework.data.keyvalue.core; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.springframework.util.Assert; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
/** | ||
* A {@link KeyValueStore} scoped to a keyspace that stores the values in via a provided {@link KeyValueAdapter}. | ||
* | ||
* @author Christoph Strobl | ||
* @param <K> | ||
* @param <V> | ||
*/ | ||
public class AdapterBackedKeyValueStore<K extends Serializable, V> implements KeyValueStore<K, V> { | ||
|
||
private final Serializable keyspace; | ||
private final KeyValueAdapter adapter; | ||
|
||
/** | ||
* @param adapter | ||
* @param keyspace | ||
*/ | ||
public AdapterBackedKeyValueStore(KeyValueAdapter adapter, Serializable keyspace) { | ||
|
||
Assert.notNull(adapter, "Adapter must not be null!"); | ||
Assert.notNull(keyspace, "Keyspace must not be null!"); | ||
this.adapter = adapter; | ||
this.keyspace = keyspace; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#put(java.io.Serializable, java.lang.Object) | ||
*/ | ||
@Override | ||
@SuppressWarnings("unchecked") | ||
public V put(K id, V item) { | ||
return (V) adapter.put(id, item, keyspace); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#contains(java.io.Serializable) | ||
*/ | ||
@Override | ||
public boolean contains(K id) { | ||
return adapter.contains(id, keyspace); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#get(java.io.Serializable) | ||
*/ | ||
@Override | ||
@SuppressWarnings("unchecked") | ||
public V get(K id) { | ||
return (V) adapter.get(id, keyspace); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#getAll(java.util.Collection) | ||
*/ | ||
@Override | ||
public Iterable<V> getAll(Collection<K> keys) { | ||
|
||
if (CollectionUtils.isEmpty(keys)) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
List<V> result = new ArrayList<V>(keys.size()); | ||
for (K key : keys) { | ||
result.add(get(key)); | ||
} | ||
return result; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#delete(java.io.Serializable) | ||
*/ | ||
@Override | ||
@SuppressWarnings("unchecked") | ||
public V remove(K id) { | ||
return (V) adapter.delete(id, keyspace); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#removeAll(java.util.Collection) | ||
*/ | ||
@Override | ||
public Iterable<V> removeAll(Collection<K> keys) { | ||
|
||
if (CollectionUtils.isEmpty(keys)) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
List<V> result = new ArrayList<V>(keys.size()); | ||
for (K key : keys) { | ||
result.add(remove(key)); | ||
} | ||
return result; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#size() | ||
*/ | ||
@Override | ||
public long size() { | ||
return adapter.count(keyspace); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.keyvalue.core.KeyValueStore#clear() | ||
*/ | ||
@Override | ||
public void clear() { | ||
adapter.deleteAllOf(keyspace); | ||
} | ||
|
||
} |
27 changes: 0 additions & 27 deletions
27
src/main/java/org/springframework/data/keyvalue/core/Entry.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/org/springframework/data/keyvalue/core/KeyValueStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* 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. | ||
*/ | ||
package org.springframework.data.keyvalue.core; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collection; | ||
|
||
/** | ||
* A key-value store that supports put, get, delete, and queries. | ||
* | ||
* @author Christoph Strobl | ||
* @author Thomas Darimont | ||
* @param <K> | ||
* @param <V> | ||
*/ | ||
public interface KeyValueStore<K extends Serializable, V> { | ||
|
||
/** | ||
* Add object with given key. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @return the item previously associated with the key. | ||
*/ | ||
V put(K key, V item); | ||
|
||
/** | ||
* Check if given key is present in KeyValue store. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @return | ||
*/ | ||
boolean contains(K key); | ||
|
||
/** | ||
* Get the Object associated with the given key. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @return {@literal null} if key not available. | ||
*/ | ||
V get(K key); | ||
|
||
/** | ||
* Get all Objects associated with the given keys. | ||
* | ||
* @param keys must not be {@literal null}. | ||
* @return an empty {@link Iterable} if no matching key found. | ||
*/ | ||
Iterable<V> getAll(Collection<K> keys); | ||
|
||
/** | ||
* Delete and return the element associated with the given key. | ||
* | ||
* @param key must not be {@literal null}. | ||
* @return | ||
*/ | ||
V remove(K key); | ||
|
||
/** | ||
* Delete and return all elements associated with the given keys. | ||
* | ||
* @param keys must not be {@literal null}. | ||
* @return | ||
*/ | ||
Iterable<V> removeAll(Collection<K> keys); | ||
|
||
/** | ||
* Get the number of total elements contained. | ||
* | ||
* @return | ||
*/ | ||
long size(); | ||
|
||
/** | ||
* Removes all elements. The {@link KeyValueStore} will be empty after this call returns. | ||
*/ | ||
void clear(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.