mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-31 11:30:39 +00:00
Add helper classes for exporting dbus properties
This commit is contained in:
parent
9839be48f3
commit
1548ce9c79
3 changed files with 147 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
package org.asamk.signal.dbus;
|
||||
|
||||
import org.asamk.Signal;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DbusInterfacePropertiesHandler {
|
||||
|
||||
private final String interfaceName;
|
||||
private final List<DbusProperty<?>> properties;
|
||||
|
||||
public DbusInterfacePropertiesHandler(
|
||||
final String interfaceName, final List<DbusProperty<?>> properties
|
||||
) {
|
||||
this.interfaceName = interfaceName;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String getInterfaceName() {
|
||||
return interfaceName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> DbusProperty<T> findProperty(String propertyName) {
|
||||
final var property = properties.stream().filter(p -> p.getName().equals(propertyName)).findFirst();
|
||||
if (property.isEmpty()) {
|
||||
throw new Signal.Error.Failure("Property not found");
|
||||
}
|
||||
return (DbusProperty<T>) property.get();
|
||||
}
|
||||
|
||||
<T> Consumer<T> getSetter(String propertyName) {
|
||||
return this.<T>findProperty(propertyName).getSetter();
|
||||
}
|
||||
|
||||
<T> Supplier<T> getGetter(String propertyName) {
|
||||
return this.<T>findProperty(propertyName).getGetter();
|
||||
}
|
||||
|
||||
Collection<DbusProperty<?>> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue