Eliminate HandlingPriority.CANNOT_HANDLE
[netconf.git] / protocol / netconf-server / src / main / java / org / opendaylight / netconf / server / api / operations / HandlingPriority.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.server.api.operations;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import org.eclipse.jdt.annotation.NonNull;
13
14 public record HandlingPriority(int priority) implements Comparable<HandlingPriority> {
15     public static final @NonNull HandlingPriority HANDLE_WITH_DEFAULT_PRIORITY =
16         new HandlingPriority(Integer.MIN_VALUE);
17     public static final @NonNull HandlingPriority HANDLE_WITH_MAX_PRIORITY = new HandlingPriority(Integer.MAX_VALUE);
18
19     public HandlingPriority increasePriority(final int priorityIncrease) {
20         checkArgument(priorityIncrease > 0, "Negative increase");
21         checkArgument(Long.valueOf(priority) + priorityIncrease < Integer.MAX_VALUE,
22                 "Resulting priority cannot be higher than %s", Integer.MAX_VALUE);
23         return new HandlingPriority(priority + priorityIncrease);
24     }
25
26     @Override
27     @SuppressWarnings("checkstyle:parameterName")
28     public int compareTo(final HandlingPriority o) {
29         return Integer.compare(priority, o.priority);
30     }
31 }