method2testcases
stringlengths
118
6.63k
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String format(Format format, List<Object> input) { if (format == null || format.getTemplate() == null) { throw new IllegalArgumentException("Format must be specified with a template"); } return String.format(Locale...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String genareteUUID(GenerateUUID action) { return UUID.randomUUID().toString(); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static S...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number indexOf(IndexOf indexOf, String input) { if (indexOf == null || indexOf.getString() == null) { throw new IllegalArgumentException("IndexOf must be specified with a string"); } return input == null ? -1 : inp...
### Question: AtlasModelFactory { public static Action cloneAction(Action action) { if (action == null) { return null; } try { ObjectMapper mapper = new ObjectMapper() .enable(MapperFeature.BLOCK_UNSAFE_POLYMORPHIC_BASE_TYPES); String s = mapper.writeValueAsString(action); System.out.println(s); return mapper.readerFor...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number lastIndexOf(LastIndexOf lastIndexOf, String input) { if (lastIndexOf == null || lastIndexOf.getString() == null) { throw new IllegalArgumentException("LastIndexOf must be specified with a string"); } return ...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String padStringLeft(PadStringLeft padStringLeft, String input) { if (padStringLeft == null || padStringLeft.getPadCharacter() == null || padStringLeft.getPadCount() == null) { throw new IllegalArgumentException("P...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String padStringRight(PadStringRight padStringRight, String input) { if (padStringRight == null || padStringRight.getPadCharacter() == null || padStringRight.getPadCount() == null) { throw new IllegalArgumentExcept...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String prepend(Prepend action, String input) { String string = action.getString(); if (input == null) { return string; } if (string == null) { return input; } return string.concat(input); } @AtlasActionProcessor s...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String replaceFirst(ReplaceFirst replaceFirst, String input) { if (replaceFirst == null || replaceFirst.getMatch() == null || replaceFirst.getMatch().isEmpty()) { throw new IllegalArgumentException("ReplaceFirst ac...
### Question: AtlasModelFactory { public static PropertyField createPropertyField() { return new PropertyField(); } private AtlasModelFactory(); @SuppressWarnings("unchecked") static T createMapping(MappingType type); static AtlasMapping createAtlasMapping(); static Collection createCollection(); static MockDocument c...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String replaceAll(ReplaceAll replaceAll, String input) { if (replaceAll == null || replaceAll.getMatch() == null || replaceAll.getMatch().isEmpty()) { throw new IllegalArgumentException("ReplaceAll action must be s...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor(sourceType = FieldType.ANY) public static String[] split(Split split, String input) { if (split == null || split.getDelimiter() == null) { throw new IllegalArgumentException("Split must be specified with a delimiter"); } return ...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Boolean startsWith(StartsWith startsWith, String input) { if (startsWith == null || startsWith.getString() == null) { throw new IllegalArgumentException("StartsWith must be specified with a string"); } return input...
### Question: AtlasModelFactory { public static Field cloneField(Field f) { throw new IllegalArgumentException("Use module specific factories to clone fields"); } private AtlasModelFactory(); @SuppressWarnings("unchecked") static T createMapping(MappingType type); static AtlasMapping createAtlasMapping(); static Colle...
### Question: StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String subString(SubString subString, String input) { if (input == null || input.length() == 0) { return input; } if (subString == null || subString.getStartIndex() == null || subString.getStartIndex() < 0) { throw...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) public static ZonedDateTime addDays(AddDays addDays, ZonedDateTime input) { if (addDays == null) { throw new IllegalArgumentException("AddDays action must be specified"); } if (input == null) { return nul...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) public static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input) { if (addSeconds == null) { throw new IllegalArgumentException("AddSeconds action must be specified"); } if (input == nul...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static ZonedDateTime currentDate(CurrentDate action) { return LocalDate.now().atStartOfDay(ZoneId.systemDefault()); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addDays(AddDays addDays, ZonedDateT...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static ZonedDateTime currentDateTime(CurrentDateTime action) { return LocalDate.now().atStartOfDay(ZoneId.systemDefault()); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addDays(AddDays addDays, Zo...
### Question: AtlasModelFactory { public static String toString(PropertyField f) { StringBuilder tmp = new StringBuilder("PropertyField [name="); if (f != null && f.getName() != null) { tmp.append(f.getName()); } tmp.append(baseFieldToString(f)); tmp.append("]"); return tmp.toString(); } private AtlasModelFactory(); @...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static ZonedDateTime currentTime(CurrentTime action) { return LocalTime.now().atDate(LocalDate.now()).atZone(ZoneId.systemDefault()); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addDays(AddDays a...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) public static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input) { return input == null ? null : input.getDayOfMonth(); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTi...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) public static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input) { return input == null ? null : input.getDayOfWeek().getValue(); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Zon...
### Question: DateFieldActions implements AtlasFieldAction { @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) public static Integer dayOfYear(DayOfYear action, ZonedDateTime input) { return input == null ? null : input.getDayOfYear(); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime ...
### Question: ObjectFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Integer count(Count action, List<Object> inputs) { if (inputs == null) { return 0; } return inputs.size(); } @AtlasActionProcessor static Integer count(Count action, List<Object> inputs); @AtlasActionProcessor static Boo...
### Question: ObjectFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Boolean contains(Contains contains, List<Object> inputs) { if (contains == null) { throw new IllegalArgumentException("Contains action must be specified"); } if (inputs == null) { return contains.getValue() == null; } ret...
### Question: ObjectFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Boolean equals(Equals equals, Object input) { if (equals == null) { throw new IllegalArgumentException("Equals action must be specified"); } if (input == null) { return equals.getValue() == null; } return input.toString()...
### Question: ObjectFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Boolean isNull(IsNull action, Object input) { return input == null; } @AtlasActionProcessor static Integer count(Count action, List<Object> inputs); @AtlasActionProcessor static Boolean contains(Contains contains, List<O...
### Question: ObjectFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Object itemAt(ItemAt itemAt, List<Object> inputs) { if (inputs == null) { return null; } Integer index = itemAt.getIndex() == null ? 0 : itemAt.getIndex(); Object[] array = inputs.toArray(new Object[0]); if (array.length ...
### Question: ObjectFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Integer length(Length length, Object input) { if (input == null) { return -1; } return input.toString().length(); } @AtlasActionProcessor static Integer count(Count action, List<Object> inputs); @AtlasActionProcessor sta...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String capitalize(Capitalize action, String input) { if (input == null || input.length() == 0) { return input; } if (input.length() == 1) { return String.valueOf(input.charAt(0)).toUpperCase(); } return String.value...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String fileExtension(FileExtension action, String input) { if (input == null) { return null; } int ndx = input.lastIndexOf('.'); return ndx < 0 ? null : input.substring(ndx + 1); } @AtlasActionProcessor static Stri...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String lowercase(Lowercase action, String input) { if (input == null) { return null; } return input.toLowerCase(); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasActionProc...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Character lowercaseChar(LowercaseChar action, Character input) { if (input == null) { return null; } return String.valueOf(input).toLowerCase().charAt(0); } @AtlasActionProcessor static String capitalize(Capitalize...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String normalize(Normalize action, String input) { return input == null ? null : input.replaceAll("\\s+", " ").trim(); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasAction...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String removeFileExtension(RemoveFileExtension action, String input) { if (input == null) { return null; } int ndx = input.lastIndexOf('.'); return ndx < 0 ? input : input.substring(0, ndx); } @AtlasActionProcessor...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String separateByDash(SeparateByDash action, String input) { if (input == null || input.length() == 0) { return input; } return STRING_SEPARATOR_PATTERN.matcher(input).replaceAll("-"); } @AtlasActionProcessor stati...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String separateByUnderscore(SeparateByUnderscore action, String input) { if (input == null || input.length() == 0) { return input; } return STRING_SEPARATOR_PATTERN.matcher(input).replaceAll("_"); } @AtlasActionPro...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String trim(Trim action, String input) { if (input == null || input.length() == 0) { return input; } return input.trim(); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasAct...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String trimLeft(TrimLeft action, String input) { if (input == null || input.length() == 0) { return input; } int i = 0; while (i < input.length() && Character.isWhitespace(input.charAt(i))) { i++; } return input.sub...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String trimRight(TrimRight action, String input) { if (input == null || input.length() == 0) { return input; } int i = input.length() - 1; while (i >= 0 && Character.isWhitespace(input.charAt(i))) { i--; } return in...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String uppercase(Uppercase action, String input) { if (input == null) { return null; } return input.toUpperCase(); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasActionProc...
### Question: StringSimpleFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Character uppercaseChar(UppercaseChar action, Character input) { if (input == null) { return null; } return String.valueOf(input).toUpperCase().charAt(0); } @AtlasActionProcessor static String capitalize(Capitalize...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number absoluteValue(AbsoluteValue action, Number input) { if (input == null) { return 0; } if (input instanceof BigDecimal) { return ((BigDecimal) input).abs(); } if (requiresDoubleResult(input)) { return Math.abs(input....
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number add(Add action, List<Number> inputs) { if (inputs == null) { return 0; } Number sum = 0L; for (Object entry : inputs) { if (entry instanceof Number) { if (sum instanceof BigDecimal) { sum = ((BigDecimal) sum).add(B...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number average(Average action, List<Number> inputs) { if (inputs == null) { return 0; } return add(null, inputs).doubleValue() / inputs.size(); } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Nu...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number ceiling(Ceiling action, Number input) { return input == null ? 0L : (long)Math.ceil(input.doubleValue()); } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProces...
### Question: DateConverter implements AtlasConverter<Date> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) public ZonedDateTime toZonedDateTime(Date date) { return DateTimeHelper.toZonedDateTime(date, null); } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetT...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input) { if (input == null) { return 0; } if (convertMassUnit == null || convertMassUnit.getFromUnit() == null || convertMassUnit.getToUnit() == null) { throw...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number divide(Divide divide, List<Number> inputs) { if (inputs == null) { return 0; } Number quotient = null; for (Object entry : inputs) { if (entry instanceof Number) { if (quotient == null) { quotient = (Number) entry;...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number floor(Floor floor, Number input) { return input == null ? 0L : (long)Math.floor(input.doubleValue()); } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor ...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number maximum(Maximum maximum, List<Number> inputs) { if (inputs == null) { return 0; } Number max = null; for (Object entry : inputs) { if (entry instanceof Number) { if (max instanceof BigDecimal && entry instanceof Bi...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number minimum(Minimum minimum, List<Number> inputs) { if (inputs == null) { return 0; } Number min = null; for (Object entry : inputs) { if (entry instanceof Number) { if (min instanceof BigDecimal && entry instanceof Bi...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number round(Round action, Number input) { return input == null ? 0L : Math.round(input.doubleValue()); } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor stati...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number subtract(Subtract subtract, List<Number> inputs) { if (inputs == null) { return 0; } Number difference = null; for (Object entry : inputs) { if (entry instanceof Number) { if (difference == null) { difference = (Nu...
### Question: NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number multiply(Multiply multiply, List<Number> inputs) { if (inputs == null) { return 0; } Number product = 1L; for (Object entry : inputs) { if (entry instanceof Number) { if (product instanceof BigDecimal) { product = ...
### Question: DateConverter implements AtlasConverter<Date> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) public Timestamp toSqlTimestamp(Date date) { return Timestamp.from(date.toInstant()); } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DE...
### Question: DateConverter implements AtlasConverter<Date> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) public Calendar toCalendar(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); return calendar; } @AtlasConversionInfo...
### Question: DateConverter implements AtlasConverter<Date> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.STRING) public String toString(Date date) { return date.toInstant().toString(); } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DECIMAL) BigDecimal...
### Question: DateConverter implements AtlasConverter<Date> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.LONG) public Long toLong(Date date) { return date.toInstant().toEpochMilli(); } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DECIMAL) BigDecimal t...
### Question: CalendarConverter implements AtlasConverter<Calendar> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME) public Date toDate(Calendar calendar) { return calendar != null ? calendar.getTime() : null; } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targ...
### Question: CalendarConverter implements AtlasConverter<Calendar> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME_TZ) public ZonedDateTime toZonedDateTime(Calendar calendar) { return calendar == null ? null : DateTimeHelper.toZonedDateTime(calendar); } @AtlasConversionInf...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) public Boolean toBoolean(Long value) { if (value == null) { return null; } return value == 0L ? Boolean.FALSE : Boolean.TRUE; } @...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) public Byte toByte(Long value) throws AtlasConversionException { if (value == null) { return null; } if (value >= Byte.MIN_VALUE && value ...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) public Character toCharacter(Long value) throws AtlasConversionException { if (value == null) { ret...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) public Date toDate(Long date) { if (date >= Instant.MIN.getEpochSecond()) { return Date.from(Instant.ofEpochMilli(date)); } return new Date(date); } @AtlasConversionInfo(...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) public Double toDouble(Long value) { if (value == null) { return null; } return value.doubleValue(); } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType....
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) public Float toFloat(Long value) { if (value == null) { return null; } return value.floatValue(); } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECI...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) public Integer toInteger(Long value) throws AtlasConversionException { if (value == null) { return null; } if (value > Integer.MAX_VALU...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) public Long toLong(Long value) { return value != null ? new Long(value) : null; } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toB...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) public Short toShort(Long value) throws AtlasConversionException { if (value == null) { return null; } if (value > Short.MAX_VALUE || val...
### Question: LongConverter implements AtlasConverter<Long> { @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) public String toString(Long value) { return value != null ? String.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) Bi...
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) public Boolean toBoolean(Character value, String sourceFormat, String targetFormat) { if (value == null) { return nu...
### Question: BackupPayload { public static BackupPayload deserialize(byte[] data){ ByteReader reader = new ByteReader(data); try { byte version = reader.get(); int timestamp = reader.getIntLE(); byte[] iv = reader.getBytes(16); int cipherTextLen = (int)reader.getCompactInt(); byte[] cipherText = reader.getBytes(cipher...
### Question: ExponentialFeeItemsAlgorithm implements FeeItemsAlgorithm { @Override public int getMinPosition() { return minPosition; } ExponentialFeeItemsAlgorithm(long minValue, int minPosition, long maxValue, int maxPosition); @Override long computeValue(int position); @Override int getMinPosition(); @Override int g...
### Question: ExponentialFeeItemsAlgorithm implements FeeItemsAlgorithm { @Override public int getMaxPosition() { return maxPosition; } ExponentialFeeItemsAlgorithm(long minValue, int minPosition, long maxValue, int maxPosition); @Override long computeValue(int position); @Override int getMinPosition(); @Override int g...
### Question: MerkleTree { public static MerkleTree fromData(byte[] data){ return fromData(data, DEFAULT_CHUNK_SIZE); } MerkleTree(Sha256Hash root, ArrayList<byte[]> chunks); static MerkleTree fromData(byte[] data); static MerkleTree fromData(byte[] data, int chunkSize); Sha256Hash getRoot(); ArrayList<byte[]> getChunk...
### Question: HexUtils { public static String toHex(byte[] bytes) { return toHex(bytes, null); } static String toHex(byte[] bytes); static String toHex(byte[] bytes, String separator); static String toHex(byte[] bytes, int offset, int length); static String toHex(byte b); static String toHex(byte[] bytes, int offset, ...
### Question: HexUtils { public static byte[] toBytes(String hexString) { if(hexString != null) { hexString = hexString.replace(" ", ""); } if (hexString == null || hexString.length() % 2 != 0) { throw new RuntimeException("Input string must contain an even number of characters"); } char[] hex = hexString.toCharArray()...
### Question: ScriptOutputOpReturn extends ScriptOutput implements Serializable { protected static boolean isScriptOutputOpReturn(byte[][] chunks) { return chunks.length == 2 && Script.isOP(chunks[0], OP_RETURN) && chunks[1] != null && chunks[1].length > 0; } protected ScriptOutputOpReturn(byte[][] chunks, byte[] scri...
### Question: StandardTransactionBuilder { public static List<byte[]> generateSignatures(SigningRequest[] requests, IPrivateKeyRing keyRing) { List<byte[]> signatures = new LinkedList<>(); for (SigningRequest request : requests) { BitcoinSigner signer = keyRing.findSignerByPublicKey(request.getPublicKey()); if (signer ...
### Question: Counter { public boolean isZero() { for (byte b : state) { if (b != 0) { return false; } } return true; } Counter(int bits); void increment(); byte[] getState(); boolean isZero(); }### Answer: @Test public void shouldBeZero() throws Exception { assertTrue(counter.isZero()); }
### Question: PopRequest implements Serializable { public Long getAmountSatoshis() { return amountSatoshis; } PopRequest(String input); byte[] getN(); Long getAmountSatoshis(); String getLabel(); Sha256Hash getTxid(); String getP(); String getMessage(); String toString(); }### Answer: @Test public void testCreateMaxBi...
### Question: Fortuna extends Random { public static Fortuna createInstance() { return createInstance(defaultSources()); } private Fortuna(Generator generator, Pool[] pools); static Fortuna createInstance(); static Fortuna createInstance(Iterable<EntropySource> sources); @Override synchronized void setSeed(long seed);...
### Question: ThreadTimeEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { long threadTime = threadMXBean.getCurrentThreadCpuTime() + threadMXBean.getCurrentThreadUserTime(); adder.add(Util.twoLeastSignificantBytes(threadTime)); scheduler.schedule(100, Tim...
### Question: PlatformEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { try { InputStream inputStream = device2Stream(); try { int size = inputStream.read(bytes); Preconditions.checkState(size == bytes.length); adder.add(bytes); scheduler.schedule(100, Ti...
### Question: SchedulingEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { long now = System.nanoTime(); long elapsed = now - lastTime; lastTime = now; adder.add(Util.twoLeastSignificantBytes(elapsed)); scheduler.schedule(10, TimeUnit.MILLISECONDS); } @Ov...
### Question: UptimeEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { long uptime = runtimeMXBean.getUptime(); adder.add(Util.twoLeastSignificantBytes(uptime)); scheduler.schedule(1, TimeUnit.SECONDS); } @Override void event(EventScheduler scheduler, Eve...
### Question: LoadAverageEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { double systemLoadAverage = operatingSystemMXBean.getSystemLoadAverage(); BigDecimal value = BigDecimal.valueOf(systemLoadAverage); long convertedValue = value.movePointRight(value....
### Question: GarbageCollectorEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { long sum = 0; for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { sum += garbageCollectorMXBean.getCollectionCount() + garbageCollectorMXBean.getCo...
### Question: FreeMemoryEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { long freeMemory = Runtime.getRuntime().freeMemory(); adder.add(Util.twoLeastSignificantBytes(freeMemory)); scheduler.schedule(100, TimeUnit.MILLISECONDS); } @Override void event(Ev...
### Question: Pool { public void add(int source, byte[] event) { writeLock.lock(); try { if (source < 0 || source > 255) { throw new IllegalArgumentException("Source needs to be in the range 0 to 255, it was " + source); } if (event.length < 1 || event.length > 32) { throw new IllegalArgumentException("The length of th...
### Question: PopRequest implements Serializable { public String getLabel() { return label; } PopRequest(String input); byte[] getN(); Long getAmountSatoshis(); String getLabel(); Sha256Hash getTxid(); String getP(); String getMessage(); String toString(); }### Answer: @Test public void testCreateUrlDecode() throws Un...
### Question: Pool { public byte[] getAndClear() { writeLock.lock(); try { size = 0; return poolDigest.digest(); } finally { writeLock.unlock(); } } long size(); void add(int source, byte[] event); byte[] getAndClear(); }### Answer: @Test public void shouldGet32BytesOfSeedData() throws Exception { byte[] bytes = pool...
### Question: BackupUtil { public String getKey() { final String realpassword; if (password.length() == 16) { boolean checksumValid = MrdExport.isChecksumValid(password); if (!checksumValid) { return "Error: the last character of the password was not matching the checksum"; } else { realpassword = password.substring(0,...
### Question: BCHBechAddress { public static BechAddressParams bchBechDecode(String bech) throws Exception { byte[] buffer = bech.getBytes(); for (byte b : buffer) { if (b < 0x21 || b > 0x7e) { throw new Exception("bech32 characters out of range"); } } if (!bech.equals(bech.toLowerCase(Locale.ROOT)) && !bech.equals(bec...
### Question: ExponentialFeeItemsAlgorithm implements FeeItemsAlgorithm { @Override public long computeValue(int position) { int step = position - minPosition; return round((double)minValue * pow(scale, step)); } ExponentialFeeItemsAlgorithm(long minValue, int minPosition, long maxValue, int maxPosition); @Override lon...
### Question: JazonList { public List<JsonExpectationInput> list() { return list; } JazonList(Predicate<?>... predicates); JazonList(Object... objects); JazonList with(Object object); JazonList with(Predicate<T> predicate); List<JsonExpectationInput> list(); }### Answer: @Test void onlySimpleTypes() { JazonList jazon...
### Question: MetadataExample implements Closeable { public void listProperties () throws IOException { for(Property property : dataset.getProperties()) { System.out.format("%s (%s) - %s%n", property.getName(), property.valueType.name(), property.getDescription()); StringBuilder propertyOutput = new StringBuilder(); fo...
### Question: StronglyTypedValues implements Closeable { public boolean isMobile(String userAgent) throws IOException { Match match = provider.match(userAgent); return match.getValues("IsMobile").toBool(); } StronglyTypedValues(); boolean isMobile(String userAgent); static void main(String[] args); @Override void close...