}
}
+ /**
+ * True, if there is no start date and no end date and no freetext representation exists.
+ * @return
+ */
+ @Transient
+ public boolean isEmpty(){
+ if (CdmUtils.isEmpty(this.getFreeText()) && start == null && end == null ){
+ return true;
+ }else{
+ return false;
+ }
+ }
+
public Partial getStart() {
return start;
}
/**
+ * For time periods that need to store more information than the one
+ * that can be stored in <code>start</code> and <code>end</code>.
+ * If free text is not <code>null</null> {@link #toString()} will always
+ * return the free text value.
+ * <BR>Use {@link #toString()} for public use.
* @return the freeText
*/
- protected String getFreeText() {
+ public String getFreeText() {
return freeText;
}
/**
+ * Use {@link #parseSingleDate(String)} for public use.
* @param freeText the freeText to set
*/
- protected void setFreeText(String freeText) {
+ public void setFreeText(String freeText) {
this.freeText = freeText;
}
//case fl. 1806 or c. 1806 or fl. 1806?
private static final Pattern prefixedYearPattern = Pattern.compile("(fl|c)\\.\\s*\\d{4}(\\s*-\\s*\\d{4})?\\??");
//standard
- private static final Pattern standardPattern = Pattern.compile("\\s*\\d{2,4}(\\s*-\\s*\\d{2,4})?");
+ private static final Pattern standardPattern = Pattern.compile("\\s*\\d{2,4}(\\s*-(\\s*\\d{2,4})?)?");
public static TimePeriod parseString(TimePeriod timePeriod, String periodString){
}
periodString = periodString.trim();
- result.setFreeText(periodString);
+ result.setFreeText(null);
//case "1806"[1807];
if (uncorrectYearPatter.matcher(periodString).matches()){
+ result.setFreeText(periodString);
String realYear = periodString.split("\\[")[1];
realYear = realYear.replace("]", "");
result.setStartYear(Integer.valueOf(realYear));
+ result.setFreeText(periodString);
//case fl. 1806 or c. 1806 or fl. 1806?
}else if(prefixedYearPattern.matcher(periodString).matches()){
+ result.setFreeText(periodString);
Matcher yearMatcher = firstYearPattern.matcher(periodString);
yearMatcher.find();
String startYear = yearMatcher.group();
result.setEnd(dtEnd);
} catch (IllegalArgumentException e) {
//logger.warn(e.getMessage());
- //use freetext instead
+ result.setFreeText(periodString);
}
}
+ }else{
+ result.setFreeText(periodString);
}
return result;
}
}
+//**************************** to String ****************************************
+
+ /**
+ * Returns the {@link #getFreeText()} value if free text is not <code>null</code>.
+ * Otherwise the concatenation of <code>start</code> and <code>end</code> is returned.
+ *
+ * @see java.lang.Object#toString()
+ */
public String toString(){
String result = null;
DateTimeFormatter formatter = new TimePeriodPartialFormatter();
- if (! CdmUtils.isEmpty(this.getFreeText())){
+ if ( CdmUtils.isNotEmpty(this.getFreeText())){
result = this.getFreeText();
}else{
- String strStart = start != null? start.toString(formatter): null;
- String strEnd = end != null? end.toString(formatter): null;
+ String strStart = start != null ? start.toString(formatter): null;
+ String strEnd = end != null ? end.toString(formatter): null;
result = CdmUtils.concat("-", strStart, strEnd);
}
return result;