2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.unifi.internal.api.cache;
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;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.unifi.internal.api.dto.UniFiClient;
26 * The {@link UniFiClientCache} is a specific implementation of {@link UniFiCache} for the purpose of caching
27 * {@link UniFiClient} instances.
29 * The cache uses the following prefixes: <code>mac</code>, <code>ip</code>, <code>hostname</code>, and
32 * @author Matthew Bowman - Initial contribution
35 class UniFiClientCache extends UniFiCache<UniFiClient> {
37 public UniFiClientCache() {
38 super(ID, MAC, IP, HOSTNAME, NAME);
42 protected @Nullable String getSuffix(final UniFiClient client, final Prefix prefix) {
45 return client.getId();
47 return client.getMac();
49 return client.getIp();
51 return safeTidy(client.getHostname());
53 return safeTidy(client.getName());
59 private static @Nullable String safeTidy(final @Nullable String value) {
60 return value == null ? null : value.trim().toLowerCase();