2 * Copyright (c) 2013 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.netconf.mapping.api;
11 import com.google.common.base.Optional;
13 public class HandlingPriority implements Comparable<HandlingPriority> {
15 public static final HandlingPriority CANNOT_HANDLE = new HandlingPriority();
16 public static final HandlingPriority HANDLE_WITH_DEFAULT_PRIORITY = new HandlingPriority(Integer.MIN_VALUE);
17 public static final HandlingPriority HANDLE_WITH_MAX_PRIORITY = new HandlingPriority(Integer.MAX_VALUE);
19 private Integer priority;
21 public static HandlingPriority getHandlingPriority(int priority) {
22 return new HandlingPriority(priority);
25 private HandlingPriority(int priority) {
26 this.priority = priority;
29 private HandlingPriority() {
33 * @return priority number or Optional.absent otherwise
35 public Optional<Integer> getPriority() {
36 return Optional.of(priority).or(Optional.<Integer> absent());
40 public int compareTo(HandlingPriority o) {
43 if (this == CANNOT_HANDLE)
45 if (o == CANNOT_HANDLE)
48 if (priority > o.priority)
50 if (priority == o.priority)
52 if (priority < o.priority)
55 throw new IllegalStateException("Unexpected state");
59 public boolean equals(Object o) {
62 if (!(o instanceof HandlingPriority))
65 HandlingPriority that = (HandlingPriority) o;
67 if (priority != null ? !priority.equals(that.priority) : that.priority != null)
74 public int hashCode() {
75 return priority != null ? priority.hashCode() : 0;