2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.concepts;
10 import com.google.common.annotations.Beta;
11 import java.util.Collection;
12 import java.util.List;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
18 * Marker interface for specifying ordering of items. There are two orderings, {@link Ordered} and {@link Unordered},
19 * and they are mutually exclusive. Item ordering is considered semantically important, such as it impacts
20 * {@link Object#equals(Object)} contract. This can be thought of as the missing interface distinction between
21 * {@link Collection}, {@link List} and {@link Set}.
23 * @param <T> Item order type
26 public interface ItemOrder<T extends ItemOrder<T>> {
28 * Items are ordered and their order is significant. A {@link List} is an example of a collection which conforms to
31 interface Ordered extends ItemOrder<Ordered> {
33 default Class<Ordered> itemOrder() {
41 * Hash code contract of {@link Ordered} objects <b>should</b> be sensitive to item order. In general similar to
42 * {@link List#hashCode()} (in the {@code must} reading of sensitivity. {@code need not} reading of sensitivity
43 * could also be implemented as {@code Map.hashCode()} in case of a map-like container.
45 // FIXME: 8.0.0: tighten 'should' to 'must'?
53 * Equality contract of {@link Ordered} objects <b>must</b> be sensitive to item order, similar to
54 * {@link List#equals(Object)}.
57 boolean equals(Object obj);
61 * Items are unordered and their order is insignificant. A {@link Set} is an example of a collection which conforms
64 interface Unordered extends ItemOrder<Unordered> {
66 default Class<Unordered> itemOrder() {
67 return Unordered.class;
74 * Hash code contract of {@link Unordered} objects <b>must</b> be insensitive to item order, similar to
75 * {@link Set#hashCode()}.
78 * This contract is also exposed through {@link #itemOrder()}.
87 * Equality contract of {@link Unordered} objects <b>must</b> be insensitive to item order, similar to
88 * {@link Set#equals(Object)}.
91 * This contract is also exposed through {@link #itemOrder()}.
94 boolean equals(Object obj);
98 * Return the item order class of this object. The class' equality contracts apply to this object's equality
101 * @return Item order class.
103 @NonNull Class<T> itemOrder();
106 * {@link ItemOrder} has impact on {@link #hashCode()}.
112 * {@link ItemOrder} has impact on {@link #equals(Object)}.
115 boolean equals(@Nullable Object obj);