/** * Thread safe way to access the {@link AliasLoader} singleton instance. * * @return a thread safe singleton instance of the {@link AliasLoader}. */ public static synchronized AliasLoader get() { if (AliasLoader.instance == null) { AliasLoader.instance = new AliasLoader(); } return AliasLoader.instance; }
/** * Checks whether the given alias relates to the given keyword. * * <p> * <b>Note:</b> This check ignores case. * </p> * * @return true if the keyword contains the given alias or if the alias and * the keyword are equal * * @see #getKeywordForAlias(String) */ public boolean isAliasForKeyword(String alias, String keyword) { if (keyword.equalsIgnoreCase(alias)) { return true; } this.keywordAliasesProperties = loadAliasProperties(ALIAS_KEYWORDS); Set<String> keywordAliases = getFormattedAliases(keywordAliasesProperties, keyword); return containsAlias(keywordAliases, alias); }
private static void initializeAliasesUsingPropertyFile() { for (String interpreterClassName : AliasLoader.get().getInterpreterClassNames()) { Set<String> aliasesSet = AliasLoader.get().getAliasesForInterpreterClassName(interpreterClassName); for (String alias : aliasesSet) { aliasInterpreter(alias, interpreterClassName); } } }
/** * Returns the aliases (trimmed) for a specific interpreter (using the class * name). */ public Set<String> getAliasesForInterpreterClassName(String interpreterClassName) { this.interpreterAliasesProperties = loadAliasProperties(ALIAS_INTERPRETERS); return getFormattedAliases(interpreterAliasesProperties, interpreterClassName); }
/** * Find the key for a given alias. * * <p> * This method will stop after the first found key. * </p> * * @return the key for the given alias or null if none alias is found. */ public String getKeywordForAlias(String alias) { this.keywordAliasesProperties = loadAliasProperties(ALIAS_KEYWORDS); return getKeyForAlias(keywordAliasesProperties, alias); }
private String identifier(Example row) { String possibleAliasIdentifier = ExampleUtil.contentOf(row.firstChild()); String aliasIdentifier = AliasLoader.get().getKeywordForAlias(possibleAliasIdentifier); return aliasIdentifier == null ? possibleAliasIdentifier : aliasIdentifier; }
@FactoryMethod public static ErrorExpectation create(String expected) { return AliasLoader.get().isAliasForKeyword(expected, ERROR) ? new ErrorExpectation() : null; }
/** * Search key for value. * * <p> * Iterates through the comma separated aliases. Stops by the first found * key. * </p> */ private String getKeyForAlias(Properties aliasProperties, String alias) { for (String key : aliasProperties.stringPropertyNames()) { if (key.equalsIgnoreCase(alias)) { return key; } Set<String> keyAliases = getFormattedAliases(aliasProperties, key); if (containsAlias(keyAliases, alias)) { return key; } } return null; }
/** * Returns all interpreter class names which are defined in the associated * interpreter properties file. */ public Set<String> getInterpreterClassNames() { this.interpreterAliasesProperties = loadAliasProperties(ALIAS_INTERPRETERS); return interpreterAliasesProperties.stringPropertyNames(); }
private String identifier(Example row) { String possibleAliasIdentifier = ExampleUtil.contentOf(row.firstChild()); String aliasIdentifier = AliasLoader.get().getKeywordForAlias(possibleAliasIdentifier); return aliasIdentifier == null ? possibleAliasIdentifier : aliasIdentifier; }
@FactoryMethod public static NullExpectation create(String expected) { return AliasLoader.get().isAliasForKeyword(expected, "null") ? new NullExpectation() : null; }