Created
November 20, 2012 02:21
-
-
Save eLafo/4115530 to your computer and use it in GitHub Desktop.
This file contains 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 class Court{ | |
private boolean[7*15] timeTable; | |
public Court(){ | |
java.util.Arrays.fill(this.timeTable,true); | |
} | |
public boolean available(DateTime d, int duration){ | |
if !validDateTime(d) || !validDateTime(d + duration){ | |
// throw exception | |
} | |
available = true; | |
hour = dateTimeToIndex(d); | |
while available && duration > 0 { | |
available = timeTable[hour]; | |
hour++ | |
duration-- | |
} | |
return available | |
} | |
public void book(DateTime d, int duration){ | |
if available(d, duration){ | |
hour = dateTimeToIndex(d); | |
for(i = 0; i <= duration; i++){ | |
// throw an exception if !timeTable[hour] | |
timeTable[hour] = false; | |
hour++ | |
} | |
} | |
} | |
private boolean validDateTime(DateTime d){ | |
return d.get(Calendar.HOUR_OF_DAY) < 9 || d.get(Calendar.HOUR_OF_DAY) > 23 | |
} | |
private int getDayNumber(DateTime d){ | |
// we want Monday to be the first day of the week | |
return d.get(Calendar.DAY_OF_WEEK) + 6 % 7 | |
} | |
private int getHourNumber(DateTime d){ | |
return d.get(Calendar.HOUR_OF_DAY) - 9 | |
} | |
private int dateTimeToIndex(DateTime d){ | |
return 15 * getDayNumber(d) + getHourNumber(d) | |
} | |
} |
This file contains 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 class PaddleClub { | |
private String nameClub; | |
private String paddleClubId; | |
private String areaId; | |
private int numOfCourts; | |
private ArrayList<Court> courts; | |
/** | |
* Constructor con dos parámetros. | |
* @param paddleClubId identificador único del club | |
* @param name nombre del club de paddle | |
*/ | |
public PaddleClub (String paddleClubId, String nameClub, String areaId, int numOfCourts){ | |
this.paddleClubId = paddleClubId; | |
this.nameClub = nameClub; | |
this.areaId = areaId; | |
this.numOfCourts = numOfCourts; | |
java.util.Arrays.fill(this.courts,new Court); | |
} | |
public int courtAvailable(Calendar dateTime, int duration){ | |
index = this.courts.size - 1; | |
available = false; | |
while(index >= 0 && !available){ | |
available = courts[index]; | |
index-- | |
} | |
return index | |
} | |
public int bookCourt(Calendar dateTime, int duration){ | |
available = courtAvailable(dateTime, duration); | |
// throw exception if available < 0 | |
this.courts[available].book | |
return available | |
} | |
/** | |
* Actualiza el nombre del club de paddle. | |
* @param paddleClub objeto con el nuevo nombre | |
*/ | |
public void actualiza(PaddleClub paddleClub) | |
{ | |
nameClub = paddleClub.nameClub; | |
} | |
/** | |
* Sobrescribe el método Object.equals(Object o) para considerar | |
* equivalentes dos objetos de la clase cuando tienen el mismo identificador. | |
* @param área objeto de la misma clase | |
* @return cierto, si el objeto recibido es de la misma clase y | |
* tiene el mismo identificador; falso, en otro caso | |
*/ | |
public boolean equals(Object paddleClub) | |
{ | |
boolean result = false; | |
if ( paddleClub != null && paddleClub instanceof Area ) | |
result = paddleClubId.equals(((PaddleClub)paddleClub).paddleClubId); | |
return result; | |
} | |
/** | |
* Método que redefine la conversión del objeto a String. | |
* @return cadena de caracteres con las datos del área. | |
*/ | |
public String toString() | |
{ | |
final String LS = System.getProperty("line.separator"); | |
StringBuffer result = new StringBuffer(); | |
result.append("IdClub: " + paddleClubId + LS); | |
result.append("nombre: " + nameClub + LS + LS); | |
/**result.append("videos: " + LS); | |
for (Iterador it = videosCategoria.elementos(); it.haySiguiente(); ) | |
{ | |
result.append(it.siguiente() + LS); | |
}*/ | |
return result.toString(); | |
} | |
private void _bookCourts(Calendar dateTime, int[] courtsIndexes){ | |
//for each courtsIndexes as court | |
court.book(dateTime) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment