Examples of Collator


Examples of com.hazelcast.mapreduce.Collator

            KeyValueSource<K, V> keyValueSource = KeyValueSource.fromMultiMap(this);
            Job<K, V> job = jobTracker.newJob(keyValueSource);
            Mapper mapper = aggregation.getMapper(supplier);
            CombinerFactory combinerFactory = aggregation.getCombinerFactory();
            ReducerFactory reducerFactory = aggregation.getReducerFactory();
            Collator collator = aggregation.getCollator();

            MappingJob mappingJob = job.mapper(mapper);
            ReducingSubmittableJob reducingJob;
            if (combinerFactory != null) {
                reducingJob = mappingJob.combiner(combinerFactory).reducer(reducerFactory);
View Full Code Here

Examples of com.ibm.icu.text.Collator

  public void testRanges() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    Field field = newField("field", "", StringField.TYPE_STORED);
    Collator collator = Collator.getInstance(); // uses -Dtests.locale
    if (random().nextBoolean()) {
      collator.setStrength(Collator.PRIMARY);
    }
    ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);
    doc.add(field);
    doc.add(collationField);
   
    int numDocs = atLeast(500);
    for (int i = 0; i < numDocs; i++) {
      String value = _TestUtil.randomSimpleString(random());
      field.setStringValue(value);
      collationField.setStringValue(value);
      iw.addDocument(doc);
    }
   
    IndexReader ir = iw.getReader();
    iw.close();
    IndexSearcher is = newSearcher(ir);
   
    int numChecks = atLeast(100);
    for (int i = 0; i < numChecks; i++) {
      String start = _TestUtil.randomSimpleString(random());
      String end = _TestUtil.randomSimpleString(random());
      BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
      BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
      Query query = new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
      doTestRanges(is, start, end, query, collator);
    }
   
    ir.close();
View Full Code Here

Examples of com.ibm.icu.text.Collator

 
  public void testThreadSafe() throws Exception {
    int iters = 20 * RANDOM_MULTIPLIER;
    for (int i = 0; i < iters; i++) {
      Locale locale = Locale.GERMAN;
      Collator collator = Collator.getInstance(locale);
      collator.setStrength(Collator.IDENTICAL);
      assertThreadSafe(new ICUCollationKeyAnalyzer(collator));
    }
  }
View Full Code Here

Examples of com.ibm.icu.text.Collator

   * Sort the commands using the correct language.
   * @param commands the List of ParameterizedCommands
   * @return The sorted List
   */
  private List sortParameterizedCommands(List commands) {
    final Collator collator = Collator.getInstance();
   
    // this comparator is based on the ParameterizedCommands#compareTo(*)
    // method, but uses the collator.
    Comparator comparator = new Comparator() {
      public int compare(Object o1, Object o2) {
        String name1 = null;
        String name2 = null;
        try {
          name1 = ((ParameterizedCommand) o1).getName();
        } catch (NotDefinedException e) {
          return -1;
        }
        try {
          name2 = ((ParameterizedCommand) o2).getName();
        } catch (NotDefinedException e) {
          return 1;
        }
        int rc = collator.compare(name1, name2);
        if (rc != 0) {
          return rc;
        }

        String id1 = ((ParameterizedCommand) o1).getId();
        String id2 = ((ParameterizedCommand) o2).getId();
        return collator.compare(id1, id2);
      }
    };
    Collections.sort(commands, comparator);
    return commands;
  }
View Full Code Here

Examples of java.text.Collator

        fireTableRowsUpdated(0, getRowCount() - 1);
      }
    }

    public Comparator<CatalogPieceOfFurniture> getFurnitureComparator(final String propertyKey) {
      final Collator collator = Collator.getInstance();
      Comparator<CatalogPieceOfFurniture> furnitureComparator = null;
      if (FurnitureLibrary.FURNITURE_ID_PROPERTY.equals(propertyKey)) {
        furnitureComparator = new Comparator<CatalogPieceOfFurniture>() {
            public int compare(CatalogPieceOfFurniture piece1, CatalogPieceOfFurniture piece2) {
              if (piece1.getId() == null) {
                return -1;
              } else if (piece2.getId() == null) {
                return 1;
              } else {
                return collator.compare(piece1.getId(), piece2.getId());
              }
            }
          };
      } else if (FurnitureLibrary.FURNITURE_NAME_PROPERTY.equals(propertyKey)) {
         furnitureComparator = new Comparator<CatalogPieceOfFurniture>() {
             public int compare(CatalogPieceOfFurniture piece1, CatalogPieceOfFurniture piece2) {
               String piece1Name = (String)furnitureLibrary.getPieceOfFurnitureLocalizedData(
                   piece1, controller.getFurnitureLangauge(), propertyKey, piece1.getName());
               String piece2Name = (String)furnitureLibrary.getPieceOfFurnitureLocalizedData(
                   piece2, controller.getFurnitureLangauge(), propertyKey, piece2.getName());
               return collator.compare(piece1Name, piece2Name);
             }
           };
      } else if (FurnitureLibrary.FURNITURE_DESCRIPTION_PROPERTY.equals(propertyKey)) {
        furnitureComparator = new Comparator<CatalogPieceOfFurniture>() {
            public int compare(CatalogPieceOfFurniture piece1, CatalogPieceOfFurniture piece2) {
              String piece1Description = (String)furnitureLibrary.getPieceOfFurnitureLocalizedData(
                  piece1, controller.getFurnitureLangauge(), propertyKey, piece1.getDescription());
              if (piece1Description == null) {
                return -1;
              } else {
                String piece2Description = (String)furnitureLibrary.getPieceOfFurnitureLocalizedData(
                    piece2, controller.getFurnitureLangauge(), propertyKey, piece2.getDescription());
                if (piece2Description == null) {
                  return 1;
                } else {
                  return collator.compare(piece1Description, piece2Description);
                }
              }
            }
          };
      } else if (FurnitureLibrary.FURNITURE_CREATOR_PROPERTY.equals(propertyKey)) {
        furnitureComparator = new Comparator<CatalogPieceOfFurniture>() {
            public int compare(CatalogPieceOfFurniture piece1, CatalogPieceOfFurniture piece2) {
              return collator.compare(piece1.getCreator(), piece2.getCreator());
            }
          };
      } else if (FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY.equals(propertyKey)) {
        furnitureComparator = new Comparator<CatalogPieceOfFurniture>() {
            public int compare(CatalogPieceOfFurniture piece1, CatalogPieceOfFurniture piece2) {
              String piece1Category = (String)furnitureLibrary.getPieceOfFurnitureLocalizedData(
                  piece1, controller.getFurnitureLangauge(), propertyKey, piece1.getCategory().getName());
              String piece2Category = (String)furnitureLibrary.getPieceOfFurnitureLocalizedData(
                  piece2, controller.getFurnitureLangauge(), propertyKey, piece2.getCategory().getName());
              return collator.compare(piece1Category, piece2Category);
            }
          };
      } else if (FurnitureLibrary.FURNITURE_PRICE_PROPERTY.equals(propertyKey)) {
        furnitureComparator = new Comparator<CatalogPieceOfFurniture>() {
            public int compare(CatalogPieceOfFurniture piece1, CatalogPieceOfFurniture piece2) {
View Full Code Here

Examples of java.text.Collator

      if (ourSortValue instanceof String && otherSortValue instanceof String) {
        // Collator.getInstance cache's Collator object, so this is relatively
        // fast.  However, storing it as static somewhere might give a small
        // performance boost.  If such an approach is take, ensure that the static
        // variable is updated the user chooses an different language.
        Collator collator = Collator.getInstance(Locale.getDefault());
        return collator.compare(ourSortValue, otherSortValue);
      }
      try {
        return ourSortValue.compareTo(otherSortValue);
      } catch (ClassCastException e) {
        // It's possible that a row was created, but not refreshed yet.
View Full Code Here

Examples of java.text.Collator

        String name = readAliasIdentifier();
        command.setString(name);
        if (equalsToken(name, CompareMode.OFF)) {
            return command;
        }
        Collator coll = CompareMode.getCollator(name);
        if (coll == null) {
            throw DbException.getInvalidValueException("collation", name);
        }
        if (readIf("STRENGTH")) {
            if (readIf("PRIMARY")) {
                command.setInt(Collator.PRIMARY);
            } else if (readIf("SECONDARY")) {
                command.setInt(Collator.SECONDARY);
            } else if (readIf("TERTIARY")) {
                command.setInt(Collator.TERTIARY);
            } else if (readIf("IDENTICAL")) {
                command.setInt(Collator.IDENTICAL);
            }
        } else {
            command.setInt(coll.getStrength());
        }
        return command;
    }
View Full Code Here

Examples of java.text.Collator

        }
        final RuleBasedCollator collator;
        if(arglen == 3) {
            Item thirdItem = argv.getItem(2);
            String collation = thirdItem.stringValue();
            Collator coll = CollationUtils.resolve(collation, dynEnv.getStaticContext());
            if(!(coll instanceof RuleBasedCollator)) {
                // If the specified collation does not support collation units an error
                // may be raised [err:FOCH0004].
                throw new DynamicError("err:FOCH0004", "Collator for the collation `" + collation
                        + "` is expected to be rule based collator, but was " + coll);
View Full Code Here

Examples of java.text.Collator

        Item param1 = argv.getItem(0); // convention to be SingleCollection
        Item param2 = argv.getItem(1);
        if(param1.isEmpty() && param2.isEmpty()) {
            return BooleanValue.TRUE;
        }
        final Collator collator;
        final int arglen = argv.size();
        if(arglen == 3) {
            Item third = argv.getItem(2);
            final String collation = third.stringValue();
            collator = CollationUtils.resolve(collation, dynEnv.getStaticContext());
View Full Code Here

Examples of java.text.Collator

            }
            return min;
        } else if(TypeUtil.subtypeOf(firstType, StringType.STRING)) {
            AtomicValue min = (AtomicValue) firstItem;
            final int arglen = argv.size();
            final Collator collator;
            if(arglen == 2) {
                Item sec = argv.getItem(1);
                Type secType = sec.getType();
                if(!TypeUtil.subtypeOf(secType, StringType.STRING)) {
                    throw new DynamicError("err:FORG0006", "second argument is expected to be xs:string, but was "
                            + secType);
                }
                String uri = sec.stringValue();
                collator = CollationUtils.resolve(uri, dynEnv.getStaticContext());
            } else {
                collator = Collator.getInstance(); // compare in default locale
            }
            while(argItor.hasNext()) {
                Item it = argItor.next();
                Type cmpType = it.getType();
                if(!TypeUtil.subtypeOf(cmpType, StringType.STRING)) {
                    throw new DynamicError("err:FORG0006", "imcomparable xs:string and " + cmpType);
                }
                if(collator.compare(it, firstItem) < 0) {
                    min = (AtomicValue) it;
                }
            }
            return min;
        } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.