net.razorvine.pickle.objects.TimeDelta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pyrolite Show documentation
Show all versions of pyrolite Show documentation
This library allows your Java program to interface very easily with the Python world. It uses the Pyro protocol to call methods on remote objects. (See https://pyro5.readthedocs.io/).
Pyrolite only implements part of the client side Pyro library, hence its name 'lite'... So if you don't need Pyro's full feature set, Pyrolite may be a good choice to connect java or .NET and python.
Version 5.0 changes: support Pyro5 wire protocol. Dropped support of Pyro4 (stick to version 4.xx for that).
package net.razorvine.pickle.objects;
import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Locale;
/**
* Helper class to mimic the datetime.timedelta Python object (holds a days/seconds/microsec time difference).
*
* @author Irmen de Jong ([email protected])
*/
public class TimeDelta implements Serializable {
private static final long serialVersionUID = 5793744158850914421L;
public int days;
public int seconds;
public int microseconds;
public double total_seconds;
public TimeDelta(int days, int seconds, int microseconds) {
this.days = days;
this.seconds = seconds;
this.microseconds = microseconds;
this.total_seconds = days*86400+seconds+microseconds/1000000.0;
}
public String toString() {
NumberFormat nf=NumberFormat.getInstance(Locale.UK);
nf.setGroupingUsed(false);
nf.setMaximumFractionDigits(6);
String floatsecs=nf.format(total_seconds);
return String.format("Timedelta: %d days, %d seconds, %d microseconds (total: %s seconds)", days, seconds, microseconds, floatsecs);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + days;
result = prime * result + microseconds;
result = prime * result + seconds;
long temp=Double.doubleToLongBits(total_seconds);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof TimeDelta))
return false;
TimeDelta other = (TimeDelta) obj;
return days==other.days && seconds==other.seconds && microseconds==other.microseconds && total_seconds==other.total_seconds;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy