List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:com.netspective.commons.text.TextUtils.java
/** * Given a text string, return a string that would be suitable for that string to be used * as a Java constant (public static final XXX). The rule is to basically take every letter * or digit and return it in uppercase and every non-letter or non-digit as an underscore. * This trims all non-letter/digit characters from the beginning of the string. *///from w w w. j a v a 2s . com public String xmlTextToJavaConstantTrimmed(String xml) { if (xml == null || xml.length() == 0) return xml; boolean stringStarted = false; StringBuffer constant = new StringBuffer(); for (int i = 0; i < xml.length(); i++) { char ch = xml.charAt(i); if (Character.isJavaIdentifierPart(ch)) { stringStarted = true; constant.append(Character.toUpperCase(ch)); } else if (stringStarted) constant.append('_'); } return constant.toString(); }
From source file:org.apache.nifi.processors.ParseCSV.ParseCSV.java
private char randomChar(Random r, String cs, boolean uppercase) { char c = cs.charAt(r.nextInt(cs.length())); return uppercase ? Character.toUpperCase(c) : c; }
From source file:br.msf.commons.text.EnhancedStringBuilder.java
public EnhancedStringBuilder toUpperCase(final int start, final int end) { ArgumentUtils.rejectIfLessThan(start, 0); ArgumentUtils.rejectIfGreaterEqual(start, end); for (int i = start; i < length() && i < end; i++) { setCharAt(i, Character.toUpperCase(charAt(i))); }/*from w w w . j av a2 s . c o m*/ return this; }
From source file:edu.stanford.muse.util.Util.java
/** capitalizes just the first letter and returns the given string */ public static String capitalizeFirstLetter(String str) { if (str == null) return null; if (str.length() == 0) return str; if (str.length() == 1) return Character.toString((Character.toUpperCase(str.charAt(0)))); else//from ww w . j av a 2 s . c o m return Character.toUpperCase(str.charAt(0)) + str.substring(1); }
From source file:com.rapidminer.gui.OperatorDocLoader.java
/** * This loads the documentation of the operator referenced by the operator description from the * Wiki in the internet./*from w w w.j a v a 2 s . c om*/ */ private static String loadSelectedOperatorDocuFromWiki(OperatorDescription opDesc) throws IOException, ParserConfigurationException, OperatorCreationException, TransformerException, URISyntaxException { String operatorWikiName = StringUtils.EMPTY; if (!opDesc.isDeprecated()) { operatorWikiName = opDesc.getName().replace(" ", "_"); if (opDesc.getProvider() != null) { String prefix = opDesc.getProvider().getPrefix(); prefix = Character.toUpperCase(prefix.charAt(0)) + prefix.substring(1); operatorWikiName = prefix + ":" + operatorWikiName; } Document documentOperator = parseDocumentForOperator(operatorWikiName, opDesc); if (documentOperator != null) { // writing html back to string Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // initialize StreamResult with File object to save to file StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(documentOperator); transformer.transform(source, result); String HTMLString = result.getWriter().toString(); HTMLString = customizeHTMLStringDirty(HTMLString, SwingTools.getIconPath("24/" + opDesc.getIconName())); return HTMLString; } } return loadSelectedOperatorDocuLocally(opDesc); }
From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java
/** * Calculate the name for a getter method to retrieve the specified property * @param propertyName/*from ww w . j a v a 2s . c o m*/ * @return The name for the getter method for this property, if it were to exist, i.e. getConstraints */ public static String getGetterName(String propertyName) { final String suffix; if (propertyName.length() > 1 && Character.isLowerCase(propertyName.charAt(0)) && Character.isUpperCase(propertyName.charAt(1))) { suffix = propertyName; } else { suffix = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); } return "get" + suffix; }
From source file:de.uniwue.info2.generator.TestcaseGenerator.java
/** * Generate unit-tests for given language-specification. * * @param targetLanguage/*from ww w . j a v a 2 s. c o m*/ * the language-specification you want to generate unit-tests for. * @param useOptionalOperations * if true, optional operations are also generated * @return true if unit-tests were successfully generated */ public boolean generateUnitTest(LanguageSpecification targetLanguage, Boolean useOptionalOperations, List<String> optionalExceptions, Boolean littleEndian) { // log operations which are not supported by current language // specification StringBuffer log; // given language-specification this.currentLanguageSpecification_ = targetLanguage; // get language-specific primitive-types translations (e.g. short, int, // float, boolean // ...) this.currentTypeTranslation_ = currentLanguageSpecification_.getTypesTranslation(); if (this.currentTypeTranslation_ == null) this.currentTypeTranslation_ = new HashMap<Class<?>, String[]>(); // get boolean translation (true, false) this.currentBooleanTranslation_ = currentLanguageSpecification_.getBooleanTranslation(); if (this.currentBooleanTranslation_ == null) this.currentBooleanTranslation_ = new HashMap<Boolean, String>(); // get line comment definition this.lineComment_ = this.currentLanguageSpecification_.getLineCommentToken(); if (this.lineComment_ == null) this.lineComment_ = "/"; this.littleEndian_ = littleEndian; // testfunctions counter, used for function-names short currentTestNumber = 1; // starts with available unit-test libraries for (UnitTestLibrarySpecification uSpec : this.currentLanguageSpecification_.getUnitTestLibraryList()) { this.currentUnitTestLibrary_ = uSpec; // then iterates through arithmetic libraries for (ArithmeticLibrarySpecification aSpec : this.currentLanguageSpecification_ .getArithmeticLibraryList()) { log = new StringBuffer(); this.currentArithmeticLibrary_ = aSpec; // get translations for negative and positive infinity-limits this.currentPositiveInfinityTable_ = this.currentArithmeticLibrary_ .getPositiveInfinityTranslation(); if (this.currentPositiveInfinityTable_ == null) this.currentPositiveInfinityTable_ = new HashMap<Class<?>, String[]>(); this.currentNegativeInfinityTable_ = this.currentArithmeticLibrary_ .getNegativeInfinityTranslation(); if (this.currentNegativeInfinityTable_ == null) this.currentNegativeInfinityTable_ = new HashMap<Class<?>, String[]>(); // add interval translation from arithmetic library this.currentTypeTranslation_.put(Interval.class, aSpec.getIntervalTranslation()); this.currentEmptyIntervalTranslation_ = aSpec.getEmptyIntervalTranslation(); if (this.currentEmptyIntervalTranslation_ == null) this.currentEmptyIntervalTranslation_ = new String[0]; this.currentEntireIntervalTranslation_ = aSpec.getEntireIntervalTranslation(); if (this.currentEntireIntervalTranslation_ == null) this.currentEntireIntervalTranslation_ = new String[0]; // add all operation-translations this.currentOperationsTranslationTable_ = aSpec.getOperationsTranslation(); if (this.currentOperationsTranslationTable_ == null) this.currentOperationsTranslationTable_ = new HashMap<String, String>(); this.currentMixedTypesOperationsTranslationTable_ = aSpec.getMixedTypesOperationsTranslation(); if (this.currentMixedTypesOperationsTranslationTable_ == null) this.currentMixedTypesOperationsTranslationTable_ = new HashMap<String, String>(); // add operations to get lower and upper limit from intervall this.currentOperationsTranslationTable_.put("intervalLowerLimit", aSpec.getIntervalLowerLimit()); this.currentOperationsTranslationTable_.put("intervalUpperLimit", aSpec.getIntervalUpperLimit()); // get main program code-sequence this.currentBuild_ = this.currentLanguageSpecification_.getCodeSequence(); // insert head comment with authors, version and description this.currentBuild_ = replacePlaceHolder(this.currentBuild_, HEAD_COMMENT, this.getHeadComment() + "\n"); // inserts imports and definitions from current // LanguageSpecification-subclass this.currentBuild_ = replacePlaceHolder(this.currentBuild_, LANGUAGE_IMPORTS, this.currentLanguageSpecification_.getImportsAndDefinitions() + "\n"); // inserts imports and definitions from current // ArithmeticLibrarySpecification-subclass this.currentBuild_ = replacePlaceHolder(this.currentBuild_, ARITHMETIC_LIB_IMPORTS, aSpec.getImportsAndDefinitions() + "\n"); // inserts imports and definitions from current // ArithmeticLibrarySpecification-subclass this.currentBuild_ = replacePlaceHolder(this.currentBuild_, TEST_LIB_IMPORTS, uSpec.getImportsAndDefinitions() + "\n\n"); // inserts custom methods from current // LanguageSpecification-subclass this.currentBuild_ = replacePlaceHolder(this.currentBuild_, CUSTOM_METHODS, this.currentLanguageSpecification_.getLanguageCustomMethods() + "\n\n"); // get program code-sequence of test-case-section this.currentBuild_ = replacePlaceHolder(this.currentBuild_, TEST_CASES, uSpec.getCodeSequence() + "\n\n"); // write all test methods into this string String testMethods = ""; // iterate through all given operations Iterator<Operation> operationIterator = this.operations_.getOperations(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); // private Class<?> currentMixedType; // given mixed type this.currentMixedType = operation.getMixedType(); boolean mixed_types = checkOperationForMixType(operation); // testing if operation is implemented if ((this.currentOperationsTranslationTable_.containsKey(operation.getName()) && !mixed_types) || (this.currentMixedTypesOperationsTranslationTable_.containsKey(operation.getName()) && mixed_types)) { // check if recommended operations are marked for generation // elaboate if block for more clarity boolean generateCurrentOp = false; if (operation.isRequired()) { generateCurrentOp = true; } else if (useOptionalOperations && !optionalExceptions.contains(operation.getName())) { generateCurrentOp = true; } else if (!useOptionalOperations && optionalExceptions.contains(operation.getName())) { generateCurrentOp = true; } if (generateCurrentOp) { Set currentSetConfig = operation.getSetRelation(); boolean isNegated = operation.isNegated(); // get raw test-method from unit-test-library testMethods += uSpec.getTestMethod(); // add comment provided by dsl to current operation String operationComments = getOperationComment(operation); testMethods = replacePlaceHolder(testMethods, TEST_CASE_COMMENTS, operationComments); // build test-case name from operations information String testcaseName = TESTCASE + INDEX.format(currentTestNumber++); String operationName = "_" + operation.getName().toLowerCase().replaceAll("[^a-z0-9]", ""); if (!operationName.equals("_")) { testcaseName += operationName; } // get input and output parameter of current // operation List<GenericParameter<?>> input_parameter = operation.getInputList(); List<GenericParameter<?>> output_parameter = operation.getOutputList(); // type declarations defined by current language // specification String declarations = ""; // assert string given by unit-test-library String assertString = ""; // raw operation string by name String function = ""; if (mixed_types) { function = this.currentMixedTypesOperationsTranslationTable_ .get(operation.getName()); } else { function = this.currentOperationsTranslationTable_.get(operation.getName()); } if (function == null) { throw new NullPointerException("function-translation is null!"); } String var_arguments = ""; // declare all input parameter for (int i = 0; i < input_parameter.size(); i++) { GenericParameter<?> input = input_parameter.get(i); String inputName = ""; if (input_parameter.size() < 2) { inputName = "input"; } else { inputName = "input_" + INDEX.format(i + 1); } // add to comment, that input parameter was // defined declarations += this.lineComment_ + " input parameter " + (i + 1) + ":" + "\n"; if (input.hasType(Interval.class)) { Interval<?> interval = (Interval<?>) input.getValue(); if (interval.isEmpty()) { declarations += getNewIntervalString(interval, inputName, true, false); } else if (interval.isEntire()) { declarations += getNewIntervalString(interval, inputName, false, true); } else { declarations += getNewIntervalString(interval, inputName, false, false); } } else { declarations += getParameterString(input, inputName); } if (function.contains(inputName(i + 1))) { function = function.replace(inputName(i + 1), inputName); } else if (function.contains(VAR_ARGS)) { if (function.split(VAR_ARGS).length > 1) { System.err.println("only one variable arguments parameter is possible"); } else { var_arguments += aSpec.getParameterSeparator() + " " + inputName; } } } if (!var_arguments.isEmpty()) { function = function.replace(VAR_ARGS, var_arguments); } else { function = function.replace(VAR_ARGS, ""); } // declare all output parameter for (int i = 0; i < output_parameter.size(); i++) { GenericParameter<?> output = output_parameter.get(i); String expectedOutputName = ""; String outputName = ""; if (output_parameter.size() < 2) { expectedOutputName = "output"; outputName = "lib_output"; } else { expectedOutputName = "output_" + INDEX.format(i + 1); outputName = "lib_output_" + INDEX.format(i + 1); } String type = ""; // add to comment, that output parameter was // defined declarations += this.lineComment_ + " expected output parameter " + (i + 1) + ":" + "\n"; assertString += "\n" + this.lineComment_ + " assert function for output " + (i + 1) + ":"; if (output.hasType(Interval.class)) { Interval<?> interval = (Interval<?>) output.getValue(); // get type translation from current // language-specification type = this.currentTypeTranslation_.get(interval.getTypeClass())[0]; if (interval.isEmpty()) { declarations += getNewIntervalString(interval, expectedOutputName, true, false); } else if (interval.isEntire()) { declarations += getNewIntervalString(interval, expectedOutputName, false, true); } else { declarations += getNewIntervalString(interval, expectedOutputName, false, false); } // get interval translation from current // arithmetic-library-specification String intervalType = this.currentTypeTranslation_ .get(((Interval<?>) output.getValue()).getTypeClass())[0]; if (interval.isEmpty()) { assertString += getAssertFunctionForEmptyInterval(expectedOutputName, outputName, currentSetConfig, isNegated); } else if (interval.isEntire()) { assertString += getAssertFunctionForEntireInterval(expectedOutputName, outputName, currentSetConfig, isNegated); } else { assertString += getAssertFunctionForInterval(intervalType, expectedOutputName, outputName, currentSetConfig, isNegated); } } else { declarations += getParameterString(output, expectedOutputName); type = this.currentTypeTranslation_.get(output.getTypeClass())[0]; assertString += "\n" + getAssertString(expectedOutputName, outputName, null, isNegated); } function = function.replace(outputName(i + 1), outputName); String[] intervalTranslation = this.currentTypeTranslation_ .get(output.getTypeClass()); function = function.replace(outputType(i + 1), intervalTranslation[0].replace(INTERVAL_TYPE, type)); } // insert one test method with current operation // name testMethods = replacePlaceHolder(testMethods, TEST_CASE_NAME, testcaseName); // add comment to current operation function declarations += "\n" + this.lineComment_ + " operation to test: " + operation.getName(); declarations += "\n" + function; testMethods = replacePlaceHolder(testMethods, ARITHMETIC_EVAL, declarations); testMethods = replacePlaceHolder(testMethods, ASSERTS, assertString + "\n"); testMethods += "\n\n"; } } else { String error = ""; if (!mixed_types) { error = "Operation with name: \"" + operation.getName() + "\" is not implemented! \n"; } else { error = "Mixed Type operation with name: \"" + operation.getName() + "\" is not implemented! \n"; } log.append(error); System.err.println(error); } } // insert custom methods from ia-library String arithCustomMethods = this.currentArithmeticLibrary_.getCustomMethods(); if (arithCustomMethods != null) { arithCustomMethods = this.lineComment_ + " Custom methods of IA-Library;\n" + arithCustomMethods + "\n"; this.currentBuild_ = replacePlaceHolder(currentBuild_, ARITHMETIC_CUSTOM_METHODS, arithCustomMethods); } // insert generated testcase-functions this.currentBuild_ = replacePlaceHolder(currentBuild_, DYNAMIC_TEST_METHODS, testMethods); // set up file name String namePlaceholders = this.currentLanguageSpecification_.getOutputFileName(); String outputFileName = ""; String replaceIllegalChras = "[^0-9a-zA-Z]+"; String langExt = this.currentLanguageSpecification_.getExtension(); String langName = this.currentLanguageSpecification_.getOptionName().replaceAll(replaceIllegalChras, ""); langName = Character.toUpperCase(langName.charAt(0)) + langName.substring(1); String unitName = this.currentUnitTestLibrary_.getOptionName().replaceAll(replaceIllegalChras, ""); unitName = Character.toUpperCase(unitName.charAt(0)) + unitName.substring(1); String arithName = this.currentArithmeticLibrary_.getOptionName().replaceAll(replaceIllegalChras, ""); arithName = Character.toUpperCase(arithName.charAt(0)) + arithName.substring(1); if (namePlaceholders != null) { if (!namePlaceholders.trim().isEmpty()) { namePlaceholders = replacePlaceHolder(namePlaceholders, LANGUAGE_SPEC_NAME, langName); namePlaceholders = replacePlaceHolder(namePlaceholders, ARITHMETIC_SPEC_NAME, arithName); namePlaceholders = replacePlaceHolder(namePlaceholders, UNITTEST_SPEC_NAME, unitName); outputFileName = namePlaceholders + "." + langExt; } } // build filename for current language specification if (outputFileName.isEmpty()) { outputFileName = (langName + "_" + unitName + "_" + arithName).toLowerCase() .replaceAll(replaceIllegalChras, "_") + "." + langExt; } this.currentBuild_ = replacePlaceHolder(this.currentBuild_, LANGUAGE_SPEC_NAME, langName); this.currentBuild_ = replacePlaceHolder(this.currentBuild_, ARITHMETIC_SPEC_NAME, arithName); this.currentBuild_ = replacePlaceHolder(this.currentBuild_, UNITTEST_SPEC_NAME, unitName); File outputFile = new File(this.outputFolder_, outputFileName); try { // if old file exists, backup it with current time in // filename if (outputFile.exists()) { backUpOldFile(outputFile); } // write file this.currentFileWriter_ = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(new File(outputFolder_, outputFileName)))); if (log.length() > 2) { this.currentLogWriter_ = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File(outputFolder_, outputFileName + ".log")))); this.currentLogWriter_.write(log.toString()); this.currentLogWriter_.flush(); } this.currentFileWriter_.write(currentBuild_.toString()); this.currentFileWriter_.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } this.currentTypeTranslation_ = currentLanguageSpecification_.getTypesTranslation(); } } try { if (this.currentLogWriter_ != null) { this.currentLogWriter_.close(); } if (this.currentFileWriter_ != null) { this.currentFileWriter_.close(); return true; } } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:com.netspective.commons.text.TextUtils.java
public String fixupTableNameCase(String tableNameOrig) { if (null == tableNameOrig) return null; StringBuffer tableNameBuf = new StringBuffer(tableNameOrig.toLowerCase()); boolean capNext = false; for (int i = 0; i < tableNameBuf.length(); i++) { if (tableNameBuf.charAt(i) == '_') capNext = true;/*from w w w . j a v a 2 s . co m*/ else { if (i == 0 || capNext) { tableNameBuf.setCharAt(i, Character.toUpperCase(tableNameBuf.charAt(i))); capNext = false; } } } return tableNameBuf.toString(); }
From source file:com.aiblockchain.api.StringUtils.java
/** * Changes case of the first character of the string. * * @param string the given string//from www . j a v a 2s. co m * @param isCapitalized whether to capitalize the first character * * @return the transformed string */ private static String changeFirstCharacterCase(final String string, final boolean isCapitalized) { if (string == null || string.length() == 0) { return string; } final StringBuilder stringBuilder = new StringBuilder(string.length()); if (isCapitalized) { stringBuilder.append(Character.toUpperCase(string.charAt(0))); } else { stringBuilder.append(Character.toLowerCase(string.charAt(0))); } stringBuilder.append(string.substring(1)); return stringBuilder.toString(); }
From source file:org.apache.uima.ruta.resource.MultiTreeWordList.java
/** * Returns true, if the MultiTreeWordList contains the string text, false otherwise. * // w w w . j a v a 2 s.c o m * @param pointer * The MultiTextNode we are looking at. * @param text * The string which is contained or not. * @param index * The index of the string text we checked until now. * @param ignoreCase * Indicates whether we search case sensitive or not. * @param fragment * Indicates whether we are looking for a prefix of the string text. * @param ignoreChars * Characters which can be ignored. * @param maxIgnoreChars * Maximum number of characters which are allowed to be ignored. * @return True, if the TreeWordList contains the string text, false otherwise. */ private boolean recursiveContains(MultiTextNode pointer, String text, int index, boolean ignoreCase, boolean fragment, char[] ignoreChars, int maxIgnoreChars) { if (pointer == null) { return false; } if (index == text.length()) { return fragment || pointer.isWordEnd(); } char charAt = text.charAt(index); boolean charAtIgnored = false; if (ignoreChars != null) { for (char each : ignoreChars) { if (each == charAt) { charAtIgnored = true; break; } } charAtIgnored &= index != 0; } int next = ++index; if (ignoreCase) { // Lower Case Node. MultiTextNode childNodeL = pointer.getChildNode(Character.toLowerCase(charAt)); // Upper Case Node. MultiTextNode childNodeU = pointer.getChildNode(Character.toUpperCase(charAt)); if (charAtIgnored && childNodeL == null && childNodeU == null) { // Character is ignored and does not appear. return recursiveContains(pointer, text, next, ignoreCase, fragment, ignoreChars, maxIgnoreChars); } else { // Recursion. return recursiveContains(childNodeL, text, next, ignoreCase, fragment, ignoreChars, maxIgnoreChars) || recursiveContains(childNodeU, text, next, ignoreCase, fragment, ignoreChars, maxIgnoreChars); } } else { // Case sensitive. MultiTextNode childNode = pointer.getChildNode(charAt); if (charAtIgnored && childNode == null) { // Recursion with incremented index. return recursiveContains(pointer, text, next, ignoreCase, fragment, ignoreChars, maxIgnoreChars); } else { // Recursion with new node. return recursiveContains(childNode, text, next, ignoreCase, fragment, ignoreChars, maxIgnoreChars); } } }