blob: 8cfe6fdc46dbae50002912150ab3dfb28f8914eb [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Brian O'Connorb876bf12014-10-02 14:59:37 -070019package org.onlab.onos.net.intent;
20
Thomas Vachuska83e090e2014-10-22 14:25:35 -070021import org.onlab.onos.net.flow.BatchOperationTarget;
22
Brian O'Connorb876bf12014-10-02 14:59:37 -070023/**
24 * Intent identifier suitable as an external key.
toma1d16b62014-10-02 23:45:11 -070025 * <p/>
Brian O'Connorb876bf12014-10-02 14:59:37 -070026 * This class is immutable.
27 */
28public final class IntentId implements BatchOperationTarget {
29
Thomas Vachuskac96058a2014-10-20 23:00:16 -070030 private final long fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
32 /**
33 * Creates an intent identifier from the specified string representation.
34 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070035 * @param fingerprint long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070036 * @return intent identifier
37 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070038 public static IntentId valueOf(long fingerprint) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070039 return new IntentId(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070040 }
41
42 /**
43 * Constructor for serializer.
44 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045 IntentId() {
46 this.fingerprint = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 }
48
49 /**
50 * Constructs the ID corresponding to a given long value.
51 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070052 * @param fingerprint the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070054 IntentId(long fingerprint) {
55 this.fingerprint = fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070056 }
57
58 @Override
59 public int hashCode() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070060 return (int) (fingerprint ^ (fingerprint >>> 32));
Brian O'Connorb876bf12014-10-02 14:59:37 -070061 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (obj == this) {
66 return true;
67 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070068 if (!(obj instanceof IntentId)) {
69 return false;
70 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070071 IntentId that = (IntentId) obj;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070072 return this.fingerprint == that.fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070073 }
74
75 @Override
76 public String toString() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070077 return "0x" + Long.toHexString(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070078 }
79
80}