Last active
August 1, 2016 18:13
-
-
Save stemmlerjs/7766d7a2d13273d38b92 to your computer and use it in GitHub Desktop.
What are GitHub Gist's for anyways?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Hashtable[] groupLinkedResources(Hashtable resourceLines, int resCount){ | |
| LinkedList list = new LinkedList(); | |
| //Put Resources Into Linked Structure | |
| for(int i = 0; i < resCount; i++){ | |
| Hashtable resource = (Hashtable) resourceLines.get("" + i); | |
| String group = JIC.cvtStr(resource.get("RSRC_PARENT")); | |
| String name = JIC.cvtStr(resource.get("RSRC")); | |
| int groupExistsPosition = searchLinkedResourceHead(list, group); | |
| if(groupExistsPosition == -1){ //Group not already added, add group to list | |
| LinkedList col = new LinkedList(); | |
| if(name.equals(group)){ | |
| col.addLast(resource); | |
| list.addLast(col); | |
| } else { | |
| //If name is not equal to group (ie: the group is not also an employee) | |
| Hashtable groupResTemp = new Hashtable(resource); | |
| groupResTemp.put("RSRC", group); //set the name to be the group | |
| col.addLast(groupResTemp); | |
| col.addLast(resource); | |
| list.addLast(col); | |
| } | |
| } else { // Group already added, add to list in position | |
| LinkedList col = (LinkedList) list.get(groupExistsPosition); | |
| col.addLast(resource); | |
| } | |
| } | |
| //Find the Crew Start and End Time for each crew + Build the XML | |
| for(int i = 0; i < list.size(); i++){ //Iterate through list | |
| LinkedList col = (LinkedList) list.get(i); | |
| String earliestStartDateTime = ""; | |
| String latestEndDateTime = ""; | |
| String linkedResourceLinesXML = ""; | |
| for(int j = 0; j < col.size(); j++){ //iterate through column | |
| Hashtable resource = (Hashtable) col.get(j); | |
| String name = JIC.cvtStr(resource.get("RSRC")); | |
| String start = "Start: " + JIC.cvtStr(resource.get("RSRC_START_DATE")) + ", " + JIC.cvtStr(resource.get("RSRC_START_TIME")); | |
| String end = "End: " + JIC.cvtStr(resource.get("RSRC_END_DATE")) + ", " + JIC.cvtStr(resource.get("RSRC_END_TIME")); | |
| //Compare Start Time | |
| if((earliestStartDateTime.equals("")) || (earliestStartDateTime.compareTo(start) == 0)){ | |
| earliestStartDateTime = start; | |
| } else if(start.compareTo(earliestStartDateTime) < 0){ | |
| earliestStartDateTime = start; | |
| } | |
| //Compare End Time | |
| if((latestEndDateTime.equals("")) || (latestEndDateTime.compareTo(end) == 0)){ | |
| latestEndDateTime = end; | |
| } else if(end.compareTo(latestEndDateTime) > 0){ | |
| latestEndDateTime = end; | |
| } | |
| if(j != 0){ | |
| linkedResourceLinesXML += "<LINKED>" + name + ", " + start + ", " + end + "</LINKED>"; | |
| } | |
| } | |
| //Set the EARLIERST start and LATEST end dates for this group (add to Hashtable) | |
| Hashtable oldGroupHeaderHash = new Hashtable((Hashtable) col.getFirst()); | |
| String groupName = JIC.cvtStr(oldGroupHeaderHash.get("RSRC_PARENT")); | |
| String line1ResourceXML = "<LINE1>" + groupName + ", " + earliestStartDateTime + ", " + latestEndDateTime + "</LINE1>"; | |
| line1ResourceXML += linkedResourceLinesXML; | |
| oldGroupHeaderHash.put("LINESRSRC", line1ResourceXML); | |
| //Add the new Hashtable | |
| col.set(0, oldGroupHeaderHash); | |
| list.set(i, col); | |
| } | |
| Hashtable [] groupReturn = new Hashtable[list.size()]; | |
| for(int i = 0; i < list.size(); i++){ | |
| LinkedList col = (LinkedList) list.get(i); | |
| groupReturn[i] = (Hashtable) col.getFirst(); | |
| } | |
| return groupReturn; | |
| } | |
| private int searchLinkedResourceHead(LinkedList list, String groupName) { | |
| ListIterator iterator = list.listIterator(); | |
| int position = 0; | |
| while(iterator.hasNext()){ | |
| LinkedList col = (LinkedList) iterator.next(); | |
| Hashtable resourceElement = (Hashtable) col.getFirst(); | |
| String elementResourceName = JIC.cvtStr(resourceElement.get("RSRC_PARENT")); | |
| if(elementResourceName.equals(groupName)){ | |
| return position; | |
| } | |
| position++; | |
| } | |
| return -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment