LocaleDateRange.java
package com.tradecloud.domain.base.utils;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import org.joda.time.LocalDate;
import java.io.IOException;
public class LocaleDateRange implements IdentifiedDataSerializable {
private LocalDate from;
private LocalDate to;
public LocaleDateRange() {
}
public LocaleDateRange(LocalDate from, LocalDate to) {
this.from = from;
this.to = to;
}
@Override
public void writeData(ObjectDataOutput out) throws IOException {
// Write as millis from epoch
out.writeLong(from != null ? from.toDate().getTime() : -1L);
out.writeLong(to != null ? to.toDate().getTime() : -1L);
}
@Override
public void readData(ObjectDataInput in) throws IOException {
long fromMillis = in.readLong();
long toMillis = in.readLong();
this.from = fromMillis != -1L ? new LocalDate(fromMillis) : null;
this.to = toMillis != -1L ? new LocalDate(toMillis) : null;
}
@Override
public int getFactoryId() {
return LocaleDateRangeSerializer.FACTORY_ID;
}
@Override
public int getClassId() {
return LocaleDateRangeSerializer.LOCALE_DATE_RANGE_ID;
}
public LocalDate getFrom() {
return from;
}
public LocalDate getTo() {
return to;
}
@Override
public String toString() {
return "LocaleDateRange{" +
"from=" + from +
", to=" + to +
'}';
}
}