update to gradle 7.3, adjust some modifiers, refactor inner enums
This commit is contained in:
parent
0e3a6d83d9
commit
ade86aad39
113 changed files with 796 additions and 1000 deletions
|
@ -9,7 +9,7 @@ wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
user = 'xbib'
|
user = 'jprante'
|
||||||
name = 'time'
|
name = 'time'
|
||||||
description = 'A bundle of Chronic, Prettytime, and org.joda.time.format optimized for Java 8 Time API'
|
description = 'A bundle of Chronic, Prettytime, and org.joda.time.format optimized for Java 8 Time API'
|
||||||
inceptionYear = '2016'
|
inceptionYear = '2016'
|
||||||
|
|
|
@ -1,323 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE module PUBLIC
|
|
||||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
|
||||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
|
||||||
|
|
||||||
<!-- This is a checkstyle configuration file. For descriptions of
|
|
||||||
what the following rules do, please see the checkstyle configuration
|
|
||||||
page at http://checkstyle.sourceforge.net/config.html -->
|
|
||||||
|
|
||||||
<module name="Checker">
|
|
||||||
|
|
||||||
<module name="FileTabCharacter">
|
|
||||||
<!-- Checks that there are no tab characters in the file.
|
|
||||||
-->
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="NewlineAtEndOfFile">
|
|
||||||
<property name="lineSeparator" value="lf"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="RegexpSingleline">
|
|
||||||
<!-- Checks that FIXME is not used in comments. TODO is preferred.
|
|
||||||
-->
|
|
||||||
<property name="format" value="((//.*)|(\*.*))FIXME" />
|
|
||||||
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="RegexpSingleline">
|
|
||||||
<!-- Checks that TODOs are named. (Actually, just that they are followed
|
|
||||||
by an open paren.)
|
|
||||||
-->
|
|
||||||
<property name="format" value="((//.*)|(\*.*))TODO[^(]" />
|
|
||||||
<property name="message" value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="JavadocPackage">
|
|
||||||
<!-- Checks that each Java package has a Javadoc file used for commenting.
|
|
||||||
Only allows a package-info.java, not package.html. -->
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<!-- All Java AST specific tests live under TreeWalker module. -->
|
|
||||||
<module name="TreeWalker">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
IMPORT CHECKS
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<module name="RedundantImport">
|
|
||||||
<!-- Checks for redundant import statements. -->
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="ImportOrder">
|
|
||||||
<!-- Checks for out of order import statements. -->
|
|
||||||
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
<property name="groups" value="com,junit,net,org,java,javax"/>
|
|
||||||
<!-- This ensures that static imports go first. -->
|
|
||||||
<property name="option" value="top"/>
|
|
||||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
JAVADOC CHECKS
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Checks for Javadoc comments. -->
|
|
||||||
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
|
||||||
<module name="JavadocMethod">
|
|
||||||
<property name="scope" value="protected"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
<property name="allowMissingJavadoc" value="true"/>
|
|
||||||
<property name="allowMissingParamTags" value="true"/>
|
|
||||||
<property name="allowMissingReturnTag" value="true"/>
|
|
||||||
<property name="allowMissingThrowsTags" value="true"/>
|
|
||||||
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
|
||||||
<property name="allowUndeclaredRTE" value="true"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="JavadocType">
|
|
||||||
<property name="scope" value="protected"/>
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="JavadocStyle">
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
NAMING CHECKS
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Item 38 - Adhere to generally accepted naming conventions -->
|
|
||||||
|
|
||||||
<module name="PackageName">
|
|
||||||
<!-- Validates identifiers for package names against the
|
|
||||||
supplied expression. -->
|
|
||||||
<!-- Here the default checkstyle rule restricts package name parts to
|
|
||||||
seven characters, this is not in line with common practice at Google.
|
|
||||||
-->
|
|
||||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="TypeNameCheck">
|
|
||||||
<!-- Validates static, final fields against the
|
|
||||||
expression "^[A-Z][a-zA-Z0-9]*$". -->
|
|
||||||
<metadata name="altname" value="TypeName"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="ConstantNameCheck">
|
|
||||||
<!-- Validates non-private, static, final fields against the supplied
|
|
||||||
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
|
|
||||||
<metadata name="altname" value="ConstantName"/>
|
|
||||||
<property name="applyToPublic" value="true"/>
|
|
||||||
<property name="applyToProtected" value="true"/>
|
|
||||||
<property name="applyToPackage" value="true"/>
|
|
||||||
<property name="applyToPrivate" value="false"/>
|
|
||||||
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
|
|
||||||
<message key="name.invalidPattern"
|
|
||||||
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="StaticVariableNameCheck">
|
|
||||||
<!-- Validates static, non-final fields against the supplied
|
|
||||||
expression "^[a-z][a-zA-Z0-9]*_?$". -->
|
|
||||||
<metadata name="altname" value="StaticVariableName"/>
|
|
||||||
<property name="applyToPublic" value="true"/>
|
|
||||||
<property name="applyToProtected" value="true"/>
|
|
||||||
<property name="applyToPackage" value="true"/>
|
|
||||||
<property name="applyToPrivate" value="true"/>
|
|
||||||
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="MemberNameCheck">
|
|
||||||
<!-- Validates non-static members against the supplied expression. -->
|
|
||||||
<metadata name="altname" value="MemberName"/>
|
|
||||||
<property name="applyToPublic" value="true"/>
|
|
||||||
<property name="applyToProtected" value="true"/>
|
|
||||||
<property name="applyToPackage" value="true"/>
|
|
||||||
<property name="applyToPrivate" value="true"/>
|
|
||||||
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="MethodNameCheck">
|
|
||||||
<!-- Validates identifiers for method names. -->
|
|
||||||
<metadata name="altname" value="MethodName"/>
|
|
||||||
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="ParameterName">
|
|
||||||
<!-- Validates identifiers for method parameters against the
|
|
||||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="LocalFinalVariableName">
|
|
||||||
<!-- Validates identifiers for local final variables against the
|
|
||||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="LocalVariableName">
|
|
||||||
<!-- Validates identifiers for local variables against the
|
|
||||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
LENGTH and CODING CHECKS
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<module name="LineLength">
|
|
||||||
<!-- Checks if a line is too long. -->
|
|
||||||
<property name="max" value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.max}" default="128"/>
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The default ignore pattern exempts the following elements:
|
|
||||||
- import statements
|
|
||||||
- long URLs inside comments
|
|
||||||
-->
|
|
||||||
|
|
||||||
<property name="ignorePattern"
|
|
||||||
value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.ignorePattern}"
|
|
||||||
default="^(package .*;\s*)|(import .*;\s*)|( *(\*|//).*https?://.*)$"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="LeftCurly">
|
|
||||||
<!-- Checks for placement of the left curly brace ('{'). -->
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="RightCurly">
|
|
||||||
<!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
|
|
||||||
the same line. e.g., the following example is fine:
|
|
||||||
<pre>
|
|
||||||
if {
|
|
||||||
...
|
|
||||||
} else
|
|
||||||
</pre>
|
|
||||||
-->
|
|
||||||
<!-- This next example is not fine:
|
|
||||||
<pre>
|
|
||||||
if {
|
|
||||||
...
|
|
||||||
}
|
|
||||||
else
|
|
||||||
</pre>
|
|
||||||
-->
|
|
||||||
<property name="option" value="same"/>
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<!-- Checks for braces around if and else blocks -->
|
|
||||||
<module name="NeedBraces">
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="UpperEll">
|
|
||||||
<!-- Checks that long constants are defined with an upper ell.-->
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="FallThrough">
|
|
||||||
<!-- Warn about falling through to the next case statement. Similar to
|
|
||||||
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
|
|
||||||
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
|
|
||||||
some other variants which we don't publicized to promote consistency).
|
|
||||||
-->
|
|
||||||
<property name="reliefPattern"
|
|
||||||
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
MODIFIERS CHECKS
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<module name="ModifierOrder">
|
|
||||||
<!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
|
|
||||||
8.4.3. The prescribed order is:
|
|
||||||
public, protected, private, abstract, static, final, transient, volatile,
|
|
||||||
synchronized, native, strictfp
|
|
||||||
-->
|
|
||||||
</module>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
WHITESPACE CHECKS
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<module name="WhitespaceAround">
|
|
||||||
<!-- Checks that various tokens are surrounded by whitespace.
|
|
||||||
This includes most binary operators and keywords followed
|
|
||||||
by regular or curly braces.
|
|
||||||
-->
|
|
||||||
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
|
|
||||||
BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
|
|
||||||
EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
|
||||||
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
|
||||||
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
|
|
||||||
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
|
|
||||||
SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="WhitespaceAfter">
|
|
||||||
<!-- Checks that commas, semicolons and typecasts are followed by
|
|
||||||
whitespace.
|
|
||||||
-->
|
|
||||||
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="NoWhitespaceAfter">
|
|
||||||
<!-- Checks that there is no whitespace after various unary operators.
|
|
||||||
Linebreaks are allowed.
|
|
||||||
-->
|
|
||||||
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
|
|
||||||
UNARY_PLUS"/>
|
|
||||||
<property name="allowLineBreaks" value="true"/>
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="NoWhitespaceBefore">
|
|
||||||
<!-- Checks that there is no whitespace before various unary operators.
|
|
||||||
Linebreaks are allowed.
|
|
||||||
-->
|
|
||||||
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
|
|
||||||
<property name="allowLineBreaks" value="true"/>
|
|
||||||
<property name="severity" value="error"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="ParenPad">
|
|
||||||
<!-- Checks that there is no whitespace before close parens or after
|
|
||||||
open parens.
|
|
||||||
-->
|
|
||||||
<property name="severity" value="warning"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
</module>
|
|
||||||
</module>
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = time
|
name = time
|
||||||
version = 2.1.1
|
version = 2.2.0
|
||||||
|
|
||||||
gradle.wrapper.version = 6.6.1
|
org.gradle.warning.mode = ALL
|
||||||
|
gradle.wrapper.version = 7.3
|
||||||
quartz.version = 2.3.2
|
quartz.version = 2.3.2
|
||||||
caliper.version = 1.0-beta-2
|
caliper.version = 1.0-beta-2
|
||||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
269
gradlew
vendored
269
gradlew
vendored
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright 2015 the original author or authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -17,67 +17,101 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
APP_BASE_NAME=${0##*/}
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
@ -106,80 +140,95 @@ location of your Java installation."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
warn "Could not query maximum file descriptor limit"
|
||||||
fi
|
esac
|
||||||
ulimit -n $MAX_FD
|
case $MAX_FD in #(
|
||||||
if [ $? -ne 0 ] ; then
|
'' | soft) :;; #(
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
*)
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
else
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=`expr $i + 1`
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
0) set -- ;;
|
|
||||||
1) set -- "$args0" ;;
|
|
||||||
2) set -- "$args0" "$args1" ;;
|
|
||||||
3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=`save "$@"`
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.time.chronic;
|
package org.xbib.time.chronic;
|
||||||
|
|
||||||
import org.xbib.time.chronic.tags.Pointer;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
@ -9,15 +9,21 @@ import java.time.ZonedDateTime;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Options {
|
public class Options {
|
||||||
|
|
||||||
private ZonedDateTime now;
|
private ZonedDateTime now;
|
||||||
|
|
||||||
private ZoneId zoneId;
|
private ZoneId zoneId;
|
||||||
private Pointer.PointerType context;
|
|
||||||
|
private PointerType context;
|
||||||
|
|
||||||
private boolean guess;
|
private boolean guess;
|
||||||
|
|
||||||
private int ambiguousTimeRange;
|
private int ambiguousTimeRange;
|
||||||
|
|
||||||
private boolean compatibilityMode;
|
private boolean compatibilityMode;
|
||||||
|
|
||||||
public Options() {
|
public Options() {
|
||||||
setContext(Pointer.PointerType.FUTURE);
|
setContext(PointerType.FUTURE);
|
||||||
setNow(ZonedDateTime.now());
|
setNow(ZonedDateTime.now());
|
||||||
setZoneId(ZoneId.of("GMT"));
|
setZoneId(ZoneId.of("GMT"));
|
||||||
setGuess(true);
|
setGuess(true);
|
||||||
|
@ -33,11 +39,11 @@ public class Options {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pointer.PointerType getContext() {
|
public PointerType getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Options setContext(Pointer.PointerType context) {
|
public Options setContext(PointerType context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,10 @@ package org.xbib.time.chronic;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Range {
|
public class Range {
|
||||||
private Long begin;
|
|
||||||
private Long end;
|
private final Long begin;
|
||||||
|
|
||||||
|
private final Long end;
|
||||||
|
|
||||||
public Range(long begin, long end) {
|
public Range(long begin, long end) {
|
||||||
this.begin = begin;
|
this.begin = begin;
|
||||||
|
|
|
@ -4,8 +4,10 @@ package org.xbib.time.chronic;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Tick {
|
public class Tick {
|
||||||
|
|
||||||
private int time;
|
private int time;
|
||||||
private boolean ambiguous;
|
|
||||||
|
private final boolean ambiguous;
|
||||||
|
|
||||||
public Tick(int time, boolean ambiguous) {
|
public Tick(int time, boolean ambiguous) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
|
|
@ -10,8 +10,10 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Token {
|
public class Token {
|
||||||
private String word;
|
|
||||||
private List<Tag<?>> tags;
|
private final String word;
|
||||||
|
|
||||||
|
private final List<Tag<?>> tags;
|
||||||
|
|
||||||
public Token(String word) {
|
public Token(String word) {
|
||||||
this.word = word;
|
this.word = word;
|
||||||
|
@ -35,13 +37,7 @@ public class Token {
|
||||||
* @param tagClass tag class
|
* @param tagClass tag class
|
||||||
*/
|
*/
|
||||||
public void untag(Class<?> tagClass) {
|
public void untag(Class<?> tagClass) {
|
||||||
Iterator<Tag<?>> tagIter = tags.iterator();
|
tags.removeIf(tagClass::isInstance);
|
||||||
while (tagIter.hasNext()) {
|
|
||||||
Tag<?> tag = tagIter.next();
|
|
||||||
if (tagClass.isInstance(tag)) {
|
|
||||||
tagIter.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +54,6 @@ public class Token {
|
||||||
* @param <T> type parameter
|
* @param <T> type parameter
|
||||||
* @return tag
|
* @return tag
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T extends Tag<?>> T getTag(Class<T> tagClass) {
|
public <T extends Tag<?>> T getTag(Class<T> tagClass) {
|
||||||
List<T> matches = getTags(tagClass);
|
List<T> matches = getTags(tagClass);
|
||||||
T matchingTag = null;
|
T matchingTag = null;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.xbib.time.chronic.handlers;
|
||||||
import org.xbib.time.chronic.Options;
|
import org.xbib.time.chronic.Options;
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
|
import org.xbib.time.chronic.repeaters.DayPortion;
|
||||||
import org.xbib.time.chronic.repeaters.EnumRepeaterDayPortion;
|
import org.xbib.time.chronic.repeaters.EnumRepeaterDayPortion;
|
||||||
import org.xbib.time.chronic.repeaters.IntegerRepeaterDayPortion;
|
import org.xbib.time.chronic.repeaters.IntegerRepeaterDayPortion;
|
||||||
import org.xbib.time.chronic.repeaters.Repeater;
|
import org.xbib.time.chronic.repeaters.Repeater;
|
||||||
|
@ -14,7 +15,8 @@ import org.xbib.time.chronic.tags.Grabber;
|
||||||
import org.xbib.time.chronic.tags.Ordinal;
|
import org.xbib.time.chronic.tags.Ordinal;
|
||||||
import org.xbib.time.chronic.tags.OrdinalDay;
|
import org.xbib.time.chronic.tags.OrdinalDay;
|
||||||
import org.xbib.time.chronic.tags.Pointer;
|
import org.xbib.time.chronic.tags.Pointer;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
import org.xbib.time.chronic.tags.Relative;
|
||||||
import org.xbib.time.chronic.tags.Scalar;
|
import org.xbib.time.chronic.tags.Scalar;
|
||||||
import org.xbib.time.chronic.tags.ScalarDay;
|
import org.xbib.time.chronic.tags.ScalarDay;
|
||||||
import org.xbib.time.chronic.tags.ScalarMonth;
|
import org.xbib.time.chronic.tags.ScalarMonth;
|
||||||
|
@ -202,7 +204,7 @@ public class Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Span getAnchor(List<Token> tokens, Options options) {
|
public static Span getAnchor(List<Token> tokens, Options options) {
|
||||||
Grabber grabber = new Grabber(Grabber.Relative.THIS);
|
Grabber grabber = new Grabber(Relative.THIS);
|
||||||
PointerType pointer = PointerType.FUTURE;
|
PointerType pointer = PointerType.FUTURE;
|
||||||
|
|
||||||
List<Repeater<?>> repeaters = getRepeaters(tokens);
|
List<Repeater<?>> repeaters = getRepeaters(tokens);
|
||||||
|
@ -219,16 +221,16 @@ public class Handler {
|
||||||
head.setNow(options.getNow());
|
head.setNow(options.getNow());
|
||||||
|
|
||||||
Span outerSpan;
|
Span outerSpan;
|
||||||
Grabber.Relative grabberType = grabber.getType();
|
Relative grabberType = grabber.getType();
|
||||||
if (grabberType == Grabber.Relative.LAST) {
|
if (grabberType == Relative.LAST) {
|
||||||
outerSpan = head.nextSpan(PointerType.PAST);
|
outerSpan = head.nextSpan(PointerType.PAST);
|
||||||
} else if (grabberType == Grabber.Relative.THIS) {
|
} else if (grabberType == Relative.THIS) {
|
||||||
if (!repeaters.isEmpty()) {
|
if (!repeaters.isEmpty()) {
|
||||||
outerSpan = head.thisSpan(PointerType.NONE);
|
outerSpan = head.thisSpan(PointerType.NONE);
|
||||||
} else {
|
} else {
|
||||||
outerSpan = head.thisSpan(options.getContext());
|
outerSpan = head.thisSpan(options.getContext());
|
||||||
}
|
}
|
||||||
} else if (grabberType == Grabber.Relative.NEXT) {
|
} else if (grabberType == Relative.NEXT) {
|
||||||
outerSpan = head.nextSpan(PointerType.FUTURE);
|
outerSpan = head.nextSpan(PointerType.FUTURE);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
|
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
|
||||||
|
@ -296,14 +298,14 @@ public class Handler {
|
||||||
Tag<RepeaterDayPortion<?>> t1Tag = t1.getTag(RepeaterDayPortion.class);
|
Tag<RepeaterDayPortion<?>> t1Tag = t1.getTag(RepeaterDayPortion.class);
|
||||||
|
|
||||||
Object t1TagType = t1Tag.getType();
|
Object t1TagType = t1Tag.getType();
|
||||||
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
|
if (DayPortion.MORNING.equals(t1TagType)) {
|
||||||
t1.untag(RepeaterDayPortion.class);
|
t1.untag(RepeaterDayPortion.class);
|
||||||
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
|
t1.tag(new EnumRepeaterDayPortion(DayPortion.AM));
|
||||||
} else if (RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType) ||
|
} else if (DayPortion.AFTERNOON.equals(t1TagType) ||
|
||||||
RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType) ||
|
DayPortion.EVENING.equals(t1TagType) ||
|
||||||
RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType)) {
|
DayPortion.NIGHT.equals(t1TagType)) {
|
||||||
t1.untag(RepeaterDayPortion.class);
|
t1.untag(RepeaterDayPortion.class);
|
||||||
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
|
t1.tag(new EnumRepeaterDayPortion(DayPortion.PM));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ package org.xbib.time.chronic.handlers;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HandlerPattern {
|
public class HandlerPattern {
|
||||||
private boolean optional;
|
|
||||||
|
private final boolean optional;
|
||||||
|
|
||||||
public HandlerPattern(boolean optional) {
|
public HandlerPattern(boolean optional) {
|
||||||
this.optional = optional;
|
this.optional = optional;
|
||||||
|
|
|
@ -4,7 +4,8 @@ package org.xbib.time.chronic.handlers;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HandlerTypePattern extends HandlerPattern {
|
public class HandlerTypePattern extends HandlerPattern {
|
||||||
private Handler.HandlerType type;
|
|
||||||
|
private final Handler.HandlerType type;
|
||||||
|
|
||||||
public HandlerTypePattern(Handler.HandlerType type) {
|
public HandlerTypePattern(Handler.HandlerType type) {
|
||||||
this(type, false);
|
this(type, false);
|
||||||
|
|
|
@ -11,5 +11,6 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IHandler {
|
public interface IHandler {
|
||||||
|
|
||||||
Span handle(List<Token> tokens, Options options);
|
Span handle(List<Token> tokens, Options options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,4 @@ public class ORGRHandler extends ORRHandler {
|
||||||
Span outerSpan = Handler.getAnchor(tokens.subList(2, 4), options);
|
Span outerSpan = Handler.getAnchor(tokens.subList(2, 4), options);
|
||||||
return handle(tokens.subList(0, 2), outerSpan, options);
|
return handle(tokens.subList(0, 2), outerSpan, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.repeaters.Repeater;
|
import org.xbib.time.chronic.repeaters.Repeater;
|
||||||
import org.xbib.time.chronic.tags.Ordinal;
|
import org.xbib.time.chronic.tags.Ordinal;
|
||||||
import org.xbib.time.chronic.tags.Pointer;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -21,7 +21,7 @@ public abstract class ORRHandler implements IHandler {
|
||||||
Integer ordinalValue = tokens.get(0).getTag(Ordinal.class).getType();
|
Integer ordinalValue = tokens.get(0).getTag(Ordinal.class).getType();
|
||||||
Span span = null;
|
Span span = null;
|
||||||
for (int i = 0; i < ordinalValue; i++) {
|
for (int i = 0; i < ordinalValue; i++) {
|
||||||
span = repeater.nextSpan(Pointer.PointerType.FUTURE);
|
span = repeater.nextSpan(PointerType.FUTURE);
|
||||||
if (span.getBegin() > outerSpan.getEnd()) {
|
if (span.getBegin() > outerSpan.getEnd()) {
|
||||||
span = null;
|
span = null;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -16,5 +16,4 @@ public class ORSRHandler extends ORRHandler {
|
||||||
Span outerSpan = Handler.getAnchor(tokens.subList(3, 4), options);
|
Span outerSpan = Handler.getAnchor(tokens.subList(3, 4), options);
|
||||||
return handle(tokens.subList(0, 2), outerSpan, options);
|
return handle(tokens.subList(0, 2), outerSpan, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,4 @@ public class RHandler implements IHandler {
|
||||||
List<Token> ddTokens = Handler.dealiasAndDisambiguateTimes(tokens, options);
|
List<Token> ddTokens = Handler.dealiasAndDisambiguateTimes(tokens, options);
|
||||||
return Handler.getAnchor(ddTokens, options);
|
return Handler.getAnchor(ddTokens, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,5 +30,4 @@ public class RmnSdSyHandler implements IHandler {
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,4 @@ public class RmnSyHandler implements IHandler {
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,4 @@ public class SRPAHandler extends SRPHandler {
|
||||||
Span anchorSpan = Handler.getAnchor(tokens.subList(3, tokens.size()), options);
|
Span anchorSpan = Handler.getAnchor(tokens.subList(3, tokens.size()), options);
|
||||||
return super.handle(tokens, anchorSpan, options);
|
return super.handle(tokens, anchorSpan, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.repeaters.Repeater;
|
import org.xbib.time.chronic.repeaters.Repeater;
|
||||||
import org.xbib.time.chronic.tags.Pointer;
|
import org.xbib.time.chronic.tags.Pointer;
|
||||||
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
import org.xbib.time.chronic.tags.Scalar;
|
import org.xbib.time.chronic.tags.Scalar;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -19,7 +20,7 @@ public class SRPHandler implements IHandler {
|
||||||
public Span handle(List<Token> tokens, Span span, Options options) {
|
public Span handle(List<Token> tokens, Span span, Options options) {
|
||||||
int distance = tokens.get(0).getTag(Scalar.class).getType();
|
int distance = tokens.get(0).getTag(Scalar.class).getType();
|
||||||
Repeater<?> repeater = tokens.get(1).getTag(Repeater.class);
|
Repeater<?> repeater = tokens.get(1).getTag(Repeater.class);
|
||||||
Pointer.PointerType pointer = tokens.get(2).getTag(Pointer.class).getType();
|
PointerType pointer = tokens.get(2).getTag(Pointer.class).getType();
|
||||||
return repeater.getOffset(span, distance, pointer);
|
return repeater.getOffset(span, distance, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,5 +21,4 @@ public class SdRmnSyHandler extends RmnSdSyHandler {
|
||||||
newTokens.addAll(tokens.subList(3, tokens.size()));
|
newTokens.addAll(tokens.subList(3, tokens.size()));
|
||||||
return super.handle(newTokens, options);
|
return super.handle(newTokens, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,4 @@ public class SmSdHandler implements IHandler {
|
||||||
ZonedDateTime end = start.plus(1, ChronoUnit.MONTHS);
|
ZonedDateTime end = start.plus(1, ChronoUnit.MONTHS);
|
||||||
return new Span(start, end);
|
return new Span(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,5 +30,4 @@ public class SmSdSyHandler implements IHandler {
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,4 @@ public class SmSyHandler implements IHandler {
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@ import org.xbib.time.chronic.tags.Tag;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class TagPattern extends HandlerPattern {
|
public class TagPattern extends HandlerPattern {
|
||||||
private Class<? extends Tag> tagClass;
|
|
||||||
|
private final Class<? extends Tag> tagClass;
|
||||||
|
|
||||||
public TagPattern(Class<? extends Tag> tagClass) {
|
public TagPattern(Class<? extends Tag> tagClass) {
|
||||||
this(tagClass, false);
|
this(tagClass, false);
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class Numerizer {
|
||||||
directNums.add(new DirectNum("nine(\\W|$)", "9$1"));
|
directNums.add(new DirectNum("nine(\\W|$)", "9$1"));
|
||||||
directNums.add(new DirectNum("ten", "10"));
|
directNums.add(new DirectNum("ten", "10"));
|
||||||
directNums.add(new DirectNum("\\ba\\b", "1"));
|
directNums.add(new DirectNum("\\ba\\b", "1"));
|
||||||
DIRECT_NUMS = directNums.toArray(new DirectNum[directNums.size()]);
|
DIRECT_NUMS = directNums.toArray(new DirectNum[0]);
|
||||||
|
|
||||||
List<TenPrefix> tenPrefixes = new LinkedList<>();
|
List<TenPrefix> tenPrefixes = new LinkedList<>();
|
||||||
tenPrefixes.add(new TenPrefix("twenty", 20));
|
tenPrefixes.add(new TenPrefix("twenty", 20));
|
||||||
|
@ -60,7 +60,7 @@ public class Numerizer {
|
||||||
tenPrefixes.add(new TenPrefix("eighty", 80));
|
tenPrefixes.add(new TenPrefix("eighty", 80));
|
||||||
tenPrefixes.add(new TenPrefix("ninety", 90));
|
tenPrefixes.add(new TenPrefix("ninety", 90));
|
||||||
tenPrefixes.add(new TenPrefix("ninty", 90));
|
tenPrefixes.add(new TenPrefix("ninty", 90));
|
||||||
TEN_PREFIXES = tenPrefixes.toArray(new TenPrefix[tenPrefixes.size()]);
|
TEN_PREFIXES = tenPrefixes.toArray(new TenPrefix[0]);
|
||||||
|
|
||||||
List<BigPrefix> bigPrefixes = new LinkedList<>();
|
List<BigPrefix> bigPrefixes = new LinkedList<>();
|
||||||
bigPrefixes.add(new BigPrefix("hundred", 100L));
|
bigPrefixes.add(new BigPrefix("hundred", 100L));
|
||||||
|
@ -68,7 +68,7 @@ public class Numerizer {
|
||||||
bigPrefixes.add(new BigPrefix("million", 1000000L));
|
bigPrefixes.add(new BigPrefix("million", 1000000L));
|
||||||
bigPrefixes.add(new BigPrefix("billion", 1000000000L));
|
bigPrefixes.add(new BigPrefix("billion", 1000000000L));
|
||||||
bigPrefixes.add(new BigPrefix("trillion", 1000000000000L));
|
bigPrefixes.add(new BigPrefix("trillion", 1000000000000L));
|
||||||
BIG_PREFIXES = bigPrefixes.toArray(new BigPrefix[bigPrefixes.size()]);
|
BIG_PREFIXES = bigPrefixes.toArray(new BigPrefix[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String numerize(String str) {
|
public static String numerize(String str) {
|
||||||
|
@ -81,7 +81,7 @@ public class Numerizer {
|
||||||
for (Prefix tp : Numerizer.TEN_PREFIXES) {
|
for (Prefix tp : Numerizer.TEN_PREFIXES) {
|
||||||
Matcher matcher = tp.getName().matcher(numerizedStr);
|
Matcher matcher = tp.getName().matcher(numerizedStr);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
StringBuffer matcherBuffer = new StringBuffer();
|
StringBuilder matcherBuffer = new StringBuilder();
|
||||||
do {
|
do {
|
||||||
if (matcher.group(1) == null) {
|
if (matcher.group(1) == null) {
|
||||||
matcher.appendReplacement(matcherBuffer, String.valueOf(tp.getNumber()));
|
matcher.appendReplacement(matcherBuffer, String.valueOf(tp.getNumber()));
|
||||||
|
@ -97,7 +97,7 @@ public class Numerizer {
|
||||||
for (Prefix bp : Numerizer.BIG_PREFIXES) {
|
for (Prefix bp : Numerizer.BIG_PREFIXES) {
|
||||||
Matcher matcher = bp.getName().matcher(numerizedStr);
|
Matcher matcher = bp.getName().matcher(numerizedStr);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
StringBuffer matcherBuffer = new StringBuffer();
|
StringBuilder matcherBuffer = new StringBuilder();
|
||||||
do {
|
do {
|
||||||
if (matcher.group(1) == null) {
|
if (matcher.group(1) == null) {
|
||||||
matcher.appendReplacement(matcherBuffer, String.valueOf(bp.getNumber()));
|
matcher.appendReplacement(matcherBuffer, String.valueOf(bp.getNumber()));
|
||||||
|
@ -113,7 +113,7 @@ public class Numerizer {
|
||||||
}
|
}
|
||||||
Matcher matcher = Numerizer.DEHAALFER.matcher(numerizedStr);
|
Matcher matcher = Numerizer.DEHAALFER.matcher(numerizedStr);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
StringBuffer matcherBuffer = new StringBuffer();
|
StringBuilder matcherBuffer = new StringBuilder();
|
||||||
do {
|
do {
|
||||||
matcher.appendReplacement(matcherBuffer,
|
matcher.appendReplacement(matcherBuffer,
|
||||||
String.valueOf(Float.parseFloat(matcher.group(1).trim()) + 0.5f));
|
String.valueOf(Float.parseFloat(matcher.group(1).trim()) + 0.5f));
|
||||||
|
@ -142,8 +142,10 @@ public class Numerizer {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static class DirectNum {
|
private static class DirectNum {
|
||||||
private Pattern name;
|
|
||||||
private String number;
|
private final Pattern name;
|
||||||
|
|
||||||
|
private final String number;
|
||||||
|
|
||||||
DirectNum(String name, String number) {
|
DirectNum(String name, String number) {
|
||||||
this.name = Pattern.compile(name, Pattern.CASE_INSENSITIVE);
|
this.name = Pattern.compile(name, Pattern.CASE_INSENSITIVE);
|
||||||
|
@ -163,8 +165,10 @@ public class Numerizer {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static class Prefix {
|
static class Prefix {
|
||||||
private Pattern name;
|
|
||||||
private long number;
|
private final Pattern name;
|
||||||
|
|
||||||
|
private final long number;
|
||||||
|
|
||||||
Prefix(Pattern name, long number) {
|
Prefix(Pattern name, long number) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum DayName {
|
||||||
|
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum DayPortion {
|
||||||
|
AM, PM, MORNING, AFTERNOON, EVENING, NIGHT
|
||||||
|
}
|
|
@ -5,12 +5,18 @@ import org.xbib.time.chronic.Range;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EnumRepeaterDayPortion extends RepeaterDayPortion<RepeaterDayPortion.DayPortion> {
|
public class EnumRepeaterDayPortion extends RepeaterDayPortion<DayPortion> {
|
||||||
|
|
||||||
private static final Range AM_RANGE = new Range(0, 12 * 60 * 60); // 12am-12pm
|
private static final Range AM_RANGE = new Range(0, 12 * 60 * 60); // 12am-12pm
|
||||||
|
|
||||||
private static final Range PM_RANGE = new Range(12 * 60 * 60, 24 * 60 * 60 - 1); // 12pm-12am
|
private static final Range PM_RANGE = new Range(12 * 60 * 60, 24 * 60 * 60 - 1); // 12pm-12am
|
||||||
|
|
||||||
private static final Range MORNING_RANGE = new Range(6 * 60 * 60, 12 * 60 * 60); // 6am-12pm
|
private static final Range MORNING_RANGE = new Range(6 * 60 * 60, 12 * 60 * 60); // 6am-12pm
|
||||||
|
|
||||||
private static final Range AFTERNOON_RANGE = new Range(13 * 60 * 60, 17 * 60 * 60); // 1pm-5pm
|
private static final Range AFTERNOON_RANGE = new Range(13 * 60 * 60, 17 * 60 * 60); // 1pm-5pm
|
||||||
|
|
||||||
private static final Range EVENING_RANGE = new Range(17 * 60 * 60, 20 * 60 * 60); // 5pm-8pm
|
private static final Range EVENING_RANGE = new Range(17 * 60 * 60, 20 * 60 * 60); // 5pm-8pm
|
||||||
|
|
||||||
private static final Range NIGHT_RANGE = new Range(20 * 60 * 60, 24 * 60 * 60); // 8pm-12pm
|
private static final Range NIGHT_RANGE = new Range(20 * 60 * 60, 24 * 60 * 60); // 8pm-12pm
|
||||||
|
|
||||||
public EnumRepeaterDayPortion(DayPortion type) {
|
public EnumRepeaterDayPortion(DayPortion type) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.xbib.time.chronic.Range;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IntegerRepeaterDayPortion extends RepeaterDayPortion<Integer> {
|
public class IntegerRepeaterDayPortion extends RepeaterDayPortion<Integer> {
|
||||||
|
|
||||||
public IntegerRepeaterDayPortion(Integer type) {
|
public IntegerRepeaterDayPortion(Integer type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum MonthName {
|
||||||
|
ZEROMONTH_DO_NOT_REMOVE,
|
||||||
|
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ package org.xbib.time.chronic.repeaters;
|
||||||
import org.xbib.time.chronic.Options;
|
import org.xbib.time.chronic.Options;
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.tags.Pointer;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
import org.xbib.time.chronic.tags.Tag;
|
import org.xbib.time.chronic.tags.Tag;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -65,25 +65,25 @@ public abstract class Repeater<T> extends Tag<T> implements Comparable<Repeater<
|
||||||
* @param pointer pointer
|
* @param pointer pointer
|
||||||
* @return span
|
* @return span
|
||||||
*/
|
*/
|
||||||
public Span nextSpan(Pointer.PointerType pointer) {
|
public Span nextSpan(PointerType pointer) {
|
||||||
if (getNow() == null) {
|
if (getNow() == null) {
|
||||||
throw new IllegalStateException("Start point must be set before calling #next");
|
throw new IllegalStateException("Start point must be set before calling #next");
|
||||||
}
|
}
|
||||||
return internalNextSpan(pointer);
|
return internalNextSpan(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Span internalNextSpan(Pointer.PointerType pointer);
|
protected abstract Span internalNextSpan(PointerType pointer);
|
||||||
|
|
||||||
public Span thisSpan(Pointer.PointerType pointer) {
|
public Span thisSpan(PointerType pointer) {
|
||||||
if (getNow() == null) {
|
if (getNow() == null) {
|
||||||
throw new IllegalStateException("Start point must be set before calling #this");
|
throw new IllegalStateException("Start point must be set before calling #this");
|
||||||
}
|
}
|
||||||
return internalThisSpan(pointer);
|
return internalThisSpan(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Span internalThisSpan(Pointer.PointerType pointer);
|
protected abstract Span internalThisSpan(PointerType pointer);
|
||||||
|
|
||||||
public abstract Span getOffset(Span span, int amount, Pointer.PointerType pointer);
|
public abstract Span getOffset(Span span, int amount, PointerType pointer);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoField;
|
import java.time.temporal.ChronoField;
|
||||||
|
@ -14,18 +14,30 @@ import java.util.regex.Pattern;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterDayName extends Repeater<RepeaterDayName.DayName> {
|
public class RepeaterDayName extends Repeater<DayName> {
|
||||||
|
|
||||||
private static final int DAY_SECONDS = 86400;
|
private static final int DAY_SECONDS = 86400;
|
||||||
|
|
||||||
private static final Pattern MON_PATTERN = Pattern.compile("^m[ou]n(day)?$");
|
private static final Pattern MON_PATTERN = Pattern.compile("^m[ou]n(day)?$");
|
||||||
|
|
||||||
private static final Pattern TUE_PATTERN = Pattern.compile("^t(ue|eu|oo|u|)s(day)?$");
|
private static final Pattern TUE_PATTERN = Pattern.compile("^t(ue|eu|oo|u|)s(day)?$");
|
||||||
|
|
||||||
private static final Pattern TUE_PATTERN_1 = Pattern.compile("^tue$");
|
private static final Pattern TUE_PATTERN_1 = Pattern.compile("^tue$");
|
||||||
|
|
||||||
private static final Pattern WED_PATTERN_1 = Pattern.compile("^we(dnes|nds|nns)day$");
|
private static final Pattern WED_PATTERN_1 = Pattern.compile("^we(dnes|nds|nns)day$");
|
||||||
|
|
||||||
private static final Pattern WED_PATTERN_2 = Pattern.compile("^wed$");
|
private static final Pattern WED_PATTERN_2 = Pattern.compile("^wed$");
|
||||||
|
|
||||||
private static final Pattern THU_PATTERN_1 = Pattern.compile("^th(urs|ers)day$");
|
private static final Pattern THU_PATTERN_1 = Pattern.compile("^th(urs|ers)day$");
|
||||||
|
|
||||||
private static final Pattern THU_PATTERN_2 = Pattern.compile("^thu$");
|
private static final Pattern THU_PATTERN_2 = Pattern.compile("^thu$");
|
||||||
|
|
||||||
private static final Pattern FRI_PATTERN = Pattern.compile("^fr[iy](day)?$");
|
private static final Pattern FRI_PATTERN = Pattern.compile("^fr[iy](day)?$");
|
||||||
|
|
||||||
private static final Pattern SAT_PATTERN = Pattern.compile("^sat(t?[ue]rday)?$");
|
private static final Pattern SAT_PATTERN = Pattern.compile("^sat(t?[ue]rday)?$");
|
||||||
|
|
||||||
private static final Pattern SUN_PATTERN = Pattern.compile("^su[nm](day)?$");
|
private static final Pattern SUN_PATTERN = Pattern.compile("^su[nm](day)?$");
|
||||||
|
|
||||||
private ZonedDateTime currentDayStart;
|
private ZonedDateTime currentDayStart;
|
||||||
|
|
||||||
public RepeaterDayName(DayName type) {
|
public RepeaterDayName(DayName type) {
|
||||||
|
@ -106,10 +118,4 @@ public class RepeaterDayName extends Repeater<RepeaterDayName.DayName> {
|
||||||
return super.toString() + "-dayname-" + getType();
|
return super.toString() + "-dayname-" + getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum DayName {
|
|
||||||
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.xbib.time.chronic.repeaters;
|
||||||
import org.xbib.time.chronic.Range;
|
import org.xbib.time.chronic.Range;
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -18,14 +18,21 @@ import java.util.regex.Pattern;
|
||||||
public abstract class RepeaterDayPortion<T> extends Repeater<T> {
|
public abstract class RepeaterDayPortion<T> extends Repeater<T> {
|
||||||
|
|
||||||
private static final Pattern AM_PATTERN = Pattern.compile("^ams?$");
|
private static final Pattern AM_PATTERN = Pattern.compile("^ams?$");
|
||||||
|
|
||||||
private static final Pattern PM_PATTERN = Pattern.compile("^pms?$");
|
private static final Pattern PM_PATTERN = Pattern.compile("^pms?$");
|
||||||
|
|
||||||
private static final Pattern MORNING_PATTERN = Pattern.compile("^mornings?$");
|
private static final Pattern MORNING_PATTERN = Pattern.compile("^mornings?$");
|
||||||
|
|
||||||
private static final Pattern AFTERNOON_PATTERN = Pattern.compile("^afternoons?$");
|
private static final Pattern AFTERNOON_PATTERN = Pattern.compile("^afternoons?$");
|
||||||
|
|
||||||
private static final Pattern EVENING_PATTERN = Pattern.compile("^evenings?$");
|
private static final Pattern EVENING_PATTERN = Pattern.compile("^evenings?$");
|
||||||
|
|
||||||
private static final Pattern NIGHT_PATTERN = Pattern.compile("^(night|nite)s?$");
|
private static final Pattern NIGHT_PATTERN = Pattern.compile("^(night|nite)s?$");
|
||||||
|
|
||||||
private static final int FULL_DAY_SECONDS = 60 * 60 * 24;
|
private static final int FULL_DAY_SECONDS = 60 * 60 * 24;
|
||||||
private Range range;
|
|
||||||
|
private final Range range;
|
||||||
|
|
||||||
private Span currentSpan;
|
private Span currentSpan;
|
||||||
|
|
||||||
public RepeaterDayPortion(T type) {
|
public RepeaterDayPortion(T type) {
|
||||||
|
@ -149,10 +156,4 @@ public abstract class RepeaterDayPortion<T> extends Repeater<T> {
|
||||||
return super.toString() + "-dayportion-" + getType();
|
return super.toString() + "-dayportion-" + getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum DayPortion {
|
|
||||||
AM, PM, MORNING, AFTERNOON, EVENING, NIGHT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterFortnight extends RepeaterUnit {
|
public class RepeaterFortnight extends RepeaterUnit {
|
||||||
|
|
||||||
public static final int FORTNIGHT_SECONDS = 1209600; // (14 * 24 * 60 * 60)
|
public static final int FORTNIGHT_SECONDS = 1209600; // (14 * 24 * 60 * 60)
|
||||||
|
|
||||||
private ZonedDateTime currentFortnightStart;
|
private ZonedDateTime currentFortnightStart;
|
||||||
|
@ -23,12 +24,12 @@ public class RepeaterFortnight extends RepeaterUnit {
|
||||||
protected Span internalNextSpan(PointerType pointer) {
|
protected Span internalNextSpan(PointerType pointer) {
|
||||||
if (currentFortnightStart == null) {
|
if (currentFortnightStart == null) {
|
||||||
if (pointer == PointerType.FUTURE) {
|
if (pointer == PointerType.FUTURE) {
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
Span nextSundaySpan = sundayRepeater.nextSpan(PointerType.FUTURE);
|
Span nextSundaySpan = sundayRepeater.nextSpan(PointerType.FUTURE);
|
||||||
currentFortnightStart = nextSundaySpan.getBeginCalendar();
|
currentFortnightStart = nextSundaySpan.getBeginCalendar();
|
||||||
} else if (pointer == PointerType.PAST) {
|
} else if (pointer == PointerType.PAST) {
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow().plus(RepeaterDay.DAY_SECONDS, ChronoUnit.SECONDS));
|
sundayRepeater.setNow(getNow().plus(RepeaterDay.DAY_SECONDS, ChronoUnit.SECONDS));
|
||||||
sundayRepeater.nextSpan(PointerType.PAST);
|
sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
sundayRepeater.nextSpan(PointerType.PAST);
|
sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
|
@ -55,7 +56,7 @@ public class RepeaterFortnight extends RepeaterUnit {
|
||||||
Span span;
|
Span span;
|
||||||
if (pointer == PointerType.FUTURE) {
|
if (pointer == PointerType.FUTURE) {
|
||||||
ZonedDateTime thisFortnightStart = ymdh(getNow()).plus(RepeaterHour.HOUR_SECONDS, ChronoUnit.SECONDS);
|
ZonedDateTime thisFortnightStart = ymdh(getNow()).plus(RepeaterHour.HOUR_SECONDS, ChronoUnit.SECONDS);
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
sundayRepeater.thisSpan(PointerType.FUTURE);
|
sundayRepeater.thisSpan(PointerType.FUTURE);
|
||||||
Span thisSundaySpan = sundayRepeater.thisSpan(PointerType.FUTURE);
|
Span thisSundaySpan = sundayRepeater.thisSpan(PointerType.FUTURE);
|
||||||
|
@ -63,7 +64,7 @@ public class RepeaterFortnight extends RepeaterUnit {
|
||||||
span = new Span(thisFortnightStart, thisFortnightEnd);
|
span = new Span(thisFortnightStart, thisFortnightEnd);
|
||||||
} else if (pointer == PointerType.PAST) {
|
} else if (pointer == PointerType.PAST) {
|
||||||
ZonedDateTime thisFortnightEnd = ymdh(getNow());
|
ZonedDateTime thisFortnightEnd = ymdh(getNow());
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
ZonedDateTime thisFortnightStart = lastSundaySpan.getBeginCalendar();
|
ZonedDateTime thisFortnightStart = lastSundaySpan.getBeginCalendar();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterHour extends RepeaterUnit {
|
public class RepeaterHour extends RepeaterUnit {
|
||||||
|
|
||||||
public static final int HOUR_SECONDS = 3600;
|
public static final int HOUR_SECONDS = 3600;
|
||||||
|
|
||||||
private ZonedDateTime currentDayStart;
|
private ZonedDateTime currentDayStart;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterMinute extends RepeaterUnit {
|
public class RepeaterMinute extends RepeaterUnit {
|
||||||
|
|
||||||
public static final int MINUTE_SECONDS = 60;
|
public static final int MINUTE_SECONDS = 60;
|
||||||
|
|
||||||
private ZonedDateTime currentMinuteStart;
|
private ZonedDateTime currentMinuteStart;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterMonth extends RepeaterUnit {
|
public class RepeaterMonth extends RepeaterUnit {
|
||||||
|
|
||||||
private static final int MONTH_SECONDS = 2592000; // 30 * 24 * 60 * 60
|
private static final int MONTH_SECONDS = 2592000; // 30 * 24 * 60 * 60
|
||||||
|
|
||||||
private ZonedDateTime currentMonthStart;
|
private ZonedDateTime currentMonthStart;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -13,21 +13,34 @@ import java.util.regex.Pattern;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterMonthName extends Repeater<RepeaterMonthName.MonthName> {
|
public class RepeaterMonthName extends Repeater<MonthName> {
|
||||||
|
|
||||||
private static final Pattern JAN_PATTERN = Pattern.compile("^jan\\.?(uary)?$");
|
private static final Pattern JAN_PATTERN = Pattern.compile("^jan\\.?(uary)?$");
|
||||||
|
|
||||||
private static final Pattern FEB_PATTERN = Pattern.compile("^feb\\.?(ruary)?$");
|
private static final Pattern FEB_PATTERN = Pattern.compile("^feb\\.?(ruary)?$");
|
||||||
|
|
||||||
private static final Pattern MAR_PATTERN = Pattern.compile("^mar\\.?(ch)?$");
|
private static final Pattern MAR_PATTERN = Pattern.compile("^mar\\.?(ch)?$");
|
||||||
|
|
||||||
private static final Pattern APR_PATTERN = Pattern.compile("^apr\\.?(il)?$");
|
private static final Pattern APR_PATTERN = Pattern.compile("^apr\\.?(il)?$");
|
||||||
|
|
||||||
private static final Pattern MAY_PATTERN = Pattern.compile("^may$");
|
private static final Pattern MAY_PATTERN = Pattern.compile("^may$");
|
||||||
|
|
||||||
private static final Pattern JUN_PATTERN = Pattern.compile("^jun\\.?e?$");
|
private static final Pattern JUN_PATTERN = Pattern.compile("^jun\\.?e?$");
|
||||||
|
|
||||||
private static final Pattern JUL_PATTERN = Pattern.compile("^jul\\.?y?$");
|
private static final Pattern JUL_PATTERN = Pattern.compile("^jul\\.?y?$");
|
||||||
|
|
||||||
private static final Pattern AUG_PATTERN = Pattern.compile("^aug\\.?(ust)?$");
|
private static final Pattern AUG_PATTERN = Pattern.compile("^aug\\.?(ust)?$");
|
||||||
|
|
||||||
private static final Pattern SEP_PATTERN = Pattern.compile("^sep\\.?(t\\.?|tember)?$");
|
private static final Pattern SEP_PATTERN = Pattern.compile("^sep\\.?(t\\.?|tember)?$");
|
||||||
|
|
||||||
private static final Pattern OCT_PATTERN = Pattern.compile("^oct\\.?(ober)?$");
|
private static final Pattern OCT_PATTERN = Pattern.compile("^oct\\.?(ober)?$");
|
||||||
|
|
||||||
private static final Pattern NOV_PATTERN = Pattern.compile("^nov\\.?(ember)?$");
|
private static final Pattern NOV_PATTERN = Pattern.compile("^nov\\.?(ember)?$");
|
||||||
|
|
||||||
private static final Pattern DEC_PATTERN = Pattern.compile("^dec\\.?(ember)?$");
|
private static final Pattern DEC_PATTERN = Pattern.compile("^dec\\.?(ember)?$");
|
||||||
|
|
||||||
private static final int MONTH_SECONDS = 2592000; // 30 * 24 * 60 * 60
|
private static final int MONTH_SECONDS = 2592000; // 30 * 24 * 60 * 60
|
||||||
|
|
||||||
private ZonedDateTime currentMonthBegin;
|
private ZonedDateTime currentMonthBegin;
|
||||||
|
|
||||||
public RepeaterMonthName(MonthName type) {
|
public RepeaterMonthName(MonthName type) {
|
||||||
|
@ -146,12 +159,4 @@ public class RepeaterMonthName extends Repeater<RepeaterMonthName.MonthName> {
|
||||||
return super.toString() + "-monthname-" + getType();
|
return super.toString() + "-monthname-" + getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum MonthName {
|
|
||||||
ZEROMONTH_DO_NOT_REMOVE,
|
|
||||||
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterSecond extends RepeaterUnit {
|
public class RepeaterSecond extends RepeaterUnit {
|
||||||
|
|
||||||
private static final int SECOND_SECONDS = 1;
|
private static final int SECOND_SECONDS = 1;
|
||||||
|
|
||||||
private ZonedDateTime secondStart;
|
private ZonedDateTime secondStart;
|
||||||
|
@ -22,7 +23,6 @@ public class RepeaterSecond extends RepeaterUnit {
|
||||||
} else {
|
} else {
|
||||||
secondStart = secondStart.plus(direction, ChronoUnit.SECONDS);
|
secondStart = secondStart.plus(direction, ChronoUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Span(secondStart, ChronoUnit.SECONDS, 1);
|
return new Span(secondStart, ChronoUnit.SECONDS, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.xbib.time.chronic.Options;
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.Tick;
|
import org.xbib.time.chronic.Tick;
|
||||||
import org.xbib.time.chronic.Token;
|
import org.xbib.time.chronic.Token;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -16,13 +16,17 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterTime extends Repeater<Tick> {
|
public class RepeaterTime extends Repeater<Tick> {
|
||||||
|
|
||||||
private static final Pattern TIME_PATTERN = Pattern.compile("^\\d{1,2}(:?\\d{2})?([\\.:]?\\d{2})?$");
|
private static final Pattern TIME_PATTERN = Pattern.compile("^\\d{1,2}(:?\\d{2})?([\\.:]?\\d{2})?$");
|
||||||
|
|
||||||
private ZonedDateTime currentTime;
|
private ZonedDateTime currentTime;
|
||||||
|
|
||||||
public RepeaterTime(String time) {
|
public RepeaterTime(String time) {
|
||||||
super(null);
|
super(null);
|
||||||
String t = time.replaceAll(":", "");
|
String t = time.replaceAll(":", "");
|
||||||
Tick type;
|
Tick type;
|
||||||
|
boolean ambiguous = time.contains(":") && Integer.parseInt(t.substring(0, 1)) != 0 &&
|
||||||
|
Integer.parseInt(t.substring(0, 2)) <= 12;
|
||||||
int length = t.length();
|
int length = t.length();
|
||||||
if (length <= 2) {
|
if (length <= 2) {
|
||||||
int hours = Integer.parseInt(t);
|
int hours = Integer.parseInt(t);
|
||||||
|
@ -37,8 +41,6 @@ public class RepeaterTime extends Repeater<Tick> {
|
||||||
int minutesInSeconds = Integer.parseInt(t.substring(1)) * 60;
|
int minutesInSeconds = Integer.parseInt(t.substring(1)) * 60;
|
||||||
type = new Tick(hoursInSeconds + minutesInSeconds, true);
|
type = new Tick(hoursInSeconds + minutesInSeconds, true);
|
||||||
} else if (length == 4) {
|
} else if (length == 4) {
|
||||||
boolean ambiguous = time.contains(":") && Integer.parseInt(t.substring(0, 1)) != 0 &&
|
|
||||||
Integer.parseInt(t.substring(0, 2)) <= 12;
|
|
||||||
int hours = Integer.parseInt(t.substring(0, 2));
|
int hours = Integer.parseInt(t.substring(0, 2));
|
||||||
int hoursInSeconds = hours * 60 * 60;
|
int hoursInSeconds = hours * 60 * 60;
|
||||||
int minutesInSeconds = Integer.parseInt(t.substring(2)) * 60;
|
int minutesInSeconds = Integer.parseInt(t.substring(2)) * 60;
|
||||||
|
@ -53,8 +55,6 @@ public class RepeaterTime extends Repeater<Tick> {
|
||||||
int seconds = Integer.parseInt(t.substring(3));
|
int seconds = Integer.parseInt(t.substring(3));
|
||||||
type = new Tick(hoursInSeconds + minutesInSeconds + seconds, true);
|
type = new Tick(hoursInSeconds + minutesInSeconds + seconds, true);
|
||||||
} else if (length == 6) {
|
} else if (length == 6) {
|
||||||
boolean ambiguous = time.contains(":") && Integer.parseInt(t.substring(0, 1)) != 0 &&
|
|
||||||
Integer.parseInt(t.substring(0, 2)) <= 12;
|
|
||||||
int hours = Integer.parseInt(t.substring(0, 2));
|
int hours = Integer.parseInt(t.substring(0, 2));
|
||||||
int hoursInSeconds = hours * 60 * 60;
|
int hoursInSeconds = hours * 60 * 60;
|
||||||
int minutesInSeconds = Integer.parseInt(t.substring(2, 4)) * 60;
|
int minutesInSeconds = Integer.parseInt(t.substring(2, 4)) * 60;
|
||||||
|
@ -84,30 +84,31 @@ public class RepeaterTime extends Repeater<Tick> {
|
||||||
private static Integer integerValue(String str) {
|
private static Integer integerValue(String str) {
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
String s = str.toLowerCase();
|
String s = str.toLowerCase();
|
||||||
if ("one".equals(s)) {
|
switch (s) {
|
||||||
return 1;
|
case "one":
|
||||||
} else if ("two".equals(s)) {
|
return 1;
|
||||||
return 2;
|
case "two":
|
||||||
} else if ("three".equals(s)) {
|
return 2;
|
||||||
return 3;
|
case "three":
|
||||||
} else if ("four".equals(s)) {
|
return 3;
|
||||||
return 4;
|
case "four":
|
||||||
} else if ("five".equals(s)) {
|
return 4;
|
||||||
return 5;
|
case "five":
|
||||||
} else if ("six".equals(s)) {
|
return 5;
|
||||||
return 6;
|
case "six":
|
||||||
} else if ("seven".equals(s)) {
|
return 6;
|
||||||
return 7;
|
case "seven":
|
||||||
} else if ("eight".equals(s)) {
|
return 7;
|
||||||
return 8;
|
case "eight":
|
||||||
} else if ("nine".equals(s)) {
|
return 8;
|
||||||
return 9;
|
case "nine":
|
||||||
} else if ("ten".equals(s)) {
|
return 9;
|
||||||
return 10;
|
case "ten":
|
||||||
} else if ("eleven".equals(s)) {
|
return 10;
|
||||||
return 11;
|
case "eleven":
|
||||||
} else if ("twelve".equals(s)) {
|
return 11;
|
||||||
return 12;
|
case "twelve":
|
||||||
|
return 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -158,8 +159,8 @@ public class RepeaterTime extends Repeater<Tick> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
List<ZonedDateTime> pastDates = new LinkedList<>();
|
||||||
if (tick.isAmbiguous()) {
|
if (tick.isAmbiguous()) {
|
||||||
List<ZonedDateTime> pastDates = new LinkedList<>();
|
|
||||||
pastDates.add(midnight.plus(halfDay + (long) tick.intValue(), ChronoUnit.SECONDS));
|
pastDates.add(midnight.plus(halfDay + (long) tick.intValue(), ChronoUnit.SECONDS));
|
||||||
pastDates.add(midnight.plus(tick.intValue(), ChronoUnit.SECONDS));
|
pastDates.add(midnight.plus(tick.intValue(), ChronoUnit.SECONDS));
|
||||||
pastDates.add(yesterdayMidnight.plus(tick.intValue() * 2L, ChronoUnit.SECONDS));
|
pastDates.add(yesterdayMidnight.plus(tick.intValue() * 2L, ChronoUnit.SECONDS));
|
||||||
|
@ -171,7 +172,6 @@ public class RepeaterTime extends Repeater<Tick> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<ZonedDateTime> pastDates = new LinkedList<>();
|
|
||||||
pastDates.add(midnight.plus(tick.intValue(), ChronoUnit.SECONDS));
|
pastDates.add(midnight.plus(tick.intValue(), ChronoUnit.SECONDS));
|
||||||
pastDates.add(yesterdayMidnight.plus(tick.intValue(), ChronoUnit.SECONDS));
|
pastDates.add(yesterdayMidnight.plus(tick.intValue(), ChronoUnit.SECONDS));
|
||||||
for (ZonedDateTime pastDate : pastDates) {
|
for (ZonedDateTime pastDate : pastDates) {
|
||||||
|
@ -183,18 +183,15 @@ public class RepeaterTime extends Repeater<Tick> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done && currentTime == null) {
|
if (!done && currentTime == null) {
|
||||||
throw new IllegalStateException("Current time cannot be null at this point.");
|
throw new IllegalStateException("Current time cannot be null at this point.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!first) {
|
if (!first) {
|
||||||
int increment = tick.isAmbiguous() ? halfDay : fullDay;
|
int increment = tick.isAmbiguous() ? halfDay : fullDay;
|
||||||
long direction = pointer == PointerType.FUTURE ? 1L : -1L;
|
long direction = pointer == PointerType.FUTURE ? 1L : -1L;
|
||||||
currentTime = currentTime.plus(direction * increment, ChronoUnit.SECONDS);
|
currentTime = currentTime.plus(direction * increment, ChronoUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Span(currentTime, currentTime.plus(getWidth(), ChronoUnit.SECONDS));
|
return new Span(currentTime, currentTime.plus(getWidth(), ChronoUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,23 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class RepeaterUnit extends Repeater<Object> {
|
public abstract class RepeaterUnit extends Repeater<Object> {
|
||||||
|
|
||||||
private static final Pattern YEAR_PATTERN = Pattern.compile("^years?$");
|
private static final Pattern YEAR_PATTERN = Pattern.compile("^years?$");
|
||||||
|
|
||||||
private static final Pattern MONTH_PATTERN = Pattern.compile("^months?$");
|
private static final Pattern MONTH_PATTERN = Pattern.compile("^months?$");
|
||||||
|
|
||||||
private static final Pattern FORTNIGHT_PATTERN = Pattern.compile("^fortnights?$");
|
private static final Pattern FORTNIGHT_PATTERN = Pattern.compile("^fortnights?$");
|
||||||
|
|
||||||
private static final Pattern WEEK_PATTERN = Pattern.compile("^weeks?$");
|
private static final Pattern WEEK_PATTERN = Pattern.compile("^weeks?$");
|
||||||
|
|
||||||
private static final Pattern WEEKEND_PATTERN = Pattern.compile("^weekends?$");
|
private static final Pattern WEEKEND_PATTERN = Pattern.compile("^weekends?$");
|
||||||
|
|
||||||
private static final Pattern DAY_PATTERN = Pattern.compile("^days?$");
|
private static final Pattern DAY_PATTERN = Pattern.compile("^days?$");
|
||||||
|
|
||||||
private static final Pattern HOUR_PATTERN = Pattern.compile("^hours?$");
|
private static final Pattern HOUR_PATTERN = Pattern.compile("^hours?$");
|
||||||
|
|
||||||
private static final Pattern MINUTE_PATTERN = Pattern.compile("^minutes?$");
|
private static final Pattern MINUTE_PATTERN = Pattern.compile("^minutes?$");
|
||||||
|
|
||||||
private static final Pattern SECOND_PATTERN = Pattern.compile("^seconds?$");
|
private static final Pattern SECOND_PATTERN = Pattern.compile("^seconds?$");
|
||||||
|
|
||||||
public RepeaterUnit() {
|
public RepeaterUnit() {
|
||||||
|
@ -66,10 +75,4 @@ public abstract class RepeaterUnit extends Repeater<Object> {
|
||||||
((Repeater) other).getNow().equals(getNow());
|
((Repeater) other).getNow().equals(getNow());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private enum UnitName {
|
|
||||||
YEAR, MONTH, FORTNIGHT, WEEK, WEEKEND, DAY, HOUR, MINUTE, SECOND
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,7 +10,9 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterWeek extends RepeaterUnit {
|
public class RepeaterWeek extends RepeaterUnit {
|
||||||
|
|
||||||
public static final int WEEK_SECONDS = 604800;
|
public static final int WEEK_SECONDS = 604800;
|
||||||
|
|
||||||
public static final int WEEK_DAYS = 7;
|
public static final int WEEK_DAYS = 7;
|
||||||
|
|
||||||
private ZonedDateTime currentWeekStart;
|
private ZonedDateTime currentWeekStart;
|
||||||
|
@ -24,12 +26,12 @@ public class RepeaterWeek extends RepeaterUnit {
|
||||||
protected Span internalNextSpan(PointerType pointer) {
|
protected Span internalNextSpan(PointerType pointer) {
|
||||||
if (currentWeekStart == null) {
|
if (currentWeekStart == null) {
|
||||||
if (pointer == PointerType.FUTURE) {
|
if (pointer == PointerType.FUTURE) {
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
Span nextSundaySpan = sundayRepeater.nextSpan(PointerType.FUTURE);
|
Span nextSundaySpan = sundayRepeater.nextSpan(PointerType.FUTURE);
|
||||||
currentWeekStart = nextSundaySpan.getBeginCalendar();
|
currentWeekStart = nextSundaySpan.getBeginCalendar();
|
||||||
} else if (pointer == PointerType.PAST) {
|
} else if (pointer == PointerType.PAST) {
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow().plus(1, ChronoUnit.DAYS));
|
sundayRepeater.setNow(getNow().plus(1, ChronoUnit.DAYS));
|
||||||
sundayRepeater.nextSpan(PointerType.PAST);
|
sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
|
@ -52,20 +54,20 @@ public class RepeaterWeek extends RepeaterUnit {
|
||||||
ZonedDateTime thisWeekEnd;
|
ZonedDateTime thisWeekEnd;
|
||||||
if (pointer == PointerType.FUTURE) {
|
if (pointer == PointerType.FUTURE) {
|
||||||
thisWeekStart = ymdh(getNow()).plus(1, ChronoUnit.HOURS);
|
thisWeekStart = ymdh(getNow()).plus(1, ChronoUnit.HOURS);
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
Span thisSundaySpan = sundayRepeater.thisSpan(PointerType.FUTURE);
|
Span thisSundaySpan = sundayRepeater.thisSpan(PointerType.FUTURE);
|
||||||
thisWeekEnd = thisSundaySpan.getBeginCalendar();
|
thisWeekEnd = thisSundaySpan.getBeginCalendar();
|
||||||
thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
|
thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
|
||||||
} else if (pointer == PointerType.PAST) {
|
} else if (pointer == PointerType.PAST) {
|
||||||
thisWeekEnd = ymdh(getNow());
|
thisWeekEnd = ymdh(getNow());
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
thisWeekStart = lastSundaySpan.getBeginCalendar();
|
thisWeekStart = lastSundaySpan.getBeginCalendar();
|
||||||
thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
|
thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
|
||||||
} else if (pointer == PointerType.NONE) {
|
} else if (pointer == PointerType.NONE) {
|
||||||
RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
|
RepeaterDayName sundayRepeater = new RepeaterDayName(DayName.SUNDAY);
|
||||||
sundayRepeater.setNow(getNow());
|
sundayRepeater.setNow(getNow());
|
||||||
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
Span lastSundaySpan = sundayRepeater.nextSpan(PointerType.PAST);
|
||||||
thisWeekStart = lastSundaySpan.getBeginCalendar();
|
thisWeekStart = lastSundaySpan.getBeginCalendar();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,7 +10,8 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterWeekend extends RepeaterUnit {
|
public class RepeaterWeekend extends RepeaterUnit {
|
||||||
public static final long WEEKEND_SECONDS = 172800L; // (2 * 24 * 60 * 60);
|
|
||||||
|
private static final long WEEKEND_SECONDS = 172800L; // (2 * 24 * 60 * 60);
|
||||||
|
|
||||||
private ZonedDateTime currentWeekStart;
|
private ZonedDateTime currentWeekStart;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ public class RepeaterWeekend extends RepeaterUnit {
|
||||||
ZonedDateTime c;
|
ZonedDateTime c;
|
||||||
switch (pointer) {
|
switch (pointer) {
|
||||||
case PAST: {
|
case PAST: {
|
||||||
RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
|
RepeaterDayName saturdayRepeater = new RepeaterDayName(DayName.SATURDAY);
|
||||||
saturdayRepeater.setNow(getNow().plus(RepeaterDay.DAY_SECONDS, ChronoUnit.SECONDS));
|
saturdayRepeater.setNow(getNow().plus(RepeaterDay.DAY_SECONDS, ChronoUnit.SECONDS));
|
||||||
Span lastSaturdaySpan = saturdayRepeater.nextSpan(PointerType.PAST);
|
Span lastSaturdaySpan = saturdayRepeater.nextSpan(PointerType.PAST);
|
||||||
currentWeekStart = lastSaturdaySpan.getBeginCalendar();
|
currentWeekStart = lastSaturdaySpan.getBeginCalendar();
|
||||||
|
@ -33,7 +34,7 @@ public class RepeaterWeekend extends RepeaterUnit {
|
||||||
return new Span(currentWeekStart, c);
|
return new Span(currentWeekStart, c);
|
||||||
}
|
}
|
||||||
case FUTURE: {
|
case FUTURE: {
|
||||||
RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
|
RepeaterDayName saturdayRepeater = new RepeaterDayName(DayName.SATURDAY);
|
||||||
saturdayRepeater.setNow(getNow());
|
saturdayRepeater.setNow(getNow());
|
||||||
Span nextSaturdaySpan = saturdayRepeater.nextSpan(PointerType.FUTURE);
|
Span nextSaturdaySpan = saturdayRepeater.nextSpan(PointerType.FUTURE);
|
||||||
currentWeekStart = nextSaturdaySpan.getBeginCalendar();
|
currentWeekStart = nextSaturdaySpan.getBeginCalendar();
|
||||||
|
@ -50,13 +51,13 @@ public class RepeaterWeekend extends RepeaterUnit {
|
||||||
protected Span internalThisSpan(PointerType pointer) {
|
protected Span internalThisSpan(PointerType pointer) {
|
||||||
Span thisSpan;
|
Span thisSpan;
|
||||||
if (pointer == PointerType.FUTURE || pointer == PointerType.NONE) {
|
if (pointer == PointerType.FUTURE || pointer == PointerType.NONE) {
|
||||||
RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
|
RepeaterDayName saturdayRepeater = new RepeaterDayName(DayName.SATURDAY);
|
||||||
saturdayRepeater.setNow(getNow());
|
saturdayRepeater.setNow(getNow());
|
||||||
Span thisSaturdaySpan = saturdayRepeater.nextSpan(PointerType.FUTURE);
|
Span thisSaturdaySpan = saturdayRepeater.nextSpan(PointerType.FUTURE);
|
||||||
thisSpan = new Span(thisSaturdaySpan.getBeginCalendar(), thisSaturdaySpan.getBeginCalendar()
|
thisSpan = new Span(thisSaturdaySpan.getBeginCalendar(), thisSaturdaySpan.getBeginCalendar()
|
||||||
.plus(RepeaterWeekend.WEEKEND_SECONDS, ChronoUnit.SECONDS));
|
.plus(RepeaterWeekend.WEEKEND_SECONDS, ChronoUnit.SECONDS));
|
||||||
} else if (pointer == PointerType.PAST) {
|
} else if (pointer == PointerType.PAST) {
|
||||||
RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
|
RepeaterDayName saturdayRepeater = new RepeaterDayName(DayName.SATURDAY);
|
||||||
saturdayRepeater.setNow(getNow());
|
saturdayRepeater.setNow(getNow());
|
||||||
Span lastSaturdaySpan = saturdayRepeater.nextSpan(PointerType.PAST);
|
Span lastSaturdaySpan = saturdayRepeater.nextSpan(PointerType.PAST);
|
||||||
thisSpan = new Span(lastSaturdaySpan.getBeginCalendar(), lastSaturdaySpan.getBeginCalendar()
|
thisSpan = new Span(lastSaturdaySpan.getBeginCalendar(), lastSaturdaySpan.getBeginCalendar()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.time.chronic.repeaters;
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
import org.xbib.time.chronic.Span;
|
import org.xbib.time.chronic.Span;
|
||||||
import org.xbib.time.chronic.tags.Pointer.PointerType;
|
import org.xbib.time.chronic.tags.PointerType;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RepeaterYear extends RepeaterUnit {
|
public class RepeaterYear extends RepeaterUnit {
|
||||||
|
|
||||||
private ZonedDateTime currentYearStart;
|
private ZonedDateTime currentYearStart;
|
||||||
|
|
||||||
private static ZonedDateTime ymd(ZonedDateTime zonedDateTime) {
|
private static ZonedDateTime ymd(ZonedDateTime zonedDateTime) {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.xbib.time.chronic.repeaters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
enum UnitName {
|
||||||
|
YEAR, MONTH, FORTNIGHT, WEEK, WEEKEND, DAY, HOUR, MINUTE, SECOND
|
||||||
|
}
|
|
@ -11,9 +11,12 @@ import java.util.regex.Pattern;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Grabber extends Tag<Grabber.Relative> {
|
public class Grabber extends Tag<Relative> {
|
||||||
|
|
||||||
private static final Pattern THIS_PATTERN = Pattern.compile("this");
|
private static final Pattern THIS_PATTERN = Pattern.compile("this");
|
||||||
|
|
||||||
private static final Pattern NEXT_PATTERN = Pattern.compile("next");
|
private static final Pattern NEXT_PATTERN = Pattern.compile("next");
|
||||||
|
|
||||||
private static final Pattern LAST_PATTERN = Pattern.compile("last");
|
private static final Pattern LAST_PATTERN = Pattern.compile("last");
|
||||||
|
|
||||||
public Grabber(Relative type) {
|
public Grabber(Relative type) {
|
||||||
|
@ -49,10 +52,4 @@ public class Grabber extends Tag<Grabber.Relative> {
|
||||||
return "grabber-" + getType();
|
return "grabber-" + getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum Relative {
|
|
||||||
LAST, NEXT, THIS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class Ordinal extends Tag<Integer> {
|
||||||
|
|
||||||
static final Pattern ORDINAL_PATTERN = Pattern.compile("^(\\d*)(st|nd|rd|th)$");
|
static final Pattern ORDINAL_PATTERN = Pattern.compile("^(\\d*)(st|nd|rd|th)$");
|
||||||
|
|
||||||
Ordinal(Integer type) {
|
protected Ordinal(Integer type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ import java.util.regex.Matcher;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OrdinalDay extends Ordinal {
|
public class OrdinalDay extends Ordinal {
|
||||||
public OrdinalDay(Integer type) {
|
|
||||||
|
private OrdinalDay(Integer type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.regex.Pattern;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Pointer extends Tag<Pointer.PointerType> {
|
public class Pointer extends Tag<PointerType> {
|
||||||
|
|
||||||
private static final Pattern IN_PATTERN = Pattern.compile("\\bin\\b");
|
private static final Pattern IN_PATTERN = Pattern.compile("\\bin\\b");
|
||||||
|
|
||||||
|
@ -52,10 +52,4 @@ public class Pointer extends Tag<Pointer.PointerType> {
|
||||||
return "pointer-" + getType();
|
return "pointer-" + getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum PointerType {
|
|
||||||
PAST, FUTURE, NONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.xbib.time.chronic.tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum PointerType {
|
||||||
|
PAST, FUTURE, NONE
|
||||||
|
}
|
8
src/main/java/org/xbib/time/chronic/tags/Relative.java
Normal file
8
src/main/java/org/xbib/time/chronic/tags/Relative.java
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package org.xbib.time.chronic.tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum Relative {
|
||||||
|
LAST, NEXT, THIS
|
||||||
|
}
|
|
@ -13,8 +13,9 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Scalar extends Tag<Integer> {
|
public class Scalar extends Tag<Integer> {
|
||||||
static final Set<String> TIMES =
|
|
||||||
new HashSet<>(Arrays.asList("am", "pm", "morning", "afternoon", "evening", "night"));
|
protected static final Set<String> TIMES = new HashSet<>(Arrays.asList("am", "pm", "morning", "afternoon", "evening", "night"));
|
||||||
|
|
||||||
private static final Pattern SCALAR_PATTERN = Pattern.compile("^\\d*$");
|
private static final Pattern SCALAR_PATTERN = Pattern.compile("^\\d*$");
|
||||||
|
|
||||||
public Scalar(Integer type) {
|
public Scalar(Integer type) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ScalarDay extends Scalar {
|
public class ScalarDay extends Scalar {
|
||||||
|
|
||||||
private static final Pattern DAY_PATTERN = Pattern.compile("^\\d\\d?$");
|
private static final Pattern DAY_PATTERN = Pattern.compile("^\\d\\d?$");
|
||||||
|
|
||||||
public ScalarDay(Integer type) {
|
public ScalarDay(Integer type) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ScalarMonth extends Scalar {
|
public class ScalarMonth extends Scalar {
|
||||||
|
|
||||||
private static final Pattern MONTH_PATTERN = Pattern.compile("^\\d\\d?$");
|
private static final Pattern MONTH_PATTERN = Pattern.compile("^\\d\\d?$");
|
||||||
|
|
||||||
public ScalarMonth(Integer type) {
|
public ScalarMonth(Integer type) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ScalarYear extends Scalar {
|
public class ScalarYear extends Scalar {
|
||||||
|
|
||||||
private static final Pattern YEAR_PATTERN = Pattern.compile("^([1-9]\\d)?\\d\\d?$");
|
private static final Pattern YEAR_PATTERN = Pattern.compile("^([1-9]\\d)?\\d\\d?$");
|
||||||
|
|
||||||
private ScalarYear(Integer type) {
|
private ScalarYear(Integer type) {
|
||||||
|
|
|
@ -8,9 +8,9 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Separator extends Tag<Separator.SeparatorType> {
|
public class Separator extends Tag<SeparatorType> {
|
||||||
|
|
||||||
Separator(SeparatorType type) {
|
public Separator(SeparatorType type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,4 @@ public class Separator extends Tag<Separator.SeparatorType> {
|
||||||
return "separator";
|
return "separator";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
enum SeparatorType {
|
|
||||||
COMMA, DASH, SLASH, AT, IN
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SeparatorAt extends Separator {
|
public class SeparatorAt extends Separator {
|
||||||
|
|
||||||
private static final Pattern AT_PATTERN = Pattern.compile("^(at|@)$");
|
private static final Pattern AT_PATTERN = Pattern.compile("^(at|@)$");
|
||||||
|
|
||||||
private SeparatorAt(SeparatorType type) {
|
private SeparatorAt(SeparatorType type) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SeparatorComma extends Separator {
|
public class SeparatorComma extends Separator {
|
||||||
|
|
||||||
private static final Pattern COMMA_PATTERN = Pattern.compile("^,$");
|
private static final Pattern COMMA_PATTERN = Pattern.compile("^,$");
|
||||||
|
|
||||||
private SeparatorComma(SeparatorType type) {
|
private SeparatorComma(SeparatorType type) {
|
||||||
|
|
|
@ -11,7 +11,9 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SeparatorSlashOrDash extends Separator {
|
public class SeparatorSlashOrDash extends Separator {
|
||||||
|
|
||||||
private static final Pattern SLASH_PATTERN = Pattern.compile("^/$");
|
private static final Pattern SLASH_PATTERN = Pattern.compile("^/$");
|
||||||
|
|
||||||
private static final Pattern DASH_PATTERN = Pattern.compile("^-$");
|
private static final Pattern DASH_PATTERN = Pattern.compile("^-$");
|
||||||
|
|
||||||
public SeparatorSlashOrDash(SeparatorType type) {
|
public SeparatorSlashOrDash(SeparatorType type) {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.xbib.time.chronic.tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum SeparatorType {
|
||||||
|
COMMA, DASH, SLASH, AT, IN
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ package org.xbib.time.chronic.tags;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StringTag extends Tag<String> {
|
public class StringTag extends Tag<String> {
|
||||||
|
|
||||||
public StringTag(String type) {
|
public StringTag(String type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TimeZone extends Tag<Object> {
|
public class TimeZone extends Tag<Object> {
|
||||||
|
|
||||||
private static final Pattern TIMEZONE_PATTERN = Pattern.compile("[pmce][ds]t");
|
private static final Pattern TIMEZONE_PATTERN = Pattern.compile("[pmce][ds]t");
|
||||||
|
|
||||||
private TimeZone() {
|
private TimeZone() {
|
||||||
|
|
|
@ -11,27 +11,25 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* Composite implementation that merges other fields to create a full pattern.
|
* Composite implementation that merges other fields to create a full pattern.
|
||||||
*/
|
*/
|
||||||
class Composite implements PeriodPrinter, PeriodParser {
|
public class Composite implements PeriodPrinter, PeriodParser {
|
||||||
|
|
||||||
private final PeriodPrinter[] iPrinters;
|
private final PeriodPrinter[] iPrinters;
|
||||||
|
|
||||||
private final PeriodParser[] iParsers;
|
private final PeriodParser[] iParsers;
|
||||||
|
|
||||||
Composite(List<Object> elementPairs) {
|
public Composite(List<Object> elementPairs) {
|
||||||
List<Object> printerList = new ArrayList<>();
|
List<PeriodPrinter> printerList = new ArrayList<>();
|
||||||
List<Object> parserList = new ArrayList<>();
|
List<PeriodParser> parserList = new ArrayList<>();
|
||||||
|
|
||||||
decompose(elementPairs, printerList, parserList);
|
decompose(elementPairs, printerList, parserList);
|
||||||
|
|
||||||
if (printerList.isEmpty()) {
|
if (printerList.isEmpty()) {
|
||||||
iPrinters = null;
|
iPrinters = null;
|
||||||
} else {
|
} else {
|
||||||
iPrinters = printerList.toArray(new PeriodPrinter[printerList.size()]);
|
iPrinters = printerList.toArray(new PeriodPrinter[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parserList.isEmpty()) {
|
if (parserList.isEmpty()) {
|
||||||
iParsers = null;
|
iParsers = null;
|
||||||
} else {
|
} else {
|
||||||
iParsers = parserList.toArray(new PeriodParser[parserList.size()]);
|
iParsers = parserList.toArray(new PeriodParser[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,32 +81,31 @@ class Composite implements PeriodPrinter, PeriodParser {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decompose(List<Object> elementPairs, List<Object> printerList, List<Object> parserList) {
|
private void decompose(List<Object> elementPairs, List<PeriodPrinter> printerList, List<PeriodParser> parserList) {
|
||||||
int size = elementPairs.size();
|
int size = elementPairs.size();
|
||||||
for (int i = 0; i < size; i += 2) {
|
for (int i = 0; i < size; i += 2) {
|
||||||
Object element = elementPairs.get(i);
|
Object element = elementPairs.get(i);
|
||||||
if (element instanceof PeriodPrinter) {
|
if (element instanceof PeriodPrinter) {
|
||||||
if (element instanceof Composite) {
|
if (element instanceof Composite) {
|
||||||
addArrayToList(printerList, ((Composite) element).iPrinters);
|
PeriodPrinter[] periodPrinters = ((Composite) element).iPrinters;
|
||||||
|
if (periodPrinters != null) {
|
||||||
|
Collections.addAll(printerList, periodPrinters);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
printerList.add(element);
|
printerList.add((PeriodPrinter) element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element = elementPairs.get(i + 1);
|
element = elementPairs.get(i + 1);
|
||||||
if (element instanceof PeriodParser) {
|
if (element instanceof PeriodParser) {
|
||||||
if (element instanceof Composite) {
|
if (element instanceof Composite) {
|
||||||
addArrayToList(parserList, ((Composite) element).iParsers);
|
PeriodParser[] periodParsers = ((Composite) element).iParsers;
|
||||||
|
if (periodParsers != null) {
|
||||||
|
Collections.addAll(parserList, periodParsers);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
parserList.add(element);
|
parserList.add((PeriodParser) element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addArrayToList(List<Object> list, Object[] array) {
|
|
||||||
if (array != null) {
|
|
||||||
Collections.addAll(list, array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -8,30 +8,31 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* Builds a composite affix by merging two other affix implementations.
|
* Builds a composite affix by merging two other affix implementations.
|
||||||
*/
|
*/
|
||||||
class CompositeAffix extends IgnorableAffix {
|
public class CompositeAffix extends IgnorableAffix {
|
||||||
|
|
||||||
private final PeriodFieldAffix iLeft;
|
private final PeriodFieldAffix iLeft;
|
||||||
|
|
||||||
private final PeriodFieldAffix iRight;
|
private final PeriodFieldAffix iRight;
|
||||||
|
|
||||||
private final String[] iLeftRightCombinations;
|
private final String[] iLeftRightCombinations;
|
||||||
|
|
||||||
CompositeAffix(PeriodFieldAffix left, PeriodFieldAffix right) {
|
public CompositeAffix(PeriodFieldAffix left, PeriodFieldAffix right) {
|
||||||
iLeft = left;
|
iLeft = left;
|
||||||
iRight = right;
|
iRight = right;
|
||||||
|
|
||||||
// We need to construct all possible combinations of left and right.
|
// We need to construct all possible combinations of left and right.
|
||||||
// We are doing it once in constructor so that getAffixes() is quicker.
|
// We are doing it once in constructor so that getAffixes() is quicker.
|
||||||
Set<String> result = new HashSet<String>();
|
Set<String> result = new HashSet<>();
|
||||||
for (String leftText : iLeft.getAffixes()) {
|
for (String leftText : iLeft.getAffixes()) {
|
||||||
for (String rightText : iRight.getAffixes()) {
|
for (String rightText : iRight.getAffixes()) {
|
||||||
result.add(leftText + rightText);
|
result.add(leftText + rightText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iLeftRightCombinations = result.toArray(new String[result.size()]);
|
iLeftRightCombinations = result.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int calculatePrintedLength(int value) {
|
public int calculatePrintedLength(int value) {
|
||||||
return iLeft.calculatePrintedLength(value)
|
return iLeft.calculatePrintedLength(value) + iRight.calculatePrintedLength(value);
|
||||||
+ iRight.calculatePrintedLength(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,10 +11,12 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* Formats the numeric value of a field, potentially with prefix/suffix.
|
* Formats the numeric value of a field, potentially with prefix/suffix.
|
||||||
*/
|
*/
|
||||||
class FieldFormatter implements PeriodPrinter, PeriodParser {
|
public class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
|
|
||||||
private final int iMinPrintedDigits;
|
private final int iMinPrintedDigits;
|
||||||
//private final int iPrintZeroSetting;
|
|
||||||
private final int iMaxParsedDigits;
|
private final int iMaxParsedDigits;
|
||||||
|
|
||||||
private final boolean iRejectSignedValues;
|
private final boolean iRejectSignedValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,10 +32,10 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
private final PeriodFieldAffix iPrefix;
|
private final PeriodFieldAffix iPrefix;
|
||||||
private final PeriodFieldAffix iSuffix;
|
private final PeriodFieldAffix iSuffix;
|
||||||
|
|
||||||
FieldFormatter(int minPrintedDigits,
|
public FieldFormatter(int minPrintedDigits,
|
||||||
int maxParsedDigits, boolean rejectSignedValues,
|
int maxParsedDigits, boolean rejectSignedValues,
|
||||||
ChronoUnit chronoUnit,
|
ChronoUnit chronoUnit,
|
||||||
PeriodFieldAffix prefix, PeriodFieldAffix suffix) {
|
PeriodFieldAffix prefix, PeriodFieldAffix suffix) {
|
||||||
iMinPrintedDigits = minPrintedDigits;
|
iMinPrintedDigits = minPrintedDigits;
|
||||||
iMaxParsedDigits = maxParsedDigits;
|
iMaxParsedDigits = maxParsedDigits;
|
||||||
iRejectSignedValues = rejectSignedValues;
|
iRejectSignedValues = rejectSignedValues;
|
||||||
|
@ -42,7 +44,7 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
iSuffix = suffix;
|
iSuffix = suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldFormatter(FieldFormatter field, PeriodFieldAffix periodFieldAffix) {
|
public FieldFormatter(FieldFormatter field, PeriodFieldAffix periodFieldAffix) {
|
||||||
PeriodFieldAffix suffix = periodFieldAffix;
|
PeriodFieldAffix suffix = periodFieldAffix;
|
||||||
iMinPrintedDigits = field.iMinPrintedDigits;
|
iMinPrintedDigits = field.iMinPrintedDigits;
|
||||||
iMaxParsedDigits = field.iMaxParsedDigits;
|
iMaxParsedDigits = field.iMaxParsedDigits;
|
||||||
|
@ -91,17 +93,14 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
if (valueLong == Long.MAX_VALUE) {
|
if (valueLong == Long.MAX_VALUE) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sum = Math.max(FormatUtils.calculateDigitCount(valueLong), iMinPrintedDigits);
|
int sum = Math.max(FormatUtils.calculateDigitCount(valueLong), iMinPrintedDigits);
|
||||||
int value = (int) valueLong;
|
int value = (int) valueLong;
|
||||||
|
|
||||||
if (iPrefix != null) {
|
if (iPrefix != null) {
|
||||||
sum += iPrefix.calculatePrintedLength(value);
|
sum += iPrefix.calculatePrintedLength(value);
|
||||||
}
|
}
|
||||||
if (iSuffix != null) {
|
if (iSuffix != null) {
|
||||||
sum += iSuffix.calculatePrintedLength(value);
|
sum += iSuffix.calculatePrintedLength(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +151,6 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
if (position >= text.length()) {
|
if (position >= text.length()) {
|
||||||
return ~position;
|
return ~position;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iPrefix != null) {
|
if (iPrefix != null) {
|
||||||
position = iPrefix.parse(text, position);
|
position = iPrefix.parse(text, position);
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
|
@ -187,7 +185,6 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
}
|
}
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasDigits) {
|
if (!hasDigits) {
|
||||||
return ~position;
|
return ~position;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +233,7 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
/**
|
/**
|
||||||
* @return Long.MAX_VALUE if nothing to print, otherwise value
|
* @return Long.MAX_VALUE if nothing to print, otherwise value
|
||||||
*/
|
*/
|
||||||
long getFieldValue(Period period) {
|
private long getFieldValue(Period period) {
|
||||||
long value;
|
long value;
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
default:
|
default:
|
||||||
|
@ -270,7 +267,7 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFieldValue(PeriodAmount period, ChronoUnit field, long value) {
|
private void setFieldValue(PeriodAmount period, ChronoUnit field, long value) {
|
||||||
switch (field) {
|
switch (field) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -300,8 +297,4 @@ class FieldFormatter implements PeriodPrinter, PeriodParser {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ChronoUnit getFieldType() {
|
|
||||||
return unit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ public class FormatUtils {
|
||||||
appenadble.append('0');
|
appenadble.append('0');
|
||||||
}
|
}
|
||||||
appenadble.append(Long.toString(Integer.MIN_VALUE));
|
appenadble.append(Long.toString(Integer.MIN_VALUE));
|
||||||
//.append("" + -(long) Integer.MIN_VALUE)
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* An affix that can be ignored.
|
* An affix that can be ignored.
|
||||||
*/
|
*/
|
||||||
abstract class IgnorableAffix implements PeriodFieldAffix {
|
public abstract class IgnorableAffix implements PeriodFieldAffix {
|
||||||
|
|
||||||
private volatile String[] iOtherAffixes;
|
private volatile String[] iOtherAffixes;
|
||||||
|
|
||||||
public void finish(Set<PeriodFieldAffix> periodFieldAffixesToIgnore) {
|
public void finish(Set<PeriodFieldAffix> periodFieldAffixesToIgnore) {
|
||||||
|
@ -20,7 +21,6 @@ abstract class IgnorableAffix implements PeriodFieldAffix {
|
||||||
shortestAffix = affix;
|
shortestAffix = affix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pick only affixes that are longer than the shortest affix in this instance.
|
// Pick only affixes that are longer than the shortest affix in this instance.
|
||||||
// This will reduce the number of parse operations and thus speed up the PeriodFormatter.
|
// This will reduce the number of parse operations and thus speed up the PeriodFormatter.
|
||||||
// also need to pick affixes that differ only in case (but not those that are identical)
|
// also need to pick affixes that differ only in case (but not those that are identical)
|
||||||
|
|
|
@ -8,11 +8,13 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* Handles a simple literal piece of text.
|
* Handles a simple literal piece of text.
|
||||||
*/
|
*/
|
||||||
class Literal implements PeriodPrinter, PeriodParser {
|
public class Literal implements PeriodPrinter, PeriodParser {
|
||||||
static final Literal EMPTY = new Literal("");
|
|
||||||
|
public static final Literal EMPTY = new Literal("");
|
||||||
|
|
||||||
private final String iText;
|
private final String iText;
|
||||||
|
|
||||||
Literal(String text) {
|
public Literal(String text) {
|
||||||
iText = text;
|
iText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class PeriodAmount implements TemporalAmount {
|
public class PeriodAmount implements TemporalAmount {
|
||||||
|
|
||||||
private Map<TemporalUnit, Long> amounts = new HashMap<>();
|
private final Map<TemporalUnit, Long> amounts = new HashMap<>();
|
||||||
|
|
||||||
public void set(TemporalUnit unit, Long value) {
|
public void set(TemporalUnit unit, Long value) {
|
||||||
amounts.put(unit, value);
|
amounts.put(unit, value);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Set;
|
||||||
* Defines a formatted field's prefix or suffix text.
|
* Defines a formatted field's prefix or suffix text.
|
||||||
* This can be used for fields such as 'n hours' or 'nH' or 'Hour:n'.
|
* This can be used for fields such as 'n hours' or 'nH' or 'Hour:n'.
|
||||||
*/
|
*/
|
||||||
interface PeriodFieldAffix {
|
public interface PeriodFieldAffix {
|
||||||
|
|
||||||
int calculatePrintedLength(int value);
|
int calculatePrintedLength(int value);
|
||||||
|
|
||||||
|
@ -17,11 +17,15 @@ interface PeriodFieldAffix {
|
||||||
void printTo(Writer out, int value) throws IOException;
|
void printTo(Writer out, int value) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param periodStr period string
|
||||||
|
* @param position position
|
||||||
* @return new position after parsing affix, or ~position of failure
|
* @return new position after parsing affix, or ~position of failure
|
||||||
*/
|
*/
|
||||||
int parse(String periodStr, int position);
|
int parse(String periodStr, int position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param periodStr period string
|
||||||
|
* @param position position
|
||||||
* @return position where affix starts, or original ~position if not found
|
* @return position where affix starts, or original ~position if not found
|
||||||
*/
|
*/
|
||||||
int scan(String periodStr, int position);
|
int scan(String periodStr, int position);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class PeriodFormatter {
|
||||||
* @param parser the internal parser, null if cannot parse
|
* @param parser the internal parser, null if cannot parse
|
||||||
* @param locale the locale to use
|
* @param locale the locale to use
|
||||||
*/
|
*/
|
||||||
PeriodFormatter(PeriodPrinter printer, PeriodParser parser, Locale locale) {
|
public PeriodFormatter(PeriodPrinter printer, PeriodParser parser, Locale locale) {
|
||||||
super();
|
super();
|
||||||
iPrinter = printer;
|
iPrinter = printer;
|
||||||
iParser = parser;
|
iParser = parser;
|
||||||
|
|
|
@ -33,12 +33,13 @@ import java.util.List;
|
||||||
public class PeriodFormatterBuilder {
|
public class PeriodFormatterBuilder {
|
||||||
|
|
||||||
private int iMinPrintedDigits;
|
private int iMinPrintedDigits;
|
||||||
|
|
||||||
private int iMaxParsedDigits;
|
private int iMaxParsedDigits;
|
||||||
|
|
||||||
private boolean iRejectSignedValues;
|
private boolean iRejectSignedValues;
|
||||||
|
|
||||||
private PeriodFieldAffix iPrefix;
|
private PeriodFieldAffix iPrefix;
|
||||||
|
|
||||||
// List of Printers and Parsers used to build a final formatter.
|
|
||||||
private List<Object> iElementPairs;
|
private List<Object> iElementPairs;
|
||||||
/**
|
/**
|
||||||
* Set to true if the formatter is not a printer.
|
* Set to true if the formatter is not a printer.
|
||||||
|
@ -49,9 +50,6 @@ public class PeriodFormatterBuilder {
|
||||||
*/
|
*/
|
||||||
private boolean iNotParser;
|
private boolean iNotParser;
|
||||||
|
|
||||||
// Last PeriodFormatter appended of each field type.
|
|
||||||
//private FieldFormatter[] iFieldFormatters;
|
|
||||||
|
|
||||||
public PeriodFormatterBuilder() {
|
public PeriodFormatterBuilder() {
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
@ -80,15 +78,11 @@ public class PeriodFormatterBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object[] createComposite(List<Object> elementPairs) {
|
private static Object[] createComposite(List<Object> elementPairs) {
|
||||||
switch (elementPairs.size()) {
|
if (elementPairs.size() == 0) {
|
||||||
case 0:
|
return new Object[]{Literal.EMPTY, Literal.EMPTY};
|
||||||
return new Object[]{Literal.EMPTY, Literal.EMPTY};
|
|
||||||
case 1:
|
|
||||||
return new Object[]{elementPairs.get(0), elementPairs.get(1)};
|
|
||||||
default:
|
|
||||||
Composite comp = new Composite(elementPairs);
|
|
||||||
return new Object[]{comp, comp};
|
|
||||||
}
|
}
|
||||||
|
Composite comp = new Composite(elementPairs);
|
||||||
|
return new Object[]{comp, comp};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,8 +102,7 @@ public class PeriodFormatterBuilder {
|
||||||
* @throws IllegalStateException if the builder can produce neither a printer nor a parser
|
* @throws IllegalStateException if the builder can produce neither a printer nor a parser
|
||||||
*/
|
*/
|
||||||
public PeriodFormatter toFormatter() {
|
public PeriodFormatter toFormatter() {
|
||||||
PeriodFormatter formatter = toFormatter(iElementPairs, iNotPrinter, iNotParser);
|
return toFormatter(iElementPairs, iNotPrinter, iNotParser);
|
||||||
return formatter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,7 +148,6 @@ public class PeriodFormatterBuilder {
|
||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
iMinPrintedDigits = 1;
|
iMinPrintedDigits = 1;
|
||||||
//iPrintZeroSetting = PRINT_ZERO_RARELY_LAST;
|
|
||||||
iMaxParsedDigits = 10;
|
iMaxParsedDigits = 10;
|
||||||
iRejectSignedValues = false;
|
iRejectSignedValues = false;
|
||||||
iPrefix = null;
|
iPrefix = null;
|
||||||
|
@ -451,16 +443,6 @@ public class PeriodFormatterBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendField(ChronoUnit unit) {
|
|
||||||
appendField(unit, iMinPrintedDigits);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendField(ChronoUnit unit, int minPrinted) {
|
|
||||||
FieldFormatter field = new FieldFormatter(minPrinted,
|
|
||||||
iMaxParsedDigits, iRejectSignedValues, unit, iPrefix, null);
|
|
||||||
append0(field, field);
|
|
||||||
iPrefix = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a field suffix which applies only to the last appended field. If
|
* Append a field suffix which applies only to the last appended field. If
|
||||||
|
@ -538,39 +520,6 @@ public class PeriodFormatterBuilder {
|
||||||
return appendSuffix(new RegExAffix(regularExpressions, suffixes));
|
return appendSuffix(new RegExAffix(regularExpressions, suffixes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a field suffix which applies only to the last appended field. If
|
|
||||||
* the field is not printed, neither is the suffix.
|
|
||||||
*
|
|
||||||
* @param suffix custom suffix
|
|
||||||
* @return this PeriodFormatterBuilder
|
|
||||||
* @throws IllegalStateException if no field exists to append to
|
|
||||||
* @see #appendPrefix
|
|
||||||
*/
|
|
||||||
private PeriodFormatterBuilder appendSuffix(PeriodFieldAffix suffix) {
|
|
||||||
final Object originalPrinter;
|
|
||||||
final Object originalParser;
|
|
||||||
if (!iElementPairs.isEmpty()) {
|
|
||||||
originalPrinter = iElementPairs.get(iElementPairs.size() - 2);
|
|
||||||
originalParser = iElementPairs.get(iElementPairs.size() - 1);
|
|
||||||
} else {
|
|
||||||
originalPrinter = null;
|
|
||||||
originalParser = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalPrinter == null || originalParser == null ||
|
|
||||||
originalPrinter != originalParser ||
|
|
||||||
!(originalPrinter instanceof FieldFormatter)) {
|
|
||||||
throw new IllegalStateException("No field to apply suffix to");
|
|
||||||
}
|
|
||||||
|
|
||||||
clearPrefix();
|
|
||||||
FieldFormatter newField = new FieldFormatter((FieldFormatter) originalPrinter, suffix);
|
|
||||||
iElementPairs.set(iElementPairs.size() - 2, newField);
|
|
||||||
iElementPairs.set(iElementPairs.size() - 1, newField);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a separator, which is output if fields are printed both before
|
* Append a separator, which is output if fields are printed both before
|
||||||
* and after the separator.
|
* and after the separator.
|
||||||
|
@ -670,10 +619,7 @@ public class PeriodFormatterBuilder {
|
||||||
if (text == null || finalText == null) {
|
if (text == null || finalText == null) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
clearPrefix();
|
clearPrefix();
|
||||||
|
|
||||||
// optimise zero formatter case
|
|
||||||
List<Object> pairs = iElementPairs;
|
List<Object> pairs = iElementPairs;
|
||||||
if (pairs.isEmpty()) {
|
if (pairs.isEmpty()) {
|
||||||
if (useAfter && !useBefore) {
|
if (useAfter && !useBefore) {
|
||||||
|
@ -683,8 +629,6 @@ public class PeriodFormatterBuilder {
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the last separator added
|
|
||||||
int i;
|
int i;
|
||||||
Separator lastSeparator = null;
|
Separator lastSeparator = null;
|
||||||
for (i = pairs.size(); --i >= 0; ) {
|
for (i = pairs.size(); --i >= 0; ) {
|
||||||
|
@ -693,10 +637,8 @@ public class PeriodFormatterBuilder {
|
||||||
pairs = pairs.subList(i + 1, pairs.size());
|
pairs = pairs.subList(i + 1, pairs.size());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i--; // element pairs
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge formatters
|
|
||||||
if (lastSeparator != null && pairs.isEmpty()) {
|
if (lastSeparator != null && pairs.isEmpty()) {
|
||||||
throw new IllegalStateException("Cannot have two adjacent separators");
|
throw new IllegalStateException("Cannot have two adjacent separators");
|
||||||
} else {
|
} else {
|
||||||
|
@ -709,7 +651,6 @@ public class PeriodFormatterBuilder {
|
||||||
pairs.add(separator);
|
pairs.add(separator);
|
||||||
pairs.add(separator);
|
pairs.add(separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,7 +658,6 @@ public class PeriodFormatterBuilder {
|
||||||
if (iPrefix != null) {
|
if (iPrefix != null) {
|
||||||
throw new IllegalStateException("Prefix not followed by field");
|
throw new IllegalStateException("Prefix not followed by field");
|
||||||
}
|
}
|
||||||
iPrefix = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PeriodFormatterBuilder append0(PeriodPrinter printer, PeriodParser parser) {
|
private PeriodFormatterBuilder append0(PeriodPrinter printer, PeriodParser parser) {
|
||||||
|
@ -727,4 +667,44 @@ public class PeriodFormatterBuilder {
|
||||||
iNotParser |= (parser == null);
|
iNotParser |= (parser == null);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void appendField(ChronoUnit unit) {
|
||||||
|
appendField(unit, iMinPrintedDigits);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendField(ChronoUnit unit, int minPrinted) {
|
||||||
|
FieldFormatter field = new FieldFormatter(minPrinted,
|
||||||
|
iMaxParsedDigits, iRejectSignedValues, unit, iPrefix, null);
|
||||||
|
append0(field, field);
|
||||||
|
iPrefix = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a field suffix which applies only to the last appended field. If
|
||||||
|
* the field is not printed, neither is the suffix.
|
||||||
|
*
|
||||||
|
* @param suffix custom suffix
|
||||||
|
* @return this PeriodFormatterBuilder
|
||||||
|
* @throws IllegalStateException if no field exists to append to
|
||||||
|
* @see #appendPrefix
|
||||||
|
*/
|
||||||
|
private PeriodFormatterBuilder appendSuffix(PeriodFieldAffix suffix) {
|
||||||
|
final Object originalPrinter;
|
||||||
|
final Object originalParser;
|
||||||
|
if (!iElementPairs.isEmpty()) {
|
||||||
|
originalPrinter = iElementPairs.get(iElementPairs.size() - 2);
|
||||||
|
originalParser = iElementPairs.get(iElementPairs.size() - 1);
|
||||||
|
} else {
|
||||||
|
originalPrinter = null;
|
||||||
|
originalParser = null;
|
||||||
|
}
|
||||||
|
if (originalPrinter != originalParser || !(originalPrinter instanceof FieldFormatter)) {
|
||||||
|
throw new IllegalStateException("No field to apply suffix to");
|
||||||
|
}
|
||||||
|
clearPrefix();
|
||||||
|
FieldFormatter newField = new FieldFormatter((FieldFormatter) originalPrinter, suffix);
|
||||||
|
iElementPairs.set(iElementPairs.size() - 2, newField);
|
||||||
|
iElementPairs.set(iElementPairs.size() - 1, newField);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,13 @@ import java.io.Writer;
|
||||||
* Implements an affix where the text varies by the amount of the field.
|
* Implements an affix where the text varies by the amount of the field.
|
||||||
* Only singular (1) and plural (not 1) are supported.
|
* Only singular (1) and plural (not 1) are supported.
|
||||||
*/
|
*/
|
||||||
class PluralAffix extends IgnorableAffix {
|
public class PluralAffix extends IgnorableAffix {
|
||||||
|
|
||||||
private final String iSingularText;
|
private final String iSingularText;
|
||||||
|
|
||||||
private final String iPluralText;
|
private final String iPluralText;
|
||||||
|
|
||||||
PluralAffix(String singularText, String pluralText) {
|
public PluralAffix(String singularText, String pluralText) {
|
||||||
iSingularText = singularText;
|
iSingularText = singularText;
|
||||||
iPluralText = pluralText;
|
iPluralText = pluralText;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.regex.Pattern;
|
||||||
* Implements an affix where the text varies by the amount of the field.
|
* Implements an affix where the text varies by the amount of the field.
|
||||||
* Different amounts are supported based on the provided parameters.
|
* Different amounts are supported based on the provided parameters.
|
||||||
*/
|
*/
|
||||||
class RegExAffix extends IgnorableAffix {
|
public class RegExAffix extends IgnorableAffix {
|
||||||
|
|
||||||
private static final ConcurrentMap<String, Pattern> PATTERNS = new ConcurrentHashMap<>();
|
private static final ConcurrentMap<String, Pattern> PATTERNS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class RegExAffix extends IgnorableAffix {
|
||||||
// Otherwise it might consume not enough characters.
|
// Otherwise it might consume not enough characters.
|
||||||
private final String[] iSuffixesSortedDescByLength;
|
private final String[] iSuffixesSortedDescByLength;
|
||||||
|
|
||||||
RegExAffix(String[] regExes, String[] texts) {
|
public RegExAffix(String[] regExes, String[] texts) {
|
||||||
iSuffixes = texts.clone();
|
iSuffixes = texts.clone();
|
||||||
iPatterns = new Pattern[regExes.length];
|
iPatterns = new Pattern[regExes.length];
|
||||||
for (int i = 0; i < regExes.length; i++) {
|
for (int i = 0; i < regExes.length; i++) {
|
||||||
|
|
|
@ -12,32 +12,37 @@ import java.util.TreeSet;
|
||||||
* Handles a separator, that splits the fields into multiple parts.
|
* Handles a separator, that splits the fields into multiple parts.
|
||||||
* For example, the 'T' in the ISO8601 standard.
|
* For example, the 'T' in the ISO8601 standard.
|
||||||
*/
|
*/
|
||||||
class Separator implements PeriodPrinter, PeriodParser {
|
public class Separator implements PeriodPrinter, PeriodParser {
|
||||||
|
|
||||||
private final String iText;
|
private final String iText;
|
||||||
|
|
||||||
private final String iFinalText;
|
private final String iFinalText;
|
||||||
|
|
||||||
private final String[] iParsedForms;
|
private final String[] iParsedForms;
|
||||||
|
|
||||||
private final boolean iUseBefore;
|
private final boolean iUseBefore;
|
||||||
|
|
||||||
private final boolean iUseAfter;
|
private final boolean iUseAfter;
|
||||||
|
|
||||||
private final PeriodPrinter iBeforePrinter;
|
private final PeriodPrinter iBeforePrinter;
|
||||||
private final PeriodParser iBeforeParser;
|
|
||||||
volatile PeriodPrinter iAfterPrinter;
|
|
||||||
volatile PeriodParser iAfterParser;
|
|
||||||
|
|
||||||
Separator(String text, String finalText, String[] variants,
|
private final PeriodParser iBeforeParser;
|
||||||
PeriodPrinter beforePrinter, PeriodParser beforeParser,
|
|
||||||
boolean useBefore, boolean useAfter) {
|
protected volatile PeriodPrinter iAfterPrinter;
|
||||||
|
|
||||||
|
protected volatile PeriodParser iAfterParser;
|
||||||
|
|
||||||
|
public Separator(String text, String finalText, String[] variants,
|
||||||
|
PeriodPrinter beforePrinter, PeriodParser beforeParser,
|
||||||
|
boolean useBefore, boolean useAfter) {
|
||||||
iText = text;
|
iText = text;
|
||||||
iFinalText = finalText;
|
iFinalText = finalText;
|
||||||
|
|
||||||
if ((finalText == null || text.equals(finalText)) &&
|
if ((finalText == null || text.equals(finalText)) &&
|
||||||
(variants == null || variants.length == 0)) {
|
(variants == null || variants.length == 0)) {
|
||||||
|
|
||||||
iParsedForms = new String[]{text};
|
iParsedForms = new String[]{text};
|
||||||
} else {
|
} else {
|
||||||
// Filter and reverse sort the parsed forms.
|
TreeSet<String> parsedSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
TreeSet<String> parsedSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
parsedSet.add(text);
|
parsedSet.add(text);
|
||||||
parsedSet.add(finalText);
|
parsedSet.add(finalText);
|
||||||
if (variants != null) {
|
if (variants != null) {
|
||||||
|
@ -47,9 +52,8 @@ class Separator implements PeriodPrinter, PeriodParser {
|
||||||
}
|
}
|
||||||
ArrayList<String> parsedList = new ArrayList<String>(parsedSet);
|
ArrayList<String> parsedList = new ArrayList<String>(parsedSet);
|
||||||
Collections.reverse(parsedList);
|
Collections.reverse(parsedList);
|
||||||
iParsedForms = parsedList.toArray(new String[parsedList.size()]);
|
iParsedForms = parsedList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
iBeforePrinter = beforePrinter;
|
iBeforePrinter = beforePrinter;
|
||||||
iBeforeParser = beforeParser;
|
iBeforeParser = beforeParser;
|
||||||
iUseBefore = useBefore;
|
iUseBefore = useBefore;
|
||||||
|
@ -67,10 +71,8 @@ class Separator implements PeriodPrinter, PeriodParser {
|
||||||
public int calculatePrintedLength(Period period, Locale locale) {
|
public int calculatePrintedLength(Period period, Locale locale) {
|
||||||
PeriodPrinter before = iBeforePrinter;
|
PeriodPrinter before = iBeforePrinter;
|
||||||
PeriodPrinter after = iAfterPrinter;
|
PeriodPrinter after = iAfterPrinter;
|
||||||
|
|
||||||
int sum = before.calculatePrintedLength(period, locale)
|
int sum = before.calculatePrintedLength(period, locale)
|
||||||
+ after.calculatePrintedLength(period, locale);
|
+ after.calculatePrintedLength(period, locale);
|
||||||
|
|
||||||
if (iUseBefore) {
|
if (iUseBefore) {
|
||||||
if (before.countFieldsToPrint(period, 1, locale) > 0) {
|
if (before.countFieldsToPrint(period, 1, locale) > 0) {
|
||||||
if (iUseAfter) {
|
if (iUseAfter) {
|
||||||
|
@ -85,7 +87,6 @@ class Separator implements PeriodPrinter, PeriodParser {
|
||||||
} else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
|
} else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
|
||||||
sum += iText.length();
|
sum += iText.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,6 @@ class Separator implements PeriodPrinter, PeriodParser {
|
||||||
public void printTo(Writer out, Period period, Locale locale) throws IOException {
|
public void printTo(Writer out, Period period, Locale locale) throws IOException {
|
||||||
PeriodPrinter before = iBeforePrinter;
|
PeriodPrinter before = iBeforePrinter;
|
||||||
PeriodPrinter after = iAfterPrinter;
|
PeriodPrinter after = iAfterPrinter;
|
||||||
|
|
||||||
before.printTo(out, period, locale);
|
before.printTo(out, period, locale);
|
||||||
if (iUseBefore) {
|
if (iUseBefore) {
|
||||||
if (before.countFieldsToPrint(period, 1, locale) > 0) {
|
if (before.countFieldsToPrint(period, 1, locale) > 0) {
|
||||||
|
@ -132,8 +132,7 @@ class Separator implements PeriodPrinter, PeriodParser {
|
||||||
after.printTo(out, period, locale);
|
after.printTo(out, period, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int parseInto(PeriodAmount period, String periodStr,
|
public int parseInto(PeriodAmount period, String periodStr, int pos, Locale locale) {
|
||||||
int pos, Locale locale) {
|
|
||||||
int position = pos;
|
int position = pos;
|
||||||
int oldPos = position;
|
int oldPos = position;
|
||||||
position = iBeforeParser.parseInto(period, periodStr, position, locale);
|
position = iBeforeParser.parseInto(period, periodStr, position, locale);
|
||||||
|
@ -162,16 +161,14 @@ class Separator implements PeriodPrinter, PeriodParser {
|
||||||
// Separator should not have been supplied.
|
// Separator should not have been supplied.
|
||||||
return ~oldPos;
|
return ~oldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position > oldPos && !found && !iUseBefore) {
|
if (position > oldPos && !found && !iUseBefore) {
|
||||||
// Separator was required.
|
// Separator was required.
|
||||||
return ~oldPos;
|
return ~oldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
Separator finish(PeriodPrinter afterPrinter, PeriodParser afterParser) {
|
protected Separator finish(PeriodPrinter afterPrinter, PeriodParser afterParser) {
|
||||||
iAfterPrinter = afterPrinter;
|
iAfterPrinter = afterPrinter;
|
||||||
iAfterParser = afterParser;
|
iAfterParser = afterParser;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -6,25 +6,30 @@ import java.io.Writer;
|
||||||
/**
|
/**
|
||||||
* Implements an affix where the text does not vary by the amount.
|
* Implements an affix where the text does not vary by the amount.
|
||||||
*/
|
*/
|
||||||
class SimpleAffix extends IgnorableAffix {
|
public class SimpleAffix extends IgnorableAffix {
|
||||||
|
|
||||||
private final String iText;
|
private final String iText;
|
||||||
|
|
||||||
SimpleAffix(String text) {
|
public SimpleAffix(String text) {
|
||||||
iText = text;
|
iText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int calculatePrintedLength(int value) {
|
public int calculatePrintedLength(int value) {
|
||||||
return iText.length();
|
return iText.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void printTo(StringBuilder buf, int value) {
|
public void printTo(StringBuilder buf, int value) {
|
||||||
buf.append(iText);
|
buf.append(iText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void printTo(Writer out, int value) throws IOException {
|
public void printTo(Writer out, int value) throws IOException {
|
||||||
out.write(iText);
|
out.write(iText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int parse(String periodStr, int position) {
|
public int parse(String periodStr, int position) {
|
||||||
String text = iText;
|
String text = iText;
|
||||||
int textLength = text.length();
|
int textLength = text.length();
|
||||||
|
@ -35,6 +40,7 @@ class SimpleAffix extends IgnorableAffix {
|
||||||
return ~position;
|
return ~position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int scan(String periodStr, final int position) {
|
public int scan(String periodStr, final int position) {
|
||||||
String text = iText;
|
String text = iText;
|
||||||
int textLength = text.length();
|
int textLength = text.length();
|
||||||
|
@ -69,6 +75,7 @@ class SimpleAffix extends IgnorableAffix {
|
||||||
return ~position;
|
return ~position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getAffixes() {
|
public String[] getAffixes() {
|
||||||
return new String[]{iText};
|
return new String[]{iText};
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class PrettyTime {
|
||||||
|
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
private Map<TimeUnit, TimeFormat> units = new LinkedHashMap<>();
|
private final Map<TimeUnit, TimeFormat> units = new LinkedHashMap<>();
|
||||||
|
|
||||||
public PrettyTime() {
|
public PrettyTime() {
|
||||||
this(LocalDateTime.now());
|
this(LocalDateTime.now());
|
||||||
|
@ -118,8 +118,7 @@ public class PrettyTime {
|
||||||
|
|
||||||
public TimeUnitQuantity calculateDuration(final long difference) {
|
public TimeUnitQuantity calculateDuration(final long difference) {
|
||||||
long absoluteDifference = Math.abs(difference);
|
long absoluteDifference = Math.abs(difference);
|
||||||
List<TimeUnit> units = new ArrayList<>();
|
List<TimeUnit> units = new ArrayList<>(getUnits());
|
||||||
units.addAll(getUnits());
|
|
||||||
TimeUnitQuantity result = new TimeUnitQuantity();
|
TimeUnitQuantity result = new TimeUnitQuantity();
|
||||||
for (int i = 0; i < units.size(); i++) {
|
for (int i = 0; i < units.size(); i++) {
|
||||||
TimeUnit unit = units.get(i);
|
TimeUnit unit = units.get(i);
|
||||||
|
@ -394,7 +393,6 @@ public class PrettyTime {
|
||||||
if (unit == null) {
|
if (unit == null) {
|
||||||
throw new IllegalArgumentException("Unit to remove must not be null.");
|
throw new IllegalArgumentException("Unit to remove must not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return units.remove(unit);
|
return units.remove(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,37 @@ package org.xbib.time.pretty;
|
||||||
* Represents a simple method of formatting a specific {@link TimeUnitQuantity} of time.
|
* Represents a simple method of formatting a specific {@link TimeUnitQuantity} of time.
|
||||||
*/
|
*/
|
||||||
public class SimpleTimeFormat implements TimeFormat {
|
public class SimpleTimeFormat implements TimeFormat {
|
||||||
|
|
||||||
private static final String SIGN = "%s";
|
private static final String SIGN = "%s";
|
||||||
|
|
||||||
private static final String QUANTITY = "%n";
|
private static final String QUANTITY = "%n";
|
||||||
|
|
||||||
private static final String UNIT = "%u";
|
private static final String UNIT = "%u";
|
||||||
|
|
||||||
private static final String NEGATIVE = "-";
|
private static final String NEGATIVE = "-";
|
||||||
|
|
||||||
private String singularName = "";
|
private String singularName = "";
|
||||||
|
|
||||||
private String pluralName = "";
|
private String pluralName = "";
|
||||||
|
|
||||||
private String futureSingularName = "";
|
private String futureSingularName = "";
|
||||||
|
|
||||||
private String futurePluralName = "";
|
private String futurePluralName = "";
|
||||||
|
|
||||||
private String pastSingularName = "";
|
private String pastSingularName = "";
|
||||||
|
|
||||||
private String pastPluralName = "";
|
private String pastPluralName = "";
|
||||||
|
|
||||||
private String pattern = "";
|
private String pattern = "";
|
||||||
|
|
||||||
private String futurePrefix = "";
|
private String futurePrefix = "";
|
||||||
|
|
||||||
private String futureSuffix = "";
|
private String futureSuffix = "";
|
||||||
|
|
||||||
private String pastPrefix = "";
|
private String pastPrefix = "";
|
||||||
|
|
||||||
private String pastSuffix = "";
|
private String pastSuffix = "";
|
||||||
|
|
||||||
private int roundingTolerance = 50;
|
private int roundingTolerance = 50;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.xbib.time.pretty;
|
package org.xbib.time.pretty;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public interface TimeFormat {
|
public interface TimeFormat {
|
||||||
/**
|
/**
|
||||||
* Given a populated {@link TimeUnitQuantity} object. Apply formatting (with rounding) and output the result.
|
* Given a populated {@link TimeUnitQuantity} object. Apply formatting (with rounding) and output the result.
|
||||||
|
|
|
@ -18,6 +18,7 @@ public abstract class MapResourceBundle extends ResourceBundle {
|
||||||
public MapResourceBundle() {
|
public MapResourceBundle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final Object handleGetObject(String key) {
|
public final Object handleGetObject(String key) {
|
||||||
if (lookup == null) {
|
if (lookup == null) {
|
||||||
loadLookup();
|
loadLookup();
|
||||||
|
@ -25,6 +26,7 @@ public abstract class MapResourceBundle extends ResourceBundle {
|
||||||
return lookup.get(key);
|
return lookup.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Enumeration<String> getKeys() {
|
public Enumeration<String> getKeys() {
|
||||||
if (lookup == null) {
|
if (lookup == null) {
|
||||||
loadLookup();
|
loadLookup();
|
||||||
|
@ -33,6 +35,7 @@ public abstract class MapResourceBundle extends ResourceBundle {
|
||||||
return new ResourceBundleEnumeration(lookup.keySet(), parent != null ? parent.getKeys() : null);
|
return new ResourceBundleEnumeration(lookup.keySet(), parent != null ? parent.getKeys() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Set<String> handleKeySet() {
|
protected Set<String> handleKeySet() {
|
||||||
if (lookup == null) {
|
if (lookup == null) {
|
||||||
loadLookup();
|
loadLookup();
|
||||||
|
@ -60,10 +63,14 @@ public abstract class MapResourceBundle extends ResourceBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ResourceBundleEnumeration implements Enumeration<String> {
|
private static class ResourceBundleEnumeration implements Enumeration<String> {
|
||||||
private Set<String> set;
|
|
||||||
private Iterator<String> iterator;
|
private final Set<String> set;
|
||||||
private Enumeration<String> enumeration;
|
|
||||||
private String next = null;
|
private final Iterator<String> iterator;
|
||||||
|
|
||||||
|
private final Enumeration<String> enumeration;
|
||||||
|
|
||||||
|
private String next;
|
||||||
|
|
||||||
ResourceBundleEnumeration(Set<String> var1, Enumeration<String> var2) {
|
ResourceBundleEnumeration(Set<String> var1, Enumeration<String> var2) {
|
||||||
this.set = var1;
|
this.set = var1;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Map;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Resources extends MapResourceBundle {
|
public class Resources extends MapResourceBundle {
|
||||||
|
|
||||||
private static final Map<String, Object> map = new HashMap<>();
|
private static final Map<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -13,7 +13,9 @@ import java.util.ResourceBundle;
|
||||||
* Represents a simple method of formatting a specific {@link TimeUnitQuantity} of time.
|
* Represents a simple method of formatting a specific {@link TimeUnitQuantity} of time.
|
||||||
*/
|
*/
|
||||||
public class ResourcesTimeFormat extends SimpleTimeFormat implements TimeFormat, LocaleAware<ResourcesTimeFormat> {
|
public class ResourcesTimeFormat extends SimpleTimeFormat implements TimeFormat, LocaleAware<ResourcesTimeFormat> {
|
||||||
|
|
||||||
private final ResourcesTimeUnit unit;
|
private final ResourcesTimeUnit unit;
|
||||||
|
|
||||||
private TimeFormat override;
|
private TimeFormat override;
|
||||||
|
|
||||||
public ResourcesTimeFormat(ResourcesTimeUnit unit) {
|
public ResourcesTimeFormat(ResourcesTimeUnit unit) {
|
||||||
|
@ -31,17 +33,14 @@ public class ResourcesTimeFormat extends SimpleTimeFormat implements TimeFormat,
|
||||||
} else {
|
} else {
|
||||||
override = null;
|
override = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (override == null) {
|
if (override == null) {
|
||||||
setPattern(bundle.getString(unit.getResourceKeyPrefix() + "Pattern"));
|
setPattern(bundle.getString(unit.getResourceKeyPrefix() + "Pattern"));
|
||||||
setFuturePrefix(bundle.getString(unit.getResourceKeyPrefix() + "FuturePrefix"));
|
setFuturePrefix(bundle.getString(unit.getResourceKeyPrefix() + "FuturePrefix"));
|
||||||
setFutureSuffix(bundle.getString(unit.getResourceKeyPrefix() + "FutureSuffix"));
|
setFutureSuffix(bundle.getString(unit.getResourceKeyPrefix() + "FutureSuffix"));
|
||||||
setPastPrefix(bundle.getString(unit.getResourceKeyPrefix() + "PastPrefix"));
|
setPastPrefix(bundle.getString(unit.getResourceKeyPrefix() + "PastPrefix"));
|
||||||
setPastSuffix(bundle.getString(unit.getResourceKeyPrefix() + "PastSuffix"));
|
setPastSuffix(bundle.getString(unit.getResourceKeyPrefix() + "PastSuffix"));
|
||||||
|
|
||||||
setSingularName(bundle.getString(unit.getResourceKeyPrefix() + "SingularName"));
|
setSingularName(bundle.getString(unit.getResourceKeyPrefix() + "SingularName"));
|
||||||
setPluralName(bundle.getString(unit.getResourceKeyPrefix() + "PluralName"));
|
setPluralName(bundle.getString(unit.getResourceKeyPrefix() + "PluralName"));
|
||||||
|
|
||||||
String key = unit.getResourceKeyPrefix() + "FuturePluralName";
|
String key = unit.getResourceKeyPrefix() + "FuturePluralName";
|
||||||
if (bundle.containsKey(key)) {
|
if (bundle.containsKey(key)) {
|
||||||
setFuturePluralName(bundle.getString(key));
|
setFuturePluralName(bundle.getString(key));
|
||||||
|
|
|
@ -6,7 +6,9 @@ import org.xbib.time.pretty.TimeUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class ResourcesTimeUnit implements TimeUnit {
|
public abstract class ResourcesTimeUnit implements TimeUnit {
|
||||||
|
|
||||||
private long maxQuantity = 0;
|
private long maxQuantity = 0;
|
||||||
|
|
||||||
private long millisPerUnit = 1;
|
private long millisPerUnit = 1;
|
||||||
|
|
||||||
protected abstract String getResourceKeyPrefix();
|
protected abstract String getResourceKeyPrefix();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Comparator;
|
||||||
*/
|
*/
|
||||||
public class TimeUnitComparator implements Comparator<TimeUnit> {
|
public class TimeUnitComparator implements Comparator<TimeUnit> {
|
||||||
|
|
||||||
|
@Override
|
||||||
public int compare(final TimeUnit left, final TimeUnit right) {
|
public int compare(final TimeUnit left, final TimeUnit right) {
|
||||||
if (left.getMillisPerUnit() < right.getMillisPerUnit()) {
|
if (left.getMillisPerUnit() < right.getMillisPerUnit()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -8,33 +8,6 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class CronExpression {
|
public abstract class CronExpression {
|
||||||
|
|
||||||
public abstract boolean matches(ZonedDateTime t);
|
|
||||||
|
|
||||||
public abstract ZonedDateTime nextExecution(ZonedDateTime from, ZonedDateTime to);
|
|
||||||
|
|
||||||
private static final String YEARLY = "0 0 1 1 *",
|
|
||||||
MONTHLY = "0 0 1 * *",
|
|
||||||
WEEKLY = "0 0 * * 7",
|
|
||||||
DAILY = "0 0 * * *",
|
|
||||||
HOURLY = "0 * * * *";
|
|
||||||
|
|
||||||
private static final Map<String, String> ALIASES = Map.ofEntries(
|
|
||||||
Map.entry("yearly", YEARLY),
|
|
||||||
Map.entry("annually", YEARLY),
|
|
||||||
Map.entry("monthly", MONTHLY),
|
|
||||||
Map.entry("weekly", WEEKLY),
|
|
||||||
Map.entry("daily", DAILY),
|
|
||||||
Map.entry("midnight", DAILY),
|
|
||||||
Map.entry("hourly", HOURLY));
|
|
||||||
|
|
||||||
private static final Pattern ALIAS_PATTERN = Pattern.compile("[a-z]+");
|
|
||||||
|
|
||||||
private static final boolean DEFAULT_ONE_BASED_DAY_OF_WEEK = false;
|
|
||||||
|
|
||||||
private static final boolean DEFAULT_SECONDS = false;
|
|
||||||
|
|
||||||
private static final boolean DEFAULT_ALLOW_BOTH_DAYS = true;
|
|
||||||
|
|
||||||
public static CronExpression yearly() {
|
public static CronExpression yearly() {
|
||||||
return parse(YEARLY);
|
return parse(YEARLY);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +36,37 @@ public abstract class CronExpression {
|
||||||
return parse(s, DEFAULT_ONE_BASED_DAY_OF_WEEK, DEFAULT_SECONDS, DEFAULT_ALLOW_BOTH_DAYS);
|
return parse(s, DEFAULT_ONE_BASED_DAY_OF_WEEK, DEFAULT_SECONDS, DEFAULT_ALLOW_BOTH_DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Parser parser() {
|
||||||
|
return new Parser();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean matches(ZonedDateTime t);
|
||||||
|
|
||||||
|
public abstract ZonedDateTime nextExecution(ZonedDateTime from, ZonedDateTime to);
|
||||||
|
|
||||||
|
private static final Pattern ALIAS_PATTERN = Pattern.compile("[a-z]+");
|
||||||
|
|
||||||
|
private static final boolean DEFAULT_ONE_BASED_DAY_OF_WEEK = false;
|
||||||
|
|
||||||
|
private static final boolean DEFAULT_SECONDS = false;
|
||||||
|
|
||||||
|
private static final boolean DEFAULT_ALLOW_BOTH_DAYS = true;
|
||||||
|
|
||||||
|
private static final String YEARLY = "0 0 1 1 *",
|
||||||
|
MONTHLY = "0 0 1 * *",
|
||||||
|
WEEKLY = "0 0 * * 7",
|
||||||
|
DAILY = "0 0 * * *",
|
||||||
|
HOURLY = "0 * * * *";
|
||||||
|
|
||||||
|
private static final Map<String, String> ALIASES = Map.ofEntries(
|
||||||
|
Map.entry("yearly", YEARLY),
|
||||||
|
Map.entry("annually", YEARLY),
|
||||||
|
Map.entry("monthly", MONTHLY),
|
||||||
|
Map.entry("weekly", WEEKLY),
|
||||||
|
Map.entry("daily", DAILY),
|
||||||
|
Map.entry("midnight", DAILY),
|
||||||
|
Map.entry("hourly", HOURLY));
|
||||||
|
|
||||||
private static boolean isValid(String s, boolean oneBasedDayOfWeek, boolean seconds, boolean allowBothDays) {
|
private static boolean isValid(String s, boolean oneBasedDayOfWeek, boolean seconds, boolean allowBothDays) {
|
||||||
boolean valid;
|
boolean valid;
|
||||||
try {
|
try {
|
||||||
|
@ -91,17 +95,18 @@ public abstract class CronExpression {
|
||||||
return new DefaultCronExpression(s, seconds, oneBasedDayOfWeek, allowBothDays);
|
return new DefaultCronExpression(s, seconds, oneBasedDayOfWeek, allowBothDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Parser parser() {
|
|
||||||
return new Parser();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Parser {
|
public static class Parser {
|
||||||
private boolean oneBasedDayOfWeek, seconds, allowBothDays;
|
|
||||||
|
private boolean oneBasedDayOfWeek;
|
||||||
|
|
||||||
|
private boolean seconds;
|
||||||
|
|
||||||
|
private boolean allowBothDays;
|
||||||
|
|
||||||
private Parser() {
|
private Parser() {
|
||||||
oneBasedDayOfWeek = DEFAULT_ONE_BASED_DAY_OF_WEEK;
|
this.oneBasedDayOfWeek = DEFAULT_ONE_BASED_DAY_OF_WEEK;
|
||||||
seconds = DEFAULT_SECONDS;
|
this.seconds = DEFAULT_SECONDS;
|
||||||
allowBothDays = DEFAULT_ALLOW_BOTH_DAYS;
|
this.allowBothDays = DEFAULT_ALLOW_BOTH_DAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid(String s) {
|
public boolean isValid(String s) {
|
||||||
|
|
|
@ -12,14 +12,14 @@ public class DayOfMonthField extends DefaultField {
|
||||||
|
|
||||||
private final boolean unspecified;
|
private final boolean unspecified;
|
||||||
|
|
||||||
private DayOfMonthField(Builder b) {
|
protected DayOfMonthField(Builder b) {
|
||||||
super(b);
|
super(b);
|
||||||
this.lastDay = b.lastDay;
|
this.lastDay = b.lastDay;
|
||||||
this.nearestWeekday = b.nearestWeekday;
|
this.nearestWeekday = b.nearestWeekday;
|
||||||
this.unspecified = b.unspecified;
|
this.unspecified = b.unspecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isUnspecified() {
|
public boolean isUnspecified() {
|
||||||
return unspecified;
|
return unspecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,15 +80,10 @@ public class DayOfMonthField extends DefaultField {
|
||||||
|
|
||||||
private boolean unspecified;
|
private boolean unspecified;
|
||||||
|
|
||||||
Builder() {
|
protected Builder() {
|
||||||
super(1, 31);
|
super(1, 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DayOfMonthField build() {
|
|
||||||
return new DayOfMonthField(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Builder parse(Tokens tokens) {
|
protected Builder parse(Tokens tokens) {
|
||||||
super.parse(tokens);
|
super.parse(tokens);
|
||||||
|
@ -118,5 +113,10 @@ public class DayOfMonthField extends DefaultField {
|
||||||
return super.parseNumber(tokens, token, first, last);
|
return super.parseNumber(tokens, token, first, last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DayOfMonthField build() {
|
||||||
|
return new DayOfMonthField(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class DayOfWeekField extends DefaultField {
|
||||||
|
|
||||||
private final boolean unspecified;
|
private final boolean unspecified;
|
||||||
|
|
||||||
private DayOfWeekField(Builder b) {
|
protected DayOfWeekField(Builder b) {
|
||||||
super(b);
|
super(b);
|
||||||
this.nth = b.nth;
|
this.nth = b.nth;
|
||||||
hasNth = !nth.isEmpty();
|
hasNth = !nth.isEmpty();
|
||||||
|
@ -38,7 +38,6 @@ public class DayOfWeekField extends DefaultField {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final DayOfWeek dayOfWeek = time.getDayOfWeek();
|
final DayOfWeek dayOfWeek = time.getDayOfWeek();
|
||||||
//int number = dayOfWeek.getValue() % 7;
|
|
||||||
int number = dayOfWeek.getValue();
|
int number = dayOfWeek.getValue();
|
||||||
if (hasLast) {
|
if (hasLast) {
|
||||||
return last.contains(number) && time.getMonth() != time.plusWeeks(1).getMonth();
|
return last.contains(number) && time.getMonth() != time.plusWeeks(1).getMonth();
|
||||||
|
@ -55,10 +54,6 @@ public class DayOfWeekField extends DefaultField {
|
||||||
return contains(number);
|
return contains(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int number(int dayOfWeek) {
|
|
||||||
return dayOfWeek % 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
@ -98,7 +93,8 @@ public class DayOfWeekField extends DefaultField {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder extends DefaultField.Builder {
|
public static class Builder extends DefaultField.Builder {
|
||||||
static final Keywords KEYWORDS = new Keywords();
|
|
||||||
|
protected static final Keywords KEYWORDS = new Keywords();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
KEYWORDS.put("MON", 1);
|
KEYWORDS.put("MON", 1);
|
||||||
|
@ -110,7 +106,7 @@ public class DayOfWeekField extends DefaultField {
|
||||||
KEYWORDS.put("SUN", 7);
|
KEYWORDS.put("SUN", 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean oneBased;
|
private final boolean oneBased;
|
||||||
|
|
||||||
private boolean unspecified;
|
private boolean unspecified;
|
||||||
|
|
||||||
|
@ -118,7 +114,7 @@ public class DayOfWeekField extends DefaultField {
|
||||||
|
|
||||||
private final MultiMap<Integer, Integer> nth;
|
private final MultiMap<Integer, Integer> nth;
|
||||||
|
|
||||||
Builder(boolean oneBased) {
|
protected Builder(boolean oneBased) {
|
||||||
super(1, 7);
|
super(1, 7);
|
||||||
this.oneBased = oneBased;
|
this.oneBased = oneBased;
|
||||||
last = new LinkedHashSet<>();
|
last = new LinkedHashSet<>();
|
||||||
|
@ -166,7 +162,7 @@ public class DayOfWeekField extends DefaultField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DayOfWeekField build() {
|
protected DayOfWeekField build() {
|
||||||
return new DayOfWeekField(this);
|
return new DayOfWeekField(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class DefaultCronExpression extends CronExpression {
|
||||||
|
|
||||||
private final DayOfMonthField dayOfMonth;
|
private final DayOfMonthField dayOfMonth;
|
||||||
|
|
||||||
DefaultCronExpression(String string, boolean seconds, boolean oneBasedDayOfWeek, boolean allowBothDayFields) {
|
public DefaultCronExpression(String string, boolean seconds, boolean oneBasedDayOfWeek, boolean allowBothDayFields) {
|
||||||
this.string = string;
|
this.string = string;
|
||||||
if (string.isEmpty()) {
|
if (string.isEmpty()) {
|
||||||
throw new IllegalArgumentException("empty spec not allowed");
|
throw new IllegalArgumentException("empty spec not allowed");
|
||||||
|
|
|
@ -10,15 +10,11 @@ public class DefaultField implements TimeField {
|
||||||
|
|
||||||
private final NavigableSet<Integer> numbers;
|
private final NavigableSet<Integer> numbers;
|
||||||
|
|
||||||
DefaultField(Builder b) {
|
protected DefaultField(Builder b) {
|
||||||
fullRange = b.fullRange;
|
fullRange = b.fullRange;
|
||||||
numbers = fullRange ? null : b.numbers;
|
numbers = fullRange ? null : b.numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DefaultField parse(Tokens s, int min, int max) {
|
|
||||||
return new Builder(min, max).parse(s).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(int number) {
|
public boolean contains(int number) {
|
||||||
return fullRange || numbers.contains(number);
|
return fullRange || numbers.contains(number);
|
||||||
|
@ -34,6 +30,10 @@ public class DefaultField implements TimeField {
|
||||||
return fullRange;
|
return fullRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DefaultField parse(Tokens s, int min, int max) {
|
||||||
|
return new Builder(min, max).parse(s).build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
@ -71,7 +71,7 @@ public class DefaultField implements TimeField {
|
||||||
|
|
||||||
private boolean fullRange;
|
private boolean fullRange;
|
||||||
|
|
||||||
Builder(int min, int max) {
|
protected Builder(int min, int max) {
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
numbers = new TreeSet<>();
|
numbers = new TreeSet<>();
|
||||||
|
@ -137,18 +137,18 @@ public class DefaultField implements TimeField {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextNumber(Tokens tokens) {
|
protected int nextNumber(Tokens tokens) {
|
||||||
if (tokens.next() == Token.NUMBER) {
|
if (tokens.next() == Token.NUMBER) {
|
||||||
return tokens.number();
|
return tokens.number();
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Expected number");
|
throw new IllegalStateException("Expected number");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean endOfField(Token token) {
|
protected boolean endOfField(Token token) {
|
||||||
return token == Token.FIELD_SEPARATOR || token == Token.END_OF_INPUT;
|
return token == Token.FIELD_SEPARATOR || token == Token.END_OF_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rangeSkip(int first, int last, int skip) {
|
protected void rangeSkip(int first, int last, int skip) {
|
||||||
for (int i = first; i <= last; i++) {
|
for (int i = first; i <= last; i++) {
|
||||||
if ((i - min) % skip == 0) {
|
if ((i - min) % skip == 0) {
|
||||||
add(i);
|
add(i);
|
||||||
|
@ -170,7 +170,7 @@ public class DefaultField implements TimeField {
|
||||||
numbers.add(value);
|
numbers.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultField build() {
|
protected DefaultField build() {
|
||||||
return new DefaultField(this);
|
return new DefaultField(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,19 @@ package org.xbib.time.schedule;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
class Entry<T> {
|
public class Entry<T> {
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
private CronExpression cronExpression;
|
private final CronExpression cronExpression;
|
||||||
|
|
||||||
private Callable<T> callable;
|
private final Callable<T> callable;
|
||||||
|
|
||||||
private ZonedDateTime lastCalled;
|
private ZonedDateTime lastCalled;
|
||||||
|
|
||||||
private ZonedDateTime nextCall;
|
private ZonedDateTime nextCall;
|
||||||
|
|
||||||
Entry(String name, CronExpression cronExpression, Callable<T> callable) {
|
public Entry(String name, CronExpression cronExpression, Callable<T> callable) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.cronExpression = cronExpression;
|
this.cronExpression = cronExpression;
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
|
|
|
@ -2,7 +2,8 @@ package org.xbib.time.schedule;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
final class Keywords {
|
public final class Keywords {
|
||||||
|
|
||||||
private final int[][][] keywords = new int[26][26][26];
|
private final int[][][] keywords = new int[26][26][26];
|
||||||
|
|
||||||
public Keywords() {
|
public Keywords() {
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class MonthField extends DefaultField {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder extends DefaultField.Builder {
|
public static class Builder extends DefaultField.Builder {
|
||||||
|
|
||||||
protected static final Keywords KEYWORDS = new Keywords();
|
protected static final Keywords KEYWORDS = new Keywords();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -6,11 +6,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
/**
|
/**
|
||||||
* Matches once only.
|
* Matches once only.
|
||||||
*/
|
*/
|
||||||
final class RebootCronExpression extends CronExpression {
|
public final class RebootCronExpression extends CronExpression {
|
||||||
|
|
||||||
private final AtomicBoolean matchOnce;
|
private final AtomicBoolean matchOnce;
|
||||||
|
|
||||||
RebootCronExpression() {
|
public RebootCronExpression() {
|
||||||
matchOnce = new AtomicBoolean(true);
|
matchOnce = new AtomicBoolean(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.time.schedule;
|
package org.xbib.time.schedule;
|
||||||
|
|
||||||
enum Token {
|
public enum Token {
|
||||||
END_OF_INPUT,
|
END_OF_INPUT,
|
||||||
FIELD_SEPARATOR,
|
FIELD_SEPARATOR,
|
||||||
LAST,
|
LAST,
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package org.xbib.time.schedule;
|
package org.xbib.time.schedule;
|
||||||
|
|
||||||
final class Tokens {
|
public final class Tokens {
|
||||||
|
|
||||||
|
private final String source;
|
||||||
|
|
||||||
|
private final int length;
|
||||||
|
|
||||||
private int number;
|
private int number;
|
||||||
|
|
||||||
|
@ -8,8 +12,6 @@ final class Tokens {
|
||||||
|
|
||||||
private Keywords keywords;
|
private Keywords keywords;
|
||||||
|
|
||||||
private final String source;
|
|
||||||
private final int length;
|
|
||||||
private int position;
|
private int position;
|
||||||
|
|
||||||
public Tokens(String s) {
|
public Tokens(String s) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue