001 package org.apache.commons.ognl.enhance;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 /**
023 * Implementation of {@link LocalReference}.
024 */
025 public class LocalReferenceImpl
026 implements LocalReference
027 {
028
029 private final String name;
030
031 private final Class<?> type;
032
033 private final String expression;
034
035 public LocalReferenceImpl( String name, String expression, Class<?> type )
036 {
037 this.name = name;
038 this.type = type;
039 this.expression = expression;
040 }
041
042 /**
043 * {@inheritDoc}
044 */
045 public String getName()
046 {
047 return name;
048 }
049
050 /**
051 * {@inheritDoc}
052 */
053 public String getExpression()
054 {
055 return expression;
056 }
057
058 /**
059 * {@inheritDoc}
060 */
061 public Class<?> getType()
062 {
063 return type;
064 }
065
066 /**
067 * {@inheritDoc}
068 */
069 @Override
070 public boolean equals( Object o )
071 {
072 if ( this == o )
073 {
074 return true;
075 }
076 if ( o == null || getClass() != o.getClass() )
077 {
078 return false;
079 }
080
081 LocalReferenceImpl that = (LocalReferenceImpl) o;
082
083 if ( expression != null ? !expression.equals( that.expression ) : that.expression != null )
084 {
085 return false;
086 }
087 if ( name != null ? !name.equals( that.name ) : that.name != null )
088 {
089 return false;
090 }
091 if ( type != null ? !type.equals( that.type ) : that.type != null )
092 {
093 return false;
094 }
095
096 return true;
097 }
098
099 /**
100 * {@inheritDoc}
101 */
102 @Override
103 public int hashCode()
104 {
105 int result;
106 result = ( name != null ? name.hashCode() : 0 );
107 result = 31 * result + ( type != null ? type.hashCode() : 0 );
108 result = 31 * result + ( expression != null ? expression.hashCode() : 0 );
109 return result;
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 @Override
116 public String toString()
117 {
118 return "LocalReferenceImpl[" + "_name='" + name + '\'' + '\n' + ", _type=" + type + '\n' + ", _expression='"
119 + expression + '\'' + '\n' + ']';
120 }
121 }