001/*
002 * MIT License
003 * 
004 * Copyright (c) 2016 Michael Angstadt
005 * 
006 * Permission is hereby granted, free of charge, to any person obtaining a copy
007 * of this software and associated documentation files (the "Software"), to deal
008 * in the Software without restriction, including without limitation the rights
009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010 * copies of the Software, and to permit persons to whom the Software is
011 * furnished to do so, subject to the following conditions:
012 * 
013 * The above copyright notice and this permission notice shall be included in
014 * all copies or substantial portions of the Software.
015 * 
016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
022 * SOFTWARE.
023 */
024
025package com.github.mangstadt.vinnie;
026
027/**
028 * Represents a vobject property.
029 * @author Michael Angstadt
030 */
031public class VObjectProperty {
032        private String group;
033        private String name;
034        private VObjectParameters parameters;
035        private String value;
036
037        /**
038         * Creates an empty property.
039         */
040        public VObjectProperty() {
041                this(null, null);
042        }
043
044        /**
045         * Create a new property.
046         * @param name the property name (should contain only letters, numbers, and
047         * dashes; letters should be uppercase by convention)
048         * @param value the property value
049         */
050        public VObjectProperty(String name, String value) {
051                this(null, name, value);
052        }
053
054        /**
055         * Creates a new property
056         * @param group the group name (should contain only letters, numbers, and
057         * dashes; can be null)
058         * @param name the property name (should contain only letters, numbers, and
059         * dashes; letters should be uppercase by convention)
060         * @param value the property value
061         */
062        public VObjectProperty(String group, String name, String value) {
063                this(group, name, new VObjectParameters(), value);
064        }
065
066        /**
067         * Creates a new property
068         * @param group the group name (should contain only letters, numbers, and
069         * dashes; can be null)
070         * @param name the property name (should contain only letters, numbers, and
071         * dashes; letters should be uppercase by convention)
072         * @param parameters the property parameters (cannot be null)
073         * @param value the property value
074         */
075        public VObjectProperty(String group, String name, VObjectParameters parameters, String value) {
076                this.group = group;
077                this.name = name;
078                this.parameters = parameters;
079                this.value = value;
080        }
081
082        /**
083         * Gets the group name (note: iCalendar properties do not use group names).
084         * @return the group name or null if the property doesn't have one
085         */
086        public String getGroup() {
087                return group;
088        }
089
090        /**
091         * Sets the group name (note: iCalendar properties do not use group names).
092         * @param group the group name or null to remove (should contain only
093         * letters, numbers, and dashes)
094         */
095        public void setGroup(String group) {
096                this.group = group;
097        }
098
099        /**
100         * Gets the property name.
101         * @return the property name
102         */
103        public String getName() {
104                return name;
105        }
106
107        /**
108         * Sets the property name.
109         * @param name the property name (should contain only letters, numbers, and
110         * dashes; letters should be uppercase by convention)
111         */
112        public void setName(String name) {
113                this.name = name;
114        }
115
116        /**
117         * Gets the parameters.
118         * @return the parameters
119         */
120        public VObjectParameters getParameters() {
121                return parameters;
122        }
123
124        /**
125         * Sets the parameters.
126         * @param parameters the parameters (cannot be null)
127         */
128        public void setParameters(VObjectParameters parameters) {
129                this.parameters = parameters;
130        }
131
132        /**
133         * Gets the property value.
134         * @return the property value
135         */
136        public String getValue() {
137                return value;
138        }
139
140        /**
141         * Sets the property value.
142         * @param value the property value
143         */
144        public void setValue(String value) {
145                this.value = value;
146        }
147
148        @Override
149        public int hashCode() {
150                final int prime = 31;
151                int result = 1;
152                result = prime * result + ((group == null) ? 0 : group.hashCode());
153                result = prime * result + ((name == null) ? 0 : name.hashCode());
154                result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
155                result = prime * result + ((value == null) ? 0 : value.hashCode());
156                return result;
157        }
158
159        @Override
160        public boolean equals(Object obj) {
161                if (this == obj) return true;
162                if (obj == null) return false;
163                if (getClass() != obj.getClass()) return false;
164                VObjectProperty other = (VObjectProperty) obj;
165                if (group == null) {
166                        if (other.group != null) return false;
167                } else if (!group.equals(other.group)) return false;
168                if (name == null) {
169                        if (other.name != null) return false;
170                } else if (!name.equals(other.name)) return false;
171                if (parameters == null) {
172                        if (other.parameters != null) return false;
173                } else if (!parameters.equals(other.parameters)) return false;
174                if (value == null) {
175                        if (other.value != null) return false;
176                } else if (!value.equals(other.value)) return false;
177                return true;
178        }
179
180        @Override
181        public String toString() {
182                return "VObjectProperty [group=" + group + ", name=" + name + ", parameters=" + parameters + ", value=" + value + "]";
183        }
184}