} // inSlot /*************************************************************************/ /** * Compares its two arguments for order. Returns a negative integer, * zero, or a positive integer as the first argument is less than, equal * to, or greater than the second. * * @param obj the first object to be compared. * @param o2 the second object to be compared. * @return a negative integer, zero, or a positive integer as the * first argument is less than, equal to, or greater than the * second. * @throws ClassCastException if the arguments' types prevent them from * being compared by this Comparator. */ public int CompareTo(Object obj) { MAssignmentSlot slot = (MAssignmentSlot)obj; // Start Date int result = GetStartTime().Value.CompareTo(slot.GetStartTime()); if (result != 0) { return(result); } // Status result = slot.GetStatus() - GetStatus(); if (result != 0) { return(result); } // End Date result = GetEndTime().Value.CompareTo(slot.GetEndTime()); if (result != 0) { return(result); } // Name result = GetName().CompareTo(slot.GetName()); if (result != 0) { return(result); } // Description return(GetDescription().CompareTo(slot.GetDescription())); } // compare
} // compare /** * Indicates whether some other object is "equal to" this * Comparator. * @param obj the reference object with which to compare. * @return <code>true</code> only if the specified object is also * a comparator and it imposes the same ordering as this * comparator. * @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#hashCode() */ public override bool Equals(Object obj) { if (obj is MAssignmentSlot) { MAssignmentSlot cmp = (MAssignmentSlot)obj; if (_startTime.Equals(cmp.GetStartTime()) && _endTime.Equals(cmp.GetEndTime()) && _status == cmp.GetStatus() && _name.Equals(cmp.GetName()) && _description.Equals(cmp.GetDescription())) { return(true); } } return(false); } // equals
} // getAssignmentSlots /** * Copy valid Slots of a day from list to clear and layout * @param list list with slos of the day * @param clean list with only valid slots */ //@SuppressWarnings("unchecked") private void LayoutSlots(List <MAssignmentSlot> list, List <MAssignmentSlot> clean) { int size = list.Count; // System.out.println("Start List=" + size + ", Clean=" + clean.size()); if (size == 0) { return; } else if (size == 1) { MAssignmentSlot mas = (MAssignmentSlot)list[0]; LayoutY(mas); clean.Add(mas); return; } // Delete Unavailability TimeSlots when all day assigments exist bool allDay = false; for (int i = 0; !allDay && i < size; i++) { MAssignmentSlot mas = (MAssignmentSlot)list[i]; if (mas.GetStatus() == MAssignmentSlot.STATUS_NotAvailable || mas.GetStatus() == MAssignmentSlot.STATUS_UnAvailable || mas.GetStatus() == MAssignmentSlot.STATUS_NonBusinessDay || mas.GetStatus() == MAssignmentSlot.STATUS_NotInSlotDay) { allDay = true; } } if (allDay) { // delete Time Slot for (int i = 0; i < list.Count; i++) { MAssignmentSlot mas = (MAssignmentSlot)list[i]; if (mas.GetStatus() == MAssignmentSlot.STATUS_NotInSlotTime) { list.RemoveAt(i--); } } } // Copy & Y layout remaining for (int i = 0; i < list.Count; i++) { MAssignmentSlot mas = (MAssignmentSlot)list[i]; LayoutY(mas); clean.Add(mas); } // X layout int maxYslots = _timeSlots.Length; int[] xSlots = new int[maxYslots]; // number of parallel slots for (int i = 0; i < list.Count; i++) { MAssignmentSlot mas = (MAssignmentSlot)list[i]; for (int y = mas.GetYStart(); y < mas.GetYEnd(); y++) { xSlots[y]++; } } // Max parallel X Slots int maxXslots = 0; for (int y = 0; y < xSlots.Length; y++) { if (xSlots[y] > maxXslots) { maxXslots = xSlots[y]; } } // Only one column if (maxXslots < 2) { for (int i = 0; i < list.Count; i++) { MAssignmentSlot mas = (MAssignmentSlot)list[i]; mas.SetX(0, 1); } return; } //// Create xy Matrix //Array [][] arr = new Array(); //Array[][] matrix = new Array [maxXslots][maxYslots]; //// Populate Matrix first column //for (int y = 0; y < maxYslots; y++) //{ // ArrayList<Object> xyList = new ArrayList<Object>(); // matrix[0][y] = xyList; // // see if one assignment fits into slot // for (int i = 0; i < list.size(); i++) // { // MAssignmentSlot mas = (MAssignmentSlot)list.get(i); // if (y >= mas.getYStart() && y <= mas.getYEnd()) // xyList.add(mas); // } // // initiate right columns // for (int x = 1; x < maxXslots; x++) // matrix[x][y] = new ArrayList<Object>(); //} // for all y slots ///** // * (AB)() -> (B)(A) -> (B)(A) // * (BC)() -> (BC)() -> (B)(C) // * - if the row above is empty, move the first one right // * - else - check col_1..x above and move any content if the same // * - if size > 0 // * - if the element is is not the same as above, // * move to the first empty column on the right // */ //// if in one column cell, there is more than one, move it to the right //for (int y = 0; y < maxYslots; y++) //{ // // if an element is the same as the line above, move it there // if (y > 0 && matrix[0][y].size() > 0) // { // for (int x = 1; x < maxXslots; x++) // { // if (matrix[x][y-1].size() > 0) // above slot is not empty // { // Object above = matrix[x][y-1].get(0); // for (int i = 0; i < matrix[x][y].size(); i++) // { // if (above.equals(matrix[0][y].get(i))) // same - move it // { // matrix[x][y].add(matrix[0][y].get(i)); // matrix[0][y].remove(i--); // } // } // } // } // } // if an element is the same as the line above, move it there // // we need to move items to the right // if (matrix[0][y].size() > 1) // { // Object above = null; // if (y > 0 && matrix[0][y-1].size() > 0) // above = matrix[0][y-1].get(0); // // // for (int i = 0; matrix[0][y].size() > 1; i++) // { // Object move = matrix[0][y].get(i); // if (!move.equals(above)) // we can move it // { // for (int x = 1; move != null && x < maxXslots; x++) // { // if (matrix[x][y].size() == 0) // found an empty slot // { // matrix[x][y].add(move); // matrix[0][y].remove(i--); // move = null; // } // } // } // } // } // we need to move items to the right //} // for all y slots //// go through the matrix and assign the X position //for (int y = 0; y < maxYslots; y++) //{ // for (int x = 0; x < maxXslots; x++) // { // if (matrix[x][y].size() > 0) // { // MAssignmentSlot mas = (MAssignmentSlot)matrix[x][y].get(0); // mas.setX(x, xSlots[y]); // } // } //} // clean up //matrix = null; } // layoutSlots