2 * WoTNS - IdentityTargets.java - Copyright © 2011 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.wotns.main;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Iterator;
24 import java.util.Map.Entry;
26 import net.pterodactylus.wotns.freenet.wot.Identity;
29 * Scans an {@link Identity}’s properties for WoTNS targets.
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 public class IdentityTargets implements Iterable<Entry<String, String>> {
35 /** The identity being scanned. */
36 private final Identity identity;
38 /** The located targets. */
39 private final Map<String, String> targets = new HashMap<String, String>();
42 * Creates a new target scanner for the given identity.
45 * The identity to scan for targets
47 public IdentityTargets(Identity identity) {
48 this.identity = identity;
56 * Returns the targets of the identity.
58 * @return The targets defined in the identity
60 public Map<String, String> getTargets() {
62 return Collections.unmodifiableMap(targets);
66 * Returns the target with the given name.
69 * The name of the target
72 public String getTarget(String name) {
74 return targets.get(name);
82 * Re-scans the identity for targets.
84 private void scanForTargets() {
85 synchronized (targets) {
87 for (Entry<String, String> property : identity.getProperties().entrySet()) {
88 if (property.getKey().startsWith("tns.")) {
89 targets.put(property.getKey().substring(4), property.getValue());
103 public Iterator<Entry<String, String>> iterator() {
104 synchronized (targets) {
106 return new HashMap<String, String>(targets).entrySet().iterator();