001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.networktables; 006 007import java.util.function.Consumer; 008 009/** NetworkTables generic publisher. */ 010public interface GenericPublisher extends Publisher, Consumer<NetworkTableValue> { 011 /** 012 * Get the corresponding topic. 013 * 014 * @return Topic 015 */ 016 @Override 017 Topic getTopic(); 018 019 /** 020 * Publish a new value. 021 * 022 * @param value value to publish 023 * @return False if the topic already exists with a different type 024 */ 025 boolean set(NetworkTableValue value); 026 027 /** 028 * Publish a new value. 029 * 030 * @param value value to publish 031 * @return False if the topic already exists with a different type 032 * @throws IllegalArgumentException if the value is not a known type 033 */ 034 default boolean setValue(Object value) { 035 return setValue(value, 0); 036 } 037 038 /** 039 * Publish a new value. 040 * 041 * @param value value to publish 042 * @param time timestamp; 0 indicates current NT time should be used 043 * @return False if the topic already exists with a different type 044 * @throws IllegalArgumentException if the value is not a known type 045 */ 046 boolean setValue(Object value, long time); 047 048 /** 049 * Publish a new value. 050 * 051 * @param value value to publish 052 * @return False if the topic already exists with a different type 053 */ 054 default boolean setBoolean(boolean value) { 055 return setBoolean(value, 0); 056 } 057 058 /** 059 * Publish a new value. 060 * 061 * @param value value to publish 062 * @param time timestamp; 0 indicates current NT time should be used 063 * @return False if the topic already exists with a different type 064 */ 065 boolean setBoolean(boolean value, long time); 066 067 /** 068 * Publish a new value. 069 * 070 * @param value value to publish 071 * @return False if the topic already exists with a different type 072 */ 073 default boolean setInteger(long value) { 074 return setInteger(value, 0); 075 } 076 077 /** 078 * Publish a new value. 079 * 080 * @param value value to publish 081 * @param time timestamp; 0 indicates current NT time should be used 082 * @return False if the topic already exists with a different type 083 */ 084 boolean setInteger(long value, long time); 085 086 /** 087 * Publish a new value. 088 * 089 * @param value value to publish 090 * @return False if the topic already exists with a different type 091 */ 092 default boolean setFloat(float value) { 093 return setFloat(value, 0); 094 } 095 096 /** 097 * Publish a new value. 098 * 099 * @param value value to publish 100 * @param time timestamp; 0 indicates current NT time should be used 101 * @return False if the topic already exists with a different type 102 */ 103 boolean setFloat(float value, long time); 104 105 /** 106 * Publish a new value. 107 * 108 * @param value value to publish 109 * @return False if the topic already exists with a different type 110 */ 111 default boolean setDouble(double value) { 112 return setDouble(value, 0); 113 } 114 115 /** 116 * Publish a new value. 117 * 118 * @param value value to publish 119 * @param time timestamp; 0 indicates current NT time should be used 120 * @return False if the topic already exists with a different type 121 */ 122 boolean setDouble(double value, long time); 123 124 /** 125 * Publish a new value. 126 * 127 * @param value value to publish 128 * @return False if the topic already exists with a different type 129 */ 130 default boolean setString(String value) { 131 return setString(value, 0); 132 } 133 134 /** 135 * Publish a new value. 136 * 137 * @param value value to publish 138 * @param time timestamp; 0 indicates current NT time should be used 139 * @return False if the topic already exists with a different type 140 */ 141 boolean setString(String value, long time); 142 143 /** 144 * Publish a new value. 145 * 146 * @param value value to publish 147 * @return False if the topic already exists with a different type 148 */ 149 default boolean setRaw(byte[] value) { 150 return setRaw(value, 0); 151 } 152 153 /** 154 * Publish a new value. 155 * 156 * @param value value to publish 157 * @param time timestamp; 0 indicates current NT time should be used 158 * @return False if the topic already exists with a different type 159 */ 160 boolean setRaw(byte[] value, long time); 161 162 /** 163 * Publish a new value. 164 * 165 * @param value value to publish 166 * @return False if the topic already exists with a different type 167 */ 168 default boolean setBooleanArray(boolean[] value) { 169 return setBooleanArray(value, 0); 170 } 171 172 /** 173 * Publish a new value. 174 * 175 * @param value value to publish 176 * @param time timestamp; 0 indicates current NT time should be used 177 * @return False if the topic already exists with a different type 178 */ 179 boolean setBooleanArray(boolean[] value, long time); 180 181 /** 182 * Publish a new value. 183 * 184 * @param value value to publish 185 * @return False if the topic already exists with a different type 186 */ 187 default boolean setBooleanArray(Boolean[] value) { 188 return setBooleanArray(value, 0); 189 } 190 191 /** 192 * Publish a new value. 193 * 194 * @param value value to publish 195 * @param time timestamp; 0 indicates current NT time should be used 196 * @return False if the topic already exists with a different type 197 */ 198 boolean setBooleanArray(Boolean[] value, long time); 199 200 /** 201 * Publish a new value. 202 * 203 * @param value value to publish 204 * @return False if the topic already exists with a different type 205 */ 206 default boolean setIntegerArray(long[] value) { 207 return setIntegerArray(value, 0); 208 } 209 210 /** 211 * Publish a new value. 212 * 213 * @param value value to publish 214 * @param time timestamp; 0 indicates current NT time should be used 215 * @return False if the topic already exists with a different type 216 */ 217 boolean setIntegerArray(long[] value, long time); 218 219 /** 220 * Publish a new value. 221 * 222 * @param value value to publish 223 * @return False if the topic already exists with a different type 224 */ 225 default boolean setIntegerArray(Long[] value) { 226 return setIntegerArray(value, 0); 227 } 228 229 /** 230 * Publish a new value. 231 * 232 * @param value value to publish 233 * @param time timestamp; 0 indicates current NT time should be used 234 * @return False if the topic already exists with a different type 235 */ 236 boolean setIntegerArray(Long[] value, long time); 237 238 /** 239 * Publish a new value. 240 * 241 * @param value value to publish 242 * @return False if the topic already exists with a different type 243 */ 244 default boolean setFloatArray(float[] value) { 245 return setFloatArray(value, 0); 246 } 247 248 /** 249 * Publish a new value. 250 * 251 * @param value value to publish 252 * @param time timestamp; 0 indicates current NT time should be used 253 * @return False if the topic already exists with a different type 254 */ 255 boolean setFloatArray(float[] value, long time); 256 257 /** 258 * Publish a new value. 259 * 260 * @param value value to publish 261 * @return False if the topic already exists with a different type 262 */ 263 default boolean setFloatArray(Float[] value) { 264 return setFloatArray(value, 0); 265 } 266 267 /** 268 * Publish a new value. 269 * 270 * @param value value to publish 271 * @param time timestamp; 0 indicates current NT time should be used 272 * @return False if the topic already exists with a different type 273 */ 274 boolean setFloatArray(Float[] value, long time); 275 276 /** 277 * Publish a new value. 278 * 279 * @param value value to publish 280 * @return False if the topic already exists with a different type 281 */ 282 default boolean setDoubleArray(double[] value) { 283 return setDoubleArray(value, 0); 284 } 285 286 /** 287 * Publish a new value. 288 * 289 * @param value value to publish 290 * @param time timestamp; 0 indicates current NT time should be used 291 * @return False if the topic already exists with a different type 292 */ 293 boolean setDoubleArray(double[] value, long time); 294 295 /** 296 * Publish a new value. 297 * 298 * @param value value to publish 299 * @return False if the topic already exists with a different type 300 */ 301 default boolean setDoubleArray(Double[] value) { 302 return setDoubleArray(value, 0); 303 } 304 305 /** 306 * Publish a new value. 307 * 308 * @param value value to publish 309 * @param time timestamp; 0 indicates current NT time should be used 310 * @return False if the topic already exists with a different type 311 */ 312 boolean setDoubleArray(Double[] value, long time); 313 314 /** 315 * Publish a new value. 316 * 317 * @param value value to publish 318 * @return False if the topic already exists with a different type 319 */ 320 default boolean setStringArray(String[] value) { 321 return setStringArray(value, 0); 322 } 323 324 /** 325 * Publish a new value. 326 * 327 * @param value value to publish 328 * @param time timestamp; 0 indicates current NT time should be used 329 * @return False if the topic already exists with a different type 330 */ 331 boolean setStringArray(String[] value, long time); 332 333 /** 334 * Sets the entry's value if it does not exist. 335 * 336 * @param defaultValue the default value to set 337 * @return False if the entry exists with a different type 338 */ 339 boolean setDefault(NetworkTableValue defaultValue); 340 341 /** 342 * Sets the entry's value if it does not exist. 343 * 344 * @param defaultValue the default value to set 345 * @return False if the entry exists with a different type 346 * @throws IllegalArgumentException if the value is not a known type 347 */ 348 boolean setDefaultValue(Object defaultValue); 349 350 /** 351 * Sets the entry's value if it does not exist. 352 * 353 * @param defaultValue the default value to set 354 * @return False if the entry exists with a different type 355 */ 356 boolean setDefaultBoolean(boolean defaultValue); 357 358 /** 359 * Sets the entry's value if it does not exist. 360 * 361 * @param defaultValue the default value to set 362 * @return False if the entry exists with a different type 363 */ 364 boolean setDefaultInteger(long defaultValue); 365 366 /** 367 * Sets the entry's value if it does not exist. 368 * 369 * @param defaultValue the default value to set 370 * @return False if the entry exists with a different type 371 */ 372 boolean setDefaultFloat(float defaultValue); 373 374 /** 375 * Sets the entry's value if it does not exist. 376 * 377 * @param defaultValue the default value to set 378 * @return False if the entry exists with a different type 379 */ 380 boolean setDefaultDouble(double defaultValue); 381 382 /** 383 * Sets the entry's value if it does not exist. 384 * 385 * @param defaultValue the default value to set 386 * @return False if the entry exists with a different type 387 */ 388 boolean setDefaultString(String defaultValue); 389 390 /** 391 * Sets the entry's value if it does not exist. 392 * 393 * @param defaultValue the default value to set 394 * @return False if the entry exists with a different type 395 */ 396 boolean setDefaultRaw(byte[] defaultValue); 397 398 /** 399 * Sets the entry's value if it does not exist. 400 * 401 * @param defaultValue the default value to set 402 * @return False if the entry exists with a different type 403 */ 404 boolean setDefaultBooleanArray(boolean[] defaultValue); 405 406 boolean setDefaultBooleanArray(Boolean[] defaultValue); 407 408 /** 409 * Sets the entry's value if it does not exist. 410 * 411 * @param defaultValue the default value to set 412 * @return False if the entry exists with a different type 413 */ 414 boolean setDefaultIntegerArray(long[] defaultValue); 415 416 boolean setDefaultIntegerArray(Long[] defaultValue); 417 418 /** 419 * Sets the entry's value if it does not exist. 420 * 421 * @param defaultValue the default value to set 422 * @return False if the entry exists with a different type 423 */ 424 boolean setDefaultFloatArray(float[] defaultValue); 425 426 boolean setDefaultFloatArray(Float[] defaultValue); 427 428 /** 429 * Sets the entry's value if it does not exist. 430 * 431 * @param defaultValue the default value to set 432 * @return False if the entry exists with a different type 433 */ 434 boolean setDefaultDoubleArray(double[] defaultValue); 435 436 boolean setDefaultDoubleArray(Double[] defaultValue); 437 438 /** 439 * Sets the entry's value if it does not exist. 440 * 441 * @param defaultValue the default value to set 442 * @return False if the entry exists with a different type 443 */ 444 boolean setDefaultStringArray(String[] defaultValue); 445 446 @Override 447 default void accept(NetworkTableValue value) { 448 set(value); 449 } 450}