-
Notifications
You must be signed in to change notification settings - Fork 1
/
Element.java
134 lines (115 loc) · 1.98 KB
/
Element.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import java.util.HashSet;
public class Element
{
HashSet<Integer> upShadow;
HashSet<Integer> downShadow;
int id;
Element(int i)
{
upShadow = new HashSet<Integer>();
downShadow = new HashSet<Integer>();
id = i;
}
Element(int i, HashSet<Integer> u, HashSet<Integer> d)
{
upShadow = u;
downShadow = d;
id = i;
}
public Element hardCopy(int ident)
{
Element copy = new Element(ident);
for(int i : upShadow)
{
copy.newGreater(i);
}
for(int i : downShadow)
{
copy.newSmaller(i);
}
return copy;
}
public void deleteGreater(Integer g)
{
upShadow.remove(g);
}
public void deleteSmaller(Integer s)
{
downShadow.remove(s);
}
void newSmaller(Integer i)
{
downShadow.add(i);
}
void newGreater(Integer i)
{
upShadow.add(i);
}
int getID()
{
return id;
}
HashSet<Integer> getUpShadow()
{
return upShadow;
}
HashSet<Integer> getDownShadow()
{
return downShadow;
}
boolean isMinumum()
{
//System.out.println(downShadow.isEmpty());
if(downShadow.isEmpty()) return true;
else return false;
}
boolean isMaximum()
{
if(upShadow.isEmpty()) return true;
else return false;
}
public Element copy()
{
HashSet<Integer> u = new HashSet<Integer>();
HashSet<Integer> d = new HashSet<Integer>();
for(int i : upShadow)
{
u.add(i);
}
for(int i : downShadow)
{
d.add(i);
}
return new Element(this.getID(),u,d);
}
public Element copy(int offset)
{
HashSet<Integer> u = new HashSet<Integer>();
HashSet<Integer> d = new HashSet<Integer>();
for(int i : upShadow)
{
u.add(i+offset);
}
for(int i : downShadow)
{
d.add(i+offset);
}
return new Element(this.getID()+offset,u,d);
}
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[");
for(Integer i : downShadow)
{
str.append(i+",");
}
str.append("]->"+this.getID()+"->[");
for(Integer i : upShadow)
{
str.append(i+",");
}
str.append("]");
return str.toString();
}
}