List of usage examples for java.lang CharSequence length
int length();
From source file:cn.edu.zjnu.acm.judge.security.password.LengthLimitedPasswordEncoder.java
private CharSequence limit(CharSequence orignPassword) { return orignPassword == null || orignPassword.length() <= length ? orignPassword : orignPassword.subSequence(0, length); }
From source file:ru.jts_dev.common.packets.OutgoingMessageWrapper.java
protected final void writeString(final CharSequence cs) { for (int i = 0; i < cs.length(); i++) { buffer.writeChar(cs.charAt(i));// w ww . j a v a2s . com } buffer.writeChar(EOS); }
From source file:dkpro.similarity.algorithms.lexical.string.LevenshteinComparator.java
private int computeLevenshteinDistance(CharSequence str1, CharSequence str2) { int[][] distance = new int[str1.length() + 1][str2.length() + 1]; for (int i = 0; i <= str1.length(); i++) { distance[i][0] = i;/*from w w w . j a v a2 s . co m*/ } for (int j = 0; j <= str2.length(); j++) { distance[0][j] = j; } for (int i = 1; i <= str1.length(); i++) { for (int j = 1; j <= str2.length(); j++) { distance[i][j] = minimum(distance[i - 1][j] + 1, distance[i][j - 1] + 1, distance[i - 1][j - 1] + ((str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0 : 1)); } } return distance[str1.length()][str2.length()]; }
From source file:com.nesscomputing.mojo.numbers.NumberField.java
private boolean isNumber(final CharSequence c) { for (int i = 0; i < c.length(); i++) { if (!Character.isDigit(c.charAt(i))) { return false; }//from w w w . j a v a 2 s.c om } return true; }
From source file:cn.remex.core.util.StringUtils.java
/** * ??null?0??true/* w ww . j a v a 2 s. c o m*/ * Check that the given CharSequence is neither <code>null</code> nor of length 0. * Note: Will return <code>true</code> for a CharSequence that purely consists of whitespace. * <p><pre> * StringUtils.hasLength(null) = false * StringUtils.hasLength("") = false * StringUtils.hasLength(" ") = true * StringUtils.hasLength("Hello") = true * </pre> * @param str the CharSequence to check (may be <code>null</code>) ? * @return <code>true</code> if the CharSequence is not null and has length ??0 true * @see #hasText(String) */ public static boolean hasLength(final CharSequence str) { return str != null && str.length() > 0; }
From source file:cn.remex.core.util.StringUtils.java
/** * ???????/*from w w w .j a v a2 s. co m*/ * Test whether the given string matches the given substring * at the given param. * @param str the original string (or StringBuffer) ? * @param index the param in the original string to start matching against ? * @param substring the substring to match at the given param ?? */ public static boolean substringMatch(final CharSequence str, final int index, final CharSequence substring) { for (int j = 0; j < substring.length(); j++) { int i = index + j; if (i >= str.length() || str.charAt(i) != substring.charAt(j)) { return false; } } return true; }
From source file:com.stratio.ingestion.serializer.elasticsearch.ElasticSearchSerializerWithMappingTest.java
private boolean hasLength(CharSequence str) { return (str != null && str.length() > 0); }
From source file:org.esigate.parser.ParserContextImpl.java
/** Writes characters into current writer. */ public void characters(CharSequence cs) throws IOException { characters(cs, 0, cs.length()); }
From source file:$.MyValidator.java
public boolean isEmailValid(CharSequence value) { if (value == null || value.length() == 0) { return true; }//from w w w. jav a2 s. co m // split email at '@' and consider local and domain part separately; // note a split limit of 3 is used as it causes all characters following // to an (illegal) second @ character to // be put into a separate array element, avoiding the regex application // in this case since the resulting array // has more than 2 elements String[] emailParts = value.toString().split("@", 3); if (emailParts.length != 2) { return false; } // if we have a trailing dot in local or domain part we have an invalid // email address. // the regular expression match would take care of this, but IDN.toASCII // drops trailing the trailing '.' // (imo a bug in the implementation) if (emailParts[0].endsWith(".") || emailParts[1].endsWith(".")) { return false; } if (!matchPart(emailParts[0], localEmailPattern)) { return false; } return matchPart(emailParts[1], emailDomainPattern); }