]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/dbus/DbusInterfacePropertiesHandler.java
Use Java 17
[signal-cli] / src / main / java / org / asamk / signal / dbus / DbusInterfacePropertiesHandler.java
1 package org.asamk.signal.dbus;
2
3 import org.asamk.Signal;
4
5 import java.util.Collection;
6 import java.util.List;
7 import java.util.function.Consumer;
8 import java.util.function.Supplier;
9
10 public class DbusInterfacePropertiesHandler {
11
12 private final String interfaceName;
13 private final List<DbusProperty<?>> properties;
14
15 public DbusInterfacePropertiesHandler(
16 final String interfaceName, final List<DbusProperty<?>> properties
17 ) {
18 this.interfaceName = interfaceName;
19 this.properties = properties;
20 }
21
22 public String getInterfaceName() {
23 return interfaceName;
24 }
25
26 @SuppressWarnings("unchecked")
27 private <T> DbusProperty<T> findProperty(String propertyName) {
28 final var property = properties.stream().filter(p -> p.getName().equals(propertyName)).findFirst();
29 if (property.isEmpty()) {
30 throw new Signal.Error.Failure("Property not found");
31 }
32 return (DbusProperty<T>) property.get();
33 }
34
35 <T> Consumer<T> getSetter(String propertyName) {
36 return this.<T>findProperty(propertyName).getSetter();
37 }
38
39 <T> Supplier<T> getGetter(String propertyName) {
40 return this.<T>findProperty(propertyName).getGetter();
41 }
42
43 Collection<DbusProperty<?>> getProperties() {
44 return properties;
45 }
46 }