Simon Hunt | a29c87b | 2015-05-21 09:56:19 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package org.onosproject.cord.gui; |
| 19 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame^] | 20 | import com.google.common.collect.ImmutableList; |
| 21 | import org.onosproject.cord.gui.model.Bundle; |
| 22 | import org.onosproject.cord.gui.model.BundleDescriptor; |
| 23 | import org.onosproject.cord.gui.model.BundleFactory; |
| 24 | import org.onosproject.cord.gui.model.SubscriberUser; |
| 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
Simon Hunt | a29c87b | 2015-05-21 09:56:19 -0700 | [diff] [blame] | 29 | /** |
| 30 | * In memory cache of the model of the subscriber's account. |
| 31 | */ |
| 32 | public class CordModelCache { |
| 33 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame^] | 34 | // 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 Hunt | a29c87b | 2015-05-21 09:56:19 -0700 | [diff] [blame] | 91 | } |