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

org.jboss.resteasy.spi.LinkHeader Maven / Gradle / Ivy

The newest version!
package org.jboss.resteasy.spi;

import org.jboss.resteasy.plugins.delegates.LinkHeaderDelegate;
import org.jboss.resteasy.specimpl.LinkBuilderImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Link;

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
public class LinkHeader
{
   private Map linksByRelationship = new HashMap();
   private Map linksByTitle = new HashMap();
   private List links = new ArrayList();

   public LinkHeader addLink(final Link link)
   {
      links.add(link);
      return this;
   }

   public LinkHeader addLink(final String title, final String rel, final String href, final String type)
   {
      final Link link = new LinkBuilderImpl().uri(href).rel(rel).title(title).type(type).build();
      return addLink(link);
   }

   public Link getLinkByTitle(String title)
   {
      return linksByTitle.get(title);
   }

   public Link getLinkByRelationship(String rel)
   {
      return linksByRelationship.get(rel);
   }

   /**
    * Index of links by relationship "rel" or "rev"
    *
    * @return map
    */
   public Map getLinksByRelationship()
   {
      return linksByRelationship;
   }

   /**
    * Index of links by title
    *
    * @return map
    */
   public Map getLinksByTitle()
   {
      return linksByTitle;
   }

   /**
    * All the links defined
    *
    * @return links
    */
   public List getLinks()
   {
      return links;
   }

   public static LinkHeader valueOf(String val)
   {
      return LinkHeaderDelegate.from(val);
   }

   public String toString()
   {
      return LinkHeaderDelegate.getString(this);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy