blob: f09ecfebf670c66a1bfdba490429bf9e46cbb77c [file] [log] [blame]
Simon Hunta29c87b2015-05-21 09:56:19 -07001/*
2 * Copyright 2015 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 */
17
18package org.onosproject.cord.gui;
19
Simon Hunt41b943e2015-05-21 13:52:01 -070020import com.google.common.collect.ImmutableList;
21import org.onosproject.cord.gui.model.Bundle;
22import org.onosproject.cord.gui.model.BundleDescriptor;
23import org.onosproject.cord.gui.model.BundleFactory;
24import org.onosproject.cord.gui.model.SubscriberUser;
25
26import java.util.ArrayList;
27import java.util.List;
28
Simon Hunta29c87b2015-05-21 09:56:19 -070029/**
30 * In memory cache of the model of the subscriber's account.
31 */
32public class CordModelCache {
33
Simon Hunt41b943e2015-05-21 13:52:01 -070034 // faked for the demo
35 private static final int SUBSCRIBER_ID = 92;
36 private static final String MAC_1 = "010203040506";
37 private static final String MAC_2 = "010203040507";
38 private static final String MAC_3 = "010203040508";
39 private static final String MAC_4 = "010203040509";
40
41 private Bundle currentBundle;
42 private final List<SubscriberUser> users;
43
44 /**
45 * Constructs a model cache, initializing it with basic bundle.
46 */
47 public CordModelCache() {
48 currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
49 users = new ArrayList<SubscriberUser>();
50 initUsers();
51 }
52
53 /**
54 * Used to initialize users for the demo. These are currently fake.
55 */
56 public void initUsers() {
57 users.add(new SubscriberUser(1, "Mom's MacBook", MAC_1));
58 users.add(new SubscriberUser(2, "Dad's iPad", MAC_2));
59 users.add(new SubscriberUser(3, "Dick's laptop", MAC_3));
60 users.add(new SubscriberUser(4, "Jane's laptop", MAC_4));
61 }
62
63 /**
64 * Returns the currently selected bundle.
65 *
66 * @return current bundle
67 */
68 public Bundle getCurrentBundle() {
69 return currentBundle;
70 }
71
72 /**
73 * Sets a new bundle.
74 *
75 * @param bundleId bundle identifier
76 * @throws IllegalArgumentException if bundle ID is unknown
77 */
78 public void setCurrentBundle(String bundleId) {
79 BundleDescriptor bdesc = BundleFactory.bundleFromId(bundleId);
80 currentBundle = new Bundle(bdesc);
81 }
82
83 /**
84 * Returns the list of current users for this subscriber account.
85 *
86 * @return the list of users
87 */
88 public List<SubscriberUser> getUsers() {
89 return ImmutableList.copyOf(users);
90 }
Simon Hunta29c87b2015-05-21 09:56:19 -070091}