001 /*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 * http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 *
014 * See the NOTICE file distributed with this work for additional
015 * information regarding copyright ownership.
016 */
017
018 package com.osbcp.cssparser;
019
020 /**
021 * Represents a property and its value of a CSS rule.
022 *
023 * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
024 */
025
026 public final class PropertyValue {
027
028 private String property;
029 private String value;
030
031 /**
032 * Creates a new PropertyValue based on a property and its value.
033 *
034 * @param property The CSS property (such as 'width' or 'color').
035 * @param value The value of the property (such as '100px' or 'red').
036 */
037
038 public PropertyValue(final String property, final String value) {
039 this.property = property;
040 this.value = value;
041 }
042
043 @Override
044 public String toString() {
045 return property + ": " + value;
046 }
047
048 @Override
049 public boolean equals(final Object object) {
050
051 if (object instanceof PropertyValue) {
052
053 PropertyValue target = (PropertyValue) object;
054
055 return target.property.equalsIgnoreCase(property) && target.value.equalsIgnoreCase(value);
056
057 }
058
059 return false;
060
061 }
062
063 @Override
064 public int hashCode() {
065 return toString().hashCode();
066 }
067
068 /**
069 * Returns the property.
070 *
071 * @return The property.
072 */
073
074 public String getProperty() {
075 return property;
076 }
077
078 /**
079 * Returns the value.
080 *
081 * @return The value.
082 */
083
084 public String getValue() {
085 return value;
086 }
087
088 }