Skip to content

Commit

Permalink
add TxnId.toFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Apr 29, 2020
1 parent 91ea675 commit 525323b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions modules/txn/src/main/java/org/jpos/transaction/TxnId.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import java.io.File;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -54,6 +55,41 @@ private TxnId init (int year, int dayOfYear, int secondOfDay, int node, long tra
+ transactionId % 100000;
return this;
}
/**
* Returns a file suitable to store contents of <i>this</i> transaction.
* File format is <i>yyyy/mm/dd/hh-mm-ss-node-id</i>
* @return file in said format
*/
public File toFile () {
long l = id;
int yy = (int) (id / YMUL); l -= yy*YMUL;
int dd = (int) (l / DMUL); l -= dd*DMUL;
int sod = (int) (l / SMUL); l -= sod*SMUL;
int node = (int) (l / NMUL); l -= node * NMUL;
int hh = sod/3600;
int mm = (sod-3600*hh) / 60;
int ss = sod % 60;

DateTime dt = new DateTime()
.withYear(2000+yy)
.withDayOfYear(dd)
.withHourOfDay(hh)
.withMinuteOfHour(mm)
.withSecondOfMinute(ss);

return new File(
String.format("%04d/%02d/%02d/%02d-%02d-%02d-%03d-%05d",
dt.year().get(),
dt.monthOfYear().get(),
dt.dayOfMonth().get(),
dt.hourOfDay().get(),
dt.minuteOfHour().get(),
dt.secondOfMinute().get(),
node,
l
)
);
}

@Override
public String toString() {
Expand Down

0 comments on commit 525323b

Please sign in to comment.