package net.onrc.onos.ofcontroller.linkdiscovery.web;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.floodlightcontroller.routing.Link;
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;

import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class LinksResource extends ServerResource {

    @Get("json")
    public Set<LinkWithType> retrieve() {
        ILinkDiscoveryService ld = (ILinkDiscoveryService)getContext().getAttributes().
                get(ILinkDiscoveryService.class.getCanonicalName());
        Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>();
        Set<LinkWithType> returnLinkSet = new HashSet<LinkWithType>();

        if (ld != null) {
            links.putAll(ld.getLinks());
            for (Link link: links.keySet()) {
                LinkInfo info = links.get(link);
                LinkWithType lwt = new LinkWithType(link,
                                                    info.getSrcPortState(),
                                                    info.getDstPortState(),
                                                    ld.getLinkType(link, info));
                returnLinkSet.add(lwt);
            }
        }
        return returnLinkSet;
    }
}

@@ -118,24 +118,52 @@
 a.util.Map;%0A
+import java.util.Map.Entry;%0A
 import java.
@@ -921,27 +921,41 @@
  for
- (Link link
+(Entry%3CLink, LinkInfo%3E e 
 : links.
 keyS
@@ -954,10 +954,12 @@
 nks.
-k
 e
+ntr
 ySet
@@ -988,34 +988,71 @@
 Link
-Info info = links.get(link
+ link = e.getKey();%0A                LinkInfo info = e.getValue(
 );%0A 

Fix potential performance issue reported by FindBugs