util

package
v1.2.62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NaturalOrderComparator = ComparableComparatorFunc(nil)
View Source
var ReverseOrderComparator = NaturalOrderComparator.Reversed()

Functions

This section is empty.

Types

type AbstractIteratorClass

type AbstractIteratorClass struct {
	class.Class
}

func (*AbstractIteratorClass) ForEachRemaining

func (iter *AbstractIteratorClass) ForEachRemaining(ctx context.Context, action consumer.Consumer)

func (*AbstractIteratorClass) HasNext

func (iter *AbstractIteratorClass) HasNext() bool

func (*AbstractIteratorClass) Next

func (iter *AbstractIteratorClass) Next() interface{}

func (*AbstractIteratorClass) Remove

func (iter *AbstractIteratorClass) Remove()

type Comparable

type Comparable interface {
	/**
	 * Compares this object with the specified object for order.  Returns a
	 * negative integer, zero, or a positive integer as this object is less
	 * than, equal to, or greater than the specified object.
	 *
	 * <p>The implementor must ensure
	 * {@code sgn(x.compareTo(y)) == -sgn(y.compareTo(x))}
	 * for all {@code x} and {@code y}.  (This
	 * implies that {@code x.compareTo(y)} must throw an exception iff
	 * {@code y.compareTo(x)} throws an exception.)
	 *
	 * <p>The implementor must also ensure that the relation is transitive:
	 * {@code (x.compareTo(y) > 0 && y.compareTo(z) > 0)} implies
	 * {@code x.compareTo(z) > 0}.
	 *
	 * <p>Finally, the implementor must ensure that {@code x.compareTo(y)==0}
	 * implies that {@code sgn(x.compareTo(z)) == sgn(y.compareTo(z))}, for
	 * all {@code z}.
	 *
	 * <p>It is strongly recommended, but <i>not</i> strictly required that
	 * {@code (x.compareTo(y)==0) == (x.equals(y))}.  Generally speaking, any
	 * class that implements the {@code Comparable} interface and violates
	 * this condition should clearly indicate this fact.  The recommended
	 * language is "Note: this class has a natural ordering that is
	 * inconsistent with equals."
	 *
	 * <p>In the foregoing description, the notation
	 * {@code sgn(}<i>expression</i>{@code )} designates the mathematical
	 * <i>signum</i> function, which is defined to return one of {@code -1},
	 * {@code 0}, or {@code 1} according to whether the value of
	 * <i>expression</i> is negative, zero, or positive, respectively.
	 *
	 * @param   o the object to be compared.
	 * @return  a negative integer, zero, or a positive integer as this object
	 *          is less than, equal to, or greater than the specified object.
	 *
	 * @throws NullPointerException if the specified object is null
	 * @throws ClassCastException if the specified object's type prevents it
	 *         from being compared to this object.
	 */
	CompareTo(o interface{}) int
}

*

  • This interface imposes a total ordering on the objects of each class that
  • implements it. This ordering is referred to as the class's <i>natural
  • ordering</i>, and the class's {@code compareTo} method is referred to as
  • its <i>natural comparison method</i>.<p> *
  • Lists (and arrays) of objects that implement this interface can be sorted
  • automatically by {@link Collections#sort(List) Collections.sort} (and
  • {@link Arrays#sort(Object[]) Arrays.sort}). Objects that implement this
  • interface can be used as keys in a {@linkplain SortedMap sorted map} or as
  • elements in a {@linkplain SortedSet sorted set}, without the need to
  • specify a {@linkplain Comparator comparator}.<p> *
  • The natural ordering for a class {@code C} is said to be <i>consistent
  • with equals</i> if and only if {@code e1.compareTo(e2) == 0} has
  • the same boolean value as {@code e1.equals(e2)} for every
  • {@code e1} and {@code e2} of class {@code C}. Note that {@code null}
  • is not an instance of any class, and {@code e.compareTo(null)} should
  • throw a {@code NullPointerException} even though {@code e.equals(null)}
  • returns {@code false}.<p> *
  • It is strongly recommended (though not required) that natural orderings be
  • consistent with equals. This is so because sorted sets (and sorted maps)
  • without explicit comparators behave "strangely" when they are used with
  • elements (or keys) whose natural ordering is inconsistent with equals. In
  • particular, such a sorted set (or sorted map) violates the general contract
  • for set (or map), which is defined in terms of the {@code equals}
  • method.<p> *
  • For example, if one adds two keys {@code a} and {@code b} such that
  • {@code (!a.equals(b) && a.compareTo(b) == 0)} to a sorted
  • set that does not use an explicit comparator, the second {@code add}
  • operation returns false (and the size of the sorted set does not increase)
  • because {@code a} and {@code b} are equivalent from the sorted set's
  • perspective.<p> *
  • Virtually all Java core classes that implement {@code Comparable} have natural
  • orderings that are consistent with equals. One exception is
  • {@code java.math.BigDecimal}, whose natural ordering equates
  • {@code BigDecimal} objects with equal values and different precisions
  • (such as 4.0 and 4.00).<p> *
  • For the mathematically inclined, the <i>relation</i> that defines
  • the natural ordering on a given class C is:<pre>{@code
  • {(x, y) such that x.compareTo(y) <= 0}.
  • }</pre> The <i>quotient</i> for this total order is: <pre>{@code
  • {(x, y) such that x.compareTo(y) == 0}.
  • }</pre> *
  • It follows immediately from the contract for {@code compareTo} that the
  • quotient is an <i>equivalence relation</i> on {@code C}, and that the
  • natural ordering is a <i>total order</i> on {@code C}. When we say that a
  • class's natural ordering is <i>consistent with equals</i>, we mean that the
  • quotient for the natural ordering is the equivalence relation defined by
  • the class's {@link Object#equals(Object) equals(Object)} method:<pre>
  • {(x, y) such that x.equals(y)}. </pre><p> *
  • This interface is a member of the
  • <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
  • Java Collections Framework</a>. *
  • @param <T> the type of objects that this object may be compared to *
  • @author Josh Bloch
  • @see java.util.Comparator
  • @since 1.2

type ComparableComparatorFunc

type ComparableComparatorFunc func(a, b interface{}) int

func (ComparableComparatorFunc) Compare

func (f ComparableComparatorFunc) Compare(a, b interface{}) int

func (ComparableComparatorFunc) Reversed

func (f ComparableComparatorFunc) Reversed() Comparator

func (ComparableComparatorFunc) ThenComparing

func (f ComparableComparatorFunc) ThenComparing(after Comparator) Comparator

type ComparableFunc

type ComparableFunc func(o interface{}) int

func (ComparableFunc) CompareTo

func (f ComparableFunc) CompareTo(o interface{}) int

type Comparator

type Comparator interface {
	/**
	 * Compares its two arguments for order.  Returns a negative integer,
	 * zero, or a positive integer as the first argument is less than, equal
	 * to, or greater than the second.<p>
	 *
	 * The implementor must ensure that {@code sgn(compare(x, y)) ==
	 * -sgn(compare(y, x))} for all {@code x} and {@code y}.  (This
	 * implies that {@code compare(x, y)} must throw an exception if and only
	 * if {@code compare(y, x)} throws an exception.)<p>
	 *
	 * The implementor must also ensure that the relation is transitive:
	 * {@code ((compare(x, y)>0) && (compare(y, z)>0))} implies
	 * {@code compare(x, z)>0}.<p>
	 *
	 * Finally, the implementor must ensure that {@code compare(x, y)==0}
	 * implies that {@code sgn(compare(x, z))==sgn(compare(y, z))} for all
	 * {@code z}.<p>
	 *
	 * It is generally the case, but <i>not</i> strictly required that
	 * {@code (compare(x, y)==0) == (x.equals(y))}.  Generally speaking,
	 * any comparator that violates this condition should clearly indicate
	 * this fact.  The recommended language is "Note: this comparator
	 * imposes orderings that are inconsistent with equals."<p>
	 *
	 * In the foregoing description, the notation
	 * {@code sgn(}<i>expression</i>{@code )} designates the mathematical
	 * <i>signum</i> function, which is defined to return one of {@code -1},
	 * {@code 0}, or {@code 1} according to whether the value of
	 * <i>expression</i> is negative, zero, or positive, respectively.
	 *
	 * @param o1 the first object to be compared.
	 * @param o2 the second object to be compared.
	 * @return a negative integer, zero, or a positive integer as the
	 *         first argument is less than, equal to, or greater than the
	 *         second.
	 * @throws NullPointerException if an argument is null and this
	 *         comparator does not permit null arguments
	 * @throws ClassCastException if the arguments' types prevent them from
	 *         being compared by this comparator.
	 */
	Compare(a, b interface{}) int
	/**
	 * Returns a lexicographic-order comparator with another comparator.
	 * If this {@code Comparator} considers two elements equal, i.e.
	 * {@code compare(a, b) == 0}, {@code other} is used to determine the order.
	 *
	 * <p>The returned comparator is serializable if the specified comparator
	 * is also serializable.
	 *
	 * @apiNote
	 * For example, to sort a collection of {@code String} based on the length
	 * and then case-insensitive natural ordering, the comparator can be
	 * composed using following code,
	 *
	 * <pre>{@code
	 *     Comparator<String> cmp = Comparator.comparingInt(String::length)
	 *             .thenComparing(String.CASE_INSENSITIVE_ORDER);
	 * }</pre>
	 *
	 * @param  other the other comparator to be used when this comparator
	 *         compares two objects that are equal.
	 * @return a lexicographic-order comparator composed of this and then the
	 *         other comparator
	 * @throws NullPointerException if the argument is null.
	 * @since 1.8
	 */
	ThenComparing(after Comparator) Comparator

	Reversed() Comparator
}

func AlwaysEqualComparator

func AlwaysEqualComparator() Comparator

AlwaysEqualComparator returns 0 always

func DefaultComparator

func DefaultComparator() Comparator

DefaultComparator returns 0 if a == b, returns -1 otherwise

func NeverEqualComparator

func NeverEqualComparator() Comparator

NeverEqualComparator returns -1 always

func NullFirst

func NullFirst(cmp Comparator, nilFirst bool) Comparator

*

  • Returns a null-friendly comparator that considers {@code null} to be
  • less than non-null. When both are {@code null}, they are considered
  • equal. If both are non-null, the specified {@code Comparator} is used
  • to determine the order. If the specified comparator is {@code null},
  • then the returned comparator considers all non-null values to be equal. *
  • <p>The returned comparator is serializable if the specified comparator
  • is serializable. *
  • @param <T> the type of the elements to be compared
  • @param comparator a {@code Comparator} for comparing non-null values
  • @return a comparator that considers {@code null} to be less than
  • non-null, and compares non-null objects with the supplied
  • {@code Comparator}.
  • @since 1.8

type ComparatorFunc

type ComparatorFunc func(a, b interface{}) int

The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

func (ComparatorFunc) Compare

func (f ComparatorFunc) Compare(a, b interface{}) int

Compare calls f(a,b).

func (ComparatorFunc) Reversed

func (f ComparatorFunc) Reversed() Comparator

func (ComparatorFunc) ThenComparing

func (f ComparatorFunc) ThenComparing(after Comparator) Comparator

type Iterator

type Iterator interface {
	/**
	 * Returns {@code true} if the iteration has more elements.
	 * (In other words, returns {@code true} if {@link #next} would
	 * return an element rather than throwing an exception.)
	 *
	 * @return {@code true} if the iteration has more elements
	 */
	HasNext() bool
	/**
	 * Returns the next element in the iteration.
	 *
	 * @return the next element in the iteration
	 * @throws NoSuchElementException if the iteration has no more elements
	 */
	Next() interface{}

	/**
	 * Removes from the underlying collection the last element returned
	 * by this iterator (optional operation).  This method can be called
	 * only once per call to {@link #next}.
	 * <p>
	 * The behavior of an iterator is unspecified if the underlying collection
	 * is modified while the iteration is in progress in any way other than by
	 * calling this method, unless an overriding class has specified a
	 * concurrent modification policy.
	 * <p>
	 * The behavior of an iterator is unspecified if this method is called
	 * after a call to the {@link #forEachRemaining forEachRemaining} method.
	 *
	 * @implSpec
	 * The default implementation throws an instance of
	 * {@link UnsupportedOperationException} and performs no other action.
	 *
	 * @throws UnsupportedOperationException if the {@code remove}
	 *         operation is not supported by this iterator
	 *
	 * @throws IllegalStateException if the {@code next} method has not
	 *         yet been called, or the {@code remove} method has already
	 *         been called after the last call to the {@code next}
	 *         method
	 */
	Remove()

	/**
	 * Performs the given action for each remaining element until all elements
	 * have been processed or the action throws an exception.  Actions are
	 * performed in the order of iteration, if that order is specified.
	 * Exceptions thrown by the action are relayed to the caller.
	 * <p>
	 * The behavior of an iterator is unspecified if the action modifies the
	 * collection in any way (even by calling the {@link #remove remove} method
	 * or other mutator methods of {@code Iterator} subtypes),
	 * unless an overriding class has specified a concurrent modification policy.
	 * <p>
	 * Subsequent behavior of an iterator is unspecified if the action throws an
	 * exception.
	 *
	 * @implSpec
	 * <p>The default implementation behaves as if:
	 * <pre>{@code
	 *     while (hasNext())
	 *         action.accept(next());
	 * }</pre>
	 *
	 * @param action The action to be performed for each element
	 * @throws NullPointerException if the specified action is null
	 * @since 1.8
	 */
	ForEachRemaining(ctx context.Context, action consumer.Consumer)
}

type NullComparator

type NullComparator struct {
	// contains filtered or unexported fields
}

Null-friendly comparators

func NewNullComparator

func NewNullComparator(nilFirst bool, real Comparator) *NullComparator

func (*NullComparator) Compare

func (n *NullComparator) Compare(a, b interface{}) int

func (*NullComparator) Reversed

func (n *NullComparator) Reversed() Comparator

func (*NullComparator) ThenComparing

func (n *NullComparator) ThenComparing(other Comparator) Comparator

type Runnable

type Runnable interface {
	/**
	 * When an object implementing interface <code>Runnable</code> is used
	 * to create a thread, starting the thread causes the object's
	 * <code>run</code> method to be called in that separately executing
	 * thread.
	 * <p>
	 * The general contract of the method <code>run</code> is that it may
	 * take any action whatsoever.
	 *
	 * @see     java.lang.Thread#run()
	 */
	Run()
}

*

  • The <code>Runnable</code> interface should be implemented by any
  • class whose instances are intended to be executed by a thread. The
  • class must define a method of no arguments called <code>run</code>.
  • <p>
  • This interface is designed to provide a common protocol for objects that
  • wish to execute code while they are active. For example,
  • <code>Runnable</code> is implemented by class <code>Thread</code>.
  • Being active simply means that a thread has been started and has not
  • yet been stopped.
  • <p>
  • In addition, <code>Runnable</code> provides the means for a class to be
  • active while not subclassing <code>Thread</code>. A class that implements
  • <code>Runnable</code> can run without subclassing <code>Thread</code>
  • by instantiating a <code>Thread</code> instance and passing itself in
  • as the target. In most cases, the <code>Runnable</code> interface should
  • be used if you are only planning to override the <code>run()</code>
  • method and no other <code>Thread</code> methods.
  • This is important because classes should not be subclassed
  • unless the programmer intends on modifying or enhancing the fundamental
  • behavior of the class. *
  • @author Arthur van Hoff
  • @see java.lang.Thread
  • @see java.util.concurrent.Callable
  • @since 1.0

type RunnableFunc

type RunnableFunc func()

func (RunnableFunc) Run

func (f RunnableFunc) Run()

Directories

Path Synopsis
consumer
A sequence of elements supporting sequential and parallel aggregate operations.
A sequence of elements supporting sequential and parallel aggregate operations.
object consists of {@code static} utility methods for operating on objects, or checking certain conditions before operation.
object consists of {@code static} utility methods for operating on objects, or checking certain conditions before operation.
internal/preconditions
Utility methods to check if state or arguments are correct.
Utility methods to check if state or arguments are correct.
A sequence of elements supporting sequential and parallel aggregate operations.
A sequence of elements supporting sequential and parallel aggregate operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL