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

org.jboss.resteasy.reactive.common.jaxrs.LinkImpl Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package org.jboss.resteasy.reactive.common.jaxrs;

import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.ws.rs.core.Link;
import jakarta.ws.rs.core.UriBuilder;
import jakarta.ws.rs.ext.RuntimeDelegate;

/**
 * @author Bill Burke
 */
public class LinkImpl extends Link {
    protected final URI uri;

    /**
     * A map for all the link parameters such as "rel", "type", etc.
     */
    protected final Map map;

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

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

    LinkImpl(final URI uri, final Map map) {
        this.uri = uri;
        this.map = map.isEmpty() ? Collections. emptyMap()
                : Collections
                        .unmodifiableMap(new HashMap(map));
    }

    @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 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