blob: 2718e6e62148789f05973c6f726ca2384baeb45b [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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'Connorb876bf12014-10-02 14:59:37 -070016package org.onlab.onos.net.intent;
17
Thomas Vachuska83e090e2014-10-22 14:25:35 -070018import org.onlab.onos.net.flow.BatchOperationTarget;
19
Brian O'Connorb876bf12014-10-02 14:59:37 -070020/**
21 * Intent identifier suitable as an external key.
Thomas Vachuska4b420772014-10-30 16:46:17 -070022 * <p>This class is immutable.</p>
Brian O'Connorb876bf12014-10-02 14:59:37 -070023 */
24public final class IntentId implements BatchOperationTarget {
25
Brian O'Connor520c0522014-11-23 23:50:47 -080026 private final long value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070027
28 /**
29 * Creates an intent identifier from the specified string representation.
30 *
Brian O'Connor520c0522014-11-23 23:50:47 -080031 * @param value long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070032 * @return intent identifier
33 */
Brian O'Connor520c0522014-11-23 23:50:47 -080034 public static IntentId valueOf(long value) {
35 return new IntentId(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070036 }
37
38 /**
39 * Constructor for serializer.
40 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070041 IntentId() {
Brian O'Connor520c0522014-11-23 23:50:47 -080042 this.value = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070043 }
44
45 /**
46 * Constructs the ID corresponding to a given long value.
47 *
Brian O'Connor520c0522014-11-23 23:50:47 -080048 * @param value the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070049 */
Brian O'Connor520c0522014-11-23 23:50:47 -080050 IntentId(long value) {
51 this.value = value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 }
53
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080054 /**
Brian O'Connor520c0522014-11-23 23:50:47 -080055 * Returns the backing value.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080056 *
Brian O'Connor520c0522014-11-23 23:50:47 -080057 * @return the value
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080058 */
59 public long fingerprint() {
Brian O'Connor520c0522014-11-23 23:50:47 -080060 return value;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080061 }
62
Brian O'Connorb876bf12014-10-02 14:59:37 -070063 @Override
64 public int hashCode() {
Brian O'Connor520c0522014-11-23 23:50:47 -080065 return (int) (value ^ (value >>> 32));
Brian O'Connorb876bf12014-10-02 14:59:37 -070066 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (obj == this) {
71 return true;
72 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070073 if (!(obj instanceof IntentId)) {
74 return false;
75 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070076 IntentId that = (IntentId) obj;
Brian O'Connor520c0522014-11-23 23:50:47 -080077 return this.value == that.value;
Brian O'Connorb876bf12014-10-02 14:59:37 -070078 }
79
80 @Override
81 public String toString() {
Brian O'Connor520c0522014-11-23 23:50:47 -080082 return "0x" + Long.toHexString(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070083 }
84
85}