Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update thrift & support duration data type #413

Merged
merged 2 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

package com.vesoft.nebula.client.graph.data;

import com.vesoft.nebula.Duration;
import java.util.Objects;

public class DurationWrapper extends BaseDataObject {
private final Duration duration;

/**
* DurationWrapper is a wrapper for the duration type of nebula-graph
*/
public DurationWrapper(Duration duration) {
this.duration = duration;
}

/**
* @return utc duration seconds
*/
public long getSeconds() {
return duration.seconds;
}

/**
* @retrun utc duration microseconds
*/
public int getMicroseconds() {
return duration.microseconds;
}

/**
* @return utc duration months
*/
public int getMonths() {
return duration.months;
}

/**
* @return the duration string
*/
public String getDurationString() {
return String.format("duration({months:%d, seconds:%d, microseconds:%d})",
getMonths(), getSeconds(), getMicroseconds());
}


@Override
public String toString() {
long year = duration.seconds / (60 * 60 * 24);
long remainSeconds = duration.seconds - (year) * (60 * 60 * 24);
return String.format("P%dM%dDT%sS",
duration.months, year, remainSeconds + duration.microseconds / 1000000.0);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DurationWrapper that = (DurationWrapper) o;
return duration.months == that.getMonths()
&& duration.seconds == that.getSeconds()
&& duration.microseconds == that.getMicroseconds();
}

@Override
public int hashCode() {
return Objects.hash(duration);
}

}
Loading