### Question:
Status implements Serializable { public boolean equals(Object object) { if (!(object instanceof Status)) { return false; } return ((Status) object).intValue == intValue; } private  Status(int intValue, String name); String toString(); static Status convertIntToStatus(int statusAsInt); int intValue(); boolean equals(Object object); boolean equals(Status status); int hashCode(); static final Status STATUS_UNINITIALISED; static final Status STATUS_ALIVE; static final Status STATUS_SHUTDOWN; }### Answer:
@Test public void testEqualsPerformance() { StopWatch stopWatch = new StopWatch(); stopWatch.getElapsedTime(); Status status2 = Status.STATUS_SHUTDOWN; for (int i = 0; i < 10000; i++) { status1.equals(status2); } stopWatch.getElapsedTime(); for (int i = 0; i < 10000; i++) { status1.equals(status2); } long statusCompareTime = stopWatch.getElapsedTime(); LOG.log(Level.INFO, "Time to do equals(Status): " + statusCompareTime); assertTrue("Status compare is greater than permitted time", statusCompareTime < 35); }
@Test public void testObjectEqualsPerformance() { StopWatch stopWatch = new StopWatch(); stopWatch.getElapsedTime(); Object object = new Object(); for (int i = 0; i < 10000; i++) { status1.equals(object); } stopWatch.getElapsedTime(); for (int i = 0; i < 10000; i++) { status1.equals(object); } long objectCompareTime = stopWatch.getElapsedTime(); LOG.log(Level.INFO, "Time to do equals(Object): " + objectCompareTime); assertTrue("Status compare is greater than permitted time", objectCompareTime < 25); }
@Test public void testEqualsPerformance() { StopWatch stopWatch = new StopWatch(); stopWatch.getElapsedTime(); Status status2 = Status.STATUS_SHUTDOWN; for (int i = 0; i < 10000; i++) { status1.equals(status2); } stopWatch.getElapsedTime(); for (int i = 0; i < 10000; i++) { status1.equals(status2); } long statusCompareTime = stopWatch.getElapsedTime(); LOG.info("Time to do equals(Status): " + statusCompareTime); assertTrue("Status compare is greater than permitted time", statusCompareTime < 35); }
@Test public void testObjectEqualsPerformance() { StopWatch stopWatch = new StopWatch(); stopWatch.getElapsedTime(); Object object = new Object(); for (int i = 0; i < 10000; i++) { status1.equals(object); } stopWatch.getElapsedTime(); for (int i = 0; i < 10000; i++) { status1.equals(object); } long objectCompareTime = stopWatch.getElapsedTime(); LOG.info("Time to do equals(Object): " + objectCompareTime); assertTrue("Status compare is greater than permitted time", objectCompareTime < 25); }