/** * {@link Headers#names()} and convert each element of {@link Set} to a {@link String}. * @param headers the headers to get the names from * @return a {@link Set} of header values or an empty {@link Set} if no values are found. */ public static Set<String> namesAsString(Headers<CharSequence, CharSequence, ?> headers) { return new CharSequenceDelegatingStringSet(headers.names()); }
/** * Test this object for equality against {@code h2}. * @param h2 The object to check equality for. * @param valueHashingStrategy Defines how values will be compared for equality. * @return {@code true} if this object equals {@code h2} given {@code valueHashingStrategy}. * {@code false} otherwise. */ public final boolean equals(Headers<K, V, ?> h2, HashingStrategy<V> valueHashingStrategy) { if (h2.size() != size()) { return false; } if (this == h2) { return true; } for (K name : names()) { List<V> otherValues = h2.getAll(name); List<V> values = getAll(name); if (otherValues.size() != values.size()) { return false; } for (int i = 0; i < otherValues.size(); i++) { if (!valueHashingStrategy.equals(otherValues.get(i), values.get(i))) { return false; } } } return true; }
/** * Copies the entries missing in this headers from the specified {@link Headers}. * This method is a shortcut of the following code: * <pre>{@code * headers.names().forEach(name -> { * if (!contains(name)) { * set(name, headers.getAll(name)); * } * }); * }</pre> */ default HttpHeaders setAllIfAbsent(Headers<AsciiString, String, ?> headers) { requireNonNull(headers, "headers"); if (!headers.isEmpty()) { headers.names().forEach(name -> { if (!contains(name)) { set(name, headers.getAll(name)); } }); } return this; }
@Override public boolean equals(Object o) { if (!(o instanceof Headers)) { return false; } Headers<?, ?, ?> rhs = (Headers<?, ?, ?>) o; return isEmpty() && rhs.isEmpty(); }
/** * {@link Headers#get(Object)} and convert each element of {@link List} to a {@link String}. * @param name the name of the header to retrieve * @return a {@link List} of header values or an empty {@link List} if no values are found. */ public static <K, V> List<String> getAllAsString(Headers<K, V, ?> headers, K name) { final List<V> allNames = headers.getAll(name); return new AbstractList<String>() { @Override public String get(int index) { V value = allNames.get(index); return value != null ? value.toString() : null; } @Override public int size() { return allNames.size(); } }; }
/** * {@link Headers#get(Object)} and convert the result to a {@link String}. * @param headers the headers to get the {@code name} from * @param name the name of the header to retrieve * @return the first header value if the header is found. {@code null} if there's no such entry. */ public static <K, V> String getAsString(Headers<K, V, ?> headers, K name) { V orig = headers.get(name); return orig != null ? orig.toString() : null; }
@Override public boolean equals(Object o) { if (!(o instanceof Headers)) { return false; } Headers<?, ?, ?> rhs = (Headers<?, ?, ?>) o; return isEmpty() && rhs.isEmpty(); }
/** * {@link Headers#get(Object)} and convert each element of {@link List} to a {@link String}. * @param name the name of the header to retrieve * @return a {@link List} of header values or an empty {@link List} if no values are found. */ public static <K, V> List<String> getAllAsString(Headers<K, V, ?> headers, K name) { final List<V> allNames = headers.getAll(name); return new AbstractList<String>() { @Override public String get(int index) { V value = allNames.get(index); return value != null ? value.toString() : null; } @Override public int size() { return allNames.size(); } }; }
/** * {@link Headers#get(Object)} and convert the result to a {@link String}. * @param headers the headers to get the {@code name} from * @param name the name of the header to retrieve * @return the first header value if the header is found. {@code null} if there's no such entry. */ public static <K, V> String getAsString(Headers<K, V, ?> headers, K name) { V orig = headers.get(name); return orig != null ? orig.toString() : null; }
/** * {@link Headers#names()} and convert each element of {@link Set} to a {@link String}. * @param headers the headers to get the names from * @return a {@link Set} of header values or an empty {@link Set} if no values are found. */ public static Set<String> namesAsString(Headers<CharSequence, CharSequence, ?> headers) { return new CharSequenceDelegatingStringSet(headers.names()); }
/** * Test this object for equality against {@code h2}. * @param h2 The object to check equality for. * @param valueHashingStrategy Defines how values will be compared for equality. * @return {@code true} if this object equals {@code h2} given {@code valueHashingStrategy}. * {@code false} otherwise. */ public final boolean equals(Headers<K, V, ?> h2, HashingStrategy<V> valueHashingStrategy) { if (h2.size() != size()) { return false; } if (this == h2) { return true; } for (K name : names()) { List<V> otherValues = h2.getAll(name); List<V> values = getAll(name); if (otherValues.size() != values.size()) { return false; } for (int i = 0; i < otherValues.size(); i++) { if (!valueHashingStrategy.equals(otherValues.get(i), values.get(i))) { return false; } } } return true; }
@Override public boolean equals(Object o) { if (!(o instanceof Headers)) { return false; } Headers<?, ?, ?> rhs = (Headers<?, ?, ?>) o; return isEmpty() && rhs.isEmpty(); }
/** * {@link Headers#get(Object)} and convert each element of {@link List} to a {@link String}. * @param name the name of the header to retrieve * @return a {@link List} of header values or an empty {@link List} if no values are found. */ public static <K, V> List<String> getAllAsString(Headers<K, V, ?> headers, K name) { final List<V> allNames = headers.getAll(name); return new AbstractList<String>() { @Override public String get(int index) { V value = allNames.get(index); return value != null ? value.toString() : null; } @Override public int size() { return allNames.size(); } }; }
/** * {@link Headers#get(Object)} and convert the result to a {@link String}. * @param headers the headers to get the {@code name} from * @param name the name of the header to retrieve * @return the first header value if the header is found. {@code null} if there's no such entry. */ public static <K, V> String getAsString(Headers<K, V, ?> headers, K name) { V orig = headers.get(name); return orig != null ? orig.toString() : null; }
/** * {@link Headers#names()} and convert each element of {@link Set} to a {@link String}. * @param headers the headers to get the names from * @return a {@link Set} of header values or an empty {@link Set} if no values are found. */ public static Set<String> namesAsString(Headers<CharSequence, CharSequence, ?> headers) { return new CharSequenceDelegatingStringSet(headers.names()); }
/** * Test this object for equality against {@code h2}. * @param h2 The object to check equality for. * @param valueHashingStrategy Defines how values will be compared for equality. * @return {@code true} if this object equals {@code h2} given {@code valueHashingStrategy}. * {@code false} otherwise. */ public final boolean equals(Headers<K, V, ?> h2, HashingStrategy<V> valueHashingStrategy) { if (h2.size() != size()) { return false; } if (this == h2) { return true; } for (K name : names()) { List<V> otherValues = h2.getAll(name); List<V> values = getAll(name); if (otherValues.size() != values.size()) { return false; } for (int i = 0; i < otherValues.size(); i++) { if (!valueHashingStrategy.equals(otherValues.get(i), values.get(i))) { return false; } } } return true; }
@Override public boolean equals(Object o) { if (!(o instanceof Headers)) { return false; } Headers<?, ?, ?> rhs = (Headers<?, ?, ?>) o; return isEmpty() && rhs.isEmpty(); }
/** * {@link Headers#get(Object)} and convert each element of {@link List} to a {@link String}. * @param name the name of the header to retrieve * @return a {@link List} of header values or an empty {@link List} if no values are found. */ public static <K, V> List<String> getAllAsString(Headers<K, V, ?> headers, K name) { final List<V> allNames = headers.getAll(name); return new AbstractList<String>() { @Override public String get(int index) { V value = allNames.get(index); return value != null ? value.toString() : null; } @Override public int size() { return allNames.size(); } }; }
/** * {@link Headers#get(Object)} and convert the result to a {@link String}. * @param headers the headers to get the {@code name} from * @param name the name of the header to retrieve * @return the first header value if the header is found. {@code null} if there's no such entry. */ public static <K, V> String getAsString(Headers<K, V, ?> headers, K name) { V orig = headers.get(name); return orig != null ? orig.toString() : null; }
@Override public T setAll(Headers<? extends K, ? extends V, ?> headers) { if (headers != this) { for (K key : headers.names()) { remove(key); } addImpl(headers); } return thisT(); }