001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.common.parsers; 015 016import org.gbif.api.vocabulary.Habitat; 017import org.gbif.common.parsers.core.EnumParser; 018 019/** 020 * Singleton implementation of the dictionary that uses the file /dictionaries/parse/habitat.txt. 021 */ 022public class HabitatParser extends EnumParser<Habitat> { 023 024 private static HabitatParser singletonObject = null; 025 026 private HabitatParser() { 027 super(Habitat.class, false, HabitatParser.class.getResourceAsStream("/dictionaries/parse/habitat.tsv")); 028 } 029 030 public static HabitatParser getInstance() { 031 synchronized (HabitatParser.class) { 032 if (singletonObject == null) { 033 singletonObject = new HabitatParser(); 034 } 035 } 036 return singletonObject; 037 } 038 039 /** 040 * Strip of any s at the end often found in english plurals 041 */ 042 @Override 043 protected String normalize(String value) { 044 String x = super.normalize(value); 045 if (x != null && x.length() > 1) { 046 if (x.endsWith("S")) { 047 return x.substring(0, x.length()-1); 048 } 049 } 050 return x; 051 } 052}