blob: b9a30d2d59caf5f99aadf2906e117da80c61d4d0 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070019import org.onosproject.net.newresource.ResourceConsumer;
Brian O'Connor9476fa12015-06-25 15:17:17 -040020
Brian O'Connorb876bf12014-10-02 14:59:37 -070021/**
22 * Intent identifier suitable as an external key.
Thomas Vachuska4b420772014-10-30 16:46:17 -070023 * <p>This class is immutable.</p>
Brian O'Connorb876bf12014-10-02 14:59:37 -070024 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040025@Beta
Sho SHIMIZUabd849c2015-07-14 09:14:12 -070026public final class IntentId implements ResourceConsumer {
Brian O'Connorb876bf12014-10-02 14:59:37 -070027
Brian O'Connor520c0522014-11-23 23:50:47 -080028 private final long value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070029
30 /**
Brian O'Connorb7baf712015-07-28 23:27:03 -070031 * Creates an intent identifier from the specified long representation.
Brian O'Connorb876bf12014-10-02 14:59:37 -070032 *
Brian O'Connor520c0522014-11-23 23:50:47 -080033 * @param value long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070034 * @return intent identifier
35 */
Brian O'Connor520c0522014-11-23 23:50:47 -080036 public static IntentId valueOf(long value) {
37 return new IntentId(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070038 }
39
40 /**
41 * Constructor for serializer.
42 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070043 IntentId() {
Brian O'Connor520c0522014-11-23 23:50:47 -080044 this.value = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070045 }
46
47 /**
48 * Constructs the ID corresponding to a given long value.
49 *
Brian O'Connor520c0522014-11-23 23:50:47 -080050 * @param value the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070051 */
Brian O'Connor520c0522014-11-23 23:50:47 -080052 IntentId(long value) {
53 this.value = value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070054 }
55
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080056 /**
Brian O'Connor520c0522014-11-23 23:50:47 -080057 * Returns the backing value.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080058 *
Brian O'Connor520c0522014-11-23 23:50:47 -080059 * @return the value
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080060 */
61 public long fingerprint() {
Brian O'Connor520c0522014-11-23 23:50:47 -080062 return value;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080063 }
64
Brian O'Connorb876bf12014-10-02 14:59:37 -070065 @Override
66 public int hashCode() {
Sho SHIMIZU87114512015-05-08 14:31:00 -070067 return Long.hashCode(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070068 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (obj == this) {
73 return true;
74 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 if (!(obj instanceof IntentId)) {
76 return false;
77 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070078 IntentId that = (IntentId) obj;
Brian O'Connor520c0522014-11-23 23:50:47 -080079 return this.value == that.value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070080 }
81
82 @Override
83 public String toString() {
Brian O'Connor520c0522014-11-23 23:50:47 -080084 return "0x" + Long.toHexString(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070085 }
86
87}