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.NonNullByDefault;
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
27 public interface ItemOrder<T extends ItemOrder<T>> {
29 * Items are ordered and their order is significant. A {@link List} is an example of a collection which conforms to
32 interface Ordered extends ItemOrder<Ordered> {
34 default Class<Ordered> itemOrder() {
42 * Hash code contract of {@link Ordered} objects <b>should</b> be sensitive to item order. In general similar to
43 * {@link List#hashCode()} (in the {@code must} reading of sensitivity. {@code need not} reading of sensitivity
44 * could also be implemented as {@code Map.hashCode()} in case of a map-like container.
46 // FIXME: 7.0.0: tighten 'should' to 'must'?
54 * Equality contract of {@link Ordered} objects <b>must</b> be sensitive to item order, similar to
55 * {@link List#equals(Object)}.
58 boolean equals(@Nullable Object obj);
62 * Items are unordered and their order is insignificant. A {@link Set} is an example of a collection which conforms
65 interface Unordered extends ItemOrder<Unordered> {
67 default Class<Unordered> itemOrder() {
68 return Unordered.class;
75 * Hash code contract of {@link Unordered} objects <b>must</b> be insensitive to item order, similar to
76 * {@link Set#hashCode()}.
79 * This contract is also exposed through {@link #itemOrder()}.
88 * Equality contract of {@link Unordered} objects <b>must</b> be insensitive to item order, similar to
89 * {@link Set#equals(Object)}.
92 * This contract is also exposed through {@link #itemOrder()}.
95 boolean equals(@Nullable Object obj);
99 * Return the item order class of this object. The class' equality contracts apply to this object's equality
102 * @return Item order class.
104 Class<T> itemOrder();
107 * {@link ItemOrder} has impact on {@link #hashCode()}.
113 * {@link ItemOrder} has impact on {@link #equals(Object)}.
116 boolean equals(@Nullable Object obj);