List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.gradle.model.internal.manage.schema.extraction.ModelSchemaExtractor.java
public <T> ModelSchema<T> extract(Class<T> type) throws InvalidManagedModelElementTypeException { validateType(type);//from ww w. jav a 2s .com List<Method> methodList = Arrays.asList(type.getDeclaredMethods()); if (methodList.isEmpty()) { return new ModelSchema<T>(type, Collections.<ModelProperty<?>>emptyList()); } List<ModelProperty<?>> properties = Lists.newLinkedList(); Map<String, Method> methods = Maps.newHashMap(); for (Method method : methodList) { String name = method.getName(); if (methods.containsKey(name)) { throw invalidMethod(type, name, "overloaded methods are not supported"); } methods.put(name, method); } List<String> methodNames = Lists.newLinkedList(methods.keySet()); List<String> handled = Lists.newArrayList(); for (ListIterator<String> iterator = methodNames.listIterator(); iterator.hasNext();) { String methodName = iterator.next(); Method method = methods.get(methodName); if (methodName.startsWith("get") && !methodName.equals("get")) { if (method.getParameterTypes().length != 0) { throw invalidMethod(type, methodName, "getter methods cannot take parameters"); } Character getterPropertyNameFirstChar = methodName.charAt(3); if (!Character.isUpperCase(getterPropertyNameFirstChar)) { throw invalidMethod(type, methodName, "the 4th character of the getter method name must be an uppercase character"); } Class<?> returnType = method.getReturnType(); ModelType<?> returnModelType = ModelType.of(returnType); if (returnType.equals(String.class)) { properties.add(extractNonManagedProperty(type, methods, methodName, returnModelType, handled)); } else if (isManaged(returnType)) { properties.add(extractManagedProperty(type, methods, methodName, returnModelType, handled)); } else { throw invalidMethod(type, methodName, "only String and managed properties are supported"); } iterator.remove(); } } methodNames.removeAll(handled); // TODO - should call out valid getters without setters if (!methodNames.isEmpty()) { throw invalid(type, "only paired getter/setter methods are supported (invalid methods: [" + Joiner.on(", ").join(methodNames) + "])"); } return new ModelSchema<T>(type, properties); }
From source file:org.intermine.task.DynamicAttributeTask.java
/** * Look at set methods on a target object and lookup values in project * properties. If no value found property will not be set but no error * will be thrown.//w w w .j a v a 2 s . c om * @param bean an object to search for setter methods */ protected void configureDynamicAttributes(Object bean) { Project antProject = getProject(); Hashtable<?, ?> projectProps = antProject.getProperties(); PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(bean); for (int i = 0; i < props.length; i++) { PropertyDescriptor desc = props[i]; Method setter = desc.getWriteMethod(); if (setter != null) { Class<?> propType = desc.getPropertyType(); String propName = setter.getName().substring(3).toLowerCase(); Object propValue = projectProps.get(propName); if (propValue == null) { // there is not all-lowercase property in projectProps, so try the camelCase // version String setterName = setter.getName(); String camelCasePropName = setterName.substring(3, 4).toLowerCase() + setterName.substring(4); propName = camelCasePropName; propValue = projectProps.get(camelCasePropName); } if (propValue == null) { // still not found, try replacing each capital (after first) in camelCase // to be a dot - i.e. setSrcDataDir -> src.data.dir String setterName = setter.getName(); String camelCasePropName = setterName.substring(3, 4).toLowerCase() + setterName.substring(4); String dotName = ""; for (int j = 0; j < camelCasePropName.length(); j++) { if (Character.isUpperCase(camelCasePropName.charAt(j))) { dotName += "." + camelCasePropName.substring(j, j + 1).toLowerCase(); } else { dotName += camelCasePropName.substring(j, j + 1); } } propValue = projectProps.get(dotName); } if (propValue != null) { try { if (propType.equals(File.class)) { String filePropValue = (String) propValue; //First check to see if we were given a complete file path, if so then // we can use it directly instead of trying to search for it. File maybeFile = new File(filePropValue); if (maybeFile.exists()) { propValue = maybeFile; LOG.info("Configuring task to use file:" + filePropValue); } else { propValue = getProject().resolveFile(filePropValue); } } PropertyUtils.setProperty(bean, propName, propValue); } catch (Exception e) { throw new BuildException( "failed to set value for " + propName + " to " + propValue + " in " + bean, e); } } } } }
From source file:org.nextframework.util.StringUtils.java
/** * Separa as palavras da string toda vez que trocar o case * @param string//from w w w. ja v a2 s . c om * @return */ public String separateOnCase(String string) { if (string.length() <= 1) { return string; } char[] toCharArray = string.substring(1).toCharArray(); StringBuilder builder = new StringBuilder(); builder.append(string.charAt(0)); for (char c : toCharArray) { if (Character.isUpperCase(c)) { builder.append(" "); } builder.append(c); } return builder.toString(); }
From source file:de.micromata.genome.gwiki.plugin.wikilink_1_0.GWikiWikiLinkFragment.java
public static GWikiFragment parseText(GWikiFragmentText textFrag) { String text = textFrag.getSource(); ParseState state = ParseState.Start; int startLink = 0; GWikiFragmentChildContainer fcc = new GWikiFragmentChildContainer(); boolean startWord = true; for (int i = 0; i < text.length(); ++i) { char c = text.charAt(i); switch (state) { case Start: boolean ws = Character.isWhitespace(c); if (ws == true || Character.isLetter(c) == false) { // addTextFrag(fcc, text.substring(startLink, i)); // startLink = i; startWord = ws;//from ww w . ja v a 2s . co m continue; } if (startWord == true && Character.isUpperCase(c) == true) { if (startLink != i) { addTextFrag(fcc, text.substring(startLink, i)); } startLink = i; state = ParseState.InWikiLink; break; } startWord = ws; break; case InWikiLink: if (Character.isLetter(c) == false) { String k = text.substring(startLink, i); if (isWikiLinkWord(k) == true) { fcc.addChild(new GWikiWikiLinkFragment(k)); } else { addTextFrag(fcc, k); } startLink = i; state = ParseState.Start; } break; } } if (startLink < text.length()) { String k = text.substring(startLink); if (state == ParseState.InWikiLink && isWikiLinkWord(k) == true) { fcc.addChild(new GWikiWikiLinkFragment(k)); } else { addTextFrag(fcc, k); } } return unfoldParsed(fcc); }
From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java
public static TrimStats getStats(Sequence seq, int trimStart, int trimStop) { if (trimStart >= trimStop) { throw new IllegalArgumentException("Trim start has to come before trim end"); }// w ww .j a va 2 s .c om TrimStats ret = new TrimStats(); int modelPos = 0; int seqPos = 0; int index; int filled = 0; char b; boolean ischar, isgap, ismodel, isupper, intrim; int alnStart = -1; char[] bases = seq.getSeqString().toCharArray(); for (index = 0; index < bases.length; index++) { b = bases[index]; ischar = Character.isLetter(b); isupper = ischar && Character.isUpperCase(b); isgap = !ischar && (b == '.' || b == '~' || b == '-'); ismodel = (b == '-') || isupper; intrim = (modelPos >= trimStart && modelPos < trimStop); if (ischar) { seqPos++; if (b == 'n' || b == 'N') { ret.numNs++; if (intrim) { ret.nsInTrim++; } } if (intrim) { ret.trimmedLength++; } } if (ismodel) { if (modelPos == trimStart) { ret.seqTrimStart = seqPos; alnStart = index; } if (modelPos >= trimStart && modelPos < trimStop) { filled++; if (ischar) { ret.filledRatio++; } } if (modelPos == trimStop) { ret.seqTrimStop = seqPos; ret.trimmedBases = Arrays.copyOfRange(bases, alnStart, index); } if (!isgap) { if (ret.seqStart == -1) { ret.seqStart = modelPos; } ret.seqStop = modelPos; } modelPos++; } } ret.seqLength = seqPos; ret.modelLength = modelPos; ret.filledRatio /= filled; return ret; }
From source file:com.slimsmart.common.util.code.EncodeUtil.java
public static String escape(String src) { int i;//from www .j a va 2 s. c om char j; StringBuffer tmp = new StringBuffer(); tmp.ensureCapacity(src.length() * 6); for (i = 0; i < src.length(); i++) { j = src.charAt(i); if (Character.isDigit(j) || Character.isLowerCase(j) || Character.isUpperCase(j)) tmp.append(j); else if (j < 256) { tmp.append("%"); if (j < 16) tmp.append("0"); tmp.append(Integer.toString(j, 16)); } else { tmp.append("%u"); tmp.append(Integer.toString(j, 16)); } } return tmp.toString(); }
From source file:com.acuityph.commons.util.ClassUtils.java
/** * @param methodName/*from w w w . ja v a2 s. co m*/ * the method name to check * @return true if the given method name matches a property getter pattern */ private static boolean isPropertyGetterName(final String methodName) { return hasLength(methodName) && methodName.length() > 3 && methodName.startsWith("get") && Character.isUpperCase(methodName.charAt(3)); }
From source file:com.labtk.biology.punnett.MonohybridPunnettSquare.java
/** * Monohybrid Punnett Square Builder. This takes the 2 parent strings, * something similar to "Aa" and "aa". It performs the genetic cross, then * builds the fancy table.// w w w. j ava 2 s . c o m * @param p1_string First Parental Genotype * @param p2_string Second Parental Genotyoe * @return Fancy Monohybrid Punnett Square. */ public String GetPunnettSquare(String p1_string, String p2_string) { //Check parental data for violations if (p1_string.length() != 2) { return "Invalid Length on Parent 1!"; } if (p2_string.length() != 2) { return "Invalid Length on Parent 2!"; } //Determine Gametes Character[] p1 = ArrayUtils.toObject(p1_string.toCharArray()); Character[] p2 = ArrayUtils.toObject(p2_string.toCharArray()); //Set up offspring ArrayList<Character[]> offspring = new ArrayList<>(); //Perform genetic cross for (Character allele : p1) { for (Character allele2 : p2) { Character[] geneArray = { allele2, allele }; offspring.add(geneArray); } } //Prepare StringBuilder and Iterator StringBuilder sb = new StringBuilder(); int myIter = 0; //Build the tabletop String tt = CreateTableTop(p1); sb.append(tt); //Output Offspring for (Character[] child : offspring) { if (myIter % 2 == 0) { sb.append('\n'); sb.append(p2[myIter / 2]); sb.append('|'); } if (!Character.isUpperCase(child[0]) && Character.isUpperCase(child[1])) { sb.append(child[1]); sb.append(child[0]); } else { sb.append(child[0]); sb.append(child[1]); } sb.append('|'); myIter++; } //Get any leftover out return sb.toString(); }
From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java
/** * Encodes a field name in Java notation (e.g. myFieldName) to an XML field name (e.g. my-field-name). *///from www . ja v a2 s .co m private final String encodeFieldName(final String pFieldName) { StringBuilder str = new StringBuilder(); int fieldNameLength = pFieldName.length(); char currentChar; for (int i = 0; i != fieldNameLength; i++) { currentChar = pFieldName.charAt(i); if (Character.isUpperCase(currentChar)) { str.append('-'); str.append(Character.toLowerCase(currentChar)); } else { str.append(currentChar); } } return str.toString(); }
From source file:com.emc.ecs.sync.config.ConfigUtil.java
public static String hyphenate(String name) { StringBuilder hyphenated = new StringBuilder(); for (char c : name.toCharArray()) { if (Character.isUpperCase(c) && hyphenated.length() > 0) hyphenated.append('-'); hyphenated.append(Character.toLowerCase(c)); }/* w w w .j a v a 2s . c o m*/ return hyphenated.toString(); }