changed byteSet from Collection to List so as to iterate by index

This commit is contained in:
Dave
2015-07-05 18:57:25 +02:00
parent 81f9361eda
commit 06fd5e9845
3 changed files with 15 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ package nodash.core;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import nodash.exceptions.NoAdapterException; import nodash.exceptions.NoAdapterException;
import nodash.exceptions.NoSessionExpiredException; import nodash.exceptions.NoSessionExpiredException;
@@ -148,7 +149,7 @@ public interface NoAdapter {
* should return an empty collection, not a null object. * should return an empty collection, not a null object.
* @throws NoAdapterException * @throws NoAdapterException
*/ */
public Collection<NoByteSet> pollNoByteSets(PublicKey address) throws NoAdapterException; public List<NoByteSet> pollNoByteSets(PublicKey address) throws NoAdapterException;
/** /**
* Adds a single NoByteSet to the addressed PublicKey address. * Adds a single NoByteSet to the addressed PublicKey address.
@@ -167,6 +168,6 @@ public interface NoAdapter {
* @throws NoAdapterException - if the adapter is unable to add the list of NoByteSet objects to * @throws NoAdapterException - if the adapter is unable to add the list of NoByteSet objects to
* the pool. * the pool.
*/ */
public void addNoByteSets(Collection<NoByteSet> byteSets, PublicKey address) public void addNoByteSets(List<NoByteSet> byteSets, PublicKey address)
throws NoAdapterException; throws NoAdapterException;
} }

View File

@@ -43,8 +43,8 @@ import nodash.models.NoByteSet;
import nodash.models.NoSession; import nodash.models.NoSession;
public class NoDefaultAdapter implements NoAdapter { public class NoDefaultAdapter implements NoAdapter {
private static Map<PublicKey, Collection<NoByteSet>> byteSets = private static Map<PublicKey, List<NoByteSet>> byteSets =
new ConcurrentHashMap<PublicKey, Collection<NoByteSet>>(); new ConcurrentHashMap<PublicKey, List<NoByteSet>>();
private static Map<String, NoSession> sessions = new ConcurrentHashMap<String, NoSession>(); private static Map<String, NoSession> sessions = new ConcurrentHashMap<String, NoSession>();
private static Set<String> online = Collections private static Set<String> online = Collections
.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); .newSetFromMap(new ConcurrentHashMap<String, Boolean>());
@@ -200,13 +200,13 @@ public class NoDefaultAdapter implements NoAdapter {
} }
@Override @Override
public Collection<NoByteSet> pollNoByteSets(PublicKey address) { public List<NoByteSet> pollNoByteSets(PublicKey address) {
if (byteSets.containsKey(address)) { if (byteSets.containsKey(address)) {
Collection<NoByteSet> storedByteSets = byteSets.get(address); List<NoByteSet> storedByteSets = byteSets.get(address);
Collection<NoByteSet> result = new ArrayList<NoByteSet>(); List<NoByteSet> result = new ArrayList<NoByteSet>();
for (NoByteSet byteSet : storedByteSets) { for (int x = 0; x < storedByteSets.size(); x++) {
result.add(byteSet); result.add(storedByteSets.get(0));
storedByteSets.remove(byteSet); storedByteSets.remove(0);
} }
return result; return result;
} else { } else {
@@ -223,7 +223,7 @@ public class NoDefaultAdapter implements NoAdapter {
} }
@Override @Override
public void addNoByteSets(Collection<NoByteSet> addedByteSets, PublicKey address) { public void addNoByteSets(List<NoByteSet> addedByteSets, PublicKey address) {
if (addedByteSets == null) { if (addedByteSets == null) {
return; return;
} }

View File

@@ -34,7 +34,7 @@ public final class NoSession implements Serializable {
private NoState state; private NoState state;
private final long expiry; private final long expiry;
private Collection<NoByteSet> incoming; private List<NoByteSet> incoming;
private NoUser current; private NoUser current;
private String uuid; private String uuid;
@@ -173,7 +173,7 @@ public final class NoSession implements Serializable {
return this.incoming; return this.incoming;
} }
public Collection<NoByteSet> getIncomingSafe() { public List<NoByteSet> getIncomingSafe() {
return this.incoming; return this.incoming;
} }
@@ -193,7 +193,7 @@ public final class NoSession implements Serializable {
} }
} }
public void setIncoming(Collection<NoByteSet> incoming) { public void setIncoming(List<NoByteSet> incoming) {
this.incoming = incoming; this.incoming = incoming;
} }