I have been trying to understand what is going on in this piece of Java code, but so far I didn't manage. This is part of this library .
My wonders are on
CURRENT_SIM_TIME(Constants.VAR_TIME_STEP), NET_BOUNDARIES(Constants.VAR_NET_BOUNDING_BOX)
They do not appear previously in the code and later on, there is one constructor which uses CURRENT_SIM_TIME
without any brackets ()
.
enum Variable {
CURRENT_SIM_TIME(Constants.VAR_TIME_STEP), NET_BOUNDARIES(
Constants.VAR_NET_BOUNDING_BOX), ;
public final int id;
private Variable(int id) {
this.id = id;
}
}
This the constructor I was talking about:
SimulationData(DataInputStream dis, DataOutputStream dos) {
super("", Variable.class);
addReadQuery(Variable.CURRENT_SIM_TIME,
new ReadObjectVarQuery.IntegerQ(dis, dos,
Constants.CMD_GET_SIM_VARIABLE, "",
Variable.CURRENT_SIM_TIME.id) {
});
addReadQuery(Variable.NET_BOUNDARIES,
new ReadObjectVarQuery.BoundingBoxQ(dis, dos,
Constants.CMD_GET_SIM_VARIABLE, "",
Variable.NET_BOUNDARIES.id));
this.dis = dis;
this.dos = dos;
}
So, how is this possible?
Inside the enum Variable we have CURRENT_SIM_TIME
and NET_BOUNDARIES
with an argument inside the brackets and then in the constructor we create an addReadQuery
with Variable.CURRENT_SIM_TIME
as well as Variable.NET_BOUNDARIES
, without brackets as an argument.
Are these functions? Static variables? Are they be defined in some other part of the code and I am not able to find them?
I am really lost right now...