001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http;
014
015import org.apache.juneau.internal.*;
016
017/**
018 * Category of headers that consist of a single string value.
019 *
020 * <p>
021 * <h5 class='figure'>Example</h5>
022 * <p class='bcode w800'>
023 *    Accept-Ranges: bytes
024 * </p>
025 *
026 * <h5 class='section'>See Also:</h5>
027 * <ul class='doctree'>
028 *    <li class='extlink'>{@doc RFC2616}
029 * </ul>
030 */
031public class HeaderString {
032
033   final String value;
034
035   /**
036    * Constructor.
037    *
038    * @param value The raw header value.
039    */
040   protected HeaderString(String value) {
041      this.value = StringUtils.trim(value);
042   }
043
044   /**
045    * Returns <jk>true</jk> if the specified value is the same using {@link String#equalsIgnoreCase(String)}.
046    *
047    * @param compare The value to compare against.
048    * @return <jk>true</jk> if the specified value is the same.
049    */
050   public boolean eqIC(String compare) {
051      return value.equalsIgnoreCase(compare);
052   }
053
054   /**
055    * Returns <jk>true</jk> if the specified value is the same using {@link String#equals(Object)}.
056    *
057    * @param compare The value to compare against.
058    * @return <jk>true</jk> if the specified value is the same.
059    */
060   public boolean eq(String compare) {
061      return value.equals(compare);
062   }
063
064   /**
065    * Returns this header as a simple string value.
066    *
067    * <p>
068    * Functionally equivalent to calling {@link #toString()}.
069    *
070    * @return This header as a simple string.
071    */
072   public String asString() {
073      return value;
074   }
075
076   @Override /* Object */
077   public String toString() {
078      return value == null ? "" : value;
079   }
080}