private static boolean isWhitespace(String text) {
    if (text == null) return true;

    boolean isWhitespace = true;

    for (int i = text.length() - 1; i >= 0; i--) {
      char ch = text.charAt(i);

      if (!Character.isWhitespace(ch)) {
        // check for comment
        if (ch == '>' && text.indexOf("-->") + 2 == i) {
          int head = text.indexOf("<!--");

          if (head >= 0) {
            for (int j = 0; j < head; j++) {
              if (!Character.isWhitespace(text.charAt(j))) {
                return false;
              }
            }

            return true;
          }
        }

        return false;
      }
    }

    return true;
  }
Ejemplo n.º 2
0
  private String toJavaName(String name, boolean firstLetterIsUpperCase) {

    name = name.toLowerCase();

    StringBuffer res = new StringBuffer();

    boolean nextIsUpperCase = firstLetterIsUpperCase;

    for (int i = 0; i < name.length(); i++) {
      char c = name.charAt(i);

      if (nextIsUpperCase) {
        c = Character.toUpperCase(c);
      }

      if (Character.isLetter(c)) {
        res.append(c);
        nextIsUpperCase = false;
      } else {
        nextIsUpperCase = true;
      }
    }

    return res.toString();
  }
Ejemplo n.º 3
0
  /**
   * Logically casts input to UTF32 ints then looks up the output or null if the input is not
   * accepted. FST must be INPUT_TYPE.BYTE4.
   */
  public static <T> T get(FST<T> fst, CharSequence input) throws IOException {
    assert fst.inputType == FST.INPUT_TYPE.BYTE4;

    // TODO: would be nice not to alloc this on every lookup
    final FST.Arc<T> arc = fst.getFirstArc(new FST.Arc<T>());

    int charIdx = 0;
    final int charLimit = input.length();

    // Accumulate output as we go
    final T NO_OUTPUT = fst.outputs.getNoOutput();
    T output = NO_OUTPUT;

    while (charIdx < charLimit) {
      final int utf32 = Character.codePointAt(input, charIdx);
      charIdx += Character.charCount(utf32);

      if (fst.findTargetArc(utf32, arc, arc) == null) {
        return null;
      } else if (arc.output != NO_OUTPUT) {
        output = fst.outputs.add(output, arc.output);
      }
    }

    if (fst.findTargetArc(FST.END_LABEL, arc, arc) == null) {
      return null;
    } else if (arc.output != NO_OUTPUT) {
      return fst.outputs.add(output, arc.output);
    } else {
      return output;
    }
  }
Ejemplo n.º 4
0
  /**
   * Replaces any empty tokens by a null token. Eg if the given delimiter
   * is ; the row
   * <P><PRE>data1;data2;;data4;
   *
   * <P>will be transformed to
   *
   * <P>data1;data2;\0;data4;\0
   *
   * @param fileRow The row to repace tokens on.
   * @param fieldDelimiter The field delimiter.
   * @return A "fixed" version of the given row.
   */
  public static String replaceEmptyTokens(String fileRow, Character fieldDelimiter) {
    // Define the empty token and the null token
    String aEmptyToken = fieldDelimiter.toString() + fieldDelimiter.toString();
    String aNullToken = fieldDelimiter.toString() + "\0" + fieldDelimiter.toString();

    // If last token is empty (ie, last char is the field delimiter),
    // append a null char at the end of the row
    if (fileRow.substring(fileRow.length() - 1).equalsIgnoreCase(fieldDelimiter.toString())) {
      fileRow = fileRow + "\0";
    }

    // Copy data to a buffer so it can be modified. Then find the
    // position of the first empty token
    StringBuffer fileRowAsBuffer = new StringBuffer(fileRow);
    int aTokenPos = fileRow.indexOf(aEmptyToken);

    // While there are empty tokens
    while (aTokenPos > -1) {
      // Replace the empty token with a null token
      fileRowAsBuffer.replace(aTokenPos, aTokenPos + 2, aNullToken);

      // Copyt data back to string and look for more empty tokens
      fileRow = fileRowAsBuffer.toString();
      aTokenPos = fileRow.indexOf(aEmptyToken);
    }
    return fileRow;
  }
Ejemplo n.º 5
0
 public static boolean isFormat(String str, String... format) {
   if (str.length() == 0) return format.length == 1 && format[0].equals("");
   char[] charset = str.toCharArray();
   int c = 0;
   for (int i = 0; i < format.length; i++) {
     String form = format[i];
     if (form.equals(NUMBERS)) {
       if (c >= charset.length) return false;
       if (!Character.isDigit(charset[c])) {
         if (charset[c] == '.') {
           if (c + 1 >= charset.length || !Character.isDigit(charset[c + 1])) return false;
         } else return false;
       }
       while (c < charset.length - 1
           && (Character.isDigit(charset[c + 1]) || charset[c + 1] == '.')) c++;
       c++;
     } else if (form.equals(LETTERS)) {
       if (c >= charset.length || !Character.isLetter(charset[c])) return false;
       while (c < charset.length - 1 && Character.isLetter(charset[c + 1])) c++;
       c++;
     } else {
       char[] formchars = form.toCharArray();
       if (formchars.length > charset.length - c) return false;
       for (int ch = 0; ch < formchars.length; ch++) {
         if (formchars[ch] != charset[c]) return false;
         c++;
       }
     }
   }
   return c == charset.length;
 }
Ejemplo n.º 6
0
  public int encounter(Character other) {
    say("You have encountered " + other);
    delay(2000);
    say("His status is:\n" + other.getStatus2());
    delay(2000);

    while (this.health > 0 && other.health > 0) {
      say("Press 1 if you wish to talk.");
      say("Press 2 if you wish to attempt to flee.");
      say("Press 3 if you wish to attack.");

      Scanner sc = new Scanner(System.in);
      int answer = sc.nextInt();

      if (answer == 1) this.talk(other);
      else if (answer == 2) {
        if (this.flee(other)) return 1;
        else return 3;
      } else if (answer == 3) {
        this.attack(other);
        delay(3000);
        other.attack(this);
        delay(3000);
      }
    }
    return 5;
  }
Ejemplo n.º 7
0
  @Override
  public String variableNameToPropertyName(String name, VariableKind variableKind) {
    if (variableKind == VariableKind.STATIC_FINAL_FIELD
        || variableKind == VariableKind.STATIC_FIELD && name.contains("_")) {
      StringBuilder buffer = new StringBuilder();
      for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        if (c != '_') {
          if (Character.isLowerCase(c)) {
            return variableNameToPropertyNameInner(name, variableKind);
          }

          buffer.append(Character.toLowerCase(c));
          continue;
        }
        //noinspection AssignmentToForLoopParameter
        i++;
        if (i < name.length()) {
          c = name.charAt(i);
          buffer.append(c);
        }
      }
      return buffer.toString();
    }

    return variableNameToPropertyNameInner(name, variableKind);
  }
Ejemplo n.º 8
0
  private String variableNameToPropertyNameInner(String name, VariableKind variableKind) {
    String prefix = getPrefixByVariableKind(variableKind);
    String suffix = getSuffixByVariableKind(variableKind);
    boolean doDecapitalize = false;

    int pLength = prefix.length();
    if (pLength > 0
        && name.startsWith(prefix)
        && name.length() > pLength
        &&
        // check it's not just a long camel word that happens to begin with the specified prefix
        (!Character.isLetter(prefix.charAt(pLength - 1))
            || Character.isUpperCase(name.charAt(pLength)))) {
      name = name.substring(pLength);
      doDecapitalize = true;
    }

    if (name.endsWith(suffix) && name.length() > suffix.length()) {
      name = name.substring(0, name.length() - suffix.length());
      doDecapitalize = true;
    }

    if (doDecapitalize) {
      name = Introspector.decapitalize(name);
    }

    return name;
  }
Ejemplo n.º 9
0
  public static void main(String args[]) {

    Scanner in = new Scanner(System.in);

    int n = in.nextInt();

    String text = in.next();

    char[] input = new char[text.length()];

    int k = in.nextInt();

    for (int i = 0; i < text.length(); ++i) input[i] = text.charAt(i);

    for (int i = 0; i < text.length(); ++i) {
      if (Character.isLetter(input[i])) {

        int value = (int) input[i] + k % 26;

        if (Character.isLowerCase(input[i])) {

          if (value > (int) 'z') value = value - 26;

        } else if (Character.isUpperCase(input[i])) {
          if (value > (int) 'Z') value = value - 26;
        }

        input[i] = (char) value;
      }
    }

    for (int i = 0; i < n; ++i) System.out.print(input[i]);

    System.out.println();
  }
Ejemplo n.º 10
0
 public static int makestring(String a, Token b) {
   char[] temp = new char[a.length()];
   temp = a.toCharArray();
   int i = 1;
   if (temp[0] == '\'') {
     while (Character.isLetter(temp[i])
         || Character.isDigit(temp[i])
         || isoperator(temp[i])
         || ispunc(temp[i])
         || Character.isWhitespace(temp[i])) {
       i++;
       if (temp[i - 1] == '\'') {
         setToken(b, i - 2, a.substring(1, i - 1), LexToInt.string);
         return i;
       }
       if (i == a.length()) {
         break;
       }
     }
     if (temp[i - 1] == '\'') {
       setToken(b, i - 2, a.substring(1, i - 1), LexToInt.string);
       return i;
     }
   }
   return -1;
 }
Ejemplo n.º 11
0
 /** Loads custom hyphenation rules. You probably want to use loadDefault() instead. */
 public void load(BufferedReader input) throws IOException {
   String line;
   while ((line = input.readLine()) != null) {
     if (StringUtils.matches(line, "\\s*(%.*)?")) {
       // comment or blank line
       System.err.println("Skipping: " + line);
       continue;
     }
     char[] linechars = line.toCharArray();
     int[] pattern = new int[linechars.length];
     char[] chars = new char[linechars.length];
     int c = 0;
     for (int i = 0; i < linechars.length; ++i) {
       if (Character.isDigit(linechars[i])) {
         pattern[c] = Character.digit(linechars[i], 10);
       } else {
         chars[c++] = linechars[i];
       }
     }
     char[] shortchars = new char[c];
     int[] shortpattern = new int[c + 1];
     System.arraycopy(chars, 0, shortchars, 0, c);
     System.arraycopy(pattern, 0, shortpattern, 0, c + 1);
     insertHyphPattern(shortchars, shortpattern);
   }
 }
Ejemplo n.º 12
0
  public static String getDataElementName(String widgetName) {
    if (widgetName == null || widgetName.length() == 0) {
      return null;
    }
    String[] nameParts = widgetName.split("_");
    String convertedName = null;
    //  making widget name camel case
    for (String namePart : nameParts) {
      int i;
      for (i = 0; i < namePart.length(); i++) {
        char c = namePart.charAt(i);
        if (!Character.isLetter(c) || Character.isLowerCase(c)) {
          break;
        }
      }
      namePart = namePart.substring(0, i).toLowerCase() + namePart.substring(i);
      if (convertedName == null) {
        convertedName = namePart;
      } else {
        convertedName += "_" + namePart;
      }
    }
    if (convertedName == null) {
      return null;
    }

    return convertedName.replaceAll(" ", "").replaceAll("-", "");
  }
Ejemplo n.º 13
0
  public static String urlEscape(String param) {
    String urlOK = "";
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < param.length(); ++i) {
      char ch = param.charAt(i);
      char lowerCh = Character.toLowerCase(ch);
      if (Character.isDigit(ch) || (-1 != "[email protected]".indexOf(lowerCh))) {
        sb.append(ch);

      } else if (' ' == ch) {
        sb.append('+');

      } else if ((0x7F & ch) == ch) {
        putCh(sb, ch);

      } else if ((0xFFF & ch) == ch) {
        putCh(sb, 0xD0 | (ch >> 6));
        putCh(sb, 0x80 | (0x3F & ch));

      } else {
        putCh(sb, 0xE8 | (ch >> 12));
        putCh(sb, 0x80 | (0x3F & (ch >> 6)));
        putCh(sb, 0x80 | (0x3F & ch));
      }
    }
    return sb.toString();
  }
Ejemplo n.º 14
0
 private static String getPropertyName(String methodName) {
   String property = methodName.substring(3);
   if (Character.isLowerCase(property.charAt(0))) return null;
   if (property.length() <= 1) return property.toLowerCase();
   if (Character.isUpperCase(property.charAt(1))) return property;
   return property.substring(0, 1).toLowerCase() + property.substring(1);
 }
Ejemplo n.º 15
0
  public StringBuffer translate() {
    for (index = 0; index < line.length(); index++) {
      char c = line.charAt(index);

      if (Character.isDigit(c)) {
        dealWithOperand();
      } else if (isOperator(c)) {
        dealWithOperator(c);
      } else if (c == '(') {
        stack.push(new Character(c));
      } else if (c == ')') {
        dealWithCloser();
      } else if (Character.isSpaceChar(c)) {
        // do nothing
      } else {
        System.out.println("Error: unknown character" + c);
      }
    }

    // pop and output all the operators left on the stack
    while (!stack.empty()) {
      out.append(popChar());
    }
    return out;
  }
Ejemplo n.º 16
0
  private Map<String, Object> retrieveObjectMap(Object object) throws Exception {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Map<String, Object> objectMap = new Hashtable<String, Object>();
    Method method[] = object.getClass().getDeclaredMethods();
    for (int i = 0; i < method.length; i++) {
      if (method[i].getName().startsWith("get")) {
        String tempKey = method[i].getName();
        tempKey = tempKey.substring(tempKey.lastIndexOf(".") + 1);
        tempKey = tempKey.substring(3);
        String key = "";
        for (int j = 0; j < tempKey.length(); j++)
          if (j == 0) key += tempKey.substring(0, 1).toLowerCase();
          else if (Character.isUpperCase(tempKey.charAt(j)))
            key += ("_" + tempKey.substring(j, j + 1).toLowerCase());
          else if (Character.isDigit(tempKey.charAt(j)))
            key += ("_" + tempKey.substring(j, j + 1).toLowerCase());
          else key += tempKey.substring(j, j + 1);

        if (object.getClass().getName().endsWith("MagazineImage") && key.equals("magazine_id"))
          key = "focus_id";

        Object value = method[i].invoke(object);
        if (value instanceof Date) value = simpleDateFormat.format((Date) value);
        if (value != null) objectMap.put(key, value);
      }
    }
    return objectMap;
  }
Ejemplo n.º 17
0
 static {
   String javaVersion = System.getProperty("java.version");
   // Value is on the form M.N.U_P[-xxx] where M,N,U,P are decimal integers
   if (null != javaVersion) {
     int startPos = 0;
     int endPos = 0;
     int max = javaVersion.length();
     while (endPos < max && Character.isDigit(javaVersion.charAt(endPos))) {
       endPos++;
     }
     if (startPos < endPos) {
       try {
         javaVersionMajor = Integer.parseInt(javaVersion.substring(startPos, endPos));
         startPos = endPos + 1;
         endPos = startPos;
         while (endPos < max && Character.isDigit(javaVersion.charAt(endPos))) {
           endPos++;
         }
         if (startPos < endPos) {
           javaVersionMinor = Integer.parseInt(javaVersion.substring(startPos, endPos));
           startPos = endPos + 1;
           endPos = startPos;
           while (endPos < max && Character.isDigit(javaVersion.charAt(endPos))) {
             endPos++;
           }
           if (startPos < endPos) {
             javaVersionMicro = Integer.parseInt(javaVersion.substring(startPos, endPos));
           }
         }
       } catch (NumberFormatException _nfe) {
       }
     }
   }
 }
Ejemplo n.º 18
0
 /**
  * Returns a cyclified string representation of the given <tt>Object</tt>. Embedded constants are
  * prefixed with "#$".
  *
  * @return a <tt>String</tt> representation in cyclified form.
  */
 public static String cyclify(Object obj) {
   if (obj == null) {
     throw new BaseClientRuntimeException("Cannot cyclify null obj");
   } else if (!isCycLObject(obj)) {
     throw new BaseClientRuntimeException(
         "Cannot cyclify: '" + obj + "' (" + obj.getClass().getName() + ").");
   }
   if (obj instanceof CycObject) {
     return ((CycObject) obj).cyclify();
   }
   if (obj instanceof String) {
     return "\"" + (String) obj + "\"";
   }
   if (obj instanceof Character) {
     // @hack -- do better job of this. Need to support other non-printable characters!!!
     Character theChar = (Character) obj;
     if (theChar == ' ') {
       return "#\\Space";
     } else if (theChar == '\n') {
       return "#\\Newline";
     } else if (theChar == '\r') {
       return "#\\Return";
     } else if (theChar == '\t') {
       return "#\\Tab";
     }
     if (Character.isWhitespace(theChar)) {
       throw new IllegalArgumentException(
           "Don't know how to trasmit the whitespace character: " + (int) theChar.charValue());
     }
     return "#\\" + obj;
   }
   return obj.toString();
 }
Ejemplo n.º 19
0
  /** puts as utf-8 string */
  protected int _put(String str) {

    final int len = str.length();
    int total = 0;

    for (int i = 0; i < len; ) {
      int c = Character.codePointAt(str, i);

      if (c < 0x80) {
        _buf.write((byte) c);
        total += 1;
      } else if (c < 0x800) {
        _buf.write((byte) (0xc0 + (c >> 6)));
        _buf.write((byte) (0x80 + (c & 0x3f)));
        total += 2;
      } else if (c < 0x10000) {
        _buf.write((byte) (0xe0 + (c >> 12)));
        _buf.write((byte) (0x80 + ((c >> 6) & 0x3f)));
        _buf.write((byte) (0x80 + (c & 0x3f)));
        total += 3;
      } else {
        _buf.write((byte) (0xf0 + (c >> 18)));
        _buf.write((byte) (0x80 + ((c >> 12) & 0x3f)));
        _buf.write((byte) (0x80 + ((c >> 6) & 0x3f)));
        _buf.write((byte) (0x80 + (c & 0x3f)));
        total += 4;
      }

      i += Character.charCount(c);
    }

    _buf.write((byte) 0);
    total++;
    return total;
  }
Ejemplo n.º 20
0
  /**
   * Move the cursor <i>where</i> characters, withough checking the current buffer.
   *
   * @see #where
   * @param where the number of characters to move to the right or left.
   */
  private final void moveInternal(final int where) throws IOException {
    // debug ("move cursor " + where + " ("
    // + buf.cursor + " => " + (buf.cursor + where) + ")");
    buf.cursor += where;

    char c;

    if (where < 0) {
      int len = 0;
      for (int i = buf.cursor; i < buf.cursor - where; i++) {
        if (buf.getBuffer().charAt(i) == '\t') len += TAB_WIDTH;
        else len++;
      }

      char cbuf[] = new char[len];
      Arrays.fill(cbuf, BACKSPACE);
      out.write(cbuf);

      return;
    } else if (buf.cursor == 0) {
      return;
    } else if (mask != null) {
      c = mask.charValue();
    } else {
      printCharacters(buf.buffer.substring(buf.cursor - where, buf.cursor).toCharArray());
      return;
    }

    // null character mask: don't output anything
    if (NULL_MASK.equals(mask)) {
      return;
    }

    printCharacters(c, Math.abs(where));
  }
Ejemplo n.º 21
0
  private boolean compare_Character(int operation, char charval, Object value2) {
    if (operation == SUBSTRING) {
      return false;
    }
    char charval2;
    try {
      charval2 = ((String) value2).charAt(0);
    } catch (IndexOutOfBoundsException e) {
      return false;
    }

    switch (operation) {
      case EQUAL:
        {
          return charval == charval2;
        }
      case APPROX:
        {
          return (charval == charval2)
              || (Character.toUpperCase(charval) == Character.toUpperCase(charval2))
              || (Character.toLowerCase(charval) == Character.toLowerCase(charval2));
        }
      case GREATER:
        {
          return charval >= charval2;
        }
      case LESS:
        {
          return charval <= charval2;
        }
    }
    return false;
  }
  private static void autoImport(final PsiFile file, int offset, final Editor editor) {
    final CharSequence text = editor.getDocument().getCharsSequence();
    while (offset > 0 && Character.isJavaIdentifierPart(text.charAt(offset))) offset--;
    if (offset <= 0) return;

    while (offset > 0 && Character.isWhitespace(text.charAt(offset))) offset--;
    if (offset <= 0 || text.charAt(offset) != '.') return;

    offset--;

    while (offset > 0 && Character.isWhitespace(text.charAt(offset))) offset--;
    if (offset <= 0) return;

    PsiJavaCodeReferenceElement element =
        extractReference(
            PsiTreeUtil.findElementOfClassAtOffset(file, offset, PsiExpression.class, false));
    if (element == null) return;

    while (true) {
      final PsiJavaCodeReferenceElement qualifier = extractReference(element.getQualifier());
      if (qualifier == null) break;

      element = qualifier;
    }
    if (!(element.getParent() instanceof PsiMethodCallExpression)
        && element.multiResolve(true).length == 0) {
      new ImportClassFix(element).doFix(editor, false, false);
    }
  }
Ejemplo n.º 23
0
  public static void main(String[] args) throws Exception {
    int size = Util.getPropertyInt("size", 100);
    double min = Util.getPropertyDouble("min", 0.01);
    double max = Util.getPropertyDouble("max", 0.9);
    Font font = new Font("serif", Font.PLAIN, size);
    String fpath = Util.getProperty("font", null);
    if (fpath != null) {
      font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fpath));
    }

    for (char c = Character.MIN_VALUE + 1; c < Character.MAX_VALUE; ++c) {
      int type = Character.getType(c);
      if (type != Character.CONTROL
          && type != Character.FORMAT
          && type != Character.PRIVATE_USE
          && type != Character.SURROGATE
          && type != Character.UNASSIGNED
          && !Character.isMirrored(c)
          && !Character.isSpaceChar(c)) {
        String s = "" + c;
        if (Normalizer.normalize(s, NFKC).contains("\u0308")) continue; // TODO: adhoc
        UnigramMetrics m = new UnigramMetrics(s, size, false, true, font);
        if (min < m.getBlackness() && m.getBlackness() < max) {
          System.out.println("" + c + " " + (int) c);
        }
      }
    }
  }
Ejemplo n.º 24
0
 /**
  * @ensures: if input file is read, a String is filled with words from file and searched in
  *     dictionary list, and if found increase words found counter, otherwise increase words not
  *     found. Otherwise error reading file
  */
 public void readFileOliver() {
   try {
     FileInputStream inf = new FileInputStream(new File("oliver.txt"));
     char let;
     String str = "";
     String key = "";
     int n = 0;
     while ((n = inf.read()) != -1) {
       let = (char) n;
       if (Character.isLetter(let)) {
         str += Character.toLowerCase(let);
       }
       if ((Character.isWhitespace(let) || let == '-') && !str.isEmpty()) {
         key = str;
         str = "";
         boolean a = dictionary[(int) key.charAt(0) - 97].contains(key);
         if (a == true) {
           counter = dictionary[(int) key.charAt(0) - 97].indexOf(key);
           counterWFound++;
           counterWFCompared += counter;
         } else {
           counter =
               dictionary[(int) key.charAt(0) - 97].indexOf(
                   dictionary[(int) key.charAt(0) - 97].getLast());
           counterWNotFound++;
           counterWNFCompared += counter;
         }
       }
     }
     inf.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 25
0
 private static String getAtomicAdder(String name) {
   final int len = 9;
   if (name.length() > len
       && name.startsWith("addAtomic")
       && Character.isUpperCase(name.charAt(len)))
     return Character.toLowerCase(name.charAt(len)) + name.substring(len + 1);
   return null;
 }
Ejemplo n.º 26
0
 private static String getTryLock(String name) {
   final int len = 7;
   if (name.length() > len
       && name.startsWith("tryLock")
       && Character.isUpperCase(name.charAt(len)))
     return Character.toLowerCase(name.charAt(len)) + name.substring(len + 1);
   return null;
 }
Ejemplo n.º 27
0
 private static String getCAS(String name) {
   final int len = 14;
   if (name.length() > len
       && name.startsWith("compareAndSwap")
       && Character.isUpperCase(name.charAt(len)))
     return Character.toLowerCase(name.charAt(len)) + name.substring(len + 1);
   return null;
 }
Ejemplo n.º 28
0
 public static String generatePropertyName(String name) {
   int i = 0;
   for (; i < name.length(); i++) {
     if (Character.isLowerCase(name.charAt(i))) break;
   }
   if (i == name.length()) return name;
   return Character.toLowerCase(name.charAt(0)) + name.substring(1);
 }
Ejemplo n.º 29
0
 /**
  * @param str The string to check.
  * @return Returns true if str is CamelCase. Note that German compounds with a dash (like
  *     "Waschmaschinen-Test") are also considered camel case by this method.
  */
 public boolean isCamelCase(final String str) {
   return isNotEmpty(str)
       && !isAllUppercase(str)
       && isNotCapitalizedWord(str)
       && Character.isUpperCase(str.charAt(0))
       && (!(str.length() > 1) || Character.isLowerCase(str.charAt(1)))
       && isNotAllLowercase(str);
 }
Ejemplo n.º 30
0
 public static byte[] hexStringToByteArray(String s) {
   int len = s.length();
   byte[] data = new byte[len / 2];
   for (int i = 0; i < len; i += 2) {
     data[i / 2] =
         (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
   }
   return data;
 }