Beispiel #1
1
  /**
   * Sets a mnemomic for the specified button.
   *
   * @param b button
   * @param mnem mnemonics that have already been assigned
   */
  public static void setMnemonic(final AbstractButton b, final StringBuilder mnem) {
    // do not set mnemonics for Mac! Alt+key used for special characters.
    if (Prop.MAC) return;

    // find and assign unused mnemomic
    final String label = b.getText();
    final int ll = label.length();
    for (int l = 0; l < ll; l++) {
      final char ch = Character.toLowerCase(label.charAt(l));
      if (!letter(ch) || mnem.indexOf(Character.toString(ch)) != -1) continue;
      b.setMnemonic(ch);
      mnem.append(ch);
      break;
    }
  }
 // by Jaume Ortola
 private boolean areEqual(final char x, final char y) {
   if (x == y) {
     return true;
   }
   if (dictionaryMetadata.getEquivalentChars() != null
       && dictionaryMetadata.getEquivalentChars().containsKey(x)
       && dictionaryMetadata.getEquivalentChars().get(x).contains(y)) {
     return true;
   }
   if (dictionaryMetadata.isIgnoringDiacritics()) {
     String xn = Normalizer.normalize(Character.toString(x), Form.NFD);
     String yn = Normalizer.normalize(Character.toString(y), Form.NFD);
     if (xn.charAt(0) == yn.charAt(0)) { // avoid case conversion, if possible
       return true;
     }
     if (dictionaryMetadata.isConvertingCase()) {
       // again case conversion only when needed -- we
       // do not need String.lowercase because we only check
       // single characters, so a cheaper method is enough
       if (Character.isLetter(xn.charAt(0))) {
         boolean testNeeded =
             Character.isLowerCase(xn.charAt(0)) != Character.isLowerCase(yn.charAt(0));
         if (testNeeded) {
           return Character.toLowerCase(xn.charAt(0)) == Character.toLowerCase(yn.charAt(0));
         }
       }
     }
     return xn.charAt(0) == yn.charAt(0);
   }
   return false;
 }
Beispiel #3
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;
  }
  private String processVariables(String parameterValue, Map<String, Object> parameters) {

    int variableBeginIndex = parameterValue.indexOf("${"); // $NON-NLS-1$
    if (variableBeginIndex == -1) return parameterValue;

    int variableEndIndex = parameterValue.indexOf('}', variableBeginIndex + 2);
    if (variableEndIndex == -1) return parameterValue;

    String preVariable = parameterValue.substring(0, variableBeginIndex);
    String variableName = parameterValue.substring(variableBeginIndex + 2, variableEndIndex);
    Object value = parameters.get(variableName);

    // try to replace this parameter with a character
    if (value == null && variableName.charAt(0) == '#') {
      try {
        int code = Integer.parseInt(variableName.substring(1));
        if (code >= 0 && code < 65536) value = Character.toString((char) code);
      } catch (Throwable t) {
        // ignore and leave value as null
      }
    }

    String variableValue = value == null ? "" : value.toString(); // $NON-NLS-1$
    String postVariable =
        processVariables(parameterValue.substring(variableEndIndex + 1), parameters);
    return preVariable + variableValue + postVariable;
  }
Beispiel #5
0
  private void fixTabs(int tabSize) {

    int rowIndex = 0;

    for (StringBuilder row1 : rows) {
      String row = row1.toString();
      StringBuilder newRow = new StringBuilder();

      char[] chars = row.toCharArray();
      for (char c : chars) {
        if (c == '\t') {
          int spacesLeft = tabSize - newRow.length() % tabSize;
          if (DEBUG) {
            System.out.println("Found tab. Spaces left: " + spacesLeft);
          }
          String spaces = StringUtils.repeatString(" ", spacesLeft);
          newRow.append(spaces);
        } else {
          String character = Character.toString(c);
          newRow.append(character);
        }
      }
      rows.set(rowIndex, newRow);
      rowIndex++;
    }
  }
Beispiel #6
0
 /** Ensures an arc's label is indeed printable (dot uses US-ASCII). */
 private static String printableLabel(int label) {
   if (label >= 0x20 && label <= 0x7d) {
     return Character.toString((char) label);
   } else {
     return "0x" + Integer.toHexString(label);
   }
 }
 private void invalidNamedArgument(String[] args) throws ArgumentDoesNotExistException {
   for (int i = 0; i < args.length; i++) {
     if (args[i].startsWith("--")) {
       String[] splitLongNamedArg = new String[2];
       splitLongNamedArg = args[i].split("--");
       NamedArgument tempArg = getNamedArgument(splitLongNamedArg[1]);
       if (tempArg == null) {
         invalidNamedArgument = splitLongNamedArg[1];
         throw new ArgumentDoesNotExistException(
             argumentDoesNotExistMessage(invalidNamedArgument));
       }
     } else if (args[i].startsWith("-")) {
       String[] splitShortNamedArg = new String[2];
       splitShortNamedArg = args[i].split("-");
       if (splitShortNamedArg[1].length() == 1) { // single char
         NamedArgument tempArg = getNamedArgument(splitShortNamedArg[1].charAt(0));
         if (tempArg == null) {
           invalidNamedArgument = splitShortNamedArg[1];
           throw new ArgumentDoesNotExistException(
               argumentDoesNotExistMessage(invalidNamedArgument));
         }
       } else {
         for (int k = 0; k < splitShortNamedArg[1].length(); k++) {
           NamedArgument tempArg = getNamedArgument(splitShortNamedArg[1].charAt(k));
           if (tempArg == null) {
             invalidNamedArgument = Character.toString(splitShortNamedArg[1].charAt(k));
             throw new ArgumentDoesNotExistException(
                 argumentDoesNotExistMessage(invalidNamedArgument));
           }
         }
       }
     }
   }
 }
Beispiel #8
0
 public String convert(String s, int numRows) {
   if (s.length() <= numRows || numRows == 1) return s;
   String[] sa = new String[numRows];
   for (int i = 0; i < sa.length; i++) {
     sa[i] = "";
   }
   String out = "";
   for (int i = 0; i < s.length(); i++) {
     // System.out.println(i);
     int idx = i % (2 * numRows - 2);
     String str = Character.toString(s.charAt(i));
     if (idx < numRows) {
       sa[idx] = sa[idx] + str;
     } else {
       sa[2 * numRows - 2 - idx] = sa[2 * numRows - 2 - idx] + str;
       // System.out.println(sa[2*numRows-2-idx] );
     }
   }
   for (String ss : sa) {
     out += ss;
     // System.out.println(out);
   }
   System.out.println(out);
   return out;
 }
Beispiel #9
0
  /** @return Expr */
  Expr read() {
    try {
      while (_tokens.nextToken() != _tokens.TT_EOF) {
        if (_tokens.ttype == -2) {
          Numeral a = new Numeral(_tokens.nval);
          return a;
        } else if (_tokens.ttype == -3) {
          String a = new String(_tokens.sval);
          return new Symbol(a);
        } else if (_tokens.ttype == (int) '(') {
          _tokens.nextToken();
          String s;
          if (_tokens.ttype == -3) {
            s = _tokens.sval;
          } else {
            s = Character.toString((char) _tokens.ttype);
          }
          System.out.println("operator: " + s);
          return Combination.create(s, getOperands());
        }
      }
    } catch (IOException e) {
      System.err.println("error: " + e.getMessage());
      System.exit(1);
    }
    System.out.println("end of file reached");

    return null;
  }
  private String ask(String cmd) {
    BufferedWriter out = null;
    BufferedReader in = null;
    Socket sock = null;
    String ret = "";
    try {
      System.out.println(server);
      sock = new Socket(server, ServerListener.PORT);
      out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
      out.write(cmd, 0, cmd.length());
      out.flush();
      in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
      int inr = in.read();
      while (inr != ';') {
        ret += Character.toString((char) inr);
        inr = in.read();
      }
    } catch (IOException io) {
      io.printStackTrace();
    } finally {
      try {
        out.close();
        in.close();
        sock.close();
      } catch (IOException io) {
        io.printStackTrace();
      }
    }

    return ret;
  }
  private static void findMines(int r, int c) {
    for (int x = 0; x < r; x++) {
      for (int y = 0; y < c; y++) {

        if (currentMap[x][y] == '*') printedMap[x][y] = Character.toString(currentMap[x][y]);
        else printedMap[x][y] = countSurrounding(x, y, r, c);
      }
    }
  }
Beispiel #12
0
  /**
   * adds a new output
   *
   * @param userId user id
   * @param hostSystemId host system id
   * @param c character
   */
  public static void addCharToOutput(Long userId, Long hostSystemId, char c) {

    UserSessionsOutput userSessionsOutput = userSessionsOutputMap.get(userId);
    if (userSessionsOutput != null) {
      SessionOutput sessionOutput = userSessionsOutput.getSessionOutputMap().get(hostSystemId);
      if (sessionOutput != null) {
        sessionOutput.setOutput(sessionOutput.getOutput() + Character.toString(c));
      }
    }
  }
 /**
  * Outputs this <code>State</code> as though it came from the text input file.
  *
  * @return a <code>String</code> describing this <code>State</code>.
  */
 public String toString() {
   return STATE
       + " "
       + Integer.toString(index)
       + " "
       + Character.toString(c)
       + " "
       + Integer.toString(qtrue)
       + " "
       + Integer.toString(qfalse);
 }
Beispiel #14
0
 public static String getRandomPwd() {
   Random rd = new Random();
   String n = "";
   int getNum;
   do {
     getNum = Math.abs(rd.nextInt()) % 10 + 48; // 产生数字0-9的随机数
     // getNum = Math.abs(rd.nextInt())%26 + 97;//产生字母a-z的随机数
     char num1 = (char) getNum;
     String dn = Character.toString(num1);
     n += dn;
   } while (n.length() < 8);
   return n;
 }
Beispiel #15
0
  /**
   * Adds to the given list of property descriptors the mapped properties, ie. properties that have
   * a getter method taking a single String value as a parameter.
   *
   * @param clazz to introspect
   * @param result is the list to add to
   */
  protected static void addMappedProperties(Class clazz, List<InternalEventPropDescriptor> result) {
    Set<String> uniquePropertyNames = new HashSet<String>();
    Method[] methods = clazz.getMethods();

    for (int i = 0; i < methods.length; i++) {
      String methodName = methods[i].getName();
      if (!methodName.startsWith("get")) {
        continue;
      }

      String inferredName = methodName.substring(3, methodName.length());
      if (inferredName.length() == 0) {
        continue;
      }

      Class<?> parameterTypes[] = methods[i].getParameterTypes();
      if (parameterTypes.length != 1) {
        continue;
      }

      if (parameterTypes[0] != String.class) {
        continue;
      }

      String newInferredName = null;
      // Leave uppercase inferred names such as URL
      if (inferredName.length() >= 2) {
        if ((Character.isUpperCase(inferredName.charAt(0)))
            && (Character.isUpperCase(inferredName.charAt(1)))) {
          newInferredName = inferredName;
        }
      }
      // camelCase the inferred name
      if (newInferredName == null) {
        newInferredName = Character.toString(Character.toLowerCase(inferredName.charAt(0)));
        if (inferredName.length() > 1) {
          newInferredName += inferredName.substring(1, inferredName.length());
        }
      }
      inferredName = newInferredName;

      // if the property inferred name already exists, don't supply it
      if (uniquePropertyNames.contains(inferredName)) {
        continue;
      }

      result.add(
          new InternalEventPropDescriptor(inferredName, methods[i], EventPropertyType.MAPPED));
      uniquePropertyNames.add(inferredName);
    }
  }
Beispiel #16
0
  /** @param args */
  public static void main(String[] args) {
    int answer = 0;
    String temp = BigInteger.valueOf(2).pow(1000).toString(10);
    ArrayList<Integer> al = new ArrayList<Integer>();
    for (int i = 0; i < temp.length(); i++) {
      al.add(Integer.parseInt(Character.toString(temp.charAt(i))));
    }

    for (Integer i : al) {
      answer += i;
    }

    System.out.println("Answer=" + answer);
  }
Beispiel #17
0
 /**
  * 根据输入的Unicode字符,获取它的GB2312编码或者ascii编码,
  *
  * @param ch 输入的GB2312中文字符或者ASCII字符(128个)
  * @return ch在GB2312中的位置,-1表示该字符不认识
  */
 public static short getgbId(char ch) {
   try {
     byte[] buffer = Character.toString(ch).getBytes("GB2312");
     if (buffer.length != 2) {
       // 正常情况下buffer应该是两个字节,否则说明ch不属于GB2312编码,故返回'?',此时说明不认识该字符
       return -1;
     }
     int b0 = (int) (buffer[0] & 0x0FF) - 161; // 编码从A1开始,因此减去0xA1=161
     int b1 = (int) (buffer[1] & 0x0FF) - 161; // 第一个字符和最后一个字符没有汉字,因此每个区只收16*6-2=94个汉字
     return (short) (b0 * 94 + b1);
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   return -1;
 }
Beispiel #18
0
  public Note prevHalfStep() {
    // If the next note a half step away, return it
    if (this.nextInterval == 0.5) {
      return this.nextNote();
    }
    ;

    // Otherwise, if the length of the note name is > 1, we have a sharp
    if (this.noteName.length() > 1) {
      String startingLetter = Character.toString(this.noteName.charAt(0));
      return new Note(startingLetter);
    } else {
      return new Note(Note.lookUp(this.noteName)[3] + "#");
    }
  }
Beispiel #19
0
 /**
  * This util method is used to retrieve the string tokens resides in a particular udt parameter.
  *
  * @param param Name of the parameter
  * @return
  */
 public static Queue<String> getTokens(String param) {
   boolean isString = false;
   Queue<String> tokens = new LinkedBlockingQueue<String>();
   char[] chars = param.toCharArray();
   StringBuilder columnName = new StringBuilder();
   for (int i = 0; i < chars.length; i++) {
     Character c = chars[i];
     if (!".".equals(c.toString()) && !"[".equals(c.toString()) && !"]".equals(c.toString())) {
       isString = true;
       columnName.append(c.toString());
       if (i == chars.length - 1) {
         tokens.add(columnName.toString());
       }
     } else {
       if (isString) {
         tokens.add(columnName.toString());
         columnName = new StringBuilder();
         isString = false;
       }
       tokens.add(c.toString());
     }
   }
   return tokens;
 }
Beispiel #20
0
  @Override
  public String toString() {
    switch (this.type) {
      case OPERATOR:
      case OPENING_BRACKET:
      case CLOSING_BRACKET:
        return Character.toString(operator);

      case FUNCTION:
        return this.function;

      case VALUE:
      default:
        return Arrays.toString(value);
    }
  }
 public static ArrayList<String> validateSamplesDirectoryStructureIdentifyVersions(
     String samplesDirPath, ArrayList<String> versionArr) {
   String samplesDir[] = getDirectoryNames(samplesDirPath);
   StringBuilder builder = new StringBuilder();
   ArrayList<String> tempArr = new ArrayList<String>();
   Pattern numeric = Pattern.compile("[0-9_.-]");
   for (String dir : samplesDir) {
     for (int item = dir.length() - 1; item >= 0; item--) {
       char singleChar = dir.charAt(item);
       Matcher matcher = numeric.matcher(Character.toString(singleChar));
       // Find all matches
       if (matcher.find()) {
         // Get the matching string
         builder.append(singleChar);
       } else {
         if (builder.length() > 1) {
           tempArr.add(builder.toString());
           builder.setLength(0);
         } else {
           builder.setLength(0);
         }
       }
       if (item == 0 && builder.length() != 0) {
         tempArr.add(builder.toString());
         builder.setLength(0);
       }
     }
     int max;
     int previousMax = 0;
     String[] version = new String[1];
     for (String element : tempArr) {
       max = element.length();
       if (max > previousMax) {
         previousMax = max;
         version[0] = element;
       }
     }
     if (version[0] != null) {
       if (version[0].length() >= 2) {
         versionArr.add(dir);
       }
     }
     tempArr.clear();
   }
   return versionArr;
 }
 /** Converts a char to a printable String for display */
 public static String charToString(char c) {
   if (c == '\n') {
     return "NL";
   } else if (c == '\r') {
     return "CR";
   } else if (c == '\t') {
     return "TAB";
   } else if (Character.isISOControl(c)) {
     int i = (int) c;
     return "\\u"
         + Character.forDigit((i / 2048) % 16, 16)
         + Character.forDigit((i / 256) % 16, 16)
         + Character.forDigit((i / 16) % 16, 16)
         + Character.forDigit((i) % 16, 16);
   }
   return Character.toString(c);
 }
 private Map<Character, Double> normalizeSymbolMap(Map<Character, Double> letterFrequency) {
   Double freq;
   Double mostFrequent = new Double(0);
   Character textCharacter;
   Set symbolsInMap = letterFrequency.entrySet();
   Iterator iterateSymbols = symbolsInMap.iterator();
   while (iterateSymbols.hasNext()) {
     Map.Entry symbolEntries = (Map.Entry) iterateSymbols.next();
     textCharacter = (Character) symbolEntries.getKey();
     freq = letterFrequency.get(textCharacter);
     letterFrequency.put(textCharacter, (freq / text.length()));
     if (freq != null && freq > mostFrequent) {
       mostFrequent = freq;
       mostFrequentLetter = textCharacter.toString();
     }
   }
   mostFrequentLetterFrequency = mostFrequent / text.length();
   return letterFrequency;
 }
 private ArrayList<String> getPositionalArgs(String[] args) {
   ArrayList<String> posArgList = new ArrayList<String>();
   for (int i = 0; i < args.length; i++) { // going through args from CLI
     if (!args[i].startsWith("-") && i == 0) { // test if the first arg is a positional arg
       posArgList.add(args[i]);
     } else if (!args[i].startsWith("-")) { // arg from CLI doesn't have a dash
       if (!args[i - 1].startsWith(
           "-")) { // if the one before it doesn't have a dash, then it's a pos arg
         posArgList.add(args[i]);
       } else {
         String[] tempNamedArg = new String[2];
         if (args[i - 1].startsWith("--")) {
           tempNamedArg = args[i - 1].split("--");
           for (int j = 0; j < namedArgumentList.size(); j++) { // g
             NamedArgument currentNamedArg = namedArgumentList.get(j);
             if (currentNamedArg.getName().equals(tempNamedArg[1])) {
               if (currentNamedArg.getType().equals("boolean")) { // to pos args
                 posArgList.add(args[i]);
               }
             }
           }
         } else {
           tempNamedArg = args[i - 1].split("-");
           if (tempNamedArg[1].length() == 1) {
             for (int j = 0; j < namedArgumentList.size(); j++) {
               NamedArgument currentNamedArg = namedArgumentList.get(j);
               if (Character.toString(currentNamedArg.getShortFormName())
                   .equals(tempNamedArg[1])) {
                 if (currentNamedArg.getType().equals("boolean")) {
                   posArgList.add(args[i]);
                 }
               }
             }
           } else {
             posArgList.add(args[i]);
           }
         }
       }
     }
   }
   return posArgList;
 }
Beispiel #25
0
  private String modifyCharacter(Character baseChar, Character modifierChar) {
    String result = null;

    switch (classifyChar(modifierChar)) {
      case DIAERESIS:
        result = addDiaeresisToCharV1(baseChar);
        break;
      case ACUTE_ACCENT:
        result = addAcuteAccentToChar(baseChar);
        break;
      case GRAVE_ACCENT:
        result = addGraveAccentToChar(baseChar);
        break;
      case CIRCUMFLEX:
        result = addCircumflexAccentToChar(baseChar);
        break;
      case TILDE:
        result = addTildeToChar(baseChar);
        break;
      case NORDIC_RING:
        result = addNordicRingToChar(baseChar);
        break;
      case CZECH_CARON:
        result = addCzechCaronToChar(baseChar);
        break;
      case CEDILLA:
        result = addCedillaToChar(baseChar);
        break;
      case NOT_A_MODIFIER:
        result = baseChar.toString();
        break;
      default:
        break;
    }

    if (result == null) {
      LOGGER.debug(
          "FIXME: cannot apply modifier '" + modifierChar + "' to character '" + baseChar + "'");
    }

    return result;
  }
  @EventHandler
  public void onTick(TickEvent event) {
    if (!bot.hasSpawned() || !bot.isConnected()) return;
    if (tickDelay > 0) {
      tickDelay--;
      return;
    }

    MainPlayerEntity player = bot.getPlayer();
    if (player == null || !bot.hasSpawned() || spamMessage == null) return;
    if (nextMessage > 0) {
      nextMessage--;
      return;
    }
    try {
      String message = spamMessage;
      MessageFormatter formatter = new MessageFormatter();
      synchronized (bots) {
        if (bots.size() > 0) {
          DarkBotMCSpambot bot = bots.get(++nextBot >= bots.size() ? nextBot = 0 : nextBot);
          if (bot != null && bot.bot != null && bot.bot.getSession() != null)
            formatter.setVariable("bot", bot.bot.getSession().getUsername());
        }
      }
      if (spamList.length > 0) {
        formatter.setVariable(
            "spamlist",
            spamList[++nextSpamList >= spamList.length ? nextSpamList = 0 : nextSpamList]);
      }
      formatter.setVariable("rnd", Util.generateRandomString(15 + random.nextInt(6)));
      formatter.setVariable(
          "msg",
          Character.toString(
              msgChars[++nextMsgChar >= msgChars.length ? nextMsgChar = 0 : nextMsgChar]));
      message = formatter.format(message);
      bot.say(message);
    } catch (Exception e) {
      e.printStackTrace();
    }
    nextMessage = messageDelay;
  }
Beispiel #27
0
  public static String firstReaptingCharacter(String s) {
    HashMap map = new HashMap<Character, Boolean>();

    for (int i = 0; i < s.length(); i++) {
      char cur = s.charAt(i);
      if (map.containsKey(cur)) {
        if ((Boolean) map.get(cur) == false) map.put(cur, true);
      } else {
        map.put(cur, false);
      }
    }

    Iterator it = map.entrySet().iterator();
    String re = null;
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();
      re = Character.toString((Character) pair.getKey());
    }

    return re;
  }
  /**
   * Calculates the phone list for a given word. If a phone list cannot be determined, <code>null
   * </code> is returned. This particular implementation ignores the part of speech.
   *
   * @param word the word to find
   * @param partOfSpeech the part of speech.
   * @return the list of phones for word or <code>null</code>
   */
  public String[] getPhones(String word, String partOfSpeech) {
    if (RiTa.PRINT_LTS_INFO && !RiTa.SILENT)
      System.out.println("[INFO] Using LTS for '" + word + "'");

    List phoneList = new ArrayList();
    State currentState;
    Integer startIndex;
    int stateIndex;
    char c;

    // Create "000#word#000"
    char[] full_buff = getFullBuff(word);

    // For each character in the word, create a WINDOW_SIZE
    // context on each size of the character, and then ask the
    // state machine what's next. Its magic
    for (int pos = 0; pos < word.length(); pos++) {
      for (int i = 0; i < WINDOW_SIZE; i++) {
        fval_buff[i] = full_buff[pos + i];
        fval_buff[i + WINDOW_SIZE] = full_buff[i + pos + 1 + WINDOW_SIZE];
      }
      c = word.charAt(pos);
      startIndex = (Integer) letterIndex.get(Character.toString(c));
      if (startIndex == null) {
        continue;
      }

      stateIndex = startIndex.intValue();
      currentState = getState(stateIndex);
      while (!(currentState instanceof FinalState)) {
        stateIndex = ((DecisionState) currentState).getNextState(fval_buff);
        currentState = getState(stateIndex);
      }

      ((FinalState) currentState).append((ArrayList) phoneList);
      // RiTa.out("phoneList: "+phoneList);
    }

    return (String[]) phoneList.toArray(new String[0]);
  }
Beispiel #29
0
 /** 获取所有的停止词 */
 public Set<String> allStopwords() {
   Node<Void> root = stopWords.getRoot();
   final List<Character> list = new ArrayList<>();
   root.childHandle(
       new NodeChildHandle<Void>() {
         @Override
         public boolean onHandle(Node<Void> child) {
           list.add(child.getChar());
           return true;
         }
       });
   Set<String> allStopWords = new HashSet<>();
   for (Character c : list) {
     List<Map.Entry<String, Void>> ret = stopWords.prefixSearch(c.toString());
     if (ret != null) {
       for (Map.Entry<String, Void> e : ret) {
         allStopWords.add(e.getKey());
       }
     }
   }
   return allStopWords;
 }
  private void setShortFormNamedArgValues(String[] args) throws NumberFormatException {
    for (int i = 0; i < args.length; i++) {
      String[] tempNamedArg = new String[2];
      if (args[i].startsWith("-")) {
        tempNamedArg = args[i].split("-");
        for (int k = 0; k < namedArgumentList.size(); k++) {
          incorrectDataTypeIndex = k;
          incorrectArgumentType = "named";
          NamedArgument currentNamedArg = namedArgumentList.get(k);
          if (tempNamedArg[1].length() == 1) { // single char
            if (Character.toString(currentNamedArg.getShortFormName()).equals(tempNamedArg[1])) {
              if (!currentNamedArg.getType().equals("boolean")) {
                incorrectArgValueForSpecifiedDataType = args[i + 1];
                if (currentNamedArg.getType().equals("integer")) {
                  int argValue = Integer.parseInt(args[i + 1]);
                  currentNamedArg.setValue(args[i + 1]);
                } else if (currentNamedArg.getType().equals("float")) {
                  float argValue = Float.parseFloat(args[i + 1]);
                  currentNamedArg.setValue(args[i + 1]);
                } else if (currentNamedArg.getType().equals("string")) {
                  currentNamedArg.setValue(args[i + 1]);
                }

              } else {
                currentNamedArg.setValue("true");
              }
            }
          } else { // multiple flags in one specification
            for (int j = 0; j < tempNamedArg[1].length(); j++) {
              if (currentNamedArg.getShortFormName() == tempNamedArg[1].charAt(j)) {
                currentNamedArg.setValue("true");
              }
            }
          }
        }
      }
    }
  }