-
Notifications
You must be signed in to change notification settings - Fork 1
/
Conjunto.java
132 lines (112 loc) · 2.78 KB
/
Conjunto.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
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
public class Conjunto implements Data, VLS, VLSM{
public LinkedHashSet<Data> set;
public Conjunto() {
set = new LinkedHashSet<>();
}
@Override
public double suma() {
double n=0;
for(Data x:set)
n+=Double.parseDouble(x.toString());
return n;
}
@Override
public double restar() {
double n=Double.parseDouble(functionfirst().toString());
double aux=n;
for(Data x:set)
n-=Double.parseDouble(x.toString());
return n+aux;
}
@Override
public double multiplicar() {
double n=1;
for(Data x:set)
n*=Double.parseDouble(x.toString());
return n;
}
@Override
public double dividir() {
double n=Double.parseDouble(functionfirst().toString());
double aux=n;
for(Data x:set)
n/=Double.parseDouble(x.toString());
return n*aux;
}
public void addData(Data data){
set.add(data);
}
public void addDataLista(Data data){
set.add(data);
}
public Object getData(){
return set;
}
public void setData(Object l) {
set = ((LinkedHashSet<Data>) (l));
}
@Override
public Data functionfirst() {
return functionget(new Numero(1),null);
}
@Override
public Data functionget(Data element, Data defecto) {
int n=0;
if (defecto!=null)
return defecto;
if (set.size()>Double.parseDouble(element.toString()))
for(Data x:set) {
n++;
if (n == (int)Double.parseDouble(element.toString())) {
return x;
}
}
return new Nil();
}
@Override
public String toString() {
return set.toString();
}
public Boolean contains( Data element){
for (Data x:set){
if(x.equals(element))
return true;
}
return false;
}
@Override
public boolean equals(Object o) {
if(!(o instanceof Conjunto))
return false;
boolean flag = true;
Conjunto aux = ((Conjunto) o);
for(Data i : aux.set){
if(!aux.set.contains(i)){
return false;
}
}
return true;
}
@Override
public int hashCode() {
return set.hashCode();
}
@Override
public List<Data> copyData() {
ArrayList<Data> a = new ArrayList<>();
for(Data data: set)
a.add(data);
return a;
}
@Override
public Object clone() {
try {
return super.clone();
} catch (Exception e){
return null;
}
}
}