• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, http://www.snakeyaml.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.yaml.snakeyaml.introspector;
17 
18 /**
19  * <p>
20  * A <code>Property</code> represents a single member variable of a class,
21  * possibly including its accessor methods (getX, setX). The name stored in this
22  * class is the actual name of the property as given for the class, not an
23  * alias.
24  * </p>
25  *
26  * <p>
27  * Objects of this class have a total ordering which defaults to ordering based
28  * on the name of the property.
29  * </p>
30  */
31 public abstract class Property implements Comparable<Property> {
32 
33     private final String name;
34     private final Class<?> type;
35 
Property(String name, Class<?> type)36     public Property(String name, Class<?> type) {
37         this.name = name;
38         this.type = type;
39     }
40 
getType()41     public Class<?> getType() {
42         return type;
43     }
44 
getActualTypeArguments()45     abstract public Class<?>[] getActualTypeArguments();
46 
getName()47     public String getName() {
48         return name;
49     }
50 
51     @Override
toString()52     public String toString() {
53         return getName() + " of " + getType();
54     }
55 
compareTo(Property o)56     public int compareTo(Property o) {
57         return name.compareTo(o.name);
58     }
59 
isWritable()60     public boolean isWritable() {
61         return true;
62     }
63 
isReadable()64     public boolean isReadable() {
65         return true;
66     }
67 
set(Object object, Object value)68     abstract public void set(Object object, Object value) throws Exception;
69 
get(Object object)70     abstract public Object get(Object object);
71 
72     @Override
hashCode()73     public int hashCode() {
74         return name.hashCode() + type.hashCode();
75     }
76 
77     @Override
equals(Object other)78     public boolean equals(Object other) {
79         if (other instanceof Property) {
80             Property p = (Property) other;
81             return name.equals(p.getName()) && type.equals(p.getType());
82         }
83         return false;
84     }
85 }