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.Supplier; 008 009/** NetworkTables generic subscriber. */ 010@SuppressWarnings("PMD.MissingOverride") 011public interface GenericSubscriber extends Subscriber, Supplier<NetworkTableValue> { 012 /** 013 * Get the corresponding topic. 014 * 015 * @return Topic 016 */ 017 @Override 018 Topic getTopic(); 019 020 /** 021 * Get the last published value. 022 * If no value has been published, returns a value with type NetworkTableType.kUnassigned. 023 * 024 * @return value 025 */ 026 NetworkTableValue get(); 027 028 /** 029 * Gets the entry's value as a boolean. If the entry does not exist or is of different type, it 030 * will return the default value. 031 * 032 * @param defaultValue the value to be returned if no value is found 033 * @return the entry's value or the given default value 034 */ 035 boolean getBoolean(boolean defaultValue); 036 037 /** 038 * Gets the entry's value as a long. If the entry does not exist or is of different type, it 039 * will return the default value. 040 * 041 * @param defaultValue the value to be returned if no value is found 042 * @return the entry's value or the given default value 043 */ 044 long getInteger(long defaultValue); 045 046 /** 047 * Gets the entry's value as a float. If the entry does not exist or is of different type, it 048 * will return the default value. 049 * 050 * @param defaultValue the value to be returned if no value is found 051 * @return the entry's value or the given default value 052 */ 053 float getFloat(float defaultValue); 054 055 /** 056 * Gets the entry's value as a double. If the entry does not exist or is of different type, it 057 * will return the default value. 058 * 059 * @param defaultValue the value to be returned if no value is found 060 * @return the entry's value or the given default value 061 */ 062 double getDouble(double defaultValue); 063 064 /** 065 * Gets the entry's value as a String. If the entry does not exist or is of different type, it 066 * will return the default value. 067 * 068 * @param defaultValue the value to be returned if no value is found 069 * @return the entry's value or the given default value 070 */ 071 String getString(String defaultValue); 072 073 /** 074 * Gets the entry's value as a byte[]. If the entry does not exist or is of different type, it 075 * will return the default value. 076 * 077 * @param defaultValue the value to be returned if no value is found 078 * @return the entry's value or the given default value 079 */ 080 byte[] getRaw(byte[] defaultValue); 081 082 /** 083 * Gets the entry's value as a boolean[]. If the entry does not exist or is of different type, it 084 * will return the default value. 085 * 086 * @param defaultValue the value to be returned if no value is found 087 * @return the entry's value or the given default value 088 */ 089 boolean[] getBooleanArray(boolean[] defaultValue); 090 091 /** 092 * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, 093 * it will return the default value. 094 * 095 * @param defaultValue the value to be returned if no value is found 096 * @return the entry's value or the given default value 097 */ 098 Boolean[] getBooleanArray(Boolean[] defaultValue); 099 100 /** 101 * Gets the entry's value as a long[]. If the entry does not exist or is of different type, it 102 * will return the default value. 103 * 104 * @param defaultValue the value to be returned if no value is found 105 * @return the entry's value or the given default value 106 */ 107 long[] getIntegerArray(long[] defaultValue); 108 109 /** 110 * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, 111 * it will return the default value. 112 * 113 * @param defaultValue the value to be returned if no value is found 114 * @return the entry's value or the given default value 115 */ 116 Long[] getIntegerArray(Long[] defaultValue); 117 118 /** 119 * Gets the entry's value as a float[]. If the entry does not exist or is of different type, it 120 * will return the default value. 121 * 122 * @param defaultValue the value to be returned if no value is found 123 * @return the entry's value or the given default value 124 */ 125 float[] getFloatArray(float[] defaultValue); 126 127 /** 128 * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, 129 * it will return the default value. 130 * 131 * @param defaultValue the value to be returned if no value is found 132 * @return the entry's value or the given default value 133 */ 134 Float[] getFloatArray(Float[] defaultValue); 135 136 /** 137 * Gets the entry's value as a double[]. If the entry does not exist or is of different type, it 138 * will return the default value. 139 * 140 * @param defaultValue the value to be returned if no value is found 141 * @return the entry's value or the given default value 142 */ 143 double[] getDoubleArray(double[] defaultValue); 144 145 /** 146 * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, 147 * it will return the default value. 148 * 149 * @param defaultValue the value to be returned if no value is found 150 * @return the entry's value or the given default value 151 */ 152 Double[] getDoubleArray(Double[] defaultValue); 153 154 /** 155 * Gets the entry's value as a String[]. If the entry does not exist or is of different type, it 156 * will return the default value. 157 * 158 * @param defaultValue the value to be returned if no value is found 159 * @return the entry's value or the given default value 160 */ 161 String[] getStringArray(String[] defaultValue); 162 163 /** 164 * Get an array of all value changes since the last call to readQueue. 165 * Also provides a timestamp for each value. 166 * 167 * <p>The "poll storage" subscribe option can be used to set the queue 168 * depth. 169 * 170 * @return Array of timestamped values; empty array if no new changes have 171 * been published since the previous call. 172 */ 173 NetworkTableValue[] readQueue(); 174}