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.ROOT, format.getTemplate(), input == null ? null : input.toArray(new Object[0])); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testFormat() { Format action = new Format(); action.setTemplate("foofoo"); assertEquals("foofoo", StringComplexFieldActions.format(action, null)); assertEquals("foofoo", StringComplexFieldActions.format(action, Arrays.asList(""))); assertEquals("foofoo", StringComplexFieldActions.format(action, Arrays.asList("bar"))); action.setTemplate("foo%sfoo"); assertEquals("foonullfoo", StringComplexFieldActions.format(action, null)); assertEquals("foofoo", StringComplexFieldActions.format(action, Arrays.asList(""))); assertEquals("foobarfoo", StringComplexFieldActions.format(action, Arrays.asList("bar"))); action.setTemplate("foo%1$sfoo%1$s"); assertEquals("foobarfoobar", StringComplexFieldActions.format(action, Arrays.asList("bar"))); }
@Test(expected=IllegalArgumentException.class) public void testFormatNullAction() { StringComplexFieldActions.format(null, null); }
@Test(expected=IllegalArgumentException.class) public void testFormatNullTemplate() { StringComplexFieldActions.format(new Format(), null); } |
### 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 String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testGenareteUUID() { validateGeneratedUUID(StringComplexFieldActions.genareteUUID(new GenerateUUID())); } |
### 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 : input.indexOf(indexOf.getString()); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testIndexOf() { IndexOf action = new IndexOf(); action.setString(""); assertEquals(-1, StringComplexFieldActions.indexOf(action, null)); assertEquals(0, StringComplexFieldActions.indexOf(action, "")); assertEquals(0, StringComplexFieldActions.indexOf(action, "foo")); action.setString("bar"); assertEquals(-1, StringComplexFieldActions.indexOf(action, null)); assertEquals(-1, StringComplexFieldActions.indexOf(action, "")); assertEquals(-1, StringComplexFieldActions.indexOf(action, "foo")); assertEquals(3, StringComplexFieldActions.indexOf(action, "foobar")); assertEquals(3, StringComplexFieldActions.indexOf(action, "foobarbar")); }
@Test(expected=IllegalArgumentException.class) public void testIndexOfNullAction() { StringComplexFieldActions.indexOf(null, null); }
@Test(expected=IllegalArgumentException.class) public void testIndexOfNullString() { StringComplexFieldActions.indexOf(new IndexOf(), null); } |
### 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(Action.class).readValue(s); } catch (IOException e) { throw new RuntimeException(e); } } private AtlasModelFactory(); @SuppressWarnings("unchecked") static T createMapping(MappingType type); static AtlasMapping createAtlasMapping(); static Collection createCollection(); static MockDocument createMockDocument(); static MockField createMockField(); static PropertyField createPropertyField(); static BaseMapping cloneMapping(BaseMapping baseMapping, boolean deepClone); static Field cloneField(Field f); static FieldGroup copyFieldGroup(FieldGroup fg); static SimpleField cloneFieldToSimpleField(Field field); static void copyField(Field from, Field to, boolean withActions); static FieldGroup createFieldGroupFrom(Field field, boolean withActions); static ArrayList<Action> cloneFieldActions(ArrayList<Action> actions); static Action cloneAction(Action action); static String toString(PropertyField f); static String toString(Field f); static Field wrapWithField(Object val); static Field wrapWithField(Object val, String parentPath); static Object unwrapField(Field f); static final String GENERATED_PATH; }### Answer:
@Test public void testCloneAction() throws Exception { for (Action a : ModelTestUtil.getAllOOTBActions()) { assertNotNull(a); Action b = AtlasModelFactory.cloneAction((Action)a); assertNotNull(String.format("Add %s to AtlasModelFactory#cloneAction()", a.getClass().getSimpleName()), b); assertNotSame(a, b); assertEquals(a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); } } |
### 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 input == null ? -1 : input.lastIndexOf(lastIndexOf.getString()); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testLastIndexOf() { LastIndexOf action = new LastIndexOf(); action.setString(""); assertEquals(-1, StringComplexFieldActions.lastIndexOf(action, null)); assertEquals(0, StringComplexFieldActions.lastIndexOf(action, "")); assertEquals(3, StringComplexFieldActions.lastIndexOf(action, "foo")); action.setString("bar"); assertEquals(-1, StringComplexFieldActions.lastIndexOf(action, null)); assertEquals(-1, StringComplexFieldActions.lastIndexOf(action, "")); assertEquals(-1, StringComplexFieldActions.lastIndexOf(action, "foo")); assertEquals(3, StringComplexFieldActions.lastIndexOf(action, "foobar")); assertEquals(6, StringComplexFieldActions.lastIndexOf(action, "foobarbar")); }
@Test(expected=IllegalArgumentException.class) public void testLastIndexOfNullAction() { StringComplexFieldActions.lastIndexOf(null, null); }
@Test(expected=IllegalArgumentException.class) public void testLastIndexOfNullString() { StringComplexFieldActions.lastIndexOf(new LastIndexOf(), null); } |
### 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("PadStringLeft must be specified with padCharacter and padCount"); } StringBuilder builder = new StringBuilder(); for (int i = 0; i < padStringLeft.getPadCount(); i++) { builder.append(padStringLeft.getPadCharacter()); } if (input != null) { builder.append(input); } return builder.toString(); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testPadStringLeft() { PadStringLeft padStringLeft = new PadStringLeft(); padStringLeft.setPadCharacter("a"); padStringLeft.setPadCount(3); assertEquals("aaa", StringComplexFieldActions.padStringLeft(padStringLeft, null)); assertEquals("aaa", StringComplexFieldActions.padStringLeft(padStringLeft, "")); assertEquals("aaaa", StringComplexFieldActions.padStringLeft(padStringLeft, "a")); assertEquals("aaab", StringComplexFieldActions.padStringLeft(padStringLeft, "b")); try { StringComplexFieldActions.padStringLeft(null, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } try { StringComplexFieldActions.padStringLeft(new PadStringLeft(), "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } try { PadStringLeft incomplete = new PadStringLeft(); incomplete.setPadCharacter("f"); StringComplexFieldActions.padStringLeft(incomplete, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } try { PadStringLeft incomplete = new PadStringLeft(); incomplete.setPadCount(3); StringComplexFieldActions.padStringLeft(incomplete, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } } |
### Question:
StringComplexFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static String padStringRight(PadStringRight padStringRight, String input) { if (padStringRight == null || padStringRight.getPadCharacter() == null || padStringRight.getPadCount() == null) { throw new IllegalArgumentException("PadStringRight must be specified with padCharacter and padCount"); } StringBuilder builder = new StringBuilder(); if (input != null) { builder.append(input); } for (int i = 0; i < padStringRight.getPadCount(); i++) { builder.append(padStringRight.getPadCharacter()); } return builder.toString(); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testPadStringRight() { PadStringRight padStringRight = new PadStringRight(); padStringRight.setPadCharacter("a"); padStringRight.setPadCount(3); assertEquals("aaa", StringComplexFieldActions.padStringRight(padStringRight, null)); assertEquals("aaa", StringComplexFieldActions.padStringRight(padStringRight, "")); assertEquals("aaaa", StringComplexFieldActions.padStringRight(padStringRight, "a")); assertEquals("baaa", StringComplexFieldActions.padStringRight(padStringRight, "b")); try { StringComplexFieldActions.padStringRight(null, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } try { StringComplexFieldActions.padStringRight(new PadStringRight(), "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } try { PadStringRight incomplete = new PadStringRight(); incomplete.setPadCharacter("f"); StringComplexFieldActions.padStringRight(incomplete, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } try { PadStringRight incomplete = new PadStringRight(); incomplete.setPadCount(3); StringComplexFieldActions.padStringRight(incomplete, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } } |
### 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 static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testPrepend() { Prepend action = new Prepend(); assertEquals(null, StringComplexFieldActions.prepend(action, null)); assertEquals("foo", StringComplexFieldActions.prepend(action, "foo")); assertEquals("1", StringComplexFieldActions.prepend(action, "1")); action.setString(""); assertEquals("", StringComplexFieldActions.prepend(action, null)); assertEquals("foo", StringComplexFieldActions.prepend(action, "foo")); action.setString("bar"); assertEquals("bar", StringComplexFieldActions.prepend(action, null)); assertEquals("barfoo", StringComplexFieldActions.prepend(action, "foo")); assertEquals("bar1", StringComplexFieldActions.prepend(action, "1")); }
@Test(expected=NullPointerException.class) public void testPrependNullAction() { StringComplexFieldActions.prepend(null, null); } |
### 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 action must be specified with a non-empty old string"); } String match = replaceFirst.getMatch(); String newString = replaceFirst.getNewString(); return input == null ? null : input.replaceFirst(match, newString == null ? "" : newString); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testReplaceFirst() { ReplaceFirst replaceFirst = new ReplaceFirst(); replaceFirst.setMatch(" "); assertNull(StringComplexFieldActions.replaceFirst(replaceFirst, null)); assertEquals("", StringComplexFieldActions.replaceFirst(replaceFirst, "")); assertEquals("test", StringComplexFieldActions.replaceFirst(replaceFirst, "test")); replaceFirst.setMatch("e"); assertEquals("tst", StringComplexFieldActions.replaceFirst(replaceFirst, "test")); replaceFirst.setMatch("t"); replaceFirst.setNewString("h"); assertEquals("hest", StringComplexFieldActions.replaceFirst(replaceFirst, "test")); replaceFirst.setMatch("is"); replaceFirst.setNewString("at"); assertEquals("That is a test", StringComplexFieldActions.replaceFirst(replaceFirst, "This is a test")); }
@Test(expected = IllegalArgumentException.class) public void testReplaceFirstEmptyMatch() { ReplaceFirst replaceFirst = new ReplaceFirst(); replaceFirst.setMatch(""); StringComplexFieldActions.replaceFirst(replaceFirst, " "); }
@Test(expected=IllegalArgumentException.class) public void testReplaceFirstNullAction() { StringComplexFieldActions.replaceFirst(null, null); }
@Test(expected = IllegalArgumentException.class) public void testReplaceFirstNullMatch() { ReplaceFirst replaceFirst = new ReplaceFirst(); StringComplexFieldActions.replaceFirst(replaceFirst, " "); } |
### 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 createMockDocument(); static MockField createMockField(); static PropertyField createPropertyField(); static BaseMapping cloneMapping(BaseMapping baseMapping, boolean deepClone); static Field cloneField(Field f); static FieldGroup copyFieldGroup(FieldGroup fg); static SimpleField cloneFieldToSimpleField(Field field); static void copyField(Field from, Field to, boolean withActions); static FieldGroup createFieldGroupFrom(Field field, boolean withActions); static ArrayList<Action> cloneFieldActions(ArrayList<Action> actions); static Action cloneAction(Action action); static String toString(PropertyField f); static String toString(Field f); static Field wrapWithField(Object val); static Field wrapWithField(Object val, String parentPath); static Object unwrapField(Field f); static final String GENERATED_PATH; }### Answer:
@Test public void testCreatePropertyField() { PropertyField p = AtlasModelFactory.createPropertyField(); assertNotNull(p); assertNull(p.getActions()); } |
### 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 specified with a non-empty old string"); } String match = replaceAll.getMatch(); String newString = replaceAll.getNewString(); return input == null ? null : input.replaceAll(match, newString == null ? "" : newString); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testReplaceAll() { ReplaceAll replaceAll = new ReplaceAll(); replaceAll.setMatch(" "); assertNull(StringComplexFieldActions.replaceAll(replaceAll, null)); assertEquals("", StringComplexFieldActions.replaceAll(replaceAll, "")); assertEquals("test", StringComplexFieldActions.replaceAll(replaceAll, "test")); replaceAll.setMatch("e"); assertEquals("tst", StringComplexFieldActions.replaceAll(replaceAll, "test")); replaceAll.setMatch("t"); replaceAll.setNewString("h"); assertEquals("hesh", StringComplexFieldActions.replaceAll(replaceAll, "test")); replaceAll.setMatch("is"); replaceAll.setNewString("at"); assertEquals("That at a test", StringComplexFieldActions.replaceAll(replaceAll, "This is a test")); }
@Test(expected = IllegalArgumentException.class) public void testReplaceAllEmptyMatch() { ReplaceAll replaceAll = new ReplaceAll(); replaceAll.setMatch(""); StringComplexFieldActions.replaceAll(replaceAll, " "); }
@Test(expected=IllegalArgumentException.class) public void testReplaceAllNullAction() { StringComplexFieldActions.replaceAll(null, null); }
@Test(expected = IllegalArgumentException.class) public void testReplaceAllNullOldString() { ReplaceAll replaceAll = new ReplaceAll(); StringComplexFieldActions.replaceAll(replaceAll, " "); } |
### 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 input == null ? null : input.toString().split(split.getDelimiter()); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test(expected=IllegalArgumentException.class) public void testSplitNoDelimiter() { Split action = new Split(); StringComplexFieldActions.split(action, "foobar"); }
@Test public void testSplit() { Split action = new Split(); action.setDelimiter(","); assertArrayEquals(null, StringComplexFieldActions.split(action, null)); assertArrayEquals(new String[] {"1", "2", "3"}, StringComplexFieldActions.split(action, "1,2,3")); } |
### 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 == null ? false : input.startsWith(startsWith.getString()); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testStartsWith() { StartsWith action = new StartsWith(); action.setString(""); assertFalse(StringComplexFieldActions.startsWith(action, null)); assertTrue(StringComplexFieldActions.startsWith(action, "")); assertTrue(StringComplexFieldActions.startsWith(action, "foo")); action.setString("foo"); assertFalse(StringComplexFieldActions.startsWith(action, null)); assertFalse(StringComplexFieldActions.startsWith(action, "")); assertTrue(StringComplexFieldActions.startsWith(action, "foo")); assertTrue(StringComplexFieldActions.startsWith(action, "foobar")); assertFalse(StringComplexFieldActions.startsWith(action, "barfoo")); }
@Test(expected=IllegalArgumentException.class) public void testStartsWithNullAction() { StringComplexFieldActions.startsWith(null, null); }
@Test(expected=IllegalArgumentException.class) public void testStartsWithNullString() { StringComplexFieldActions.startsWith(new StartsWith(), null); } |
### 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 Collection createCollection(); static MockDocument createMockDocument(); static MockField createMockField(); static PropertyField createPropertyField(); static BaseMapping cloneMapping(BaseMapping baseMapping, boolean deepClone); static Field cloneField(Field f); static FieldGroup copyFieldGroup(FieldGroup fg); static SimpleField cloneFieldToSimpleField(Field field); static void copyField(Field from, Field to, boolean withActions); static FieldGroup createFieldGroupFrom(Field field, boolean withActions); static ArrayList<Action> cloneFieldActions(ArrayList<Action> actions); static Action cloneAction(Action action); static String toString(PropertyField f); static String toString(Field f); static Field wrapWithField(Object val); static Field wrapWithField(Object val, String parentPath); static Object unwrapField(Field f); static final String GENERATED_PATH; }### Answer:
@Test public void testCloneField() { PropertyField p = AtlasModelFactory.createPropertyField(); SimpleField s = AtlasModelFactory.cloneFieldToSimpleField(p); assertNotNull(s); } |
### 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 new IllegalArgumentException("SubString action must be specified with a positive startIndex"); } return doSubString(input, subString.getStartIndex(), subString.getEndIndex()); } @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testSubString() { SubString action = new SubString(); action.setStartIndex(2); action.setEndIndex(4); assertNull(StringComplexFieldActions.subString(action, null)); assertEquals("", StringComplexFieldActions.subString(action, "")); try { StringComplexFieldActions.subString(null, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } } |
### 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 null; } return input.plusDays(addDays.getDays() == null ? 0L : addDays.getDays()); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addDays(AddDays addDays, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testAddDays() { AddDays action = new AddDays(); action.setDays(2); assertNull(DateFieldActions.addDays(action, null)); ZonedDateTime origDate = ZonedDateTime.now(); ZonedDateTime laterDate = origDate.plusDays(2); assertEquals(laterDate, DateFieldActions.addDays(action, origDate)); }
@Test(expected=IllegalArgumentException.class) public void testAddDaysWithNullAction() { DateFieldActions.addDays(null, ZonedDateTime.now()); } |
### 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 == null) { return null; } return input.plusSeconds(addSeconds.getSeconds() == null ? 0L : addSeconds.getSeconds()); } @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addDays(AddDays addDays, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testAddSeconds() { AddSeconds action = new AddSeconds(); action.setSeconds(2); assertNull(DateFieldActions.addSeconds(action, null)); ZonedDateTime origDate = ZonedDateTime.now(); ZonedDateTime laterDate = origDate.plusSeconds(2); assertEquals(laterDate, DateFieldActions.addSeconds(action, origDate)); }
@Test(expected=IllegalArgumentException.class) public void testAddSecondsWithNullAction() { DateFieldActions.addSeconds(null, ZonedDateTime.now()); } |
### 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, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testCurrentDate() { assertNotNull(DateFieldActions.currentDate(null)); } |
### 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, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testCurrentDateTime() { assertNotNull(DateFieldActions.currentDateTime(null)); } |
### 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(); @SuppressWarnings("unchecked") static T createMapping(MappingType type); static AtlasMapping createAtlasMapping(); static Collection createCollection(); static MockDocument createMockDocument(); static MockField createMockField(); static PropertyField createPropertyField(); static BaseMapping cloneMapping(BaseMapping baseMapping, boolean deepClone); static Field cloneField(Field f); static FieldGroup copyFieldGroup(FieldGroup fg); static SimpleField cloneFieldToSimpleField(Field field); static void copyField(Field from, Field to, boolean withActions); static FieldGroup createFieldGroupFrom(Field field, boolean withActions); static ArrayList<Action> cloneFieldActions(ArrayList<Action> actions); static Action cloneAction(Action action); static String toString(PropertyField f); static String toString(Field f); static Field wrapWithField(Object val); static Field wrapWithField(Object val, String parentPath); static Object unwrapField(Field f); static final String GENERATED_PATH; }### Answer:
@Test public void testSimpleFieldToString() { SimpleField s = new SimpleField(); System.out.println(AtlasModelFactory.toString(s)); } |
### 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 addDays, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testCurrentTime() { assertNotNull(DateFieldActions.currentTime(null)); } |
### 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 ZonedDateTime addDays(AddDays addDays, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testDayOfMonth() { assertNull(DateFieldActions.dayOfMonth(null, null)); ZonedDateTime origDate = LocalDate.of(2018, 10, 3).atStartOfDay(ZoneId.systemDefault()); assertEquals(Integer.valueOf(3), DateFieldActions.dayOfMonth(null, origDate)); } |
### 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 ZonedDateTime addDays(AddDays addDays, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testDayOfWeek() { assertNull(DateFieldActions.dayOfWeek(null, null)); ZonedDateTime origDate = LocalDate.of(2017, 12, 14).atStartOfDay(ZoneId.systemDefault()); assertEquals(Integer.valueOf(4), DateFieldActions.dayOfWeek(null, origDate)); } |
### 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 addDays(AddDays addDays, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static ZonedDateTime addSeconds(AddSeconds addSeconds, ZonedDateTime input); @AtlasActionProcessor static ZonedDateTime currentDate(CurrentDate action); @AtlasActionProcessor static ZonedDateTime currentDateTime(CurrentDateTime action); @AtlasActionProcessor static ZonedDateTime currentTime(CurrentTime action); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfMonth(DayOfMonth action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfWeek(DayOfWeek action, ZonedDateTime input); @AtlasActionProcessor(sourceType = FieldType.ANY_DATE) static Integer dayOfYear(DayOfYear action, ZonedDateTime input); }### Answer:
@Test public void testDayOfYear() { assertNull(DateFieldActions.dayOfYear(null, null)); ZonedDateTime origDate = LocalDate.of(2017, 12, 31).atStartOfDay(ZoneId.systemDefault()); assertEquals(Integer.valueOf(365), DateFieldActions.dayOfYear(null, origDate)); } |
### 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 Boolean contains(Contains contains, List<Object> inputs); @AtlasActionProcessor static Boolean equals(Equals equals, Object input); @AtlasActionProcessor static Boolean isNull(IsNull action, Object input); @AtlasActionProcessor static Object itemAt(ItemAt itemAt, List<Object> inputs); @AtlasActionProcessor static Integer length(Length length, Object input); }### Answer:
@Test public void testCount() { assertEquals(new Integer(0), ObjectFieldActions.count(new Count(), new ArrayList<>())); Object[] array = new Object[] {false, "foo", 2}; assertEquals(new Integer(3), ObjectFieldActions.count(new Count(), Arrays.asList(array))); } |
### 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; } return collectionContains(inputs, contains); } @AtlasActionProcessor static Integer count(Count action, List<Object> inputs); @AtlasActionProcessor static Boolean contains(Contains contains, List<Object> inputs); @AtlasActionProcessor static Boolean equals(Equals equals, Object input); @AtlasActionProcessor static Boolean isNull(IsNull action, Object input); @AtlasActionProcessor static Object itemAt(ItemAt itemAt, List<Object> inputs); @AtlasActionProcessor static Integer length(Length length, Object input); }### Answer:
@Test public void testContains() { Contains action = new Contains(); assertTrue(ObjectFieldActions.contains(action, null)); assertFalse(ObjectFieldActions.contains(action, Arrays.asList(new Object[] {""}))); Object[] array = new Object[] {false, "foo", 2}; Object[] arrayWithNull = new Object[] {false, null, "foo", 2}; assertFalse(ObjectFieldActions.contains(action, Arrays.asList(array))); assertTrue(ObjectFieldActions.contains(action, Arrays.asList(arrayWithNull))); action.setValue("foo"); assertFalse(ObjectFieldActions.contains(action, null)); assertFalse(ObjectFieldActions.contains(action, Arrays.asList(new Object[] {""}))); assertFalse(ObjectFieldActions.contains(action, Arrays.asList(new Object[] {"foobar"}))); assertTrue(ObjectFieldActions.contains(action, Arrays.asList(array))); }
@Test(expected=IllegalArgumentException.class) public void testContainsWithNullAction() { ObjectFieldActions.contains(null, Arrays.asList(new Object[] {""})); } |
### 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().equals(equals.getValue()); } @AtlasActionProcessor static Integer count(Count action, List<Object> inputs); @AtlasActionProcessor static Boolean contains(Contains contains, List<Object> inputs); @AtlasActionProcessor static Boolean equals(Equals equals, Object input); @AtlasActionProcessor static Boolean isNull(IsNull action, Object input); @AtlasActionProcessor static Object itemAt(ItemAt itemAt, List<Object> inputs); @AtlasActionProcessor static Integer length(Length length, Object input); }### Answer:
@Test public void testEquals() { Equals action = new Equals(); assertTrue(ObjectFieldActions.equals(action, null)); action.setValue("6"); assertFalse(ObjectFieldActions.equals(action, 169)); action.setValue("169"); assertTrue(ObjectFieldActions.equals(action, 169)); action.setValue("ru"); assertFalse(ObjectFieldActions.equals(action, true)); action.setValue("true"); assertTrue(ObjectFieldActions.equals(action, true)); action.setValue("b"); assertFalse(ObjectFieldActions.equals(action, 'a')); action.setValue("a"); assertTrue(ObjectFieldActions.equals(action, 'a')); }
@Test(expected=IllegalArgumentException.class) public void testEqualsWithNullAction() { ObjectFieldActions.equals(null, ""); } |
### 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<Object> inputs); @AtlasActionProcessor static Boolean equals(Equals equals, Object input); @AtlasActionProcessor static Boolean isNull(IsNull action, Object input); @AtlasActionProcessor static Object itemAt(ItemAt itemAt, List<Object> inputs); @AtlasActionProcessor static Integer length(Length length, Object input); }### Answer:
@Test public void testIsNull() { assertTrue(ObjectFieldActions.isNull(null, null)); assertFalse(ObjectFieldActions.isNull(null, "")); assertFalse(ObjectFieldActions.isNull(null, new Object[0])); } |
### 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 > index) { return array[index]; } else { throw new ArrayIndexOutOfBoundsException(String.format( "Collection '%s' has fewer (%s) than expected (%s)", array, array.length, index)); } } @AtlasActionProcessor static Integer count(Count action, List<Object> inputs); @AtlasActionProcessor static Boolean contains(Contains contains, List<Object> inputs); @AtlasActionProcessor static Boolean equals(Equals equals, Object input); @AtlasActionProcessor static Boolean isNull(IsNull action, Object input); @AtlasActionProcessor static Object itemAt(ItemAt itemAt, List<Object> inputs); @AtlasActionProcessor static Integer length(Length length, Object input); }### Answer:
@Test public void testItemAt() { ItemAt action = new ItemAt(); action.setIndex(0); assertEquals("one", ObjectFieldActions.itemAt(action, Arrays.asList(new Object[] {"one", "two"}))); action.setIndex(1); assertEquals("two", ObjectFieldActions.itemAt(action, Arrays.asList(new Object[] {"one", "two"}))); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void testItemAtOutOfBounds() { ItemAt action = new ItemAt(); action.setIndex(2); ObjectFieldActions.itemAt(action, Arrays.asList(new Object[] {"one", "two"})); } |
### 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 static Boolean contains(Contains contains, List<Object> inputs); @AtlasActionProcessor static Boolean equals(Equals equals, Object input); @AtlasActionProcessor static Boolean isNull(IsNull action, Object input); @AtlasActionProcessor static Object itemAt(ItemAt itemAt, List<Object> inputs); @AtlasActionProcessor static Integer length(Length length, Object input); }### Answer:
@Test public void testLength() { assertEquals(new Integer(-1), ObjectFieldActions.length(new Length(), null)); assertEquals(new Integer(0), ObjectFieldActions.length(new Length(), "")); assertEquals(new Integer(5), ObjectFieldActions.length(new Length(), " foo ")); assertEquals(new Integer(4), ObjectFieldActions.length(new Length(), true)); assertEquals(new Integer(3), ObjectFieldActions.length(new Length(), 169)); } |
### 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.valueOf(input.charAt(0)).toUpperCase() + input.substring(1); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testCapitalize() { assertNull(StringSimpleFieldActions.capitalize(new Capitalize(), null)); assertEquals("", StringSimpleFieldActions.capitalize(new Capitalize(), "")); assertEquals(" foo ", StringSimpleFieldActions.capitalize(new Capitalize(), " foo ")); assertEquals(" Foo", StringSimpleFieldActions.capitalize(new Capitalize(), " Foo")); assertEquals("FOo ", StringSimpleFieldActions.capitalize(new Capitalize(), "fOo ")); assertEquals(" foO ", StringSimpleFieldActions.capitalize(new Capitalize(), " foO ")); assertEquals("\t\n FOO", StringSimpleFieldActions.capitalize(new Capitalize(), "\t\n FOO")); assertEquals("\t\n FOO\f\r", StringSimpleFieldActions.capitalize(new Capitalize(), "\t\n FOO\f\r")); } |
### 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 String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testFileExtension() { assertNull(StringSimpleFieldActions.fileExtension(null, null)); assertNull(StringSimpleFieldActions.fileExtension(null, "")); assertNull(StringSimpleFieldActions.fileExtension(null, "foo")); assertEquals("", StringSimpleFieldActions.fileExtension(null, ".")); assertEquals("", StringSimpleFieldActions.fileExtension(null, "foo.")); assertEquals("bar", StringSimpleFieldActions.fileExtension(null, "foo.bar")); assertEquals("bar", StringSimpleFieldActions.fileExtension(null, "foo.foo.bar")); } |
### 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); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testLowerCase() { assertNull(StringSimpleFieldActions.lowercase(new Lowercase(), null)); assertEquals("", StringSimpleFieldActions.lowercase(new Lowercase(), "")); assertEquals("foo", StringSimpleFieldActions.lowercase(new Lowercase(), "foo")); assertEquals("foo", StringSimpleFieldActions.lowercase(new Lowercase(), "Foo")); assertEquals("foo", StringSimpleFieldActions.lowercase(new Lowercase(), "fOo")); assertEquals("foo", StringSimpleFieldActions.lowercase(new Lowercase(), "foO")); assertEquals("foo", StringSimpleFieldActions.lowercase(new Lowercase(), "FOO")); assertEquals("foo bar", StringSimpleFieldActions.lowercase(new Lowercase(), "FOO BAR")); } |
### 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 action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testLowerCaseChar() { assertNull(StringSimpleFieldActions.lowercaseChar(new LowercaseChar(), null)); assertEquals('\0', StringSimpleFieldActions.lowercaseChar(new LowercaseChar(), '\0').charValue()); assertEquals('f', StringSimpleFieldActions.lowercaseChar(new LowercaseChar(), 'f').charValue()); assertEquals('f', StringSimpleFieldActions.lowercaseChar(new LowercaseChar(), 'F').charValue()); } |
### 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); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testNormalize() { assertNull(StringSimpleFieldActions.normalize(null, null)); assertEquals("", StringSimpleFieldActions.normalize(null, "")); assertEquals("foo bar", StringSimpleFieldActions.normalize(null, " foo bar ")); assertEquals("Foo Bar", StringSimpleFieldActions.normalize(null, " Foo Bar ")); assertEquals("fOo bar", StringSimpleFieldActions.normalize(null, "fOo bar")); assertEquals("foO bar", StringSimpleFieldActions.normalize(null, " foO bar ")); assertEquals("FOO BAR", StringSimpleFieldActions.normalize(null, "\t\n FOO \f\t BAR ")); assertEquals("FOO BAR", StringSimpleFieldActions.normalize(null, "\t\n FOO \f\r BAR\f\r")); } |
### 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 static String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testRemoveFileExtension() { assertNull(StringSimpleFieldActions.removeFileExtension(null, null)); assertEquals("", StringSimpleFieldActions.removeFileExtension(null, "")); assertEquals("foo", StringSimpleFieldActions.removeFileExtension(null, "foo")); assertEquals("", StringSimpleFieldActions.removeFileExtension(null, ".")); assertEquals("foo", StringSimpleFieldActions.removeFileExtension(null, "foo.")); assertEquals("foo", StringSimpleFieldActions.removeFileExtension(null, "foo.bar")); assertEquals("foo.foo", StringSimpleFieldActions.removeFileExtension(null, "foo.foo.bar")); } |
### 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 static String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testSeparateByDash() { assertNull(StringSimpleFieldActions.separateByDash(new SeparateByDash(), null)); assertEquals("", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "")); assertEquals("-", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "-")); assertEquals("foo", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "foo")); assertEquals("foo-bar", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "foo bar")); assertEquals("foo-bar", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "foo+bar")); assertEquals("foo-bar", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "foo=bar")); assertEquals("foo-bar", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "foo:bar")); assertEquals("f-o-o-b-a-r", StringSimpleFieldActions.separateByDash(new SeparateByDash(), "f:o:o:b:a:r")); } |
### 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("_"); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testSeparateByUnderscore() { assertNull(StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), null)); assertEquals("", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "")); assertEquals("_", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "-")); assertEquals("foo", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "foo")); assertEquals("foo_bar", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "foo bar")); assertEquals("foo_bar", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "foo+bar")); assertEquals("foo_bar", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "foo=bar")); assertEquals("foo_bar", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "foo:bar")); assertEquals("f_o_o_b_a_r", StringSimpleFieldActions.separateByUnderscore(new SeparateByUnderscore(), "f:o:o:b:a:r")); } |
### 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); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testTrim() { assertNull(StringSimpleFieldActions.trim(new Trim(), null)); assertEquals("", StringSimpleFieldActions.trim(new Trim(), "")); assertEquals("foo", StringSimpleFieldActions.trim(new Trim(), " foo ")); assertEquals("Foo", StringSimpleFieldActions.trim(new Trim(), " Foo")); assertEquals("fOo", StringSimpleFieldActions.trim(new Trim(), "fOo ")); assertEquals("foO", StringSimpleFieldActions.trim(new Trim(), " foO ")); assertEquals("FOO", StringSimpleFieldActions.trim(new Trim(), "\t\n FOO")); assertEquals("FOO", StringSimpleFieldActions.trim(new Trim(), "\t\n FOO\f\r")); } |
### 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.substring(i); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testTrimLeft() { assertNull(StringSimpleFieldActions.trimLeft(new TrimLeft(), null)); assertEquals("", StringSimpleFieldActions.trimLeft(new TrimLeft(), "")); assertEquals("foo ", StringSimpleFieldActions.trimLeft(new TrimLeft(), " foo ")); assertEquals("Foo", StringSimpleFieldActions.trimLeft(new TrimLeft(), " Foo")); assertEquals("fOo ", StringSimpleFieldActions.trimLeft(new TrimLeft(), "fOo ")); assertEquals("foO ", StringSimpleFieldActions.trimLeft(new TrimLeft(), " foO ")); assertEquals("FOO", StringSimpleFieldActions.trimLeft(new TrimLeft(), "\t\n FOO")); assertEquals("FOO\f\r", StringSimpleFieldActions.trimLeft(new TrimLeft(), "\t\n FOO\f\r")); } |
### 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 input.substring(0, i + 1); } @AtlasActionProcessor static String capitalize(Capitalize action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testTrimRight() { assertNull(StringSimpleFieldActions.trimRight(new TrimRight(), null)); assertEquals("", StringSimpleFieldActions.trimRight(new TrimRight(), "")); assertEquals(" foo", StringSimpleFieldActions.trimRight(new TrimRight(), " foo ")); assertEquals(" Foo", StringSimpleFieldActions.trimRight(new TrimRight(), " Foo")); assertEquals("fOo", StringSimpleFieldActions.trimRight(new TrimRight(), "fOo ")); assertEquals(" foO", StringSimpleFieldActions.trimRight(new TrimRight(), " foO ")); assertEquals("\t\n FOO", StringSimpleFieldActions.trimRight(new TrimRight(), "\t\n FOO")); assertEquals("\t\n FOO", StringSimpleFieldActions.trimRight(new TrimRight(), "\t\n FOO\f\r")); } |
### 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); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testUpperCase() { assertNull(StringSimpleFieldActions.uppercase(new Uppercase(), null)); assertEquals("", StringSimpleFieldActions.uppercase(new Uppercase(), "")); assertEquals("FOO", StringSimpleFieldActions.uppercase(new Uppercase(), "foo")); assertEquals("FOO", StringSimpleFieldActions.uppercase(new Uppercase(), "Foo")); assertEquals("FOO", StringSimpleFieldActions.uppercase(new Uppercase(), "fOo")); assertEquals("FOO", StringSimpleFieldActions.uppercase(new Uppercase(), "foO")); assertEquals("FOO", StringSimpleFieldActions.uppercase(new Uppercase(), "FOO")); assertEquals("FOO BAR", StringSimpleFieldActions.uppercase(new Uppercase(), "foo bar")); } |
### 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 action, String input); @AtlasActionProcessor static String fileExtension(FileExtension action, String input); @AtlasActionProcessor static String lowercase(Lowercase action, String input); @AtlasActionProcessor static Character lowercaseChar(LowercaseChar action, Character input); @AtlasActionProcessor static String normalize(Normalize action, String input); @AtlasActionProcessor static String removeFileExtension(RemoveFileExtension action, String input); @AtlasActionProcessor static String separateByDash(SeparateByDash action, String input); @AtlasActionProcessor static String separateByUnderscore(SeparateByUnderscore action, String input); @AtlasActionProcessor static String trim(Trim action, String input); @AtlasActionProcessor static String trimLeft(TrimLeft action, String input); @AtlasActionProcessor static String trimRight(TrimRight action, String input); @AtlasActionProcessor static String uppercase(Uppercase action, String input); @AtlasActionProcessor static Character uppercaseChar(UppercaseChar action, Character input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }### Answer:
@Test public void testUpperCaseChar() { assertNull(StringSimpleFieldActions.uppercaseChar(new UppercaseChar(), null)); assertEquals('\0', StringSimpleFieldActions.uppercaseChar(new UppercaseChar(), '\0').charValue()); assertEquals('F', StringSimpleFieldActions.uppercaseChar(new UppercaseChar(), 'f').charValue()); assertEquals('F', StringSimpleFieldActions.uppercaseChar(new UppercaseChar(), 'F').charValue()); } |
### 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.doubleValue()); } return Math.abs(input.longValue()); } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testAbsoluteValue() { assertEquals(0, NumberFieldActions.absoluteValue(new AbsoluteValue(), null)); assertEquals(BigDecimal.valueOf(1), NumberFieldActions.absoluteValue(new AbsoluteValue(), BigDecimal.valueOf(-1))); assertEquals(1.0, NumberFieldActions.absoluteValue(new AbsoluteValue(), -1.0)); assertEquals(1.0, NumberFieldActions.absoluteValue(new AbsoluteValue(), -1F)); assertEquals(1L, NumberFieldActions.absoluteValue(new AbsoluteValue(), new AtomicLong(-1L))); assertEquals(1L, NumberFieldActions.absoluteValue(new AbsoluteValue(), -1L)); assertEquals(1L, NumberFieldActions.absoluteValue(new AbsoluteValue(), new AtomicInteger(-1))); assertEquals(1L, NumberFieldActions.absoluteValue(new AbsoluteValue(), -1)); assertEquals(1L, NumberFieldActions.absoluteValue(new AbsoluteValue(), (byte) -1)); } |
### 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(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { sum = BigDecimal.valueOf(sum.doubleValue()).add((BigDecimal) entry); } else if (requiresDoubleResult(sum) || requiresDoubleResult(entry)) { sum = sum.doubleValue() + ((Number) entry).doubleValue(); } else { sum = sum.longValue() + ((Number) entry).longValue(); } } else { warnIgnoringValue("Add", entry); } } return sum; } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testAdd() { assertEquals(BigDecimal.valueOf(10.0), NumberFieldActions.add(new Add(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4) }))); assertEquals(10.0, NumberFieldActions.add(new Add(), Arrays.asList(1.0, 2.0, 3.0, 4.0))); assertEquals(10L, NumberFieldActions.add(new Add(), Arrays.asList(1, 2, 3, 4))); assertEquals(0, NumberFieldActions.add(new Add(), null)); assertEquals(10L, NumberFieldActions.add(new Add(), Arrays.asList(null, 1, 2, 3, null, 4, null))); } |
### 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, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testAverage() { assertEquals(2.5, NumberFieldActions.average(new Average(), Arrays.asList(1.0, 2.0, 3.0, 4.0))); assertEquals(2.5, NumberFieldActions.average(new Average(), Arrays.asList(1, 2, 3, 4))); assertEquals(0, NumberFieldActions.average(new Average(), null)); } |
### 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); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testCeiling() { assertEquals(0L, NumberFieldActions.ceiling(new Ceiling(), null)); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), BigDecimal.valueOf(1.1))); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), 1.1)); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), 1.1F)); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), new AtomicLong(2L))); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), 2L)); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), new AtomicInteger(2))); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), 2)); assertEquals(2L, NumberFieldActions.ceiling(new Ceiling(), (byte) 2)); } |
### 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, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DOUBLE) Double toDouble(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.FLOAT) Float toFloat(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) LocalDate toLocalDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) LocalTime toLocalTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.LONG) Long toLong(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.NUMBER) Number toNumber(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) java.sql.Date toSqlDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) Time toSqlTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.STRING) String toString(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) Timestamp toSqlTimestamp(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Date date); }### Answer:
@Test public void convertToZonedDateTime() { ZonedDateTime zonedDateTime = DateTimeHelper.toZonedDateTime(new Date(), null); assertNotNull(zonedDateTime); assertThat(zonedDateTime, instanceOf(ZonedDateTime.class)); assertTrue(zonedDateTime.getZone().getId().equals(ZoneId.systemDefault().getId())); }
@Test public void convertToZonedDateTimeWithZoneId() { ZonedDateTime zonedDateTime = DateTimeHelper.toZonedDateTime(new Date(), "America/New_York"); assertNotNull(zonedDateTime); assertThat(zonedDateTime, instanceOf(ZonedDateTime.class)); assertTrue(zonedDateTime.getZone().getId().equals("America/New_York")); } |
### 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 new IllegalArgumentException("ConvertMassUnit must be specified with fromUnit and toUnit"); } MassUnitType fromUnit = convertMassUnit.getFromUnit(); MassUnitType toUnit = convertMassUnit.getToUnit(); double rate = massConvertionTable.get(fromUnit).get(toUnit); return doMultiply(input, rate); } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testConvertMassUnit() { ConvertMassUnit action = new ConvertMassUnit(); action.setFromUnit(MassUnitType.KILOGRAM_KG); action.setToUnit(MassUnitType.POUND_LB); assertEquals(11, NumberFieldActions.convertMassUnit(action, 5).intValue()); action.setFromUnit(MassUnitType.POUND_LB); action.setToUnit(MassUnitType.KILOGRAM_KG); assertEquals(4.5359235f, NumberFieldActions.convertMassUnit(action, 10.0f).floatValue(), 0); assertEquals(0, NumberFieldActions.convertMassUnit(action, null).intValue()); }
@Test(expected = IllegalArgumentException.class) public void testConvertMassUnitErrorNoFromNorToSpecified() { ConvertMassUnit action = new ConvertMassUnit(); assertEquals(11, NumberFieldActions.convertMassUnit(action, 5)); }
@Test(expected = IllegalArgumentException.class) public void testConvertMassUnitErrorNoFromSpecified() { ConvertMassUnit action = new ConvertMassUnit(); action.setToUnit(MassUnitType.POUND_LB); assertEquals(11, NumberFieldActions.convertMassUnit(action, 5)); }
@Test(expected = IllegalArgumentException.class) public void testConvertMassUnitErrorNoToSpecified() { ConvertMassUnit action = new ConvertMassUnit(); action.setFromUnit(MassUnitType.KILOGRAM_KG); assertEquals(11, NumberFieldActions.convertMassUnit(action, 5)); }
@Test(expected = IllegalArgumentException.class) public void testConvertMassUnitIllegalArgumentException() { assertEquals(11, NumberFieldActions.convertMassUnit(new ConvertMassUnit(), 5).intValue()); } |
### 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; } else if (quotient instanceof BigDecimal) { quotient = ((BigDecimal) quotient).divide(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { quotient = BigDecimal.valueOf(quotient.doubleValue()).divide((BigDecimal) entry); } else { quotient = quotient.doubleValue() / ((Number) entry).doubleValue(); } } else { warnIgnoringValue("Divide", entry); } } return quotient; } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testDivide() { assertEquals(BigDecimal.valueOf(2), NumberFieldActions.divide(new Divide(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(4), BigDecimal.valueOf(2) }))); assertEquals(2.0, NumberFieldActions.divide(new Divide(), Arrays.asList(4.0, 2.0))); assertEquals(2.0, NumberFieldActions.divide(new Divide(), Arrays.asList(4, 2))); assertEquals(0, NumberFieldActions.divide(new Divide(), null)); assertEquals(2.0, NumberFieldActions.divide(new Divide(), Arrays.asList(null, 4, null, 2, null))); } |
### 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 static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testFloor() { assertEquals(0L, NumberFieldActions.floor(new Floor(), null)); assertEquals(1L, NumberFieldActions.floor(new Floor(), BigDecimal.valueOf(1.5))); assertEquals(1L, NumberFieldActions.floor(new Floor(), 1.5)); assertEquals(1L, NumberFieldActions.floor(new Floor(), 1.5F)); assertEquals(2L, NumberFieldActions.floor(new Floor(), new AtomicLong(2L))); assertEquals(2L, NumberFieldActions.floor(new Floor(), 2L)); assertEquals(2L, NumberFieldActions.floor(new Floor(), new AtomicInteger(2))); assertEquals(2L, NumberFieldActions.floor(new Floor(), 2)); assertEquals(2L, NumberFieldActions.floor(new Floor(), (byte) 2)); } |
### 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 BigDecimal) { max = ((BigDecimal) entry).max((BigDecimal)max); } else if (max == null || ((Number) entry).doubleValue() > max.doubleValue()) { max = (Number) entry; } } else { warnIgnoringValue("Maximum", entry); } } return max; } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testMaximum() { assertEquals(BigDecimal.valueOf(4), NumberFieldActions.maximum(new Maximum(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4) }))); assertEquals(4.0, NumberFieldActions.maximum(new Maximum(), Arrays.asList(1.0, 2.0, 3.0, 4.0))); assertEquals(4, NumberFieldActions.maximum(new Maximum(), Arrays.asList(1, 2, 3, 4))); assertEquals(BigDecimal.valueOf(4), NumberFieldActions.maximum(new Maximum(), Arrays.asList((byte) 1, 2, 3.0, BigDecimal.valueOf(4)))); assertEquals(0, NumberFieldActions.maximum(new Maximum(), null)); assertEquals(4, NumberFieldActions.maximum(new Maximum(), Arrays.asList(null, 1, 2, 3, null, 4, null))); } |
### 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 BigDecimal) { min = ((BigDecimal) entry).min((BigDecimal)min); } else if (min == null || ((Number) entry).doubleValue() < min.doubleValue()) { min = (Number) entry; } } else { warnIgnoringValue("Minimum", entry); } } return min; } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testMinimum() { assertEquals(BigDecimal.valueOf(1), NumberFieldActions.minimum(new Minimum(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4) }))); assertEquals(1.0, NumberFieldActions.minimum(new Minimum(), Arrays.asList(1.0, 2.0, 3.0, 4.0))); assertEquals(1, NumberFieldActions.minimum(new Minimum(), Arrays.asList(1, 2, 3, 4))); assertEquals((byte) 1, NumberFieldActions.minimum(new Minimum(), Arrays.asList((byte) 1, 2, 3.0, BigDecimal.valueOf(4)))); assertEquals(0, NumberFieldActions.minimum(new Minimum(), null)); assertEquals(1, NumberFieldActions.minimum(new Minimum(), Arrays.asList(null, 1, 2, null, 3, 4, null))); } |
### 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 static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testRound() { assertEquals(0L, NumberFieldActions.round(new Round(), null)); assertEquals(2L, NumberFieldActions.round(new Round(), BigDecimal.valueOf(1.5))); assertEquals(1L, NumberFieldActions.round(new Round(), 1.4)); assertEquals(2L, NumberFieldActions.round(new Round(), 1.5F)); assertEquals(2L, NumberFieldActions.round(new Round(), new AtomicLong(2L))); assertEquals(2L, NumberFieldActions.round(new Round(), 2L)); assertEquals(2L, NumberFieldActions.round(new Round(), new AtomicInteger(2))); assertEquals(2L, NumberFieldActions.round(new Round(), 2)); assertEquals(2L, NumberFieldActions.round(new Round(), (byte) 2)); } |
### 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 = (Number) entry; } else if (difference instanceof BigDecimal) { difference = ((BigDecimal) difference).subtract(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { difference = BigDecimal.valueOf(difference.doubleValue()).subtract((BigDecimal) entry); } else if (requiresDoubleResult(difference) || requiresDoubleResult(entry)) { difference = difference.doubleValue() - ((Number) entry).doubleValue(); } else { difference = difference.longValue() - ((Number) entry).longValue(); } } else { warnIgnoringValue("Subtract", entry); } } return difference; } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testSubtract() { assertEquals(BigDecimal.valueOf(-8.0), NumberFieldActions.subtract(new Subtract(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4) }))); assertEquals(-8.0, NumberFieldActions.subtract(new Subtract(), Arrays.asList(1.0, 2.0, 3.0, 4.0))); assertEquals(-8L, NumberFieldActions.subtract(new Subtract(), Arrays.asList(1, 2, 3, 4))); assertEquals(0, NumberFieldActions.subtract(new Subtract(), null)); assertEquals(-8.0, NumberFieldActions.subtract(new Subtract(), Arrays.asList(null, 1.0, null, 2.0, 3.0, null, 4.0, null))); } |
### 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 = ((BigDecimal) product).multiply(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { product = BigDecimal.valueOf(product.doubleValue()).multiply((BigDecimal) entry); } else if (requiresDoubleResult(product) || requiresDoubleResult(entry)) { product = product.doubleValue() * ((Number) entry).doubleValue(); } else { product = product.longValue() * ((Number) entry).longValue(); } } else { warnIgnoringValue("Multiply", entry); } } return product; } @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }### Answer:
@Test public void testMultiply() { assertNotNull(new NumberFieldActions()); assertEquals(0, NumberFieldActions.multiply(new Multiply(), null)); assertEquals(new BigDecimal("24.0000"), NumberFieldActions.multiply(new Multiply(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4) }))); assertEquals(24.0, NumberFieldActions.multiply(new Multiply(), Arrays.asList(1.0, 2.0, 3.0, 4.0 ))); assertEquals(24.0, NumberFieldActions.multiply(new Multiply(), Arrays.asList(1.0f, 2.0f, 3.0f, 4.0f))); assertEquals(24L, NumberFieldActions.multiply(new Multiply(), Arrays.asList(1L, 2L, 3L, 4L))); assertEquals(24L, NumberFieldActions.multiply(new Multiply(), Arrays.asList(1, 2, 3, 4))); assertEquals(24L, NumberFieldActions.multiply(new Multiply(), Arrays.asList(null, 1, 2, null, 3, 4, null))); } |
### 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.DECIMAL) BigDecimal toBigDecimal(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DOUBLE) Double toDouble(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.FLOAT) Float toFloat(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) LocalDate toLocalDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) LocalTime toLocalTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.LONG) Long toLong(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.NUMBER) Number toNumber(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) java.sql.Date toSqlDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) Time toSqlTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.STRING) String toString(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) Timestamp toSqlTimestamp(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Date date); }### Answer:
@Test public void convertToTimestamp() { Timestamp timestamp = dateConverter.toSqlTimestamp(new Date()); assertNotNull(timestamp); assertThat(timestamp, instanceOf(Timestamp.class)); } |
### 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(sourceType = FieldType.DATE_TIME, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DOUBLE) Double toDouble(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.FLOAT) Float toFloat(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) LocalDate toLocalDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) LocalTime toLocalTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.LONG) Long toLong(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.NUMBER) Number toNumber(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) java.sql.Date toSqlDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) Time toSqlTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.STRING) String toString(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) Timestamp toSqlTimestamp(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Date date); }### Answer:
@Test public void convertToCalendar() { Calendar calendar = dateConverter.toCalendar(new Date()); assertNotNull(calendar); assertThat(calendar, instanceOf(GregorianCalendar.class)); } |
### 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 toBigDecimal(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DOUBLE) Double toDouble(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.FLOAT) Float toFloat(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) LocalDate toLocalDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) LocalTime toLocalTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.LONG) Long toLong(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.NUMBER) Number toNumber(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) java.sql.Date toSqlDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) Time toSqlTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.STRING) String toString(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) Timestamp toSqlTimestamp(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Date date); }### Answer:
@Test public void convertToString() { String dateString = dateConverter.toString(new Date()); assertNotNull(dateString); assertThat(dateString, instanceOf(String.class)); } |
### 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 toBigDecimal(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DOUBLE) Double toDouble(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.FLOAT) Float toFloat(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) LocalDate toLocalDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) LocalTime toLocalTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.LONG) Long toLong(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.NUMBER) Number toNumber(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Date value); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) java.sql.Date toSqlDate(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) Time toSqlTime(Date date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.STRING) String toString(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) Timestamp toSqlTimestamp(Date date); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Date date); }### Answer:
@Test public void convertToLong() { Date now = new Date(); Long dateAsLong = dateConverter.toLong(now); assertNotNull(dateAsLong); assertThat(dateAsLong, instanceOf(Long.class)); assertTrue(now.getTime() == dateAsLong); } |
### 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, targetType = FieldType.DATE_TIME) Date toDate(Calendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Calendar calendar); }### Answer:
@Test public void toDate() { Date date = converter.toDate(Calendar.getInstance()); assertNotNull(date); } |
### 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); } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME) Date toDate(Calendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Calendar calendar); }### Answer:
@Test public void toZonedDateTime() { ZonedDateTime date = converter.toZonedDateTime(Calendar.getInstance()); assertNotNull(date); } |
### 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; } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToBoolean() { Long aLong = 0L; Long l = 1L; Boolean b = converter.toBoolean(l); assertNotNull(b); assertTrue(b); b = converter.toBoolean(aLong); assertNotNull(b); assertFalse(b); }
@Test public void convertToBooleanNull() { Long l = null; Boolean b = converter.toBoolean(l); assertNull(b); }
@Test public void convertToBooleanNegative() { Long dt = -1L; Boolean b = converter.toBoolean(dt); assertTrue(b); } |
### 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 <= Byte.MAX_VALUE) { return value.byteValue(); } throw new AtlasConversionException(new AtlasUnsupportedException( String.format("Long %s is greater than Byte.MAX_VALUE or less than Byte.MIN_VALUE", value))); } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToByte() throws Exception { Long l = 0L; Byte value = (byte) 0; assertEquals(value, converter.toByte(l)); }
@Test(expected = AtlasConversionException.class) public void convertToByteOutOfRange() throws Exception { converter.toByte(Long.MAX_VALUE); }
@Test public void convertToByteNull() throws Exception { assertNull(converter.toByte(null)); } |
### 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) { return null; } if (value < Character.MIN_VALUE || value > Character.MAX_VALUE) { throw new AtlasConversionException(String .format("Long %s is greater than Character.MAX_VALUE or less than Character.MIN_VALUE", value)); } return Character.valueOf((char) value.intValue()); } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToCharacter() throws Exception { Long l = 0L; Character c = converter.toCharacter(l); assertNotNull(c); assertEquals(0, c.charValue()); }
@Test public void convertToCharacterNull() throws Exception { Long l = null; Character c = converter.toCharacter(l); assertNull(c); }
@Test(expected = AtlasConversionException.class) public void convertToCharacterMAX() throws Exception { Long l = Long.MAX_VALUE; converter.toCharacter(l); }
@Test(expected = AtlasConversionException.class) public void convertToCharacterMIN() throws Exception { Long l = -1L; converter.toCharacter(l); } |
### 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(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void toDate() throws Exception { Date date = converter.toDate(Long.MAX_VALUE); assertNotNull(date); date = converter.toDate(Long.MIN_VALUE); assertNotNull(date); date = converter.toDate(Long.parseLong("0")); assertTrue(date.toInstant().toString().equals("1970-01-01T00:00:00Z")); } |
### 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.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToDouble() { Long l = 0L; Double d = converter.toDouble(l); assertNotNull(d); assertEquals(0.0, d, 0.0); }
@Test public void convertToDoubleNull() { Long l = null; Double d = converter.toDouble(l); assertNull(d); }
@Test public void convertToDoubleMAX() { Long l = Long.MAX_VALUE; Double d = converter.toDouble(l); assertNotNull(d); assertEquals(Long.MAX_VALUE, l, 0.0); } |
### 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.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToFloat() { Long l = 0L; Float f = converter.toFloat(l); assertNotNull(f); assertEquals(0.0, f, 0.0); l = 1L; f = converter.toFloat(l); assertNotNull(f); assertEquals(1.0f, f, 0.0); }
@Test public void convertToFloatNull() { assertNull(converter.toFloat(null)); }
@Test public void convertToFloatMAX() { Long l = Long.MAX_VALUE; Float f = converter.toFloat(l); assertNotNull(f); assertEquals(Long.MAX_VALUE, l, 0.0); } |
### 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_VALUE || value < Integer.MIN_VALUE) { throw new AtlasConversionException( String.format("Long %s is greater than Integer.MAX_VALUE or less than Integer.MIN_VALUE", value)); } return value.intValue(); } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToInteger() throws Exception { Long l = 0L; Integer i = converter.toInteger(l); assertNotNull(i); assertEquals(0, i, 0.0); }
@Test(expected = AtlasConversionException.class) public void convertToIntegerMAX() throws Exception { converter.toInteger(Long.MAX_VALUE); }
@Test(expected = AtlasConversionException.class) public void convertToIntegerMIN() throws Exception { converter.toInteger(Long.MIN_VALUE); }
@Test public void convertToIntegerNull() throws Exception { Long l = null; Integer i = converter.toInteger(l); assertNull(i); } |
### 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 toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToLong() { Long l = 1L; Long d = converter.toLong(l); assertNotNull(d); assertNotSame(l, d); assertEquals(1L, d, 0.0); }
@Test public void convertToLongNull() { Long l = null; Long d = converter.toLong(l); assertNull(d); } |
### 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 || value < Short.MIN_VALUE) { throw new AtlasConversionException( String.format("Long %s is greater than Short.MAX_VALUE or less than Short.MIN_VALUE", value)); } return value.shortValue(); } @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToShort() throws Exception { Long l = 0L; Short s = converter.toShort(l); assertNotNull(s); assertEquals(0, s, 0.0); }
@Test public void convertToShortNull() throws Exception { Long l = null; Short s = converter.toShort(l); assertNull(s); }
@Test(expected = AtlasConversionException.class) public void convertToShortExceptionMAX() throws Exception { Long l = Long.MAX_VALUE; converter.toShort(l); } |
### 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) BigDecimal toBigDecimal(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) Date toDate(Long date); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DOUBLE) Double toDouble(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.FLOAT) Float toFloat(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE) LocalDate toLocalDate(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.TIME) LocalTime toLocalTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.LONG) Long toLong(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.NUMBER) Number toNumber(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.STRING) String toString(Long value); @AtlasConversionInfo(sourceType = FieldType.LONG, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Long value); }### Answer:
@Test public void convertToString() { Long l = 0L; String s = converter.toString(l); assertNotNull(s); assertTrue("0".equals(s)); }
@Test public void convertToStringNull() { Long l = null; String s = converter.toString(l); assertNull(s); } |
### 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 null; } String regex = sourceFormat != null && !"".equals(sourceFormat) ? sourceFormat : TRUE_REGEX; if (Character.toString(value).matches(regex)) { return Boolean.TRUE; } return Boolean.FALSE; } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer:
@Test public void convertToBoolean() { Character c = Character.forDigit(1, 10); Boolean t = converter.toBoolean(c, null, null); assertNotNull(t); assertTrue(t); c = "T".charAt(0); Boolean t2 = converter.toBoolean(c, null, null); assertNotNull(t2); assertTrue(t2); c = "t".charAt(0); Boolean t3 = converter.toBoolean(c, null, null); assertNotNull(t3); assertTrue(t3); c = Character.forDigit(0, 10); Boolean f = converter.toBoolean(c, null, null); assertNotNull(f); assertFalse(f); c = "F".charAt(0); Boolean f2 = converter.toBoolean(c, null, null); assertNotNull(f2); assertFalse(f2); c = "f".charAt(0); Boolean f3 = converter.toBoolean(c, null, null); assertNotNull(f3); assertFalse(f3); }
@Test public void convertToBooleanInvalid() { Character c = null; converter.toBoolean(c, null, null); assertNull(c); } |
### 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(cipherTextLen); int sigLen = (int)reader.getCompactInt(); byte[] signature = reader.getBytes(sigLen); return new BackupPayload(version, timestamp, iv, cipherText, signature); } catch (ByteReader.InsufficientBytesException e) { throw new IllegalArgumentException("Backup payload invalid"); } } private BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, byte[] signature); BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, PrivateKey signatureKey); static BackupPayload deserialize(byte[] data); byte[] serialize(); Sha256Hash getHashedContentToSign(); boolean verifySignature(final byte[] apub); byte[] getSignature(); @Override boolean equals(Object o); @Override int hashCode(); }### Answer:
@Test public void testDeserialize() throws Exception { byte[] encryptedContent = HexUtils.toBytes("01074b1955bf07aaa979ae8af6eebfea5da8e83cad505edbaade9ba4ed528a8d" + "e36c95ece996189dedf4756fba2599f94b4f370d701366e2f0ba4e59111c0787" + "708cf4b0b82de558b4d8bf5d90b3512f09814d605d4c14f2f85b596211f83918" + "c31c4bef19ea473045022100ddbc9b06625c2b3c9cbfb27b6ac39596bd13daf4" + "3d4ddecbb7257a0d26f5e2c402200a5bd5fd27df7ac262ac3cff9d5398742c6f" + "d9c76c427548667bee45dcb1134c"); byte[] apub = HexUtils.toBytes("028747be6de07552c48f9db23617792d47df1accd611175f6dfe636f4098984a09"); byte[] wrongApub = HexUtils.toBytes("028747be6de07552c48f9db23617792d47df1accd611175f6dfe636f4098984a08"); BackupPayload payload = BackupPayload.deserialize(encryptedContent); assertEquals("content hash", "89bfc7bf81f8e3b2944c4903b68034dc7317806b40f2d225fe4b13907fdb225d", HexUtils.toHex(payload.getHashedContentToSign().getBytes())); assertTrue("signature check", payload.verifySignature(apub)); assertFalse("failing signature check", payload.verifySignature(wrongApub)); } |
### 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 getMaxPosition(); }### Answer:
@Test public void getMinPosition() throws Exception { assertEquals(MIN_POSITION, algorithm.getMinPosition()); } |
### 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 getMaxPosition(); }### Answer:
@Test public void getMaxPosition() throws Exception { assertEquals(MAX_POSITION, algorithm.getMaxPosition()); } |
### 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[]> getChunks(); @Override boolean equals(Object o); @Override int hashCode(); static final int DEFAULT_CHUNK_SIZE; }### Answer:
@Test public void testFromData() throws Exception { byte[] cipherText = HexUtils.toBytes("5edbaade9ba4ed528a8de36c95ece996189dedf4756fba2599f94b4f370d7013" + "66e2f0ba4e59111c0787708cf4b0b82de558b4d8bf5d90b3512f09814d605d4c" + "14f2f85b596211f83918c31c4bef19ea"); MerkleTree merkleTree = MerkleTree.fromData(cipherText); assertEquals("Merkle root", "9e913cd60f7df551b3baa320602bfba78489921d661362a64a03550a45add008", merkleTree.getRoot().toHex()); } |
### 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, int length, String separator); static byte[] toBytes(String hexString); static void appendByteAsHex(StringBuilder sb, byte b); static boolean isAllZero(byte[] bytes); }### Answer:
@Test public void toHex() throws Exception { for(byte[] bytes : bytess) { String hex = new String(Hex.encode(bytes)); assertEquals(hex, HexUtils.toHex(bytes)); } } |
### 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(); int length = hex.length / 2; byte[] raw = new byte[length]; for (int i = 0; i < length; i++) { int high = Character.digit(hex[i * 2], 16); int low = Character.digit(hex[i * 2 + 1], 16); if (high < 0 || low < 0){ throw new RuntimeException("Invalid hex digit " + hex[i * 2] + hex[i * 2 + 1]); } int value = (high << 4) | low; if (value > 127) value -= 256; raw[i] = (byte) value; } return raw; } 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, int length, String separator); static byte[] toBytes(String hexString); static void appendByteAsHex(StringBuilder sb, byte b); static boolean isAllZero(byte[] bytes); }### Answer:
@Test public void toBytes() throws Exception { for(String string : strings) { byte [] bytes = Hex.decode(string); assertArrayEquals(bytes, HexUtils.toBytes(string)); } } |
### 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[] scriptBytes); byte[] getDataBytes(); @Override byte[] getAddressBytes(); @Override Address getAddress(NetworkParameters network); }### Answer:
@Test public void isScriptOutputOpReturnTest() throws Exception { byte[][] chunks = new byte[2][]; chunks[0]=new byte[]{OP_RETURN}; assertFalse(isScriptOutputOpReturn(chunks)); assertTrue(isScriptOutputOpReturn(new byte[][]{{OP_RETURN}, "Hallotest".getBytes()})); assertFalse(isScriptOutputOpReturn(new byte[][]{{OP_RETURN}, null})); assertFalse(isScriptOutputOpReturn(new byte[][]{{OP_RETURN}, "".getBytes()})); assertFalse(isScriptOutputOpReturn(new byte[][]{null, "Hallo".getBytes()})); } |
### 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 == null) { throw new RuntimeException("Private key not found"); } byte[] signature = signer.makeStandardBitcoinSignature(request.getToSign()); signatures.add(signature); } return signatures; } StandardTransactionBuilder(NetworkParameters network); void addOutput(Address sendTo, long value); void addOutput(TransactionOutput output); void addOutputs(OutputList outputs); static TransactionOutput createOutput(Address sendTo, long value, NetworkParameters network); static List<byte[]> generateSignatures(SigningRequest[] requests, IPrivateKeyRing keyRing); UnsignedTransaction createUnsignedTransaction(Collection<UnspentTransactionOutput> inventory,
@Nonnull Address changeAddress, IPublicKeyRing keyRing,
NetworkParameters network, long minerFeeToUse); static Transaction finalizeTransaction(UnsignedTransaction unsigned, List<byte[]> signatures); static final int MAX_INPUT_SIZE; }### Answer:
@Test(timeout=500) @Ignore("This is not really a requirement but was meant to show the supperior performance of bitcoinJ") public void generateSignaturesBitlib() throws Exception { List<SigningRequest> requests = new ArrayList<>(); for(int i = 0; i<30; i++) { requests.add(new SigningRequest(PUBLIC_KEYS[i % COUNT], HashUtils.sha256(("bla" + i).getBytes()))); } StandardTransactionBuilder.generateSignatures(requests.toArray(new SigningRequest[]{}), PRIVATE_KEY_RING); } |
### 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 testCreateMaxBitcoin() { PopRequest uri = new PopRequest("btcpop:?p=a&n=1&amount=21000000.00000000"); assertEquals(2100000000000000L, uri.getAmountSatoshis().longValue()); } |
### 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); }### Answer:
@Test public void shouldCreateInstanceAndWaitForInitialization() throws Exception { Fortuna fortuna = Fortuna.createInstance(); try { fortuna.nextInt(42); } catch (IllegalStateException ignored) { fail("Did not wait for initialization"); } }
@Ignore @Test public void shouldProduceEvenDistribution() throws Exception { int[] numbers = new int[10]; Fortuna fortuna = Fortuna.createInstance(); for (int i = 0; i < 1000000; i++) { numbers[fortuna.nextInt(10)]++; } int lowest = Integer.MAX_VALUE; int highest = Integer.MIN_VALUE; for (int number : numbers) { if (number > highest) { highest = number; } if (number < lowest) { lowest = number; } } System.out.println("numbers = " + Arrays.toString(numbers)); int percentage = (100 * (highest - lowest)) / lowest; System.out.println("percentage = " + percentage); assertEquals(0, percentage); } |
### 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, TimeUnit.MILLISECONDS); } @Override void event(EventScheduler scheduler, EventAdder adder); }### Answer:
@Test public void shouldAddBytes() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(100, timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(2, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### 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, TimeUnit.MILLISECONDS); } finally { inputStream.close(); } } catch (IOException e) { throw new IllegalStateException("unexpected error while obtaining entropy: ", e); } } @Override void event(EventScheduler scheduler, EventAdder adder); static final File URANDOM; }### Answer:
@Test public void shouldAddUptime() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(100, timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(32, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### 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); } @Override void event(EventScheduler scheduler, EventAdder adder); }### Answer:
@Test public void shouldUseTimeBetweenCallsToCreateEvents() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(10, timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(2, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### 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, EventAdder adder); }### Answer:
@Test public void shouldAddUptime() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(1000, timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(2, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### 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.scale()).longValue(); adder.add(Util.twoLeastSignificantBytes(convertedValue)); scheduler.schedule(1000, TimeUnit.MILLISECONDS); } @Override void event(EventScheduler scheduler, EventAdder adder); }### Answer:
@Test public void shouldAddTwoBytesAndSchedule() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(1000, timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(2, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### Question:
GarbageCollectorEntropySource implements EntropySource { @Override public void event(EventScheduler scheduler, EventAdder adder) { long sum = 0; for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { sum += garbageCollectorMXBean.getCollectionCount() + garbageCollectorMXBean.getCollectionTime(); } adder.add(Util.twoLeastSignificantBytes(sum)); scheduler.schedule(10, TimeUnit.SECONDS); } @Override void event(EventScheduler scheduler, EventAdder adder); }### Answer:
@Test public void shouldGetGarbageCollectionData() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(TimeUnit.SECONDS.toMillis(10), timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(2, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### 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(EventScheduler scheduler, EventAdder adder); }### Answer:
@Test public void shouldReadFreeMemory() throws Exception { target.event( new EventScheduler() { @Override public void schedule(long delay, TimeUnit timeUnit) { assertEquals(100, timeUnit.toMillis(delay)); schedules++; } }, new EventAdder() { @Override public void add(byte[] event) { assertEquals(2, event.length); adds++; } } ); assertEquals(1, schedules); assertEquals(1, adds); } |
### 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 the event need to be in the range 1 to 32, it was " + event.length); } size += event.length + 2; poolDigest.update(new byte[]{(byte) source, (byte) event.length}); poolDigest.update(event); } finally { writeLock.unlock(); } } long size(); void add(int source, byte[] event); byte[] getAndClear(); }### Answer:
@Test(expected = IllegalArgumentException.class) public void shouldFailIfSourceIsLessThanZero() throws Exception { pool.add(-1, "Hello".getBytes()); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfSourceIsGreaterThan255() throws Exception { pool.add(256, "Hello".getBytes()); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfEventIsEmpty() throws Exception { pool.add(0, new byte[0]); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfEventLengthIsGreaterThan32() throws Exception { pool.add(0, new byte[33]); } |
### 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 UnsupportedEncodingException { String encoded = URLEncoder.encode("http: PopRequest uri = new PopRequest("btcpop:?label=a text&n=111&p=" + encoded); assertEquals("a text", uri.getLabel()); assertEquals("http: } |
### 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.getAndClear(); assertEquals(32, bytes.length); } |
### 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, 15); } } else { if (password.length() != 15) { return "Error: the supplied password did not match the expected length"; } realpassword = password; } try { MrdExport.V1.Header header = MrdExport.V1.extractHeader(encryptedPrivateKey); MrdExport.V1.KdfParameters kdfParameters = MrdExport.V1.KdfParameters.fromPassphraseAndHeader(realpassword, header); MrdExport.V1.EncryptionParameters parameters = MrdExport.V1.EncryptionParameters.generate(kdfParameters); String privateKey = MrdExport.V1.decryptPrivateKey(parameters, encryptedPrivateKey, header.network); InMemoryPrivateKey key = new InMemoryPrivateKey(privateKey, header.network); return "Private key (Wallet Import Format): " + key.getBase58EncodedPrivateKey(header.network) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2PKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2SH_P2WPKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2WPKH); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (MrdExport.V1.WrongNetworkException e) { throw new RuntimeException(e); } catch (MrdExport.V1.InvalidChecksumException e) { return "Error: the supplied password did not match the checksum of the encrypted key"; } catch (MrdExport.DecodingException e) { throw new RuntimeException(e); } } BackupUtil(String... args); static void main(String[] args); String getKey(); }### Answer:
@Test public void testParse(){ BackupUtil util = new BackupUtil(ENCRYPTED_KEY, CORRECT_PASSWORD); String decoded = util.getKey(); assertEquals(EXPECTED_RESPONSE, decoded); decoded= new BackupUtil(ENCRYPTED_KEY, "QDTDXOYFBXBKKMK").getKey(); assertEquals(EXPECTED_RESPONSE, decoded); }
@Test public void testErrorHandling(){ BackupUtil util = new BackupUtil(ENCRYPTED_KEY, "QDTDXOYFBXBKKAA"); String decoded = util.getKey(); assertTrue(decoded.startsWith("Error: ")); util = new BackupUtil(ENCRYPTED_KEY, "QDTDXOYFBXBKKAAA"); decoded = util.getKey(); assertTrue(decoded.startsWith("Error: ")); util = new BackupUtil("xEncGXICZE1_eVYfGWDioAA_8hA6RZzep4XqwPGRtcKb01MDg3s1XFntJYI9Dw", CORRECT_PASSWORD); decoded = util.getKey(); assertTrue(decoded.startsWith("Error: ")); } |
### 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(bech.toUpperCase(Locale.ROOT))) { throw new Exception("BCH bech32 cannot mix upper and lower case"); } bech = bech.toLowerCase(); int position = bech.lastIndexOf(":"); if (position < 1) { throw new Exception("BCH bech32 missing separator"); } else if (position + 7 > bech.length()) { throw new Exception("BCH bech32 separator misplaced"); } else if (bech.length() < 8) { throw new Exception("BCH bech32 input too short"); } else if (bech.length() > 90) { throw new Exception("BCH bech32 input too long"); } String s = bech.substring(position + 1); for (int i = 0; i < s.length(); i++) { if (CHARSET.indexOf(s.charAt(i)) == -1) { throw new Exception("BCH bech32 characters out of range"); } } byte[] humanReadablePart = bech.substring(0, position).getBytes(); byte[] data = new byte[bech.length() - position - 1]; for (int j = 0, i = position + 1; i < bech.length(); i++, j++) { data[j] = (byte) CHARSET.indexOf(bech.charAt(i)); } if (!verifyChecksum(humanReadablePart, data)) { throw new Exception("invalid BCH bech32 checksum"); } byte[] payloadData = fromBase5Array(Arrays.copyOfRange(data, 0, data.length - 8)); byte[] hash = Arrays.copyOfRange(payloadData, 1, payloadData.length); String type = getType(payloadData[0]); return new BechAddressParams(type, hash, new String(humanReadablePart)); } static BechAddressParams bchBechDecode(String bech); }### Answer:
@Test public void P2PKHAddressTest() throws Exception { Assert.assertEquals(Address.fromStandardBytes(BCHBechAddress.bchBechDecode("bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a").getHash(), NetworkParameters.productionNetwork).toString(), "1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu"); }
@Test public void P2SHAddressTest() throws Exception { Assert.assertEquals(Address.fromP2SHBytes(BCHBechAddress.bchBechDecode("bitcoincash:pqq3728yw0y47sqn6l2na30mcw6zm78dzq5ucqzc37").getHash(), NetworkParameters.productionNetwork).toString(), "31nwvkZwyPdgzjBJZXfDmSWsC4ZLKpYyUw"); }
@Test public void legacyAddressConstructorTest() throws Exception { Assert.assertEquals(BCHBechAddress.bchBechDecode("bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a") .constructLegacyAddress(NetworkParameters.productionNetwork).toString(), "1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu"); Assert.assertEquals(BCHBechAddress.bchBechDecode("bitcoincash:pqq3728yw0y47sqn6l2na30mcw6zm78dzq5ucqzc37") .constructLegacyAddress(NetworkParameters.productionNetwork).toString(), "31nwvkZwyPdgzjBJZXfDmSWsC4ZLKpYyUw"); } |
### 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 long computeValue(int position); @Override int getMinPosition(); @Override int getMaxPosition(); }### Answer:
@Test public void computeValue() throws Exception { assertEquals(MIN_VALUE, algorithm.computeValue(MIN_POSITION)); assertEquals(MAX_VALUE, algorithm.computeValue(MAX_POSITION)); assertTrue(algorithm.computeValue(MIN_POSITION + 1) > MIN_VALUE); assertTrue(algorithm.computeValue(MAX_POSITION - 1) < MAX_VALUE); } |
### 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 jazonList = new JazonList("orange", 55, false, 173.50, null); List<JsonExpectationInput> list = jazonList.list(); assertEquals(5, list.size()); assertEquals(new ObjectExpectationInput("orange"), list.get(0)); assertEquals(new ObjectExpectationInput(55), list.get(1)); assertEquals(new ObjectExpectationInput(false), list.get(2)); assertEquals(new ObjectExpectationInput(173.50), list.get(3)); assertEquals(new ObjectExpectationInput(null), list.get(4)); }
@Test void nullIsTranslatedToNullPredicate_usingConstructor() { JazonList jazonList = new JazonList(null, null); List<JsonExpectationInput> list = jazonList.list(); assertEquals(2, list.size()); assertEquals(new PredicateExpectationInput<>(null), list.get(0)); }
@Test void onlyPredicates() { JazonList jazonList = new JazonList((Integer it) -> it > 0, (String s) -> s.matches("re.*")); List<JsonExpectationInput> list = jazonList.list(); assertEquals(2, list.size()); PredicateExpectationInput firstPredicateInput = (PredicateExpectationInput) list.get(0); Predicate<Integer> firstPredicate = firstPredicateInput.predicate(); assertFalse(firstPredicate.test(-10)); assertFalse(firstPredicate.test(-1)); assertFalse(firstPredicate.test(0)); assertTrue(firstPredicate.test(1)); assertTrue(firstPredicate.test(10)); PredicateExpectationInput secondPredicateInput = (PredicateExpectationInput) list.get(1); Predicate<String> secondPredicate = secondPredicateInput.predicate(); assertTrue(secondPredicate.test("red")); assertTrue(secondPredicate.test("reindeer")); assertFalse(secondPredicate.test("black")); assertFalse(secondPredicate.test("octopus")); }
@Test void nestedList() { JazonList drinks = new JazonList("pepsi", "coca cola", "sprite"); JazonList birds = new JazonList("pigeon", "sparrow"); JazonList jazonList = new JazonList(drinks, birds); List<JsonExpectationInput> list = jazonList.list(); assertEquals(2, list.size()); assertEquals(new ObjectExpectationInput(drinks), list.get(0)); assertEquals(new ObjectExpectationInput(birds), list.get(1)); } |
### 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(); for (Value value : property.getValues().getAll()) { propertyOutput.append("\t") .append(truncateToNl(value.getName())); if (value.getDescription() != null) { propertyOutput.append(" - ") .append(value.getDescription()); } propertyOutput.append("\n"); } System.out.println(propertyOutput); propertyOutput.setLength(0); } } MetadataExample(); void listProperties(); @Override void close(); static void main(String[] args); }### Answer:
@Test public void testListProperties() throws Exception { example.listProperties(); } |
### 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(); }### Answer:
@Test public void testLiteGettingStartedMediahubUA() throws IOException { assertFalse(gs.isMobile(gs.mediaHubUserAgent)); }
@Test public void testLiteGettingStartedMobileUA() throws IOException { assertTrue(gs.isMobile(gs.mobileUserAgent)); }
@Test public void testLiteGettingStartedDesktopUA() throws IOException { assertFalse(gs.isMobile(gs.desktopUserAgent)); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.