Changeset b048b01 for apps/addressbook


Ignore:
Timestamp:
Mar 11, 2011 2:01:20 AM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f4e9257
Parents:
41fc9cf
Message:

generics

Location:
apps/addressbook/java/src/net/i2p/addressbook
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/addressbook/java/src/net/i2p/addressbook/AddressBook.java

    r41fc9cf rb048b01  
    4343    private String location;
    4444
    45     private Map addresses;
     45    private Map<String, String> addresses;
    4646
    4747    private boolean modified;
     
    5454     *            base64 i2p destinations.
    5555     */
    56     public AddressBook(Map addresses) {
     56    public AddressBook(Map<String, String> addresses) {
    5757        this.addresses = addresses;
    5858    }
     
    140140     *         destination.
    141141     */
    142     public Map getAddresses() {
     142    public Map<String, String> getAddresses() {
    143143        return this.addresses;
    144144    }
  • apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java

    r41fc9cf rb048b01  
    3131import java.io.StringReader;
    3232import java.util.HashMap;
    33 import java.util.Iterator;
    3433import java.util.LinkedList;
    3534import java.util.List;
     
    8685     * 
    8786     */
    88     public static Map parse(BufferedReader input) throws IOException {
    89         Map result = new HashMap();
     87    public static Map<String, String> parse(BufferedReader input) throws IOException {
     88        Map<String, String> result = new HashMap();
    9089        String inputLine;
    9190        inputLine = input.readLine();
     
    112111     *             if file cannot be read.
    113112     */
    114     public static Map parse(File file) throws IOException {
     113    public static Map<String, String> parse(File file) throws IOException {
    115114        FileInputStream fileStream = new FileInputStream(file);
    116115        BufferedReader input = new BufferedReader(new InputStreamReader(
    117116                fileStream));
    118         Map rv = ConfigParser.parse(input);
     117        Map<String, String> rv = ConfigParser.parse(input);
    119118        try {
    120119            fileStream.close();
     
    133132     *             if file cannot be read.
    134133     */
    135     public static Map parse(String string) throws IOException {
     134    public static Map<String, String> parse(String string) throws IOException {
    136135        StringReader stringReader = new StringReader(string);
    137136        BufferedReader input = new BufferedReader(stringReader);
     
    150149     *         cannot be read, map.
    151150     */
    152     public static Map parse(File file, Map map) {
    153         Map result;
     151    public static Map<String, String>  parse(File file, Map<String, String> map) {
     152        Map<String, String> result;
    154153        try {
    155154            result = ConfigParser.parse(file);
    156             for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
    157                 String key = (String) iter.next();
    158                 if (!result.containsKey(key))
    159                     result.put(key, map.get(key));
     155            for (Map.Entry<String, String> entry : map.entrySet()) {
     156                if (!result.containsKey(entry.getKey()))
     157                    result.put(entry.getKey(), entry.getValue());
    160158            }
    161159        } catch (IOException exp) {
     
    178176     *             if input cannot be read.
    179177     */
    180     public static List parseSubscriptions(BufferedReader input)
     178    public static List<String> parseSubscriptions(BufferedReader input)
    181179            throws IOException {
    182         List result = new LinkedList();
     180        List<String> result = new LinkedList();
    183181        String inputLine = input.readLine();
    184182        while (inputLine != null) {
     
    202200     *             if file cannot be read.
    203201     */
    204     public static List parseSubscriptions(File file) throws IOException {
     202    public static List<String> parseSubscriptions(File file) throws IOException {
    205203        FileInputStream fileStream = new FileInputStream(file);
    206204        BufferedReader input = new BufferedReader(new InputStreamReader(
    207205                fileStream));
    208         List rv = ConfigParser.parseSubscriptions(input);
     206        List<String> rv = ConfigParser.parseSubscriptions(input);
    209207        try {
    210208            fileStream.close();
     
    222220     *             if string cannot be read.
    223221     */
    224     public static List parseSubscriptions(String string) throws IOException {
     222    public static List<String> parseSubscriptions(String string) throws IOException {
    225223        StringReader stringReader = new StringReader(string);
    226224        BufferedReader input = new BufferedReader(stringReader);
     
    239237     *         file cannot be read, list.
    240238     */
    241     public static List parseSubscriptions(File file, List list) {
    242         List result;
     239    public static List<String> parseSubscriptions(File file, List<String> list) {
     240        List<String> result;
    243241        try {
    244242            result = ConfigParser.parseSubscriptions(file);
     
    264262     *             if the BufferedWriter cannot be written to.
    265263     */
    266     public static void write(Map map, BufferedWriter output) throws IOException {
    267         Iterator keyIter = map.keySet().iterator();
    268 
    269         while (keyIter.hasNext()) {
    270             String key = (String) keyIter.next();
    271             output.write(key + "=" + (String) map.get(key));
     264    public static void write(Map<String, String>  map, BufferedWriter output) throws IOException {
     265        for (Map.Entry<String, String> entry : map.entrySet()) {
     266            output.write(entry.getKey() + '=' + entry.getValue());
    272267            output.newLine();
    273268        }
     
    289284     *             if file cannot be written to.
    290285     */
    291     public static void write(Map map, File file) throws IOException {
     286    public static void write(Map<String, String> map, File file) throws IOException {
    292287        boolean success = false;
    293288        if (!isWindows) {
     
    319314     *             if output cannot be written to.
    320315     */
    321     public static void writeSubscriptions(List list, BufferedWriter output)
     316    public static void writeSubscriptions(List<String> list, BufferedWriter output)
    322317            throws IOException {
    323         Iterator iter = list.iterator();
    324 
    325         while (iter.hasNext()) {
    326             output.write((String) iter.next());
     318        for (String s : list) {
     319            output.write(s);
    327320            output.newLine();
    328321        }
     
    341334     *             if output cannot be written to.
    342335     */
    343     public static void writeSubscriptions(List list, File file)
     336    public static void writeSubscriptions(List<String> list, File file)
    344337            throws IOException {
    345338        ConfigParser.writeSubscriptions(list, new BufferedWriter(
  • apps/addressbook/java/src/net/i2p/addressbook/Daemon.java

    r41fc9cf rb048b01  
    8484     *            The directory containing addressbook's configuration files.
    8585     */
    86     public void update(Map settings, String home) {
    87         File masterFile = new File(home, (String) settings
     86    public void update(Map<String, String> settings, String home) {
     87        File masterFile = new File(home, settings
    8888                .get("master_addressbook"));
    89         File routerFile = new File(home, (String) settings
     89        File routerFile = new File(home, settings
    9090                .get("router_addressbook"));
    9191        File published = null;
    9292        if ("true".equals(settings.get("should_publish")))
    93             published = new File(home, (String) settings
     93            published = new File(home, settings
    9494                .get("published_addressbook"));
    95         File subscriptionFile = new File(home, (String) settings
     95        File subscriptionFile = new File(home, settings
    9696                .get("subscriptions"));
    97         File logFile = new File(home, (String) settings.get("log"));
    98         File etagsFile = new File(home, (String) settings.get("etags"));
    99         File lastModifiedFile = new File(home, (String) settings
     97        File logFile = new File(home, settings.get("log"));
     98        File etagsFile = new File(home, settings.get("etags"));
     99        File lastModifiedFile = new File(home, settings
    100100                .get("last_modified"));
    101         File lastFetchedFile = new File(home, (String) settings
     101        File lastFetchedFile = new File(home, settings
    102102                .get("last_fetched"));
    103103        long delay;
    104104        try {
    105             delay = Long.parseLong((String) settings.get("update_delay"));
     105            delay = Long.parseLong(settings.get("update_delay"));
    106106        } catch (NumberFormatException nfe) {
    107107            delay = 12;
     
    112112        AddressBook router = new AddressBook(routerFile);
    113113       
    114         List defaultSubs = new LinkedList();
     114        List<String> defaultSubs = new LinkedList();
    115115        // defaultSubs.add("http://i2p/NF2RLVUxVulR3IqK0sGJR0dHQcGXAzwa6rEO4WAWYXOHw-DoZhKnlbf1nzHXwMEJoex5nFTyiNMqxJMWlY54cvU~UenZdkyQQeUSBZXyuSweflUXFqKN-y8xIoK2w9Ylq1k8IcrAFDsITyOzjUKoOPfVq34rKNDo7fYyis4kT5bAHy~2N1EVMs34pi2RFabATIOBk38Qhab57Umpa6yEoE~rbyR~suDRvD7gjBvBiIKFqhFueXsR2uSrPB-yzwAGofTXuklofK3DdKspciclTVzqbDjsk5UXfu2nTrC1agkhLyqlOfjhyqC~t1IXm-Vs2o7911k7KKLGjB4lmH508YJ7G9fLAUyjuB-wwwhejoWqvg7oWvqo4oIok8LG6ECR71C3dzCvIjY2QcrhoaazA9G4zcGMm6NKND-H4XY6tUWhpB~5GefB3YczOqMbHq4wi0O9MzBFrOJEOs3X4hwboKWANf7DT5PZKJZ5KorQPsYRSq0E3wSOsFCSsdVCKUGsAAAA/i2p/hosts.txt");
    116116        defaultSubs.add("http://www.i2p2.i2p/hosts.txt");
    117117       
    118118        SubscriptionList subscriptions = new SubscriptionList(subscriptionFile,
    119                 etagsFile, lastModifiedFile, lastFetchedFile, delay, defaultSubs, (String) settings
    120                 .get("proxy_host"), Integer.parseInt((String) settings.get("proxy_port")));
     119                etagsFile, lastModifiedFile, lastFetchedFile, delay, defaultSubs, settings
     120                .get("proxy_host"), Integer.parseInt(settings.get("proxy_port")));
    121121        Log log = new Log(logFile);
    122122
     
    150150        }
    151151       
    152         Map defaultSettings = new HashMap();
     152        Map<String, String> defaultSettings = new HashMap();
    153153        defaultSettings.put("proxy_host", "127.0.0.1");
    154154        defaultSettings.put("proxy_port", "4444");
     
    174174        File settingsFile = new File(homeFile, settingsLocation);
    175175       
    176         Map settings = ConfigParser.parse(settingsFile, defaultSettings);
     176        Map<String, String> settings = ConfigParser.parse(settingsFile, defaultSettings);
    177177        // wait
    178178        try {
     
    182182       
    183183        while (_running) {
    184             long delay = Long.parseLong((String) settings.get("update_delay"));
     184            long delay = Long.parseLong(settings.get("update_delay"));
    185185            if (delay < 1) {
    186186                delay = 1;
  • apps/addressbook/java/src/net/i2p/addressbook/SubscriptionIterator.java

    r41fc9cf rb048b01  
    3636 * @author Ragnarok
    3737 */
    38 class SubscriptionIterator implements Iterator {
     38class SubscriptionIterator implements Iterator<AddressBook> {
    3939
    40     private Iterator subIterator;
     40    private Iterator<Subscription> subIterator;
    4141    private String proxyHost;
    4242    private int proxyPort;
     
    5252     * @param proxyPort proxt port number
    5353     */
    54     public SubscriptionIterator(List subscriptions, long delay, String proxyHost, int proxyPort) {
     54    public SubscriptionIterator(List<Subscription> subscriptions, long delay, String proxyHost, int proxyPort) {
    5555        this.subIterator = subscriptions.iterator();
    5656        this.delay = delay;
     
    7373     * @return an AddressBook (empty if the minimum delay has not been met)
    7474     */
    75     public Object next() {
    76         Subscription sub = (Subscription) this.subIterator.next();
     75    public AddressBook next() {
     76        Subscription sub = this.subIterator.next();
    7777        if (sub.getLastFetched() + this.delay < I2PAppContext.getGlobalContext().clock().now()) {
    7878            //System.err.println("Fetching addressbook from " + sub.getLocation());
  • apps/addressbook/java/src/net/i2p/addressbook/SubscriptionList.java

    r41fc9cf rb048b01  
    2525import java.io.IOException;
    2626import java.util.HashMap;
    27 import java.util.Iterator;
    2827import java.util.LinkedList;
    2928import java.util.List;
     
    3837class SubscriptionList {
    3938
    40     private List subscriptions;
     39    private List<Subscription> subscriptions;
    4140
    4241    private File etagsFile;
     
    6968     */
    7069    public SubscriptionList(File locationsFile, File etagsFile,
    71             File lastModifiedFile, File lastFetchedFile, long delay, List defaultSubs, String proxyHost,
     70            File lastModifiedFile, File lastFetchedFile, long delay, List<String> defaultSubs, String proxyHost,
    7271            int proxyPort) {
    7372        this.subscriptions = new LinkedList();
     
    7877        this.proxyHost = proxyHost;
    7978        this.proxyPort = proxyPort;
    80         Map etags;
    81         Map lastModified;
    82         Map lastFetched;
    83         String location;
    84         List locations = ConfigParser.parseSubscriptions(locationsFile,
     79        Map<String, String> etags;
     80        Map<String, String> lastModified;
     81        Map<String, String> lastFetched;
     82        List<String> locations = ConfigParser.parseSubscriptions(locationsFile,
    8583                defaultSubs);
    8684        try {
     
    9997            lastFetched = new HashMap();
    10098        }
    101         Iterator iter = locations.iterator();
    102         while (iter.hasNext()) {
    103             location = (String) iter.next();
    104             this.subscriptions.add(new Subscription(location, (String) etags.get(location),
    105                                    (String) lastModified.get(location),
    106                                    (String) lastFetched.get(location)));
     99        for (String location : locations) {
     100            this.subscriptions.add(new Subscription(location, etags.get(location),
     101                                   lastModified.get(location),
     102                                   lastFetched.get(location)));
    107103        }
    108104    }
     
    126122     */
    127123    public void write() {
    128         Iterator iter = this.subscriptions.iterator();
    129         Subscription sub;
    130         Map etags = new HashMap();
    131         Map lastModified = new HashMap();
    132         Map lastFetched = new HashMap();
    133         while (iter.hasNext()) {
    134             sub = (Subscription) iter.next();
     124        Map<String, String> etags = new HashMap();
     125        Map<String, String>  lastModified = new HashMap();
     126        Map<String, String>  lastFetched = new HashMap();
     127        for (Subscription sub : this.subscriptions) {
    135128            if (sub.getEtag() != null) {
    136129                etags.put(sub.getLocation(), sub.getEtag());
Note: See TracChangeset for help on using the changeset viewer.