blob: e2bf307e71443ea328fa754257cb333207af3a1d [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
18/**
19 * Intent identifier suitable as an external key.
Thomas Vachuska4b420772014-10-30 16:46:17 -070020 * <p>This class is immutable.</p>
Brian O'Connorb876bf12014-10-02 14:59:37 -070021 */
Sho SHIMIZU591dc992015-01-20 17:35:25 -080022public final class IntentId {
Brian O'Connorb876bf12014-10-02 14:59:37 -070023
Brian O'Connor520c0522014-11-23 23:50:47 -080024 private final long value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070025
26 /**
27 * Creates an intent identifier from the specified string representation.
28 *
Brian O'Connor520c0522014-11-23 23:50:47 -080029 * @param value long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070030 * @return intent identifier
31 */
Brian O'Connor520c0522014-11-23 23:50:47 -080032 public static IntentId valueOf(long value) {
33 return new IntentId(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070034 }
35
36 /**
37 * Constructor for serializer.
38 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070039 IntentId() {
Brian O'Connor520c0522014-11-23 23:50:47 -080040 this.value = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070041 }
42
43 /**
44 * Constructs the ID corresponding to a given long value.
45 *
Brian O'Connor520c0522014-11-23 23:50:47 -080046 * @param value the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 */
Brian O'Connor520c0522014-11-23 23:50:47 -080048 IntentId(long value) {
49 this.value = value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 }
51
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080052 /**
Brian O'Connor520c0522014-11-23 23:50:47 -080053 * Returns the backing value.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080054 *
Brian O'Connor520c0522014-11-23 23:50:47 -080055 * @return the value
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080056 */
57 public long fingerprint() {
Brian O'Connor520c0522014-11-23 23:50:47 -080058 return value;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080059 }
60
Brian O'Connorb876bf12014-10-02 14:59:37 -070061 @Override
62 public int hashCode() {
Brian O'Connor520c0522014-11-23 23:50:47 -080063 return (int) (value ^ (value >>> 32));
Brian O'Connorb876bf12014-10-02 14:59:37 -070064 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (obj == this) {
69 return true;
70 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070071 if (!(obj instanceof IntentId)) {
72 return false;
73 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070074 IntentId that = (IntentId) obj;
Brian O'Connor520c0522014-11-23 23:50:47 -080075 return this.value == that.value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070076 }
77
78 @Override
79 public String toString() {
Brian O'Connor520c0522014-11-23 23:50:47 -080080 return "0x" + Long.toHexString(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070081 }
82
83}