Project

General

Profile

« Previous | Next » 

Revision 43f0d97d

Added by Andreas Müller almost 3 years ago

fix #9030 add reverse order pattern for monthPattern with extreme values

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/temporal/in/TemporalDataExcelImport.java
101 101
        if(StringUtils.isBlank(monthStr)){
102 102
            return null;
103 103
        }else {
104
            int extremeIndex = 2;
105
            int normalIndex = 1;
104 106
            Matcher matcher = getPattern().matcher(monthStr);
107
            if (!matcher.matches()){
108
                matcher = getReversePattern().matcher(monthStr);
109
                extremeIndex = 1;
110
                normalIndex = 2;
111
            }
105 112
            if (matcher.matches()){
106 113
                if(isExtreme){
107
                    if (matcher.group(2) != null){
108
                        String extreme = matcher.group(2);
114
                    if (matcher.group(extremeIndex) != null){
115
                        String extreme = matcher.group(extremeIndex);
109 116
                        return Integer.valueOf(extreme);
110 117
                    }else{
111 118
                        return null; //extreme value does not exist
112 119
                    }
113 120
                }else{
114
                    String normal = matcher.group(1);
121
                    String normal = matcher.group(normalIndex);
115 122
                    return Integer.valueOf(normal);
116 123
                }
117 124
            }else{
......
125 132
    }
126 133

  
127 134
    private Pattern monthPattern;
135
    private String nr = "(0?[1-9]|1[0-2])";
136

  
128 137
    private Pattern getPattern() {
129 138
        if (monthPattern == null){
130
            String nr = "(0?[1-9]|1[0-2])";
131 139
            monthPattern = Pattern.compile(nr + "\\s*(?:\\(" + nr + "\\))?");
132 140
        }
133 141
        return monthPattern;
134 142
    }
135 143

  
144
    private Pattern reverseMonthPattern;
145
    private Pattern getReversePattern(){
146
        if (reverseMonthPattern == null){
147
            reverseMonthPattern = Pattern.compile("(?:\\(" + nr + "\\))?\\s*" + nr);
148
        }
149
        return reverseMonthPattern;
150
    }
151

  
136 152
    @Override
137 153
    protected boolean requiresNomenclaturalCode() {
138 154
        return false;

Also available in: Unified diff