PageRenderTime 37ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/net/sf/persist/DefaultNameGuesser.java

http://github.com/rufiao/persist
Java | 32 lines | 16 code | 7 blank | 9 comment | 0 complexity | 97a91f7dd04acb1afc190532102fd2ae MD5 | raw file
 1// $Id$
 2
 3package net.sf.persist;
 4
 5import java.util.LinkedHashSet;
 6import java.util.Locale;
 7import java.util.Set;
 8
 9/**
10 * Default NameGuesser implementation.
11 */
12public 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("([A-Z])", "_$1").toLowerCase();
22		final String nameLowercase = fieldOrClassName.toLowerCase(Locale.ENGLISH);
23
24		final Set<String> names = new LinkedHashSet();
25		names.add(nameUnderscore);
26		names.add(nameLowercase);
27		names.add(nameUnderscore + "s");
28		names.add(nameLowercase + "s");
29		return names;
30	}
31
32}