package org.opennms.newts.api;


import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Collections;
import java.util.Map;

import com.google.common.base.Objects;


/**
 * A unique resource to associate a group of metrics to. Newts utilizes this structure to index the
 * resources of the samples it has seen, providing a means of search and discovery.
 * 
 * @author eevans
 */
public class Resource {

    private final String m_id;
    private final Map<String, String> m_attributes;

    /**
     * Creates a new {@link Resource} instance with the supplied resource ID, and an empty set of
     * attributes.
     *
     * @param id
     *            the resource identifier.
     */
    public Resource(String id) {
        this(id, Collections.<String, String> emptyMap());
    }

    /**
     * Creates a new {@link Resource} with the supplied ID.
     *
     * @param parent
     *            the parent resource.
     * @param attributes
     *            attributes to associate with this resource.
     */
    public Resource(String id, Map<String, String> attributes) {
        m_id = checkNotNull(id, "id argument");
        m_attributes = checkNotNull(attributes, "attributes argument");
    }

    /**
     * @return the ID of this resource.
     */
    public String getId() {
        return m_id;
    }

    /**
     * @return the set of attributes for this resource.
     */
    public Map<String, String> getAttributes() {
        return m_attributes;
    }

    @Override
    public String toString() {
        return String.format("%s[%s]", getClass().getSimpleName(), getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId(), getAttributes());
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Resource)) return false;
        return getId().equals(((Resource) o).getId());
    }

}

@@ -425,16 +425,115 @@
 urce %7B%0A%0A
+    public static final String DEFAULT_APPLICATION = %22D%22;%0A%0A    private final String m_application;%0A
     priv
@@ -693,16 +693,47 @@
 urce ID,
+ default application%0A     * ID,
  and an 
@@ -744,23 +744,16 @@
 y set of
-%0A     *
  attribu
@@ -910,17 +910,16 @@
  String%3E
- 
 emptyMap
@@ -975,16 +975,25 @@
 esource%7D
+ instance
  with th
@@ -1007,77 +1007,466 @@
 ied 
-ID.%0A     *%0A     * @param parent%0A     *            the parent resource
+resource ID, attributes and the%0A     * default application ID.%0A     *%0A     * @param id%0A     *            the resource identifier.%0A     */%0A    public Resource(String id, Map%3CString, String%3E attributes) %7B%0A        this(DEFAULT_APPLICATION, id, attributes);%0A    %7D%0A%0A    /**%0A     * Creates a new %7B@link Resource%7D with the supplied ID.%0A     *%0A     * @param application%0A     *            the parent application.%0A     * @param id%0A     *            resource identifier
 .%0A  
@@ -1577,32 +1577,52 @@
 Resource(String 
+application, String 
 id, Map%3CString, 
@@ -1635,32 +1635,107 @@
 %3E attributes) %7B%0A
+        m_application = checkNotNull(application, %22application argument%22);%0A
         m_id = c
@@ -1837,32 +1837,174 @@
 ument%22);%0A    %7D%0A%0A
+    /**%0A     * @return the application ID of this resource.%0A     */%0A    public String getApplication() %7B%0A        return m_application;%0A    %7D%0A%0A
     /**%0A     * @
@@ -2459,16 +2459,34 @@
 ashCode(
+getApplication(), 
 getId(),
@@ -2629,16 +2629,75 @@
   return
+ getApplication().equals(((Resource)o).getApplication()) &&
  getId()

add application id to resources