com.nike.riposte.server.http.header.AcceptHeader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riposte-spi Show documentation
Show all versions of riposte-spi Show documentation
Riposte module riposte-spi
package com.nike.riposte.server.http.header;
import com.nike.riposte.server.http.header.accept.MediaRange;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* Models an RFC-2616 14.1 Accept Header, which is a list of MediaRange instances, sorted most-significant-first.
*
* @author Kirk Peterson
*/
@SuppressWarnings("WeakerAccess")
public class AcceptHeader implements Iterable {
/**
* the MediaRanges found in this AcceptHeader, sorted by most-significant-first order.
*/
public final List mediaRanges;
/**
* Constructs an AcceptHeader using the given list of MediaRanges, sorting them in most-significant-first order.
* Note: the given list will have Collections.sort(mediaRanges) performed on it, ordering of the given list
* could be modified. If you need to reuse the given list, you should pass in a copy instead.
*/
public AcceptHeader(final List mediaRanges) {
Collections.sort(mediaRanges);
this.mediaRanges = Collections.unmodifiableList(mediaRanges);
}
private String toStringCache = null;
@Override
public String toString() {
if (toStringCache == null) {
toStringCache = mediaRanges.stream().map(MediaRange::toString).collect(Collectors.joining(","));
}
return toStringCache;
}
@Override
public Iterator iterator() {
return mediaRanges.iterator();
}
}