Java tutorial
package org.apache.http.message; import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; import org.apache.http.Header; import org.apache.http.HeaderIterator; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.util.CharArrayBuffer; @NotThreadSafe public class HeaderGroup implements Serializable, Cloneable { private static final long serialVersionUID = 2608834160639271617L; private final List<Header> headers; public HeaderGroup() { this.headers = new ArrayList(16); } public void clear() { this.headers.clear(); } public void addHeader(Header header) { if (header != null) { this.headers.add(header); } } public void removeHeader(Header header) { if (header != null) { this.headers.remove(header); } } public void updateHeader(Header header) { if (header != null) { for (int i = 0; i < this.headers.size(); i++) { if (((Header) this.headers.get(i)).getName().equalsIgnoreCase(header.getName())) { this.headers.set(i, header); return; } } this.headers.add(header); } } public void setHeaders(Header[] headerArr) { clear(); if (headerArr != null) { Collections.addAll(this.headers, headerArr); } } public Header getCondensedHeader(String str) { int i = 1; Header[] headers = getHeaders(str); if (headers.length == 0) { return null; } if (headers.length == 1) { return headers[0]; } CharArrayBuffer charArrayBuffer = new CharArrayBuffer( AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); charArrayBuffer.append(headers[0].getValue()); while (i < headers.length) { charArrayBuffer.append(", "); charArrayBuffer.append(headers[i].getValue()); i++; } return new BasicHeader(str.toLowerCase(Locale.ENGLISH), charArrayBuffer.toString()); } public Header[] getHeaders(String str) { List arrayList = new ArrayList(); for (int i = 0; i < this.headers.size(); i++) { Header header = (Header) this.headers.get(i); if (header.getName().equalsIgnoreCase(str)) { arrayList.add(header); } } return (Header[]) arrayList.toArray(new Header[arrayList.size()]); } public Header getFirstHeader(String str) { for (int i = 0; i < this.headers.size(); i++) { Header header = (Header) this.headers.get(i); if (header.getName().equalsIgnoreCase(str)) { return header; } } return null; } public Header getLastHeader(String str) { for (int size = this.headers.size() - 1; size >= 0; size--) { Header header = (Header) this.headers.get(size); if (header.getName().equalsIgnoreCase(str)) { return header; } } return null; } public Header[] getAllHeaders() { return (Header[]) this.headers.toArray(new Header[this.headers.size()]); } public boolean containsHeader(String str) { for (int i = 0; i < this.headers.size(); i++) { if (((Header) this.headers.get(i)).getName().equalsIgnoreCase(str)) { return true; } } return false; } public HeaderIterator iterator() { return new BasicListHeaderIterator(this.headers, null); } public HeaderIterator iterator(String str) { return new BasicListHeaderIterator(this.headers, str); } public HeaderGroup copy() { HeaderGroup headerGroup = new HeaderGroup(); headerGroup.headers.addAll(this.headers); return headerGroup; } public Object clone() throws CloneNotSupportedException { return super.clone(); } public String toString() { return this.headers.toString(); } }