List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:msi.gama.util.GAML.java
public static String getDocumentationOn2(final String query) { final String keyword = StringUtils.removeEnd(StringUtils.removeStart(query.trim(), "#"), ":"); final THashMap<String, String> results = new THashMap<>(); // Statements final SymbolProto p = DescriptionFactory.getStatementProto(keyword); if (p != null) { results.put("Statement", p.getDocumentation()); }/* w ww. j ava 2s . co m*/ DescriptionFactory.visitStatementProtos((name, proto) -> { if (proto.getFacet(keyword) != null) { results.put("Facet of statement " + name, proto.getFacet(keyword).getDocumentation()); } }); final Set<String> types = new HashSet<>(); final String[] facetDoc = { "" }; DescriptionFactory.visitVarProtos((name, proto) -> { if (proto.getFacet(keyword) != null && types.size() < 4) { if (!Types.get(name).isAgentType() || name.equals(IKeyword.AGENT)) { types.add(name); } facetDoc[0] = proto.getFacet(keyword).getDocumentation(); } }); if (!types.isEmpty()) { results.put("Facet of attribute declarations with types " + types + (types.size() == 4 ? " ..." : ""), facetDoc[0]); } // Operators final THashMap<Signature, OperatorProto> ops = IExpressionCompiler.OPERATORS.get(keyword); if (ops != null) { ops.forEachEntry((sig, proto) -> { results.put("Operator on " + sig.toString(), proto.getDocumentation()); return true; }); } // Built-in skills final SkillDescription sd = GamaSkillRegistry.INSTANCE.get(keyword); if (sd != null) { results.put("Skill", sd.getDocumentation()); } GamaSkillRegistry.INSTANCE.visitSkills(desc -> { final SkillDescription sd1 = (SkillDescription) desc; final VariableDescription var = sd1.getAttribute(keyword); if (var != null) { results.put("Attribute of skill " + desc.getName(), var.getDocumentation()); } final ActionDescription action = sd1.getAction(keyword); if (action != null) { results.put("Primitive of skill " + desc.getName(), action.getDocumentation().isEmpty() ? "" : ":" + action.getDocumentation()); } return true; }); // Types final IType<?> t = Types.builtInTypes.containsType(keyword) ? Types.get(keyword) : null; if (t != null) { String tt = t.getDocumentation(); if (tt == null) { tt = "type " + keyword; } results.put("Type", tt); } // Built-in species for (final TypeDescription td : Types.getBuiltInSpecies()) { if (td.getName().equals(keyword)) { results.put("Built-in species", ((SpeciesDescription) td).getDocumentationWithoutMeta()); } final IDescription var = td.getOwnAttribute(keyword); if (var != null) { results.put("Attribute of built-in species " + td.getName(), var.getDocumentation()); } final ActionDescription action = td.getOwnAction(keyword); if (action != null) { results.put("Primitive of built-in species " + td.getName(), action.getDocumentation().isEmpty() ? "" : ":" + action.getDocumentation()); } } // Constants final UnitConstantExpression exp = IUnits.UNITS_EXPR.get(keyword); if (exp != null) { results.put("Constant", exp.getDocumentation()); } if (results.isEmpty()) { return "No result found"; } final StringBuilder sb = new StringBuilder(); final int max = results.keySet().stream().mapToInt(each -> each.length()).max().getAsInt(); final String separator = StringUtils.repeat("", max + 6).concat(Strings.LN); results.forEachEntry((sig, doc) -> { sb.append("").append(separator).append("|| "); sb.append(StringUtils.rightPad(sig, max)); sb.append(" ||").append(Strings.LN).append(separator); sb.append(toText(doc)).append(Strings.LN); return true; }); return sb.toString(); // }
From source file:com.hangum.tadpole.sql.util.SQLUtil.java
/** * jdbc? .//from w ww . j a va 2 s . c o m * * @param exeSQL * @return */ public static String sqlExecutable(String exeSQL) { // tmpStrSelText = UnicodeUtils.getUnicode(tmpStrSelText); try { // // https://github.com/hangum/TadpoleForDBTools/issues/140 . // TO DO ? ?? ??..DB? ? . // ? // ? ? ?? ? . /* * mysql? ?? , -- ? ? -- ? ?? ?. --comment ? ? ?? .( (mssql, oralce, pgsql)? ? ??) * , ?? ?? ?? ?? . - 2013.11.11- (hangum) */ // exeSQL = delComment(exeSQL, "--"); // // exeSQL = StringUtils.replace(exeSQL, "\r", " "); // exeSQL = StringUtils.replace(exeSQL, "\n", " "); // exeSQL = StringUtils.replace(exeSQL, Define.LINE_SEPARATOR, " "); // exeSQL = exeSQL.replaceAll("(\r\n|\n|\r)", " "); // ? ? exeSQL = removeComment(exeSQL); exeSQL = StringUtils.trimToEmpty(exeSQL); exeSQL = StringUtils.removeEnd(exeSQL, PublicTadpoleDefine.SQL_DELIMITER); } catch (Exception e) { logger.error("query execute", e); } return exeSQL.trim(); }
From source file:com.fiveamsolutions.nci.commons.validator.MultipleCriteriaMessageInterpolator.java
@SuppressWarnings("rawtypes") private String interpolateWithDefault(String message, Validator validator, MessageInterpolator defaultInterpolator) { String toInterpolate = message; String key = StringUtils.removeStart(StringUtils.removeEnd(message, "}"), "{"); if (bundle != null && bundle.containsKey(key)) { toInterpolate = bundle.getString(key); }//from w ww. j a v a 2s. c om return defaultInterpolator.interpolate(toInterpolate, validator, defaultInterpolator); }
From source file:edu.mayo.cts2.framework.core.json.JsonConverter.java
/** * Builds the gson./* ww w. j av a2s.c o m*/ * * @return the gson */ protected Gson buildGson() { GsonBuilder gson = new GsonBuilder(); gson.setDateFormat(ISO_DATE_FORMAT); gson.setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes f) { return f.getName().equals(CHOICE_VALUE); } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }); gson.registerTypeAdapter(List.class, new EmptyCollectionSerializer()); gson.registerTypeAdapter(TsAnyType.class, new TsAnyTypeSerializer()); gson.registerTypeAdapter(Date.class, new DateTypeAdapter()); gson.registerTypeAdapterFactory(new ChangeableTypeAdapterFactory()); gson.registerTypeAdapterFactory(new ChangeableResourceTypeAdapterFactory()); gson.setFieldNamingStrategy(new FieldNamingStrategy() { @Override public String translateName(Field field) { String fieldName = field.getName(); char[] array = fieldName.toCharArray(); if (array[0] == '_') { array = ArrayUtils.remove(array, 0); } String name = new String(array); if (name.endsWith(LIST_SUFFIX)) { name = StringUtils.removeEnd(name, LIST_SUFFIX); } return name; } }); return gson.create(); }
From source file:gobblin.cluster.GobblinClusterManager.java
/** * Create the service based application launcher and other associated services * @throws Exception/*w w w .j av a 2 s .c o m*/ */ private void initializeAppLauncherAndServices() throws Exception { // Done to preserve backwards compatibility with the previously hard-coded timeout of 5 minutes Properties properties = ConfigUtils.configToProperties(this.config); if (!properties.contains(ServiceBasedAppLauncher.APP_STOP_TIME_SECONDS)) { properties.setProperty(ServiceBasedAppLauncher.APP_STOP_TIME_SECONDS, Long.toString(300)); } this.applicationLauncher = new ServiceBasedAppLauncher(properties, this.clusterName); // create a job catalog for keeping track of received jobs if a job config path is specified if (this.config.hasPath(GobblinClusterConfigurationKeys.GOBBLIN_CLUSTER_PREFIX + ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)) { String jobCatalogClassName = ConfigUtils.getString(config, GobblinClusterConfigurationKeys.JOB_CATALOG_KEY, GobblinClusterConfigurationKeys.DEFAULT_JOB_CATALOG); this.jobCatalog = (MutableJobCatalog) GobblinConstructorUtils.invokeFirstConstructor( Class.forName(jobCatalogClassName), ImmutableList.<Object>of(config.getConfig( StringUtils.removeEnd(GobblinClusterConfigurationKeys.GOBBLIN_CLUSTER_PREFIX, ".")))); } else { this.jobCatalog = null; } SchedulerService schedulerService = new SchedulerService(properties); this.applicationLauncher.addService(schedulerService); this.applicationLauncher.addService(buildGobblinHelixJobScheduler(config, this.appWorkDir, getMetadataTags(clusterName, applicationId), schedulerService)); this.applicationLauncher.addService(buildJobConfigurationManager(config)); }
From source file:com.gemstone.gemfire.management.internal.cli.parser.jopt.JoptOptionParser.java
public OptionSet parse(String userInput) throws CliCommandOptionException { OptionSet optionSet = new OptionSet(); optionSet.setUserInput(userInput != null ? userInput.trim() : ""); if (userInput != null) { TrimmedInput input = PreprocessorUtils.trim(userInput); String[] preProcessedInput = preProcess(input.getString()); joptsimple.OptionSet joptOptionSet = null; CliCommandOptionException ce = null; // int factor = 0; try {/*from w w w. j a v a 2 s . c om*/ joptOptionSet = parser.parse(preProcessedInput); } catch (Exception e) { if (e instanceof OptionException) { ce = processException(e); joptOptionSet = ((OptionException) e).getDetected(); } } if (joptOptionSet != null) { // Make sure there are no miscellaneous, unknown strings that cannot be identified as // either options or arguments. if (joptOptionSet.nonOptionArguments().size() > arguments.size()) { String unknownString = joptOptionSet.nonOptionArguments().get(arguments.size()); // If the first option is un-parseable then it will be returned as "<option>=<value>" since it's // been interpreted as an argument. However, all subsequent options will be returned as "<option>". // This hack splits off the string before the "=" sign if it's the first case. if (unknownString.matches("^-*\\w+=.*$")) { unknownString = unknownString.substring(0, unknownString.indexOf('=')); } ce = processException( OptionException.createUnrecognizedOptionException(unknownString, joptOptionSet)); } // First process the arguments StringBuffer argument = new StringBuffer(); int j = 0; for (int i = 0; i < joptOptionSet.nonOptionArguments().size() && j < arguments.size(); i++) { argument = argument.append(joptOptionSet.nonOptionArguments().get(i)); // Check for syntax of arguments before adding them to the // option set as we want to support quoted arguments and those // in brackets if (PreprocessorUtils.isSyntaxValid(argument.toString())) { optionSet.put(arguments.get(j), argument.toString()); j++; argument.delete(0, argument.length()); } } if (argument.length() > 0) { // Here we do not need to check for the syntax of the argument // because the argument list is now over and this is the last // argument which was not added due to improper syntax optionSet.put(arguments.get(j), argument.toString()); } // Now process the options for (Option option : options) { List<String> synonyms = option.getAggregate(); for (String string : synonyms) { if (joptOptionSet.has(string)) { // Check whether the user has actually entered the // full option or just the start boolean present = false; outer: for (String inputSplit : preProcessedInput) { if (inputSplit.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) { // Remove option prefix inputSplit = StringUtils.removeStart(inputSplit, SyntaxConstants.LONG_OPTION_SPECIFIER); // Remove value specifier inputSplit = StringUtils.removeEnd(inputSplit, SyntaxConstants.OPTION_VALUE_SPECIFIER); if (!inputSplit.equals("")) { if (option.getLongOption().equals(inputSplit)) { present = true; break outer; } else { for (String optionSynonym : option.getSynonyms()) { if (optionSynonym.equals(inputSplit)) { present = true; break outer; } } } } } } if (present) { if (joptOptionSet.hasArgument(string)) { List<?> arguments = joptOptionSet.valuesOf(string); if (arguments.size() > 1 && !(option.getConverter() instanceof MultipleValueConverter) && option.getValueSeparator() == null) { List<String> optionList = new ArrayList<String>(1); optionList.add(string); ce = processException( new MultipleArgumentsForOptionException(optionList, joptOptionSet)); } else if ((arguments.size() == 1 && !(option.getConverter() instanceof MultipleValueConverter)) || option.getValueSeparator() == null) { optionSet.put(option, arguments.get(0).toString().trim()); } else { StringBuffer value = new StringBuffer(); String valueSeparator = option.getValueSeparator(); for (Object object : joptOptionSet.valuesOf(string)) { if (value.length() == 0) { value.append((String) object); } else { if (valueSeparator != null) { value.append(valueSeparator + ((String) object).trim()); } else { value.append(((String) object).trim()); } } } optionSet.put(option, value.toString()); } } else { optionSet.put(option, option.getSpecifiedDefaultValue()); } break; } } } } } // Convert the preProcessedInput into List<String> List<String> split = new ArrayList<String>(); for (int i = 0; i < preProcessedInput.length; i++) { split.add(preProcessedInput[i]); } optionSet.setNoOfSpacesRemoved(input.getNoOfSpacesRemoved() /* + factor */); optionSet.setSplit(split); if (ce != null) { ce.setOptionSet(optionSet); throw ce; } } return optionSet; }
From source file:com.activecq.experiments.redis.impl.RedisResourceProviderImpl.java
private void configure(final ComponentContext componentContext) { final Map<String, String> properties = (Map<String, String>) componentContext.getProperties(); // Get Roots from Service properties this.roots = new ArrayList<String>(); String[] rootsArray = PropertiesUtil.toStringArray(properties.get(ResourceProvider.ROOTS), new String[] {}); for (String root : rootsArray) { root = StringUtils.strip(root);/* w ww. j a v a 2s .c o m*/ if (StringUtils.isBlank(root)) { continue; } else if (StringUtils.equals(root, "/")) { // Cowardly refusing to mount the root continue; } this.roots.add(StringUtils.removeEnd(root, "/")); } }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractController.java
protected boolean isPartialRedirect(HttpServletRequest request, String urlTemplatePath) { String adjustedTemplate = StringUtils.removeEnd(urlTemplatePath, ALL_WILDCARD); String contextPath = this.getUrlPathHelper().getContextPath(request); String requestUri = StringUtils.removeStart(request.getRequestURI(), contextPath); return !(StringUtils.removeStart(StringUtils.removeEnd(requestUri, "/"), "/") .equals(StringUtils.removeStart(StringUtils.removeEnd(adjustedTemplate, "/"), "/"))); }
From source file:com.hangum.tadpole.db.metadata.MakeContentAssistUtil.java
/** * Table ? /* ww w . ja va 2 s .co m*/ * * @param showTables * @param userDB * @return */ public List<TableDAO> getTableAfterwork(List<TableDAO> showTables, final UserDBDAO userDB) { /** filter . */ showTables = DBAccessCtlManager.getInstance().getTableFilter(showTables, userDB); // ? ?? . ' " ???. StringBuffer strTablelist = new StringBuffer(); for (TableDAO tableDao : showTables) { tableDao.setSysName(SQLUtil.makeIdentifierName(userDB, tableDao.getName())); strTablelist.append(makeObjectPattern(tableDao.getSchema_name(), tableDao.getSysName(), "Table")); //$NON-NLS-1$ } userDB.setTableListSeparator(StringUtils.removeEnd(strTablelist.toString(), _PRE_GROUP)); //$NON-NLS-1$ return showTables; }
From source file:info.magnolia.setup.for4_5.UpdateSecurityFilterClientCallbacksConfiguration.java
private String simplifyClassName(String clazz) { return StringUtils.removeEnd(StringUtils.substringAfterLast(clazz, "."), "ClientCallback").toLowerCase(); }