Example #1
0
 // Check int input edit field for an error
 private static boolean intFieldError(TextField theField, double minValue, double maxValue) {
   StringTokenizer fieldTokenizer = new StringTokenizer(theField.getText());
   if (!fieldTokenizer.hasMoreElements()) {
     theField.setText("Error");
     return true;
   } else {
     String fieldString = fieldTokenizer.nextToken();
     try {
       int fieldValue = new Integer(fieldString).intValue();
       if (fieldValue < minValue) {
         theField.setText("Error");
         return true;
       } else if (fieldValue > maxValue) {
         theField.setText("Error");
         return true;
       }
     } catch (Throwable e) {
       theField.setText("Error");
       return true;
     }
   }
   if (fieldTokenizer.hasMoreElements()) {
     theField.setText("Error");
     return true;
   } else {
     return false;
   }
 }
Example #2
0
  public FeatureList(String featReplyMsg) {

    StringTokenizer responseTokenizer =
        new StringTokenizer(featReplyMsg, System.getProperty("line.separator"));

    // ignore the first part of the message
    if (responseTokenizer.hasMoreElements()) {
      responseTokenizer.nextToken();
    }

    while (responseTokenizer.hasMoreElements()) {

      String line = (String) responseTokenizer.nextElement();
      line = line.trim().toUpperCase();
      if (line.startsWith("211 END")) {
        break;
      }
      String[] splitFeature = line.split(" ");

      if (splitFeature.length == 2) {
        features.add(new Feature(splitFeature[0], splitFeature[1]));
      } else {
        features.add(new Feature(line));
      }
    }
  }
Example #3
0
 @Override
 public Locale read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   String locale = in.nextString();
   StringTokenizer tokenizer = new StringTokenizer(locale, "_");
   String language = null;
   String country = null;
   String variant = null;
   if (tokenizer.hasMoreElements()) {
     language = tokenizer.nextToken();
   }
   if (tokenizer.hasMoreElements()) {
     country = tokenizer.nextToken();
   }
   if (tokenizer.hasMoreElements()) {
     variant = tokenizer.nextToken();
   }
   if (country == null && variant == null) {
     return new Locale(language);
   } else if (variant == null) {
     return new Locale(language, country);
   } else {
     return new Locale(language, country, variant);
   }
 }
  /**
   * Search by criteria.
   *
   * @param criteria the criteria
   * @return the list< t>
   */
  protected List<T> searchByCriteria(E criteria) {
    CriteriaQuery<T> query = getCriteriaBuilder().createQuery(getEntityClass());
    Root<T> from = query.from(getEntityClass());
    query.select(from);
    List<Predicate> predicateList = buildConditions(from, criteria);
    if (predicateList != null) {
      Predicate[] predicates = new Predicate[predicateList.size()];
      predicateList.toArray(predicates);
      query.where(predicates);
    }
    if (criteria.getGroupBy() != null) {
      query.groupBy(from.get(criteria.getGroupBy()));
    }
    if (criteria.getOrderField() != null) {
      if (criteria.getOrderType() != null && !"".equals(criteria.getOrderType())) {
        StringTokenizer outerTokenizer = new StringTokenizer(criteria.getOrderField(), ",");
        StringTokenizer typeTokenizer = new StringTokenizer(criteria.getOrderType(), ",");
        List<Order> orders = new ArrayList<Order>();
        while (outerTokenizer.hasMoreElements()) {
          String field = (String) outerTokenizer.nextElement();
          String type = (String) typeTokenizer.nextElement();
          Path ex = null;
          if (field.indexOf(".") > 0) {
            StringTokenizer tokenizer = new StringTokenizer(field, ".");
            while (tokenizer.hasMoreElements()) {
              String key = (String) tokenizer.nextElement();
              if (ex == null) {
                ex = from.get(key);
              } else {
                ex = ex.get(key);
              }
            }
          } else {
            ex = from.get(field);
          }
          if ("desc".equals(type)) {
            orders.add(getCriteriaBuilder().desc(ex));
          } else if ("asc".equals(type)) {
            orders.add(getCriteriaBuilder().asc(ex));
          }
        }
        if (orders.size() > 0) {
          query.orderBy(orders);
        }
      } else {
        query.orderBy(getCriteriaBuilder().desc(from.get(criteria.getOrderField())));
      }
    }

    TypedQuery<T> typedQuery = getEntityManager().createQuery(query);
    if (criteria.getStartIndex() != null) {
      typedQuery.setFirstResult(criteria.getStartIndex());
      typedQuery.setMaxResults(criteria.getPageSize());
    } else {
      typedQuery.setFirstResult(0);
      typedQuery.setMaxResults(rowLimit);
    }
    System.out.println("dfjdfjdkfdkfjd" + typedQuery.toString());
    return typedQuery.getResultList();
  }
  public static String findUrl(PsiFile file, int offset, String uri) {
    final PsiElement currentElement = file.findElementAt(offset);
    final XmlAttribute attribute = PsiTreeUtil.getParentOfType(currentElement, XmlAttribute.class);

    if (attribute != null) {
      final XmlTag tag = PsiTreeUtil.getParentOfType(currentElement, XmlTag.class);

      if (tag != null) {
        final String prefix = tag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI);
        if (prefix != null) {
          final String attrValue =
              tag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT, XmlUtil.XML_SCHEMA_INSTANCE_URI);
          if (attrValue != null) {
            final StringTokenizer tokenizer = new StringTokenizer(attrValue);

            while (tokenizer.hasMoreElements()) {
              if (uri.equals(tokenizer.nextToken())) {
                if (!tokenizer.hasMoreElements()) return uri;
                final String url = tokenizer.nextToken();

                return url.startsWith(HTTP_PROTOCOL) ? url : uri;
              }

              if (!tokenizer.hasMoreElements()) return uri;
              tokenizer.nextToken(); // skip file location
            }
          }
        }
      }
    }
    return uri;
  }
Example #6
0
  public static Triangle parseTriangle(String s) throws InvalidShapeStringException {
    StringTokenizer st = new StringTokenizer(s, ":,");

    int available;
    String[] arr;
    {
      available = 0;
      arr = new String[available];
    }

    while (st.hasMoreElements()) {
      ++available;
      arr = Arrays.copyOf(arr, available);
      arr[arr.length - 1] = (String) st.nextElement();
    }

    if (arr.length == 5) {

      while (st.hasMoreElements()) {
        String figure = st.nextElement().toString();
        String color = st.nextElement().toString();
        String a = st.nextElement().toString();
        String b = st.nextElement().toString();
        String c = st.nextElement().toString();
        Triangle triangle =
            new Triangle(
                color, Double.parseDouble(a), Double.parseDouble(b), Double.parseDouble(c));
        // System.out.println(triangle.toString());

      }
    } else throw new InvalidShapeStringException();

    return new Triangle("WHITE", 1.1, 1.1, 1.1);
  }
 public static String newLineToBR(String data) {
   StringTokenizer tokened = new StringTokenizer(data, "\n");
   String result = new String();
   while (tokened.hasMoreElements()) {
     result += tokened.nextElement();
     if (tokened.hasMoreElements()) result += "<BR>";
   }
   return result;
 }
Example #8
0
 public Version(String s) {
   StringTokenizer tok = new StringTokenizer(s, ".");
   if (!tok.hasMoreElements()) return;
   major = Integer.parseInt(tok.nextToken());
   if (!tok.hasMoreElements()) return;
   minor = Integer.parseInt(tok.nextToken());
   if (!tok.hasMoreElements()) return;
   build = Integer.parseInt(tok.nextToken());
 }
Example #9
0
  private static Boolean analyzeTokens(StringTokenizer tok1, StringTokenizer tok2) {

    List<String> alist1 = new ArrayList<String>();
    List<String> alist2 = new ArrayList<String>();

    while (tok1.hasMoreElements()) {
      alist1.add(tok1.nextToken());
    }
    while (tok2.hasMoreElements()) {
      alist2.add(tok2.nextToken());
    }

    for (String elem1 : new ArrayList<String>(alist1)) {
      for (String elem2 : new ArrayList<String>(alist2)) {
        if (elem1.equals(elem2)) {
          alist1.remove(elem1);
          alist2.remove(elem2);
          break;
        }
      }
    }

    Boolean validated = false;
    String returnString = "";
    for (String elem1 : alist1) {
      returnString = returnString + elem1 + ";";
    }
    if (returnString.length() > 0) {
      returnString =
          " |remaining tokenizer content: |##### | "
              + returnString
              + "<- from original file| ### |";
    } else {
      returnString =
          " |no tokenizer content remained:|##### | "
              + returnString
              + "<- from original file| ### |";
      validated = true;
    }
    for (String elem2 : alist2) {
      returnString = returnString + elem2 + ";";
    }
    if (returnString.length() > 0) {
      returnString = returnString + " <- from converted file|";
    }

    errorMsg = returnString;

    return validated;
  }
 public EmployeeCSV(String values) {
   StringTokenizer tokenizer = new StringTokenizer(values, ",");
   if (tokenizer.hasMoreElements()) {
     id = Integer.parseInt(tokenizer.nextToken());
   }
   if (tokenizer.hasMoreElements()) {
     firstname = tokenizer.nextToken();
   }
   if (tokenizer.hasMoreElements()) {
     lastname = tokenizer.nextToken();
   }
   if (tokenizer.hasMoreElements()) {
     emailAddress = tokenizer.nextToken();
   }
 }
Example #11
0
  /**
   * Gets a created package.
   *
   * @param qualifiedName the package to search
   * @return a found package or null
   */
  public CtPackage get(String qualifiedName) {
    if (qualifiedName.contains(CtType.INNERTTYPE_SEPARATOR)) {
      throw new RuntimeException("Invalid package name " + qualifiedName);
    }
    StringTokenizer token = new StringTokenizer(qualifiedName, CtPackage.PACKAGE_SEPARATOR);
    CtPackage current = rootPackage;
    if (token.hasMoreElements()) {
      current = current.getPackage(token.nextToken());
      while (token.hasMoreElements() && current != null) {
        current = current.getPackage(token.nextToken());
      }
    }

    return current;
  }
  public static ClassLoader newClassLoader(final Class... userClasses) throws Exception {

    Set<URL> userClassUrls = new HashSet<>();
    for (Class anyUserClass : userClasses) {
      ProtectionDomain protectionDomain = anyUserClass.getProtectionDomain();
      CodeSource codeSource = protectionDomain.getCodeSource();
      URL classLocation = codeSource.getLocation();
      userClassUrls.add(classLocation);
    }
    StringTokenizer tokenString =
        new StringTokenizer(System.getProperty("java.class.path"), File.pathSeparator);
    String pathIgnore = System.getProperty("java.home");
    if (pathIgnore == null) {
      pathIgnore = userClassUrls.iterator().next().toString();
    }

    List<URL> urls = new ArrayList<>();
    while (tokenString.hasMoreElements()) {
      String value = tokenString.nextToken();
      URL itemLocation = new File(value).toURI().toURL();
      if (!userClassUrls.contains(itemLocation)
          && itemLocation.toString().indexOf(pathIgnore) >= 0) {
        urls.add(itemLocation);
      }
    }
    URL[] urlArray = urls.toArray(new URL[urls.size()]);

    ClassLoader masterClassLoader = URLClassLoader.newInstance(urlArray, null);
    ClassLoader appClassLoader =
        URLClassLoader.newInstance(userClassUrls.toArray(new URL[0]), masterClassLoader);
    return appClassLoader;
  }
Example #13
0
  /** Convert input from regular mathematical expression to a postfix one. */
  public void convert(String input) {
    StringHandler sh = new StringHandler();
    this.input = sh.toStandardInput(input);
    StringTokenizer tokenizer = new StringTokenizer(this.input, " ");

    while (tokenizer.hasMoreElements()) {
      String token = tokenizer.nextToken();

      // Single digit, Check if type is digit or operator.
      if (token.length() == 1) {
        char temp = token.charAt(0);

        // Digit
        if (Character.isDigit(temp)) {
          addToOutputQueue(token);
        }
        // Operator
        else if (isOperator(temp)) {
          processOperator(token);
        }
        // Parenthesis
        else if (isParenthesis(temp)) {
          processParenthesis(token);
        }
      }
      // More than one digit. Can only be number
      else {
        addToOutputQueue(token);
      }
    }

    while (opStack.size() != 0) {
      addToOutputQueue(opStack.pop().getType());
    }
  }
 /**
  * Get the list of codecs listed in the configuration
  *
  * @param conf the configuration to look in
  * @return a list of the Configuration classes or null if the attribute was not set
  */
 public static List<Class<? extends CompressionCodec>> getCodecClasses(Configuration conf) {
   String codecsString = conf.get("io.compression.codecs");
   if (codecsString != null) {
     List<Class<? extends CompressionCodec>> result =
         new ArrayList<Class<? extends CompressionCodec>>();
     StringTokenizer codecSplit = new StringTokenizer(codecsString, ",");
     while (codecSplit.hasMoreElements()) {
       String codecSubstring = codecSplit.nextToken();
       if (codecSubstring.length() != 0) {
         try {
           Class<?> cls = conf.getClassByName(codecSubstring);
           if (!CompressionCodec.class.isAssignableFrom(cls)) {
             throw new IllegalArgumentException(
                 "Class " + codecSubstring + " is not a CompressionCodec");
           }
           result.add(cls.asSubclass(CompressionCodec.class));
         } catch (ClassNotFoundException ex) {
           throw new IllegalArgumentException(
               "Compression codec " + codecSubstring + " not found.", ex);
         }
       }
     }
     return result;
   } else {
     return null;
   }
 }
Example #15
0
 /**
  * Get currently running java version and subversion numbers. This is the running JRE version. If
  * no version could be identified <code>null</code> is returned.
  *
  * @return Array of version and subversion numbers.
  */
 public static int[] getJavaVersion() {
   final String version = System.getProperty("java.version");
   final List numbers = new ArrayList();
   final StringTokenizer tokenizer = new StringTokenizer(version, ".");
   while (tokenizer.hasMoreElements()) {
     String sub = tokenizer.nextToken();
     for (int i = 0; i < sub.length(); i++) {
       if (!Character.isDigit(sub.charAt(i))) {
         sub = sub.substring(0, i);
         break;
       }
     }
     try {
       numbers.add(new Integer(Integer.parseInt(sub)));
     } catch (Exception e) {
       e.printStackTrace();
       break;
     }
   }
   if (numbers.size() == 0) {
     return null;
   }
   final int[] result = new int[numbers.size()];
   for (int i = 0; i < numbers.size(); i++) {
     result[i] = ((Integer) numbers.get(i)).intValue();
   }
   return result;
 }
  public static void getTablePaths(String myMultiLocs) {
    StringTokenizer st = new StringTokenizer(myMultiLocs, ",");

    // get how many tokens inside st object
    System.out.println("tokens count: " + st.countTokens());
    int count = 0;

    // iterate st object to get more tokens from it
    while (st.hasMoreElements()) {
      count++;
      String token = st.nextElement().toString();
      if (mode == TestMode.local) {
        System.out.println("in mini, token: " + token);
        // in mini, token: file:/homes/<uid>/grid/multipleoutput/pig-table/contrib/zebra/ustest3
        if (count == 1) strTable1 = token;
        if (count == 2) strTable2 = token;
        if (count == 3) strTable3 = token;
      } else {
        System.out.println("in real, token: " + token);
        // in real, token: /user/hadoopqa/ustest3
        // note: no prefix file:  in real cluster
        if (count == 1) strTable1 = token;
        if (count == 2) strTable2 = token;
        if (count == 3) strTable3 = token;
      }
    }
  }
Example #17
0
 private Object parseRecursive(StringTokenizer st) {
   List<Object> currentSequence = new ArrayList<>();
   Object lastParsed = null;
   while (st.hasMoreElements()) {
     String s = st.nextToken();
     switch (s) {
       case " ": // split on blanks
         currentSequence.add(lastParsed);
         break;
       case "?":
         lastParsed = grammar.zeroOrOne(lastParsed);
         break;
       case "*":
         lastParsed = grammar.zeroOrMore(lastParsed);
         break;
       case "(":
         lastParsed = parseRecursive(st);
         break;
       case ")": // current group finished
         return finish(currentSequence, lastParsed);
       case "'":
         lastParsed = Token.getFromDescription(st.nextToken("'"));
         st.nextToken("'?*() "); // '
         break;
       default:
         lastParsed = s; // rule name
         break;
     }
   }
   return finish(currentSequence, lastParsed);
 }
Example #18
0
  /**
   * evaluates the 'Set-Cookie'-Header of a HTTP response
   *
   * @param name key of a cookie value
   * @param conn URLConnection
   * @return cookie value referenced by the key. null if key not found
   * @throws IOException
   */
  private static String getCookie(String name, URLConnection conn) {

    for (int i = 0; ; i++) {
      String headerName = conn.getHeaderFieldKey(i);
      String headerValue = conn.getHeaderField(i);

      if (headerName == null && headerValue == null) {
        // No more headers
        break;
      }
      if (headerName != null && headerName.equals("Set-Cookie")) {
        if (headerValue.startsWith(name)) {
          // several key-value-pairs are separated by ';'
          StringTokenizer st = new StringTokenizer(headerValue, "; ");
          while (st.hasMoreElements()) {
            String token = st.nextToken();
            if (token.startsWith(name)) {
              return token;
            }
          }
        }
      }
    }
    return null;
  }
 public VersionString(String paramString) {
   if (paramString != null) {
     StringTokenizer localStringTokenizer = new StringTokenizer(paramString, " ", false);
     while (localStringTokenizer.hasMoreElements())
       this._versionIds.add(new VersionID(localStringTokenizer.nextToken()));
   }
 }
Example #20
0
  /**
   * Given a context node and the argument to the XPath <code>id</code> function, checks whether the
   * context node is in the set of nodes that results from that reference to the <code>id</code>
   * function. This is used in the implementation of <code>id</code> patterns.
   *
   * @param node The context node
   * @param value The argument to the <code>id</code> function
   * @return <code>1</code> if the context node is in the set of nodes returned by the reference to
   *     the <code>id</code> function; <code>0</code>, otherwise
   */
  public int containsID(int node, Object value) {
    final String string = (String) value;
    int rootHandle = _dom.getAxisIterator(Axis.ROOT).setStartNode(node).next();

    // Get the mapping table for the document containing the context node
    Hashtable index = (Hashtable) _rootToIndexMap.get(new Integer(rootHandle));

    // Split argument to id function into XML whitespace separated tokens
    final StringTokenizer values = new StringTokenizer(string, " \n\t");

    while (values.hasMoreElements()) {
      final String token = (String) values.nextElement();
      IntegerArray nodes = null;

      if (index != null) {
        nodes = (IntegerArray) index.get(token);
      }

      // If input was from W3C DOM, use DOM's getElementById to do
      // the look-up.
      if (nodes == null && _enhancedDOM != null && _enhancedDOM.hasDOMSource()) {
        nodes = getDOMNodeById(token);
      }

      // Did we find the context node in the set of nodes?
      if (nodes != null && nodes.indexOf(node) >= 0) {
        return 1;
      }
    }

    // Didn't find the context node in the set of nodes returned by id
    return 0;
  }
Example #21
0
  public float[] getVertBinAltitude() throws Exception {
    String propertyFileName = null;
    float[] altitude = new float[VertLen];
    try {
      propertyFileName = (String) metadata.get(ancillary_file_name);
      InputStream ios = getClass().getResourceAsStream(propertyFileName);
      BufferedReader ancillaryReader = new BufferedReader(new InputStreamReader(ios));

      int line_cnt = 0;
      while (true) {
        String line = ancillaryReader.readLine();
        if (line == null) break;
        if (line.startsWith("!")) continue;
        StringTokenizer strTok = new StringTokenizer(line);
        String[] tokens = new String[strTok.countTokens()];
        int tokCnt = 0;
        while (strTok.hasMoreElements()) {
          tokens[tokCnt++] = strTok.nextToken();
        }
        altitude[line_cnt] = (Float.valueOf(tokens[0])) * 1000f;
        line_cnt++;
      }
      ios.close();
    } catch (Exception e) {
      logger.error("fail on ancillary file read: " + propertyFileName);
    }
    return altitude;
  }
Example #22
0
 /**
  * Extracts column names referenced by enclosing them in curly braces (“{” and “}”) in a string
  * template.
  *
  * @param stringTemplate
  * @return
  */
 public static Set<String> extractColumnNamesFromStringTemplate(String stringTemplate) {
   Set<String> result = new HashSet<String>();
   // Curly braces that do not enclose column names MUST be
   // escaped by a backslash character (“\”).
   stringTemplate = stringTemplate.replaceAll("\\\\\\{", "");
   stringTemplate = stringTemplate.replaceAll("\\\\\\}", "");
   if (stringTemplate != null) {
     StringTokenizer st = new StringTokenizer(stringTemplate, "{}", true);
     boolean keepNext = false;
     String next = null;
     while (st.hasMoreElements()) {
       String element = st.nextElement().toString();
       if (keepNext) next = element;
       keepNext = element.equals("{");
       if (element.equals("}") && element != null) {
         log.debug(
             "[R2RMLToolkit:extractColumnNamesFromStringTemplate] Extracted column name "
                 + next
                 + " from string template "
                 + stringTemplate);
         result.add(next);
         next = null;
       }
     }
   }
   return result;
 }
Example #23
0
 private long stringToIp(String ip) throws EntitlementException {
   StringTokenizer st = new StringTokenizer(ip, ".");
   int tokenCount = st.countTokens();
   if (tokenCount != 4) {
     String args[] = {"ip", ip};
     throw new EntitlementException(400, args);
   }
   long ipValue = 0L;
   while (st.hasMoreElements()) {
     String s = st.nextToken();
     short ipElement = 0;
     try {
       ipElement = Short.parseShort(s);
     } catch (Exception e) {
       String args[] = {"ip", ip};
       throw new EntitlementException(400, args);
     }
     if (ipElement < 0 || ipElement > 255) {
       String args[] = {"ipElement", s};
       throw new EntitlementException(400, args);
     }
     ipValue = ipValue * 256L + ipElement;
   }
   return ipValue;
 }
  public static void buildWordMap(String out, List<String> wordMap, Set<String> dictionarySet)
      throws IOException {
    String currentLine = "", currentWord = "";

    StringTokenizer st = new StringTokenizer(out.toString(), " ");

    while (st.hasMoreElements()) {
      Integer i = null;
      currentWord = st.nextToken();

      currentWord = CheckWord(currentWord); // remove any
      // unwanted
      // chars

      if (currentWord == null) continue;

      if (dictionarySet.contains(currentWord)) continue;

      // List<Integer> lines = wordMap.get(currentWord);

      // if (lines == null)
      // {
      //	lines = new ArrayList<Integer>();
      //	wordMap.put(currentWord, lines);
      // }
      wordMap.add(currentWord);
      // lines.add(LineNumber);
    }
  }
Example #25
0
 public void setAuthor(String authors) {
   StringTokenizer st = new StringTokenizer(authors, ",");
   author = new Vector<String>();
   while (st.hasMoreElements()) {
     author.add(st.nextToken());
   }
 }
Example #26
0
  /**
   * Add a CLASSPATH or -lib to lib path urls. Only filesystem resources are supported.
   *
   * @param path the classpath or lib path to add to the libPathULRLs
   * @param getJars if true and a path is a directory, add the jars in the directory to the path
   *     urls
   * @param libPathURLs the list of paths to add to
   * @throws MalformedURLException if we can't create a URL
   */
  private void addPath(String path, boolean getJars, List libPathURLs)
      throws MalformedURLException {
    StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator);
    while (tokenizer.hasMoreElements()) {
      String elementName = tokenizer.nextToken();
      File element = new File(elementName);
      if (elementName.indexOf('%') != -1 && !element.exists()) {
        continue;
      }
      if (getJars && element.isDirectory()) {
        // add any jars in the directory
        URL[] dirURLs = Locator.getLocationURLs(element);
        for (int j = 0; j < dirURLs.length; ++j) {
          if (launchDiag) {
            System.out.println("adding library JAR: " + dirURLs[j]);
          }
          libPathURLs.add(dirURLs[j]);
        }
      }

      URL url = Locator.fileToURL(element);
      if (launchDiag) {
        System.out.println("adding library URL: " + url);
      }
      libPathURLs.add(url);
    }
  }
Example #27
0
  public static DataPointType lookup(String dptID) {
    dptID = dptID.toUpperCase().trim();

    if (dptID.startsWith("DPT")) {
      dptID = dptID.substring(3, dptID.length()).trim();
    }

    StringTokenizer tokenizer = new StringTokenizer(dptID, ".");

    int main, sub;

    try {
      main = Integer.parseInt(tokenizer.nextToken().trim());

      if (!tokenizer.hasMoreElements()) {
        throw new NoSuchCommandException("Unable to parse DPT : '" + dptID + "'.");
      }

      sub = Integer.parseInt(tokenizer.nextToken().trim());

      return lookup.get(getDPTID(main, sub));
    } catch (NumberFormatException exception) {
      throw new NoSuchCommandException(
          "Cannot parse datapoint type '" + dptID + "', " + exception.getMessage(), exception);
    }
  }
 private void executeMultipleInlineStatements(String line, StringBuilder sql) {
   final StringTokenizer sqlStatements = new StringTokenizer(line, getStatementDelimiter());
   while (sqlStatements.hasMoreElements()) {
     sql.append(sqlStatements.nextToken());
     executeStatements(sql);
   }
 }
Example #29
0
  public static ArrayList<Long> splitStringToLongs(String line, String delim) {
    if (line == null) {
      err("splitString: line is null");
      return null;
    }
    ArrayList<Long> res = new ArrayList<Long>();
    StringTokenizer tokenizer = new StringTokenizer(line, delim);

    while (tokenizer.hasMoreElements()) {
      String next = tokenizer.nextToken().trim();
      if (next.startsWith("\"")) {
        next = next.substring(1, next.length());
      }
      if (next.endsWith("\"")) {
        next = next.substring(0, next.length() - 1);
      }
      long d = 0;
      try {
        d = Long.parseLong(next);
      } catch (Exception e) {
      }
      res.add(d);
      // p("token "+res.size()+" is:"+next);
    }
    return res;
  }
  public Distribution<T> parse(String distrAsString) {
    DiscreteDistribution<T> dist = new DiscreteDistribution<T>();

    StringTokenizer tok = new StringTokenizer(distrAsString, ",");

    while (tok.hasMoreElements()) {
      String pair = tok.nextToken().trim();
      StringTokenizer sub = new StringTokenizer(pair, "/");

      try {
        T value = (T) domainType.getConstructor(String.class).newInstance(sub.nextToken().trim());
        Degree deg = (Degree) getDegreeStringConstructor().newInstance(sub.nextToken().trim());

        dist.put(value, deg);
      } catch (NoSuchMethodException nsme) {
        nsme.printStackTrace();
      } catch (IllegalAccessException iae) {
        iae.printStackTrace();
      } catch (InstantiationException ie) {
        ie.printStackTrace();
      } catch (InvocationTargetException ite) {
        ite.printStackTrace();
      }
    }
    return dist;
  }