blob: 567af95456d6d24a359db01decbbc76b8d8b9e63 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Jian Lib6d998e2016-02-29 11:41:18 -080019import org.onlab.util.Identifier;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080020import org.onosproject.net.resource.ResourceConsumer;
Brian O'Connor9476fa12015-06-25 15:17:17 -040021
Brian O'Connorb876bf12014-10-02 14:59:37 -070022/**
23 * Intent identifier suitable as an external key.
Thomas Vachuska4b420772014-10-30 16:46:17 -070024 * <p>This class is immutable.</p>
Brian O'Connorb876bf12014-10-02 14:59:37 -070025 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040026@Beta
Jian Lib6d998e2016-02-29 11:41:18 -080027public final class IntentId extends Identifier<Long> implements ResourceConsumer {
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
29 /**
Brian O'Connorb7baf712015-07-28 23:27:03 -070030 * Creates an intent identifier from the specified long representation.
Brian O'Connorb876bf12014-10-02 14:59:37 -070031 *
Brian O'Connor520c0522014-11-23 23:50:47 -080032 * @param value long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070033 * @return intent identifier
34 */
Brian O'Connor520c0522014-11-23 23:50:47 -080035 public static IntentId valueOf(long value) {
36 return new IntentId(value);
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() {
Jian Lib6d998e2016-02-29 11:41:18 -080043 super(0L);
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 }
45
46 /**
47 * Constructs the ID corresponding to a given long value.
48 *
Brian O'Connor520c0522014-11-23 23:50:47 -080049 * @param value the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 */
Brian O'Connor520c0522014-11-23 23:50:47 -080051 IntentId(long value) {
Jian Lib6d998e2016-02-29 11:41:18 -080052 super(value);
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 }
54
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080055 /**
Brian O'Connor520c0522014-11-23 23:50:47 -080056 * Returns the backing value.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080057 *
Brian O'Connor520c0522014-11-23 23:50:47 -080058 * @return the value
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080059 */
60 public long fingerprint() {
Jian Lib6d998e2016-02-29 11:41:18 -080061 return identifier;
Brian O'Connorb876bf12014-10-02 14:59:37 -070062 }
63
64 @Override
65 public String toString() {
Jian Lib6d998e2016-02-29 11:41:18 -080066 return "0x" + Long.toHexString(identifier);
Brian O'Connorb876bf12014-10-02 14:59:37 -070067 }
68
69}