_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q22800
HttpRequestBuilder.addHeader
train
public HttpRequestBuilder addHeader(String name, String value) { if (value != null) { reqHeaders.put(name, value); } return this; }
java
{ "resource": "" }
q22801
Optimizer.optimize
train
static Matcher optimize(Matcher matcher) { Matcher m = matcher; Matcher opt = optimizeSinglePass(m); for (int i = 0; !m.equals(opt) && i < MAX_ITERATIONS; ++i) { m = opt; opt = optimizeSinglePass(m); } return opt; }
java
{ "resource": "" }
q22802
Optimizer.mergeNext
train
static Matcher mergeNext(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); List<Matcher> ms = new ArrayList<>(); for (int i = 0; i < matchers.size(); ++i) { Matcher m = matchers.get(i); if (m instanceof GreedyMatch...
java
{ "resource": "" }
q22803
Optimizer.removeTrueInSequence
train
static Matcher removeTrueInSequence(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); List<Matcher> ms = new ArrayList<>(); for (Matcher m : matchers) { if (!(m instanceof TrueMatcher)) { ms.add(m); } ...
java
{ "resource": "" }
q22804
Optimizer.sequenceWithFalseIsFalse
train
static Matcher sequenceWithFalseIsFalse(Matcher matcher) { if (matcher instanceof SeqMatcher) { for (Matcher m : matcher.<SeqMatcher>as().matchers()) { if (m instanceof FalseMatcher) { return FalseMatcher.INSTANCE; } } } return matcher; }
java
{ "resource": "" }
q22805
Optimizer.sequenceWithStuffAfterEndIsFalse
train
static Matcher sequenceWithStuffAfterEndIsFalse(Matcher matcher) { if (matcher instanceof SeqMatcher) { boolean end = false; for (Matcher m : matcher.<SeqMatcher>as().matchers()) { if (m instanceof EndMatcher) { end = true; } else if (end && !m.alwaysMatches()) { retu...
java
{ "resource": "" }
q22806
Optimizer.convertEmptyCharClassToFalse
train
static Matcher convertEmptyCharClassToFalse(Matcher matcher) { if (matcher instanceof CharClassMatcher) { return matcher.<CharClassMatcher>as().set().isEmpty() ? FalseMatcher.INSTANCE : matcher; } return matcher; }
java
{ "resource": "" }
q22807
Optimizer.inlineMatchAnyPrecedingOr
train
static Matcher inlineMatchAnyPrecedingOr(Matcher matcher) { if (matcher instanceof ZeroOrMoreMatcher) { ZeroOrMoreMatcher zm = matcher.as(); if (zm.repeated() instanceof AnyMatcher && zm.next() instanceof OrMatcher) { List<Matcher> matchers = zm.next().<OrMatcher>as().matchers(); List<Ma...
java
{ "resource": "" }
q22808
Optimizer.startsWithCharSeq
train
static Matcher startsWithCharSeq(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); if (matchers.size() >= 2 && matchers.get(0) instanceof StartMatcher && matchers.get(1) instanceof CharSeqMatcher) { List<Matc...
java
{ "resource": "" }
q22809
Optimizer.combineCharSeqAfterStartsWith
train
static Matcher combineCharSeqAfterStartsWith(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); if (matchers.size() >= 2 && matchers.get(0) instanceof StartsWithMatcher && matchers.get(1) instanceof CharSeqMatcher) { ...
java
{ "resource": "" }
q22810
Optimizer.combineCharSeqAfterIndexOf
train
static Matcher combineCharSeqAfterIndexOf(Matcher matcher) { if (matcher instanceof IndexOfMatcher) { IndexOfMatcher m = matcher.as(); Matcher next = PatternUtils.head(m.next()); if (next instanceof CharSeqMatcher) { String pattern = m.pattern() + next.<CharSeqMatcher>as().pattern(); ...
java
{ "resource": "" }
q22811
Optimizer.combineAdjacentCharSeqs
train
static Matcher combineAdjacentCharSeqs(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); List<Matcher> ms = new ArrayList<>(); CharSeqMatcher cs1 = null; for (Matcher m : matchers) { if (m instanceof CharSeqMatcher) ...
java
{ "resource": "" }
q22812
Optimizer.removeRepeatedStart
train
static Matcher removeRepeatedStart(Matcher matcher) { if (matcher instanceof ZeroOrMoreMatcher) { ZeroOrMoreMatcher zm = matcher.as(); if (zm.repeated() instanceof StartMatcher) { return zm.next(); } } return matcher; }
java
{ "resource": "" }
q22813
Optimizer.combineAdjacentStart
train
static Matcher combineAdjacentStart(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); if (!matchers.isEmpty() && matchers.get(0) instanceof StartMatcher) { List<Matcher> ms = new ArrayList<>(); ms.add(StartMatcher.INSTAN...
java
{ "resource": "" }
q22814
MetricsController.getDefaultMeasurementFilter
train
public Predicate<Measurement> getDefaultMeasurementFilter() throws IOException { if (defaultMeasurementFilter != null) { return defaultMeasurementFilter; } if (!prototypeFilterPath.isEmpty()) { defaultMeasurementFilter = PrototypeMeasurementFilter.loadFromPath( prototypeFilterPath); ...
java
{ "resource": "" }
q22815
MetricsController.encodeRegistry
train
Map<String, MetricValues> encodeRegistry( Registry sourceRegistry, Predicate<Measurement> filter) { Map<String, MetricValues> metricMap = new HashMap<>(); /* * Flatten the meter measurements into a map of measurements keyed by * the name and mapped to the different tag variants. */ f...
java
{ "resource": "" }
q22816
MetricsController.meterToKind
train
public static String meterToKind(Registry registry, Meter meter) { String kind; if (meter instanceof Timer) { kind = "Timer"; } else if (meter instanceof Counter) { kind = "Counter"; } else if (meter instanceof Gauge) { kind = "Gauge"; } else if (meter instanceof DistributionSummar...
java
{ "resource": "" }
q22817
HttpResponse.header
train
public String header(String k) { List<String> vs = headers.get(k); return (vs == null || vs.isEmpty()) ? null : vs.get(0); }
java
{ "resource": "" }
q22818
HttpResponse.dateHeader
train
public Instant dateHeader(String k) { String d = header(k); return (d == null) ? null : parseDate(d); }
java
{ "resource": "" }
q22819
HttpResponse.decompress
train
public HttpResponse decompress() throws IOException { String enc = header("Content-Encoding"); return (enc != null && enc.contains("gzip")) ? unzip() : this; }
java
{ "resource": "" }
q22820
Agent.loadConfig
train
static Config loadConfig(String userResources) { Config config = ConfigFactory.load("agent"); if (userResources != null && !"".equals(userResources)) { for (String userResource : userResources.split("[,\\s]+")) { if (userResource.startsWith("file:")) { File file = new File(userResource.s...
java
{ "resource": "" }
q22821
Agent.premain
train
public static void premain(String arg, Instrumentation instrumentation) throws Exception { // Setup logging Config config = loadConfig(arg); LOGGER.debug("loaded configuration: {}", config.root().render()); createDependencyProperties(config); // Setup Registry AtlasRegistry registry = new Atlas...
java
{ "resource": "" }
q22822
JmxMeasurementConfig.from
train
static JmxMeasurementConfig from(Config config) { String name = config.getString("name"); Map<String, String> tags = config.getConfigList("tags") .stream() .collect(Collectors.toMap(c -> c.getString("key"), c -> c.getString("value"))); String value = config.getString("value"); boolean co...
java
{ "resource": "" }
q22823
HttpUtils.gzip
train
static byte[] gzip(byte[] data, int level) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length); try (GzipLevelOutputStream out = new GzipLevelOutputStream(baos)) { out.setLevel(level); out.write(data); } return baos.toByteArray(); }
java
{ "resource": "" }
q22824
HttpUtils.gunzip
train
@SuppressWarnings("PMD.AssignmentInOperand") static byte[] gunzip(byte[] data) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length * 10); try (InputStream in = new GZIPInputStream(new ByteArrayInputStream(data))) { byte[] buffer = new byte[4096]; int length; ...
java
{ "resource": "" }
q22825
NetflixConfig.createConfig
train
public static Config createConfig(Config config) { try { // We cannot use the libraries layer as the nf-archaius2-platform-bridge // will delegate the Config binding to archaius1 and the libraries layer // then wraps that. So anything added to the libraries layer will not get // picked up by...
java
{ "resource": "" }
q22826
NetflixConfig.commonTags
train
public static Map<String, String> commonTags() { final Map<String, String> commonTags = new HashMap<>(); put(commonTags, "nf.app", Env.app()); put(commonTags, "nf.cluster", Env.cluster()); put(commonTags, "nf.asg", Env.asg()); put(commonTags, "nf.stack", Env.stack()); put(commonTags, "nf.zone", ...
java
{ "resource": "" }
q22827
SparkNameFunction.fromConfig
train
public static SparkNameFunction fromConfig(Config config, String key, Registry registry) { return fromPatternList(config.getConfigList(key), registry); }
java
{ "resource": "" }
q22828
ServerGroup.sequence
train
public String sequence() { return dN == asg.length() ? null : substr(asg, dN + 1, asg.length()); }
java
{ "resource": "" }
q22829
GcLogger.start
train
public synchronized void start(GcEventListener listener) { // TODO: this class has a bad mix of static fields used from an instance of the class. For now // this has been changed not to throw to make the dependency injection use-cases work. A // more general refactor of the GcLogger class is needed. if ...
java
{ "resource": "" }
q22830
GcLogger.stop
train
public synchronized void stop() { Preconditions.checkState(notifListener != null, "logger has not been started"); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { if (mbean instanceof NotificationEmitter) { final NotificationEmitter emitter = (NotificationEmitt...
java
{ "resource": "" }
q22831
GcLogger.getLogs
train
public List<GcEvent> getLogs() { final List<GcEvent> logs = new ArrayList<>(); for (CircularBuffer<GcEvent> buffer : gcLogs.values()) { logs.addAll(buffer.toList()); } Collections.sort(logs, GcEvent.REVERSE_TIME_ORDER); return logs; }
java
{ "resource": "" }
q22832
SpectatorExecutionInterceptor.isStatusSet
train
private boolean isStatusSet(ExecutionAttributes attrs) { Boolean s = attrs.getAttribute(STATUS_IS_SET); return s != null && s; }
java
{ "resource": "" }
q22833
Subscriptions.update
train
public void update(Map<Subscription, Long> subs, long currentTime, long expirationTime) { // Update expiration time for existing subs and log new ones for (Subscription sub : expressions) { if (subs.put(sub, expirationTime) == null) { LOGGER.info("new subscription: {}", sub); } } //...
java
{ "resource": "" }
q22834
MicrometerMeter.convert
train
Iterable<Measurement> convert(Iterable<io.micrometer.core.instrument.Measurement> ms) { long now = Clock.SYSTEM.wallTime(); List<Measurement> measurements = new ArrayList<>(); for (io.micrometer.core.instrument.Measurement m : ms) { Id measurementId = id.withTag("statistic", m.getStatistic().getTagVal...
java
{ "resource": "" }
q22835
ArrayTagSet.create
train
static ArrayTagSet create(Iterable<Tag> tags) { return (tags instanceof ArrayTagSet) ? (ArrayTagSet) tags : EMPTY.addAll(tags); }
java
{ "resource": "" }
q22836
CircularBuffer.add
train
void add(T item) { int i = nextIndex.getAndIncrement() % data.length(); data.set(i, item); }
java
{ "resource": "" }
q22837
CircularBuffer.toList
train
List<T> toList() { List<T> items = new ArrayList<>(data.length()); for (int i = 0; i < data.length(); ++i) { T item = data.get(i); if (item != null) { items.add(item); } } return items; }
java
{ "resource": "" }
q22838
Scheduler.newThreadFactory
train
private static ThreadFactory newThreadFactory(final String id) { return new ThreadFactory() { private final AtomicInteger next = new AtomicInteger(); @Override public Thread newThread(Runnable r) { final String name = "spectator-" + id + "-" + next.getAndIncrement(); final Thread t = ne...
java
{ "resource": "" }
q22839
Scheduler.schedule
train
public ScheduledFuture<?> schedule(Options options, Runnable task) { if (!started) { startThreads(); } DelayedTask t = new DelayedTask(clock, options, task); queue.put(t); return t; }
java
{ "resource": "" }
q22840
Scheduler.shutdown
train
public synchronized void shutdown() { shutdown = true; for (int i = 0; i < threads.length; ++i) { if (threads[i] != null && threads[i].isAlive()) { threads[i].interrupt(); threads[i] = null; } } }
java
{ "resource": "" }
q22841
JmxConfig.from
train
static JmxConfig from(Config config) { try { ObjectName query = new ObjectName(config.getString("query")); List<JmxMeasurementConfig> ms = new ArrayList<>(); for (Config cfg : config.getConfigList("measurements")) { ms.add(JmxMeasurementConfig.from(cfg)); } return new JmxConfig...
java
{ "resource": "" }
q22842
SwapMeter.unwrap
train
@SuppressWarnings("unchecked") private T unwrap(T meter) { T tmp = meter; while (tmp instanceof SwapMeter<?> && registry == ((SwapMeter<?>) tmp).registry) { tmp = ((SwapMeter<T>) tmp).underlying; } return tmp; }
java
{ "resource": "" }
q22843
DoubleDistributionSummary.get
train
static DoubleDistributionSummary get(Registry registry, Id id) { DoubleDistributionSummary instance = INSTANCES.get(id); if (instance == null) { final Clock c = registry.clock(); DoubleDistributionSummary tmp = new DoubleDistributionSummary(c, id, RESET_FREQ); instance = INSTANCES.putIfAbsent(...
java
{ "resource": "" }
q22844
SpiExample.read
train
public static void read() throws IOException, InterruptedException { for(short channel = 0; channel < ADC_CHANNEL_COUNT; channel++){ int conversion_value = getConversionValue(channel); console.print(String.format(" | %04d", conversion_value)); // print 4 digits with leading zeros ...
java
{ "resource": "" }
q22845
SpiExample.getConversionValue
train
public static int getConversionValue(short channel) throws IOException { // create a data buffer and initialize a conversion request payload byte data[] = new byte[] { (byte) 0b00000001, // first byte, start bit (byte)(0b10000000 |( ((channel...
java
{ "resource": "" }
q22846
PlatformManager.setPlatform
train
public static void setPlatform(Platform platform) throws PlatformAlreadyAssignedException { // prevent changing the platform once it has been initially set if(PlatformManager.platform != null){ throw new PlatformAlreadyAssignedException(PlatformManager.platform); } // set in...
java
{ "resource": "" }
q22847
PlatformManager.getDefaultPlatform
train
protected static Platform getDefaultPlatform(){ // attempt to get assigned platform identifier from the environment variables String envPlatformId = System.getenv("PI4J_PLATFORM"); // attempt to get assigned platform identifier from the system properties String platformId = System.getPr...
java
{ "resource": "" }
q22848
W1Master.getDeviceIDs
train
public List<String> getDeviceIDs() { final List<String> ids = new ArrayList<>(); for (final File deviceDir : getDeviceDirs()) { ids.add(deviceDir.getName()); } /* * //for (final W1Device device: devices) { ids.add(device.getId()); */ return ids; ...
java
{ "resource": "" }
q22849
W1Master.getDevices
train
@SuppressWarnings("unchecked") public <T> List<T> getDevices(final Class<T> type) { final List<W1Device> allDevices = getDevices(); final List<T> filteredDevices = new ArrayList<>(); for (final W1Device device : allDevices) { if (type.isAssignableFrom(device.getClass())) { ...
java
{ "resource": "" }
q22850
MicrochipPotentiometerDeviceController.getDeviceStatus
train
public DeviceControllerDeviceStatus getDeviceStatus() throws IOException { // get status from device int deviceStatus = read(MEMADDR_STATUS); // check formal criterias int reservedValue = deviceStatus & STATUS_RESERVED_MASK; if (reservedValue != STATUS_RESERVED_VALUE) { throw new IOException( "statu...
java
{ "resource": "" }
q22851
MicrochipPotentiometerDeviceController.increase
train
public void increase(final DeviceControllerChannel channel, final int steps) throws IOException { if (channel == null) { throw new RuntimeException("null-channel is not allowed. For devices " + "knowing just one wiper Channel.A is mandatory for " + "parameter 'channel'"); } // decrease only work...
java
{ "resource": "" }
q22852
MicrochipPotentiometerDeviceController.decrease
train
public void decrease(final DeviceControllerChannel channel, final int steps) throws IOException { if (channel == null) { throw new RuntimeException("null-channel is not allowed. For devices " + "knowing just one wiper Channel.A is mandatory for " + "parameter 'channel'"); } // decrease only work...
java
{ "resource": "" }
q22853
MicrochipPotentiometerDeviceController.getValue
train
public int getValue(final DeviceControllerChannel channel, final boolean nonVolatile) throws IOException { if (channel == null) { throw new RuntimeException("null-channel is not allowed. For devices " + "knowing just one wiper Channel.A is mandatory for " + "parameter 'channel'"); } // choose pr...
java
{ "resource": "" }
q22854
MicrochipPotentiometerDeviceController.setValue
train
public void setValue(final DeviceControllerChannel channel, final int value, final boolean nonVolatile) throws IOException { if (channel == null) { throw new RuntimeException("null-channel is not allowed. For devices " + "knowing just one wiper Channel.A is mandatory for " + "parameter 'channel'"); ...
java
{ "resource": "" }
q22855
MicrochipPotentiometerDeviceController.getTerminalConfiguration
train
public DeviceControllerTerminalConfiguration getTerminalConfiguration( final DeviceControllerChannel channel) throws IOException { if (channel == null) { throw new RuntimeException("null-channel is not allowed. For devices " + "knowing just one wiper Channel.A is mandatory for " + "parameter 'channel...
java
{ "resource": "" }
q22856
MicrochipPotentiometerDeviceController.setTerminalConfiguration
train
public void setTerminalConfiguration(final DeviceControllerTerminalConfiguration config) throws IOException { if (config == null) { throw new RuntimeException("null-config is not allowed!"); } final DeviceControllerChannel channel = config.getChannel(); if (channel == null) { throw new RuntimeExceptio...
java
{ "resource": "" }
q22857
MicrochipPotentiometerDeviceController.read
train
private int read(final byte memAddr) throws IOException { // ask device for reading data - see FIGURE 7-5 byte[] cmd = new byte[] { (byte) ((memAddr << 4) | CMD_READ) }; // read two bytes byte[] buf = new byte[2]; int read = i2cDevice.read(cmd, 0, cmd.length, buf, 0, buf.length); if (read != 2) { t...
java
{ "resource": "" }
q22858
MicrochipPotentiometerDeviceController.write
train
private void write(final byte memAddr, final int value) throws IOException { // bit 8 of value byte firstBit = (byte) ((value >> 8) & 0x000001); // ask device for setting a value - see FIGURE 7-2 byte cmd = (byte) ((memAddr << 4) | CMD_WRITE | firstBit); // 7 bits of value byte data = (byte) (value & 0x0...
java
{ "resource": "" }
q22859
I2CBusImpl.selectBusSlave
train
protected void selectBusSlave(final I2CDevice device) throws IOException { final int addr = device.getAddress(); if (lastAddress != addr) { lastAddress = addr; file.ioctl(I2CConstants.I2C_SLAVE, addr & 0xFF); } }
java
{ "resource": "" }
q22860
PinProvider.allPins
train
public static Pin[] allPins(PinMode ... mode) { List<Pin> results = new ArrayList<>(); for(Pin p : pins.values()){ EnumSet<PinMode> supported_modes = p.getSupportedPinModes(); for(PinMode m : mode){ if(supported_modes.contains(m)){ results.add(...
java
{ "resource": "" }
q22861
GpioSensorComponent.getState
train
@Override public SensorState getState() { if(pin.isState(openState)) return SensorState.OPEN; else return SensorState.CLOSED; }
java
{ "resource": "" }
q22862
SpiFactory.getInstance
train
public static SpiDevice getInstance(SpiChannel channel, SpiMode mode) throws IOException { return new SpiDeviceImpl(channel, mode); }
java
{ "resource": "" }
q22863
MCP4725GpioProvider.setValue
train
@Override public void setValue(Pin pin, double value) { // validate range if(value <= getMinSupportedValue()){ value = getMinSupportedValue(); } else if(value >= getMaxSupportedValue()){ value = getMaxSupportedValue(); } // the DAC only supp...
java
{ "resource": "" }
q22864
MicrochipPotentiometerBase.initialize
train
protected void initialize(final int initialValueForVolatileWipers) throws IOException { if (isCapableOfNonVolatileWiper()) { // the device's volatile-wiper will be set to the value stored // in the non-volatile memory. so for those devices the wiper's // current value has to be retrieved currentValue = ...
java
{ "resource": "" }
q22865
MicrochipPotentiometerBase.updateCacheFromDevice
train
@Override public int updateCacheFromDevice() throws IOException { currentValue = controller.getValue(DeviceControllerChannel.valueOf(channel), false); return currentValue; }
java
{ "resource": "" }
q22866
MicrochipPotentiometerBase.decrease
train
@Override public void decrease(final int steps) throws IOException { if (currentValue == 0) { return; } if (steps < 0) { throw new RuntimeException("Only positive values for parameter 'steps' allowed!"); } if (getNonVolatileMode() != MicrochipPotentiometerNonVolatileMode.VOLATILE_ONLY) { throw new ...
java
{ "resource": "" }
q22867
MicrochipPotentiometerBase.increase
train
@Override public void increase(final int steps) throws IOException { int maxValue = getMaxValue(); if (currentValue == maxValue) { return; } if (steps < 0) { throw new RuntimeException("only positive values for parameter 'steps' allowed!"); } if (getNonVolatileMode() != MicrochipPotentiometerNonVol...
java
{ "resource": "" }
q22868
MicrochipPotentiometerBase.setWiperLock
train
@Override public void setWiperLock(final boolean enabled) throws IOException { controller.setWiperLock(DeviceControllerChannel.valueOf(channel), enabled); }
java
{ "resource": "" }
q22869
MicrochipPotentiometerBase.doWiperAction
train
private void doWiperAction(final WiperAction wiperAction) throws IOException { // for volatile-wiper switch (nonVolatileMode) { case VOLATILE_ONLY: case VOLATILE_AND_NONVOLATILE: wiperAction.run(MicrochipPotentiometerDeviceController.VOLATILE_WIPER); break; case NONVOLATILE_ONLY: // do nothing } ...
java
{ "resource": "" }
q22870
GpioPowerComponent.getState
train
@Override public PowerState getState() { if(pin.isState(onState)) return PowerState.ON; else if(pin.isState(offState)) return PowerState.OFF; else return PowerState.UNKNOWN; }
java
{ "resource": "" }
q22871
RaspiPin.createDigitalPinNoPullDown
train
protected static Pin createDigitalPinNoPullDown(int address, String name) { return createDigitalPin(RaspiGpioProvider.NAME, address, name, EnumSet.of(PinPullResistance.OFF, PinPullResistance.PULL_UP), PinEdge.all()); }
java
{ "resource": "" }
q22872
RaspiPin.allPins
train
public static Pin[] allPins(SystemInfo.BoardType board) { List<Pin> pins = new ArrayList<>(); // pins for all Raspberry Pi models pins.add(RaspiPin.GPIO_00); pins.add(RaspiPin.GPIO_01); pins.add(RaspiPin.GPIO_02); pins.add(RaspiPin.GPIO_03); pins.add(RaspiPin.GPI...
java
{ "resource": "" }
q22873
Serial.write
train
public synchronized static void write(int fd, InputStream input) throws IOException { // ensure bytes are available if(input.available() <= 0){ throw new IOException("No available bytes in input stream to write to serial port."); } ByteArrayOutputStream buffer = new ByteArr...
java
{ "resource": "" }
q22874
DacGpioProviderBase.setPercentValue
train
public void setPercentValue(Pin pin, Number percent){ // validate range if(percent.doubleValue() <= 0){ setValue(pin, getMinSupportedValue()); } else if(percent.doubleValue() >= 100){ setValue(pin, getMaxSupportedValue()); } else{ doubl...
java
{ "resource": "" }
q22875
DacGpioProviderBase.setPercentValue
train
@Override public void setPercentValue(GpioPinAnalogOutput pin, Number percent){ setPercentValue(pin.getPin(), percent); }
java
{ "resource": "" }
q22876
DacGpioProviderBase.setValue
train
@Override public void setValue(Pin pin, Number value) { super.setValue(pin, value.doubleValue()); }
java
{ "resource": "" }
q22877
DacGpioProviderBase.shutdown
train
@Override public void shutdown() { // prevent reentrant invocation if(isShutdown()) return; // perform shutdown login in base super.shutdown(); try { // iterate over all pins and apply shutdown values if configured for the pin instance f...
java
{ "resource": "" }
q22878
NativeLibraryLoader.loadLibraryFromClasspath
train
public static void loadLibraryFromClasspath(String path) throws IOException { Path inputPath = Paths.get(path); if (!inputPath.isAbsolute()) { throw new IllegalArgumentException("The path has to be absolute, but found: " + inputPath); } String fileNameFull = inputPath.getFileName().toString(); int dotInd...
java
{ "resource": "" }
q22879
SerialDataEvent.getHexByteString
train
public String getHexByteString(CharSequence prefix, CharSequence separator, CharSequence suffix) throws IOException { byte data[] = getBytes(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length; i++) { if(i > 0) sb.append(separator); int v = ...
java
{ "resource": "" }
q22880
TemperatureConversion.convert
train
public static double convert(TemperatureScale from, TemperatureScale to, double temperature) { switch(from) { case FARENHEIT: return convertFromFarenheit(to, temperature); case CELSIUS: return convertFromCelsius(to, temperature); case KELVIN:...
java
{ "resource": "" }
q22881
TemperatureConversion.convertFromFarenheit
train
public static double convertFromFarenheit (TemperatureScale to, double temperature) { switch(to) { case FARENHEIT: return temperature; case CELSIUS: return convertFarenheitToCelsius(temperature); case KELVIN: return convertFar...
java
{ "resource": "" }
q22882
TemperatureConversion.convertToFarenheit
train
public static double convertToFarenheit (TemperatureScale from, double temperature) { switch(from) { case FARENHEIT: return temperature; case CELSIUS: return convertCelsiusToFarenheit(temperature); case KELVIN: return convertK...
java
{ "resource": "" }
q22883
TemperatureConversion.convertFromCelsius
train
public static double convertFromCelsius(TemperatureScale to, double temperature) { switch(to) { case FARENHEIT: return convertCelsiusToFarenheit(temperature); case CELSIUS: return temperature; case KELVIN: return convertCelsiu...
java
{ "resource": "" }
q22884
TemperatureConversion.convertToCelsius
train
public static double convertToCelsius (TemperatureScale from, double temperature) { switch(from) { case FARENHEIT: return convertFarenheitToCelsius(temperature); case CELSIUS: return temperature; case KELVIN: return convertKel...
java
{ "resource": "" }
q22885
TemperatureConversion.convertFromKelvin
train
public static double convertFromKelvin(TemperatureScale to, double temperature) { switch(to) { case FARENHEIT: return convertKelvinToFarenheit(temperature); case CELSIUS: return convertKelvinToCelsius(temperature); case KELVIN: ...
java
{ "resource": "" }
q22886
TemperatureConversion.convertToKelvin
train
public static double convertToKelvin(TemperatureScale from, double temperature) { switch(from) { case FARENHEIT: return convertFarenheitToKelvin(temperature); case CELSIUS: return convertCelsiusToKelvin(temperature); case KELVIN: ...
java
{ "resource": "" }
q22887
TemperatureConversion.convertFromRankine
train
public static double convertFromRankine(TemperatureScale to, double temperature) { switch(to) { case FARENHEIT: return convertRankineToFarenheit(temperature); case CELSIUS: return convertRankineToCelsius(temperature); case KELVIN: ...
java
{ "resource": "" }
q22888
TemperatureConversion.convertToRankine
train
public static double convertToRankine(TemperatureScale from, double temperature) { switch(from) { case FARENHEIT: return convertFarenheitToRankine(temperature); case CELSIUS: return convertCelsiusToRankine(temperature); case KELVIN: ...
java
{ "resource": "" }
q22889
AdcGpioProviderBase.getPercentValue
train
public float getPercentValue(Pin pin){ double value = getValue(pin); if(value > INVALID_VALUE) { return (float) (value / (getMaxSupportedValue() - getMinSupportedValue())) * 100f; } return INVALID_VALUE; }
java
{ "resource": "" }
q22890
AdcGpioProviderBase.shutdown
train
@Override public void shutdown() { // prevent reentrant invocation if(isShutdown()) return; // perform shutdown login in base super.shutdown(); try { // if a monitor is running, then shut it down now if (monitor != null) { ...
java
{ "resource": "" }
q22891
AdcGpioProviderBase.setEventThreshold
train
@Override public void setEventThreshold(double threshold, GpioPinAnalogInput...pin){ for(GpioPin p : pin){ setEventThreshold(threshold, p.getPin()); } }
java
{ "resource": "" }
q22892
AdcGpioProviderBase.setMonitorEnabled
train
@Override public void setMonitorEnabled(boolean enabled) { if(enabled) { // create and start background monitor if (monitor == null) { monitor = new AdcGpioProviderBase.ADCMonitor(); monitor.start(); } } else{ tr...
java
{ "resource": "" }
q22893
LinuxFile.ioctl
train
public void ioctl(long command, int value) throws IOException { final int response = directIOCTL(getFileDescriptor(), command, value); if(response < 0) throw new LinuxFileException(); }
java
{ "resource": "" }
q22894
LinuxFile.ioctl
train
public void ioctl(final long command, ByteBuffer data, IntBuffer offsets) throws IOException { ByteBuffer originalData = data; if(data == null || offsets == null) throw new NullPointerException("data and offsets required!"); if(offsets.order() != ByteOrder.nativeOrder()) ...
java
{ "resource": "" }
q22895
LinuxFile.getFileDescriptor
train
private int getFileDescriptor() throws IOException { final int fd = SharedSecrets.getJavaIOFileDescriptorAccess().get(getFD()); if(fd < 1) throw new IOException("failed to get POSIX file descriptor!"); return fd; }
java
{ "resource": "" }
q22896
LinuxFile.mmap
train
public ByteBuffer mmap(int length, MMAPProt prot, MMAPFlags flags, int offset) throws IOException { long pointer = mmap(getFileDescriptor(), length, prot.flag, flags.flag, offset); if(pointer == -1) throw new LinuxFileException(); return newMappedByteBuffer(length, pointer, () -> {...
java
{ "resource": "" }
q22897
GpioRelayComponent.getState
train
@Override public RelayState getState() { if(pin.isState(openState)) return RelayState.OPEN; else return RelayState.CLOSED; }
java
{ "resource": "" }
q22898
GpioStepperMotorComponent.setState
train
@Override public void setState(MotorState state) { switch(state) { case STOP: { // set internal tracking state currentState = MotorState.STOP; // turn all GPIO pins to OFF state for(GpioPinDigitalOutput pin : pins) ...
java
{ "resource": "" }
q22899
GpioStepperMotorComponent.doStep
train
private void doStep(boolean forward) { // increment or decrement sequence if(forward) sequenceIndex++; else sequenceIndex--; // check sequence bounds; rollover if needed if(sequenceIndex >= stepSequence.length) sequenceIndex = 0; else...
java
{ "resource": "" }