All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gw.lang.enhancements.CoreCollectionEnhancement.gsx Maven / Gradle / Ivy

There is a newer version: 1.18.2
Show newest version
package gw.lang.enhancements

uses java.util.Collection
uses java.lang.IllegalStateException
uses java.lang.Comparable
uses gw.util.IOrderedList
uses java.util.Comparator

/*
 *  Copyright 2014 Guidewire Software, Inc.
 */
enhancement CoreCollectionEnhancement : Collection {

  //!! The following methods are here instead of CoreIterableEnhancement because 
  //!! they otherwise interfere with IQueryResult methods.


  /**
   * Returns a lazily-computed List that consists of the elements of this Collection, ordered
   * by the value mapped to by the given block.
   */
  reified function orderBy( value(elt:T):R ) : IOrderedList {
    return orderBy(value, null)
  }
  
  /**
   * Returns a lazily-computed List that consists of the elements of this Collection, ordered
   * by the value mapped to by the given block using the specified comparator.
   */
  reified function orderBy( value(elt:T):R, comparator : Comparator ) : IOrderedList {
    if( this typeis IOrderedList ) {
      throw new IllegalStateException( "You must only call thenBy() after an orderBy()" )
    }
    var ordered = new OrderedList( this )
    ordered.addOrderBy( value, comparator )
    return ordered
  }

  /**
   * Returns a lazily-computed List that consists of the elements of this Collection, in descending order
   * by the value mapped to by the given block.
   */
  reified function orderByDescending( value(elt:T):R ) : IOrderedList {
    return orderByDescending(value, null)
  }

  /**
   * Returns a lazily-computed List that consists of the elements of this Collection, in descending order
   * by the value mapped to by the given block using the specified comparator.
   */
  reified function orderByDescending( value(elt:T):R, comparator : Comparator ) : IOrderedList {
    if( this typeis IOrderedList ) {
      throw new IllegalStateException( "You must only call thenBy() after an orderBy()" )
    }
    var ordered = new OrderedList( this )
    ordered.addOrderByDescending( value, comparator )
    return ordered
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy