import net.pterodactylus.wotns.freenet.wot.Identity;
/**
- * TODO
+ * Scans an {@link Identity}’s properties for WoTNS targets.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public class IdentityTargets implements Iterable<Entry<String, String>> {
+ /** The identity being scanned. */
private final Identity identity;
+ /** The located targets. */
private final Map<String, String> targets = new HashMap<String, String>();
+ /**
+ * 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<String, String> 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);
// PRIVATE METHODS
//
+ /**
+ * Re-scans the identity for targets.
+ */
private void scanForTargets() {
synchronized (targets) {
targets.clear();
*/
@Override
public Iterator<Entry<String, String>> iterator() {
- scanForTargets();
- return targets.entrySet().iterator();
+ synchronized (targets) {
+ scanForTargets();
+ return new HashMap<String, String>(targets).entrySet().iterator();
+ }
}
}