下面列出了java.util.Date#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public StockPriceHistoryExternalizable(String s, Date startDate,
Date endDate, EntityManager em) {
Date curDate = new Date(startDate.getTime());
symbol = s;
while (!curDate.after(endDate)) {
StockPriceEagerLazyImpl sp =
em.find(StockPriceEagerLazyImpl.class,
new StockPricePK(s, (Date) curDate.clone()));
if (sp != null) {
Date d = (Date) curDate.clone();
if (firstDate == null) {
firstDate = d;
}
prices.put(d, sp);
lastDate = d;
}
curDate.setTime(curDate.getTime() + msPerDay);
}
}
/**
* @param cargo cargo
* @param completionTime completion time, the reported time that the event
* actually happened (e.g. the receive took place).
* @param registrationTime registration time, the time the message is
* received
* @param type type of event
* @param location where the event took place
*/
public HandlingEvent(Cargo cargo, Date completionTime,
Date registrationTime, Type type, Location location) {
Validate.notNull(cargo, "Cargo is required");
Validate.notNull(completionTime, "Completion time is required");
Validate.notNull(registrationTime, "Registration time is required");
Validate.notNull(type, "Handling event type is required");
Validate.notNull(location, "Location is required");
if (type.requiresVoyage()) {
throw new IllegalArgumentException(
"Voyage is required for event type " + type);
}
this.completionTime = (Date) completionTime.clone();
this.registrationTime = (Date) registrationTime.clone();
this.type = type;
this.location = location;
this.cargo = cargo;
this.voyage = null;
}
/**
* @param cargo The cargo
* @param completionTime completion time, the reported time that the event
* actually happened (e.g. the receive took place).
* @param registrationTime registration time, the time the message is
* received
* @param type type of event
* @param location where the event took place
* @param voyage the voyage
*/
public HandlingEvent(Cargo cargo, Date completionTime,
Date registrationTime, Type type, Location location, Voyage voyage) {
Validate.notNull(cargo, "Cargo is required");
Validate.notNull(completionTime, "Completion time is required");
Validate.notNull(registrationTime, "Registration time is required");
Validate.notNull(type, "Handling event type is required");
Validate.notNull(location, "Location is required");
Validate.notNull(voyage, "Voyage is required");
if (type.prohibitsVoyage()) {
throw new IllegalArgumentException(
"Voyage is not allowed with event type " + type);
}
this.voyage = voyage;
this.completionTime = (Date) completionTime.clone();
this.registrationTime = (Date) registrationTime.clone();
this.type = type;
this.location = location;
this.cargo = cargo;
}
public MarriageDataBase(final @NotNull MARRIAGE_PLAYER player1, final @NotNull MARRIAGE_PLAYER player2, final @Nullable MARRIAGE_PLAYER priest, final @NotNull Date weddingDate, final @Nullable String surname,
final boolean pvpEnabled, final @Nullable MessageColor color, final @Nullable HOME home, final @Nullable Object databaseKey)
{
this.player1 = player1;
this.player2 = player2;
this.priest = priest;
this.surname = surname;
this.pvpEnabled = pvpEnabled;
this.weddingDate = (Date) weddingDate.clone();
this.databaseKey = databaseKey;
this.home = home;
this.color = color;
this.chatPrefix = ""; // TODO implement in db
if(player1 instanceof MarriagePlayerDataBase && player2 instanceof MarriagePlayerDataBase)
{
((MarriagePlayerDataBase) player1).addMarriage(this);
((MarriagePlayerDataBase) player2).addMarriage(this);
}
hash = player1.hashCode() * 53 + player2.hashCode();
}
public TaskExecution(long executionId, Integer exitCode, String taskName,
Date startTime, Date endTime, String exitMessage, List<String> arguments,
String errorMessage, String externalExecutionId, Long parentExecutionId) {
Assert.notNull(arguments, "arguments must not be null");
this.executionId = executionId;
this.exitCode = exitCode;
this.taskName = taskName;
this.exitMessage = exitMessage;
this.arguments = new ArrayList<>(arguments);
this.startTime = (startTime != null) ? (Date) startTime.clone() : null;
this.endTime = (endTime != null) ? (Date) endTime.clone() : null;
this.errorMessage = errorMessage;
this.externalExecutionId = externalExecutionId;
this.parentExecutionId = parentExecutionId;
}
/**
* @param cargo The cargo
* @param completionTime completion time, the reported time that the event
* actually happened (e.g. the receive took place).
* @param registrationTime registration time, the time the message is
* received
* @param type type of event
* @param location where the event took place
* @param voyage the voyage
*/
public HandlingEvent(Cargo cargo, Date completionTime,
Date registrationTime, Type type, Location location, Voyage voyage) {
Validate.notNull(cargo, "Cargo is required");
Validate.notNull(completionTime, "Completion time is required");
Validate.notNull(registrationTime, "Registration time is required");
Validate.notNull(type, "Handling event type is required");
Validate.notNull(location, "Location is required");
Validate.notNull(voyage, "Voyage is required");
if (type.prohibitsVoyage()) {
throw new IllegalArgumentException(
"Voyage is not allowed with event type " + type);
}
this.voyage = voyage;
this.completionTime = (Date) completionTime.clone();
this.registrationTime = (Date) registrationTime.clone();
this.type = type;
this.location = location;
this.cargo = cargo;
}
/**
* @param cargo cargo
* @param completionTime completion time, the reported time that the event
* actually happened (e.g. the receive took place).
* @param registrationTime registration time, the time the message is
* received
* @param type type of event
* @param location where the event took place
*/
public HandlingEvent(Cargo cargo, Date completionTime,
Date registrationTime, Type type, Location location) {
Validate.notNull(cargo, "Cargo is required");
Validate.notNull(completionTime, "Completion time is required");
Validate.notNull(registrationTime, "Registration time is required");
Validate.notNull(type, "Handling event type is required");
Validate.notNull(location, "Location is required");
if (type.requiresVoyage()) {
throw new IllegalArgumentException(
"Voyage is required for event type " + type);
}
this.completionTime = (Date) completionTime.clone();
this.registrationTime = (Date) registrationTime.clone();
this.type = type;
this.location = location;
this.cargo = cargo;
this.voyage = null;
}
/**
* @param cargo cargo
* @param completionTime completion time, the reported time that the event
* actually happened (e.g. the receive took place).
* @param registrationTime registration time, the time the message is
* received
* @param type type of event
* @param location where the event took place
*/
public HandlingEvent(Cargo cargo, Date completionTime,
Date registrationTime, Type type, Location location) {
Validate.notNull(cargo, "Cargo is required");
Validate.notNull(completionTime, "Completion time is required");
Validate.notNull(registrationTime, "Registration time is required");
Validate.notNull(type, "Handling event type is required");
Validate.notNull(location, "Location is required");
if (type.requiresVoyage()) {
throw new IllegalArgumentException(
"Voyage is required for event type " + type);
}
this.completionTime = (Date) completionTime.clone();
this.registrationTime = (Date) registrationTime.clone();
this.type = type;
this.location = location;
this.cargo = cargo;
this.voyage = null;
}
/**
* @param date
* @return 复制新Date,不改变参数
*/
public static Date nextDay(Date date) {
Date newDate = (Date) date.clone();
long time = (newDate.getTime() / 1000) + 60 * 60 * 24;
newDate.setTime(time * 1000);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
newDate = format.parse(format.format(newDate));
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
return newDate;
}
public StockPriceHistoryCompressUnbuffered(String s,
Date startDate, Date endDate, EntityManager em) {
Date curDate = new Date(startDate.getTime());
symbol = s;
while (!curDate.after(endDate)) {
StockPriceEagerLazyImpl sp =
em.find(StockPriceEagerLazyImpl.class,
new StockPricePK(s, (Date) curDate.clone()));
if (sp != null) {
Date d = (Date) curDate.clone();
if (firstDate == null) {
firstDate = d;
}
prices.put(d, sp);
lastDate = d;
}
curDate.setTime(curDate.getTime() + msPerDay);
}
}
/**
* @param origin origin location - can't be the same as the destination
* @param destination destination location - can't be the same as the origin
* @param arrivalDeadline arrival deadline
*/
public RouteSpecification(final Location origin, final Location destination, final Date arrivalDeadline) {
Validate.notNull(origin, "Origin is required");
Validate.notNull(destination, "Destination is required");
Validate.notNull(arrivalDeadline, "Arrival deadline is required");
Validate.isTrue(!origin.sameIdentityAs(destination), "Origin and destination can't be the same: " + origin);
this.origin = origin;
this.destination = destination;
this.arrivalDeadline = (Date) arrivalDeadline.clone();
}
/**
* @param origin origin location - can't be the same as the destination
* @param destination destination location - can't be the same as the origin
* @param arrivalDeadline arrival deadline
*/
public RouteSpecification(Location origin, Location destination,
Date arrivalDeadline) {
Validate.notNull(origin, "Origin is required");
Validate.notNull(destination, "Destination is required");
Validate.notNull(arrivalDeadline, "Arrival deadline is required");
Validate.isTrue(!origin.sameIdentityAs(destination),
"Origin and destination can't be the same: " + origin);
this.origin = origin;
this.destination = destination;
this.arrivalDeadline = (Date) arrivalDeadline.clone();
}
/**
* Initialization code shared by constructors.
*
* @param date a <code>Date</code> object representing the specified time down to second
* resolution. This date should have a date of 01/01/1970. If it does not, such a
* date will be forced. If this object has non-zero milliseconds, they are combined
* with the nanoseconds parameter.
* @param nanoseconds the number of nanoseconds beyond the Date specified in the date parameter
* @param timeZone the time zone specified for this object (or TZ_UNSPECIFIED if unspecified).
* The offset to GMT, in minutes.
* @param defaultedTimeZone the time zone actually used for this object (if it was originally
* unspecified, the default time zone used). The offset to GMT, in minutes.
*/
private void init(Date date, int nanoseconds, int timeZone, int defaultedTimeZone) {
// Shouldn't happen, but just in case...
if (earlyException != null)
throw earlyException;
// get a temporary copy of the date
Date tmpDate = (Date) (date.clone());
// Combine the nanoseconds so they are between 0 and 999,999,999
this.nanoseconds = DateTimeAttribute.combineNanos(tmpDate, nanoseconds);
// now that the date has been (potentially) updated, store the time
this.timeGMT = tmpDate.getTime();
// keep track of the timezone values
this.timeZone = timeZone;
this.defaultedTimeZone = defaultedTimeZone;
// Check that the date is normalized to 1/1/70
if ((timeGMT >= DateAttribute.MILLIS_PER_DAY) || (timeGMT < 0)) {
timeGMT = timeGMT % DateAttribute.MILLIS_PER_DAY;
// if we had a negative value then we need to shift by a day
if (timeGMT < 0)
timeGMT += DateAttribute.MILLIS_PER_DAY;
}
}
@SuppressWarnings("JdkObsolete")
public Date getBootTime() {
final Date bootTimeRef = bootTime;
return bootTimeRef != null ? (Date) bootTimeRef.clone() : null;
}
public void setCreationDate(Date creationDate) {
this.creationDate = (creationDate != null) ? (Date) creationDate.clone() : null;
}
public void setModified(Date modified) {
this.modified = modified == null ? null : (Date) modified.clone();
}
public void setModified(Date modified) {
this.modified = modified == null ? null : (Date) modified.clone();
}
public void setModified(Date modified) {
this.modified = modified == null ? null : (Date) modified.clone();
}
@JsonProperty("closed_at")
public void setClosedAt(Date closedAt) {
this.closedAt = closedAt == null ? null : (Date) closedAt.clone();
}
/**
* Setter for property {@code lastModifiedBefore}.
* @param lastModifiedBefore A file will be selected only if it was
* last modified before {@code lastModifiedBefore}.
* <br>This condition is ignored if {@code lastModifiedBefore} is
* {@code null}.
*/
public void setLastModifiedBefore(Date lastModifiedBefore) {
this.lastModifiedBefore =
(lastModifiedBefore==null)?null:(Date)lastModifiedBefore.clone();
}