blob: c4c27524a79f757df2ab0102548c542e09bb69ab [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
Thomas Vachuskac96058a2014-10-20 23:00:16 -070026 private final long fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070027
28 /**
29 * Creates an intent identifier from the specified string representation.
30 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070031 * @param fingerprint long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070032 * @return intent identifier
33 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070034 public static IntentId valueOf(long fingerprint) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070035 return new IntentId(fingerprint);
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() {
42 this.fingerprint = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070043 }
44
45 /**
46 * Constructs the ID corresponding to a given long value.
47 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070048 * @param fingerprint the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070049 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070050 IntentId(long fingerprint) {
51 this.fingerprint = fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 }
53
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080054 /**
55 * Returns the backing fingerprint.
56 *
57 * @return the fingerprint
58 */
59 public long fingerprint() {
60 return fingerprint;
61 }
62
Brian O'Connorb876bf12014-10-02 14:59:37 -070063 @Override
64 public int hashCode() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070065 return (int) (fingerprint ^ (fingerprint >>> 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;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070077 return this.fingerprint == that.fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070078 }
79
80 @Override
81 public String toString() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070082 return "0x" + Long.toHexString(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070083 }
84
85}