![]() ![]() Is there some function which provides this functionality? Second.I want to have a reversed list view on a list (in a similar way than List#sublist provides a sublist view on a list). Returns: a negative integer, zero, or a positive integer as theįirst argument is less than, equal to, or greater than the Parameters: o1 - the first object to be compared. Signum function, which is defined to return one of -1,Ġ, or 1 according to whether the value ofĮxpression is negative, zero, or positive, respectively. Sgn( expression ) designates the mathematical In the foregoing description, the notation Imposes orderings that are inconsistent with equals." The recommended language is "Note: this comparator Generally speaking,Īny comparator that violates this condition should clearly indicate It is generally the case, but not strictly required that Implies that sgn(compare(x, z))=sgn(compare(y, z)) for all ((compare(x, y)>0) & (compare(y, z)>0)) impliesįinally, the implementor must ensure that compare(x, y)=0 The implementor must also ensure that the relation is transitive: Implies that compare(x, y) must throw an exception if and only The implementor must ensure that sgn(compare(x, y)) = Zero, or a positive integer as the first argument is less than, equal Since: 1.2 See Also: Comparable,Ĭompares its two arguments for order. Unlike Comparable, a comparator may optionally permitĬomparison of null arguments, while maintaining the requirements for Relation defined by the objects' equals(Object) method(s): The ordering imposed by c on S is consistent withĮquals, we mean that the quotient for the ordering is the equivalence Quotient is an equivalence relation on S, and that the It follows immediately from the contract for compare that the Imposed ordering that a given comparator c imposes on a ![]() Order for the data structure to serialize successfully, the comparator (ifįor the mathematically inclined, the relation that defines the Serializable data structures (like TreeSet, TreeMap). Java.io.Serializable, as they may be used as ordering methods in Note: It is generally a good idea for comparators to also implement This is contrary to the specification of the True (and the size of the tree set will increase) because a andī are not equivalent from the tree set's perspective, even though Map), which is defined in terms of equals.įor example, suppose one adds two elements a and b such that Sorted set (or sorted map) will violate the general contract for set (or The sorted set (or sorted map) will behave "strangely." In particular the Ordering imposed by c on S is inconsistent with equals, Is used with elements (or keys) drawn from a set S. Suppose a sorted set (or sorted map) with an explicit comparator c Ordering inconsistent with equals to order a sorted set (or sorted map). ![]() S is said to be consistent with equals if and only ifĬ.compare(e1, e2)=0 has the same boolean value asĬaution should be exercised when using a comparator capable of imposing an The ordering imposed by a comparator c on a set of elements Objects that don't have a natural ordering. Comparators can also be used to control the order ofĬertain data structures (such as sorted sets or sorted maps), or to provide an ordering for collections of Comparators can be passed to a sort method (suchĪs Collections.sort or Arrays.sort) to allow precise control A comparison function, which imposes a total ordering on someĬollection of objects. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |