Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Intent identifier suitable as an external key. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 20 | * <p>This class is immutable.</p> |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 21 | */ |
Sho SHIMIZU | 591dc99 | 2015-01-20 17:35:25 -0800 | [diff] [blame] | 22 | public final class IntentId { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 23 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 24 | private final long value; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Creates an intent identifier from the specified string representation. |
| 28 | * |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 29 | * @param value long value |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 30 | * @return intent identifier |
| 31 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 32 | public static IntentId valueOf(long value) { |
| 33 | return new IntentId(value); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Constructor for serializer. |
| 38 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 39 | IntentId() { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 40 | this.value = 0; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Constructs the ID corresponding to a given long value. |
| 45 | * |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 46 | * @param value the underlying value of this ID |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 48 | IntentId(long value) { |
| 49 | this.value = value; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 52 | /** |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 53 | * Returns the backing value. |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 54 | * |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 55 | * @return the value |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 56 | */ |
| 57 | public long fingerprint() { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 58 | return value; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 61 | @Override |
| 62 | public int hashCode() { |
Sho SHIMIZU | 8711451 | 2015-05-08 14:31:00 -0700 | [diff] [blame] | 63 | return Long.hashCode(value); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public boolean equals(Object obj) { |
| 68 | if (obj == this) { |
| 69 | return true; |
| 70 | } |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 71 | if (!(obj instanceof IntentId)) { |
| 72 | return false; |
| 73 | } |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 74 | IntentId that = (IntentId) obj; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 75 | return this.value == that.value; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public String toString() { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 80 | return "0x" + Long.toHexString(value); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } |