Added PeriodDataType

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widget-common-event@111638 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-02-03 18:01:33 +00:00
parent 47e4bcbdef
commit 3e241e25e7
2 changed files with 0 additions and 152 deletions

View File

@ -1,119 +0,0 @@
package org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum PeriodDataType {
DAY("Day"),
MONTH("Month"),
QUARTER("Quarter_of_year"),
YEAR("Year"),
DECADE("Decade"),
CENTURY("Century");
private static Map<PeriodDataType, List<PeriodDataType>> hierarchicalRelation = new HashMap<PeriodDataType, List<PeriodDataType>>();
static {
hierarchicalRelation.put(DAY, Arrays.asList(MONTH, QUARTER, YEAR, DECADE, CENTURY));
hierarchicalRelation.put(MONTH, Arrays.asList(QUARTER, YEAR, DECADE, CENTURY));
hierarchicalRelation.put(QUARTER, Arrays.asList(YEAR, DECADE, CENTURY));
hierarchicalRelation.put(YEAR, Arrays.asList(DECADE, CENTURY));
hierarchicalRelation.put(DECADE, Arrays.asList(CENTURY));
}
private static final int START_YEAR = 1700;
private static final int END_YEAR = 2300;
/**
* @param text
*/
private PeriodDataType(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public List<PeriodDataType> getHierarchicalRelationOfPeriodDataType(PeriodDataType periodDataType){
return hierarchicalRelation.get(periodDataType);
}
public Map<PeriodDataType, List<PeriodDataType>> getHierarchicalRelation(){
return hierarchicalRelation;
}
public String getPeriodDataTypeLabel() {
switch (this) {
case DAY:
return "Day";
case MONTH:
return "Month";
case QUARTER:
return "Quarter of year";
case YEAR:
return "Year";
case DECADE:
return "Decade";
case CENTURY:
return "Century";
default:
return null;
}
}
public static int getStartYear(){
return START_YEAR;
}
public static int getEndYear(){
return END_YEAR;
}
public static PeriodDataType getPeriodFromString(String period){
if(period.compareToIgnoreCase(PeriodDataType.DAY.toString())==0){
return PeriodDataType.DAY;
} else {
if(period.compareToIgnoreCase(PeriodDataType.MONTH.toString())==0){
return PeriodDataType.MONTH;
} else {
if(period.compareToIgnoreCase(PeriodDataType.QUARTER.toString())==0){
return PeriodDataType.QUARTER;
} else {
if(period.compareToIgnoreCase(PeriodDataType.YEAR.toString())==0){
return PeriodDataType.YEAR;
} else {
if(period.compareToIgnoreCase(PeriodDataType.DECADE.toString())==0){
return PeriodDataType.DECADE;
} else {
if(period.compareToIgnoreCase(PeriodDataType.CENTURY.toString())==0){
return PeriodDataType.CENTURY;
} else {
return null;
}
}
}
}
}
}
}
}

View File

@ -1,33 +0,0 @@
package org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class PeriodDataTypeMap {
public static PeriodDataType map(String id) {
if (id.compareTo(PeriodDataType.DAY.toString()) == 0) {
return PeriodDataType.DAY;
} else {
if (id.compareTo(PeriodDataType.MONTH.toString()) == 0) {
return PeriodDataType.MONTH;
} else {
if (id.compareTo(PeriodDataType.QUARTER.toString()) == 0) {
return PeriodDataType.QUARTER;
} else {
if (id.compareTo(PeriodDataType.YEAR.toString()) == 0) {
return PeriodDataType.YEAR;
} else {
return null;
}
}
}
}
}
}