com.squeakysand.commons.valueobjects.AbstractMutableValueObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of squeakysand-commons Show documentation
Show all versions of squeakysand-commons Show documentation
Classes, interfaces and enums that assist with everyday Java development tasks.
The newest version!
/*
* Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squeakysand.commons.valueobjects;
import java.util.Date;
/**
* Abstract implementation of the {@link MutableValueObject} interface, providing implementations of many methods.
*/
public abstract class AbstractMutableValueObject extends AbstractValueObject implements MutableValueObject {
private static final long serialVersionUID = 8318832838894714104L;
private Date createdTimeStamp;
private Date modifiedTimeStamp;
/**
* Creates a new AbstractMutableValueObject object. Same as calling {@link #AbstractMutableValueObject(Date, Date)} and passing null parameter
* values.
*/
public AbstractMutableValueObject() {
this(null, null);
}
/**
* Creates a new AbstractMutableValueObject object.
*
* @param createdTimeStamp
* may benull if VO represents a new entity that has not been persisted yet.
* @param modifiedTimeStamp
* may benull if VO represents a new entity that has not been persisted yet.
*/
public AbstractMutableValueObject(Date createdTimeStamp, Date modifiedTimeStamp) {
if (createdTimeStamp == null) {
this.createdTimeStamp = null;
} else {
this.createdTimeStamp = (Date) createdTimeStamp.clone();
}
if (modifiedTimeStamp == null) {
this.modifiedTimeStamp = null;
} else {
this.modifiedTimeStamp = (Date) modifiedTimeStamp.clone();
}
}
/**
* {@inheritDoc}
*
* Accessor for the createdTimeStamp property.
*/
@Override
public Date getCreatedTimeStamp() {
return createdTimeStamp;
}
/**
* {@inheritDoc}
*
* Accessor for the modifiedTimeStamp property.
*/
@Override
public Date getModifiedTimeStamp() {
return modifiedTimeStamp;
}
/**
* {@inheritDoc}.
*/
@Override
public boolean isDirty() {
return true;
}
/**
* Mutator for the createdTimeStamp property.
*
* @param createdTimeStamp
* the new value for the createdTimeStamp property.
*/
public void setCreatedTimeStamp(Date createdTimeStamp) {
if (createdTimeStamp == null) {
this.createdTimeStamp = null;
} else {
// clone it since Date is mutable
this.createdTimeStamp = (Date) createdTimeStamp.clone();
}
}
/**
* Mutator for the modifiedTimeStamp property.
*
* @param modifiedTimeStamp
* the new value for the modifiedTimeStamp property.
*/
public void setModifiedTimeStamp(Date modifiedTimeStamp) {
if (modifiedTimeStamp == null) {
this.modifiedTimeStamp = null;
} else {
// clone it since Date is mutable
this.modifiedTimeStamp = (Date) modifiedTimeStamp.clone();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy