DATAKV-99 - Polishing.
Removed dedicated Entry<K,V> interface, since Map.Entry<K,V> is already sufficient. Favoured CloseableIterator over KeyValueIterator since it offers no additional functionality but less generic parameter clutter. Added missing JavaDoc.
This commit is contained in:
committed by
Thomas Darimont
parent
952a901164
commit
02759f58ea
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* 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.util.Map;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public interface Entry<K, V> extends Map.Entry<K, V> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
|
||||
/**
|
||||
* Forwards {@link CloseableIterator} invocations to the configured {@link Iterator} delegate.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public class ForwardingCloseableIterator<K, V> implements CloseableIterator<Map.Entry<K, V>> {
|
||||
|
||||
private final Iterator<? extends Map.Entry<K, V>> delegate;
|
||||
private final Runnable closeHandler;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ForwardingCloseableIterator}.
|
||||
*
|
||||
* @param delegate must not be {@literal null}
|
||||
*/
|
||||
public ForwardingCloseableIterator(Iterator<? extends Map.Entry<K, V>> delegate) {
|
||||
this(delegate, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ForwardingCloseableIterator} that invokes the configured {@code closeHanlder} on {@link #close()}.
|
||||
*
|
||||
* @param delegate must not be {@literal null}
|
||||
* @param closeHandler may be {@literal null}
|
||||
*/
|
||||
public ForwardingCloseableIterator(Iterator<? extends Map.Entry<K, V>> delegate, Runnable closeHandler) {
|
||||
this.delegate = delegate;
|
||||
this.closeHandler = closeHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return delegate.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map.Entry<K, V> next() {
|
||||
return delegate.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (closeHandler != null) {
|
||||
closeHandler.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public class ForwardingKeyValueIterator<K, V> implements KeyValueIterator<K, V> {
|
||||
|
||||
private final Iterator<? extends Map.Entry<K, V>> delegate;
|
||||
|
||||
public ForwardingKeyValueIterator(Iterator<? extends java.util.Map.Entry<K, V>> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return delegate.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<K, V> next() {
|
||||
return new ForwardingEntry(delegate.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
class ForwardingEntry implements Entry<K, V> {
|
||||
|
||||
private final Map.Entry<K, V> entry;
|
||||
|
||||
public ForwardingEntry(Map.Entry<K, V> entry) {
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return entry.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
return entry.setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return entry != null ? entry.toString() : "null";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,11 @@ package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
|
||||
/**
|
||||
* {@link KeyValueAdapter} unifies access and shields the underlying key/value specific implementation.
|
||||
@@ -79,7 +81,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
KeyValueIterator<? extends Serializable, ?> entries(Serializable keyspace);
|
||||
CloseableIterator<Map.Entry<Serializable, Object>> entries(Serializable keyspace);
|
||||
|
||||
/**
|
||||
* Remove all objects of given type.
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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.Closeable;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public interface KeyValueIterator<K, V> extends Iterator<Entry<K, V>>, Closeable {
|
||||
|
||||
}
|
||||
@@ -17,14 +17,16 @@ package org.springframework.data.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.data.keyvalue.core.AbstractKeyValueAdapter;
|
||||
import org.springframework.data.keyvalue.core.ForwardingKeyValueIterator;
|
||||
import org.springframework.data.keyvalue.core.ForwardingCloseableIterator;
|
||||
import org.springframework.data.keyvalue.core.KeyValueAdapter;
|
||||
import org.springframework.data.keyvalue.core.KeyValueIterator;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -104,7 +106,6 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
return get(id, keyspace) != null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(java.io.Serializable)
|
||||
*/
|
||||
@@ -149,8 +150,8 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#entries(java.io.Serializable)
|
||||
*/
|
||||
@Override
|
||||
public KeyValueIterator<Serializable, ?> entries(Serializable keyspace) {
|
||||
return new ForwardingKeyValueIterator<Serializable, Object>(getKeySpaceMap(keyspace).entrySet().iterator());
|
||||
public CloseableIterator<Map.Entry<Serializable, Object>> entries(Serializable keyspace) {
|
||||
return new ForwardingCloseableIterator<Serializable, Object>(getKeySpaceMap(keyspace).entrySet().iterator());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user