Java Code Examples for java.util.Date#clone()

The following examples show how to use java.util.Date#clone() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
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);
    }
}
 
Example 2
/**
 * @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;
}
 
Example 3
Source Project: CargoTracker-J12015   File: HandlingEvent.java    License: MIT License 6 votes vote down vote up
/**
 * @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;
}
 
Example 4
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();
}
 
Example 5
Source Project: spring-cloud-task   File: TaskExecution.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
/**
 * @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;
}
 
Example 7
/**
 * @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;
}
 
Example 8
/**
 * @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;
}
 
Example 9
Source Project: uavstack   File: DateTimeHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @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;

}
 
Example 10
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);
    }
}
 
Example 11
Source Project: dddsample-core   File: RouteSpecification.java    License: MIT License 5 votes vote down vote up
/**
 * @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();
}
 
Example 12
/**
 * @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();
}
 
Example 13
Source Project: balana   File: TimeAttribute.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 14
Source Project: sentry-android   File: Device.java    License: MIT License 4 votes vote down vote up
@SuppressWarnings("JdkObsolete")
public Date getBootTime() {
  final Date bootTimeRef = bootTime;
  return bootTimeRef != null ? (Date) bootTimeRef.clone() : null;
}
 
Example 15
Source Project: eplmp   File: PartRevisionDTO.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public void setCreationDate(Date creationDate) {
    this.creationDate = (creationDate != null) ? (Date) creationDate.clone() : null;
}
 
Example 16
Source Project: mySSM   File: UserPassword.java    License: MIT License 4 votes vote down vote up
public void setModified(Date modified) {
    this.modified = modified == null ? null : (Date) modified.clone();
}
 
Example 17
Source Project: mySSM   File: UserRelease.java    License: MIT License 4 votes vote down vote up
public void setModified(Date modified) {
    this.modified = modified == null ? null : (Date) modified.clone();
}
 
Example 18
Source Project: mySSM   File: WantContext.java    License: MIT License 4 votes vote down vote up
public void setModified(Date modified) {
    this.modified = modified == null ? null : (Date) modified.clone();
}
 
Example 19
Source Project: gitea-plugin   File: GiteaMilestone.java    License: MIT License 4 votes vote down vote up
@JsonProperty("closed_at")
public void setClosedAt(Date closedAt) {
    this.closedAt = closedAt == null ? null : (Date) closedAt.clone();
}
 
Example 20
/**
 * 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();
}