]> git.basschouten.com Git - openhab-addons.git/blob
3dfc3bc07c4bf042af69aab8c919dc15800b8868
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.unifi.internal.api.cache;
14
15 import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.HOSTNAME;
16 import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.ID;
17 import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.IP;
18 import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.MAC;
19 import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.NAME;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.unifi.internal.api.dto.UniFiClient;
24
25 /**
26  * The {@link UniFiClientCache} is a specific implementation of {@link UniFiCache} for the purpose of caching
27  * {@link UniFiClient} instances.
28  *
29  * The cache uses the following prefixes: <code>mac</code>, <code>ip</code>, <code>hostname</code>, and
30  * <code>name</code>
31  *
32  * @author Matthew Bowman - Initial contribution
33  */
34 @NonNullByDefault
35 class UniFiClientCache extends UniFiCache<UniFiClient> {
36
37     public UniFiClientCache() {
38         super(ID, MAC, IP, HOSTNAME, NAME);
39     }
40
41     @Override
42     protected @Nullable String getSuffix(final UniFiClient client, final Prefix prefix) {
43         switch (prefix) {
44             case ID:
45                 return client.getId();
46             case MAC:
47                 return client.getMac();
48             case IP:
49                 return client.getIp();
50             case HOSTNAME:
51                 return safeTidy(client.getHostname());
52             case NAME:
53                 return safeTidy(client.getName());
54             default:
55                 return null;
56         }
57     }
58
59     private static @Nullable String safeTidy(final @Nullable String value) {
60         return value == null ? null : value.trim().toLowerCase();
61     }
62 }