You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2019/05/02 13:40:11 UTC
[wicket] 05/15: Decommisioning of wucket-util package
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a commit to branch WICKET-6662
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 55013c7ddf580068e2fde0582e13bd219548f367
Author: Andrea Del Bene <ad...@apache.org>
AuthorDate: Mon Apr 22 18:24:15 2019 +0200
Decommisioning of wucket-util package
---
.../main/java/org/apache/wicket/Application.java | 5 +-
.../src/main/java/org/apache/wicket/Session.java | 6 +-
.../wicket/ajax/AbstractAjaxTimerBehavior.java | 6 +-
.../wicket/ajax/AbstractDefaultAjaxBehavior.java | 13 +-
.../apache/wicket/ajax/AjaxClientInfoBehavior.java | 4 +-
.../wicket/ajax/AjaxSelfUpdatingTimerBehavior.java | 2 +-
.../ajax/attributes/AjaxRequestAttributes.java | 2 +-
.../wicket/ajax/attributes/ThrottlingSettings.java | 2 +-
.../ajax/form/AjaxFormValidatingBehavior.java | 2 +-
.../wicket/application/ReloadingClassLoader.java | 4 +-
.../core/util/resource/PackageResourceStream.java | 5 +-
.../core/util/resource/UrlResourceStream.java | 9 +-
.../util/resource/WebExternalResourceStream.java | 6 +-
.../core/util/watch/Nio2ModificationWatcher.java | 2 +-
.../apache/wicket/markup/MarkupResourceStream.java | 5 +-
.../resource/RenderedDynamicImageResource.java | 5 +-
.../wicket/markup/html/link/DownloadLink.java | 2 +-
.../org/apache/wicket/mock/MockWebRequest.java | 11 +-
.../org/apache/wicket/mock/MockWebResponse.java | 10 +-
.../wicket/page/CouldNotLockPageException.java | 2 +-
.../apache/wicket/page/PageAccessSynchronizer.java | 23 +-
.../org/apache/wicket/page/PartialPageUpdate.java | 6 +-
.../protocol/http/AbstractRequestLogger.java | 6 +-
.../wicket/protocol/http/BufferedWebResponse.java | 6 +-
.../protocol/http/HeaderBufferingWebResponse.java | 5 +-
.../wicket/protocol/http/StoredResponsesMap.java | 17 +-
.../wicket/protocol/http/WebApplication.java | 4 +-
.../protocol/http/servlet/ServletWebRequest.java | 8 +-
.../protocol/http/servlet/ServletWebResponse.java | 8 +-
.../wicket/protocol/http/servlet/UploadInfo.java | 9 +-
.../resource/ResourceStreamRequestHandler.java | 2 +-
.../wicket/request/resource/AbstractResource.java | 27 +-
.../wicket/request/resource/BaseDataResource.java | 6 +-
.../request/resource/DynamicImageResource.java | 11 +-
.../wicket/request/resource/PackageResource.java | 6 +-
.../request/resource/ResourceStreamResource.java | 8 +-
.../version/LastModifiedResourceVersion.java | 7 +-
.../resource/TextTemplateResourceReference.java | 9 +-
.../resource/bundles/ConcatBundleResource.java | 18 +-
.../wicket/settings/RequestCycleSettings.java | 5 +-
.../apache/wicket/settings/ResourceSettings.java | 2 +-
.../apache/wicket/util/cookies/CookieUtils.java | 6 +-
.../util/template/TextTemplateDecorator.java | 7 +-
.../wicket/util/tester/BaseWicketTester.java | 2 +-
.../wicket/ajax/AjaxBehaviorAndMetaDataPage.java | 4 +-
.../apache/wicket/ajax/AjaxRequestHandlerTest.java | 9 +-
.../apache/wicket/ajax/AjaxTimerBehaviorTest.java | 14 +-
.../markup/html/componentMap/SimpleTestPanel.java | 4 +-
.../wicket/page/PageAccessSynchronizerTest.java | 57 +-
.../protocol/http/StoredResponsesMapTest.java | 24 +-
.../http/servlet/WicketSessionFilterTest.java | 6 +-
.../apache/wicket/request/cycle/RerenderPage.java | 5 +-
...nameWithVersionResourceCachingStrategyTest.java | 5 +-
...ringWithVersionResourceCachingStrategyTest.java | 5 +-
.../devutils/pagestore/browser/PersistedPanel.java | 5 +-
.../examples/ServerHostNameAndTimeFilter.java | 7 +-
.../examples/ajax/builtin/AjaxDownloadPage.java | 7 +-
.../wicket/examples/ajax/builtin/ClockPage.java | 5 +-
.../wicket/examples/ajax/builtin/FormPage.java | 4 +-
.../examples/ajax/builtin/LazyLoadingPage.java | 9 +-
.../examples/ajax/builtin/WorldClockPage.java | 6 +-
.../apache/wicket/examples/linkomatic/Home.java | 5 +-
.../examples/resourcedecoration/HomePage.java | 4 +-
.../websocket/WebSocketBehaviorDemoPage.java | 5 +-
.../wicket/http2/markup/head/PushHeaderItem.java | 26 +-
.../ajax/markup/html/AjaxLazyLoadPanel.java | 14 +-
.../ajax/markup/html/AjaxLazyLoadPanelTester.java | 2 +-
.../html/form/upload/UploadStatusResource.java | 5 +-
.../captcha/kittens/KittenCaptchaPanel.java | 8 +-
.../markup/html/captcha/CaptchaImageResource.java | 5 +-
.../image/resource/ThumbnailImageResource.java | 6 +-
.../repeater/data/table/export/ExportToolbar.java | 5 +-
.../wicket/jmx/RequestCycleSettingsMBean.java | 5 +-
.../apache/wicket/jmx/ResourceSettingsMBean.java | 1 -
.../wicket/jmx/wrapper/RequestCycleSettings.java | 10 +-
.../wicket/jmx/wrapper/ResourceSettings.java | 3 +-
.../wicket/protocol/ws/api/WebSocketResponse.java | 6 +-
.../wicket/request/HttpHeaderCollection.java | 19 +-
.../org/apache/wicket/request/http/WebRequest.java | 10 +-
.../apache/wicket/request/http/WebResponse.java | 22 +-
.../wicket/request/HttpHeaderCollectionTest.java | 10 +-
.../java/org/apache/wicket/util/file/File.java | 7 +-
.../java/org/apache/wicket/util/file/Files.java | 7 +-
.../org/apache/wicket/util/io/Connections.java | 7 +-
.../org/apache/wicket/util/lang/Comparators.java} | 35 +-
.../util/resource/AbstractResourceStream.java | 5 +-
.../resource/AbstractResourceStreamWriter.java | 7 +-
.../resource/AbstractStringResourceStream.java | 11 +-
.../wicket/util/resource/FileResourceStream.java | 5 +-
.../util/resource/FileSystemResourceStream.java | 7 +-
.../util/resource/ResourceStreamWrapper.java | 5 +-
.../util/resource/StringBufferResourceStream.java | 6 +-
.../wicket/util/resource/XSLTResourceStream.java | 5 +-
.../wicket/util/resource/ZipResourceStream.java | 5 +-
.../org/apache/wicket/util/string/StringValue.java | 116 ++--
.../java/org/apache/wicket/util/thread/Task.java | 39 +-
.../org/apache/wicket/util/time/AbstractTime.java | 119 ----
.../apache/wicket/util/time/AbstractTimeValue.java | 52 --
.../java/org/apache/wicket/util/time/Duration.java | 553 -------------------
.../org/apache/wicket/util/time/Durations.java | 80 +++
.../time/{ITimeFrameSource.java => Instants.java} | 75 ++-
.../java/org/apache/wicket/util/time/Time.java | 612 ---------------------
.../org/apache/wicket/util/time/TimeFrame.java | 258 ---------
.../java/org/apache/wicket/util/time/TimeMap.java | 108 ----
.../org/apache/wicket/util/time/TimeOfDay.java | 418 --------------
.../wicket/util/value/CopyOnWriteValueMap.java | 19 +-
.../org/apache/wicket/util/value/IValueMap.java | 14 +-
.../org/apache/wicket/util/value/ValueMap.java | 19 +-
.../org/apache/wicket/util/watch/IModifiable.java | 4 +-
.../wicket/util/watch/IModificationWatcher.java | 2 +-
.../wicket/util/watch/ModificationWatcher.java | 13 +-
.../org/apache/wicket/util/io/ConnectionsTest.java | 14 +-
.../apache/wicket/util/io/LastModifiedTest.java | 14 +-
.../apache/wicket/util/string/StringValueTest.java | 23 +-
.../org/apache/wicket/util/time/DurationTest.java | 153 ------
.../org/apache/wicket/util/time/TimeFrameTest.java | 100 ----
.../org/apache/wicket/util/time/TimeMapTest.java | 58 --
.../java/org/apache/wicket/util/time/TimeTest.java | 54 --
.../org/apache/wicket/util/value/ValueMapTest.java | 36 +-
119 files changed, 634 insertions(+), 3089 deletions(-)
diff --git a/wicket-core/src/main/java/org/apache/wicket/Application.java b/wicket-core/src/main/java/org/apache/wicket/Application.java
index 035ee0b..61a3116 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Application.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Application.java
@@ -17,13 +17,13 @@
package org.apache.wicket;
import java.net.URLConnection;
+import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Supplier;
-
import org.apache.wicket.application.ComponentInitializationListenerCollection;
import org.apache.wicket.application.ComponentInstantiationListenerCollection;
import org.apache.wicket.application.ComponentOnAfterRenderListenerCollection;
@@ -91,7 +91,6 @@ import org.apache.wicket.settings.SecuritySettings;
import org.apache.wicket.settings.StoreSettings;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Generics;
-import org.apache.wicket.util.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -281,7 +280,7 @@ public abstract class Application implements UnboundListener, IEventSink, IMetad
switch (getConfigurationType())
{
case DEVELOPMENT : {
- getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
+ getResourceSettings().setResourcePollFrequency(Duration.ofSeconds(1));
getResourceSettings().setJavaScriptCompressor(null);
getResourceSettings().setUseMinifiedResources(false);
getMarkupSettings().setStripWicketTags(false);
diff --git a/wicket-core/src/main/java/org/apache/wicket/Session.java b/wicket-core/src/main/java/org/apache/wicket/Session.java
index 60f5676..a6c395b 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Session.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Session.java
@@ -17,6 +17,7 @@
package org.apache.wicket;
import java.io.Serializable;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -26,7 +27,6 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
-
import org.apache.wicket.application.IClassResolver;
import org.apache.wicket.authorization.IAuthorizationStrategy;
import org.apache.wicket.core.request.ClientInfo;
@@ -38,7 +38,6 @@ import org.apache.wicket.feedback.FeedbackMessages;
import org.apache.wicket.feedback.IFeedbackContributor;
import org.apache.wicket.page.IPageManager;
import org.apache.wicket.page.PageAccessSynchronizer;
-import org.apache.wicket.pageStore.IPageStore;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.session.ISessionStore;
@@ -46,7 +45,6 @@ import org.apache.wicket.util.LazyInitializer;
import org.apache.wicket.util.io.IClusterable;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Objects;
-import org.apache.wicket.util.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -991,7 +989,7 @@ public abstract class Session implements IClusterable, IEventSink, IMetadataCont
}
else
{
- timeout = Duration.minutes(1);
+ timeout = Duration.ofMinutes(1);
log.warn(
"PageAccessSynchronizer created outside of application thread, using default timeout: {}",
timeout);
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
index da947ee..20ea241 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
@@ -16,13 +16,13 @@
*/
package org.apache.wicket.ajax;
+import java.time.Duration;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.OnLoadHeaderItem;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Duration;
import org.danekja.java.util.function.serializable.SerializableConsumer;
/**
@@ -69,7 +69,7 @@ public abstract class AbstractAjaxTimerBehavior extends AbstractDefaultAjaxBehav
*/
protected final void setUpdateInterval(Duration updateInterval)
{
- if (updateInterval == null || updateInterval.getMilliseconds() <= 0)
+ if (updateInterval == null || updateInterval.toMillis() <= 0)
{
throw new IllegalArgumentException("Invalid update interval");
}
@@ -202,7 +202,7 @@ public abstract class AbstractAjaxTimerBehavior extends AbstractDefaultAjaxBehav
headerResponse.render(
OnLoadHeaderItem.forScript(String.format("Wicket.Timer.set('%s', function(){%s}, %d);",
- timerId, js, updateInterval.getMilliseconds())));
+ timerId, js, updateInterval.toMillis())));
}
private void clearTimeout(IHeaderResponse headerResponse)
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
index ae0857f3..291303f 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
@@ -16,11 +16,8 @@
*/
package org.apache.wicket.ajax;
+import java.time.Duration;
import java.util.List;
-
-import com.github.openjson.JSONArray;
-import com.github.openjson.JSONException;
-import com.github.openjson.JSONObject;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.WicketRuntimeException;
@@ -43,7 +40,9 @@ import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.resource.CoreLibrariesContributor;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
+import com.github.openjson.JSONArray;
+import com.github.openjson.JSONException;
+import com.github.openjson.JSONObject;
/**
* The base class for Wicket's default AJAX implementation.
@@ -370,7 +369,7 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior
if (requestTimeout != null)
{
attributesJson.put(AjaxAttributeName.REQUEST_TIMEOUT.jsonName(),
- requestTimeout.getMilliseconds());
+ requestTimeout.toMillis());
}
boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
@@ -396,7 +395,7 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior
}
throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_ID.jsonName(), throttleId);
throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_DELAY.jsonName(),
- throttlingSettings.getDelay().getMilliseconds());
+ throttlingSettings.getDelay().toMillis());
if (throttlingSettings.getPostponeTimerOnUpdate())
{
throttlingSettingsJson.put(
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java
index f51f8a4..9429d72 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.ajax;
+import java.time.Duration;
import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
@@ -26,7 +27,6 @@ import org.apache.wicket.protocol.http.request.WebClientInfo;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Duration;
import org.danekja.java.util.function.serializable.SerializableBiConsumer;
/**
@@ -46,7 +46,7 @@ public class AjaxClientInfoBehavior extends AbstractAjaxTimerBehavior
*/
public AjaxClientInfoBehavior()
{
- this(Duration.milliseconds(50));
+ this(Duration.ofMillis(50));
}
/**
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxSelfUpdatingTimerBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxSelfUpdatingTimerBehavior.java
index 6d40901..a12d563 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxSelfUpdatingTimerBehavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxSelfUpdatingTimerBehavior.java
@@ -17,7 +17,7 @@
package org.apache.wicket.ajax;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.danekja.java.util.function.serializable.SerializableConsumer;
/**
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
index 76e2f0c..7ced97d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
@@ -23,7 +23,7 @@ import java.util.Map;
import org.apache.wicket.ajax.AjaxChannel;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
/**
* Attributes of an Ajax Request.
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/ThrottlingSettings.java b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/ThrottlingSettings.java
index 42c6d7d..efdf542 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/ThrottlingSettings.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/ThrottlingSettings.java
@@ -19,7 +19,7 @@ package org.apache.wicket.ajax.attributes;
import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.util.io.IClusterable;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
/**
* Class to keep track of throttling settings.
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormValidatingBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormValidatingBehavior.java
index 1900e6d..fc6022f 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormValidatingBehavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormValidatingBehavior.java
@@ -26,7 +26,7 @@ import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.util.io.IClusterable;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
diff --git a/wicket-core/src/main/java/org/apache/wicket/application/ReloadingClassLoader.java b/wicket-core/src/main/java/org/apache/wicket/application/ReloadingClassLoader.java
index 8501519..2a1e1c6 100644
--- a/wicket-core/src/main/java/org/apache/wicket/application/ReloadingClassLoader.java
+++ b/wicket-core/src/main/java/org/apache/wicket/application/ReloadingClassLoader.java
@@ -29,7 +29,7 @@ import java.util.TreeSet;
import org.apache.wicket.util.collections.UrlExternalFormComparator;
import org.apache.wicket.util.file.File;
import org.apache.wicket.util.listener.IChangeListener;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.apache.wicket.util.watch.IModifiable;
import org.apache.wicket.util.watch.IModificationWatcher;
import org.apache.wicket.util.watch.ModificationWatcher;
@@ -203,7 +203,7 @@ public class ReloadingClassLoader extends URLClassLoader
{
addURL(url);
}
- Duration pollFrequency = Duration.seconds(3);
+ Duration pollFrequency = Duration.ofSeconds(3);
watcher = new ModificationWatcher(pollFrequency);
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/PackageResourceStream.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/PackageResourceStream.java
index 4a1a4e6..d619a22 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/PackageResourceStream.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/PackageResourceStream.java
@@ -18,8 +18,8 @@ package org.apache.wicket.core.util.resource;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Instant;
import java.util.Locale;
-
import org.apache.wicket.Application;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator;
@@ -28,7 +28,6 @@ import org.apache.wicket.util.lang.Packages;
import org.apache.wicket.util.resource.AbstractResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Time;
/**
@@ -117,7 +116,7 @@ public class PackageResourceStream extends AbstractResourceStream
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return resourceStream.lastModifiedTime();
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/UrlResourceStream.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/UrlResourceStream.java
index cb905df..7f36cbe 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/UrlResourceStream.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/UrlResourceStream.java
@@ -20,9 +20,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
-
import org.apache.wicket.Application;
import org.apache.wicket.util.io.Connections;
import org.apache.wicket.util.io.IOUtils;
@@ -32,7 +32,6 @@ import org.apache.wicket.util.lang.Objects;
import org.apache.wicket.util.resource.AbstractResourceStream;
import org.apache.wicket.util.resource.IFixedLocationResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,7 +62,7 @@ public class UrlResourceStream extends AbstractResourceStream
private final URL url;
/** Last known time the stream was last modified. */
- private Time lastModified;
+ private Instant lastModified;
/**
* Meta data class for the stream attributes
@@ -202,12 +201,12 @@ public class UrlResourceStream extends AbstractResourceStream
* @return The last time this resource was modified
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
try
{
// get url modification timestamp
- final Time time = Connections.getLastModified(url);
+ final Instant time = Connections.getLastModified(url);
// if timestamp changed: update content length and last modified date
if (Objects.equal(time, lastModified) == false)
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/WebExternalResourceStream.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/WebExternalResourceStream.java
index 9697a18..2b725e4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/WebExternalResourceStream.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/WebExternalResourceStream.java
@@ -20,9 +20,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-
+import java.time.Instant;
import javax.servlet.ServletContext;
-
import org.apache.wicket.Application;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.util.io.Connections;
@@ -30,7 +29,6 @@ import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.resource.AbstractResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,7 +77,7 @@ public class WebExternalResourceStream extends AbstractResourceStream
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
try
{
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/watch/Nio2ModificationWatcher.java b/wicket-core/src/main/java/org/apache/wicket/core/util/watch/Nio2ModificationWatcher.java
index 158ffa2..c25d712 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/watch/Nio2ModificationWatcher.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/watch/Nio2ModificationWatcher.java
@@ -41,7 +41,7 @@ import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.thread.ICode;
import org.apache.wicket.util.thread.Task;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.apache.wicket.util.watch.ModificationWatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java b/wicket-core/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
index d2efdd9..c848367 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
@@ -18,10 +18,10 @@ package org.apache.wicket.markup;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Instant;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.wicket.Component;
import org.apache.wicket.core.util.lang.WicketObjects;
import org.apache.wicket.util.lang.Args;
@@ -30,7 +30,6 @@ import org.apache.wicket.util.resource.IFixedLocationResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -143,7 +142,7 @@ public class MarkupResourceStream implements IResourceStream, IFixedLocationReso
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return resourceStream.lastModifiedTime();
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
index 5982a26..3d00735 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
@@ -19,9 +19,8 @@ package org.apache.wicket.markup.html.image.resource;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.lang.ref.SoftReference;
-
+import java.time.Instant;
import org.apache.wicket.request.resource.DynamicImageResource;
-import org.apache.wicket.util.time.Time;
/**
@@ -163,7 +162,7 @@ public abstract class RenderedDynamicImageResource extends DynamicImageResource
{
data = render(attributes);
imageData = new SoftReference<byte[]>(data);
- setLastModifiedTime(Time.now());
+ setLastModifiedTime(Instant.now());
}
return data;
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
index b44e534..88e55da 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
@@ -28,7 +28,7 @@ import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.resource.FileResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
/**
* A link that streams a file to the client. When clicked this link will prompt the save as dialog
diff --git a/wicket-core/src/main/java/org/apache/wicket/mock/MockWebRequest.java b/wicket-core/src/main/java/org/apache/wicket/mock/MockWebRequest.java
index ffbbd6f..39758e4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/mock/MockWebRequest.java
+++ b/wicket-core/src/main/java/org/apache/wicket/mock/MockWebRequest.java
@@ -17,21 +17,20 @@
package org.apache.wicket.mock;
import java.nio.charset.Charset;
+import java.sql.Time;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-
import javax.servlet.http.Cookie;
-
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.Url.QueryParameter;
import org.apache.wicket.request.UrlUtils;
import org.apache.wicket.request.http.WebRequest;
-import org.apache.wicket.util.time.Time;
/**
* Mutable mock {@link WebRequest}.
@@ -138,7 +137,7 @@ public class MockWebRequest extends WebRequest
@Override
- public Time getDateHeader(String name)
+ public Instant getDateHeader(String name)
{
List<Object> dates = headers.get(name);
if (dates == null || dates.isEmpty())
@@ -148,12 +147,12 @@ public class MockWebRequest extends WebRequest
Object date = dates.get(0);
- if (date instanceof Time == false)
+ if (date instanceof Instant == false)
{
throw new WicketRuntimeException("Date header with name '" + name +
"' is not a valid Time.");
}
- return (Time)date;
+ return (Instant)date;
}
private void addHeaderObject(String name, Object value)
diff --git a/wicket-core/src/main/java/org/apache/wicket/mock/MockWebResponse.java b/wicket-core/src/main/java/org/apache/wicket/mock/MockWebResponse.java
index ba09a16..ba65975 100644
--- a/wicket-core/src/main/java/org/apache/wicket/mock/MockWebResponse.java
+++ b/wicket-core/src/main/java/org/apache/wicket/mock/MockWebResponse.java
@@ -18,18 +18,16 @@ package org.apache.wicket.mock;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
-
import javax.servlet.http.Cookie;
-
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.request.HttpHeaderCollection;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
/**
* Mocked {@link WebResponse}.
@@ -145,7 +143,7 @@ public class MockWebResponse extends WebResponse
}
@Override
- public void setDateHeader(String name, Time date)
+ public void setDateHeader(String name, Instant date)
{
Args.notNull(date, "date");
headers.setDateHeader(name, date);
@@ -156,9 +154,9 @@ public class MockWebResponse extends WebResponse
*
* @return date header with specified name
*/
- public Time getDateHeader(String name)
+ public Instant getDateHeader(String name)
{
- final Time time = headers.getDateHeader(name);
+ final Instant time = headers.getDateHeader(name);
if (time == null)
{
diff --git a/wicket-core/src/main/java/org/apache/wicket/page/CouldNotLockPageException.java b/wicket-core/src/main/java/org/apache/wicket/page/CouldNotLockPageException.java
index 15ff1f9..4e2ee15 100644
--- a/wicket-core/src/main/java/org/apache/wicket/page/CouldNotLockPageException.java
+++ b/wicket-core/src/main/java/org/apache/wicket/page/CouldNotLockPageException.java
@@ -16,7 +16,7 @@
*/
package org.apache.wicket.page;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
/**
* An exception that is being thrown when a second thread attempts to get
diff --git a/wicket-core/src/main/java/org/apache/wicket/page/PageAccessSynchronizer.java b/wicket-core/src/main/java/org/apache/wicket/page/PageAccessSynchronizer.java
index 8d69fda..829a073 100644
--- a/wicket-core/src/main/java/org/apache/wicket/page/PageAccessSynchronizer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/page/PageAccessSynchronizer.java
@@ -17,18 +17,17 @@
package org.apache.wicket.page;
import java.io.Serializable;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
-
import org.apache.wicket.Application;
import org.apache.wicket.pageStore.IPageStore;
import org.apache.wicket.settings.ExceptionSettings.ThreadDumpStrategy;
import org.apache.wicket.util.LazyInitializer;
import org.apache.wicket.util.lang.Threads;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,9 +68,10 @@ public class PageAccessSynchronizer implements Serializable
this.timeout = timeout;
}
- private static long remaining(Time start, Duration timeout)
+ private static long remaining(Instant start, Duration timeout)
{
- return Math.max(0, timeout.subtract(start.elapsedSince()).getMilliseconds());
+ Duration elapsedTime = elapsedSince(start);
+ return Math.max(0, timeout.minus(elapsedTime).toMillis());
}
/**
@@ -96,7 +96,7 @@ public class PageAccessSynchronizer implements Serializable
{
final Thread thread = Thread.currentThread();
final PageLock lock = new PageLock(pageId, thread);
- final Time start = Time.now();
+ final Instant start = Instant.now();
boolean locked = false;
@@ -106,7 +106,7 @@ public class PageAccessSynchronizer implements Serializable
Duration timeout = getTimeout(pageId);
- while (!locked && start.elapsedSince().lessThan(timeout))
+ while (!locked && elapsedSince(start).compareTo(timeout) < 0)
{
if (isDebugEnabled)
{
@@ -145,7 +145,7 @@ public class PageAccessSynchronizer implements Serializable
logger.warn(
"Thread '{}' failed to acquire lock to page with id '{}', attempted for {} out of allowed {}." +
" The thread that holds the lock has name '{}'.",
- thread.getName(), pageId, start.elapsedSince(), timeout,
+ thread.getName(), pageId, Duration.between(start, Instant.now()), timeout,
previous.thread.getName());
if (Application.exists())
{
@@ -381,7 +381,7 @@ public class PageAccessSynchronizer implements Serializable
if (isDebugEnabled)
{
logger.debug("{} waiting for lock to page {} for {}",
- thread.getName(), pageId, Duration.milliseconds(remaining));
+ thread.getName(), pageId, Duration.ofMillis(remaining));
}
try
{
@@ -403,4 +403,9 @@ public class PageAccessSynchronizer implements Serializable
notifyAll();
}
}
+
+ public static Duration elapsedSince(Instant start)
+ {
+ return Duration.between(start, Instant.now());
+ }
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java b/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java
index 37a05bb..2e026bd 100644
--- a/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java
+++ b/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.page;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -23,9 +24,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import javax.servlet.http.Cookie;
-
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.feedback.FeedbackDelay;
@@ -49,7 +48,6 @@ import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Generics;
import org.apache.wicket.util.string.AppendingStringBuffer;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -811,7 +809,7 @@ public abstract class PartialPageUpdate
}
@Override
- public void setDateHeader(String name, Time date)
+ public void setDateHeader(String name, Instant date)
{
originalResponse.setDateHeader(name, date);
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/AbstractRequestLogger.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/AbstractRequestLogger.java
index dda4147..e39ca47 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/AbstractRequestLogger.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/AbstractRequestLogger.java
@@ -17,22 +17,20 @@
package org.apache.wicket.protocol.http;
import static java.lang.System.arraycopy;
-
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.wicket.Application;
import org.apache.wicket.MetaDataKey;
import org.apache.wicket.Session;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -496,7 +494,7 @@ public abstract class AbstractRequestLogger implements IRequestLogger
{
Args.notNull(date, "date");
- final Calendar cal = Calendar.getInstance(Time.GMT);
+ final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
final StringBuilder buf = new StringBuilder(32);
cal.setTimeInMillis(date.getTime());
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/BufferedWebResponse.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/BufferedWebResponse.java
index 27f56cd..23de6ea 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/BufferedWebResponse.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/BufferedWebResponse.java
@@ -19,13 +19,12 @@ package org.apache.wicket.protocol.http;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
-
import javax.servlet.http.Cookie;
-
import org.apache.wicket.Application;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.request.Response;
@@ -33,7 +32,6 @@ import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.response.filter.IResponseFilter;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.AppendingStringBuffer;
-import org.apache.wicket.util.time.Time;
/**
* Subclass of {@link WebResponse} that buffers the actions and performs those on another response.
@@ -188,7 +186,7 @@ public class BufferedWebResponse extends WebResponse implements IMetaDataBufferi
}
@Override
- public void setDateHeader(String name, Time date)
+ public void setDateHeader(String name, Instant date)
{
Args.notNull(date, "date");
actions.add(ActionType.HEADER.action(res -> res.setDateHeader(name, date)));
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
index ac116d9..993f959 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
@@ -16,12 +16,11 @@
*/
package org.apache.wicket.protocol.http;
+import java.time.Instant;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
/**
* Response that keeps headers in buffers until the first content is written.
@@ -130,7 +129,7 @@ class HeaderBufferingWebResponse extends WebResponse implements IMetaDataBufferi
}
@Override
- public void setDateHeader(String name, Time date)
+ public void setDateHeader(String name, Instant date)
{
Args.notNull(date, "date");
getMetaResponse().setDateHeader(name, date);
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/StoredResponsesMap.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/StoredResponsesMap.java
index 343bffa..699fe0c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/StoredResponsesMap.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/StoredResponsesMap.java
@@ -16,11 +16,10 @@
*/
package org.apache.wicket.protocol.http;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Map;
-
import org.apache.wicket.util.collections.MostRecentlyUsedMap;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
* A map that contains the buffered responses. It has a constraint on the maximum entries that it
@@ -40,7 +39,7 @@ class StoredResponsesMap extends MostRecentlyUsedMap<String, Object>
private BufferedWebResponse response;
/** the time when this response is stored */
- private Time creationTime;
+ private Instant creationTime;
}
/**
@@ -72,8 +71,8 @@ class StoredResponsesMap extends MostRecentlyUsedMap<String, Object>
Value value = (Value)eldest.getValue();
if (value != null)
{
- Duration elapsedTime = Time.now().subtract(value.creationTime);
- if (lifetime.lessThanOrEqual(elapsedTime))
+ Duration elapsedTime = Duration.between(value.creationTime, Instant.now());
+ if (lifetime.compareTo(elapsedTime) <= 0)
{
removedValue = value.response;
removed = true;
@@ -93,7 +92,7 @@ class StoredResponsesMap extends MostRecentlyUsedMap<String, Object>
}
Value value = new Value();
- value.creationTime = Time.now();
+ value.creationTime = Instant.now();
value.response = (BufferedWebResponse)bufferedResponse;
Value oldValue;
@@ -116,8 +115,8 @@ class StoredResponsesMap extends MostRecentlyUsedMap<String, Object>
}
if (value != null)
{
- Duration elapsedTime = Time.now().subtract(value.creationTime);
- if (lifetime.greaterThan(elapsedTime))
+ Duration elapsedTime = Duration.between(value.creationTime, Instant.now());
+ if (lifetime.compareTo(elapsedTime) > 0)
{
result = value.response;
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 503f793..0f3177f 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -77,7 +77,7 @@ import org.apache.wicket.util.file.Path;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.PackageName;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.apache.wicket.util.watch.IModificationWatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -963,7 +963,7 @@ public abstract class WebApplication extends Application
* is no need to configure these parameters externally.
*/
private final StoredResponsesMap storedResponses = new StoredResponsesMap(1000,
- Duration.seconds(60));
+ Duration.ofSeconds(60));
/**
*
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
index 45b0544..e8fb669 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
@@ -17,6 +17,7 @@
package org.apache.wicket.protocol.http.servlet;
import java.nio.charset.Charset;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -26,11 +27,9 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.wicket.protocol.http.RequestUtils;
@@ -45,7 +44,6 @@ import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.string.PrependingStringBuffer;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -236,7 +234,7 @@ public class ServletWebRequest extends WebRequest
}
@Override
- public Time getDateHeader(String name)
+ public Instant getDateHeader(String name)
{
try
{
@@ -247,7 +245,7 @@ public class ServletWebRequest extends WebRequest
return null;
}
- return Time.millis(value);
+ return Instant.ofEpochMilli(value);
}
catch (IllegalArgumentException e)
{
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
index a1e5c8c..8f11fa0 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
@@ -17,18 +17,16 @@
package org.apache.wicket.protocol.http.servlet;
import java.io.IOException;
-
+import java.time.Instant;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.UrlRenderer;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
/**
* WebResponse that wraps a {@link ServletWebResponse}.
@@ -84,10 +82,10 @@ public class ServletWebResponse extends WebResponse
}
@Override
- public void setDateHeader(String name, Time date)
+ public void setDateHeader(String name, Instant date)
{
Args.notNull(date, "date");
- httpServletResponse.setDateHeader(name, date.getMilliseconds());
+ httpServletResponse.setDateHeader(name, date.toEpochMilli());
}
@Override
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/UploadInfo.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/UploadInfo.java
index 89a1bbd..c528316 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/UploadInfo.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/UploadInfo.java
@@ -16,10 +16,11 @@
*/
package org.apache.wicket.protocol.http.servlet;
+import java.time.Duration;
import org.apache.wicket.Session;
import org.apache.wicket.util.io.IClusterable;
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Duration;
+import org.apache.wicket.util.time.Durations;
/**
@@ -152,9 +153,7 @@ public class UploadInfo implements IClusterable
*/
public String getRemainingTimeString()
{
- return Duration.milliseconds(getRemainingMilliseconds())
- .toString(Session.get().getLocale());
+ return Durations.toString(Duration.ofMillis(getRemainingMilliseconds()),
+ Session.get().getLocale());
}
-
-
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/handler/resource/ResourceStreamRequestHandler.java b/wicket-core/src/main/java/org/apache/wicket/request/handler/resource/ResourceStreamRequestHandler.java
index 2fedc45..1f2ee18 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/handler/resource/ResourceStreamRequestHandler.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/handler/resource/ResourceStreamRequestHandler.java
@@ -26,7 +26,7 @@ import org.apache.wicket.request.resource.ResourceStreamResource;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
index 7957c90..a4ec9ec 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
@@ -18,12 +18,13 @@ package org.apache.wicket.request.resource;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
-
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.Application;
import org.apache.wicket.MetaDataKey;
import org.apache.wicket.WicketRuntimeException;
@@ -39,8 +40,6 @@ import org.apache.wicket.util.io.Streams;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Classes;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
* Convenience resource implementation. The subclass must implement
@@ -140,7 +139,7 @@ public abstract class AbstractResource implements IResource
private ContentRangeType contentRangeType = null;
private String textEncoding;
private long contentLength = -1;
- private Time lastModified = null;
+ private Instant lastModified = null;
private WriteCallback writeCallback;
private Duration cacheDuration;
private WebResponse.CacheScope cacheScope;
@@ -407,7 +406,7 @@ public abstract class AbstractResource implements IResource
*
* @return {@code this}, for chaining.
*/
- public ResourceResponse setLastModified(Time lastModified)
+ public ResourceResponse setLastModified(Instant lastModified)
{
this.lastModified = lastModified;
return this;
@@ -416,7 +415,7 @@ public abstract class AbstractResource implements IResource
/**
* @return last modification timestamp
*/
- public Time getLastModified()
+ public Instant getLastModified()
{
return lastModified;
}
@@ -434,18 +433,18 @@ public abstract class AbstractResource implements IResource
public boolean dataNeedsToBeWritten(Attributes attributes)
{
WebRequest request = (WebRequest)attributes.getRequest();
- Time ifModifiedSince = request.getIfModifiedSinceHeader();
+ Instant ifModifiedSince = request.getIfModifiedSinceHeader();
- if (cacheDuration != Duration.NONE && ifModifiedSince != null && lastModified != null)
+ if (cacheDuration != Duration.ZERO && ifModifiedSince != null && lastModified != null)
{
// [Last-Modified] headers have a maximum precision of one second
// so we have to truncate the milliseconds part for a proper compare.
// that's stupid, since changes within one second will not be reliably
// detected by the client ... any hint or clarification to improve this
// situation will be appreciated...
- Time roundedLastModified = Time.millis(lastModified.getMilliseconds() / 1000 * 1000);
+ Instant roundedLastModified = lastModified.truncatedTo(ChronoUnit.SECONDS);
- return ifModifiedSince.before(roundedLastModified);
+ return ifModifiedSince.isBefore(roundedLastModified);
}
else
{
@@ -460,7 +459,7 @@ public abstract class AbstractResource implements IResource
*/
public ResourceResponse disableCaching()
{
- return setCacheDuration(Duration.NONE);
+ return setCacheDuration(Duration.ZERO);
}
/**
@@ -600,7 +599,7 @@ public abstract class AbstractResource implements IResource
{
Duration duration = data.getCacheDuration();
WebResponse webResponse = (WebResponse)response;
- if (duration.compareTo(Duration.NONE) > 0)
+ if (duration.compareTo(Duration.ZERO) > 0)
{
webResponse.enableCaching(duration, data.getCacheScope());
}
@@ -771,7 +770,7 @@ public abstract class AbstractResource implements IResource
WebResponse webResponse = (WebResponse)response;
// 1. Last Modified
- Time lastModified = resourceResponse.getLastModified();
+ Instant lastModified = resourceResponse.getLastModified();
if (lastModified != null)
{
webResponse.setLastModifiedTime(lastModified);
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/BaseDataResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/BaseDataResource.java
index eff98e4..6874b94 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/BaseDataResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/BaseDataResource.java
@@ -17,11 +17,9 @@
package org.apache.wicket.request.resource;
import java.net.URLConnection;
-
+import java.time.Instant;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.request.Response;
-import org.apache.wicket.util.time.Time;
/**
* An abstract resource that can deliver static data - passed to the constructor, or dynamic -
@@ -41,7 +39,7 @@ public abstract class BaseDataResource<T> extends AbstractResource
private T data;
/** the time that this resource was last modified; same as construction time. */
- private final Time lastModified = Time.now();
+ private final Instant lastModified = Instant.now();
private final String filename;
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/DynamicImageResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/DynamicImageResource.java
index 26ab5a0..8eeb845 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/DynamicImageResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/DynamicImageResource.java
@@ -19,13 +19,12 @@ package org.apache.wicket.request.resource;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-
+import java.sql.Time;
+import java.time.Instant;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
/**
* Base class for dynamically generated ImageResources.
@@ -38,7 +37,7 @@ public abstract class DynamicImageResource extends AbstractResource
private String format = "png";
/** The last modified time of this resource */
- private Time lastModifiedTime;
+ private Instant lastModifiedTime;
/**
@@ -84,7 +83,7 @@ public abstract class DynamicImageResource extends AbstractResource
*
* @param time
*/
- protected synchronized void setLastModifiedTime(Time time)
+ protected synchronized void setLastModifiedTime(Instant time)
{
lastModifiedTime = time;
}
@@ -143,7 +142,7 @@ public abstract class DynamicImageResource extends AbstractResource
}
else
{
- response.setLastModified(Time.now());
+ response.setLastModified(Instant.now());
}
if (response.dataNeedsToBeWritten(attributes))
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResource.java
index 614d6f2..60e76f1 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResource.java
@@ -22,11 +22,10 @@ import java.io.InputStream;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.time.Instant;
import java.util.Locale;
import java.util.Objects;
-
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.Application;
import org.apache.wicket.IWicketInternalException;
import org.apache.wicket.Session;
@@ -50,7 +49,6 @@ import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
import org.apache.wicket.util.resource.ResourceStreamWrapper;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -331,7 +329,7 @@ public class PackageResource extends AbstractResource implements IStaticCacheabl
}
// add Last-Modified header (to support HEAD requests and If-Modified-Since)
- final Time lastModified = resourceStream.lastModifiedTime();
+ final Instant lastModified = resourceStream.lastModifiedTime();
resourceResponse.setLastModified(lastModified);
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
index b781206..0c81570 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
@@ -18,17 +18,15 @@ package org.apache.wicket.request.resource;
import java.io.IOException;
import java.io.InputStream;
-
+import java.time.Duration;
+import java.time.Instant;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.Application;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.lang.Checks;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.IResourceStreamWriter;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -141,7 +139,7 @@ public class ResourceStreamResource extends AbstractResource
{
final IResourceStream resourceStream = internalGetResourceStream(attributes);
ResourceResponse data = new ResourceResponse();
- Time lastModifiedTime = resourceStream.lastModifiedTime();
+ Instant lastModifiedTime = resourceStream.lastModifiedTime();
if (lastModifiedTime != null)
{
data.setLastModified(lastModifiedTime);
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/version/LastModifiedResourceVersion.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/version/LastModifiedResourceVersion.java
index 76f0f19..f7a4196 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/version/LastModifiedResourceVersion.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/version/LastModifiedResourceVersion.java
@@ -16,11 +16,10 @@
*/
package org.apache.wicket.request.resource.caching.version;
+import java.time.Instant;
import java.util.regex.Pattern;
-
import org.apache.wicket.request.resource.caching.IStaticCacheableResource;
import org.apache.wicket.util.resource.IResourceStream;
-import org.apache.wicket.util.time.Time;
/**
* Uses the last modified timestamp of a {@link org.apache.wicket.request.resource.caching.IStaticCacheableResource}
@@ -49,7 +48,7 @@ public class LastModifiedResourceVersion implements IResourceVersion
return null;
}
- final Time lastModified = stream.lastModifiedTime();
+ final Instant lastModified = stream.lastModifiedTime();
// if no timestamp is available we can not provide a version
if (lastModified == null)
@@ -57,7 +56,7 @@ public class LastModifiedResourceVersion implements IResourceVersion
return null;
}
// version string = last modified timestamp converted to milliseconds
- return String.valueOf(lastModified.getMilliseconds()).intern();
+ return String.valueOf(lastModified.toEpochMilli()).intern();
}
@Override
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
index 6d761d9..1a9089a 100644
--- a/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
+++ b/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
@@ -16,9 +16,10 @@
*/
package org.apache.wicket.resource;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Locale;
import java.util.Map;
-
import org.apache.wicket.Application;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.IResource;
@@ -30,8 +31,6 @@ import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
import org.apache.wicket.util.template.PackageTextTemplate;
import org.apache.wicket.util.template.TextTemplate;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
* A class which adapts a {@link PackageTextTemplate} to a {@link ResourceReference}.
@@ -151,12 +150,12 @@ public class TextTemplateResourceReference extends ResourceReference implements
StringResourceStream resourceStream = new StringResourceStream(stringValue,
textTemplate.getContentType());
- resourceStream.setLastModified(Time.now());
+ resourceStream.setLastModified(Instant.now());
return resourceStream;
}
};
- resource.setCacheDuration(Duration.NONE);
+ resource.setCacheDuration(Duration.ZERO);
if (Application.exists())
{
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/bundles/ConcatBundleResource.java b/wicket-core/src/main/java/org/apache/wicket/resource/bundles/ConcatBundleResource.java
index 95087c4..b73911d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/resource/bundles/ConcatBundleResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/resource/bundles/ConcatBundleResource.java
@@ -20,12 +20,11 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
-
import javax.servlet.http.HttpServletResponse;
-
import org.apache.wicket.Application;
import org.apache.wicket.markup.head.IReferenceHeaderItem;
import org.apache.wicket.request.resource.AbstractResource;
@@ -41,7 +40,6 @@ import org.apache.wicket.util.lang.Classes;
import org.apache.wicket.util.resource.AbstractResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,7 +93,7 @@ public class ConcatBundleResource extends AbstractResource implements IStaticCac
resourceResponse.setContentType(findContentType(resources));
// add Last-Modified header (to support HEAD requests and If-Modified-Since)
- final Time lastModified = findLastModified(resources);
+ final Instant lastModified = findLastModified(resources);
if (lastModified != null)
resourceResponse.setLastModified(lastModified);
@@ -157,13 +155,13 @@ public class ConcatBundleResource extends AbstractResource implements IStaticCac
return null;
}
- protected Time findLastModified(List<IResourceStream> resources)
+ protected Instant findLastModified(List<IResourceStream> resources)
{
- Time ret = null;
+ Instant ret = null;
for (IResourceStream curStream : resources)
{
- Time curLastModified = curStream.lastModifiedTime();
- if (ret == null || curLastModified.after(ret))
+ Instant curLastModified = curStream.lastModifiedTime();
+ if (ret == null || curLastModified.isAfter(ret))
ret = curLastModified;
}
return ret;
@@ -278,7 +276,7 @@ public class ConcatBundleResource extends AbstractResource implements IStaticCac
}
final String contentType = findContentType(resources);
- final Time lastModified = findLastModified(resources);
+ final Instant lastModified = findLastModified(resources);
final ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
final long length = bytes.length;
AbstractResourceStream ret = new AbstractResourceStream()
@@ -304,7 +302,7 @@ public class ConcatBundleResource extends AbstractResource implements IStaticCac
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return lastModified;
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/settings/RequestCycleSettings.java b/wicket-core/src/main/java/org/apache/wicket/settings/RequestCycleSettings.java
index 784ac38..b40317b 100644
--- a/wicket-core/src/main/java/org/apache/wicket/settings/RequestCycleSettings.java
+++ b/wicket-core/src/main/java/org/apache/wicket/settings/RequestCycleSettings.java
@@ -16,13 +16,12 @@
*/
package org.apache.wicket.settings;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import org.apache.wicket.response.filter.IResponseFilter;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Duration;
/**
* Class for request related settings
@@ -169,7 +168,7 @@ public class RequestCycleSettings
* The time that a request will by default be waiting for the previous request to be handled
* before giving up. Defaults to one minute.
*/
- private Duration timeout = Duration.ONE_MINUTE;
+ private Duration timeout = Duration.ofMinutes(1);
private int exceptionRetryCount = 10;
diff --git a/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java b/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java
index 72c80d6..b76fbcd 100644
--- a/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java
+++ b/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java
@@ -56,7 +56,7 @@ import org.apache.wicket.util.file.IResourceFinder;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Generics;
import org.apache.wicket.util.resource.IResourceStream;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.apache.wicket.util.watch.IModificationWatcher;
import org.apache.wicket.util.watch.ModificationWatcher;
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java b/wicket-core/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java
index 5bce94f..a7acecb 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.util.cookies;
+import java.time.Instant;
import javax.servlet.http.Cookie;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.protocol.http.WebApplication;
@@ -25,7 +26,7 @@ import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebRequest;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
+import org.apache.wicket.util.time.Instants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -369,6 +370,7 @@ public class CookieUtils
{
return "[Cookie " + " name = " + cookie.getName() + ", value = " + cookie.getValue() +
", domain = " + cookie.getDomain() + ", path = " + cookie.getPath() + ", maxAge = " +
- Time.millis(cookie.getMaxAge()).toDateString() + "(" + cookie.getMaxAge() + ")" + "]";
+ Instants.localDateFormatter.format(Instant.ofEpochMilli(cookie.getMaxAge())) +
+ "(" + cookie.getMaxAge() + ")" + "]";
}
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java b/wicket-core/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
index 6a1ef32..3737bbe 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
@@ -19,13 +19,12 @@ package org.apache.wicket.util.template;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.time.Instant;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
-
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Time;
/**
@@ -167,7 +166,7 @@ public abstract class TextTemplateDecorator extends TextTemplate
* @see org.apache.wicket.util.resource.AbstractStringResourceStream#lastModifiedTime()
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return decorated.lastModifiedTime();
}
@@ -185,7 +184,7 @@ public abstract class TextTemplateDecorator extends TextTemplate
* @see org.apache.wicket.util.resource.AbstractStringResourceStream#setLastModified(org.apache.wicket.util.time.Time)
*/
@Override
- public void setLastModified(Time lastModified)
+ public void setLastModified(Instant lastModified)
{
decorated.setLastModified(lastModified);
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index 03a3d08..3cf02f9 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -130,7 +130,7 @@ import org.apache.wicket.util.lang.Classes;
import org.apache.wicket.util.lang.Generics;
import org.apache.wicket.util.resource.StringResourceStream;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
import org.slf4j.Logger;
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxBehaviorAndMetaDataPage.java b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxBehaviorAndMetaDataPage.java
index 0f311a7..4c84e34 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxBehaviorAndMetaDataPage.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxBehaviorAndMetaDataPage.java
@@ -16,9 +16,9 @@
*/
package org.apache.wicket.ajax;
+import java.time.Duration;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
-import org.apache.wicket.util.time.Duration;
/** */
@@ -36,7 +36,7 @@ public class AjaxBehaviorAndMetaDataPage extends WebPage implements IAjaxIndicat
ajaxContainer.setMarkupId("menu");
ajaxContainer.setOutputMarkupId(true);
- ajaxIndicatorAppender = new AjaxSelfUpdatingTimerBehavior(Duration.ONE_MINUTE);
+ ajaxIndicatorAppender = new AjaxSelfUpdatingTimerBehavior(Duration.ofMinutes(1));
ajaxContainer.add(ajaxIndicatorAppender);
add(ajaxContainer);
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxRequestHandlerTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxRequestHandlerTest.java
index eace93c..e3fdc5d 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxRequestHandlerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxRequestHandlerTest.java
@@ -21,14 +21,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.nio.charset.Charset;
+import java.time.Instant;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.MockPageWithLinkAndComponent;
@@ -42,7 +41,7 @@ import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
import org.apache.wicket.util.tester.DiffUtil;
import org.apache.wicket.util.tester.WicketTestCase;
-import org.apache.wicket.util.time.Time;
+import org.apache.wicket.util.time.Instants;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -284,14 +283,14 @@ class AjaxRequestHandlerTest extends WicketTestCase
tester.startPage(new Wicket3921());
tester.clickLink("updatePage");
- assertEquals(Time.START_OF_UNIX_TIME.toRfc1123TimestampString(),
+ assertEquals(Instants.toRFC7231Format(Instant.EPOCH),
tester.getLastResponse().getHeader("Expires"));
assertEquals("no-cache", tester.getLastResponse().getHeader("Pragma"));
assertEquals("no-cache, no-store", tester.getLastResponse().getHeader("Cache-Control"));
tester.clickLink("updateComponent");
- assertEquals(Time.START_OF_UNIX_TIME.toRfc1123TimestampString(),
+ assertEquals(Instants.toRFC7231Format(Instant.EPOCH),
tester.getLastResponse().getHeader("Expires"));
assertEquals("no-cache", tester.getLastResponse().getHeader("Pragma"));
assertEquals("no-cache, no-store", tester.getLastResponse().getHeader("Cache-Control"));
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
index db459b6..9a6a3d6 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
@@ -27,7 +27,7 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.tester.WicketTestCase;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +48,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
@Test
void addedInAjaxSetsTimout()
{
- Duration dur = Duration.seconds(20);
+ Duration dur = Duration.ofSeconds(20);
final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
@@ -90,7 +90,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
@Test
void pageRenderSetsTimeout()
{
- Duration dur = Duration.seconds(20);
+ Duration dur = Duration.ofSeconds(20);
final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
@@ -127,7 +127,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
@Test
void ajaxUpdateDoesNotSetTimeout()
{
- Duration dur = Duration.seconds(20);
+ Duration dur = Duration.ofSeconds(20);
final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
@@ -164,7 +164,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
@Test
void setVisibleSetsTimeout()
{
- Duration dur = Duration.seconds(20);
+ Duration dur = Duration.ofSeconds(20);
final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
@@ -203,7 +203,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
@Test
void setDisabledClearsTimeout()
{
- final AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(20))
+ final AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.ofSeconds(20))
{
private boolean enabled = true;
@@ -260,7 +260,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
// the duration doesn't matter because we manually trigger the behavior
final AbstractAjaxTimerBehavior timerBehavior = new AbstractAjaxTimerBehavior(
- Duration.seconds(2))
+ Duration.ofSeconds(2))
{
private static final long serialVersionUID = 1L;
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanel.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanel.java
index e57ae07..d0ccef5 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanel.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanel.java
@@ -20,7 +20,7 @@ import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.PropertyModel;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
/**
*
@@ -43,7 +43,7 @@ public class SimpleTestPanel extends SimpleTestPanelBase
super(name);
Label ajaxLabel = new Label("linja1", new PropertyModel<Integer>(this, "count"));
- timer = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(2));
+ timer = new AjaxSelfUpdatingTimerBehavior(Duration.ofSeconds(2));
ajaxLabel.add(timer);
baseSpan.add(ajaxLabel);
diff --git a/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java b/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
index ad697ed..85a5b03 100644
--- a/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
@@ -19,20 +19,18 @@ package org.apache.wicket.page;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-
+import java.time.Duration;
+import java.time.Instant;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.wicket.MockPage;
import org.apache.wicket.core.util.lang.WicketObjects;
import org.apache.wicket.mock.MockPageManager;
import org.apache.wicket.page.PageAccessSynchronizer.PageLock;
import org.apache.wicket.util.WicketTestTag;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
@@ -54,7 +52,7 @@ class PageAccessSynchronizerTest
@Test
void testReentrant() throws Exception
{
- final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(5));
+ final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.ofSeconds(5));
sync.lockPage(0);
sync.lockPage(0);
}
@@ -65,10 +63,10 @@ class PageAccessSynchronizerTest
@Test
void testBlocking() throws Exception
{
- final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(5));
- final Duration hold = Duration.seconds(1);
- final Time t1locks[] = new Time[1];
- final Time t2locks[] = new Time[1];
+ final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.ofSeconds(5));
+ final Duration hold = Duration.ofSeconds(1);
+ final Instant t1locks[] = new Instant[1];
+ final Instant t2locks[] = new Instant[1];
class T1 extends Thread
{
@@ -76,8 +74,15 @@ class PageAccessSynchronizerTest
public void run()
{
sync.lockPage(1);
- t1locks[0] = Time.now();
- hold.sleep();
+ t1locks[0] = Instant.now();
+ try
+ {
+ Thread.sleep(hold.toMillis());
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException(e);
+ }
sync.unlockAllPages();
}
}
@@ -88,7 +93,7 @@ class PageAccessSynchronizerTest
public void run()
{
sync.lockPage(1);
- t2locks[0] = Time.now();
+ t2locks[0] = Instant.now();
sync.unlockAllPages();
}
}
@@ -98,13 +103,13 @@ class PageAccessSynchronizerTest
T2 t2 = new T2();
t2.setName("t2");
t1.start();
- Duration.milliseconds(100).sleep();
+ Thread.sleep(100);
t2.start();
t1.join();
t2.join();
- assertTrue(!t2locks[0].before(t1locks[0].add(hold)));
+ assertTrue(!t2locks[0].isBefore(t1locks[0].plus(hold)));
}
/**
@@ -116,7 +121,7 @@ class PageAccessSynchronizerTest
private void runContentionTest(final int pages, final int workers, final Duration duration)
throws Exception
{
- final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(1));
+ final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.ofSeconds(1));
final AtomicInteger[] counts = new AtomicInteger[pages];
for (int i = 0; i < counts.length; i++)
@@ -134,12 +139,12 @@ class PageAccessSynchronizerTest
public void run()
{
Random random = new Random();
- Time start = Time.now();
+ Instant start = Instant.now();
- while (start.elapsedSince().lessThan(duration) && error[0] == null)
+ while (PageAccessSynchronizer.elapsedSince(start).compareTo(duration) < 0 && error[0] == null)
{
logger.info("{} elapsed: {}, duration: {}", new Object[] {
- Thread.currentThread().getName(), start.elapsedSince(), duration });
+ Thread.currentThread().getName(), PageAccessSynchronizer.elapsedSince(start), duration });
int page1 = random.nextInt(counts.length);
int page2 = random.nextInt(counts.length);
int count = 0;
@@ -252,7 +257,7 @@ class PageAccessSynchronizerTest
@Test
void testConcurrency() throws Exception
{
- runContentionTest(20, 10, Duration.seconds(10));
+ runContentionTest(20, 10, Duration.ofSeconds(10));
}
/**
@@ -261,7 +266,7 @@ class PageAccessSynchronizerTest
@Test
void testContention() throws Exception
{
- runContentionTest(10, 20, Duration.seconds(10));
+ runContentionTest(10, 20, Duration.ofSeconds(10));
}
/**
@@ -288,7 +293,7 @@ class PageAccessSynchronizerTest
}
// set up a synchronizer and lock page 5 with locker1
- final Duration timeout = Duration.seconds(30);
+ final Duration timeout = Duration.ofSeconds(30);
final PageAccessSynchronizer sync = new PageAccessSynchronizer(timeout);
Locker locker1 = new Locker(sync);
@@ -304,7 +309,7 @@ class PageAccessSynchronizerTest
// locker2
Locker locker2 = new Locker(sync2);
locker2.run();
- assertTrue(Duration.milliseconds(System.currentTimeMillis() - start).lessThan(timeout));
+ assertTrue(Duration.ofMillis(System.currentTimeMillis() - start).compareTo(timeout) < 0);
}
/**
@@ -313,7 +318,7 @@ class PageAccessSynchronizerTest
@Test
void unlockIfNoSuchPage()
{
- PageAccessSynchronizer synchronizer = new PageAccessSynchronizer(Duration.seconds(2));
+ PageAccessSynchronizer synchronizer = new PageAccessSynchronizer(Duration.ofSeconds(2));
IPageManager pageManager = new MockPageManager();
IPageManager synchronizedPageManager = synchronizer.adapt(pageManager);
synchronizedPageManager.getPage(0);
@@ -337,14 +342,14 @@ class PageAccessSynchronizerTest
@Test
void failToReleaseUnderLoad() throws Exception
{
- final Duration duration = Duration.seconds(20); /* seconds */
+ final Duration duration = Duration.ofSeconds(20); /* seconds */
final ConcurrentLinkedQueue<Exception> errors = new ConcurrentLinkedQueue<Exception>();
- final long endTime = System.currentTimeMillis() + duration.getMilliseconds();
+ final long endTime = System.currentTimeMillis() + duration.toMillis();
// set the synchronizer timeout one second longer than the test runs to prevent
// starvation to become an issue
final PageAccessSynchronizer sync = new PageAccessSynchronizer(
- duration.add(Duration.ONE_SECOND));
+ duration.plus(Duration.ofSeconds(1)));
final CountDownLatch latch = new CountDownLatch(100);
for (int count = 0; count < 100; count++)
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java
index f525314..d95e634 100644
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java
@@ -20,16 +20,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-
import java.security.SecureRandom;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
import org.apache.wicket.util.WicketTestTag;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -48,7 +47,7 @@ class StoredResponsesMapTest
@Test
void entriesLife2Seconds() throws Exception
{
- StoredResponsesMap map = new StoredResponsesMap(1000, Duration.seconds(2));
+ StoredResponsesMap map = new StoredResponsesMap(1000, Duration.ofSeconds(2));
assertEquals(0, map.size());
map.put("1", new BufferedWebResponse(null));
assertEquals(1, map.size());
@@ -66,14 +65,17 @@ class StoredResponsesMapTest
@Test
void getExpiredValue() throws Exception
{
- Time start = Time.now();
- Duration timeout = Duration.milliseconds(50);
+ Instant start = Instant.now();
+ Duration timeout = Duration.ofMillis(50);
StoredResponsesMap map = new StoredResponsesMap(1000, timeout);
assertEquals(0, map.size());
map.put("1", new BufferedWebResponse(null));
assertEquals(1, map.size());
- TimeUnit.MILLISECONDS.sleep(timeout.getMilliseconds() * 2); // sleep for twice longer than the timeout
- assertTrue(Time.now().subtract(start).compareTo(timeout) == 1, "The timeout has passed.");
+ TimeUnit.MILLISECONDS.sleep(timeout.toMillis() * 2); // sleep for twice longer than the timeout
+ Duration elapsedTime = Duration.between(start, Instant.now());
+ elapsedTime = elapsedTime.truncatedTo(ChronoUnit.MILLIS);
+
+ assertTrue(elapsedTime.compareTo(timeout) > 0, "The timeout has passed.");
Object value = map.get("1");
assertNull(value);
}
@@ -84,7 +86,7 @@ class StoredResponsesMapTest
@Test
void cannotPutArbitraryValue()
{
- StoredResponsesMap map = new StoredResponsesMap(1000, Duration.days(1));
+ StoredResponsesMap map = new StoredResponsesMap(1000, Duration.ofDays(1));
assertThrows(IllegalArgumentException.class, () -> {
map.put("1", new Object());
});
@@ -107,7 +109,7 @@ class StoredResponsesMapTest
final CountDownLatch startLatch = new CountDownLatch(numberOfThreads);
final CountDownLatch endLatch = new CountDownLatch(numberOfThreads);
final SecureRandom rnd = new SecureRandom();
- final StoredResponsesMap map = new StoredResponsesMap(1000, Duration.seconds(60));
+ final StoredResponsesMap map = new StoredResponsesMap(1000, Duration.ofSeconds(60));
final List<String> keys = new CopyOnWriteArrayList<String>();
final Runnable r = new Runnable()
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java
index 0e05b72..de28a48 100644
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java
@@ -18,9 +18,9 @@ package org.apache.wicket.protocol.http.servlet;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
+import java.time.Duration;
import java.util.Enumeration;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.FilterChain;
@@ -29,7 +29,6 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-
import org.apache.wicket.Application;
import org.apache.wicket.Session;
import org.apache.wicket.mock.MockApplication;
@@ -37,7 +36,6 @@ import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.session.HttpSessionStore;
import org.apache.wicket.util.tester.WicketTestCase;
import org.apache.wicket.util.tester.WicketTester;
-import org.apache.wicket.util.time.Duration;
import org.junit.jupiter.api.Test;
/**
@@ -114,7 +112,7 @@ class WicketSessionFilterTest extends WicketTestCase
}
});
testThread.start();
- testThread.join(Duration.seconds(1).getMilliseconds());
+ testThread.join(Duration.ofSeconds(1).toMillis());
assertTrue(passed.get(), failMessage.toString());
}
diff --git a/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPage.java b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPage.java
index fc0ed3e..6adba97 100644
--- a/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPage.java
+++ b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPage.java
@@ -17,13 +17,12 @@
package org.apache.wicket.request.cycle;
import java.io.Serializable;
-
+import java.time.Duration;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.StringHeaderItem;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.util.time.Duration;
@SuppressWarnings("javadoc")
public class RerenderPage extends WebPage
@@ -47,7 +46,7 @@ public class RerenderPage extends WebPage
this.newValue = pars.get("value").toInteger();
// make page statefull
- add(new AjaxSelfUpdatingTimerBehavior(Duration.ONE_DAY));
+ add(new AjaxSelfUpdatingTimerBehavior(Duration.ofDays(1)));
}
@Override
diff --git a/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategyTest.java b/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategyTest.java
index 0d37fbb..21f807f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategyTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategyTest.java
@@ -17,7 +17,7 @@
package org.apache.wicket.request.resource.caching;
import static org.junit.jupiter.api.Assertions.assertEquals;
-
+import java.time.Duration;
import org.apache.wicket.Application;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.request.cycle.RequestCycle;
@@ -28,7 +28,6 @@ import org.apache.wicket.request.resource.caching.version.IResourceVersion;
import org.apache.wicket.request.resource.caching.version.MessageDigestResourceVersion;
import org.apache.wicket.util.tester.BaseWicketTester;
import org.apache.wicket.util.tester.WicketTester;
-import org.apache.wicket.util.time.Duration;
import org.junit.jupiter.api.Test;
/**
@@ -82,7 +81,7 @@ class FilenameWithVersionResourceCachingStrategyTest
@Test
void testDecorateResponse() throws Exception
{
- Duration defaultDuration = Duration.minutes(60);
+ Duration defaultDuration = Duration.ofMinutes(60);
// setup RequestCycle
BaseWicketTester tester = new BaseWicketTester();
diff --git a/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategyTest.java b/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategyTest.java
index 0eabafe..c0268d0 100644
--- a/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategyTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategyTest.java
@@ -18,7 +18,7 @@ package org.apache.wicket.request.resource.caching;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
-
+import java.time.Duration;
import org.apache.wicket.Application;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.request.cycle.RequestCycle;
@@ -30,7 +30,6 @@ import org.apache.wicket.request.resource.caching.version.IResourceVersion;
import org.apache.wicket.request.resource.caching.version.MessageDigestResourceVersion;
import org.apache.wicket.util.tester.BaseWicketTester;
import org.apache.wicket.util.tester.WicketTester;
-import org.apache.wicket.util.time.Duration;
import org.junit.jupiter.api.Test;
/**
@@ -70,7 +69,7 @@ class QueryStringWithVersionResourceCachingStrategyTest
@Test
void testDecorateResponse() throws Exception
{
- Duration defaultDuration = Duration.minutes(60);
+ Duration defaultDuration = Duration.ofMinutes(60);
// setup RequestCycle
BaseWicketTester tester = new BaseWicketTester();
diff --git a/wicket-devutils/src/main/java/org/apache/wicket/devutils/pagestore/browser/PersistedPanel.java b/wicket-devutils/src/main/java/org/apache/wicket/devutils/pagestore/browser/PersistedPanel.java
index 38031df..344a659 100644
--- a/wicket-devutils/src/main/java/org/apache/wicket/devutils/pagestore/browser/PersistedPanel.java
+++ b/wicket-devutils/src/main/java/org/apache/wicket/devutils/pagestore/browser/PersistedPanel.java
@@ -16,10 +16,10 @@
*/
package org.apache.wicket.devutils.pagestore.browser;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-
import org.apache.wicket.PageReference;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -45,7 +45,6 @@ import org.apache.wicket.pageStore.DefaultPageContext;
import org.apache.wicket.pageStore.IPageContext;
import org.apache.wicket.pageStore.IPersistedPage;
import org.apache.wicket.pageStore.IPersistentPageStore;
-import org.apache.wicket.util.time.Duration;
/**
* A panel that shows data about {@link IPersistedPage}s in an {@link IPersistentPageStore}.
@@ -122,7 +121,7 @@ public class PersistedPanel extends GenericPanel<IPersistentPageStore>
}
});
- add(new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
+ add(new AbstractAjaxTimerBehavior(Duration.ofSeconds(5)) {
@Override
protected void onTimer(AjaxRequestTarget target)
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java
index ce4d7a1..194e361 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java
@@ -18,14 +18,13 @@ package org.apache.wicket.examples;
import java.net.InetAddress;
import java.net.UnknownHostException;
-
+import java.time.Duration;
+import org.apache.wicket.core.util.string.JavaScriptUtils;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.response.filter.IResponseFilter;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.AppendingStringBuffer;
-import org.apache.wicket.core.util.string.JavaScriptUtils;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
/**
@@ -89,7 +88,7 @@ public class ServerHostNameAndTimeFilter implements IResponseFilter
script.append("Host: ");
script.append(host);
script.append(", handled in: ");
- script.append(Duration.milliseconds(timeTaken));
+ script.append(Duration.ofMillis(timeTaken));
script.append("';\n");
script.append(JavaScriptUtils.SCRIPT_CLOSE_TAG);
script.append('\n');
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
index fdd43fb..0b1cccc 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
@@ -16,8 +16,8 @@
*/
package org.apache.wicket.examples.ajax.builtin;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
-
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
@@ -31,7 +31,6 @@ import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.request.resource.ResourceStreamResource;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
-import org.apache.wicket.util.time.Duration;
/**
* Ajax download.
@@ -334,7 +333,7 @@ public class AjaxDownloadPage extends BasePage
StaticResource() {
setFileName("File-from-ResourceReference");
setContentDisposition(ContentDisposition.ATTACHMENT);
- setCacheDuration(Duration.NONE);
+ setCacheDuration(Duration.ZERO);
}
@Override
@@ -374,7 +373,7 @@ public class AjaxDownloadPage extends BasePage
this.content = content;
setFileName("File-from-IResource.txt");
- setCacheDuration(Duration.NONE);
+ setCacheDuration(Duration.ZERO);
}
@Override
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/ClockPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/ClockPage.java
index 2d7cbf2..90e8d0d 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/ClockPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/ClockPage.java
@@ -16,10 +16,9 @@
*/
package org.apache.wicket.examples.ajax.builtin;
+import java.time.Duration;
import java.time.ZoneId;
-
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
-import org.apache.wicket.util.time.Duration;
/**
@@ -40,6 +39,6 @@ public class ClockPage extends BasePage
// add the ajax behavior which will keep updating the component every 5
// seconds
- clock.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(5)));
+ clock.add(new AjaxSelfUpdatingTimerBehavior(Duration.ofSeconds(5)));
}
}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/FormPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/FormPage.java
index e9d7405..99ab8a3 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/FormPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/FormPage.java
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.examples.ajax.builtin;
+import java.time.Duration;
import org.apache.wicket.ajax.AjaxPreventSubmitBehavior;
import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
import org.apache.wicket.feedback.ExactLevelFeedbackMessageFilter;
@@ -28,7 +29,6 @@ import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.util.io.IClusterable;
-import org.apache.wicket.util.time.Duration;
import org.apache.wicket.validation.validator.EmailAddressValidator;
import org.apache.wicket.validation.validator.StringValidator;
@@ -102,7 +102,7 @@ public class FormPage extends BasePage
// attach an ajax validation behavior to all form component's keydown
// event and throttle it down to once per second
- form.add(new AjaxFormValidatingBehavior("keydown", Duration.ONE_SECOND));
+ form.add(new AjaxFormValidatingBehavior("keydown", Duration.ofSeconds(1)));
}
private void addFormComponents(final Form<Bean> form) {
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LazyLoadingPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LazyLoadingPage.java
index ba89084..868bbb8 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LazyLoadingPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LazyLoadingPage.java
@@ -16,8 +16,8 @@
*/
package org.apache.wicket.examples.ajax.builtin;
+import java.time.Duration;
import java.util.Random;
-
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
@@ -25,7 +25,6 @@ import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.RepeatingView;
-import org.apache.wicket.util.time.Duration;
@SuppressWarnings({ "javadoc", "serial" })
public class LazyLoadingPage extends BasePage
@@ -103,14 +102,14 @@ public class LazyLoadingPage extends BasePage
@Override
protected boolean isContentReady()
{
- return Duration.milliseconds(System.currentTimeMillis() - startTime)
- .seconds() > seconds;
+ return Duration.ofMillis(System.currentTimeMillis() - startTime)
+ .toSeconds() > seconds;
}
@Override
protected Duration getUpdateInterval()
{
- return Duration.milliseconds(seconds * 1000 / 10);
+ return Duration.ofMillis(seconds * 1000 / 10);
}
@Override
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/WorldClockPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/WorldClockPage.java
index 80f95dd..5f7a687 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/WorldClockPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/WorldClockPage.java
@@ -17,12 +17,10 @@
package org.apache.wicket.examples.ajax.builtin;
import static org.apache.wicket.ajax.AbstractAjaxTimerBehavior.onTimer;
-
+import java.time.Duration;
import java.time.ZoneId;
-
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.util.time.Duration;
/**
@@ -57,7 +55,7 @@ public class WorldClockPage extends BasePage
// add the timer behavior to the page and make it update all
// other components as well
- final AbstractAjaxTimerBehavior timer = onTimer(Duration.seconds(1), target -> target.add(la, ny, moscow, prague, london));
+ final AbstractAjaxTimerBehavior timer = onTimer(Duration.ofSeconds(1), target -> target.add(la, ny, moscow, prague, london));
add(timer);
add(new AjaxLink<Void>("stop") {
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/Home.java b/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/Home.java
index 95ce343..a9fae1a 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/Home.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/Home.java
@@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-
+import java.time.Duration;
import org.apache.wicket.Component;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.html.basic.Label;
@@ -44,7 +44,6 @@ import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.SharedResourceReference;
import org.apache.wicket.util.file.Files;
-import org.apache.wicket.util.time.Duration;
/**
@@ -171,7 +170,7 @@ public class Home extends WicketExamplePage
return tempFile;
}
- }, "Downlöad\"here now.tmp").setCacheDuration(Duration.NONE).setDeleteAfterDownload(true));
+ }, "Downlöad\"here now.tmp").setCacheDuration(Duration.ZERO).setDeleteAfterDownload(true));
// redirect to external url form
FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/resourcedecoration/HomePage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/resourcedecoration/HomePage.java
index 172a98a..b1a0445 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/resourcedecoration/HomePage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/resourcedecoration/HomePage.java
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.examples.resourcedecoration;
+import java.time.Duration;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -34,7 +35,6 @@ import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.resource.JQueryPluginResourceReference;
-import org.apache.wicket.util.time.Duration;
/**
* A demo page showing how to render grouped resources
@@ -70,7 +70,7 @@ public class HomePage extends WicketExamplePage
add(jsPlaceholder);
add(new AjaxProofContainer("ajaxProofPlaceholder"));
- add(new AbstractAjaxTimerBehavior(Duration.seconds(4))
+ add(new AbstractAjaxTimerBehavior(Duration.ofSeconds(4))
{
private static final long serialVersionUID = 1L;
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/WebSocketBehaviorDemoPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/WebSocketBehaviorDemoPage.java
index d27bf29..8d038aa 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/WebSocketBehaviorDemoPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/WebSocketBehaviorDemoPage.java
@@ -16,8 +16,8 @@
*/
package org.apache.wicket.examples.websocket;
+import java.time.Duration;
import java.util.concurrent.ScheduledExecutorService;
-
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.examples.WicketExamplePage;
@@ -35,7 +35,6 @@ import org.apache.wicket.request.resource.IResource;
import org.apache.wicket.request.resource.ResourceStreamResource;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
-import org.apache.wicket.util.time.Duration;
@RequireHttps
public class WebSocketBehaviorDemoPage extends WicketExamplePage
@@ -59,7 +58,7 @@ public class WebSocketBehaviorDemoPage extends WicketExamplePage
}
}.setContentDisposition(ContentDisposition.ATTACHMENT)
.setFileName("File-from-IResource.txt")
- .setCacheDuration(Duration.NONE);
+ .setCacheDuration(Duration.ZERO);
final AjaxDownloadBehavior download = new AjaxDownloadBehavior(resource)
{
diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
index 85b27c3..2a6e1cf 100644
--- a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
+++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
@@ -18,19 +18,17 @@ package org.apache.wicket.http2.markup.head;
import java.io.IOException;
import java.net.URL;
+import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
-import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
-
import javax.servlet.http.HttpServletRequest;
-
import org.apache.wicket.Application;
import org.apache.wicket.Page;
import org.apache.wicket.WicketRuntimeException;
@@ -49,7 +47,6 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.mapper.parameter.PageParametersEncoder;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.collections.ConcurrentHashSet;
-import org.apache.wicket.util.time.Time;
/**
* A push header item to be used in the http/2 context and to reduce the latency of the web
@@ -173,7 +170,7 @@ public class PushHeaderItem extends HeaderItem
*
* @return the time the page of this header item has been modified
*/
- protected Time getPageModificationTime()
+ protected Instant getPageModificationTime()
{
URL resource = page.getClass().getResource(page.getClass().getSimpleName() + ".html");
if (resource == null)
@@ -183,7 +180,7 @@ public class PushHeaderItem extends HeaderItem
}
try
{
- return Time.valueOf(new Date(resource.openConnection().getLastModified()));
+ return Instant.ofEpochMilli(resource.openConnection().getLastModified());
}
catch (IOException e)
{
@@ -200,9 +197,9 @@ public class PushHeaderItem extends HeaderItem
protected void applyPageCacheHeader()
{
// check modification of page html
- Time pageModificationTime = getPageModificationTime();
+ Instant pageModificationTime = getPageModificationTime();
// The date of the page is now
- pageWebResponse.setDateHeader("Date", Time.now());
+ pageWebResponse.setDateHeader("Date", Instant.now());
// Set the modification time so that the browser sends a "If-Modified-Since" header which
// can be compared
pageWebResponse.setLastModifiedTime(pageModificationTime);
@@ -229,7 +226,7 @@ public class PushHeaderItem extends HeaderItem
if (isHttp2(request))
{
- Time pageModificationTime = getPageModificationTime();
+ Instant pageModificationTime = getPageModificationTime();
String ifModifiedSinceHeader = pageWebRequest.getHeader("If-Modified-Since");
// Check if the if-modified-since header is set - if not push all resources
@@ -237,7 +234,7 @@ public class PushHeaderItem extends HeaderItem
{
// Try to parse RFC1123
- Time ifModifiedSinceFromRequestTime = parseIfModifiedSinceHeader(
+ Instant ifModifiedSinceFromRequestTime = parseIfModifiedSinceHeader(
ifModifiedSinceHeader, headerDateFormat_RFC1123);
// Try to parse ASCTIME
@@ -257,7 +254,7 @@ public class PushHeaderItem extends HeaderItem
// if the modified since header is before the page modification time or if it can't
// be parsed push it.
if (ifModifiedSinceFromRequestTime == null ||
- ifModifiedSinceFromRequestTime.before(pageModificationTime))
+ ifModifiedSinceFromRequestTime.isBefore(pageModificationTime))
{
// Some browsers like IE 9-11 or Chrome 39 that does not send right headers
// receive the resource via push all the time
@@ -281,13 +278,14 @@ public class PushHeaderItem extends HeaderItem
* the formatter to parse the header string with
* @return the time or null
*/
- private Time parseIfModifiedSinceHeader(String ifModifiedSinceHeader,
+ private Instant parseIfModifiedSinceHeader(String ifModifiedSinceHeader,
DateTimeFormatter dateTimeFormatter)
{
try
{
- return Time.valueOf(Date.from(LocalDateTime
- .parse(ifModifiedSinceHeader, dateTimeFormatter).toInstant(ZoneOffset.UTC)));
+ return LocalDateTime
+ .parse(ifModifiedSinceHeader, dateTimeFormatter)
+ .toInstant(ZoneOffset.UTC);
}
catch (DateTimeParseException e)
{
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
index cdf39ab..ff715aa 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
@@ -16,9 +16,9 @@
*/
package org.apache.wicket.extensions.ajax.markup.html;
+import java.time.Duration;
import java.util.List;
import java.util.Optional;
-
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
@@ -29,7 +29,7 @@ import org.apache.wicket.model.IModel;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
-import org.apache.wicket.util.time.Duration;
+import org.apache.wicket.util.lang.Comparators;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
@@ -187,7 +187,7 @@ public abstract class AjaxLazyLoadPanel<T extends Component> extends Panel
* @return update interval, must not be {@value null}
*/
protected Duration getUpdateInterval() {
- return Duration.seconds(1);
+ return Duration.ofSeconds(1);
}
/**
@@ -239,7 +239,7 @@ public abstract class AjaxLazyLoadPanel<T extends Component> extends Panel
public AjaxLazyLoadTimer()
{
- super(Duration.ONE_SECOND);
+ super(Duration.ofSeconds(1));
}
@Override
@@ -250,7 +250,7 @@ public abstract class AjaxLazyLoadPanel<T extends Component> extends Panel
public void load(AjaxRequestTarget target)
{
- setUpdateInterval(Duration.MAXIMUM);
+ setUpdateInterval(Duration.ofMillis(Long.MAX_VALUE));
getComponent().getPage().visitChildren(AjaxLazyLoadPanel.class, new IVisitor<AjaxLazyLoadPanel<?>, Void>()
{
@@ -263,13 +263,13 @@ public abstract class AjaxLazyLoadPanel<T extends Component> extends Panel
throw new IllegalArgumentException("update interval must not ben null");
}
- setUpdateInterval(Duration.min(getUpdateInterval(), updateInterval));
+ setUpdateInterval(Comparators.min(getUpdateInterval(), updateInterval));
}
}
});
// all panels have completed their replacements, we can stop the timer
- if (Duration.MAXIMUM.equals(getUpdateInterval()))
+ if (Duration.ofMillis(Long.MAX_VALUE).equals(getUpdateInterval()))
{
stop(target);
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
index b136707..b4775f2 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
@@ -21,7 +21,7 @@ import java.util.List;
import org.apache.wicket.Page;
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel.AjaxLazyLoadTimer;
import org.apache.wicket.util.tester.BaseWicketTester;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadStatusResource.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadStatusResource.java
index 92d9a4b..bd0a366 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadStatusResource.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadStatusResource.java
@@ -16,8 +16,8 @@
*/
package org.apache.wicket.extensions.ajax.markup.html.form.upload;
+import java.time.Duration;
import javax.servlet.http.HttpServletRequest;
-
import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.model.Model;
@@ -26,7 +26,6 @@ import org.apache.wicket.protocol.http.servlet.MultipartServletWebRequestImpl;
import org.apache.wicket.protocol.http.servlet.UploadInfo;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.AbstractResource;
-import org.apache.wicket.util.time.Duration;
/**
* A resource that prints out basic statistics about the current upload. This resource is used to
@@ -63,7 +62,7 @@ class UploadStatusResource extends AbstractResource
ResourceResponse response = new ResourceResponse();
response.setContentType("text/html; charset=" + encoding);
- response.setCacheDuration(Duration.NONE);
+ response.setCacheDuration(Duration.ZERO);
final String status = getStatus(attributes);
response.setWriteCallback(new WriteCallback()
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
index efe7d82..287573d 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
@@ -24,14 +24,13 @@ import java.awt.image.RescaleOp;
import java.io.IOException;
import java.io.Serializable;
import java.lang.ref.SoftReference;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
-
import javax.imageio.ImageIO;
import javax.imageio.stream.MemoryCacheImageInputStream;
-
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -49,7 +48,6 @@ import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.DynamicImageResource;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -428,7 +426,7 @@ public class KittenCaptchaPanel extends Panel
protected byte[] getImageData(final Attributes attributes)
{
// Handle caching
- setLastModifiedTime(Time.now());
+ setLastModifiedTime(Instant.now());
final WebResponse response = (WebResponse)RequestCycle.get().getResponse();
response.setHeader("Cache-Control", "no-cache, must-revalidate, max-age=0, no-store");
@@ -466,7 +464,7 @@ public class KittenCaptchaPanel extends Panel
private void clearData()
{
invalidate();
- setLastModifiedTime(Time.now());
+ setLastModifiedTime(Instant.now());
}
/**
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/captcha/CaptchaImageResource.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/captcha/CaptchaImageResource.java
index 3208116..01e0561 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/captcha/CaptchaImageResource.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/captcha/CaptchaImageResource.java
@@ -31,16 +31,15 @@ import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
-
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.resource.DynamicImageResource;
import org.apache.wicket.util.io.IClusterable;
-import org.apache.wicket.util.time.Time;
/**
@@ -254,7 +253,7 @@ public class CaptchaImageResource extends DynamicImageResource
{
data = render();
imageData = new SoftReference<>(data);
- setLastModifiedTime(Time.now());
+ setLastModifiedTime(Instant.now());
}
return data;
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/image/resource/ThumbnailImageResource.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/image/resource/ThumbnailImageResource.java
index e80ef29..1f9bb17 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/image/resource/ThumbnailImageResource.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/image/resource/ThumbnailImageResource.java
@@ -22,16 +22,14 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-
+import java.time.Instant;
import javax.imageio.ImageIO;
-
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.request.resource.DynamicImageResource;
import org.apache.wicket.request.resource.IResource;
import org.apache.wicket.response.ByteArrayResponse;
import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
/**
* Image resource that dynamically scales the given original resource to a thumbnail. It is scaled
@@ -81,7 +79,7 @@ public class ThumbnailImageResource extends DynamicImageResource
{
final BufferedImage image = getScaledImageInstance(attributes);
thumbnail = toImageData(image);
- setLastModifiedTime(Time.now());
+ setLastModifiedTime(Instant.now());
}
return thumbnail;
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/export/ExportToolbar.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/export/ExportToolbar.java
index 1763848..8b2bca4 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/export/ExportToolbar.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/export/ExportToolbar.java
@@ -18,9 +18,9 @@ package org.apache.wicket.extensions.markup.html.repeater.data.table.export;
import java.io.IOException;
import java.io.OutputStream;
+import java.time.Duration;
import java.util.LinkedList;
import java.util.List;
-
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar;
@@ -39,7 +39,6 @@ import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.IResourceStreamWriter;
-import org.apache.wicket.util.time.Duration;
/**
* A toolbar that provides links to download the data represented by all {@link IExportableColumn}s in the table
@@ -230,7 +229,7 @@ public class ExportToolbar extends AbstractToolbar
* @return default is {@link Duration#NONE}
*/
protected Duration getCacheDuration() {
- return Duration.NONE;
+ return Duration.ZERO;
}
@Override
diff --git a/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestCycleSettingsMBean.java b/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestCycleSettingsMBean.java
index b4393bf..c11f396 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestCycleSettingsMBean.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestCycleSettingsMBean.java
@@ -17,6 +17,7 @@
package org.apache.wicket.jmx;
import java.io.UnsupportedEncodingException;
+import java.time.Duration;
import org.apache.wicket.markup.html.pages.BrowserInfoPage;
@@ -57,7 +58,7 @@ public interface RequestCycleSettingsMBean
*
* @return The time out
*/
- String getTimeout();
+ Duration getTimeout();
/**
* @param bufferResponse
@@ -97,7 +98,7 @@ public interface RequestCycleSettingsMBean
*
* @param timeout
*/
- void setTimeout(String timeout);
+ void setTimeout(Duration timeout);
/**
diff --git a/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettingsMBean.java b/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettingsMBean.java
index f1dfa61..7847f6b 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettingsMBean.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettingsMBean.java
@@ -17,7 +17,6 @@
package org.apache.wicket.jmx;
import org.apache.wicket.markup.html.PackageResourceGuard;
-import org.apache.wicket.util.time.Duration;
/**
* Resource settings.
diff --git a/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/RequestCycleSettings.java b/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/RequestCycleSettings.java
index b5707dc..028ec6a 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/RequestCycleSettings.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/RequestCycleSettings.java
@@ -17,10 +17,10 @@
package org.apache.wicket.jmx.wrapper;
import java.io.UnsupportedEncodingException;
+import java.time.Duration;
import org.apache.wicket.Application;
import org.apache.wicket.jmx.RequestCycleSettingsMBean;
-import org.apache.wicket.util.time.Duration;
/**
@@ -73,9 +73,9 @@ public class RequestCycleSettings implements RequestCycleSettingsMBean
* @see org.apache.wicket.jmx.RequestCycleSettingsMBean#getTimeout()
*/
@Override
- public String getTimeout()
+ public Duration getTimeout()
{
- return application.getRequestCycleSettings().getTimeout().toString();
+ return application.getRequestCycleSettings().getTimeout();
}
/**
@@ -117,9 +117,9 @@ public class RequestCycleSettings implements RequestCycleSettingsMBean
* @see org.apache.wicket.jmx.RequestCycleSettingsMBean#setTimeout(java.lang.String)
*/
@Override
- public void setTimeout(final String timeout)
+ public void setTimeout(final Duration timeout)
{
- application.getRequestCycleSettings().setTimeout(Duration.valueOf(timeout));
+ application.getRequestCycleSettings().setTimeout(timeout);
}
@Override
diff --git a/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/ResourceSettings.java b/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/ResourceSettings.java
index 863804d..9285907 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/ResourceSettings.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/wrapper/ResourceSettings.java
@@ -16,14 +16,13 @@
*/
package org.apache.wicket.jmx.wrapper;
+import java.time.Duration;
import java.util.List;
-
import org.apache.wicket.Application;
import org.apache.wicket.jmx.ResourceSettingsMBean;
import org.apache.wicket.resource.loader.IStringResourceLoader;
import org.apache.wicket.util.file.IResourceFinder;
import org.apache.wicket.util.lang.Generics;
-import org.apache.wicket.util.time.Duration;
/**
diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java
index 1296325..325eeab 100644
--- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java
+++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java
@@ -18,12 +18,10 @@ package org.apache.wicket.protocol.ws.api;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-
+import java.time.Instant;
import javax.servlet.http.Cookie;
-
import org.apache.wicket.request.Response;
import org.apache.wicket.request.http.WebResponse;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -164,7 +162,7 @@ public class WebSocketResponse extends WebResponse
}
@Override
- public void setDateHeader(String name, Time date)
+ public void setDateHeader(String name, Instant date)
{
throw new UnsupportedOperationException();
}
diff --git a/wicket-request/src/main/java/org/apache/wicket/request/HttpHeaderCollection.java b/wicket-request/src/main/java/org/apache/wicket/request/HttpHeaderCollection.java
index 126e8d1..adbb68e 100644
--- a/wicket-request/src/main/java/org/apache/wicket/request/HttpHeaderCollection.java
+++ b/wicket-request/src/main/java/org/apache/wicket/request/HttpHeaderCollection.java
@@ -16,6 +16,8 @@
*/
package org.apache.wicket.request;
+import java.sql.Time;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -25,9 +27,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-
import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.time.Time;
+import org.apache.wicket.util.time.Instants;
/**
* A multivalue map of headers names and header values suitable for processing http request and
@@ -115,7 +116,7 @@ public class HttpHeaderCollection
* @param time
* timestamp
*/
- public void addDateHeader(String name, Time time)
+ public void addDateHeader(String name, Instant time)
{
internalAdd(name, time);
}
@@ -128,7 +129,7 @@ public class HttpHeaderCollection
* @param time
* timestamp
*/
- public void setDateHeader(String name, Time time)
+ public void setDateHeader(String name, Instant time)
{
// remove previous values
removeHeader(name);
@@ -161,9 +162,9 @@ public class HttpHeaderCollection
private String valueToString(Object value)
{
- if (value instanceof Time)
+ if (value instanceof Instant)
{
- return ((Time)value).toRfc1123TimestampString();
+ return Instants.toRFC7231Format((Instant)value);
}
else
{
@@ -261,7 +262,7 @@ public class HttpHeaderCollection
* @param name
* @return {@code null} when the header was not found
*/
- public Time getDateHeader(String name)
+ public Instant getDateHeader(String name)
{
final List<Object> objects = headers.get(new HeaderKey(name));
@@ -271,11 +272,11 @@ public class HttpHeaderCollection
}
Object object = objects.get(0);
- if ((object instanceof Time) == false)
+ if ((object instanceof Instant) == false)
{
throw new IllegalStateException("header value is not of type date");
}
- return (Time)object;
+ return (Instant)object;
}
/**
diff --git a/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java b/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
index 1ac1596..f1ef967 100644
--- a/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
+++ b/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
@@ -17,17 +17,15 @@
package org.apache.wicket.request.http;
import java.nio.charset.Charset;
+import java.time.Instant;
import java.util.List;
import java.util.Locale;
-
import javax.servlet.http.Cookie;
-
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Url;
import org.apache.wicket.util.string.StringValueConversionException;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
/**
* Base class for request that provides additional web-related information.
@@ -97,14 +95,14 @@ public abstract class WebRequest extends Request
* @param name
* @return date value of request header or <code>null</code> if not found
*/
- public abstract Time getDateHeader(String name);
+ public abstract Instant getDateHeader(String name);
/**
* Convenience method for retrieving If-Modified-Since header.
*
* @return date representing the header or <code>null</code> if not set
*/
- public final Time getIfModifiedSinceHeader()
+ public final Instant getIfModifiedSinceHeader()
{
return getDateHeader("If-Modified-Since");
}
@@ -181,7 +179,7 @@ public abstract class WebRequest extends Request
}
@Override
- public Time getDateHeader(final String name)
+ public Instant getDateHeader(final String name)
{
return WebRequest.this.getDateHeader(name);
}
diff --git a/wicket-request/src/main/java/org/apache/wicket/request/http/WebResponse.java b/wicket-request/src/main/java/org/apache/wicket/request/http/WebResponse.java
index 5b508f7..322f4ff 100644
--- a/wicket-request/src/main/java/org/apache/wicket/request/http/WebResponse.java
+++ b/wicket-request/src/main/java/org/apache/wicket/request/http/WebResponse.java
@@ -17,15 +17,13 @@
package org.apache.wicket.request.http;
import java.io.IOException;
-
+import java.time.Duration;
+import java.time.Instant;
import javax.servlet.http.Cookie;
-
import org.apache.wicket.request.Response;
import org.apache.wicket.util.encoding.UrlEncoder;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
* Base class for web-related responses.
@@ -36,7 +34,7 @@ public abstract class WebResponse extends Response
{
/** Recommended value for cache duration */
// one year, maximum recommended cache duration in RFC-2616
- public static final Duration MAX_CACHE_DURATION = Duration.days(365);
+ public static final Duration MAX_CACHE_DURATION = Duration.ofDays(365);
/**
* Add a cookie to the web response
@@ -76,7 +74,7 @@ public abstract class WebResponse extends Response
* @param name
* @param date
*/
- public abstract void setDateHeader(String name, Time date);
+ public abstract void setDateHeader(String name, Instant date);
/**
* Set the content length on the response, if appropriate in the subclass. This default
@@ -128,7 +126,7 @@ public abstract class WebResponse extends Response
* @param time
* The last modified time
*/
- public void setLastModifiedTime(final Time time)
+ public void setLastModifiedTime(final Instant time)
{
setDateHeader("Last-Modified", time);
}
@@ -230,8 +228,8 @@ public abstract class WebResponse extends Response
*/
public void disableCaching()
{
- setDateHeader("Date", Time.now());
- setDateHeader("Expires", Time.START_OF_UNIX_TIME);
+ setDateHeader("Date", Instant.now());
+ setDateHeader("Expires", Instant.EPOCH);
setHeader("Pragma", "no-cache");
setHeader("Cache-Control", "no-cache, no-store");
}
@@ -263,19 +261,19 @@ public abstract class WebResponse extends Response
}
// Get current time
- Time now = Time.now();
+ Instant now = Instant.now();
// Time of message generation
setDateHeader("Date", now);
// Time for cache expiry = now + duration
- setDateHeader("Expires", now.add(duration));
+ setDateHeader("Expires", now.plus(duration));
// Set cache scope
setHeader("Cache-Control", scope.cacheControl);
// Set maximum age for caching in seconds (rounded)
- addHeader("Cache-Control", "max-age=" + Math.round(duration.seconds()));
+ addHeader("Cache-Control", "max-age=" + Math.round(duration.getSeconds()));
// Though 'cache' is not an official value it will eliminate an eventual 'no-cache' header
setHeader("Pragma", "cache");
diff --git a/wicket-request/src/test/java/org/apache/wicket/request/HttpHeaderCollectionTest.java b/wicket-request/src/test/java/org/apache/wicket/request/HttpHeaderCollectionTest.java
index faabc4b..6d5e35f 100644
--- a/wicket-request/src/test/java/org/apache/wicket/request/HttpHeaderCollectionTest.java
+++ b/wicket-request/src/test/java/org/apache/wicket/request/HttpHeaderCollectionTest.java
@@ -22,12 +22,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-
+import java.time.Instant;
import java.util.Locale;
import java.util.Set;
import java.util.TimeZone;
-
-import org.apache.wicket.util.time.Time;
import org.junit.jupiter.api.Test;
@SuppressWarnings("javadoc")
@@ -89,8 +87,8 @@ public class HttpHeaderCollectionTest
{
final HttpHeaderCollection headers = new HttpHeaderCollection();
- final Time time1 = Time.millis(1000000);
- final Time time2 = Time.millis(2000000);
+ final Instant time1 = Instant.ofEpochMilli(1000000);
+ final Instant time2 = Instant.ofEpochMilli(2000000);
headers.setDateHeader("date", time1);
headers.addDateHeader("date", time2);
@@ -128,7 +126,7 @@ public class HttpHeaderCollectionTest
headers.setHeader("date", "foobar");
try
{
- Time date = headers.getDateHeader("date");
+ Instant date = headers.getDateHeader("date");
fail();
}
catch (IllegalStateException e)
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/file/File.java b/wicket-util/src/main/java/org/apache/wicket/util/file/File.java
index b48bbde..00d52f7 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/file/File.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/file/File.java
@@ -29,9 +29,8 @@ import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.URI;
-
+import java.time.Instant;
import org.apache.wicket.util.io.Streams;
-import org.apache.wicket.util.time.Time;
import org.apache.wicket.util.watch.IModifiable;
@@ -167,7 +166,7 @@ public class File extends java.io.File implements IModifiable
* that information is not available
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
final long time = lastModified();
@@ -175,7 +174,7 @@ public class File extends java.io.File implements IModifiable
{
return null;
}
- return Time.millis(time);
+ return Instant.ofEpochMilli(time);
}
/**
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java b/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
index 8091dd8..11bfccd 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
@@ -24,13 +24,12 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-
+import java.time.Instant;
import org.apache.wicket.util.encoding.UrlDecoder;
import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.io.Streams;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -413,7 +412,7 @@ public class Files
*
* @return timestamp
*/
- public static Time getLastModified(File file)
+ public static Instant getLastModified(File file)
{
// get file modification timestamp
long millis = file.lastModified();
@@ -425,7 +424,7 @@ public class Files
}
// last file modification timestamp
- return Time.millis(millis);
+ return Instant.ofEpochMilli(millis);
}
/**
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/io/Connections.java b/wicket-util/src/main/java/org/apache/wicket/util/io/Connections.java
index 167cefd..13d50c2 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/io/Connections.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/io/Connections.java
@@ -22,9 +22,8 @@ import java.net.HttpURLConnection;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
-
+import java.time.Instant;
import org.apache.wicket.util.file.Files;
-import org.apache.wicket.util.time.Time;
/**
* {@link URLConnection} related utilities
@@ -44,7 +43,7 @@ public class Connections
* @return last modified timestamp or <code>null</code> if not available
* @throws IOException
*/
- public static Time getLastModified(final URL url) throws IOException
+ public static Instant getLastModified(final URL url) throws IOException
{
// check if url points to a local file
final File file = Files.getLocalFileFromUrl(url);
@@ -84,7 +83,7 @@ public class Connections
}
// return UNIX timestamp
- return Time.millis(milliseconds);
+ return Instant.ofEpochMilli(milliseconds);
}
finally
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java b/wicket-util/src/main/java/org/apache/wicket/util/lang/Comparators.java
similarity index 53%
rename from wicket-util/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java
rename to wicket-util/src/main/java/org/apache/wicket/util/lang/Comparators.java
index e7cea80..b209f89 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/lang/Comparators.java
@@ -14,33 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.wicket.util.time;
+package org.apache.wicket.util.lang;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Test cases for {@link TimeOfDay}.
- *
- * @author Jonathan Locke
- */
-public final class TimeOfDayTest
+public class Comparators
{
- /**
- *
- */
- @Test
- public void test()
- {
- assertEquals(0, TimeOfDay.MIDNIGHT.hour());
- assertEquals(21, TimeOfDay.time(9, 30, TimeOfDay.PM).hour());
- assertEquals(TimeOfDay.MIDNIGHT, TimeOfDay.valueOf(TimeOfDay.MIDNIGHT.next()));
- final TimeOfDay three = TimeOfDay.time(3, 0, TimeOfDay.PM);
- final TimeOfDay five = TimeOfDay.time(5, 0, TimeOfDay.PM);
+ public static <T extends Comparable<? super T>> T min(T firstComp, T secondComp)
+ {
+ return firstComp.compareTo(secondComp) < 0 ? firstComp : secondComp;
+ }
- assertTrue(five.after(three));
- }
+ public static <T extends Comparable<? super T>> T max(T firstComp, T secondComp)
+ {
+ return firstComp.compareTo(secondComp) > 0 ? firstComp : secondComp;
+ }
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStream.java
index a4ec5d4..e061463 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStream.java
@@ -16,10 +16,9 @@
*/
package org.apache.wicket.util.resource;
+import java.time.Instant;
import java.util.Locale;
-
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
/**
@@ -84,7 +83,7 @@ public abstract class AbstractResourceStream implements IResourceStream
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return null;
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java
index abbd3db..ef93536 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java
@@ -18,10 +18,9 @@ package org.apache.wicket.util.resource;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Instant;
import java.util.Locale;
-
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
/**
* Base implementation of an IResourceStreamWriter so that you only have to override the
@@ -67,9 +66,9 @@ public abstract class AbstractResourceStreamWriter implements IResourceStreamWri
* Just returns now.
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
- return Time.now();
+ return Instant.now();
}
/**
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
index a0489ef..1b6bc43 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
@@ -23,12 +23,11 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
-
+import java.time.Instant;
import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.io.Streams;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.time.Time;
/**
@@ -52,7 +51,7 @@ public abstract class AbstractStringResourceStream extends AbstractResourceStrea
private final String contentType;
/** The last time this stylesheet was modified */
- private Time lastModified = null;
+ private Instant lastModified = null;
/**
* Constructor.
@@ -73,7 +72,7 @@ public abstract class AbstractStringResourceStream extends AbstractResourceStrea
// TODO null for contentType is allowed? or should the default be applied instead?
this.contentType = contentType;
- lastModified = Time.now();
+ lastModified = Instant.now();
}
/**
@@ -178,7 +177,7 @@ public abstract class AbstractStringResourceStream extends AbstractResourceStrea
* @see org.apache.wicket.util.watch.IModifiable#lastModifiedTime()
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return lastModified;
}
@@ -187,7 +186,7 @@ public abstract class AbstractStringResourceStream extends AbstractResourceStrea
* @param lastModified
* The lastModified to set.
*/
- public void setLastModified(final Time lastModified)
+ public void setLastModified(final Instant lastModified)
{
this.lastModified = lastModified;
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/FileResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/FileResourceStream.java
index 499df49..87e2b20 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/FileResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/FileResourceStream.java
@@ -21,11 +21,10 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
-
+import java.time.Instant;
import org.apache.wicket.util.file.File;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
/**
@@ -134,7 +133,7 @@ public class FileResourceStream extends AbstractResourceStream
* @return The last time this resource was modified
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
if (file != null)
{
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/FileSystemResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/FileSystemResourceStream.java
index 12ef3eb..aae172b 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/FileSystemResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/FileSystemResourceStream.java
@@ -23,11 +23,10 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
-
+import java.time.Instant;
import org.apache.wicket.util.file.File;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
/**
* A FileSystemResourceStream is an IResourceStream implementation for Java NIO paths.
@@ -140,14 +139,14 @@ public class FileSystemResourceStream extends AbstractResourceStream
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
try
{
BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
FileTime lastModifiedTime = attributes.lastModifiedTime();
long millis = lastModifiedTime.toMillis();
- return Time.millis(millis);
+ return Instant.ofEpochMilli(millis);
}
catch (IOException e)
{
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceStreamWrapper.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceStreamWrapper.java
index d0c23b6..bc5a611 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceStreamWrapper.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceStreamWrapper.java
@@ -18,11 +18,10 @@ package org.apache.wicket.util.resource;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Instant;
import java.util.Locale;
-
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
/**
* A IResourceStream that wraps another resource stream
@@ -114,7 +113,7 @@ public class ResourceStreamWrapper implements IResourceStream
}
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return delegate.lastModifiedTime();
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
index 8ae3551..c95a297 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
@@ -16,8 +16,8 @@
*/
package org.apache.wicket.util.resource;
+import java.time.Instant;
import org.apache.wicket.util.string.AppendingStringBuffer;
-import org.apache.wicket.util.time.Time;
/**
* A string resource that can be appended to.
@@ -59,7 +59,7 @@ public class StringBufferResourceStream extends AbstractStringResourceStream
public StringBufferResourceStream append(final CharSequence s)
{
buffer.append(s);
- setLastModified(Time.now());
+ setLastModified(Instant.now());
return this;
}
@@ -73,7 +73,7 @@ public class StringBufferResourceStream extends AbstractStringResourceStream
public StringBufferResourceStream prepend(final CharSequence s)
{
buffer.insert(0, s);
- setLastModified(Time.now());
+ setLastModified(Instant.now());
return this;
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/XSLTResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/XSLTResourceStream.java
index 9e74cbb..5fe6250 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/XSLTResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/XSLTResourceStream.java
@@ -20,12 +20,11 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Instant;
import java.util.Map;
import java.util.Map.Entry;
-
import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
/**
* {@link IResourceStream} that applies XSLT on an input {@link IResourceStream}. The XSL stylesheet
@@ -146,7 +145,7 @@ public class XSLTResourceStream extends AbstractResourceStream
* @see org.apache.wicket.util.watch.IModifiable#lastModifiedTime()
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return null;
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java
index 270dd67..d0b46f2 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java
@@ -22,13 +22,12 @@ import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.time.Instant;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-
import org.apache.wicket.util.file.File;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -214,7 +213,7 @@ public class ZipResourceStream extends AbstractResourceStream
* @see org.apache.wicket.util.resource.AbstractResourceStream#lastModifiedTime()
*/
@Override
- public Time lastModifiedTime()
+ public Instant lastModifiedTime()
{
return null;
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java b/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
index 1f94e55..bb5cc86 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
@@ -20,13 +20,14 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.ParseException;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
import java.util.Locale;
import org.apache.wicket.util.io.IClusterable;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Objects;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -220,7 +221,7 @@ public class StringValue implements IClusterable
*/
protected StringValue(final String text)
{
- this(text , Locale.getDefault());
+ this(text, Locale.getDefault());
}
/**
@@ -346,9 +347,9 @@ public class StringValue implements IClusterable
return (T)toCharacter();
}
- if (type == Time.class)
+ if (type == Instant.class)
{
- return (T)toTime();
+ return (T)toInstant();
}
if (type == Duration.class)
@@ -361,8 +362,8 @@ public class StringValue implements IClusterable
return (T)toEnum((Class)type);
}
- throw new StringValueConversionException("Cannot convert '" + toString() + "'to type "
- + type);
+ throw new StringValueConversionException(
+ "Cannot convert '" + toString() + "'to type " + type);
}
/**
@@ -410,9 +411,10 @@ public class StringValue implements IClusterable
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to a boolean: %s", text,
- x.getMessage()), x);
+ LOG.debug(
+ String.format("An error occurred while converting '%s' to a boolean: %s",
+ text, x.getMessage()),
+ x);
}
}
}
@@ -461,9 +463,10 @@ public class StringValue implements IClusterable
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to a character: %s", text,
- x.getMessage()), x);
+ LOG.debug(
+ String.format("An error occurred while converting '%s' to a character: %s",
+ text, x.getMessage()),
+ x);
}
}
}
@@ -495,8 +498,8 @@ public class StringValue implements IClusterable
}
catch (ParseException e)
{
- throw new StringValueConversionException("Unable to convert '" + text
- + "' to a double value", e);
+ throw new StringValueConversionException(
+ "Unable to convert '" + text + "' to a double value", e);
}
}
@@ -519,9 +522,10 @@ public class StringValue implements IClusterable
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to a double: %s", text,
- x.getMessage()), x);
+ LOG.debug(
+ String.format("An error occurred while converting '%s' to a double: %s",
+ text, x.getMessage()),
+ x);
}
}
}
@@ -548,7 +552,14 @@ public class StringValue implements IClusterable
*/
public final Duration toDuration() throws StringValueConversionException
{
- return Duration.valueOf(text, locale);
+ try
+ {
+ return Duration.parse(text);
+ }
+ catch (Exception e)
+ {
+ throw new StringValueConversionException("xxx", e);
+ }
}
/**
@@ -572,9 +583,10 @@ public class StringValue implements IClusterable
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to a Duration: %s", text,
- x.getMessage()), x);
+ LOG.debug(
+ String.format("An error occurred while converting '%s' to a Duration: %s",
+ text, x.getMessage()),
+ x);
}
}
}
@@ -595,8 +607,8 @@ public class StringValue implements IClusterable
}
catch (NumberFormatException e)
{
- throw new StringValueConversionException("Unable to convert '" + text
- + "' to an int value", e);
+ throw new StringValueConversionException(
+ "Unable to convert '" + text + "' to an int value", e);
}
}
@@ -619,9 +631,10 @@ public class StringValue implements IClusterable
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to an integer: %s", text,
- x.getMessage()), x);
+ LOG.debug(
+ String.format("An error occurred while converting '%s' to an integer: %s",
+ text, x.getMessage()),
+ x);
}
}
}
@@ -642,8 +655,8 @@ public class StringValue implements IClusterable
}
catch (NumberFormatException e)
{
- throw new StringValueConversionException("Unable to convert '" + text
- + "' to an Integer value", e);
+ throw new StringValueConversionException(
+ "Unable to convert '" + text + "' to an Integer value", e);
}
}
@@ -661,8 +674,8 @@ public class StringValue implements IClusterable
}
catch (NumberFormatException e)
{
- throw new StringValueConversionException("Unable to convert '" + text
- + "' to a long value", e);
+ throw new StringValueConversionException(
+ "Unable to convert '" + text + "' to a long value", e);
}
}
@@ -686,9 +699,8 @@ public class StringValue implements IClusterable
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to a long: %s", text,
- x.getMessage()), x);
+ LOG.debug(String.format("An error occurred while converting '%s' to a long: %s",
+ text, x.getMessage()), x);
}
}
}
@@ -709,8 +721,8 @@ public class StringValue implements IClusterable
}
catch (NumberFormatException e)
{
- throw new StringValueConversionException("Unable to convert '" + text
- + "' to a Long value", e);
+ throw new StringValueConversionException(
+ "Unable to convert '" + text + "' to a Long value", e);
}
}
@@ -796,9 +808,9 @@ public class StringValue implements IClusterable
* @return converted
* @throws StringValueConversionException
*/
- public final Time toOptionalTime() throws StringValueConversionException
+ public final Instant toOptionalInstant() throws StringValueConversionException
{
- return Strings.isEmpty(text) ? null : toTime();
+ return Strings.isEmpty(text) ? null : toInstant();
}
/**
@@ -823,46 +835,45 @@ public class StringValue implements IClusterable
}
/**
- * Convert this text to a time instance.
+ * Convert this text to an {@link Instant} instance.
*
* @return Converted text
* @throws StringValueConversionException
*/
- public final Time toTime() throws StringValueConversionException
+ public final Instant toInstant() throws StringValueConversionException
{
try
{
- return Time.valueOf(text);
+ return Instant.parse(text);
}
- catch (ParseException e)
+ catch (DateTimeParseException e)
{
- throw new StringValueConversionException("Unable to convert '" + text
- + "' to a Time value", e);
+ throw new StringValueConversionException(
+ "Unable to convert '" + text + "' to a Instant value", e);
}
}
/**
- * Convert to time, returning default value if text is inconvertible.
+ * Convert to {@link Instant}, returning default value if text is inconvertible.
*
* @param defaultValue
* the default value
- * @return the converted text as a time or the default value if text is inconvertible.
+ * @return the converted text as a {@link Instant} or the default value if text is inconvertible.
*/
- public final Time toTime(final Time defaultValue)
+ public final Instant toInstant(final Instant defaultValue)
{
if (text != null)
{
try
{
- return toTime();
+ return toInstant();
}
catch (StringValueConversionException x)
{
if (LOG.isDebugEnabled())
{
- LOG.debug(String.format(
- "An error occurred while converting '%s' to a Time: %s", text,
- x.getMessage()), x);
+ LOG.debug(String.format("An error occurred while converting '%s' to an Instant: %s",
+ text, x.getMessage()), x);
}
}
}
@@ -877,8 +888,7 @@ public class StringValue implements IClusterable
* @return The value as an enum
* @throws StringValueConversionException
*/
- public final <T extends Enum<T>> T toEnum(Class<T> eClass)
- throws StringValueConversionException
+ public final <T extends Enum<T>> T toEnum(Class<T> eClass) throws StringValueConversionException
{
return Strings.toEnum(text, eClass);
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java b/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
index 003c119..b32f50b 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
@@ -16,8 +16,9 @@
*/
package org.apache.wicket.util.thread;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
+import java.time.Duration;
+import java.time.Instant;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,8 +54,8 @@ public final class Task
/** the name of this <code>Task</code> */
private final String name;
- /** the <code>Time</code> at which the task should start */
- private Time startTime = Time.now();
+ /** the <code>Instant</code> at which the task should start */
+ private Instant startTime = Instant.now();
/** When set the task will stop as soon as possible */
private boolean stop;
@@ -95,15 +96,27 @@ public final class Task
public void run()
{
// Sleep until start time
- startTime.fromNow().sleep();
- final Logger log = getLog();
+ Duration untilStart = Duration.between(startTime, Instant.now());
+
+ final Logger log = getLog();
+
+ if (!untilStart.isNegative())
+ {
+ try
+ {
+ Thread.sleep(untilStart.toMillis());
+ } catch (InterruptedException e)
+ {
+ log.error("An error occurred during sleeping phase.", e);
+ }
+ }
try
{
while (!stop)
{
// Get the start of the current period
- final Time startOfPeriod = Time.now();
+ final Instant startOfPeriod = Instant.now();
if (log.isTraceEnabled())
{
@@ -128,7 +141,15 @@ public final class Task
// Sleep until the period is over (or not at all if it's
// already passed)
- startOfPeriod.add(frequency).fromNow().sleep();
+ Instant nextExecution = startOfPeriod.plus(frequency);
+
+ Duration timeToNextExecution = Duration.between(nextExecution, Instant.now());
+
+ if (!timeToNextExecution.isNegative())
+ {
+ Thread.sleep(timeToNextExecution.toMillis());
+ }
+
}
}
catch (Exception x)
@@ -198,7 +219,7 @@ public final class Task
* @throws IllegalStateException
* Thrown if task is already running
*/
- public synchronized void setStartTime(final Time startTime)
+ public synchronized void setStartTime(final Instant startTime)
{
if (isStarted)
{
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/AbstractTime.java b/wicket-util/src/main/java/org/apache/wicket/util/time/AbstractTime.java
deleted file mode 100755
index e22bc89..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/AbstractTime.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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 java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-
-/**
- * Abstract base class for subclasses that represent a point in time (as opposed to a
- * {@link Duration} of time).
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-abstract class AbstractTime extends AbstractTimeValue
-{
- private static final long serialVersionUID = 1L;
-
- /** calendar for the local time zone */
- static final Calendar localtime = Calendar.getInstance();
-
- /** time format */
- static final SimpleDateFormat timeFormat = new SimpleDateFormat("h.mma", Locale.ENGLISH);
-
- /**
- * @param milliseconds
- * @see AbstractTimeValue
- */
- AbstractTime(final long milliseconds)
- {
- super(milliseconds);
- }
-
- /**
- * Returns <code>true</code> if this <code>Time</code> value is after the given
- * <code>Time</code> argument's value.
- *
- * @param that
- * the <code>AbstractTimeValue</code> to compare with
- * @return <code>true</code> if this <code>Time</code> value is after <code>that</code>
- * <code>Time</code> value
- */
- public final boolean after(final AbstractTimeValue that)
- {
- return greaterThan(that);
- }
-
- /**
- * Returns <code>true</code> if this <code>Time</code> value is before the given
- * <code>Time</code> argument's value.
- *
- * @param that
- * the <code>AbstractTimeValue</code> to compare with
- * @return <code>true</code> if this <code>Time</code> value is before <code>that</code>
- * <code>Time</code> value
- */
- public final boolean before(final AbstractTimeValue that)
- {
- return lessThan(that);
- }
-
- /**
- * Converts this <code>Time</code> to a time <code>String</code> using the formatter 'h.mma'.
- *
- * @return the <code>Time</code> <code>String</code>
- */
- public final String toTimeString()
- {
- return toTimeString(localtime);
- }
-
- /**
- * Converts this <code>Time</code> to a <code>Date String</code> using the <code>Date</code>
- * formatter 'h.mma'.
- *
- * @param calendar
- * the <code>Calendar</code> to use in the conversion
- * @return the <code>Date</code> <code>String</code>
- */
- public final String toTimeString(final Calendar calendar)
- {
- synchronized (timeFormat)
- {
- synchronized (calendar)
- {
- timeFormat.setCalendar(calendar);
- return timeFormat.format(new Date(getMilliseconds())).toLowerCase(Locale.ROOT);
- }
- }
- }
-
- /**
- * Converts this <code>Time</code> to a <code>String</code> suitable for use in a file system
- * name.
- *
- * @return this <code>Time</code> as a formatted <code>String</code>
- */
- @Override
- public String toString()
- {
- return toTimeString();
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/AbstractTimeValue.java b/wicket-util/src/main/java/org/apache/wicket/util/time/AbstractTimeValue.java
deleted file mode 100755
index 2905851..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/AbstractTimeValue.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 org.apache.wicket.util.value.LongValue;
-
-/**
- * Package local class for representing immutable time values in milliseconds and typical operations
- * on such values.
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-abstract class AbstractTimeValue extends LongValue
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * Package local constructor for package subclasses only.
- *
- * @param milliseconds
- * the number of milliseconds in this <code>Time</code> value
- */
- AbstractTimeValue(final long milliseconds)
- {
- super(milliseconds);
- }
-
- /**
- * Retrieves the number of milliseconds in this <code>Time</code> value.
- *
- * @return the number of milliseconds in this <code>Time</code> value
- */
- public final long getMilliseconds()
- {
- return value;
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/Duration.java b/wicket-util/src/main/java/org/apache/wicket/util/time/Duration.java
deleted file mode 100755
index bd2bb9e..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/Duration.java
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
- * 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 java.util.Locale;
-import java.util.Locale.Category;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.wicket.util.string.StringValue;
-import org.apache.wicket.util.string.StringValueConversionException;
-import org.apache.wicket.util.thread.ICode;
-import org.slf4j.Logger;
-
-
-/**
- * A <code>Duration</code> is an immutable length of time stored as a number of milliseconds.
- * Various factory and conversion methods are available for convenience.
- * <p>
- * These static factory methods allow easy construction of value objects using either long values
- * like <code>seconds(2034)</code> or <code>hours(3)</code>:
- * <p>
- * <ul>
- * <li><code>Duration.milliseconds(long)</code>
- * <li><code>Duration.seconds(int)</code>
- * <li><code>Duration.minutes(int)</code>
- * <li><code>Duration.hours(int)</code>
- * <li><code>Duration.days(int)</code>
- * </ul>
- * <p>
- * ...or double-precision floating point values like <code>days(3.2)</code>:
- * <p>
- * <ul>
- * <li><code>Duration.milliseconds(double)</code>
- * <li><code>Duration.seconds(double)</code>
- * <li><code>Duration.minutes(double)</code>
- * <li><code>Duration.hours(double)</code>
- * <li><code>Duration.days(double)</code>
- * </ul>
- * <p>
- * In the case of <code>milliseconds(double)</code>, the value will be rounded off to the nearest
- * integral millisecond using <code>Math.round()</code>.
- * <p>
- * The precise number of milliseconds represented by a <code>Duration</code> object can be retrieved
- * by calling the <code>getMilliseconds</code> method. The value of a <code>Duration</code> object
- * in a given unit like days or hours can be retrieved by calling one of the following unit methods,
- * each of which returns a double-precision floating point number:
- * <p>
- * <ul>
- * <li><code>seconds()</code>
- * <li><code>minutes()</code>
- * <li><code>hours()</code>
- * <li><code>days()</code>
- * </ul>
- * <p>
- * Values can be added and subtracted using the <code>add(Duration)</code> and
- * <code>subtract(Duration)</code> methods, each of which returns a new immutable
- * <code>Duration</code> object.
- * <p>
- * <code>String</code> values can be converted to <code>Duration</code> objects using the static
- * <code>valueOf</code> factory methods. The <code>String</code> format is the opposite of the one
- * created by <code>toString()</code>, which converts a <code>Duration</code> object to a readable
- * form, such as "3.2 hours" or "32.5 minutes". Valid units are: milliseconds, seconds, minutes
- * hours and days. Correct English plural forms are used in creating <code>String</code> values and
- * are parsed as well. The <code>Locale</code> is respected and "," will be used instead of "." in
- * the Eurozone.
- * <p>
- * The benchmark method will "benchmark" a <code>Runnable</code> or an {@link ICode} implementing
- * object, returning a <code>Duration</code> object that represents the amount of time elapsed in
- * running the code.
- * <p>
- * Finally, the <code>sleep</code> method will sleep for the value of a <code>Duration</code>.
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-public class Duration extends AbstractTimeValue
-{
- private static final long serialVersionUID = 1L;
-
- /** Constant for maximum duration. */
- public static final Duration MAXIMUM = milliseconds(Long.MAX_VALUE);
-
- /** Constant for no duration. */
- public static final Duration NONE = milliseconds(0);
-
- /** Constant for one day. */
- public static final Duration ONE_DAY = days(1);
-
- /** Constant for one hour. */
- public static final Duration ONE_HOUR = hours(1);
-
- /** Constant for on minute. */
- public static final Duration ONE_MINUTE = minutes(1);
-
- /** Constant for one second. */
- public static final Duration ONE_SECOND = seconds(1);
-
- /** Constant for one week. */
- public static final Duration ONE_WEEK = days(7);
-
- /** pattern to match strings */
- private static final Pattern pattern = Pattern.compile(
- "([0-9]+([.,][0-9]+)?)\\s+(millisecond|second|minute|hour|day)s?", Pattern.CASE_INSENSITIVE);
-
- /**
- * Benchmark the given command.
- *
- * @param code
- * an <code>ICode</code>
- * @param log
- * optional logger to use with errors and exceptions
- * @return the <code>Time</code> value it took to run the code
- */
- public static Duration benchmark(final ICode code, final Logger log)
- {
- // Get time before running code
- final Time start = Time.now();
-
- // Run the code
- code.run(log);
-
- // Return the difference
- return Time.now().subtract(start);
- }
-
- /**
- * Benchmark the given command.
- *
- * @param code
- * a <code>Runnable</code>
- * @return the <code>Time</code> value it took to run the code
- */
- public static Duration benchmark(final Runnable code)
- {
- // Get time before running code
- final Time start = Time.now();
-
- // Run code
- code.run();
-
- // Return the difference
- return Time.now().subtract(start);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on days.
- *
- * @param days
- * days <code>double</code> value
- * @return the <code>Duration</code> based on days
- */
- public static Duration days(final double days)
- {
- return hours(24.0 * days);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on days.
- *
- * @param days
- * days <code>int</code> value
- * @return the <code>Duration</code> based on days
- */
- public static Duration days(final int days)
- {
- return hours(24 * days);
- }
-
- /**
- * Calculates the amount of time elapsed since start time.
- *
- * @param start
- * the start <code>Time</code>
- * @return the elapsed period as a <code>Duration</code>
- * @throws IllegalStateException
- * if start <code>Time</code> is in the future
- */
- public static Duration elapsed(final Time start)
- {
- return start.elapsedSince();
- }
-
- /**
- * Retrieves the <code>Duration</code> based on hours.
- *
- * @param hours
- * hours <code>double</code> value
- * @return the <code>Duration</code> based on hours
- */
- public static Duration hours(final double hours)
- {
- return minutes(60.0 * hours);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on hours.
- *
- * @param hours
- * hours <code>int</code> value
- * @return the <code>Duration</code> based on hours
- */
- public static Duration hours(final int hours)
- {
- return minutes(60 * hours);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on milliseconds.
- *
- * @param milliseconds
- * milliseconds <code>double</code> value
- * @return the <code>Duration</code> based on milliseconds
- */
- public static Duration milliseconds(final double milliseconds)
- {
- return milliseconds(Math.round(milliseconds));
- }
-
- /**
- * Retrieves the <code>Duration</code> based on milliseconds.
- *
- * @param milliseconds
- * milliseconds <code>long</code> value
- * @return the <code>Duration</code> based on milliseconds
- */
- public static Duration milliseconds(final long milliseconds)
- {
- return new Duration(milliseconds);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on minutes.
- *
- * @param minutes
- * minutes <code>double</code> value
- * @return the <code>Duration</code> based on minutes
- */
- public static Duration minutes(final double minutes)
- {
- return seconds(60.0 * minutes);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on minutes.
- *
- * @param minutes
- * minutes <code>int</code> value
- * @return the <code>Duration</code> based on minutes
- */
- public static Duration minutes(final int minutes)
- {
- return seconds(60 * minutes);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on seconds.
- *
- * @param seconds
- * seconds <code>double</code> value
- * @return the <code>Duration</code> based on seconds
- */
- public static Duration seconds(final double seconds)
- {
- return milliseconds(seconds * 1000.0);
- }
-
- /**
- * Retrieves the <code>Duration</code> based on seconds.
- *
- * @param seconds
- * seconds <code>int</code> value
- * @return the <code>Duration</code> based on seconds
- */
- public static Duration seconds(final int seconds)
- {
- return milliseconds(seconds * 1000L);
- }
-
- /**
- * Retrieves the given <code>long</code> as a <code>Duration</code>.
- *
- * @param time
- * the duration <code>long</code> value in milliseconds
- * @return the <code>Duration</code> value
- */
- public static Duration valueOf(final long time)
- {
- return new Duration(time);
- }
-
- /**
- * Converts the given <code>String</code> to a new <code>Duration</code> object. The string can
- * take the form of a floating point number followed by a number of milliseconds, seconds,
- * minutes, hours or days. For example "6 hours" or "3.4 days". Parsing is case-insensitive.
- *
- * @param string
- * a <code>String</code> to parse
- * @return the <code>Duration</code> value of the given <code>String</code>
- * @throws StringValueConversionException
- */
- public static Duration valueOf(final String string) throws StringValueConversionException
- {
- return valueOf(string, Locale.getDefault(Locale.Category.FORMAT));
- }
-
- /**
- * Converts the given <code>String</code> to a new <code>Duration</code> object. The string can
- * take the form of a floating point number followed by a number of milliseconds, seconds,
- * minutes, hours or days. For example "6 hours" or "3.4 days". Parsing is case-insensitive.
- *
- * @param string
- * a <code>String</code> to parse
- * @param locale
- * the <code>Locale</code> used for parsing
- * @return the <code>Duration</code> value of the given <code>String</code>
- * @throws StringValueConversionException
- */
- public static Duration valueOf(final String string, final Locale locale)
- throws StringValueConversionException
- {
- final Matcher matcher = pattern.matcher(string);
-
- if (matcher.matches())
- {
- final double value = StringValue.valueOf(matcher.group(1), locale).toDouble();
- final String units = matcher.group(3);
-
- if (units.equalsIgnoreCase("millisecond"))
- {
- return milliseconds(value);
- }
- else if (units.equalsIgnoreCase("second"))
- {
- return seconds(value);
- }
- else if (units.equalsIgnoreCase("minute"))
- {
- return minutes(value);
- }
- else if (units.equalsIgnoreCase("hour"))
- {
- return hours(value);
- }
- else if (units.equalsIgnoreCase("day"))
- {
- return days(value);
- }
- else
- {
- throw new StringValueConversionException("Unrecognized units: " + string);
- }
- }
- else
- {
- throw new StringValueConversionException("Unable to parse duration: " + string);
- }
- }
-
- /**
- * Private constructor forces use of static factory methods.
- *
- * @param milliseconds
- * number of milliseconds in this <code>Duration</code>
- */
- protected Duration(final long milliseconds)
- {
- super(milliseconds);
- }
-
- /**
- * Adds a given <code>Duration</code> to this <code>Duration</code>.
- *
- * @param duration
- * the <code>Duration</code> to add
- * @return the sum of the <code>Duration</code>s
- */
- public Duration add(final Duration duration)
- {
- return valueOf(getMilliseconds() + duration.getMilliseconds());
- }
-
- /**
- * Retrieves the number of days of the current <code>Duration</code>.
- *
- * @return number of days of the current <code>Duration</code>
- */
- public final double days()
- {
- return hours() / 24.0;
- }
-
- /**
- * Retrieves the number of hours of the current <code>Duration</code>.
- *
- * @return number of hours of the current <code>Duration</code>
- */
- public final double hours()
- {
- return minutes() / 60.0;
- }
-
- /**
- * Retrieves the number of minutes of the current <code>Duration</code>.
- *
- * @return number of minutes of the current <code>Duration</code>
- */
- public final double minutes()
- {
- return seconds() / 60.0;
- }
-
- /**
- * Retrieves the number of seconds of the current <code>Duration</code>.
- *
- * @return number of seconds of the current <code>Duration</code>
- */
- public final double seconds()
- {
- return getMilliseconds() / 1000.0;
- }
-
- /**
- * Sleeps for the current <code>Duration</code>.
- */
- public final void sleep()
- {
- if (getMilliseconds() > 0)
- {
- try
- {
- Thread.sleep(getMilliseconds());
- }
- catch (InterruptedException e)
- {
- // Ignored
- }
- }
- }
-
- /**
- * Subtracts a given <code>Duration</code> from this <code>Duration</code>.
- *
- * @param that
- * the <code>Duration</code> to subtract
- * @return this <code>Duration</code> minus that <code>Duration</code>
- */
- public Duration subtract(final Duration that)
- {
- return valueOf(getMilliseconds() - that.getMilliseconds());
- }
-
- /**
- * Wait for this duration on the given monitor
- *
- * @param object
- * The monitor to wait on
- */
- public void wait(final Object object)
- {
- try
- {
- object.wait(getMilliseconds());
- }
- catch (InterruptedException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Retrieves the <code>String</code> representation of this <code>Duration</code> in days,
- * hours, minutes, seconds or milliseconds, as appropriate. Uses the default <code>Locale</code>
- * .
- *
- * @return a <code>String</code> representation
- */
- @Override
- public String toString()
- {
- return toString(Locale.getDefault(Category.FORMAT));
- }
-
- /**
- * Retrieves the <code>String</code> representation of this <code>Duration</code> in days,
- * hours, minutes, seconds or milliseconds, as appropriate.
- *
- * @param locale
- * a <code>Locale</code>
- * @return a <code>String</code> representation
- */
- public String toString(final Locale locale)
- {
- if (getMilliseconds() >= 0)
- {
- if (days() >= 1.0)
- {
- return unitString(days(), "day", locale);
- }
-
- if (hours() >= 1.0)
- {
- return unitString(hours(), "hour", locale);
- }
-
- if (minutes() >= 1.0)
- {
- return unitString(minutes(), "minute", locale);
- }
-
- if (seconds() >= 1.0)
- {
- return unitString(seconds(), "second", locale);
- }
-
- return unitString(getMilliseconds(), "millisecond", locale);
- }
- else
- {
- return "N/A";
- }
- }
-
- /**
- * Converts a value to a unit-suffixed value, taking care of English singular/plural suffix.
- *
- * @param value
- * a <code>double</code> value to format
- * @param units
- * the units to apply singular or plural suffix to
- * @param locale
- * the <code>Locale</code>
- * @return a <code>String</code> representation
- */
- private String unitString(final double value, final String units, final Locale locale)
- {
- return StringValue.valueOf(value, locale) + " " + units + ((value > 1.0) ? "s" : "");
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/Durations.java b/wicket-util/src/main/java/org/apache/wicket/util/time/Durations.java
new file mode 100644
index 0000000..8601108
--- /dev/null
+++ b/wicket-util/src/main/java/org/apache/wicket/util/time/Durations.java
@@ -0,0 +1,80 @@
+/*
+ * 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 java.time.Duration;
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.util.string.StringValue;
+
+public class Durations
+{
+
+ /** pattern to match strings */
+ private static final Pattern pattern = Pattern.compile(
+ "([0-9]+([.,][0-9]+)?)\\s+(millisecond|second|minute|hour|day)s?",
+ Pattern.CASE_INSENSITIVE);
+
+ public static String toString(final Duration duration, final Locale locale)
+ {
+ if (duration.toMillis() >= 0)
+ {
+ if (duration.toDays() >= 1.0)
+ {
+ return unitString(duration.toDays(), "day", locale);
+ }
+
+ if (duration.toHours() >= 1.0)
+ {
+ return unitString(duration.toHours(), "hour", locale);
+ }
+
+ if (duration.toMinutes() >= 1.0)
+ {
+ return unitString(duration.toMinutes(), "minute", locale);
+ }
+
+ if (duration.toSeconds() >= 1.0)
+ {
+ return unitString(duration.toSeconds(), "second", locale);
+ }
+
+ return unitString(duration.toMillis(), "millisecond", locale);
+ }
+ else
+ {
+ return "N/A";
+ }
+ }
+
+ /**
+ * Converts a value to a unit-suffixed value, taking care of English singular/plural suffix.
+ *
+ * @param value
+ * a <code>double</code> value to format
+ * @param units
+ * the units to apply singular or plural suffix to
+ * @param locale
+ * the <code>Locale</code>
+ * @return a <code>String</code> representation
+ */
+ private static String unitString(final double value, final String units, final Locale locale)
+ {
+ return StringValue.valueOf(value, locale) + " " + units + ((value > 1.0) ? "s" : "");
+ }
+}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/ITimeFrameSource.java b/wicket-util/src/main/java/org/apache/wicket/util/time/Instants.java
old mode 100755
new mode 100644
similarity index 61%
rename from wicket-util/src/main/java/org/apache/wicket/util/time/ITimeFrameSource.java
rename to wicket-util/src/main/java/org/apache/wicket/util/time/Instants.java
index 18bc4e3..e17f228
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/ITimeFrameSource.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/time/Instants.java
@@ -1,38 +1,37 @@
-/*
- * 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 java.io.Serializable;
-
-/**
- * An <code>ITimeFrameSource</code> produces <code>TimeFrame</code> values. The value returned by an
- * <code>ITimeFrameSource</code> source may vary over time.
- *
- * @see TimeFrame
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-public interface ITimeFrameSource extends Serializable
-{
- /**
- * Retrieves the current <code>TimeFrame</code> value.
- *
- * @return the current <code>TimeFrame</code> value
- */
- TimeFrame getTimeFrame();
-}
+/*
+ * 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 java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+
+public class Instants
+{
+
+ public static final DateTimeFormatter RFC7231Formatter = DateTimeFormatter
+ .ofPattern("EEE, dd MMM yyyy HH:mm:ss O").withZone(ZoneId.of("UTC"));
+
+ public static final DateTimeFormatter localDateFormatter = DateTimeFormatter
+ .ofPattern("yyyy.MM.dd", Locale.ENGLISH);
+
+ public static String toRFC7231Format(final Instant instant)
+ {
+ return RFC7231Formatter.format(instant);
+ }
+}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/Time.java b/wicket-util/src/main/java/org/apache/wicket/util/time/Time.java
deleted file mode 100755
index 21a8abc..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/Time.java
+++ /dev/null
@@ -1,612 +0,0 @@
-/*
- * 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 java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * An immutable <code>Time</code> class that represents a specific point in time. The underlying
- * representation is a <code>long</code> value which holds a number of milliseconds since January 1,
- * 1970, 0:00 GMT. To represent a duration of time, such as "6 seconds", use the
- * <code>Duration</code> class. To represent a time period with a start and end time, use the
- * <code>TimeFrame</code> class. To represent a time of day, use the <code>TimeOfDay</code> class.
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-public final class Time extends AbstractTime
-{
- private static final long serialVersionUID = 1L;
-
- /** the beginning of UNIX time: January 1, 1970, 0:00 GMT. */
- public static final Time START_OF_UNIX_TIME = millis(0);
-
- /** parser in 'yyyy.MM.dd' format. */
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd",
- Locale.ENGLISH);
-
- /** parser in 'yyyy.MM.dd-h.mma' format. */
- private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy.MM.dd-h.mma",
- Locale.ENGLISH);
-
- /** required for rfc1123 date format */
- private static final String[] DAYS =
- {"Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
-
- /** required for rfc1123 date format */
- private static final String[] MONTHS =
- {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan"};
-
- /** time zone for greenwich mean time */
- public static final TimeZone GMT = TimeZone.getTimeZone("GMT");
-
- /**
- * Retrieves a <code>Time</code> instance based on the current time.
- *
- * @return the current <code>Time</code>
- */
- public static Time now()
- {
- return millis(System.currentTimeMillis());
- }
-
- /**
- * Retrieves a <code>Time</code> instance based on the given milliseconds.
- *
- * @param time
- * the <code>Time</code> value in milliseconds since START_OF_UNIX_TIME
- * @return a corresponding immutable <code>Time</code> object
- */
- public static Time millis(final long time)
- {
- return new Time(time);
- }
-
- /**
- * Retrieves a <code>Time</code> instance by parsing 'yyyy.MM.dd' format.
- *
- * @param calendar
- * the <code>Calendar</code> to use when parsing date <code>String</code>
- * @param string
- * the <code>String</code> to parse
- * @return the time
- * @throws ParseException
- */
- public static Time parseDate(final Calendar calendar, final String string)
- throws ParseException
- {
- synchronized (dateFormat)
- {
- synchronized (calendar)
- {
- dateFormat.setCalendar(calendar);
-
- return valueOf(dateFormat.parse(string));
- }
- }
- }
-
- /**
- * Retrieves a <code>Time</code> instance by parsing 'yyyy.MM.dd' format using a local time
- * <code>Calendar</code>.
- *
- * @param string
- * the <code>String</code> to parse
- * @return the time
- * @throws ParseException
- */
- public static Time parseDate(final String string) throws ParseException
- {
- return parseDate(localtime, string);
- }
-
- /**
- * Retrieves a <code>Time</code> instance by parsing 'yyyy.MM.dd-h.mma' format.
- *
- * @param calendar
- * the <code>Calendar</code> to use when parsing the <code>String</code>
- * @param string
- * the <code>String</code> to parse
- * @return an immutable UNIX <code>Time</code> value
- * @throws ParseException
- */
- public static Time valueOf(final Calendar calendar, final String string) throws ParseException
- {
- synchronized (dateTimeFormat)
- {
- synchronized (calendar)
- {
- dateTimeFormat.setCalendar(calendar);
-
- return valueOf(dateTimeFormat.parse(string));
- }
- }
- }
-
- /**
- * Retrieves a <code>Time</code> instance based on the given <code>Calendar</code> and
- * {@link TimeOfDay} objects.
- *
- * @param calendar
- * the <code>Calendar</code> to use
- * @param timeOfDay
- * the time of day
- * @return a <code>Time</code> value for the time of day today
- */
- public static Time valueOf(final Calendar calendar, final TimeOfDay timeOfDay)
- {
- synchronized (calendar)
- {
- // Set time to midnight today
- calendar.setTimeInMillis(System.currentTimeMillis());
- calendar.set(Calendar.HOUR_OF_DAY, 0); // WICKET-2349
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0); // WICKET-1670
-
- // Add time of day milliseconds to midnight
- return millis(calendar.getTimeInMillis() + timeOfDay.getMilliseconds());
- }
- }
-
- /**
- * Retrieves a <code>Time</code> instance based on the given <code>Date</code> object.
- *
- * @param date
- * a <code>java.util.Date</code> object
- * @return a corresponding immutable <code>Time</code> object
- */
- public static Time valueOf(final Date date)
- {
- return new Time(date.getTime());
- }
-
- /**
- * Retrieves a <code>Time</code> instance by parsing 'yyyy.MM.dd-h.mma' format.
- *
- * @param string
- * the <code>String</code> to parse
- * @return the <code>Time</code> instance
- * @throws ParseException
- */
- public static Time valueOf(final String string) throws ParseException
- {
- return valueOf(localtime, string);
- }
-
- /**
- * Retrieves a <code>Time</code> instance by parsing 'pattern' format.
- *
- * @param string
- * input
- * @param pattern
- * the pattern to parse
- * @return a <code>Time</code> instance that resulted from parsing the given <code>String</code>
- * @throws ParseException
- */
- public static Time valueOf(final String string, final String pattern) throws ParseException
- {
- final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(pattern, Locale.ENGLISH);
- dateTimeFormat.setCalendar(localtime);
- return valueOf(dateTimeFormat.parse(string));
- }
-
- /**
- * Retrieves a <code>Time</code> instance based on the given {@link TimeOfDay} object.
- *
- * @param timeOfDay
- * the time of day in local time
- * @return a <code>Time</code> value for the time of day today
- */
- public static Time valueOf(final TimeOfDay timeOfDay)
- {
- return valueOf(localtime, timeOfDay);
- }
-
- /**
- * Private constructor forces use of static factory methods.
- *
- * @param time
- * the <code>Time</code> value in milliseconds since START_OF_UNIX_TIME
- */
- private Time(final long time)
- {
- super(time);
- }
-
- /**
- * Adds the given <code>Duration</code> to this <code>Time</code> object, moving the time into
- * the future.
- *
- * @param duration
- * the <code>Duration</code> to add
- * @return this <code>Time</code> + <code>Duration</code>
- */
- public Time add(final Duration duration)
- {
- return millis(getMilliseconds() + duration.getMilliseconds());
- }
-
- /**
- * Calculates the amount of time that has elapsed since this <code>Time</code> value.
- *
- * @return the amount of time that has elapsed since this <code>Time</code> value
- * @throws IllegalStateException
- * thrown if this <code>Time</code> value is in the future
- */
- public Duration elapsedSince()
- {
- final Time now = now();
- if (this.greaterThan(now))
- {
- throw new IllegalStateException("This time is in the future");
- }
- return now.subtract(this);
- }
-
- /**
- * Retrieves the <code>Duration</code> from now to this <code>Time</code> value. If this
- * <code>Time</code> value is in the past, then the <code>Duration</code> returned will be
- * negative. Otherwise, it will be the number of milliseconds from now to this <code>Time</code>
- * .
- *
- * @return the <code>Duration</code> from now to this <code>Time</code> value
- */
- public Duration fromNow()
- {
- return subtract(now());
- }
-
- /**
- * Retrieves the value of a field from the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> to use
- * @param field
- * the <code>Calendar</code> field to get
- * @return the field's value for this point in time on the given <code>Calendar</code>
- */
- public int get(final Calendar calendar, final int field)
- {
- synchronized (calendar)
- {
- calendar.setTimeInMillis(getMilliseconds());
-
- return calendar.get(field);
- }
- }
-
- /**
- * Retrieves the value of a field.
- *
- * @param field
- * the <code>Calendar</code> field to get
- * @return the field's value (in local time)
- */
- public int get(final int field)
- {
- return get(localtime, field);
- }
-
- /**
- * Retrieves the day of month field of the current <code>Calendar</code>.
- *
- * @return the day of month field value
- */
- public int getDayOfMonth()
- {
- return getDayOfMonth(localtime);
- }
-
- /**
- * Retrieves the day of month field of the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> to get the field value from
- * @return the day of month field value
- */
- public int getDayOfMonth(final Calendar calendar)
- {
- return get(calendar, Calendar.DAY_OF_MONTH);
- }
-
- /**
- * Retrieves the hour field of the current <code>Calendar</code>.
- *
- * @return the hour field value
- */
- public int getHour()
- {
- return getHour(localtime);
- }
-
- /**
- * Retrieves the hour field of the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> to get the field value from
- * @return the hour field value
- */
- public int getHour(final Calendar calendar)
- {
- return get(calendar, Calendar.HOUR_OF_DAY);
- }
-
- /**
- * Retrieves the minute field of the current <code>Calendar</code>.
- *
- * @return the minute field value
- */
- public int getMinute()
- {
- return getMinute(localtime);
- }
-
- /**
- * Retrieves the minute field of the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> from which to get the field value
- * @return the minute field value
- */
- public int getMinute(final Calendar calendar)
- {
- return get(calendar, Calendar.MINUTE);
- }
-
- /**
- * Retrieves the month field of the current <code>Calendar</code>.
- *
- * @return the month field value
- */
- public int getMonth()
- {
- return getMonth(localtime);
- }
-
- /**
- * Retrieves the month field of the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> from which to get the field value
- * @return the month field value
- */
- public int getMonth(final Calendar calendar)
- {
- return get(calendar, Calendar.MONTH);
- }
-
- /**
- * Retrieves the seconds field of the current <code>Calendar</code>.
- *
- * @return the seconds field value
- */
- public int getSecond()
- {
- return getSecond(localtime);
- }
-
- /**
- * Retrieves the seconds field of the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> from which to get the field value
- * @return the seconds field value
- */
- public int getSecond(final Calendar calendar)
- {
- return get(calendar, Calendar.SECOND);
- }
-
- /**
- * Retrieves the year field of the current <code>Calendar</code>.
- *
- * @return the year field value
- */
- public int getYear()
- {
- return getYear(localtime);
- }
-
- /**
- * Retrieves the year field of the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> from which to get the field value
- * @return the year field value
- */
- public int getYear(final Calendar calendar)
- {
- return get(calendar, Calendar.YEAR);
- }
-
- /**
- * Subtracts the given <code>Duration</code> from this <code>Time</code> object, moving the time
- * into the past.
- *
- * @param duration
- * the <code>Duration</code> to subtract
- * @return this duration of time
- */
- public Time subtract(final Duration duration)
- {
- return millis(getMilliseconds() - duration.getMilliseconds());
- }
-
- /**
- * Subtract time from this and returns the difference as a <code>Duration</code> object.
- *
- * @param that
- * the time to subtract
- * @return the <code>Duration</code> between this and that time
- */
- public Duration subtract(final Time that)
- {
- return Duration.milliseconds(getMilliseconds() - that.getMilliseconds());
- }
-
- /**
- * Retrieves a <code>Date</code> object for this <code>Time</code> object. A new
- * <code>Date</code> object is always returned rather than attempting to cache a date since
- * <code>Date</code> is mutable.
- *
- * @return this immutable <code>Time</code> object as a mutable <code>java.util.Date</code>
- * object
- */
- public Date toDate()
- {
- return new Date(getMilliseconds());
- }
-
- /**
- * Converts this <code>Time</code> value to a date <code>String</code> using the date formatter
- * 'yyyy.MM.dd'.
- *
- * @return the date string
- */
- public String toDateString()
- {
- return toDateString(localtime);
- }
-
- /**
- * Converts this <code>Time</code> value to a date <code>String</code> using the formatter
- * 'yyyy.MM.dd'.
- *
- * @param calendar
- * the <code>Calendar</code> to use in the conversion
- * @return the date <code>String</code>
- */
- public String toDateString(final Calendar calendar)
- {
- synchronized (dateFormat)
- {
- synchronized (calendar)
- {
- dateFormat.setCalendar(calendar);
-
- return dateFormat.format(new Date(getMilliseconds())).toLowerCase(Locale.ROOT);
- }
- }
- }
-
- /**
- * Converts this <code>Time</code> value to a <code>String</code> suitable for use in a file
- * system name.
- *
- * @return this <code>Time</code> value as a formatted <code>String</code>
- */
- @Override
- public String toString()
- {
- return toDateString() + "-" + toTimeString();
- }
-
- /**
- * Converts this <code>Time</code> object to a <code>String</code> using the given
- * <code>Calendar</code> and format.
- *
- * @param calendar
- * the <code>Calendar</code> to use in the conversion
- * @param format
- * the format to use
- * @return this <code>Time</code> value as a formatted <code>String</code>
- */
- public String toString(final Calendar calendar, final String format)
- {
- final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(format, Locale.ENGLISH);
- dateTimeFormat.setCalendar(calendar == null ? localtime : calendar);
- return dateTimeFormat.format(new Date(getMilliseconds()));
- }
-
- /**
- * Converts this <code>Time</code> value to a <code>String</code> using the given format.
- *
- * @param format
- * the format to use
- * @return this <code>Time</code> value as a formatted string
- */
- public String toString(final String format)
- {
- return toString(null, format);
- }
-
- /**
- * Returns this time stamp in RFC1123 string format. Contrary to
- * {@link java.text.SimpleDateFormat} this is thread-safe. Taken from the source code of jetty
- * 7.3.0, credits + thanks to Greg Wilkins!
- *
- * @return timestamp string in RFC1123 format
- */
- public String toRfc1123TimestampString()
- {
- final Calendar cal = GregorianCalendar.getInstance(GMT);
- final StringBuilder buf = new StringBuilder(32);
-
- cal.setTimeInMillis(getMilliseconds());
-
- int day_of_week = cal.get(Calendar.DAY_OF_WEEK);
- int day_of_month = cal.get(Calendar.DAY_OF_MONTH);
- int month = cal.get(Calendar.MONTH);
- int year = cal.get(Calendar.YEAR);
- int century = year / 100;
- year = year % 100;
-
- int hours = cal.get(Calendar.HOUR_OF_DAY);
- int minutes = cal.get(Calendar.MINUTE);
- int seconds = cal.get(Calendar.SECOND);
-
- buf.append(DAYS[day_of_week]);
- buf.append(',');
- buf.append(' ');
- appendTwoDigits(buf, day_of_month);
-
- buf.append(' ');
- buf.append(MONTHS[month]);
- buf.append(' ');
- appendTwoDigits(buf, century);
- appendTwoDigits(buf, year);
-
- buf.append(' ');
- appendTwoDigits(buf, hours);
- buf.append(':');
- appendTwoDigits(buf, minutes);
- buf.append(':');
- appendTwoDigits(buf, seconds);
- buf.append(" GMT");
-
- return buf.toString();
- }
-
- /**
- * helper method for {@link #toRfc1123TimestampString()}
- *
- * @param str
- * @param number
- */
- private static void appendTwoDigits(StringBuilder str, int number)
- {
- str.append((char)(number / 10 + '0'));
- str.append((char)(number % 10 + '0'));
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/TimeFrame.java b/wicket-util/src/main/java/org/apache/wicket/util/time/TimeFrame.java
deleted file mode 100755
index fab51e7..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/TimeFrame.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * 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 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
- * includes 1pm, but not 2pm. 1:59:59 is the last value in the <code>TimeFrame</code>.
- * <p>
- * <code>TimeFrame</code>s can be constructed by calling the <code>valueOf</code> static factory
- * methods <code>valueOf(Time, Time)</code> (yielding a <code>TimeFrame</code> between two absolute
- * times) and <code>valueOf(Time, Duration)</code> yielding a <code>TimeFrame</code> starting at an
- * absolute time and having a given length.
- * <p>
- * The start and end of a <code>TimeFrame</code> can be retrieved by calling <code>getStart</code>
- * and <code>getEnd</code>. Its duration can be retrieved by calling <code>getDuration</code>.
- * <p>
- * The <code>contains(Time)</code> method can be called to determine if a <code>TimeFrame</code>
- * contains a given point in time. The <code>overlaps(TimeFrame)</code> method can be called to
- * determine if two <code>TimeFrames</code> overlap.
- * <p>
- * The <code>eachDay(TimeOfDay, TimeOfDay)</code> will return a <code>TimeFrameSource</code> which
- * generates a <code>TimeFrame</code> using the two times of day. In other words, if the start is
- * 3pm and the end is 4pm, the <code>TimeFrameSource</code> returned will yield 3-4pm on the day it
- * is called (each day).
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-public final class TimeFrame implements ITimeFrameSource
-{
- private static final long serialVersionUID = 1L;
-
- /** end of this <code>TimeFrame</code> */
- private final Time end;
-
- /** beginning of this <code>TimeFrame</code> */
- private final Time start;
-
- /**
- * Creates an <code>ITimeFrameSource</code> source for start and end <code>TimeOfDay</code>s.
- * For example, called with 3pm and 5pm as parameters, the <code>TimeFrame</code> source
- * returned would produce <code>TimeFrame</code> objects representing 3pm-5pm on whatever day it
- * is when the caller calls the <code>TimeFrameSource</code> interface.
- *
- * @param startTimeOfDay
- * the start <code>TimeOfDay</code> for this <code>TimeFrame</code> each day
- * @param endTimeOfDay
- * the end <code>TimeOfDay</code> for this <code>TimeFrame</code> each day
- * @return a <code>TimeFrameSource</code> which will return the specified <code>TimeFrame</code>
- * each day
- */
- public static ITimeFrameSource eachDay(final TimeOfDay startTimeOfDay,
- final TimeOfDay endTimeOfDay)
- {
- check(startTimeOfDay, endTimeOfDay);
-
- return new ITimeFrameSource()
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public TimeFrame getTimeFrame()
- {
- return new TimeFrame(Time.valueOf(startTimeOfDay), Time.valueOf(endTimeOfDay));
- }
- };
- }
-
- /**
- * Creates a <code>TimeFrame</code> for a start <code>Time</code> and <code>Duration</code>.
- *
- * @param start
- * the start <code>Time</code>
- * @param duration
- * the <code>Duration</code>
- * @return the <code>TimeFrame</code>
- * @throws IllegalArgumentException
- * thrown if start <code>Time</code> value is before end <code>Time</code> value
- */
- public static TimeFrame valueOf(final Time start, final Duration duration)
- {
- return new TimeFrame(start, start.add(duration));
- }
-
- /**
- * Creates a <code>TimeFrame</code> for given start and end <code>Time</code>s.
- *
- * @param start
- * the start <code>Time</code>
- * @param end
- * the end <code>Time</code>
- * @return the <code>TimeFrame</code>
- * @throws IllegalArgumentException
- * thrown if start <code>Time</code> value is before end <code>Time</code> value
- */
- public static TimeFrame valueOf(final Time start, final Time end)
- {
- return new TimeFrame(start, end);
- }
-
- /**
- * Checks consistency of start and end <code>AbstractTimeValue</code> values, ensuring that the
- * end value is less than the start value.
- *
- * @param start
- * start <code>AbstractTimeValue</code> value
- * @param end
- * end <code>AbstractTimeValue</code> value
- * @throws IllegalArgumentException
- * thrown if end is less than start
- */
- private static void check(final AbstractTimeValue start, final AbstractTimeValue end)
- {
- // Throw illegal argument exception if end is less than start
- if (end.lessThan(start))
- {
- throw new IllegalArgumentException("Start time of time frame " + start +
- " was after end time " + end);
- }
- }
-
- /**
- * Private constructor to force use of static factory methods.
- *
- * @param start
- * the start <code>Time</code>
- * @param end
- * the end <code>Time</code>
- * @throws IllegalArgumentException
- * thrown if start <code>Time</code> value is before end <code>Time</code> value
- */
- private TimeFrame(final Time start, final Time end)
- {
- check(start, end);
- this.start = start;
- this.end = end;
- }
-
- /**
- * Determines if this <code>TimeFrame</code> contains a given point in time.
- *
- * @param time
- * the <code>Time</code> to check
- * @return <code>true</code> if this <code>TimeFrame</code> contains the given time
- */
- public boolean contains(final Time time)
- {
- return (start.equals(time) || start.before(time)) && end.after(time);
- }
-
- /**
- * Retrieves the <code>Duration</code> of this <code>TimeFrame</code>.
- *
- * @return the <code>Duration</code> of this <code>TimeFrame</code>
- */
- public Duration getDuration()
- {
- return end.subtract(start);
- }
-
- /**
- * Retrieves the end <code>Time</code> of this <code>TimeFrame</code>.
- *
- * @return the end of this <code>TimeFrame</code>
- */
- public Time getEnd()
- {
- return end;
- }
-
- /**
- * Retrieves the start <code>Time</code> of this <code>TimeFrame</code>.
- *
- * @return the start of this <code>TimeFrame</code>
- */
- public Time getStart()
- {
- return start;
- }
-
- /**
- * Implementation of <code>ITimeFrameSource</code> that simply returns this
- * <code>TimeFrame</code>.
- *
- * @return this <code>TimeFrame</code>
- */
- @Override
- public TimeFrame getTimeFrame()
- {
- return this;
- }
-
- /**
- * Determines if two <code>TimeFrame</code>s overlap.
- *
- * @param timeframe
- * the <code>TimeFrame</code> to test
- * @return <code>true</code> if the given <code>TimeFrame</code> overlaps this one
- */
- public boolean overlaps(final TimeFrame timeframe)
- {
- return contains(timeframe.start) || contains(timeframe.end) || timeframe.contains(start) ||
- timeframe.contains(end);
- }
-
- @Override
- public int hashCode()
- {
- return Objects.hashCode(start, end);
- }
-
- @Override
- public boolean equals(final 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);
- }
-
- /**
- * Converts this <code>TimeFrame</code> to a <code>String</code> representation.
- *
- * @return a <code>String</code> representation of this object
- */
- @Override
- public String toString()
- {
- return "[start=" + start + ", end=" + end + "]";
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/TimeMap.java b/wicket-util/src/main/java/org/apache/wicket/util/time/TimeMap.java
deleted file mode 100755
index 0de939c..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/TimeMap.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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 java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * This class maps <code>ITimeFrame</code>s to <code>Object</code>s. Since values are stored using
- * <code>ITimeFrameSource</code> implementing objects, the value returned by the source may vary
- * over time. For example, one implementation of <code>ITimeFrameSource</code> might return the
- * start and end time of lunch on any given day.
- * <p>
- * To associate an object with a dynamic <code>TimeFrame</code> (via <code>ITimeFrameSource</code>),
- * call <code>put(ITimeFrameSource, Object)</code>. You can later retrieve the first object for a
- * point in time with <code>get(Time)</code>. The <code>get</code> method is provided for
- * convenience and is equivalent to <code>get(Time.now())</code>.
- * <p>
- * This class is not thread-safe.
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-public final class TimeMap implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * <code>Map</code> from <code>ITimeFrameSource</code> implementing objects to
- * <code>Object</code> values.
- */
- private final Map<ITimeFrameSource, Object> sources = new ConcurrentHashMap<>();
-
- /**
- * Retrieves an <code>Object</code> for the current <code>Time</code> value.
- *
- * @return <code>Object</code> for the current <code>Time</code> value
- */
- public Object get()
- {
- return get(Time.now());
- }
-
- /**
- * Retrieves an <code>Object</code> for the given <code>Time</code> value.
- *
- * @param time
- * the <code>Time</code> value
- * @return gets an <code>Object</code> for the given <code>Time</code> value or
- * <code>null</code> if none exists
- */
- public Object get(final Time time)
- {
- for (ITimeFrameSource source : sources.keySet())
- {
- final TimeFrame current = source.getTimeFrame();
- if (current.contains(time))
- {
- return sources.get(current);
- }
- }
-
- return null;
- }
-
- /**
- * Associates an <code>Object</code> with a dynamic <code>TimeFrame</code>.
- *
- * @param source
- * a source that can produce a <code>TimeFrame</code> with which to compare a
- * <code>Time</code> value
- * @param o
- * the <code>Object</code> to be returned for the given dynamic
- * <code>TimeFrame</code>
- */
- public void put(final ITimeFrameSource source, final Object o)
- {
- final TimeFrame timeframe = source.getTimeFrame();
-
- for (ITimeFrameSource tfs : sources.keySet())
- {
- final TimeFrame current = tfs.getTimeFrame();
-
- if (timeframe.overlaps(current))
- {
- throw new IllegalArgumentException("Timeframe " + timeframe +
- " overlaps timeframe " + current);
- }
- }
-
- sources.put(source, o);
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/time/TimeOfDay.java b/wicket-util/src/main/java/org/apache/wicket/util/time/TimeOfDay.java
deleted file mode 100755
index c488404..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/time/TimeOfDay.java
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * 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 java.text.ParseException;
-import java.util.Calendar;
-
-import org.apache.wicket.util.lang.EnumeratedType;
-
-
-/**
- * An immutable time of day value represented as milliseconds since the most recent midnight.
- * <p>
- * Values can be constructed using various factory methods:
- * <ul>
- * <li><code>valueOf(long)</code> where <code>long</code> is milliseconds since midnight
- * <li><code>valueOf(String)</code> where the <code>String</code> is in 'h.mma' format
- * <li><code>valueOf(Calendar, String)</code> where the <code>String</code> is in 'h.mma' format
- * <li><code>valueOf(Duration)</code> where <code>Duration</code> is time since midnight
- * <li><code>valueOf(Time)</code> where <code>Time</code> is some point in time today
- * <li><code>valueOf(Calendar, Time)</code> where <code>Time</code> is some point in time today
- * <li><code>militaryTime(int hour, int minute, int second)</code> for 24-hour time
- * <li><code>time(int hour, int minute, Meridian)</code> where <code>Meridian</code> is AM or PM
- * <li><code>time(int hour, int minute, int second, Meridian)</code> where <code>Meridian</code> is
- * AM or PM
- * <li><code>now()</code> to construct the current time of day
- * <li><code>now(Calendar)</code> to construct the current time of day using a given
- * <code>Calendar</code>
- * </ul>
- * <p>
- * If an attempt is made to construct an illegal time of day value (one that is greater than 24
- * hours worth of milliseconds), an <code>IllegalArgumentException</code> will be thrown.
- * <p>
- * Military hours, minutes and seconds of the time of day can be retrieved by calling the
- * <code>hour</code>, <code>minute</code>, and <code>second</code> methods.
- * <p>
- * The next occurrence of a given <code>TimeOfDay</code> can be retrieved by calling
- * <code>next()</code> or <code>next(Calendar)</code>.
- *
- * @author Jonathan Locke
- * @since 1.2.6
- */
-public final class TimeOfDay extends AbstractTime
-{
- private static final long serialVersionUID = 1L;
-
- /** Constant for AM time. */
- public static final Meridian AM = new Meridian("AM");
-
- /** Constant for midnight. */
- public static final TimeOfDay MIDNIGHT = time(12, 0, AM);
-
- /** Constant for PM time. */
- public static final Meridian PM = new Meridian("PM");
-
- /** Constant for noon. */
- public static final TimeOfDay NOON = time(12, 0, PM);
-
- /** Typesafe AM/PM enumeration. */
- public static final class Meridian extends EnumeratedType
- {
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- *
- * @param name
- * the meridian name (value)
- */
- Meridian(final String name)
- {
- super(name);
- }
- }
-
- /**
- * Retrieves a <code>TimeOfDay</code> value on a 24-hour clock.
- *
- * @param hour
- * the hour (0-23)
- * @param minute
- * the minute (0-59)
- * @param second
- * the second (0-59)
- * @return the time of day
- */
- public static TimeOfDay militaryTime(final int hour, final int minute, final int second)
- {
- if ((hour > 23) || (hour < 0))
- {
- throw new IllegalArgumentException("Hour " + hour + " is not valid");
- }
-
- if ((minute > 59) || (minute < 0))
- {
- throw new IllegalArgumentException("Minute " + minute + " is not valid");
- }
-
- if ((second > 59) || (second < 0))
- {
- throw new IllegalArgumentException("Second " + second + " is not valid");
- }
-
- return valueOf(Duration.hours(hour)
- .add(Duration.minutes(minute))
- .add(Duration.seconds(second)));
- }
-
- /**
- * Retrieves the <code>TimeOfDay</code> representing 'now'.
- *
- * @return the time of day it is now
- */
- public static TimeOfDay now()
- {
- return valueOf(Time.now());
- }
-
- /**
- * Retrieves the <code>TimeOfDay</code> representing 'now' on the given <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> to use
- * @return the time of day it is now on the given <code>Calendar</code>
- */
- public static TimeOfDay now(final Calendar calendar)
- {
- return valueOf(calendar, Time.now());
- }
-
- /**
- * Retrieves a <code>TimeOfDay</code> on a 12-hour clock.
- *
- * @param hour
- * the hour (1-12)
- * @param minute
- * the minute (0-59)
- * @param second
- * the second (0-59)
- * @param meridian
- * AM or PM
- * @return the <code>TimeOfDay</code> value
- */
- public static TimeOfDay time(final int hour, final int minute, final int second,
- final Meridian meridian)
- {
- if (meridian == PM)
- {
- if (hour == 12)
- {
- return militaryTime(12, minute, second);
- }
- else
- {
- return militaryTime(hour + 12, minute, second);
- }
- }
- else
- {
- if (hour == 12)
- {
- return militaryTime(0, minute, second);
- }
- else
- {
- return militaryTime(hour, minute, second);
- }
- }
- }
-
- /**
- * Retrieves a <code>TimeOfDay</code> on a 12-hour clock.
- *
- * @param hour
- * the hour (1-12)
- * @param minute
- * the minute (0-59)
- * @param meridian
- * AM of PM
- * @return the <code>TimeOfDay</code> value
- */
- public static TimeOfDay time(final int hour, final int minute, final Meridian meridian)
- {
- return time(hour, minute, 0, meridian);
- }
-
- /**
- * Converts a time <code>String</code> and <code>Calendar</code> to a <code>TimeOfDay</code>
- * instance.
- *
- * @param calendar
- * the <code>Calendar</code> to use when parsing time <code>String</code>
- * @param time
- * a <code>String</code> in 'h.mma' format
- * @return the <code>TimeOfDay</code> on the given <code>Calendar</code>
- * @throws ParseException
- */
- public static TimeOfDay valueOf(final Calendar calendar, final String time)
- throws ParseException
- {
- synchronized (timeFormat)
- {
- synchronized (calendar)
- {
- timeFormat.setCalendar(calendar);
- return new TimeOfDay(timeFormat.parse(time).getTime());
- }
- }
- }
-
- /**
- * Converts a <code>Time</code> instance and <code>Calendar</code> to a <code>TimeOfDay</code>
- * instance.
- *
- * @param calendar
- * the <code>Calendar</code> to use
- * @param time
- * a <code>Time</code> instance
- * @return the <code>TimeOfDay</code> on the given <code>Calendar</code>
- */
- public static TimeOfDay valueOf(final Calendar calendar, final Time time)
- {
- return militaryTime(time.getHour(calendar), time.getMinute(calendar),
- time.getSecond(calendar));
- }
-
- /**
- * Converts a <code>Duration</code> instance to a <code>TimeOfDay</code> instance.
- *
- * @param duration
- * the <code>Duration</code> to use
- * @return the <code>TimeOfDay</code> of the given <code>Duration</code>
- */
- public static TimeOfDay valueOf(final Duration duration)
- {
- return new TimeOfDay(duration.getMilliseconds());
- }
-
- /**
- * Converts a <code>long</code> value to a <code>TimeOfDay</code> instance.
- *
- * @param time
- * the time in milliseconds today
- * @return the <code>TimeOfDay</code>
- */
- public static TimeOfDay valueOf(final long time)
- {
- return new TimeOfDay(time);
- }
-
- /**
- * Converts a <code>String</code> value to a <code>TimeOfDay</code> instance.
- *
- * @param time
- * a <code>String</code> in 'h.mma' format
- * @return the <code>TimeOfDay</code>
- * @throws ParseException
- */
- public static TimeOfDay valueOf(final String time) throws ParseException
- {
- return valueOf(localtime, time);
- }
-
- /**
- * Converts a <code>String</code> value to a <code>TimeOfDay</code> instance.
- *
- * @param time
- * a <code>Time</code> to convert to <code>TimeOfDay</code>
- * @return the <code>TimeOfDay</code> in the current time zone
- */
- public static TimeOfDay valueOf(final Time time)
- {
- return valueOf(AbstractTime.localtime, time);
- }
-
- /**
- * Private utility constructor forces use of static factory methods.
- *
- * @param time
- * the time today in milliseconds
- */
- private TimeOfDay(final long time)
- {
- super(time);
-
- // A time of day value must be less than 1 day of milliseconds
- if (Duration.valueOf(time).greaterThan(Duration.ONE_DAY))
- {
- throw new IllegalArgumentException("Time " + this + " is not a time of day value");
- }
- }
-
- /**
- * Retrieves the hour of the day.
- *
- * @return the hour (0-23) of this <code>TimeOfDay</code>
- */
- public int hour()
- {
- return toHours(getMilliseconds());
- }
-
- /**
- * Retrieves the minute.
- *
- * @return the minute (0-59) of this <code>TimeOfDay</code>
- */
- public int minute()
- {
- return toMinutes(getMilliseconds()) % 60;
- }
-
- /**
- * Retrieves the next occurrence of this <code>TimeOfDay</code> in local time.
- *
- * @return the next occurrence of this <code>TimeOfDay</code> in local time
- */
- public Time next()
- {
- return next(AbstractTime.localtime);
- }
-
- /**
- * Retrieves the next occurrence of this <code>TimeOfDay</code> on the given
- * <code>Calendar</code>.
- *
- * @param calendar
- * the <code>Calendar</code> to use
- * @return the next occurrence of this <code>TimeOfDay</code> on the given <code>Calendar</code>
- */
- public Time next(final Calendar calendar)
- {
- // Get this time of day today
- final Time timeToday = Time.valueOf(calendar, this);
-
- // If it has already passed
- if (timeToday.before(Time.now()))
- {
- // Return the time tomorrow
- return Time.valueOf(calendar, this).add(Duration.ONE_DAY);
- }
- else
- {
- // Time hasn't happened yet today
- return timeToday;
- }
- }
-
- /**
- * Retrieves the second.
- *
- * @return the second (0-59)
- */
- public int second()
- {
- return toSeconds(getMilliseconds()) % 60;
- }
-
- /**
- * @see Object#toString()
- */
- @Override
- public String toString()
- {
- final int second = second();
- return "" + hour() + ":" + minute() + (second != 0 ? ":" + second : "");
- }
-
- /**
- * Retrieves milliseconds as hours.
- *
- * @param milliseconds
- * milliseconds to convert
- * @return converted input
- */
- private int toHours(final long milliseconds)
- {
- return toMinutes(milliseconds) / 60;
- }
-
- /**
- * Retrieves milliseconds as minutes.
- *
- * @param milliseconds
- * milliseconds to convert
- * @return converted input
- */
- private int toMinutes(final long milliseconds)
- {
- return toSeconds(milliseconds) / 60;
- }
-
- /**
- * Retrieves milliseconds as seconds.
- *
- * @param milliseconds
- * milliseconds to convert
- * @return converted input
- */
- private int toSeconds(final long milliseconds)
- {
- return (int)(milliseconds / 1000);
- }
-}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/value/CopyOnWriteValueMap.java b/wicket-util/src/main/java/org/apache/wicket/util/value/CopyOnWriteValueMap.java
index 6cbe048..fa2834c 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/value/CopyOnWriteValueMap.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/value/CopyOnWriteValueMap.java
@@ -17,14 +17,15 @@
package org.apache.wicket.util.value;
import java.io.Serializable;
+import java.sql.Time;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.string.StringValueConversionException;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
@@ -256,12 +257,12 @@ public class CopyOnWriteValueMap implements IValueMap, Serializable
}
/**
- * @see IValueMap#getTime(String)
+ * @see IValueMap#getInstant(String)
*/
@Override
- public Time getTime(final String key) throws StringValueConversionException
+ public Instant getInstant(final String key) throws StringValueConversionException
{
- return wrapped.getTime(key);
+ return wrapped.getInstant(key);
}
/**
@@ -446,19 +447,19 @@ public class CopyOnWriteValueMap implements IValueMap, Serializable
}
/**
- * @see IValueMap#getAsTime(String)
+ * @see IValueMap#getAsInstant(String)
*/
@Override
- public Time getAsTime(final String key)
+ public Instant getAsInstant(final String key)
{
- return wrapped.getAsTime(key);
+ return wrapped.getAsInstant(key);
}
/**
* @see IValueMap#getAsTime(String, Time)
*/
@Override
- public Time getAsTime(final String key, final Time defaultValue)
+ public Instant getAsTime(final String key, final Instant defaultValue)
{
return wrapped.getAsTime(key, defaultValue);
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/value/IValueMap.java b/wicket-util/src/main/java/org/apache/wicket/util/value/IValueMap.java
index 00acdbb..f46fb6d 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/value/IValueMap.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/value/IValueMap.java
@@ -16,12 +16,12 @@
*/
package org.apache.wicket.util.value;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Map;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.string.StringValueConversionException;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
@@ -173,14 +173,14 @@ public interface IValueMap extends Map<String, Object>
StringValue getStringValue(final String key);
/**
- * Retrieves a <code>Time</code> object by key.
+ * Retrieves a <code>Instant</code> object by key.
*
* @param key
* the key
- * @return the <code>Time</code> object
+ * @return the <code>Instant</code> object
* @throws StringValueConversionException
*/
- Time getTime(final String key) throws StringValueConversionException;
+ Instant getInstant(final String key) throws StringValueConversionException;
/**
* Returns whether or not this <code>IValueMap</code> is immutable.
@@ -359,7 +359,7 @@ public interface IValueMap extends Map<String, Object>
* <code>IValueMap</code>
*
*/
- Time getAsTime(String key);
+ Instant getAsInstant(String key);
/**
* Retrieves a <code>Time</code> value by key.
@@ -374,7 +374,7 @@ public interface IValueMap extends Map<String, Object>
* <code>IValueMap</code>
*
*/
- Time getAsTime(String key, Time defaultValue);
+ Instant getAsTime(String key, Instant defaultValue);
/**
* Retrieves an <code>Enum</code> value by key.
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/value/ValueMap.java b/wicket-util/src/main/java/org/apache/wicket/util/value/ValueMap.java
index ede0d3f..c0c5e00 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/value/ValueMap.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/value/ValueMap.java
@@ -19,6 +19,9 @@ package org.apache.wicket.util.value;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.sql.Time;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -29,8 +32,6 @@ import org.apache.wicket.util.string.IStringIterator;
import org.apache.wicket.util.string.StringList;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.string.StringValueConversionException;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
/**
@@ -419,12 +420,12 @@ public class ValueMap extends LinkedHashMap<String, Object> implements IValueMap
}
/**
- * @see IValueMap#getTime(String)
+ * @see IValueMap#getInstant(String)
*/
@Override
- public final Time getTime(final String key) throws StringValueConversionException
+ public final Instant getInstant(final String key) throws StringValueConversionException
{
- return getStringValue(key).toTime();
+ return getStringValue(key).toInstant();
}
/**
@@ -754,10 +755,10 @@ public class ValueMap extends LinkedHashMap<String, Object> implements IValueMap
}
/**
- * @see IValueMap#getAsTime(String)
+ * @see IValueMap#getAsInstant(String)
*/
@Override
- public Time getAsTime(final String key)
+ public Instant getAsInstant(final String key)
{
return getAsTime(key, null);
}
@@ -766,7 +767,7 @@ public class ValueMap extends LinkedHashMap<String, Object> implements IValueMap
* @see IValueMap#getAsTime(String, Time)
*/
@Override
- public Time getAsTime(final String key, final Time defaultValue)
+ public Instant getAsTime(final String key, final Instant defaultValue)
{
if (!containsKey(key))
{
@@ -775,7 +776,7 @@ public class ValueMap extends LinkedHashMap<String, Object> implements IValueMap
try
{
- return getTime(key);
+ return getInstant(key);
}
catch (StringValueConversionException ignored)
{
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/watch/IModifiable.java b/wicket-util/src/main/java/org/apache/wicket/util/watch/IModifiable.java
index 77905af..556d30b 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/watch/IModifiable.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/watch/IModifiable.java
@@ -16,7 +16,7 @@
*/
package org.apache.wicket.util.watch;
-import org.apache.wicket.util.time.Time;
+import java.time.Instant;
/**
* Interface to get the last time something was modified.
@@ -32,5 +32,5 @@ public interface IModifiable
* @return the last modification <code>Time</code> or
* <code>null</code> if that information is not available
*/
- Time lastModifiedTime();
+ Instant lastModifiedTime();
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/watch/IModificationWatcher.java b/wicket-util/src/main/java/org/apache/wicket/util/watch/IModificationWatcher.java
index 8afe221..fc3e485 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/watch/IModificationWatcher.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/watch/IModificationWatcher.java
@@ -19,7 +19,7 @@ package org.apache.wicket.util.watch;
import java.util.Set;
import org.apache.wicket.util.listener.IChangeListener;
-import org.apache.wicket.util.time.Duration;
+import java.time.Duration;
/**
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java b/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
index c37317a..c95ac20 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
@@ -16,16 +16,15 @@
*/
package org.apache.wicket.util.watch;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-
import org.apache.wicket.util.lang.Generics;
import org.apache.wicket.util.listener.ChangeListenerSet;
import org.apache.wicket.util.listener.IChangeListener;
import org.apache.wicket.util.thread.ICode;
import org.apache.wicket.util.thread.Task;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,7 +53,7 @@ public class ModificationWatcher implements IModificationWatcher
protected static final class Entry
{
// The most recent lastModificationTime polled on the object
- public Time lastModifiedTime;
+ public Instant lastModifiedTime;
// The set of listeners to call when the modifiable changes
public final ChangeListenerSet<IModifiable> listeners = new ChangeListenerSet<>();
@@ -90,7 +89,7 @@ public class ModificationWatcher implements IModificationWatcher
// Found it?
if (entry == null)
{
- Time lastModifiedTime = modifiable.lastModifiedTime();
+ Instant lastModifiedTime = modifiable.lastModifiedTime();
if (lastModifiedTime != null)
{
// Construct new entry
@@ -154,9 +153,9 @@ public class ModificationWatcher implements IModificationWatcher
{
// If the modifiable has been modified after the last known
// modification time
- final Time modifiableLastModified = entry.modifiable.lastModifiedTime();
+ final Instant modifiableLastModified = entry.modifiable.lastModifiedTime();
if ((modifiableLastModified != null) &&
- modifiableLastModified.after(entry.lastModifiedTime))
+ modifiableLastModified.isAfter(entry.lastModifiedTime))
{
// Notify all listeners that the modifiable was modified
entry.listeners.notifyListeners(entry.modifiable);
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/io/ConnectionsTest.java b/wicket-util/src/test/java/org/apache/wicket/util/io/ConnectionsTest.java
index b0b0c0f..5ea6f25 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/io/ConnectionsTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/io/ConnectionsTest.java
@@ -16,16 +16,14 @@
*/
package org.apache.wicket.util.io;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import java.net.URL;
+import java.time.Instant;
import org.apache.wicket.util.WicketTestTag;
-import org.apache.wicket.util.time.Time;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import java.net.URL;
-
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
/**
* Tests for {@link Connections}
*/
@@ -39,8 +37,8 @@ public class ConnectionsTest
public void getLastModified() throws Exception
{
URL url = new URL("http://wicket.apache.org/learn/books/wia.png");
- Time lastModified = Connections.getLastModified(url);
+ Instant lastModified = Connections.getLastModified(url);
assertNotNull(lastModified);
- assertNotEquals(lastModified.getMilliseconds(), 0L);
+ assertNotEquals(lastModified.toEpochMilli(), 0L);
}
}
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/io/LastModifiedTest.java b/wicket-util/src/test/java/org/apache/wicket/util/io/LastModifiedTest.java
index 481ef87..2ed3710 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/io/LastModifiedTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/io/LastModifiedTest.java
@@ -16,15 +16,15 @@
*/
package org.apache.wicket.util.io;
-import org.apache.wicket.util.file.Files;
-import org.apache.wicket.util.time.Time;
-import org.junit.jupiter.api.Test;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-
-import static org.junit.jupiter.api.Assertions.*;
+import java.time.Instant;
+import org.apache.wicket.util.file.Files;
+import org.junit.jupiter.api.Test;
/**
* @author pertl
@@ -82,7 +82,7 @@ public class LastModifiedTest
// it could be the case that the current system does not support last-modified at all
if (lm != 0)
{
- final Time expected = Time.millis(lm);
+ final Instant expected = Instant.ofEpochMilli(lm);
assertEquals(expected, Files.getLastModified(file));
assertEquals(expected,
Connections.getLastModified(new URL("file:" + file.getAbsolutePath())));
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java b/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
index 527b3ad..19bf6a3 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
@@ -16,13 +16,18 @@
*/
package org.apache.wicket.util.string;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
-import org.junit.jupiter.api.Test;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.time.Duration;
+import java.time.Instant;
import java.util.Locale;
-import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
@SuppressWarnings("javadoc")
public class StringValueTest
@@ -55,7 +60,7 @@ public class StringValueTest
assertNull(sv.toOptionalInteger());
assertNull(sv.toOptionalLong());
assertEquals("", sv.toOptionalString());
- assertNull(sv.toOptionalTime());
+ assertNull(sv.toOptionalInstant());
}
/**
@@ -72,7 +77,7 @@ public class StringValueTest
assertNull(sv.toOptionalInteger());
assertNull(sv.toOptionalLong());
assertNull(sv.toOptionalString());
- assertNull(sv.toOptionalTime());
+ assertNull(sv.toOptionalInstant());
}
/**
@@ -89,8 +94,8 @@ public class StringValueTest
assertEquals(4, sv.toInt(4));
assertEquals(4.0, sv.toDouble(4.0), 0.005);
assertEquals('c', sv.toChar('c'));
- assertEquals(Duration.seconds(3), sv.toDuration(Duration.seconds(3)));
- assertEquals(Time.millis(5), sv.toTime(Time.millis(5)));
+ assertEquals(Duration.ofSeconds(3), sv.toDuration(Duration.ofSeconds(3)));
+ assertEquals(Instant.ofEpochMilli(5), sv.toInstant(Instant.ofEpochMilli(5)));
assertEquals(40L, sv.toLong(40));
assertEquals("unknown", sv.toString("def"));
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/time/DurationTest.java b/wicket-util/src/test/java/org/apache/wicket/util/time/DurationTest.java
deleted file mode 100644
index 1ff1460..0000000
--- a/wicket-util/src/test/java/org/apache/wicket/util/time/DurationTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * 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 org.apache.wicket.util.string.StringValueConversionException;
-import org.junit.jupiter.api.Test;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-import java.util.Locale.Category;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Test cases for this object
- *
- * @author Jonathan Locke
- */
-public final class DurationTest
-{
- /**
- * @throws StringValueConversionException
- */
- @Test
- public void values() throws StringValueConversionException
- {
- assertEquals(Duration.milliseconds(3000), Duration.seconds(3));
- assertEquals(Duration.seconds(120), Duration.minutes(2));
- assertEquals(Duration.minutes(1440), Duration.hours(24));
- assertEquals(Duration.hours(48), Duration.days(2));
- assertEquals(Duration.minutes(90), Duration.valueOf("90 minutes"));
- assertEquals(Duration.days(9), Duration.valueOf("9 days"));
- assertEquals(Duration.hours(1), Duration.valueOf("1 hour"));
- assertTrue(9 == Duration.days(9).days());
- assertTrue(11 == Duration.hours(11).hours());
- assertTrue(21 == Duration.minutes(21).minutes());
- assertTrue(51 == Duration.seconds(51).seconds());
- }
-
- /** */
- @Test
- public void operations()
- {
- assertTrue(Duration.milliseconds(3001).greaterThan(Duration.seconds(3)));
- assertTrue(Duration.milliseconds(3001).greaterThanOrEqual(Duration.seconds(3)));
- assertTrue(Duration.milliseconds(3000).greaterThanOrEqual(Duration.seconds(3)));
- assertTrue(Duration.milliseconds(2999).lessThan(Duration.seconds(3)));
- assertTrue(Duration.milliseconds(2999).lessThanOrEqual(Duration.seconds(3)));
- assertTrue(Duration.milliseconds(3000).lessThanOrEqual(Duration.seconds(3)));
- assertEquals(-1, Duration.milliseconds(2999).compareTo(Duration.seconds(3)));
- assertEquals(1, Duration.milliseconds(3001).compareTo(Duration.seconds(3)));
- assertEquals(0, Duration.milliseconds(3000).compareTo(Duration.seconds(3)));
- assertEquals(Duration.minutes(10), Duration.minutes(4).add(Duration.minutes(6)));
- assertEquals(Duration.ONE_HOUR, Duration.minutes(90).subtract(Duration.minutes(30)));
-
- String value = NumberFormat.getNumberInstance().format(1.5);
-
- assertEquals(value + " minutes", Duration.seconds(90).toString());
- assertEquals("12 hours", Duration.days(0.5).toString());
- }
-
- @Test
- public void formatLocale() throws Exception
- {
- final Locale oldFormatLocale = Locale.getDefault(Category.FORMAT);
- final Locale oldDefaultLocale = Locale.getDefault();
- try
- {
- Locale.setDefault(Locale.US);
- Locale.setDefault(Category.FORMAT, Locale.GERMANY);
- assertEquals("1,5 minutes", Duration.seconds(90)
- .toString(), "should take formatting locale into account");
- } finally
- {
- Locale.setDefault(oldDefaultLocale);
- Locale.setDefault(Category.FORMAT, oldFormatLocale);
- }
- }
-
- /** */
- @Test
- public void testSleep()
- {
- assertTrue(Duration.seconds(0.5).lessThan(Duration.benchmark(new Runnable()
- {
- @Override
- public void run()
- {
- Duration.seconds(1.5).sleep();
- }
- })));
-
- assertTrue(Duration.seconds(1).greaterThan(Duration.benchmark(new Runnable()
- {
- @Override
- public void run()
- {
- Duration.hours(-1).sleep();
- }
- })));
- }
-
- /**
- * @throws StringValueConversionException
- */
- @Test
- public void locale() throws StringValueConversionException
- {
- assertEquals(Duration.minutes(90), Duration.valueOf("90 minutes"));
- assertEquals(Duration.hours(1.5), Duration.valueOf("1.5 hour", Locale.US));
- assertEquals(Duration.hours(1.5), Duration.valueOf("1,5 hour", Locale.GERMAN));
- assertEquals("1.5 hours", Duration.hours(1.5).toString(Locale.US));
- assertEquals("1,5 hours", Duration.hours(1.5).toString(Locale.GERMAN));
- }
-
-
- /**
- * Check if toString(Locale locale) respects the appropriate value and format (in English).
- */
- @Test
- public void toStringValues()
- {
- assertEquals("1 day", Duration.days(1).toString(Locale.ENGLISH));
- assertEquals("5 days", Duration.days(5).toString(Locale.ENGLISH));
-
- assertEquals("1 hour", Duration.hours(1).toString(Locale.ENGLISH));
- assertEquals("23 hours", Duration.hours(23).toString(Locale.ENGLISH));
-
- assertEquals("1 minute", Duration.minutes(1).toString(Locale.ENGLISH));
- assertEquals("2 minutes", Duration.minutes(2).toString(Locale.ENGLISH));
-
- assertEquals("1 second", Duration.seconds(1).toString(Locale.ENGLISH));
- assertEquals("2 seconds", Duration.seconds(2).toString(Locale.ENGLISH));
-
- assertEquals("1 millisecond", Duration.milliseconds(1).toString(Locale.ENGLISH));
- assertEquals("955 milliseconds", Duration.milliseconds(955).toString(Locale.ENGLISH));
- }
-}
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java b/wicket-util/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
deleted file mode 100644
index 9b23927..0000000
--- a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeFrameTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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 org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-/**
- * @author v857829
- */
-public class TimeFrameTest
-{
-
- 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
- * {@link org.apache.wicket.util.time.TimeFrame#eachDay(org.apache.wicket.util.time.TimeOfDay, org.apache.wicket.util.time.TimeOfDay)}
- * .
- */
- @Test
- public void eachDay()
- {
- ITimeFrameSource test = TimeFrame.eachDay(three, five);
- assertTrue(test.getTimeFrame().contains(Time.valueOf(four)));
- }
-
- /**
- * Test method for
- * {@link org.apache.wicket.util.time.TimeFrame#valueOf(org.apache.wicket.util.time.Time, org.apache.wicket.util.time.Duration)}
- * .
- */
- @Test
- public void valueOfTimeDuration()
- {
- TimeFrame test = TimeFrame.valueOf(Time.valueOf(three), Duration.minutes(60));
- assertEquals(test.getStart(), Time.valueOf(three));
- assertEquals(test.getEnd(), Time.valueOf(four));
- }
-
- /**
- * Test method for
- * {@link org.apache.wicket.util.time.TimeFrame#contains(org.apache.wicket.util.time.Time)}.
- */
- @Test
- public void contains()
- {
- TimeFrame test = TimeFrame.valueOf(Time.valueOf(three), Duration.minutes(70));
- assertTrue(test.contains(Time.valueOf(four)));
- }
-
- /**
- * Test method for
- * {@link org.apache.wicket.util.time.TimeFrame#overlaps(org.apache.wicket.util.time.TimeFrame)}
- * .
- */
- @Test
- public void overlaps()
- {
- 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));
- assertTrue(test.overlaps(test2));
- assertTrue(test3.overlaps(test2));
- assertTrue(test.overlaps(test3));
- assertFalse(test4.overlaps(test3));
- }
-
- /**
- * Test method for {@link org.apache.wicket.util.time.TimeFrame#equals(java.lang.Object)}.
- */
- @Test
- 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));
- assertEquals(test, test2);
- assertNotSame(test2, test3);
- }
-
-}
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeMapTest.java b/wicket-util/src/test/java/org/apache/wicket/util/time/TimeMapTest.java
deleted file mode 100644
index 508f2ff..0000000
--- a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeMapTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 org.junit.jupiter.api.Test;
-
-import java.text.ParseException;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-/**
- * Test cases for this object
- *
- * @author Jonathan Locke
- */
-public final class TimeMapTest
-{
- /**
- *
- * @throws ParseException
- */
- @Test
- public void simpleStaticTimeFrame() throws ParseException
- {
- final TimeMap map = new TimeMap();
- final Time start = Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH),
- "3.14pm"));
- final Time end = Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH),
- "3.20pm"));
- final String value = "test";
-
- map.put(TimeFrame.valueOf(start, end), value);
- assertEquals(
- value,
- map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH), "3.15pm"))));
- assertNull(map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH),
- "3.21pm"))));
- assertNull(map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH),
- "3.13pm"))));
- }
-}
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeTest.java b/wicket-util/src/test/java/org/apache/wicket/util/time/TimeTest.java
deleted file mode 100644
index 5593ed0..0000000
--- a/wicket-util/src/test/java/org/apache/wicket/util/time/TimeTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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 org.junit.jupiter.api.Test;
-
-import java.text.ParseException;
-import java.util.Calendar;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-@SuppressWarnings("javadoc")
-public final class TimeTest
-{
- @Test
- public void test() throws ParseException
- {
- Time.now();
-
- final Time birthday = Time.parseDate("1966.06.01");
-
- assertEquals(1966, birthday.getYear());
- assertEquals(Calendar.JUNE, birthday.getMonth());
- assertEquals(1, birthday.getDayOfMonth());
-
- final String y2k = "2000.01.01-12.00am";
-
- assertEquals(y2k, Time.valueOf(y2k).toString());
- }
-
- /**
- * WICKET-5442 getHour() should be on 24-hour clock
- */
- @Test
- public void hour() throws ParseException
- {
- Time time = Time.valueOf("2000.10.30-9.30PM");
- assertEquals(21, time.getHour());
- }
-}
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java b/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java
index 2b5671b..be3d6b7 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/value/ValueMapTest.java
@@ -16,14 +16,15 @@
*/
package org.apache.wicket.util.value;
-import org.apache.wicket.util.time.Duration;
-import org.apache.wicket.util.time.Time;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
+import java.time.Duration;
+import java.time.Instant;
+
+import org.junit.jupiter.api.Test;
+
/**
* @author jcompagner
* @author Doug Donohoe
@@ -181,20 +182,20 @@ public class ValueMapTest
Integer integerValue = 42;
Long longValue = integerValue * 1L;
Double doubleValue = integerValue * 1.0D;
- Time timeValue = Time.now();
- Duration durationValue = Duration.hours(1);
+ Instant timeValue = Instant.now();
+ Duration durationValue = Duration.ofHours(1);
boolean defBoolean = !booleanValue;
int defInteger = 10101;
long defLong = defInteger * 1L;
double defDouble = defInteger * 1.0D;
- Time defTime = Time.now();
- Duration defDuration = Duration.hours(42);
+ Instant defTime = Instant.now();
+ Duration defDuration = Duration.ofHours(42);
vm.put("num", integerValue.toString());
vm.put("num.bad", "xxx");
- vm.put("time", timeValue.toString());
- vm.put("time.bad", "xxx");
+ vm.put("instant", timeValue.toString());
+ vm.put("instant.bad", "xxx");
vm.put("duration", durationValue.toString());
vm.put("duration.bad", "xxx");
vm.put("boolean", booleanValue.toString());
@@ -229,14 +230,13 @@ public class ValueMapTest
assertNull(vm.getAsDouble("num.missing"));
assertEquals(defDouble, vm.getAsDouble("num.missing", defDouble), 0.001);
- // time
- assertEquals(timeValue.toString(), vm.getAsTime("time").toString()); // use toSTring since
- // equals seems
- // broken
- assertNull(vm.getAsTime("time.bad"));
- assertEquals(defTime, vm.getAsTime("time.bad", defTime));
- assertNull(vm.getAsTime("time.missing"));
- assertEquals(defTime, vm.getAsTime("time.missing", defTime));
+ // instant
+ assertEquals(timeValue, vm.getAsInstant("instant"));
+
+ assertNull(vm.getAsInstant("instant.bad"));
+ assertEquals(defTime, vm.getAsTime("instant.bad", defTime));
+ assertNull(vm.getAsInstant("instant.missing"));
+ assertEquals(defTime, vm.getAsTime("instant.missing", defTime));
// duration
assertEquals(durationValue, vm.getAsDuration("duration"));