MCPcopy Create free account
hub / github.com/MenoData/Time4J / writeDuration

Method writeDuration

base/src/main/java/net/time4j/SPX.java:489–525  ·  view source on GitHub ↗
(ObjectOutput out)

Source from the content-addressed store, hash-verified

487 }
488
489 private void writeDuration(ObjectOutput out)
490 throws IOException {
491
492 Duration<?> d = Duration.class.cast(this.obj);
493 int size = d.getTotalLength().size();
494 boolean useLong = false;
495
496 for (int i = 0, n = Math.min(size, 6); i < n; i++ ) {
497 if (d.getTotalLength().get(i).getAmount() >= 1000) {
498 useLong = true;
499 break;
500 }
501 }
502
503 int header = DURATION_TYPE;
504 header <<= 4;
505 if (useLong) {
506 header |= 1;
507 }
508 out.writeByte(header);
509 out.writeInt(size);
510
511 for (int i = 0; i < size; i++ ) {
512 TimeSpan.Item<?> item = d.getTotalLength().get(i);
513 if (useLong) {
514 out.writeLong(item.getAmount());
515 } else {
516 out.writeInt((int) item.getAmount());
517 }
518 out.writeObject(item.getUnit());
519 }
520
521 if (size > 0) {
522 out.writeBoolean(d.isNegative());
523 }
524
525 }
526
527 private Object readDuration(
528 ObjectInput in,

Callers 1

writeExternalMethod · 0.95

Calls 8

getTotalLengthMethod · 0.65
getMethod · 0.65
isNegativeMethod · 0.65
castMethod · 0.45
sizeMethod · 0.45
minMethod · 0.45
getAmountMethod · 0.45
getUnitMethod · 0.45

Tested by

no test coverage detected