// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package edu.wpi.first.networktables; import java.util.function.Consumer; /** NetworkTables generic publisher. */ public interface GenericPublisher extends Publisher, Consumer { /** * Get the corresponding topic. * * @return Topic */ @Override Topic getTopic(); /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ boolean set(NetworkTableValue value); /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type * @throws IllegalArgumentException if the value is not a known type */ default boolean setValue(Object value) { return setValue(value, 0); } /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type * @throws IllegalArgumentException if the value is not a known type */ boolean setValue(Object value, long time); {% for t in types %} /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ default boolean set{{ t.TypeName }}({{ t.java.ValueType }} value) { return set{{ t.TypeName }}(value, 0); } /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ boolean set{{ t.TypeName }}({{ t.java.ValueType }} value, long time); {% if t.java.WrapValueType %} /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ default boolean set{{ t.TypeName }}({{ t.java.WrapValueType }} value) { return set{{ t.TypeName }}(value, 0); } /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ boolean set{{ t.TypeName }}({{ t.java.WrapValueType }} value, long time); {% endif -%} {% endfor %} /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type */ boolean setDefault(NetworkTableValue defaultValue); /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type * @throws IllegalArgumentException if the value is not a known type */ boolean setDefaultValue(Object defaultValue); {% for t in types %} /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type */ boolean setDefault{{ t.TypeName }}({{ t.java.ValueType }} defaultValue); {% if t.java.WrapValueType %} boolean setDefault{{ t.TypeName }}({{ t.java.WrapValueType }} defaultValue); {% endif -%} {% endfor %} @Override default void accept(NetworkTableValue value) { set(value); } }