Revision 0d330678
ref #7644 some further fine tuning on setting CONTINUED/end date in TimePeriod and some cleanup
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/TimePeriod.java | ||
---|---|---|
292 | 292 |
start=startDate; |
293 | 293 |
} |
294 | 294 |
public TimePeriod(Partial startDate, Partial endDate) { |
295 |
start=startDate;
|
|
296 |
end=endDate;
|
|
295 |
start = startDate;
|
|
296 |
end = endDate;
|
|
297 | 297 |
} |
298 | 298 |
|
299 | 299 |
//******************* GETTER / SETTER ************************************/ |
... | ... | |
311 | 311 |
|
312 | 312 |
@JsonIgnore // currently used for swagger model scanner |
313 | 313 |
public Partial getEnd() { |
314 |
return end; |
|
314 |
return isContinued() ? null : end;
|
|
315 | 315 |
} |
316 | 316 |
|
317 | 317 |
public void setEnd(Partial end) { |
... | ... | |
340 | 340 |
} |
341 | 341 |
|
342 | 342 |
|
343 |
/** |
|
344 |
* Shortcut to define that {@link #getEnd() end of period} is defined end |
|
345 |
* for a continuous period represented by {@link #CONTINUED} |
|
346 |
* @return |
|
347 |
*/ |
|
348 |
public boolean isContinued() { |
|
349 |
return CONTINUED.equals(end); |
|
350 |
} |
|
351 |
public void setContinued(boolean isContinued) { |
|
352 |
if (isContinued == true){ |
|
353 |
this.end = CONTINUED; |
|
354 |
} |
|
355 |
} |
|
356 |
|
|
357 |
|
|
343 | 358 |
//******************* Transient METHODS ************************************/ |
344 | 359 |
|
345 | 360 |
/** |
... | ... | |
405 | 420 |
|
406 | 421 |
@Transient |
407 | 422 |
public Integer getEndYear(){ |
408 |
return getPartialValue(end, YEAR_TYPE);
|
|
423 |
return getPartialValue(getEnd(), YEAR_TYPE);
|
|
409 | 424 |
} |
410 | 425 |
|
411 | 426 |
@Transient |
412 | 427 |
public Integer getEndMonth(){ |
413 |
return getPartialValue(end, MONTH_TYPE);
|
|
428 |
return getPartialValue(getEnd(), MONTH_TYPE);
|
|
414 | 429 |
} |
415 | 430 |
|
416 | 431 |
@Transient |
417 | 432 |
public Integer getEndDay(){ |
418 |
return getPartialValue(end, DAY_TYPE);
|
|
433 |
return getPartialValue(getEnd(), DAY_TYPE);
|
|
419 | 434 |
} |
420 | 435 |
|
421 | 436 |
public TimePeriod setStartYear(Integer year){ |
... | ... | |
465 | 480 |
@Transient |
466 | 481 |
private TimePeriod setEndField(Integer value, DateTimeFieldType type) |
467 | 482 |
throws IndexOutOfBoundsException{ |
468 |
end = setPartialField(end, value, type);
|
|
483 |
end = setPartialField(getEnd(), value, type);
|
|
469 | 484 |
return this; |
470 | 485 |
} |
471 | 486 |
|
... | ... | |
526 | 541 |
|
527 | 542 |
/** |
528 | 543 |
* Returns the concatenation of <code>start</code> and <code>end</code> |
529 |
* |
|
530 | 544 |
*/ |
531 | 545 |
public String getTimePeriod(){ |
532 | 546 |
String result = null; |
... | ... | |
578 | 592 |
public int hashCode() { |
579 | 593 |
int hashCode = 7; |
580 | 594 |
hashCode = 29*hashCode + |
581 |
(start== null? 33: start.hashCode()) + |
|
582 |
(end== null? 39: end.hashCode()) + |
|
583 |
(freeText== null? 41: freeText.hashCode()); |
|
595 |
(start == null? 33: start.hashCode()) +
|
|
596 |
(end == null? 39: end.hashCode()) +
|
|
597 |
(freeText == null? 41: freeText.hashCode());
|
|
584 | 598 |
return hashCode; |
585 | 599 |
} |
586 | 600 |
|
... | ... | |
609 | 623 |
target.setFreeText(origin.freeText); |
610 | 624 |
} |
611 | 625 |
|
612 |
|
|
613 |
/** |
|
614 |
* Shortcut to define that {@link #getEnd() end of period} is defined end |
|
615 |
* for a continuous period represented by {@link #CONTINUED} |
|
616 |
* @return |
|
617 |
*/ |
|
618 |
public boolean isContinued() { |
|
619 |
return CONTINUED.equals(end); |
|
620 |
} |
|
621 |
public void setContinued(boolean isContinued) { |
|
622 |
if (isContinued == true){ |
|
623 |
this.end = CONTINUED; |
|
624 |
} |
|
625 |
} |
|
626 |
|
|
627 |
|
|
628 | 626 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/common/TimePeriodTest.java | ||
---|---|---|
332 | 332 |
Assert.assertEquals("+", tp1.toString()); |
333 | 333 |
} |
334 | 334 |
|
335 |
@Test |
|
336 |
public void testContinued() { |
|
337 |
TimePeriod tp1 = TimePeriod.NewInstance(2017, 2018); |
|
338 |
Assert.assertEquals((Integer)2018, tp1.getEndYear()); |
|
339 |
tp1.setContinued(true); |
|
340 |
Assert.assertNull("The end should be removed and also the CONTINUED constant should be returned for getEnd()", tp1.getEnd()); |
|
341 |
Assert.assertTrue(tp1.isContinued()); |
|
342 |
Assert.assertEquals(null, tp1.getEndYear()); |
|
343 |
Assert.assertEquals(null, tp1.getEndMonth()); |
|
344 |
Assert.assertEquals(null, tp1.getEndDay()); |
|
345 |
tp1.setEndMonth(month); |
|
346 |
Assert.assertFalse(tp1.isContinued()); |
|
347 |
Assert.assertEquals(null, tp1.getEndYear()); |
|
348 |
Assert.assertEquals(month, tp1.getEndMonth()); |
|
349 |
Assert.assertEquals(null, tp1.getEndDay()); |
|
350 |
|
|
351 |
} |
|
352 |
|
|
353 |
|
|
335 | 354 |
|
336 | 355 |
/** |
337 | 356 |
* Test method for {@link eu.etaxonomy.cdm.model.common.TimePeriod#clone()}. |
Also available in: Unified diff