X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fwotns%2Fmain%2FIdentityTargets.java;h=a992091118916cabb031155f689d8b2cd87ffff7;hb=HEAD;hp=1266874991bda54e2dd09dc80584a2f7faa2305d;hpb=befa0c12ba6d90d47bd7d15bd9fedb1f58cc6de2;p=WoTNS.git
diff --git a/src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java b/src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java
index 1266874..a992091 100644
--- a/src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java
+++ b/src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java
@@ -26,25 +26,49 @@ import java.util.Map.Entry;
import net.pterodactylus.wotns.freenet.wot.Identity;
/**
- * TODO
+ * Scans an {@link Identity}âs properties for WoTNS targets.
*
* @author David âBombeâ Roden
*/
public class IdentityTargets implements Iterable> {
+ /** The identity being scanned. */
private final Identity identity;
+ /** The located targets. */
private final Map targets = new HashMap();
+ /**
+ * Creates a new target scanner for the given identity.
+ *
+ * @param identity
+ * The identity to scan for targets
+ */
public IdentityTargets(Identity identity) {
this.identity = identity;
}
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the targets of the identity.
+ *
+ * @return The targets defined in the identity
+ */
public Map getTargets() {
scanForTargets();
return Collections.unmodifiableMap(targets);
}
+ /**
+ * Returns the target with the given name.
+ *
+ * @param name
+ * The name of the target
+ * @return The target
+ */
public String getTarget(String name) {
scanForTargets();
return targets.get(name);
@@ -54,6 +78,9 @@ public class IdentityTargets implements Iterable> {
// PRIVATE METHODS
//
+ /**
+ * Re-scans the identity for targets.
+ */
private void scanForTargets() {
synchronized (targets) {
targets.clear();
@@ -74,7 +101,10 @@ public class IdentityTargets implements Iterable> {
*/
@Override
public Iterator> iterator() {
- return targets.entrySet().iterator();
+ synchronized (targets) {
+ scanForTargets();
+ return new HashMap(targets).entrySet().iterator();
+ }
}
}