List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:edu.lternet.pasta.dml.database.DatabaseAdapter.java
/** * Given an entity name, return a well-formed table name. This is a generic * implementation that should work for most databases. This method should be * overridden by a database adapter subclass if it has special rules for the * well-formedness of a table name. This method simply looks for illegal * table name characters in the entity name and replaces them with underscore * characters./* w w w . jav a2 s . co m*/ * * @param entityName the entity name * @return a well-formed table name corresponding to the entity\ * name */ public static String getLegalDBTableName(String entityName) { final int tableNameMaxLength = getTableNameMaxLength(); String legalName = null; char[] badChars = { ' ', '-', '.', '/', ',', '(', ')', '<', '>' }; char goodChar = '_'; if (entityName != null) { int entityNameLength = entityName.length(); int legalNameLength = Math.min(entityNameLength, tableNameMaxLength); legalName = entityName.substring(0, legalNameLength); } if (legalName != null) { for (int i = 0; i < badChars.length; i++) { legalName = legalName.replace(badChars[i], goodChar); } // If first character is a digit, prepend an underscore char firstCharacter = legalName.charAt(0); if (Character.isDigit(firstCharacter)) { legalName = UNDERSCORE + legalName; } } return legalName; }
From source file:com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpUriRequestInterceptor.java
/** * copy/*from w w w . j av a 2 s.c o m*/ * org.apache.http.client.utils.URIUtils#extractHost(java.net.URI) * @param uri * @return */ private NameIntValuePair<String> extractHost(final URI uri) { if (uri == null) { return null; } NameIntValuePair<String> target = null; if (uri.isAbsolute()) { int port = uri.getPort(); // may be overridden later String host = uri.getHost(); if (host == null) { // normal parse failed; let's do it ourselves // authority does not seem to care about the valid character-set // for host names host = uri.getAuthority(); if (host != null) { // Strip off any leading user credentials int at = host.indexOf('@'); if (at >= 0) { if (host.length() > at + 1) { host = host.substring(at + 1); } else { host = null; // @ on its own } } // Extract the port suffix, if present if (host != null) { int colon = host.indexOf(':'); if (colon >= 0) { int pos = colon + 1; int len = 0; for (int i = pos; i < host.length(); i++) { if (Character.isDigit(host.charAt(i))) { len++; } else { break; } } if (len > 0) { try { port = Integer.parseInt(host.substring(pos, pos + len)); } catch (NumberFormatException ignore) { // skip } } host = host.substring(0, colon); } } } } if (host != null) { target = new NameIntValuePair<String>(host, port); } } return target; }
From source file:cloudeventbus.codec.Decoder.java
@Override public Frame decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { in.markReaderIndex();/*from w ww .j a v a 2 s .co m*/ final int frameLength = indexOf(in, Codec.DELIMITER); // Frame hasn't been fully read yet. if (frameLength < 0) { if (in.readableBytes() > maxMessageSize) { throw new TooLongFrameException("Frame exceeds maximum size"); } in.resetReaderIndex(); return null; } // Empty frame, discard and continue decoding if (frameLength == 0) { in.skipBytes(Codec.DELIMITER.length); return decode(ctx, in); } if (frameLength > maxMessageSize) { throw new TooLongFrameException("Frame exceeds maximum size"); } final String command = in.readBytes(frameLength).toString(CharsetUtil.UTF_8); in.skipBytes(Codec.DELIMITER.length); final String[] parts = command.split("\\s+"); final char frameTypeChar = parts[0].charAt(0); final FrameType frameType = FrameType.getFrameType(frameTypeChar); if (frameType == null) { throw new DecodingException("Invalid frame type " + frameTypeChar); } LOGGER.debug("Decoding frame of type {}", frameType); final int argumentsLength = parts.length - 1; switch (frameType) { case AUTH_RESPONSE: assertArgumentsLength(3, argumentsLength, "authentication response"); final CertificateChain certificates = new CertificateChain(); final byte[] rawCertificates = Base64.decodeBase64(parts[1].getBytes()); CertificateStoreLoader.load(new ByteArrayInputStream(rawCertificates), certificates); final byte[] salt = Base64.decodeBase64(parts[2]); final byte[] digitalSignature = Base64.decodeBase64(parts[3]); return new AuthenticationResponseFrame(certificates, salt, digitalSignature); case AUTHENTICATE: assertArgumentsLength(1, argumentsLength, "authentication request"); final byte[] challenge = Base64.decodeBase64(parts[1]); return new AuthenticationRequestFrame(challenge); case ERROR: if (parts.length == 0) { throw new DecodingException("Error is missing error code"); } final Integer errorNumber = Integer.valueOf(parts[1]); final ErrorFrame.Code errorCode = ErrorFrame.Code.lookupCode(errorNumber); int messageIndex = 1; messageIndex = skipWhiteSpace(messageIndex, command); while (messageIndex < command.length() && Character.isDigit(command.charAt(messageIndex))) { messageIndex++; } messageIndex = skipWhiteSpace(messageIndex, command); final String errorMessage = command.substring(messageIndex).trim(); if (errorMessage.length() > 0) { return new ErrorFrame(errorCode, errorMessage); } else { return new ErrorFrame(errorCode); } case GREETING: assertArgumentsLength(3, argumentsLength, "greeting"); final int version = Integer.valueOf(parts[1]); final String agent = parts[2]; final long id = Long.valueOf(parts[3]); return new GreetingFrame(version, agent, id); case PING: return PingFrame.PING; case PONG: return PongFrame.PONG; case PUBLISH: if (argumentsLength < 2 || argumentsLength > 3) { throw new DecodingException( "Expected message frame to have 2 or 3 arguments. It has " + argumentsLength + "."); } final String messageSubject = parts[1]; final String replySubject; final Integer messageLength; if (parts.length == 3) { replySubject = null; messageLength = Integer.valueOf(parts[2]); } else { replySubject = parts[2]; messageLength = Integer.valueOf(parts[3]); } if (in.readableBytes() < messageLength + Codec.DELIMITER.length) { // If we haven't received the entire message body (plus the CRLF), wait until it arrives. in.resetReaderIndex(); return null; } final ByteBuf messageBytes = in.readBytes(messageLength); final String messageBody = new String(messageBytes.array(), CharsetUtil.UTF_8); in.skipBytes(Codec.DELIMITER.length); // Ignore the CRLF after the message body. return new PublishFrame(new Subject(messageSubject), replySubject == null ? null : new Subject(replySubject), messageBody); case SERVER_READY: return ServerReadyFrame.SERVER_READY; case SUBSCRIBE: assertArgumentsLength(1, argumentsLength, "subscribe"); return new SubscribeFrame(new Subject(parts[1])); case UNSUBSCRIBE: assertArgumentsLength(1, argumentsLength, "unsubscribe"); return new UnsubscribeFrame(new Subject(parts[1])); default: throw new DecodingException("Unknown frame type " + frameType); } }
From source file:ca.mcgill.cs.creco.logic.ConcreteServiceFacade.java
@Override public String getCompletions(String pInput) { if (pInput.length() <= MIN_NUMBER_OF_TYPED_LETTERS) { return ""; }/*from ww w. j av a 2 s.c o m*/ String[] result_set = new String[100]; int pointer = 0; String temp = new String(""); int index = 0; JSONArray response = new JSONArray(); JSONObject obj = new JSONObject(); for (Category category : aDataStore.getCategories()) { if (category.getNumberOfProducts() == 0) { continue; } if (category.getName().toLowerCase().contains(pInput.toLowerCase())) { result_set[pointer++] = category.getName().toLowerCase(); result_set[pointer++] = "Category"; } } Set<String> collectedbrandstillnow = new HashSet<String>(); Set<String> collectedtexttillnow = new HashSet<String>(); Set<String> brands = new HashSet<String>(); Set<String> textSearch = new HashSet<String>(); for (Product productname : aDataStore.getProducts()) { if (productname.getName().toLowerCase().contains(pInput.toLowerCase())) { for (String productspace : productname.getName().toLowerCase().split(" ")) { if (productspace.contains(pInput.toLowerCase())) { if (productspace.equals(productname.getBrandName().toLowerCase())) { if (collectedbrandstillnow.contains(productspace)) { } else { collectedbrandstillnow.add(productspace); brands.add(productspace); } } else if (collectedtexttillnow.contains(productspace) || collectedbrandstillnow.contains(productspace)) { } else { collectedtexttillnow.add(productspace); int count = 0; for (int i = 0; i < productspace.length(); i++) { if (Character.isDigit(productspace.charAt(i))) { count++; } } if (count < 2 && !productspace.contains("(") && !productspace.contains(")")) { textSearch.add(productspace); } } } } } } for (String brandname : brands) { if (Arrays.asList(result_set).contains(brandname)) { index = Arrays.asList(result_set).indexOf(brandname); result_set[index + 1] = result_set[index + 1].concat("|Brand"); temp = result_set[0]; result_set[0] = result_set[index]; result_set[index] = temp; temp = result_set[1]; result_set[1] = result_set[index + 1]; result_set[index + 1] = temp; } else { result_set[pointer++] = brandname; result_set[pointer++] = "Brand"; } } for (String textname : textSearch) { if (Arrays.asList(result_set).contains(textname)) { index = Arrays.asList(result_set).indexOf(textname); result_set[index + 1] = result_set[index + 1].concat("|Product"); temp = result_set[0]; result_set[0] = result_set[index]; result_set[index] = temp; temp = result_set[1]; result_set[1] = result_set[index + 1]; result_set[index + 1] = temp; } else { result_set[pointer++] = textname; result_set[pointer++] = "Product"; } } for (index = 0; index < result_set.length; index = index + 2) { obj.put("name", result_set[index]); obj.put("type", result_set[index + 1]); response.add(obj); obj = new JSONObject(); } return response.toJSONString(); }
From source file:edu.illinois.cs.cogcomp.edison.features.lrec.TestWordTypeInformation.java
public final void test() throws EdisonException { log.debug("WordTypeInformation"); // Using the first TA and a constituent between span of 0 - 20 as a test TextAnnotation ta = tas.get(1);/*from ww w . j av a 2 s. c o m*/ View TOKENS = ta.getView("TOKENS"); log.debug("GOT TOKENS FROM TEXTAnn"); List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20); String[] teststrings = new String[5]; int i = 0, start = 1, end = 6; for (Constituent c : testlist) { log.debug(c.getSurfaceForm()); if (i >= start && i < end) { teststrings[i - start] = c.getSurfaceForm(); } i++; } log.debug("Testlist size is " + testlist.size()); Constituent test = testlist.get(3); log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm()); WordTypeInformation wti = new WordTypeInformation("WordTypeInformation"); log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan()); Set<Feature> feats = wti.getFeatures(test); String[] expected_outputs = { "WordTypeInformation:c0(false)", "WordTypeInformation:d0(false)", "WordTypeInformation:c1(false)", "WordTypeInformation:d1(false)", "WordTypeInformation:c2(false)", "WordTypeInformation:d2(false)", "WordTypeInformation:c2(true)", "WordTypeInformation:c3(false)", "WordTypeInformation:d3(false)", "WordTypeInformation:c4(false)", "WordTypeInformation:d4(false)", "WordTypeInformation:c4(true)" }; Set<String> __result = new LinkedHashSet<String>(); String __id; String __value; String classifier = "WordTypeInformation"; if (feats == null) { log.debug("Feats are returning NULL."); assertFalse(true); } log.debug("Printing Set of Features"); for (Feature f : feats) { log.debug(f.getName()); assert (ArrayUtils.contains(expected_outputs, f.getName())); } for (; (start < end && teststrings[start - 1] != null); start++) { boolean allCapitalized = true, allDigits = true, allNonLetters = true; for (int j = 0; j < teststrings[start - 1].length(); ++j) { allCapitalized &= Character.isUpperCase(teststrings[start - 1].charAt(j)); allDigits &= Character.isDigit(teststrings[start - 1].charAt(j)); allNonLetters &= !Character.isLetter(teststrings[start - 1].charAt(j)); } __id = classifier + ":" + ("c" + (start - 1)); __value = "(" + (allCapitalized) + ")"; __result.add(__id + __value); __id = classifier + ":" + ("d" + (start - 1)); __value = "(" + (allDigits) + ")"; __result.add(__id + __value); __id = classifier + ":" + ("c" + (start - 1)); __value = "(" + (allNonLetters) + ")"; __result.add(__id + __value); } for (Feature feat : feats) { if (!__result.contains(feat.getName())) { assertFalse(true); } } // System.exit(0); }
From source file:com.redhat.smonkey.RndDate.java
private Date applyDiff(Date base, String diff, boolean neg) { cal.setTime(base);//from w w w .java 2 s . c om StringBuilder bld = new StringBuilder(); int value = 0; String unit; int state = 0; boolean done = false; int calfield; for (int i = 0; i < diff.length() && !done; i++) { char c = diff.charAt(i); switch (state) { case 0: if (Character.isSpace(c)) ; else if (Character.isDigit(c)) { bld.append(c); state = 1; } else throw new RuntimeException("Bad expression:" + diff); break; case 1: if (Character.isDigit(c)) { bld.append(c); } else if (Character.isSpace(c)) { state = 2; value = Integer.valueOf(bld.toString()); bld = new StringBuilder(); } else { state = 3; value = Integer.valueOf(bld.toString()); bld = new StringBuilder(); bld.append(c); } break; case 2: if (!Character.isSpace(c)) { state = 3; bld.append(c); } break; case 3: if (!Character.isSpace(c)) { bld.append(c); } else done = true; break; } } if (state == 2 || state == 3) { unit = bld.toString(); if ("sec".equals(unit)) { calfield = Calendar.SECOND; } else if ("min".equals(unit)) { calfield = Calendar.MINUTE; } else if ("hr".equals(unit)) { calfield = Calendar.HOUR_OF_DAY; } else if ("d".equals(unit)) { calfield = Calendar.DAY_OF_MONTH; } else if ("m".equals(unit)) { calfield = Calendar.MONTH; } else if ("y".equals(unit)) { calfield = Calendar.YEAR; } else throw new RuntimeException("Bad expression:" + diff); } else throw new RuntimeException("Bad expression:" + diff); cal.add(calfield, neg ? -value : value); return cal.getTime(); }
From source file:TestStore.java
private void dumpRecord(byte[] data, int size, PrintStream out, StringBuffer hexLine, StringBuffer charLine, int maxLen) { if (size == 0) return;//from ww w . j ava 2 s .c o m hexLine.setLength(0); charLine.setLength(0); int count = 0; for (int i = 0; i < size; ++i) { char b = (char) (data[i] & 0xFF); if (b < 0x10) { hexLine.append('0'); } hexLine.append(Integer.toHexString(b)); hexLine.append(' '); if ((b >= 32 && b <= 127) || Character.isDigit(b) || Character.isLowerCase(b) || Character.isUpperCase(b)) { charLine.append((char) b); } else { charLine.append('.'); } if (++count >= maxLen || i == size - 1) { while (count++ < maxLen) { hexLine.append(" "); } hexLine.append(' '); hexLine.append(charLine.toString()); out.println(hexLine.toString()); hexLine.setLength(0); charLine.setLength(0); count = 0; } } }
From source file:eu.trentorise.smartcampus.geocoder.manager.OSMGeocoder.java
private String parseAddress(String address) throws UnsupportedEncodingException { String q = ""; String[] tokens = address.split(","); String[] subtokens = tokens[0].split(" "); String nq = "name:(", sq = "street:("; for (String subtoken : subtokens) { nq += " +" + subtoken.trim(); sq += " +" + subtoken.trim(); }// w ww .j a v a 2s.c o m nq += ")"; sq += ")"; q += "+(" + nq + " OR " + sq + ") "; if (tokens.length >= 3 && tokens[1] != null && tokens[1].trim().length() > 0) { q += "+housenumber:" + tokens[1].trim() + " "; } if (tokens.length == 2 && tokens[1] != null && tokens[1].trim().length() > 0) { if (Character.isDigit(tokens[1].trim().toCharArray()[0])) { q += "+housenumber:" + tokens[1].trim() + " "; } else { q += "+city:" + tokens[1].trim() + " "; } } if (tokens.length >= 3 && tokens[2] != null && tokens[2].trim().length() > 0) { q += "+city:" + tokens[2].trim() + " "; } return q; }
From source file:com.github.stagirs.lingvo.build.Xml2Plain.java
private static List<Attr> fillAttributes(List<Attr> list, Matcher attrMatcher) { while (attrMatcher.find()) { String attr = attrMatcher.group(1).replace("-", "_"); if (Character.isDigit(attr.charAt(0))) { attr = "N" + attr; }/*from ww w . j a va2 s . c om*/ if (attr.toLowerCase().equals("ms_f")) { if (list.contains(Attr.femn)) { list.remove(Attr.femn); } if (list.contains(Attr.masc)) { list.remove(Attr.masc); } if (list.contains(Attr.neut)) { list.remove(Attr.neut); } if (list.contains(Attr.GNdr)) { list.remove(Attr.GNdr); } list.add(ms_f); continue; } Attr attrVal = Attr.valueOf(attr); if (attrVal == Attr.inan && list.contains(Attr.anim)) { continue; } if (attrVal == Attr.anim && list.contains(Attr.inan)) { list.remove(Attr.inan); } if (attrVal == Attr.femn || attrVal == Attr.masc || attrVal == Attr.neut || attrVal == Attr.GNdr) { if (list.contains(ms_f)) { continue; } } if (attrVal == Attr.loc1 || attrVal == Attr.loc2) { attrVal = Attr.loct; } if (attrVal == Attr.gent || attrVal == Attr.gen1 || attrVal == Attr.gen2) { if (list.get(0) == Attr.ADJS) { continue; } attrVal = Attr.gent; } if (attrVal == Attr.acc2) { attrVal = Attr.accs; } if (attrVal.getType() == Type.Other) { continue; } list.add(attrVal); } if (list.contains(Attr.Name) || list.contains(Attr.Surn) || list.contains(Attr.Patr)) { list.remove(Attr.inan); if (!list.contains(Attr.anim)) { list.add(Attr.anim); } } if (list.contains(Attr.VERB) && list.contains(Attr.Impe) && list.contains(Attr.neut)) { list.remove(Attr.neut); } return list; }
From source file:gov.nih.nci.evs.browser.utils.CodeSearchUtils.java
public String findBestContainsAlgorithm(String matchText) { if (matchText == null) return "nonLeadingWildcardLiteralSubString"; matchText = matchText.trim();/*from w w w. j a v a 2s .c om*/ if (matchText.length() == 0) return "nonLeadingWildcardLiteralSubString"; // or null if (matchText.length() > 1) return "nonLeadingWildcardLiteralSubString"; char ch = matchText.charAt(0); if (Character.isDigit(ch)) return "literal"; else if (Character.isLetter(ch)) return "LuceneQuery"; else return "literalContains"; }