RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
TunableLong.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.tunable;
6
7import java.util.function.LongConsumer;
8import java.util.function.LongSupplier;
9
11public abstract class TunableLong extends TunableBase implements LongSupplier, LongConsumer {
17 public static TunableLong create() {
18 return create(0);
19 }
20
27 public static TunableLong create(long initialValue) {
28 return createConfig(initialValue, null);
29 }
30
40 public static TunableLong create(LongSupplier getter, LongConsumer setter) {
41 return createConfig(getter, setter, null);
42 }
43
50 public static TunableLong createConfig(TunableConfig config) {
51 return createConfig(0, config);
52 }
53
61 public static TunableLong createConfig(long initialValue, TunableConfig config) {
62 return new TunableLong(config, true) {
63 @Override
64 public void set(long value) {
65 if (m_value == value) {
66 return;
67 }
68 m_value = value;
70 }
71
72 @Override
73 public long get() {
74 return m_value;
75 }
76
77 private long m_value = initialValue;
78 };
79 }
80
92 LongSupplier getter, LongConsumer setter, TunableConfig config) {
93 if (config == null) {
95 } else if (config.getPolling() == TunableConfig.Polling.DEFAULT) {
97 }
98 return new TunableLong(config, true) {
99 @Override
100 public void set(long value) {
101 boolean changed = getter.getAsLong() != value;
102 if (setter != null) {
103 setter.accept(value);
104 }
105 if (changed) {
106 markChanged();
107 }
108 }
109
110 @Override
111 public long get() {
112 return getter.getAsLong();
113 }
114 };
115 }
116
122 protected TunableLong(TunableConfig config) {
123 super(config);
124 }
125
133 super(config, supportsChangeNotification);
134 }
135
143 public abstract void set(long value);
144
152 public abstract long get();
153
154 @Override
155 public long getAsLong() {
156 return get();
157 }
158
159 @Override
160 public void accept(long value) {
161 set(value);
162 }
163}
TunableBase(TunableConfig config)
TunableConfig withPolling(Polling polling)
static TunableConfig of(TunableOption... options)
static TunableLong createConfig(TunableConfig config)
static TunableLong create()
TunableLong(TunableConfig config)
static TunableLong createConfig(LongSupplier getter, LongConsumer setter, TunableConfig config)
static TunableLong create(LongSupplier getter, LongConsumer setter)
static TunableLong createConfig(long initialValue, TunableConfig config)
TunableLong(TunableConfig config, boolean supportsChangeNotification)
static TunableLong create(long initialValue)