forked from powerdata/com.powerdata.openpa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractBaseObject.java
98 lines (83 loc) · 1.56 KB
/
AbstractBaseObject.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.powerdata.openpa;
/**
* Starting point of the base object hierarchy
*
* @author [email protected]
*
*/
public class AbstractBaseObject implements BaseObject
{
protected int _ndx;
protected BaseList<? extends BaseObject> _list;
public static final BaseObject Null = new AbstractBaseObject(null, -1)
{
@Override
public String toString()
{
return "Null";
}
};
public AbstractBaseObject(BaseList<? extends BaseObject> list, int ndx)
{
_list = list;
_ndx = ndx;
}
@Override
public int getIndex()
{
return _list.getIndex(_ndx);
}
@Override
public int getKey()
{
return _list.getKey(_ndx);
}
@Override
public String getID() throws PAModelException
{
return _list.getID(_ndx);
}
@Override
public void setID(String id) throws PAModelException
{
_list.setID(_ndx, id);
}
@Override
public String getName() throws PAModelException
{
return _list.getName(_ndx);
}
@Override
public void setName(String name) throws PAModelException
{
_list.setName(_ndx, name);
}
@Override
public String toString()
{
if (_ndx == -1) return "Null";
StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append(' ');
try
{
return sb.append(getName()).append(' ').append(getID()).toString();
} catch (Exception e)
{
return sb.append(_ndx).toString();
}
}
@Override
public BaseList<? extends BaseObject> getList()
{
return _list;
}
@Override
public boolean equals(Object obj)
{
return _list.objEquals(_ndx, obj);
}
@Override
public int hashCode()
{
return _list.objHash(_ndx);
}
}