Package com.ibm.icu.impl

Examples of com.ibm.icu.impl.TextTrieMap$Node


     */
    public static String parse(ULocale locale, String text, int type, ParsePosition pos) {
        //TextTrieMap currencyNameTrie = (TextTrieMap)CURRENCY_NAME_CACHE.get(locale);
        Vector currencyTrieVec = (Vector)CURRENCY_NAME_CACHE.get(locale);
        if (currencyTrieVec == null) {
            TextTrieMap currencyNameTrie = new TextTrieMap(true);
            TextTrieMap currencySymbolTrie = new TextTrieMap(false);
            currencyTrieVec = new Vector();
            currencyTrieVec.addElement(currencySymbolTrie);
            currencyTrieVec.addElement(currencyNameTrie);
            setupCurrencyTrieVec(locale, currencyTrieVec);
            CURRENCY_NAME_CACHE.put(locale, currencyTrieVec);
        }
       
        int maxLength = 0;
        String isoResult = null;

          // look for the names
        TextTrieMap currencyNameTrie = (TextTrieMap)currencyTrieVec.elementAt(1);
        CurrencyNameResultHandler handler = new CurrencyNameResultHandler();
        currencyNameTrie.find(text, pos.getIndex(), handler);
        List list = handler.getMatchedCurrencyNames();
        if (list != null && list.size() != 0) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                CurrencyStringInfo info = (CurrencyStringInfo)it.next();
                String isoCode = info.getISOCode();
                String currencyString = info.getCurrencyString();
                if (currencyString.length() > maxLength) {
                    maxLength = currencyString.length();
                    isoResult = isoCode;
                }
            }
        }

        if (type != Currency.LONG_NAME) {  // not long name only
          TextTrieMap currencySymbolTrie = (TextTrieMap)currencyTrieVec.elementAt(0);
          handler = new CurrencyNameResultHandler();
          currencySymbolTrie.find(text, pos.getIndex(), handler);
          list = handler.getMatchedCurrencyNames();
          if (list != null && list.size() != 0) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                CurrencyStringInfo info = (CurrencyStringInfo)it.next();
View Full Code Here


        2. If there is no match, fall back to "en" and try again
        3. If there is no match, fall back to root and try again
        4. If still no match, parse 3-letter ISO {this code is probably unchanged}.
        */

        TextTrieMap symTrie = (TextTrieMap)trieVec.elementAt(0);
        TextTrieMap trie = (TextTrieMap)trieVec.elementAt(1);

        HashSet visited = new HashSet();
        ULocale parentLocale = locale;
        while (parentLocale != null) {
            UResourceBundle rb = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,parentLocale);
            // We can't cast this to String[][]; the cast has to happen later
            try {
                UResourceBundle currencies = rb.get("Currencies");
                // Do a linear search
                for (int i=0; i<currencies.getSize(); ++i) {
                    UResourceBundle item = currencies.get(i);
                    String ISOCode = item.getKey();
                    if (!visited.contains(ISOCode)) {
                        CurrencyStringInfo info = new CurrencyStringInfo(ISOCode, ISOCode);
                        symTrie.put(ISOCode, info);

                        String name = item.getString(0);
                        if (name.length() > 1 && name.charAt(0) == '=' &&
                            name.charAt(1) != '=') {
                            // handle choice format here
                            name = name.substring(1);
                            ChoiceFormat choice = new ChoiceFormat(name);
                            Object[] names = choice.getFormats();
                            for (int nameIndex = 0; nameIndex < names.length;
                                 ++nameIndex) {
                                info = new CurrencyStringInfo(ISOCode,
                                                      (String)names[nameIndex]);
                                symTrie.put((String)names[nameIndex], info);
                            }
                        } else {
                            info = new CurrencyStringInfo(ISOCode, name);
                            symTrie.put(name, info);
                        }

                        info = new CurrencyStringInfo(ISOCode, item.getString(1));
                        trie.put(item.getString(1), info);
                        visited.add(ISOCode);
                    }
                }
            }
            catch (MissingResourceException e) {}

            parentLocale = parentLocale.getFallback();
        }
        // Look up the CurrencyPlurals resource for the given locale.  The
        // CurrencyPlurals locale data looks like this:
        //|en {
        //|  CurrencyPlurals {
        //|    USD {
        //|      one{"US Dollar"} 
        //|      other{"US dollars"}
        //|    }
        //|    //...
        //|  }
        //|}

        HashMap visitedInMap = new HashMap();
        parentLocale = locale;
        while (parentLocale != null) {
            UResourceBundle rb = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,parentLocale);
            try {
                UResourceBundle currencies;
                currencies = rb.get("CurrencyPlurals");
                for (int i=0; i<currencies.getSize(); ++i) {
                    UResourceBundle item = currencies.get(i);
                    String ISOCode = item.getKey();
                    HashSet visitPluralCount = (HashSet)visitedInMap.get(ISOCode);
                    if (visitPluralCount == null) {
                        visitPluralCount = new HashSet();
                        visitedInMap.put(ISOCode, visitPluralCount);
                    }
                    for (int j=0; j<item.getSize(); ++j) {
                        String count = item.get(j).getKey();
                        if (!visitPluralCount.contains(count)) {
                            CurrencyStringInfo info = new CurrencyStringInfo(ISOCode, item.get(j).getString());

                            trie.put(item.get(j).getString(), info);
                            visitPluralCount.add(count);
                        }
                    }
                }
            }
View Full Code Here

        test.run(args);
    }

    public void TestCaseSensitive() {
        Iterator itr = null;
        TextTrieMap map = new TextTrieMap(false);
        for (int i = 0; i < TESTDATA.length; i++) {
            map.put((String)TESTDATA[i][0], TESTDATA[i][1]);
        }

        logln("Test for get(String)");
        for (int i = 0; i < TESTCASES.length; i++) {
            itr = map.get((String)TESTCASES[i][0]);
            checkResult(itr, TESTCASES[i][1]);
        }

        logln("Test for get(String, int)");
        StringBuffer textBuf = new StringBuffer();
        for (int i = 0; i < TESTCASES.length; i++) {
            textBuf.setLength(0);
            for (int j = 0; j < i; j++) {
                textBuf.append('X');
            }
            textBuf.append(TESTCASES[i][0]);
            itr = map.get(textBuf.toString(), i);
            checkResult(itr, TESTCASES[i][1]);
        }

        // Add duplicated entry
        map.put("Sunday", FOO);
        // Add duplicated entry with different casing
        map.put("sunday", BAR);

        // Make sure the all entries are returned
        itr = map.get("Sunday");
        checkResult(itr, new Object[]{FOO, SUN});
    }
View Full Code Here

        checkResult(itr, new Object[]{FOO, SUN});
    }

    public void TestCaseInsensitive() {
        Iterator itr = null;
        TextTrieMap map = new TextTrieMap(true);
        for (int i = 0; i < TESTDATA.length; i++) {
            map.put((String)TESTDATA[i][0], TESTDATA[i][1]);
        }

        logln("Test for get(String)");
        for (int i = 0; i < TESTCASES.length; i++) {
            itr = map.get((String)TESTCASES[i][0]);
            checkResult(itr, TESTCASES[i][2]);
        }
       
        logln("Test for get(String, int)");
        StringBuffer textBuf = new StringBuffer();
        for (int i = 0; i < TESTCASES.length; i++) {
            textBuf.setLength(0);
            for (int j = 0; j < i; j++) {
                textBuf.append('X');
            }
            textBuf.append(TESTCASES[i][0]);
            itr = map.get(textBuf.toString(), i);
            checkResult(itr, TESTCASES[i][2]);
        }

        // Add duplicated entry
        map.put("Sunday", FOO);
        // Add duplicated entry with different casing
        map.put("sunday", BAR);

        // Make sure the all entries are returned
        itr = map.get("Sunday");
        checkResult(itr, new Object[]{SUN, FOO, BAR});
    }
View Full Code Here

     */
    private ZoneItemInfo getZoneItemInfo(String[][] strings) {
        ZoneItemInfo zii = new ZoneItemInfo();
        zii.tzStrings = strings;
        zii.tzidMap = new HashMap();
        zii.tzStringMap = new TextTrieMap(true);
        for (int i = 0; i < strings.length; i++) {
            String zid = strings[i][0];
            if (zid != null && zid.length() > 0) {
                zii.tzidMap.put(zid, strings[i]);
                int nameCount = strings[i].length < 8 ? strings[i].length : 8;
View Full Code Here

    // create list for SortContainers...
    final LinkedList<SortContainer> scl = new LinkedList<SortContainer>();

    // walk through children...
    for (int i = 0; i < node.jjtGetNumChildren(); ++i) {
      Node n = node.jjtGetChild(i); // get current child

      boolean desc = false; // set order ASC as default

      // current node is Order node...
      if (n instanceof ASTAscOrder || n instanceof ASTDescOrder) {
        if (n instanceof ASTDescOrder) // reset order value to DESC...
          desc = true;

        i++; // increase counter to get next child (which is sort
        // condition)
      }

      n = node.jjtGetChild(i); // get next child (which is sort condition)

      // parse node with the filter...
      final SPARQLParserVisitorImplementationDumper filterDumper = new SPARQLParserVisitorImplementationDumper();
      final String sortString = n.accept(filterDumper);

      try {
        final SortContainer sc = new SortContainer(this.prefix, desc,
            sortString); // create SortContainer
View Full Code Here

  @SuppressWarnings("unchecked")
  public Object visit(final ASTTripleSet node, final Object data) {
    final Item[] item = { null, null, null };

    for (int i = 0; i < 3; i++) {
      final Node n = node.jjtGetChild(i);
      item[i] = lupos.sparql1_1.operatorgraph.SPARQLCoreParserVisitorImplementation.getItem(n);
    }

    final HashMap<Item, QueryRDFTerm> rdfHash = (HashMap<Item, QueryRDFTerm>) data;
View Full Code Here

    // if AST exists...
    if (debugViewerCreator!=null && debugViewerCreator instanceof SPARQLDebugViewerCreator
        && ((SPARQLDebugViewerCreator) debugViewerCreator).getAST() != null) {

      final Node ast = ((SPARQLDebugViewerCreator) debugViewerCreator).getAST(); // get AST

      // walk through first level children of AST...
      for (int i = 0; i < ast.jjtGetNumChildren(); ++i) {
        final Node child = ast.jjtGetChild(i); // get current child

        if (child instanceof ASTSelectQuery) {
          final ASTSelectQuery selectChild = (ASTSelectQuery) child;

          // SELECT is not the wildcard *...
          if (!selectChild.isSelectAll()) {
            // walk through select children...
            for (int j = 0; j < selectChild.jjtGetNumChildren(); ++j) {
              final Node selectChildChild = selectChild
              .jjtGetChild(j);

              // child of select is variable...
              if (selectChildChild instanceof ASTVar) {
                final ASTVar var = (ASTVar) selectChildChild;

                // add name of variable to order...
                if (!resultOrder.contains(var.getName())) {
                  resultOrder.add(var.getName());
                }
              } else if (selectChildChild instanceof ASTAs) {
                for (int j1 = 0; j1 < selectChildChild
                .jjtGetNumChildren(); ++j1) {
                  final Node selectChildChildChild = selectChildChild
                  .jjtGetChild(j1);
                  if (selectChildChildChild instanceof ASTVar) {
                    final ASTVar var = (ASTVar) selectChildChildChild;

                    // add name of variable to order...
View Full Code Here

        ret += "\n";
        final String orderByClause = " ORDER BY "
          + toBeSorted.toString() + "\n";
        boolean ORDERBYADDED = false;
        while (i < node.jjtGetNumChildren()) {
          final Node child = node.jjtGetChild(i);
          if (!ORDERBYADDED
              && (child instanceof ASTOrderConditions
                  || child instanceof ASTLimit || child instanceof ASTOffset)) {
            ORDERBYADDED = true;
            ret += orderByClause;
View Full Code Here

  private static void determineVariables(final Node root,
      final Set<String> variables) {
    if (root instanceof ASTSelectQuery) {
      for (int i = 0; i < root.jjtGetNumChildren(); i++) {
        final Node node = root.jjtGetChild(i);
        if (node instanceof ASTGroupConstraint)
          determineVariables(node, variables);
      }
    } else {
      if (root instanceof ASTVar) {
View Full Code Here

TOP

Related Classes of com.ibm.icu.impl.TextTrieMap$Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.