/* * Created on Jun 23, 2004 * */ package net.sourceforge.fenixedu.util; import java.io.Serializable; import java.util.ArrayList; import java.util.List; public class EntryPhase implements Serializable, Comparable { public static final int FIRST_PHASE = 1; public static final int SECOND_PHASE = 2; public static final String FIRST_PHASE_STRING = "1ª Fase"; public static final String SECOND_PHASE_STRING = "2ª Fase"; public static final EntryPhase FIRST_PHASE_OBJ = new EntryPhase(EntryPhase.FIRST_PHASE); public static final EntryPhase SECOND_PHASE_OBJ = new EntryPhase(EntryPhase.SECOND_PHASE); private final Integer entryPhase; public EntryPhase(int entryPhase) { this.entryPhase = Integer.valueOf(entryPhase); } public EntryPhase(Integer entryPhase) { this.entryPhase = entryPhase; } public EntryPhase(String entryPhase) { if (entryPhase.equals(EntryPhase.FIRST_PHASE_STRING)) { this.entryPhase = Integer.valueOf(EntryPhase.FIRST_PHASE); } else if (entryPhase.equals(EntryPhase.SECOND_PHASE_STRING)) { this.entryPhase = Integer.valueOf(EntryPhase.SECOND_PHASE); } else throw new UnsupportedOperationException(); } public Integer getEntryPhase() { return entryPhase; } @Override public String toString() { switch (entryPhase.intValue()) { case FIRST_PHASE: return "FIRST_PHASE"; case SECOND_PHASE: return "SECOND_PHASE"; default: throw new Error("Unknown entry phase value."); } } public static List getAll() { ArrayList result = new ArrayList(); result.add(EntryPhase.FIRST_PHASE_OBJ); result.add(EntryPhase.SECOND_PHASE_OBJ); return result; } public String getName() { if (this.entryPhase.equals(1)) { return EntryPhase.FIRST_PHASE_STRING; } if (this.entryPhase.equals(2)) { return EntryPhase.SECOND_PHASE_STRING; } return null; } @Override public boolean equals(Object obj) { if (obj instanceof EntryPhase) { return ((EntryPhase) obj).getEntryPhase().equals(this.getEntryPhase()); } return false; } public static EntryPhase valueOf(int phase) { switch (phase) { case 1: return FIRST_PHASE_OBJ; case 2: return SECOND_PHASE_OBJ; default: return null; } } public int compareTo(EntryPhase entryPhase) { return this.getEntryPhase().compareTo(entryPhase.getEntryPhase()); } }