0

I have an ArrayList "Weekly Payroll" that contains a week worth of shift details (monday through sunday) the shift details are also an ArrayList which contains the list of employees worked that day.

Now I have to compute weekly payroll based on the variables which the Employee class contains.

My question is (and hopefully I'm being clear): is there a way to go through cascading Collections to reach a specific object by defining a path like XPath for XML?

Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62
davedno
  • 349
  • 1
  • 5
  • 15
  • 1
    [Ways to iterate over a List in java?](http://stackoverflow.com/q/18410035) – Tom Mar 11 '15 at 23:41
  • I'm sorry Tom but that in no way helps me, I'm aware of the basics – davedno Mar 11 '15 at 23:44
  • 1
    So what is your question? – Tom Mar 11 '15 at 23:45
  • Do you thin of a syntax for querying those specific objects? Like `payrollList("PayrollWeek2").employeeList("Hans Wurst"), according to XPath (for XML ) http://stackoverflow.com/questions/2811001/how-to-read-xml-using-xpath-in-java? – Marvin Emil Brach Mar 11 '15 at 23:46
  • Yes, assume I have all the correct methods for grabing information, I just need to go into an array list through the subclass array list which contains information about a superclass Employee that I need to modify. – davedno Mar 11 '15 at 23:48
  • The chain is : Weekly shifts array list - > shift array list - > employee class which has variables like weekly pay year hire ect... How can I successfully go down that chain and access and mutate those variables – davedno Mar 11 '15 at 23:49
  • There is no ability of the language for that purpose. Either you have to arrange the data in XML and use XPath (or something equally) or you have to implement that funtion by yourself; defining a function with params for the `ArrayList` and a `String` defining your path. But this funtion will do the same cascaded `for` loops. – Marvin Emil Brach Mar 11 '15 at 23:52

1 Answers1

1

If you're thinking of a syntax for querying those specific objects like payroll("Week.2").employees("Hans Wurst") or /payroll/week/2/employees/hans wurst/, according to XPath (for XML – How to read XML using XPath in Java), then I have to say:

No, there is no ability of the language for that purpose.
Either you have to arrange the data in XML and use XPath (or something equally) or you have to implement that function by yourself:
Define a function with parameters passing the list and a String defining your path. But this function at least will do the same cascaded for-loops you've already rejected.

Community
  • 1
  • 1
Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62