~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/analysis/EntityPropertyValue.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.importexport.analysis;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 * * Redistributions of source code must retain the above copyright notice, this
 
10
 *   list of conditions and the following disclaimer.
 
11
 * * Redistributions in binary form must reproduce the above copyright notice,
 
12
 *   this list of conditions and the following disclaimer in the documentation
 
13
 *   and/or other materials provided with the distribution.
 
14
 * * Neither the name of the HISP project nor the names of its contributors may
 
15
 *   be used to endorse or promote products derived from this software without
 
16
 *   specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
22
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
25
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
/**
 
31
 * @author Lars Helge Overland
 
32
 * @version $Id$
 
33
 */
 
34
public class EntityPropertyValue
 
35
    implements Comparable<EntityPropertyValue>
 
36
{
 
37
    private String entity;
 
38
 
 
39
    private String property;
 
40
 
 
41
    private String value;
 
42
 
 
43
    // -------------------------------------------------------------------------
 
44
    // Constructors
 
45
    // -------------------------------------------------------------------------
 
46
 
 
47
    public EntityPropertyValue( Class<?> entity, String property, String value )
 
48
    {
 
49
        this.entity = entity.getSimpleName();
 
50
        this.property = property;
 
51
        this.value = value;
 
52
    }
 
53
 
 
54
    // -------------------------------------------------------------------------
 
55
    // Getters and setters
 
56
    // -------------------------------------------------------------------------
 
57
 
 
58
    public String getEntity()
 
59
    {
 
60
        return entity;
 
61
    }
 
62
 
 
63
    public void setEntity( String entity )
 
64
    {
 
65
        this.entity = entity;
 
66
    }
 
67
 
 
68
    public String getProperty()
 
69
    {
 
70
        return property;
 
71
    }
 
72
 
 
73
    public void setProperty( String property )
 
74
    {
 
75
        this.property = property;
 
76
    }
 
77
 
 
78
    public String getValue()
 
79
    {
 
80
        return value;
 
81
    }
 
82
 
 
83
    public void setValue( String value )
 
84
    {
 
85
        this.value = value;
 
86
    }
 
87
    
 
88
    // -------------------------------------------------------------------------
 
89
    // hashCode, equals, toString, compareTo
 
90
    // -------------------------------------------------------------------------
 
91
 
 
92
    @Override
 
93
    public int hashCode()
 
94
    {
 
95
        final int prime = 31;        
 
96
        
 
97
        int result = 1;
 
98
        
 
99
        result = prime * result + ( ( entity == null ) ? 0 : entity.hashCode() );
 
100
        result = prime * result + ( ( property == null ) ? 0 : property.hashCode() );
 
101
        result = prime * result + ( ( value == null ) ? 0 : value.hashCode() );
 
102
        
 
103
        return result;
 
104
    }
 
105
 
 
106
    @Override
 
107
    public boolean equals( Object object )
 
108
    {
 
109
        if ( this == object )
 
110
        {
 
111
            return true;
 
112
        }
 
113
        
 
114
        if ( object == null )
 
115
        {
 
116
            return false;
 
117
        }
 
118
        
 
119
        if ( getClass() != object.getClass() )
 
120
        {
 
121
            return false;
 
122
        }
 
123
        
 
124
        final EntityPropertyValue other = (EntityPropertyValue) object;
 
125
        
 
126
        if ( entity == null )
 
127
        {
 
128
            if ( other.entity != null )
 
129
            {
 
130
                return false;
 
131
            }
 
132
        }
 
133
        else if ( !entity.equals( other.entity ) )
 
134
        {
 
135
            return false;
 
136
        }
 
137
        
 
138
        if ( property == null )
 
139
        {
 
140
            if ( other.property != null )
 
141
            {
 
142
                return false;
 
143
            }
 
144
        }
 
145
        else if ( !property.equals( other.property ) )
 
146
        {
 
147
            return false;
 
148
        }
 
149
        
 
150
        if ( value == null )
 
151
        {
 
152
            if ( other.value != null )
 
153
            {
 
154
                return false;
 
155
            }
 
156
        }
 
157
        else if ( !value.equals( other.value ) )
 
158
        {
 
159
            return false;
 
160
        }
 
161
        
 
162
        return true;
 
163
    }
 
164
 
 
165
    @Override
 
166
    public String toString()
 
167
    {
 
168
        return "[" + entity + ", " + property + ", " + value + "]";
 
169
    }
 
170
 
 
171
    public int compareTo( EntityPropertyValue other )
 
172
    {
 
173
        if ( this == other )
 
174
        {
 
175
            return 0;
 
176
        }
 
177
        
 
178
        int compare1 = compareTo( entity, other.entity );
 
179
        int compare2 = compareTo( property, other.property );
 
180
        int compare3 = compareTo( value, other.value );
 
181
        
 
182
        return ( compare1 != 0 ) ? compare1 : ( compare2 != 0 ) ? compare2 : compare3;
 
183
    }
 
184
    
 
185
    private int compareTo( String string1, String string2 )
 
186
    {
 
187
        if ( string1 == null && string2 == null )
 
188
        {
 
189
            return 0;
 
190
        }
 
191
        
 
192
        if ( string1 == null )
 
193
        {
 
194
            return -1;
 
195
        }
 
196
        
 
197
        if ( string2 == null )
 
198
        {
 
199
            return 1;
 
200
        }
 
201
        
 
202
        return string1.compareTo( string2 );
 
203
    }
 
204
}