コード例 #1
0
  private int keyCompare(String s1, String s2) {
    SortKey<Object> k1 = sort.createSortKey(null, s1);
    SortKey<Object> k2 = sort.createSortKey(null, s2);
    System.out.println("K1: " + k1);
    System.out.println("K2: " + k2);

    return k1.compareTo(k2);
  }
コード例 #2
0
  @Test
  public void testEquals() {
    String abc = "ABC\u0234\u1023";
    SortKey<Object> key1 = sort.createSortKey(null, abc);
    SortKey<Object> key2 = sort.createSortKey(null, abc);

    assertEquals(0, key1.compareTo(key2));
  }
コード例 #3
0
 /**
  * {@inheritDoc}
  *
  * <p>
  */
 @Override
 public void resetSortOrders() {
   if (!isSortable()) return;
   List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
   for (int i = keys.size() - 1; i >= 0; i--) {
     SortKey sortKey = keys.get(i);
     if (isSortable(sortKey.getColumn())) {
       keys.remove(sortKey);
     }
   }
   setSortKeys(keys);
 }
コード例 #4
0
ファイル: ZGroupLayer.java プロジェクト: atrofast/geotools
  public void drawFeatures(Graphics2D graphics, final StreamingRenderer renderer, String layerId)
      throws IOException, FactoryException, NoninvertibleTransformException, SchemaException,
          TransformException {
    // 1) init all the readers and the lfts associated to them (one at a time to avoid deadlock)
    // and create one RenderableFeature for each
    // 2) process all the features one z-level at a time, backtracking if there are multiple
    // fts for a certain layer.

    // a listener passed around to stop data reading/painting if rendering stop request is
    // issued
    ProgressListener cancellationListener =
        new DefaultProgressListener() {
          public boolean isCanceled() {
            return renderer.renderingStopRequested;
          };
        };

    List<ZGroupLayerPainter> painters = null;
    try {
      painters = buildLayerPainters(graphics, renderer, layerId, cancellationListener);
      if (painters.isEmpty()) {
        return;
      }

      // get a comparator to find the first key to paint
      Comparator<SortKey> comparator = SortKey.buildComparator(painters.get(0).sortBy);

      // paint all the features as we can
      SortKey previousKey = null;
      while (!painters.isEmpty()) {
        SortKey smallestKey = getSmallestKey(painters, comparator);
        if (previousKey == null) {
          previousKey = smallestKey;
        } else if (comparator.compare(previousKey, smallestKey) >= 0) {
          throw new IllegalStateException(
              "The sorted rendering moved from a set of "
                  + "sort attributes, to one that's equal or greater, this is unexpected, "
                  + "bailing out to avoid an infinite loop");
        } else {
          previousKey = smallestKey;
        }

        for (Iterator it = painters.iterator(); it.hasNext(); ) {
          ZGroupLayerPainter painter = (ZGroupLayerPainter) it.next();
          painter.paintKey(smallestKey);
          // if the painter is done, close it
          if (painter.complete()) {
            painter.close();
            it.remove();
          }
        }
      }
    } finally {
      if (painters != null) {
        for (ZGroupLayerPainter painter : painters) {
          painter.close();
        }
      }
    }
  }
コード例 #5
0
 public void setSortKeys(List<? extends SortKey> keys) {
   if ((keys == null) || keys.isEmpty()) {
     setSorter(null);
     return;
   }
   SortKey sortKey = SortKey.getFirstSortingKey(keys);
   // only crappy unsorted...
   if (sortKey == null) return;
   Sorter sorter = getSorter();
   if (sorter == null) {
     sorter = createDefaultSorter();
   }
   sorter.setSortKey(sortKey);
   // technically, we could re-use the sorter
   // and only reset column, comparator and direction
   // need to detangle from TableColumn before going there...
   // so for now we only change the order if we have a sorter
   // for the given column, create a new default sorter if not
   //            if ((currentSorter == null) ||
   //                    (currentSorter.getColumnIndex() != sortKey.getColumn())) {
   //                currentSorter = createDefaultSorter(sortKey);
   //            }
   //            if (currentSorter.isAscending() != sortKey.getSortOrder().isAscending()) {
   //                currentSorter.setAscending(sortKey.getSortOrder().isAscending());
   //            }
   setSorter(sorter);
 }
コード例 #6
0
 void doApply(
     Stylesheet stylesheet,
     QName mode,
     Node context,
     int pos,
     int len,
     Node parent,
     Node nextSibling)
     throws TransformerException {
   if (children != null) {
     // Set current template to null
     Template saved = stylesheet.currentTemplate;
     stylesheet.currentTemplate = null;
     Object ret = select.evaluate(context, pos, len);
     // System.err.println(toString() + ": " + context+" -> "+ret);
     if (ret instanceof Collection) {
       Collection ns = (Collection) ret;
       List list = new ArrayList(ns);
       if (sortKeys != null) {
         for (Iterator i = sortKeys.iterator(); i.hasNext(); ) {
           SortKey sortKey = (SortKey) i.next();
           sortKey.init(stylesheet, mode, context, pos, len, parent, nextSibling);
         }
         Collections.sort(list, new XSLComparator(sortKeys));
       } else {
         Collections.sort(list, documentOrderComparator);
       }
       // Perform children for each node
       int l = list.size();
       int p = 1;
       for (Iterator i = list.iterator(); i.hasNext(); ) {
         Node node = (Node) i.next();
         stylesheet.current = node;
         children.apply(stylesheet, mode, node, p++, l, parent, nextSibling);
       }
     }
     // Restore current template
     stylesheet.currentTemplate = saved;
   }
   if (next != null) {
     next.apply(stylesheet, mode, context, pos, len, parent, nextSibling);
   }
 }
コード例 #7
0
 /**
  * {@inheritDoc}
  *
  * <p>Overridden - that is completely new implementation - to get first/next SortOrder from sort
  * order cycle. Does nothing if the cycle is empty.
  */
 @Override
 public void toggleSortOrder(int column) {
   checkColumn(column);
   if (!isSortable(column)) return;
   SortOrder firstInCycle = getFirstInCycle();
   // nothing to toggle through
   if (firstInCycle == null) return;
   List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
   SortKey sortKey = SortUtils.getFirstSortKeyForColumn(keys, column);
   if (keys.indexOf(sortKey) == 0) {
     //  primary key: in this case we'll use next sortorder in cylce
     keys.set(0, new SortKey(column, getNextInCycle(sortKey.getSortOrder())));
   } else {
     // all others: make primary with first sortOrder in cycle
     keys.remove(sortKey);
     keys.add(0, new SortKey(column, getFirstInCycle()));
   }
   if (keys.size() > getMaxSortKeys()) {
     keys = keys.subList(0, getMaxSortKeys());
   }
   setSortKeys(keys);
 }
コード例 #8
0
 /**
  * {@inheritDoc}
  *
  * <p>
  */
 @Override
 public SortOrder getSortOrder(int column) {
   SortKey key = SortUtils.getFirstSortKeyForColumn(getSortKeys(), column);
   return key != null ? key.getSortOrder() : SortOrder.UNSORTED;
 }