blob: 59ffe3a3c43fc500260e2f7da390b608fd14d799 [file] [log] [blame]
Thomas Vachuska1eff3a62016-05-03 01:07:24 -07001/*
2 * Copyright 2016 Open Networking Laboratory
3 *
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
7 *
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.
15 */
16
17package org.onlab.warden;
18
19import static com.google.common.base.Preconditions.checkState;
20
21/**
22 * Cell reservation record.
23 */
24final class Reservation {
25
26 final String cellName;
27 final String userName;
28 final long time;
29 final int duration;
30
31 // Creates a new reservation record
32 Reservation(String cellName, String userName, long time, int duration) {
33 this.cellName = cellName;
34 this.userName = userName;
35 this.time = time;
36 this.duration = duration;
37 }
38
39 /**
40 * Decodes reservation record from the specified line.
41 *
42 * @param line string line
43 */
44 Reservation(String line) {
45 String[] fields = line.trim().split("\t");
46 checkState(fields.length == 4, "Incorrect reservation encoding");
47 this.cellName = fields[0];
48 this.userName = fields[1];
49 this.time = Long.parseLong(fields[2]);
50 this.duration = Integer.parseInt(fields[3]);
51 }
52
53 /**
54 * Encodes reservation record into a string line.
55 *
56 * @return encoded string
57 */
58 String encode() {
59 return String.format("%s\t%s\t%s\t%s\n", cellName, userName, time, duration);
60 }
61
62}