Author: ivaynberg
Date: Fri May 30 09:46:55 2008
New Revision: 661789
URL: http://svn.apache.org/viewvc?rev=661789&view=rev
Log:
WICKET-1669
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
(with props)
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/time/TimeFrame.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/time/TimeFrame.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/time/TimeFrame.java?rev=661789&r1=661788&r2=661789&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/time/TimeFrame.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/time/TimeFrame.java
Fri May 30 09:46:55 2008
@@ -16,6 +16,8 @@
*/
package org.apache.wicket.util.time;
+import org.apache.wicket.util.lang.Objects;
+
/**
* Immutable class which represents an interval of time with a beginning and
an end. The beginning
* value is inclusive and the end value is exclusive. In other words, the time
frame of 1pm to 2pm
@@ -63,7 +65,7 @@
* <code>TimeFrame</code> each day
*/
public static ITimeFrameSource eachDay(final TimeOfDay startTimeOfDay,
- final TimeOfDay endTimeOfDay)
+ final TimeOfDay endTimeOfDay)
{
check(startTimeOfDay, endTimeOfDay);
@@ -125,7 +127,7 @@
if (end.lessThan(start))
{
throw new IllegalArgumentException("Start time of time
frame " + start +
- " was after end time " + end);
+ " was after end time " + end);
}
}
@@ -209,7 +211,32 @@
public boolean overlaps(final TimeFrame timeframe)
{
return contains(timeframe.start) || contains(timeframe.end) ||
timeframe.contains(start) ||
- timeframe.contains(end);
+ timeframe.contains(end);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hashCode(start, end);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ TimeFrame other = (TimeFrame)obj;
+ return Objects.equal(start, other.start) && Objects.equal(end,
other.end);
}
/**
@@ -217,6 +244,7 @@
*
* @return a <code>String</code> representation of this object
*/
+ @Override
public String toString()
{
return "[start=" + start + ", end=" + end + "]";
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java?rev=661789&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
Fri May 30 09:46:55 2008
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.time;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author v857829
+ */
+public class TimeFrameTest extends TestCase
+{
+
+ private final TimeOfDay three = TimeOfDay.time(3, 0, TimeOfDay.PM);
+ private final TimeOfDay four = TimeOfDay.time(4, 0, TimeOfDay.PM);
+ private final TimeOfDay five = TimeOfDay.time(5, 0, TimeOfDay.PM);
+
+ /**
+ * Test method for
+ * [EMAIL PROTECTED]
org.apache.wicket.util.time.TimeFrame#eachDay(org.apache.wicket.util.time.TimeOfDay,
org.apache.wicket.util.time.TimeOfDay)}.
+ */
+ public void testEachDay()
+ {
+ ITimeFrameSource test = TimeFrame.eachDay(three, five);
+
Assert.assertTrue(test.getTimeFrame().contains(Time.valueOf(four)));
+ }
+
+ /**
+ * Test method for
+ * [EMAIL PROTECTED]
org.apache.wicket.util.time.TimeFrame#valueOf(org.apache.wicket.util.time.Time,
org.apache.wicket.util.time.Duration)}.
+ */
+ public void testValueOfTimeDuration()
+ {
+ TimeFrame test = TimeFrame.valueOf(Time.valueOf(three),
Duration.minutes(60));
+ Assert.assertEquals(test.getStart(), Time.valueOf(three));
+ Assert.assertEquals(test.getEnd(), Time.valueOf(four));
+ }
+
+ /**
+ * Test method for
+ * [EMAIL PROTECTED]
org.apache.wicket.util.time.TimeFrame#contains(org.apache.wicket.util.time.Time)}.
+ */
+ public void testContains()
+ {
+ TimeFrame test = TimeFrame.valueOf(Time.valueOf(three),
Duration.minutes(70));
+ Assert.assertTrue(test.contains(Time.valueOf(four)));
+ }
+
+ /**
+ * Test method for
+ * [EMAIL PROTECTED]
org.apache.wicket.util.time.TimeFrame#overlaps(org.apache.wicket.util.time.TimeFrame)}.
+ */
+ public void testOverlaps()
+ {
+ TimeFrame test = TimeFrame.valueOf(Time.valueOf(three),
Duration.minutes(70));
+ TimeFrame test2 = TimeFrame.valueOf(Time.valueOf(four),
Duration.minutes(50));
+ TimeFrame test3 = TimeFrame.valueOf(Time.valueOf(four),
Time.valueOf(five));
+ TimeFrame test4 = TimeFrame.valueOf(Time.valueOf(three),
Duration.minutes(20));
+ Assert.assertTrue(test.overlaps(test2));
+ Assert.assertTrue(test3.overlaps(test2));
+ Assert.assertTrue(test.overlaps(test3));
+ Assert.assertFalse(test4.overlaps(test3));
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.wicket.util.time.TimeFrame#equals(java.lang.Object)}.
+ */
+ public void testEquals()
+ {
+ TimeFrame test = TimeFrame.valueOf(Time.valueOf(three),
Duration.minutes(60));
+ TimeFrame test2 = TimeFrame.valueOf(Time.valueOf(three),
Time.valueOf(four));
+ TimeFrame test3 = TimeFrame.valueOf(Time.valueOf(three),
Duration.minutes(59));
+ Assert.assertEquals(test, test2);
+ Assert.assertNotSame(test2, test3);
+ }
+
+}
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain