Implematation of some data structure in Java