Im trying to make a class which will be kind of data base. Here is a code:
public class DataFrame {
public HashMap<String, ArrayList<?>> data;
public String[] nazwy;
public String[] typy;
public DataFrame(String[] _nazwy, String[] _typy) {
data = new HashMap<String, ArrayList<?>>();
nazwy = new String[_nazwy.length];
typy = new String[_typy.length];
for(int i = 0; i < _nazwy.length; i++) {
nazwy[i] = _nazwy[i];
typy[i] = _typy[i];
ArrayList<?> kolumna = new ArrayList<>();
data.put(_nazwy[i], kolumna);
}
}
public int size() {
return data.size();
}
public ArrayList get(String kolname) {
return data.get(kolname);
}
public DataFrame get(String [] kols, boolean copy) { // shallow and deep
int size = kols.length;
String[] _typy = new String[size]; // naprawic typy
int i = 0;
int j = 0;
for(String kol : kols) {
if(kol == typy[i]) {
_typy[j] += typy[i];
j++;
}
i++;
}
if(copy) {
DataFrame temp = new DataFrame(kols, _typy);
for(String kol : kols) {
if(data.containsKey(kol))
temp.data.put(kol, data.get(kol));
}
return temp;
}
else {
DataFrame temp = new DataFrame(kols, _typy);
for(String kol : kols) {
if(data.containsKey(kol))
temp.data.clone();
}
return temp;
}
}
}
I made constructor, size() and get(column). It's working fine(Ive tested it). I also tried to make a deep copy and I think its working, but I have no idea how to make a shallow one which will have only listed columns. I found clone() method but it's not working :(
public DataFrame get(String [] kols, boolean copy) { // shallow and deep
int size = kols.length;
String[] _typy = new String[size]; // naprawic typy
int i = 0;
int j = 0;
for(String kol : kols) {
if(kol == typy[i]) {
_typy[j] += typy[i];
j++;
}
i++;
}
if(copy) {
DataFrame temp = new DataFrame(kols, _typy);
for(String kol : kols) {
temp.data.put(kol, data.get(kol));
}
return temp;
}
else {
DataFrame temp = new DataFrame(kols, _typy);
temp.data = data;
Set<String> set = new HashSet<String>();
for(int k=0; k<kols.length; ++k)
set.add(kols[k]);
temp.data.keySet().retainAll(set);
return temp;
}
}
i made it like this. When im checking objects it returns false in shallowcopy and true when doing deep