01: // $Id: DefaultNameGuesser.java 12 2007-08-29 05:23:13Z jcamaia $
02:
03: package net.sf.persist;
04:
05: import java.util.LinkedHashSet;
06: import java.util.Locale;
07: import java.util.Set;
08:
09: /**
10: * Default NameGuesser implementation.
11: */
12: public final class DefaultNameGuesser implements NameGuesser {
13:
14: /**
15: * Given a field or class name in the form CompoundName (for classes) or
16: * compoundName (for fields) will return a set of guessed names such as
17: * [compound_name, compound_names, compoundname, compoundnames].
18: */
19: public Set<String> guessColumn(final String fieldOrClassName) {
20:
21: final String nameUnderscore = fieldOrClassName.replaceAll(
22: "([A-Z])", "_$1").toLowerCase();
23: final String nameLowercase = fieldOrClassName
24: .toLowerCase(Locale.ENGLISH);
25:
26: final Set<String> names = new LinkedHashSet();
27: names.add(nameUnderscore);
28: names.add(nameLowercase);
29: names.add(nameUnderscore + "s");
30: names.add(nameLowercase + "s");
31: return names;
32: }
33:
34: }
|