All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.specimpl.LinkImpl Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package org.jboss.resteasy.specimpl;

import javax.ws.rs.core.Link;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.ext.RuntimeDelegate;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
public class LinkImpl extends Link
{
   protected URI uri;

   /**
    * A map for all the link parameters such as "rel", "type", etc.
    */
   protected Map map = new HashMap();

   protected static final RuntimeDelegate.HeaderDelegate delegate =
           RuntimeDelegate.getInstance().createHeaderDelegate(Link.class);

   public static Link valueOf(String value)
   {
      return delegate.fromString(value);
   }

   @Override
   public URI getUri() {
      return uri;
   }

   @Override
   public UriBuilder getUriBuilder() {
      return UriBuilder.fromUri(uri);
   }

   @Override
   public String getRel() {
      return map.get(REL);
   }

   @Override
   public List getRels() {
      final String rels = map.get(REL);
      return rels == null ? Collections.emptyList() : Arrays.asList(rels.split(" +"));
   }

   @Override
   public String getTitle() {
      return map.get(TITLE);
   }

   @Override
   public String getType() {
      return map.get(TYPE);
   }

   @Override
   public Map getParams() {
      return new HashMap(map);
   }

   @Override
   public boolean equals(Object other) {
      if (this == other) {
         return true;
      }
      if (other instanceof LinkImpl) {
         final LinkImpl otherLink = (LinkImpl) other;
         return uri.equals(otherLink.uri) && map.equals(otherLink.map);
      }
      return false;
   }

   @Override
   public int hashCode() {
      int hash = 3;
      hash = 89 * hash + (this.uri != null ? this.uri.hashCode() : 0);
      hash = 89 * hash + (this.map != null ? this.map.hashCode() : 0);
      return hash;
   }

   @Override
   public String toString() {
      return delegate.toString(this);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy