-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* minimal support for parsing dates * minimal support for parsing dates * wire date into list parser * test date-typed param * fix parsing of '@' with missing digits * extend test runner to handle sfdate and integrate date.json
- Loading branch information
Showing
6 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.greenbytes.http.sfv; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a Date. | ||
*/ | ||
public class DateItem implements NumberItem<Long> { | ||
|
||
private final long value; | ||
private final Parameters params; | ||
|
||
private static final long MIN = -999999999999999L; | ||
private static final long MAX = 999999999999999L; | ||
|
||
private DateItem(long value, Parameters params) { | ||
if (value < MIN || value > MAX) { | ||
throw new IllegalArgumentException("value must be in the range from " + MIN + " to " + MAX); | ||
} | ||
this.value = value; | ||
this.params = Objects.requireNonNull(params, "params must not be null"); | ||
} | ||
|
||
/** | ||
* Creates an {@link DateItem} instance representing the specified | ||
* {@code long} value. | ||
* | ||
* @param value | ||
* a {@code long} value. | ||
* @return a {@link DateItem} representing {@code value}. | ||
*/ | ||
public static DateItem valueOf(long value) { | ||
return new DateItem(value, Parameters.EMPTY); | ||
} | ||
|
||
@Override | ||
public DateItem withParams(Parameters params) { | ||
if (Objects.requireNonNull(params, "params must not be null").isEmpty()) { | ||
return this; | ||
} else { | ||
return new DateItem(this.value, params); | ||
} | ||
} | ||
|
||
@Override | ||
public Parameters getParams() { | ||
return params; | ||
} | ||
|
||
@Override | ||
public StringBuilder serializeTo(StringBuilder sb) | ||
{ | ||
sb.append('@'); | ||
sb.append(Long.toString(value)); | ||
params.serializeTo(sb); | ||
return sb; | ||
} | ||
|
||
@Override | ||
public String serialize() { | ||
return serializeTo(new StringBuilder()).toString(); | ||
} | ||
|
||
@Override | ||
public Long get() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public long getAsLong() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int getDivisor() { | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters