/** * Tests if the specified values should be grouped together. * * @param sourceIndex0 the first index of the source list to test * @param sourceIndex1 the second index of the source list to test * * @return true iff the values at the specified index are equal according * to the Comparator which defines the grouping logic; false if * either index is out of range or the values shall not be grouped */ private boolean groupTogether(int sourceIndex0, int sourceIndex1) { if(sourceIndex0 < 0 || sourceIndex0 >= sortedList.size()) return false; if(sourceIndex1 < 0 || sourceIndex1 >= sortedList.size()) return false; return comparator.compare(sortedList.get(sourceIndex0), sortedList.get(sourceIndex1)) == 0; }
/** * Tests if the specified values should be grouped together. * * @param sourceIndex0 the first index of the source list to test * @param sourceIndex1 the second index of the source list to test * * @return true iff the values at the specified index are equal according * to the Comparator which defines the grouping logic; false if * either index is out of range or the values shall not be grouped */ private boolean groupTogether(int sourceIndex0, int sourceIndex1) { if(sourceIndex0 < 0 || sourceIndex0 >= sortedList.size()) return false; if(sourceIndex1 < 0 || sourceIndex1 >= sortedList.size()) return false; return comparator.compare(sortedList.get(sourceIndex0), sortedList.get(sourceIndex1)) == 0; }
/** * Tests if the specified values should be grouped together. * * @param sourceIndex0 the first index of the source list to test * @param sourceIndex1 the second index of the source list to test * * @return true iff the values at the specified index are equal according * to the Comparator which defines the grouping logic; false if * either index is out of range or the values shall not be grouped */ private boolean groupTogether(int sourceIndex0, int sourceIndex1) { if(sourceIndex0 < 0 || sourceIndex0 >= sortedList.size()) return false; if(sourceIndex1 < 0 || sourceIndex1 >= sortedList.size()) return false; return comparator.compare(sortedList.get(sourceIndex0), sortedList.get(sourceIndex1)) == 0; }
/** * Returns the index in this list of the first occurrence of the specified * element, or the index where that element would be in the list if it were * inserted. * * @return the index in this list of the first occurrence of the specified * element, or the index where that element would be in the list if it * were inserted. This will return a value in <tt>[0, size()]</tt>, * inclusive. * * @deprecated Deprecated as of 12/11/2005. Replaced with {@link #sortIndex(Object)} * which has cleaner semantics. */ public int indexOfSimulated(Object object) { return comparator != null ? ((SimpleTree)sorted).indexOfValue(object, true, true, ALL_COLORS) : size(); }
/** * Returns the index in this list of the first occurrence of the specified * element, or the index where that element would be in the list if it were * inserted. * * @return the index in this list of the first occurrence of the specified * element, or the index where that element would be in the list if it * were inserted. This will return a value in <tt>[0, size()]</tt>, * inclusive. * * @deprecated Deprecated as of 12/11/2005. Replaced with {@link #sortIndex(Object)} * which has cleaner semantics. */ @Deprecated public int indexOfSimulated(Object object) { return comparator != null ? ((SimpleTree)sorted).indexOfValue(object, true, true, ALL_COLORS) : size(); }
/** * Returns the index in this list of the first occurrence of the specified * element, or the index where that element would be in the list if it were * inserted. * * @return the index in this list of the first occurrence of the specified * element, or the index where that element would be in the list if it * were inserted. This will return a value in <tt>[0, size()]</tt>, * inclusive. * * @deprecated Deprecated as of 12/11/2005. Replaced with {@link #sortIndex(Object)} * which has cleaner semantics. */ public int indexOfSimulated(Object object) { return comparator != null ? ((SimpleTree)sorted).indexOfValue(object, true, true, ALL_COLORS) : size(); }
/** {@inheritDoc} */ @Override public int getEndIndex() { // search for the upperThreshold value int index = sortedSource.lastSortIndex(new Integer(upperThreshold)); // if the upperThreshold exists in the sortedSource, convert the exclusive index to an inclusive index if (index < sortedSource.size() && evaluator.evaluate(sortedSource.get(index)) == upperThreshold) index++; return index; }
/** {@inheritDoc} */ @Override public int getEndIndex() { // search for the upperThreshold value int index = sortedSource.lastSortIndex(new Integer(upperThreshold)); // if the upperThreshold exists in the sortedSource, convert the exclusive index to an inclusive index if (index < sortedSource.size() && evaluator.evaluate(sortedSource.get(index)) == upperThreshold) index++; return index; }
/** {@inheritDoc} */ @Override public int getEndIndex() { // search for the upperThreshold value int index = sortedSource.lastSortIndex(new Integer(upperThreshold)); // if the upperThreshold exists in the sortedSource, convert the exclusive index to an inclusive index if (index < sortedSource.size() && evaluator.evaluate(sortedSource.get(index)) == upperThreshold) index++; return index; }
/** * Set the comparator used to determine which elements are grouped together. As * a consequence this will rebuild the grouping state. */ public void setComparator(Comparator<? super E> comparator) { if(this.comparator == comparator) return; this.comparator = comparator; // Populate the barcode by examining adjacent entries within the // source SortedList to check if they belong to the same group. barcode = new Barcode(); for (int i = 0, n = sortedList.size(); i < n; i++) { barcode.add(i, groupTogether(i, i-1) ? DUPLICATE : UNIQUE, 1); } }
/** * Set the comparator used to determine which elements are grouped together. As * a consequence this will rebuild the grouping state. */ public void setComparator(Comparator<? super E> comparator) { if(this.comparator == comparator) return; this.comparator = comparator; // Populate the barcode by examining adjacent entries within the // source SortedList to check if they belong to the same group. barcode = new Barcode(); for (int i = 0, n = sortedList.size(); i < n; i++) { barcode.add(i, groupTogether(i, i-1) ? DUPLICATE : UNIQUE, 1); } }
/** * Set the comparator used to determine which elements are grouped together. As * a consequence this will rebuild the grouping state. */ public void setComparator(Comparator<? super E> comparator) { if(this.comparator == comparator) return; this.comparator = comparator; // Populate the barcode by examining adjacent entries within the // source SortedList to check if they belong to the same group. barcode = new Barcode(); for (int i = 0, n = sortedList.size(); i < n; i++) { barcode.add(i, groupTogether(i, i-1) ? DUPLICATE : UNIQUE, 1); } }
/** {@inheritDoc} */ @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); // use the fact that we have sorted data to quickly locate a position // at which we can begin a linear search for an object that .equals(object) int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); // if we couldn't use the comparator to find the index, return -1 if (index == -1) return -1; // otherwise, we must now begin a linear search for the index of an element // that .equals() the given object for (; index < size(); index++) { E objectAtIndex = get(index); // if the objectAtIndex no longer compares equally with the given object, stop the linear search if (comparator.compare((E)object, objectAtIndex) != 0) return -1; // if the objectAtIndex and object are equal, return the index if (GlazedListsImpl.equal(object, objectAtIndex)) return index; } // if we fall out of the loop we could not locate the object return -1; }
/** {@inheritDoc} */ @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); // use the fact that we have sorted data to quickly locate a position // at which we can begin a linear search for an object that .equals(object) int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); // if we couldn't use the comparator to find the index, return -1 if (index == -1) return -1; // otherwise, we must now begin a linear search for the index of an element // that .equals() the given object for (; index < size(); index++) { E objectAtIndex = get(index); // if the objectAtIndex no longer compares equally with the given object, stop the linear search if (comparator.compare((E)object, objectAtIndex) != 0) return -1; // if the objectAtIndex and object are equal, return the index if (GlazedListsImpl.equal(object, objectAtIndex)) return index; } // if we fall out of the loop we could not locate the object return -1; }
/** {@inheritDoc} */ @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return source.indexOf(object); // use the fact that we have sorted data to quickly locate a position // at which we can begin a linear search for an object that .equals(object) int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); // if we couldn't use the comparator to find the index, return -1 if (index == -1) return -1; // otherwise, we must now begin a linear search for the index of an element // that .equals() the given object for (; index < size(); index++) { E objectAtIndex = get(index); // if the objectAtIndex no longer compares equally with the given object, stop the linear search if (comparator.compare((E)object, objectAtIndex) != 0) return -1; // if the objectAtIndex and object are equal, return the index if (GlazedListsImpl.equal(object, objectAtIndex)) return index; } // if we fall out of the loop we could not locate the object return -1; }
assertEquals( 3, sorted.size() ); assertEquals( 1, ((Cheese)sorted.get( 0 ).get( "stilton" )).getPrice() ); assertEquals( 2, ((Cheese)sorted.get( 1 ).get( "stilton" )).getPrice() ); ksession.fireAllRules(); assertEquals( 2, sorted.size() ); assertEquals( 1, ((Cheese)sorted.get( 0 ).get( "stilton" )).getPrice() ); assertEquals( 2, ((Cheese)sorted.get( 1 ).get( "stilton" )).getPrice() ); assertEquals( 3, sorted.size() ); assertEquals( 1, ((Cheese)sorted.get( 0 ).get( "stilton" )).getPrice() ); assertEquals( 2, ((Cheese)sorted.get( 1 ).get( "stilton" )).getPrice() ); assertEquals( 2, sorted.size() ); assertEquals( 1, ((Cheese)sorted.get( 0 ).get( "stilton" )).getPrice() ); assertEquals( 3, ((Cheese)sorted.get( 1 ).get( "stilton" )).getPrice() ); assertEquals( 3, sorted.size() ); assertEquals( 1, ((Cheese)sorted.get( 0 ).get( "stilton" )).getPrice() ); assertEquals( 3, ((Cheese)sorted.get( 1 ).get( "stilton" )).getPrice() ); assertEquals( 2, sorted.size() ); assertEquals( 3, ((Cheese)sorted.get( 0 ).get( "stilton" )).getPrice() ); assertEquals( 4, ((Cheese)sorted.get( 1 ).get( "stilton" )).getPrice() ); assertEquals( 0, sorted.size() );
for (int i = 0; i < sortedEpisodes.size(); i++) { TvShowEpisodeChooserModel model = sortedEpisodes.get(i); if (equals(TvShowEpisodeAndSeasonParser.cleanEpisodeTitle(episode.getVideoBasenameWithoutStacking(), episode.getTvShow().getTitle()), for (int i = 0; i < sortedEpisodes.size(); i++) { TvShowEpisodeChooserModel model = sortedEpisodes.get(i); if (equals(TvShowEpisodeAndSeasonParser.cleanEpisodeTitle(episode.getTitle(), episode.getTvShow().getTitle()), model.getTitle())) {
int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) {
int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) {
int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) {