method2testcases
stringlengths
118
6.63k
### Question: BytesUtils { public static byte[] concatByteArray(byte[] a, byte[] b) { byte[] c = new byte[a.length + b.length]; System.arraycopy(a, 0, c, 0, a.length); System.arraycopy(b, 0, c, a.length, b.length); return c; } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); s...
### Question: BytesUtils { public static byte[] concatByteArrayList(List<byte[]> list) { int size = list.size(); int len = 0; for (byte[] cs : list) { len += cs.length; } byte[] result = new byte[len]; int pos = 0; for (int i = 0; i < size; i++) { int l = list.get(i).length; System.arraycopy(list.get(i), 0, result, pos...
### Question: AbstractClient { protected static String checkRequiredArg(String arg, String name, CommandLine commandLine, boolean isRequired, String defaultValue) throws ArgsErrorException { String str = commandLine.getOptionValue(arg); if (str == null) { if (isRequired) { String msg = String .format("%s: Required valu...
### Question: BytesUtils { public static byte[] subBytes(byte[] src, int start, int length) { if ((start + length) > src.length) { return null; } if (length <= 0) { return null; } byte[] result = new byte[length]; for (int i = 0; i < length; i++) { result[i] = src[start + i]; } return result; } static byte[] intToByte...
### Question: BytesUtils { public static int getByteN(byte data, int offset) { offset %= 8; if ((data & (1 << (7 - offset))) != 0) { return 1; } else { return 0; } } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result, int pos, int...
### Question: BytesUtils { public static int getLongN(long data, int offset) { offset %= 64; if ((data & (1L << (offset))) != 0) { return 1; } else { return 0; } } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result, int pos, int w...
### Question: BytesUtils { public static int getIntN(int data, int offset) { offset %= 32; if ((data & (1 << (offset))) != 0) { return 1; } else { return 0; } } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result, int pos, int widt...
### Question: BytesUtils { public static int readInt(InputStream in) throws IOException { byte[] b = safeReadInputStreamToBytes(4, in); return BytesUtils.bytesToInt(b); } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result, int pos...
### Question: BytesUtils { public static float readFloat(InputStream in) throws IOException { byte[] b = safeReadInputStreamToBytes(4, in); return BytesUtils.bytesToFloat(b); } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result, i...
### Question: BytesUtils { public static double readDouble(InputStream in) throws IOException { byte[] b = safeReadInputStreamToBytes(8, in); return BytesUtils.bytesToDouble(b); } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result...
### Question: BytesUtils { public static boolean readBool(InputStream in) throws IOException { byte[] b = safeReadInputStreamToBytes(1, in); return BytesUtils.bytesToBool(b); } static byte[] intToBytes(int i); static byte[] intToBytes(int i, byte[] desc, int offset); static void intToBytes(int srcNum, byte[] result, i...
### Question: StringContainer { public String getSubString(int index) { int realIndex = index >= 0 ? index : count + index; if (realIndex < 0 || realIndex >= count) { throw new IndexOutOfBoundsException( "Index: " + index + ", Real Index: " + realIndex + ", Size: " + count); } if (realIndex < reverseList.size()) { retu...
### Question: AbstractClient { protected static String[] removePasswordArgs(String[] args) { int index = -1; for (int i = 0; i < args.length; i++) { if (args[i].equals("-" + PASSWORD_ARGS)) { index = i; break; } } if (index >= 0) { if ((index + 1 >= args.length) || (index + 1 < args.length && keywordSet .contains(args[...
### Question: StringContainer { public StringContainer getSubStringContainer(int start, int end) { int realStartIndex = start >= 0 ? start : count + start; int realEndIndex = end >= 0 ? end : count + end; if (realStartIndex < 0 || realStartIndex >= count) { throw new IndexOutOfBoundsException( "start Index: " + start +...
### Question: StringContainer { @Override public int hashCode() { final int prime = 31; int result = 1; if (joinSeparator != null) { result = prime * result + joinSeparator.hashCode(); } for (String string : reverseList) { result = prime * result + ((string == null) ? 0 : string.hashCode()); } for (String string : sequ...
### Question: MetadataQuerierByFileImpl implements MetadataQuerier { @Override public List<ChunkMetaData> getChunkMetaDataList(Path path) throws IOException { return chunkMetaDataCache.get(path); } MetadataQuerierByFileImpl(TsFileSequenceReader tsFileReader); @Override List<ChunkMetaData> getChunkMetaDataList(Path path...
### Question: Path { public boolean startWith(String prefix) { return prefix != null && fullPath.startsWith(prefix); } Path(StringContainer pathSc); Path(String pathSc); Path(String[] pathSc); Path(String device, String measurement); static Path mergePath(Path prefix, Path suffix); static Path addPrefixPath(Path src...
### Question: Path { public static Path mergePath(Path prefix, Path suffix) { StringContainer sc = new StringContainer(SystemConstant.PATH_SEPARATOR); sc.addTail(prefix); sc.addTail(suffix); return new Path(sc); } Path(StringContainer pathSc); Path(String pathSc); Path(String[] pathSc); Path(String device, String me...
### Question: Path { public static Path replace(String srcPrefix, Path descPrefix) { if ("".equals(srcPrefix) || descPrefix.startWith(srcPrefix)) { return descPrefix; } int prefixSize = srcPrefix.split(SystemConstant.PATH_SEPARATER_NO_REGEX).length; String[] descArray = descPrefix.fullPath.split(SystemConstant.PATH_SEP...
### Question: ReadOnlyTsFile { public QueryDataSet query(QueryExpression queryExpression) throws IOException { return tsFileExecutor.execute(queryExpression); } ReadOnlyTsFile(TsFileSequenceReader fileReader); QueryDataSet query(QueryExpression queryExpression); void close(); }### Answer: @Test public void queryTest()...
### Question: IoTDBStatement implements Statement { @Override public boolean execute(String sql) throws SQLException { checkConnection("execute"); isClosed = false; try { return executeSQL(sql); } catch (TException e) { boolean flag = connection.reconnect(); reInit(); if (flag) { try { return executeSQL(sql); } catch (...
### Question: IoTDBStatement implements Statement { @Override public int getFetchSize() throws SQLException { checkConnection("getFetchSize"); return fetchSize; } IoTDBStatement(IoTDBConnection connection, TSIService.Iface client, TS_SessionHandle sessionHandle, int fetchSize, ZoneId zoneId); IoTDBStatemen...
### Question: IoTDBStatement implements Statement { @Override public void setFetchSize(int fetchSize) throws SQLException { checkConnection("setFetchSize"); if (fetchSize < 0) { throw new SQLException(String.format("fetchSize %d must be >= 0!", fetchSize)); } this.fetchSize = fetchSize == 0 ? Config.fetchSize : fetchSi...
### Question: IoTDBStatement implements Statement { @Override public void setMaxRows(int num) throws SQLException { checkConnection("setMaxRows"); if (num < 0) { throw new SQLException(String.format("maxRows %d must be >= 0!", num)); } this.maxRows = num; } IoTDBStatement(IoTDBConnection connection, TSIService.Iface cl...
### Question: IoTDBMetadataResultMetadata implements ResultSetMetaData { @Override public int getColumnCount() throws SQLException { if (showLabels == null || showLabels.length == 0) { throw new SQLException("No column exists"); } return showLabels.length; } IoTDBMetadataResultMetadata(String[] showLabels); @Override b...
### Question: IoTDBMetadataResultMetadata implements ResultSetMetaData { @Override public String getColumnName(int column) throws SQLException { return getColumnLabel(column); } IoTDBMetadataResultMetadata(String[] showLabels); @Override boolean isWrapperFor(Class<?> arg0); @Override T unwrap(Class<T> arg0); @Override ...
### Question: IoTDBResultMetadata implements ResultSetMetaData { @Override public int getColumnCount() throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } return columnInfoList.size(); } IoTDBResultMetadata(List<String> columnInfoList, String o...
### Question: IoTDBResultMetadata implements ResultSetMetaData { @Override public String getColumnName(int column) throws SQLException { return getColumnLabel(column); } IoTDBResultMetadata(List<String> columnInfoList, String operationType, List<String> columnTypeList); @Override boolean isWrapperFor(Class<?> arg...
### Question: IoTDBResultMetadata implements ResultSetMetaData { @Override public int getColumnType(int column) throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } if (column > columnInfoList.size()) { throw new SQLException(String.format("colu...
### Question: IoTDBResultMetadata implements ResultSetMetaData { @Override public String getColumnTypeName(int arg0) throws SQLException { return operationType; } IoTDBResultMetadata(List<String> columnInfoList, String operationType, List<String> columnTypeList); @Override boolean isWrapperFor(Class<?> arg0); @Ov...
### Question: FloatDecoder extends Decoder { @Override public float readFloat(ByteBuffer buffer) { readMaxPointValue(buffer); int value = decoder.readInt(buffer); double result = value / maxPointValue; return (float) result; } FloatDecoder(TSEncoding encodingType, TSDataType dataType); @Override float readFloat(ByteBuf...
### Question: IoTDBConnection implements Connection { public void setTimeZone(String zoneId) throws TException, IoTDBSQLException { TSSetTimeZoneReq req = new TSSetTimeZoneReq(zoneId); TSSetTimeZoneResp resp = client.setTimeZone(req); Utils.verifySuccess(resp.getStatus()); this.zoneId = ZoneId.of(zoneId); } IoTDBConnec...
### Question: IoTDBConnection implements Connection { public String getTimeZone() throws TException, IoTDBSQLException { if (zoneId != null) { return zoneId.toString(); } TSGetTimeZoneResp resp = client.getTimeZone(); Utils.verifySuccess(resp.getStatus()); return resp.getTimeZone(); } IoTDBConnection(); IoTDBConnectio...
### Question: IoTDBConnection implements Connection { public ServerProperties getServerProperties() throws TException { return client.getProperties(); } IoTDBConnection(); IoTDBConnection(String url, Properties info); static TSIService.Iface newSynchronizedClient(TSIService.Iface client); @Override boolean isWrapperFo...
### Question: Utils { public static IoTDBConnectionParams parseUrl(String url, Properties info) throws IoTDBURLException { IoTDBConnectionParams params = new IoTDBConnectionParams(url); if (url.trim().equalsIgnoreCase(Config.IOTDB_URL_PREFIX)) { return params; } Pattern pattern = Pattern.compile("([^;]*):([^;]*)/"); Ma...
### Question: Utils { public static void verifySuccess(TS_Status status) throws IoTDBSQLException { if (status.getStatusCode() != TS_StatusCode.SUCCESS_STATUS) { throw new IoTDBSQLException(status.errorMessage); } } static IoTDBConnectionParams parseUrl(String url, Properties info); static void verifySuccess(TS_Status...
### Question: PriorityMergeReaderByTimestamp extends PriorityMergeReader implements EngineReaderByTimeStamp { @Override public TsPrimitiveType getValueInTimestamp(long timestamp) throws IOException { if (hasCachedTimeValuePair) { if (cachedTimeValuePair.getTimestamp() == timestamp) { hasCachedTimeValuePair = false;...
### Question: Processor { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Processor other = (Processor) obj; if (processorName == null) { if (other.processorName != null) { return false; } } else if (!...
### Question: GorillaDecoder extends Decoder { @Override public boolean hasNext(ByteBuffer buffer) throws IOException { if (buffer.remaining() > 0 || !isEnd) { return true; } return false; } GorillaDecoder(); @Override void reset(); @Override boolean hasNext(ByteBuffer buffer); }### Answer: @Test public void testNegat...
### Question: OFFileMetadata { public OFFileMetadata() { } OFFileMetadata(); OFFileMetadata(long lastFooterOffset, List<OFRowGroupListMetadata> rowGroupLists); static OFFileMetadata deserializeFrom(InputStream inputStream); static OFFileMetadata deserializeFrom(ByteBuffer buffer); void addRowGroupListMetaData(OFRowGro...
### Question: OFRowGroupListMetadata { private OFRowGroupListMetadata() { } private OFRowGroupListMetadata(); OFRowGroupListMetadata(String deviceId); static OFRowGroupListMetadata deserializeFrom(InputStream inputStream); static OFRowGroupListMetadata deserializeFrom(ByteBuffer buffer); void addSeriesListMetaData(OF...
### Question: OverflowProcessor extends Processor { private void recovery(File parentFile) throws IOException { String[] subFilePaths = clearFile(parentFile.list()); if (subFilePaths.length == 0) { workResource = new OverflowResource(parentPath, String.valueOf(dataPahtCount.getAndIncrement())); return; } else if (subFi...
### Question: OverflowIO extends TsFileIOWriter { public void close() throws IOException { overflowReadWriter.close(); } OverflowIO(OverflowReadWriter overflowReadWriter); @Deprecated static InputStream readOneTimeSeriesChunk(ChunkMetaData chunkMetaData, TsFileInput fileReader); @Deprecated ChunkMetaData flush(Ov...
### Question: OverflowSupport { public void insert(TSRecord tsRecord) { for (DataPoint dataPoint : tsRecord.dataPointList) { memTable.write(tsRecord.deviceId, dataPoint.getMeasurementId(), dataPoint.getType(), tsRecord.time, dataPoint.getValue().toString()); } } OverflowSupport(); void insert(TSRecord tsRecord); @Depre...
### Question: IoTDBThreadPoolFactory { public static ExecutorService newFixedThreadPool(int nthreads, String poolName) { return Executors.newFixedThreadPool(nthreads, new IoTThreadFactory(poolName)); } static ExecutorService newFixedThreadPool(int nthreads, String poolName); static ExecutorService newFixedThreadPool(i...
### Question: IoTDBThreadPoolFactory { public static ExecutorService newSingleThreadExecutor(String poolName) { return Executors.newSingleThreadExecutor(new IoTThreadFactory(poolName)); } static ExecutorService newFixedThreadPool(int nthreads, String poolName); static ExecutorService newFixedThreadPool(int nthreads, S...
### Question: IoTDBThreadPoolFactory { public static ExecutorService newCachedThreadPool(String poolName) { return Executors.newCachedThreadPool(new IoTThreadFactory(poolName)); } static ExecutorService newFixedThreadPool(int nthreads, String poolName); static ExecutorService newFixedThreadPool(int nthreads, String po...
### Question: IoTDBThreadPoolFactory { public static ScheduledExecutorService newSingleThreadScheduledExecutor(String poolName) { return Executors.newSingleThreadScheduledExecutor(new IoTThreadFactory(poolName)); } static ExecutorService newFixedThreadPool(int nthreads, String poolName); static ExecutorService newFixe...
### Question: IoTDBThreadPoolFactory { public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, String poolName) { return Executors.newScheduledThreadPool(corePoolSize, new IoTThreadFactory(poolName)); } static ExecutorService newFixedThreadPool(int nthreads, String poolName); static ExecutorSer...
### Question: IoTDBThreadPoolFactory { public static ExecutorService createJDBCClientThreadPool(Args args, String poolName) { SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<Runnable>(); return new ThreadPoolExecutor(args.minWorkerThreads, args.maxWorkerThreads, args.stopTimeoutVal, args.stopTimeoutUnit...
### Question: LogicalGenerator { public long parseTimeFormat(String timestampStr) throws LogicalOperatorException { if (timestampStr == null || timestampStr.trim().equals("")) { throw new LogicalOperatorException("input timestamp cannot be empty"); } if (timestampStr.toLowerCase().equals(SQLConstant.NOW_FUNC)) { return...
### Question: Pair { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (left == null) { if (other.left != null) { return false; } } else if (!left.equals(other.lef...
### Question: IconHelper { public static int getTextBoxAlphaValue() { return textBoxAlphaValue; } private IconHelper(); static int getTextBoxAlphaValue(); static void setTextBoxAlphaValue(int textBoxAlphaValue); static int getRollingTextPadding(); static void setRollingTextPadding(int rollingTextPadding); static SDIma...
### Question: IconHelper { public static BufferedImage fillBackground(BufferedImage img, Color color) { BufferedImage nImg = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); Graphics2D g = nImg.createGraphics(); g.setColor(color); g.fillRect(0, 0, nImg.getWidth(), nImg.getHeight()); g.drawImage(img, 0...
### Question: IconHelper { public static BufferedImage flipHoriz(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D gg = newImage.createGraphics(); gg.drawImage(image, image.getHeight(), 0, -image.getWidth(), image.getHeight()...
### Question: IconHelper { public static SDImage getImage(String string) { if (imageCache == null) imageCache = new HashMap<>(); return imageCache.get(string); } private IconHelper(); static int getTextBoxAlphaValue(); static void setTextBoxAlphaValue(int textBoxAlphaValue); static int getRollingTextPadding(); static ...
### Question: IconHelper { public static BufferedImage getImageFromResource(String fileName) { BufferedImage buff = null; try (InputStream inS = IconHelper.class.getResourceAsStream(fileName)) { if (inS != null) { logger.debug("Loading image as resource: " + fileName); buff = ImageIO.read(inS); } else { logger.error("I...
### Question: IconHelper { public static SDImage loadImageSafe(String path) { return loadImageSafe(path, false, null); } private IconHelper(); static int getTextBoxAlphaValue(); static void setTextBoxAlphaValue(int textBoxAlphaValue); static int getRollingTextPadding(); static void setRollingTextPadding(int rollingTex...
### Question: IconHelper { public static SDImage loadImageFromResource(String path) { if (imageCache.containsKey(path)) return imageCache.get(path); BufferedImage img = getImageFromResource(path); if (img != null) { SDImage imgData = convertImage(img); cache(path, imgData); return imgData; } return null; } private Ico...
### Question: IconHelper { public static SDImage loadImageFromResourceSafe(String path) { if (imageCache.containsKey(path)) return imageCache.get(path); BufferedImage img = getImageFromResource(path); if (img != null) { SDImage imgData = convertImage(img); cache(path, imgData); return imgData; } return IconHelper.getIm...
### Question: IconHelper { public static void setTextBoxAlphaValue(int textBoxAlphaValue) { IconHelper.textBoxAlphaValue = textBoxAlphaValue; } private IconHelper(); static int getTextBoxAlphaValue(); static void setTextBoxAlphaValue(int textBoxAlphaValue); static int getRollingTextPadding(); static void setRollingTex...
### Question: IconHelper { public static BufferedImage rotate180(BufferedImage inputImage) { int width = inputImage.getWidth(); int height = inputImage.getHeight(); BufferedImage returnImage = new BufferedImage(height, width, inputImage.getType()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { in...
### Question: IconHelper { public static int getRollingTextPadding() { return rollingTextPadding; } private IconHelper(); static int getTextBoxAlphaValue(); static void setTextBoxAlphaValue(int textBoxAlphaValue); static int getRollingTextPadding(); static void setRollingTextPadding(int rollingTextPadding); static SDI...
### Question: IconHelper { public static void setRollingTextPadding(int rollingTextPadding) { IconHelper.rollingTextPadding = rollingTextPadding; } private IconHelper(); static int getTextBoxAlphaValue(); static void setTextBoxAlphaValue(int textBoxAlphaValue); static int getRollingTextPadding(); static void setRollin...
### Question: IconHelper { public static SDImage createColoredFrame(Color borderColor) { String frameKey = FRAME_IMAGE_PREFIX + String.format("#%02x%02x%02x", borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue()); if(imageCache.containsKey(frameKey)) return imageCache.get(frameKey); BufferedImage img = n...
### Question: IconHelper { public static void applyAlpha(BufferedImage image, BufferedImage mask) { int width = image.getWidth(); int height = image.getHeight(); int[] imagePixels = image.getRGB(0, 0, width, height, null, 0, width); int[] maskPixels = mask.getRGB(0, 0, width, height, null, 0, width); for (int i = 0; i ...
### Question: IconHelper { public static SDImage cacheImage(String path, BufferedImage img) { int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData(); byte[] imgData = new byte[StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE * 3]; int imgDataCount = 0; for (int i = 0; i < StreamDeck.ICON_SIZE * StreamDec...
### Question: IconHelper { public static SDImage applyImage(SDImage imgData, BufferedImage apply) { BufferedImage img = new BufferedImage(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE, imgData. image. getType()); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VA...
### Question: IconHelper { public static BufferedImage applyFrame(BufferedImage img, Color frameColor) { if(img.getWidth() > StreamDeck.ICON_SIZE || img.getHeight() > StreamDeck.ICON_SIZE) img = createResizedCopy(img, true); BufferedImage nImg = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); Graphic...
### Question: BitStream { public void write(int n, long v) { if (n < 1 || n > 64) { throw new IllegalArgumentException( String.format("Unable to write %s bits to value %d", n, v)); } reserve(n); long v1 = v << 64 - n >>> shift; data[index] = data[index] | v1; shift += n; if (shift >= 64) { shift -= 64; index++; if (shi...
### Question: ChunkManager { public List<TimeSeries> query(Query query, long startTsSecs, long endTsSecs, QueryAggregation queryAggregation) { return queryAroundChunkBoundaries(query, startTsSecs, endTsSecs, queryAggregation); } ChunkManager(String chunkDataPrefix, int expectedTagStoreSize); ChunkManager(String chunkD...
### Question: ChunkManager { public void addMetric(final String metricString) { try { String[] metricParts = metricString.split(" "); if (metricParts.length > 1 && metricParts[0].equals("put")) { String metricName = metricParts[1].trim(); List<String> rawTags = Arrays.asList(metricParts).subList(4, metricParts.length);...
### Question: InvertedIndexTagStore implements TagStore { @Override public Optional<Integer> get(Metric m) { if (metricIndex.containsKey(m.fullMetricName)) { return Optional.of(lookupMetricIndex(m.fullMetricName).getIntIterator().next()); } return Optional.empty(); } InvertedIndexTagStore(); InvertedIndexTagStore(int ...
### Question: InvertedIndexTagStore implements TagStore { @Override public int getOrCreate(final Metric m) { Optional<Integer> optionalMetric = get(m); return optionalMetric.isPresent() ? optionalMetric.get() : create(m); } InvertedIndexTagStore(); InvertedIndexTagStore(int metricIdMapCapacity, int initialIndexSize); ...
### Question: TagMatcher { public static TagMatcher wildcardMatch(String key, String wildcardString) { return createWildCardTagMatcher(key, wildcardString, MatchType.WILDCARD); } TagMatcher(MatchType type, Tag tag); @Override boolean equals(Object o); @Override int hashCode(); static TagMatcher exactMatch(Tag tag); sta...
### Question: Tag implements Comparable<Tag> { public static Tag parseTag(String rawTag) { int index = getDelimiterIndex(rawTag); String key = rawTag.substring(0, index); String value = rawTag.substring(index + 1); if (key.isEmpty() || value.isEmpty()) { throw new IllegalArgumentException("Invalid rawTag" + rawTag); } ...
### Question: Query { public Query(final String metricName, final List<TagMatcher> tagMatchers) { if (metricName == null || metricName.isEmpty() || tagMatchers == null) { throw new IllegalArgumentException("metric name or tag matcher can't be null."); } final Map<String, List<TagMatcher>> tagNameMap = tagMatchers.strea...
### Question: Query { public static Query parse(String s) { List<String> splits = Arrays.asList(s.split(" ")); String metricName = splits.get(0); List<TagMatcher> matchers = new ArrayList<>(); for (String s2 : splits.subList(1, splits.size())) { Tag tag = Tag.parseTag(s2); if (tag.value.equals("*")) { matchers.add(TagM...
### Question: OffHeapVarBitMetricStore implements MetricStore { @Override public List<Point> getSeries(long uuid) { final LongValue key = Values.newHeapInstance(LongValue.class); key.setValue(uuid); if (timeSeries.containsKey(key)) { ByteBuffer serializedValues = timeSeries.get(key); TimeSeriesIterator iterator = VarBi...
### Question: OffHeapVarBitMetricStore implements MetricStore { public void addPoint(long uuid, ByteBuffer series) { LongValue key = Values.newHeapInstance(LongValue.class); key.setValue(uuid); timeSeries.put(key, series); } OffHeapVarBitMetricStore(long size, String chunkInfo); OffHeapVarBitMetricStore(long size, int...
### Question: VarBitTimeSeries { public synchronized void append(long timestamp, double value) { if (timestamp < 0 || timestamp > MAX_UNIX_TIMESTAMP) { throw new IllegalArgumentException("Timestamp is not a valid unix timestamp: " + timestamp); } if (size == 0) { appendFirstPoint(timestamp, value); } else { appendNextP...
### Question: VarBitTimeSeries { public synchronized TimeSeriesIterator read() { return new CachingVarBitTimeSeriesIterator(size, timestamps.read(), values.read()); } VarBitTimeSeries(); synchronized void append(long timestamp, double value); synchronized TimeSeriesIterator read(); Map<String, Double> getStats(); int g...
### Question: VarBitMetricStore implements MetricStore { @Override public List<Point> getSeries(long uuid) { mu.readLock().lock(); try { VarBitTimeSeries s = series.get(uuid); if (s == null) { return Collections.emptyList(); } return s.read().getPoints(); } finally { mu.readLock().unlock(); } } VarBitMetricStore(); Va...
### Question: ChunkImpl implements Chunk { @Override public boolean containsDataInTimeRange(long startTs, long endTs) { return (chunkInfo.startTimeSecs <= startTs && chunkInfo.endTimeSecs >= startTs) || (chunkInfo.startTimeSecs <= endTs && chunkInfo.endTimeSecs >= endTs) || (chunkInfo.startTimeSecs >= startTs && chunkI...
### Question: EtcdServiceRegistry implements ServiceRegistry<EtcdRegistration> { @Override public void register(EtcdRegistration registration) { String etcdKey = registration.etcdKey(properties.getPrefix()); try { long leaseId = lease.getLeaseId(); PutOption putOption = PutOption.newBuilder() .withLeaseId(leaseId) .bui...
### Question: EtcdServiceRegistry implements ServiceRegistry<EtcdRegistration> { @Override public void deregister(EtcdRegistration registration) { String etcdKey = registration.etcdKey(properties.getPrefix()); try { etcdClient.getKVClient() .delete(fromString(etcdKey)) .get(); lease.revoke(); } catch (InterruptedExcept...
### Question: EtcdHeartbeatLease implements AutoCloseable { public Long getLeaseId() { initLease(); return leaseId; } EtcdHeartbeatLease(Client etcdClient, HeartbeatProperties properties); void initLease(); Long getLeaseId(); void revoke(); @Override void close(); }### Answer: @Test public void testEtcdLeaseIsAvailabl...
### Question: Counter extends Applet { private void getBalance(APDU apdu, byte[] buffer) { Util.setShort(buffer, (byte) 0, balance); apdu.setOutgoingAndSend((byte) 0, (byte) 2); } private Counter(); static void install(byte[] buffer, short offset, byte length); void process(APDU apdu); static final byte INS_GET_BALANC...
### Question: Counter extends Applet { private void credit(APDU apdu, byte[] buffer) { short credit; if (apdu.setIncomingAndReceive() != 2) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); credit = Util.getShort(buffer, ISO7816.OFFSET_CDATA); if (((short) (credit + balance) > MAX_BALANCE) || (credit <= 0) || (credit > MA...
### Question: Counter extends Applet { private void debit(APDU apdu, byte[] buffer) { short debit; if (apdu.setIncomingAndReceive() != 2) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); debit = Util.getShort(buffer, ISO7816.OFFSET_CDATA); if ((debit > balance) || (debit <= 0) || (debit > MAX_DEBIT)) ISOException.throwIt...
### Question: PasswordEntry { static void delete(byte[] buf, short ofs, byte len) { PasswordEntry pe = search(buf, ofs, len); if (pe != null) { JCSystem.beginTransaction(); pe.remove(); pe.recycle(); JCSystem.commitTransaction(); } } private PasswordEntry(); static PasswordEntry getFirst(); byte getIdLength(); Passwor...
### Question: MapValueReader implements ValueReader<Map<String, Object>> { @Override public Object get(Map<String, Object> source, String memberName) { return source.get(memberName); } @Override Object get(Map<String, Object> source, String memberName); @SuppressWarnings("unchecked") @Override Member<Map<String, Objec...
### Question: NumberConverter implements ConditionalConverter<Object, Number> { public Number convert(MappingContext<Object, Number> context) { Object source = context.getSource(); if (source == null) return null; Class<?> destinationType = Primitives.wrapperFor(context.getDestinationType()); if (source instanceof Numb...
### Question: ProxyFactory { static <T> T proxyFor(Class<T> type, InvocationHandler interceptor, Errors errors) throws ErrorsException { return proxyFor(type, interceptor, errors, Boolean.FALSE); } }### Answer: @Test public void shouldProxyTypesWithNonDefaultConstructor() { InvocationHandler interceptor = mock(Invoc...
### Question: BooleanConverter implements ConditionalConverter<Object, Boolean> { public Boolean convert(MappingContext<Object, Boolean> context) { Object source = context.getSource(); if (source == null) return null; String stringValue = source.toString().toLowerCase(); if (stringValue.length() == 0) return null; for ...
### Question: MapObjs { synchronized static Object[] toArray(Object now) { if (now instanceof MapObjs) { return ((MapObjs) now).all.toArray(); } final Fn.Presenter p = getOnlyPresenter(); if (p == null) { return new Object[0]; } return new Object[] { p, now }; } private MapObjs(Fn.Ref id1, Object js); private MapObjs...
### Question: JSON { public static Character charValue(Object val) { if (val instanceof Number) { return Character.toChars(numberValue(val).intValue())[0]; } if (val instanceof Boolean) { return (Boolean)val ? (char)1 : (char)0; } if (val instanceof String) { String s = (String)val; return s.isEmpty() ? (char)0 : s.cha...
### Question: JSON { public static Boolean boolValue(Object val) { if (val instanceof String) { return Boolean.parseBoolean((String)val); } if (val instanceof Number) { return numberValue(val).doubleValue() != 0.0; } return Boolean.TRUE.equals(val); } private JSON(); static Transfer findTransfer(BrwsrCtx c); static WS...
### Question: SimpleList implements List<E> { @Override public ListIterator<E> listIterator() { return new LI(0, size); } SimpleList(); private SimpleList(Object[] data); static List<T> asList(T... arr); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<E> iter...
### Question: SimpleList implements List<E> { @Override public boolean retainAll(Collection<?> c) { return retainImpl(this, c); } SimpleList(); private SimpleList(Object[] data); static List<T> asList(T... arr); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator...