/* dIntProg Browser. A webbrowser written in Java.
 * Copyright (C) 2001 Martin Geisler <gimpster@gimpster.com>
 *  
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * 
 * Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

import java.net.*;
import java.util.*;

/** A set of hyperlinks. The elements doesn't have to be unique. */
public class HyperLinkSet {

    private LinkedList links;

    /** Constructor. */
    public HyperLinkSet() {
        links = new LinkedList();
    }
    
    /** Inserts a new {@link HyperLink} into the set.
     *  @param l the link to be inserted. */
    public void insert(HyperLink l) {
        links.addLast(l);
    }

    /** Finds the {@link HyperLink} at (<code>x</code>,
     *  <code>y</code>).
     *  @param x the <code>x</code> coordinate.
     *  @param y the <code>y</code> coordinate.
     *  @return the {@link HyperLink} at (<code>x</code>,
     *  <code>y</code>), or <code>null</code> if no link was found. */
    public URL getURL(int x, int y) {
        ListIterator iterator = links.listIterator();
        while (iterator.hasNext()) {
            HyperLink link = (HyperLink)iterator.next();
            if (link.contains(x, y)) {
                return link.getURL();
            }
        }
        return null;
    }

    /** Clears the set. */
    public void clear() {
        links.clear();
    }

}