blob: cd75e6f88b847ea7cbfd0f1a0d832d1390a9746d [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.
toma1d16b62014-10-02 23:45:11 -070022 * <p/>
Brian O'Connorb876bf12014-10-02 14:59:37 -070023 * This class is immutable.
24 */
25public final class IntentId implements BatchOperationTarget {
26
Thomas Vachuskac96058a2014-10-20 23:00:16 -070027 private final long fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
29 /**
30 * Creates an intent identifier from the specified string representation.
31 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070032 * @param fingerprint long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070033 * @return intent identifier
34 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070035 public static IntentId valueOf(long fingerprint) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070036 return new IntentId(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070037 }
38
39 /**
40 * Constructor for serializer.
41 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070042 IntentId() {
43 this.fingerprint = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 }
45
46 /**
47 * Constructs the ID corresponding to a given long value.
48 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070049 * @param fingerprint the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070051 IntentId(long fingerprint) {
52 this.fingerprint = fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 }
54
55 @Override
56 public int hashCode() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070057 return (int) (fingerprint ^ (fingerprint >>> 32));
Brian O'Connorb876bf12014-10-02 14:59:37 -070058 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (obj == this) {
63 return true;
64 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070065 if (!(obj instanceof IntentId)) {
66 return false;
67 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070068 IntentId that = (IntentId) obj;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070069 return this.fingerprint == that.fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070070 }
71
72 @Override
73 public String toString() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070074 return "0x" + Long.toHexString(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 }
76
77}