src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
HiveReaderSetting implements IReaderSetting { @Override public boolean isVectorMode(){ return isVectorModeFlag; } HiveReaderSetting( final Configuration config , final IExpressionNode node , final boolean isVectorModeFlag , final boolean disableSkipBlock , final boolean disableFilterPushdown ); HiveReaderSetting( fina...
@Test public void T_isVectorMode_1(){ HiveReaderSetting setting = new HiveReaderSetting( null , null , true , false , false ); assertTrue( setting.isVectorMode() ); setting = new HiveReaderSetting( null , null , false , false , false ); assertFalse( setting.isVectorMode() ); }
MDSStructObjectInspector extends SettableStructObjectInspector { @Override public boolean equals( final Object o ) { if ( o == null || o.getClass() != getClass() ) { return false; } else if ( o == this ){ return true; } else { List<StructField> other = ( (MDSStructObjectInspector) o ).fields; if ( other.size() != field...
@Test public void T_equals_1(){ MDSStructObjectInspector inspector = new MDSStructObjectInspector( getTypeInfo() ); assertTrue( inspector.equals( inspector ) ); }
MDSStructObjectInspector extends SettableStructObjectInspector { @Override public List<Object> getStructFieldsDataAsList( final Object object ){ ColumnAndIndex columnAndIndex = (ColumnAndIndex) object; List<Object> result = new ArrayList<Object>( fields.size() ); for( StructField field : fields ){ MDSStructField struct...
@Test public void T_getStructFieldsDataAsList_1() throws IOException{ MDSStructObjectInspector inspector = new MDSStructObjectInspector( getTypeInfo() ); Map<String,Object> dataContainer = new HashMap<String,Object>(); dataContainer.put( "str" , new StringObj( "a" ) ); dataContainer.put( "num" , new IntegerObj( 1 ) ); ...
ConvertArrowFormatTool { public static void convert( final MDSArrowReader arrowReader , final OutputStream out , final Configuration config ) throws IOException{ ArrowFileWriter writer = null; while( arrowReader.hasNext() ){ ValueVector vector = arrowReader.next(); if( writer == null ){ VectorSchemaRoot schema = new Ve...
@Test public void T_convert_1() throws IOException{ byte[] mdsFile = createTestData(); InputStream in = new ByteArrayInputStream( mdsFile ); MDSReader reader = new MDSReader(); Configuration config = new Configuration(); reader.setNewStream( in , mdsFile.length , config ); MDSArrowReader arrowReader = new MDSArrowReade...
MakeMDSFileStep1 { public static void main( final String[] args ) throws IOException{ new MakeMDSFileStep1().run(); } private MakeMDSFileStep1(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ MakeMDSFileStep1.main( null ); }
UseSpreadStep4 { public static void main( final String[] args ) throws IOException{ new UseSpreadStep4().run(); } private UseSpreadStep4(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ UseSpreadStep4.main( new String[0] ); }
LoadDataToSpreadStep1 { public static void main( final String[] args ) throws IOException{ new LoadDataToSpreadStep1().run(); } private LoadDataToSpreadStep1(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ LoadDataToSpreadStep1.main( null ); }
UseExpandSpread1 { public static void main( final String[] args ) throws IOException{ new UseExpandSpread1().run(); } private UseExpandSpread1(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ UseExpandSpread1.main( new String[0] ); }
UseSpreadStep2 { public static void main( final String[] args ) throws IOException{ new UseSpreadStep2().run(); } private UseSpreadStep2(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ UseSpreadStep2.main( new String[0] ); }
UseSpreadStep1 { public static void main( final String[] args ) throws IOException{ new UseSpreadStep1().run(); } private UseSpreadStep1(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ UseSpreadStep1.main( new String[0] ); }
UseSpreadStep3 { public static void main( final String[] args ) throws IOException{ new UseSpreadStep3().run(); } private UseSpreadStep3(); int run(); static void main( final String[] args ); }
@Test public void T_run_1() throws IOException{ UseSpreadStep3.main( new String[0] ); }
HiveReaderSetting implements IReaderSetting { @Override public Configuration getReaderConfig(){ return config; } HiveReaderSetting( final Configuration config , final IExpressionNode node , final boolean isVectorModeFlag , final boolean disableSkipBlock , final boolean disableFilterPushdown ); HiveReaderSetting( final...
@Test public void T_getReaderConfig_1(){ HiveReaderSetting setting = new HiveReaderSetting( null , null , true , false , false ); assertEquals( null , setting.getReaderConfig() ); }
ArrowBytesMemoryAllocator implements IMemoryAllocator { @Override public void setBytes( final int index , final byte[] value ) throws IOException{ setBytes( index , value , 0 , value.length ); } ArrowBytesMemoryAllocator( final VarBinaryVector vector , final int rowCount ); @Override void setNull( final int index ); @O...
@Test public void T_setBytes_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew()...
ArrowFloatMemoryAllocator implements IMemoryAllocator { @Override public void setFloat( final int index , final float value ) throws IOException{ vector.setSafe( index , value ); } ArrowFloatMemoryAllocator( final Float4Vector vector , final int rowCount ); @Override void setNull( final int index ); @Override void setB...
@Test public void T_setFloat_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew()...
ArrowIntegerMemoryAllocator implements IMemoryAllocator { @Override public void setInteger( final int index , final int value ) throws IOException{ vector.setSafe( index , value ); } ArrowIntegerMemoryAllocator( final IntVector vector , final int rowCount ); @Override void setNull( final int index ); @Override void set...
@Test public void T_setInteger_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew...
ArrowStringMemoryAllocator implements IMemoryAllocator { @Override public void setString( final int index , final String value ) throws IOException{ byte[] strBytes = value.getBytes( "UTF-8" ); setBytes( index , strBytes ); } ArrowStringMemoryAllocator( final VarCharVector vector , final int rowCount ); @Override void ...
@Test public void T_setString_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew(...
ArrowShortMemoryAllocator implements IMemoryAllocator { @Override public void setShort( final int index , final short value ) throws IOException{ vector.setSafe( index , value ); } ArrowShortMemoryAllocator( final SmallIntVector vector , final int rowCount ); @Override void setNull( final int index ); @Override void se...
@Test public void T_setShort_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew()...
ArrowLongMemoryAllocator implements IMemoryAllocator { @Override public void setLong( final int index , final long value ) throws IOException{ vector.setSafe( index , value ); } ArrowLongMemoryAllocator( final BigIntVector vector , final int rowCount ); @Override void setNull( final int index ); @Override void setBoole...
@Test public void T_setLong_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew();...
ArrowBooleanMemoryAllocator implements IMemoryAllocator { @Override public void setBoolean( final int index , final boolean value ) throws IOException{ if( value ){ vector.setSafe( index , 1 ); } else{ vector.setSafe( index , 0 ); } } ArrowBooleanMemoryAllocator( final BitVector vector , final int rowCount ); @Override...
@Test public void T_setBoolean_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew...
ArrowByteMemoryAllocator implements IMemoryAllocator { @Override public void setByte( final int index , final byte value ) throws IOException{ vector.setSafe( index , value ); } ArrowByteMemoryAllocator( final TinyIntVector vector , final int rowCount ); @Override void setNull( final int index ); @Override void setBool...
@Test public void T_setByte_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew();...
ArrowDoubleMemoryAllocator implements IMemoryAllocator { @Override public void setDouble( final int index , final double value ) throws IOException{ vector.setSafe( index , value ); } ArrowDoubleMemoryAllocator( final Float8Vector vector , final int rowCount ); @Override void setNull( final int index ); @Override void ...
@Test public void T_setDouble_1() throws IOException{ BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 ); SchemaChangeCallBack callBack = new SchemaChangeCallBack(); StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); parent.allocateNew(...
FloatRangeBlockIndex implements IBlockIndex { @Override public BlockIndexType getBlockIndexType(){ return BlockIndexType.RANGE_FLOAT; } FloatRangeBlockIndex(); FloatRangeBlockIndex( final Float min , final Float max ); @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ...
@Test public void T_getBlockIndexType_1(){ IBlockIndex bIndex = new FloatRangeBlockIndex(); assertEquals( BlockIndexType.RANGE_FLOAT , bIndex.getBlockIndexType() ); }
HiveReaderSetting implements IReaderSetting { @Override public IExpressionNode getExpressionNode(){ return node; } HiveReaderSetting( final Configuration config , final IExpressionNode node , final boolean isVectorModeFlag , final boolean disableSkipBlock , final boolean disableFilterPushdown ); HiveReaderSetting( fin...
@Test public void T_getExpressionNode_1(){ HiveReaderSetting setting = new HiveReaderSetting( null , null , true , false , false ); assertEquals( null , setting.getExpressionNode() ); }
FloatRangeBlockIndex implements IBlockIndex { @Override public int getBinarySize(){ return Float.BYTES * 2; } FloatRangeBlockIndex(); FloatRangeBlockIndex( final Float min , final Float max ); @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Override int getBinary...
@Test public void T_getBinarySize_1(){ FloatRangeBlockIndex bIndex = new FloatRangeBlockIndex( (float)10 , (float)20 ); assertEquals( Float.BYTES * 2 , bIndex.getBinarySize() ); }
BlockIndexNode { public int getBinarySize() throws IOException{ if( isDisable ){ return 0; } int length = 0; length += Integer.BYTES; if( blockIndex != null ){ length += Integer.BYTES; length += RangeBlockIndexNameShortCut.getShortCutName( blockIndex.getClass().getName() ).getBytes( "UTF-8" ).length; length += Integer....
@Test public void T_getBinarySize_1() throws IOException{ BlockIndexNode b = new BlockIndexNode(); assertEquals( 8 , b.getBinarySize() ); }
StringRangeBlockIndex implements IBlockIndex { @Override public BlockIndexType getBlockIndexType(){ return BlockIndexType.RANGE_STRING; } StringRangeBlockIndex(); StringRangeBlockIndex( final String min , final String max ); @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex block...
@Test public void T_getBlockIndexType_1(){ IBlockIndex bIndex = new StringRangeBlockIndex(); assertEquals( BlockIndexType.RANGE_STRING , bIndex.getBlockIndexType() ); }
StringRangeBlockIndex implements IBlockIndex { @Override public int getBinarySize(){ return ( min.length() * 2 ) + ( max.length() * 2 ) + 4 + 4; } StringRangeBlockIndex(); StringRangeBlockIndex( final String min , final String max ); @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIn...
@Test public void T_getBinarySize_1(){ StringRangeBlockIndex bIndex = new StringRangeBlockIndex( "10" , "20" ); assertEquals( Integer.BYTES * 2 + Character.BYTES * 4 , bIndex.getBinarySize() ); }
ByteRangeBlockIndex implements IBlockIndex { @Override public BlockIndexType getBlockIndexType(){ return BlockIndexType.RANGE_BYTE; } ByteRangeBlockIndex(); ByteRangeBlockIndex( final byte min , final byte max ); @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Ov...
@Test public void T_getBlockIndexType_1(){ IBlockIndex bIndex = new ByteRangeBlockIndex(); assertEquals( BlockIndexType.RANGE_BYTE , bIndex.getBlockIndexType() ); }
ByteRangeBlockIndex implements IBlockIndex { @Override public int getBinarySize(){ return Byte.BYTES * 2; } ByteRangeBlockIndex(); ByteRangeBlockIndex( final byte min , final byte max ); @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Override int getBinarySize()...
@Test public void T_getBinarySize_1(){ ByteRangeBlockIndex bIndex = new ByteRangeBlockIndex( (byte)10 , (byte)20 ); assertEquals( 2 , bIndex.getBinarySize() ); }
UnsupportedBlockIndex implements IBlockIndex { @Override public BlockIndexType getBlockIndexType(){ return BlockIndexType.UNSUPPORTED; } @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Override int getBinarySize(); @Override byte[] toBinary(); @Override void setF...
@Test public void T_getBlockIndexType_1(){ assertEquals( BlockIndexType.UNSUPPORTED , UnsupportedBlockIndex.INSTANCE.getBlockIndexType() ); }
UnsupportedBlockIndex implements IBlockIndex { @Override public boolean merge( final IBlockIndex blockIndex ){ return false; } @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Override int getBinarySize(); @Override byte[] toBinary(); @Override void setFromBinary(...
@Test public void T_merge_1(){ assertFalse( UnsupportedBlockIndex.INSTANCE.merge( null ) ); }
UnsupportedBlockIndex implements IBlockIndex { @Override public int getBinarySize(){ return 0; } @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Override int getBinarySize(); @Override byte[] toBinary(); @Override void setFromBinary( final byte[] buffer , final i...
@Test public void T_getBinarySize_1(){ assertEquals( 0 , UnsupportedBlockIndex.INSTANCE.getBinarySize() ); }
UnsupportedBlockIndex implements IBlockIndex { @Override public byte[] toBinary(){ return new byte[0]; } @Override BlockIndexType getBlockIndexType(); @Override boolean merge( final IBlockIndex blockIndex ); @Override int getBinarySize(); @Override byte[] toBinary(); @Override void setFromBinary( final byte[] buffer ,...
@Test public void T_binary_1(){ byte[] binary = UnsupportedBlockIndex.INSTANCE.toBinary(); assertEquals( 0 , binary.length ); }
ParserWritable implements Writable { @Override public void write( final DataOutput dataOutput ) throws IOException { throw new UnsupportedOperationException("write unsupported"); } void set( final IParser parser ); @Override void write( final DataOutput dataOutput ); @Override void readFields( final DataInput dataInpu...
@Test public void T_write_1() throws IOException{ ParserWritable writable = new ParserWritable(); assertThrows( UnsupportedOperationException.class , () -> { writable.write( null ); } ); }
Promise { public static Promise <List <Object>> all (Promise <?>... promises) { return all (Arrays.asList (promises)); } Promise(PromiseExecutor<T> impl); Promise(String name, PromiseExecutor<T> impl); private Promise(T value); private Promise(Throwable reason); private Promise(String name, PromiseExecutor<T> impl,...
@Test public void testAll () throws Exception { synchronized (this.lock_) { Promise<List<Object>> p = Promise.all ( new Promise<> (settlement -> settlement.resolve (10)), new Promise<> (settlement -> settlement.resolve (20)) ); p.then (resolved (values -> { Assert.assertEquals (2, values.size ()); Assert.assertEquals (...
Promise { public static <U> Promise <U> race (Promise <U>... promises) { return race (Arrays.asList (promises)); } Promise(PromiseExecutor<T> impl); Promise(String name, PromiseExecutor<T> impl); private Promise(T value); private Promise(Throwable reason); private Promise(String name, PromiseExecutor<T> impl, Statu...
@Test public void testRace () throws Exception { synchronized (this.lock_) { Promise<Integer> p = Promise.race ( new Promise<> (settlement -> { { try { Thread.sleep (500); settlement.resolve (10); } catch (InterruptedException e) { settlement.reject (e); } } }), new Promise<> (settlement -> { { try { Thread.sleep (300)...
Promise { public boolean cancel () { return this.cancel (true); } Promise(PromiseExecutor<T> impl); Promise(String name, PromiseExecutor<T> impl); private Promise(T value); private Promise(Throwable reason); private Promise(String name, PromiseExecutor<T> impl, Status status, T value, Throwable reason); static OnRe...
@Test public void testCancel () throws Exception { synchronized (this.lock_) { Promise<Integer> p1 = new Promise<> (settlement -> { try { Thread.sleep (300); } catch (InterruptedException e) { this.isComplete_ = true; } }); Thread.sleep (100); p1.cancel (true); p1.then (resolved (value -> this.isComplete_ = false)); th...
Promise { public static <T> T await (Promise <T> promise) throws Throwable { return await (promise, true); } Promise(PromiseExecutor<T> impl); Promise(String name, PromiseExecutor<T> impl); private Promise(T value); private Promise(Throwable reason); private Promise(String name, PromiseExecutor<T> impl, Status stat...
@Test public void testAwaitResolved () throws Throwable { int result = await (this.makeSimplePromise (5, 2000)); Assert.assertEquals (result, 5); } @Test public void testAwaitRejected () { try { await (this.makeSimplePromise (new IllegalStateException ("REJECTED"), 2000)); Assert.fail ("The promise should have been rej...
StatisticalOperation { public synchronized float addValue(final float value) { sumBuffer += value; if ((minBuffer == null) || (value < minBuffer)) { minBuffer = value; } if ((maxBuffer == null) || (value > maxBuffer)) { maxBuffer = value; } buffer[pointer++] = value; pointer = pointer % bufferSize; if (maxValidFieldVal...
@Test public final void testAddValueSUM1() { final StatisticalOperation statisticalOperation = new StatisticalOperation(10, STATISTICAL_OPERATIONS.SUM); statisticalOperation.addValue(1); statisticalOperation.addValue(2); statisticalOperation.addValue(3); statisticalOperation.addValue(4); statisticalOperation.addValue(5...
QuadTree implements Layer, BoundingBoxChangeListener { @Override public void clear() { if (threadSafe) { synchronized (lock) { final Set<DrawingObject> dos = tree.searchItems(); for (final DrawingObject dob : dos) { dob.removeBoundingBoxChangeListener(this); } tree.clear(); insertionOrder.clear(); insertionOrderLargest...
@Test public void testClear() { addAllRectangles(); assertTrue(tree.getDrawingObjects().size() == 4); tree.clear(); assertTrue(tree.getDrawingObjects().isEmpty()); }
QuadTree implements Layer, BoundingBoxChangeListener { @Override public Set<DrawingObject> getDrawingObjects() { return getDrawingObjects(false); } @SuppressWarnings("synthetic-access") QuadTree(final int originX, final int originY, final int totalSideLength, final int minSideLength, final int capacity, final boole...
@Test public void testContains() { addAllRectangles(); assertTrue(tree.getDrawingObjects(rectangle1.getBoundingBox()).contains(rectangle1)); assertTrue(tree.getDrawingObjects(rectangle2.getBoundingBox()).contains(rectangle2)); assertTrue(tree.getDrawingObjects(rectangle3.getBoundingBox()).contains(rectangle3)); assertT...
QuadTree implements Layer, BoundingBoxChangeListener { @Override public void pushBack(final DrawingObject object) { if (threadSafe) { synchronized (lock) { insertionOrder.put(object, --insertionOrderSmallest); } } else { insertionOrder.put(object, --insertionOrderSmallest); } } @SuppressWarnings("synthetic-access") Qu...
@Test public void testPushBack() { Set<DrawingObject> set; addAllRectangles(); set = tree.getDrawingObjects(true); assertTrue(set.toArray()[3] == rectangle4); assertTrue(set.toArray()[0] == rectangle1); tree.pushBack(rectangle1); set = tree.getDrawingObjects(true); assertTrue(set.toArray()[0] == rectangle1); tree.pushB...
QuadTree implements Layer, BoundingBoxChangeListener { @Override public void remove(final DrawingObject d) { if (threadSafe) { final Rectangle rect = d.getBoundingBox().rectangle; synchronized (lock) { tree.removeItem(d, rect); d.removeBoundingBoxChangeListener(this); insertionOrder.remove(d); } } else { tree.removeIte...
@Test public void testRemove() { addAllRectangles(); tree.remove(rectangle1); assertFalse(tree.getDrawingObjects().contains(rectangle1)); assertTrue(tree.getDrawingObjects().contains(rectangle2)); assertTrue(tree.getDrawingObjects().contains(rectangle3)); assertTrue(tree.getDrawingObjects().contains(rectangle4)); tree....
QuadTree implements Layer, BoundingBoxChangeListener { @Override public void add(final DrawingObject d) { if (threadSafe) { synchronized (lock) { if (insertionOrder.containsKey(d)) { throw new RuntimeException("Don't do double insert, no no ;-)"); } d.addBoundingBoxChangedListener(this); insertionOrder.put(d, ++inserti...
@Test public void borderTest() { final Rectangle rectBorderLeft = new Rectangle(upperLeftX, upperLeftY + (height / 2), rectWidth, rectHeight); final Rectangle rectBorderTop = new Rectangle(upperLeftX + (width / 2), upperLeftY, rectWidth, rectHeight); final Rectangle rectBorderRight = new Rectangle(upperLeftX + width - ...
QuadTree implements Layer, BoundingBoxChangeListener { @Override public void bringToFront(final DrawingObject dob) { if (threadSafe) { synchronized (lock) { insertionOrder.put(dob, ++insertionOrderLargest); } } else { insertionOrder.put(dob, ++insertionOrderLargest); } } @SuppressWarnings("synthetic-access") QuadTree(...
@Test public void testBringToFront() { Set<DrawingObject> set; addAllRectangles(); set = tree.getDrawingObjects(true); assertTrue(set.toArray()[0] == rectangle1); assertTrue(set.toArray()[3] == rectangle4); tree.bringToFront(rectangle1); set = tree.getDrawingObjects(true); assertTrue(set.toArray()[3] == rectangle1); tr...
JSONArray extends JSONGetter<Integer> implements JSON, List<Object> { @Override public boolean add(Object e) { return this.rawArrayList.add(JSONUtil.wrap(e)); } JSONArray(); JSONArray(JSONTokener x); JSONArray(String source); JSONArray(Object arrayOrCollection); boolean isNull(int index); String join(String separato...
@Test public void addTest(){ JSONArray array = JSONUtil.createArray(); array.add("value1"); array.add("value2"); array.add("value3"); Assert.assertEquals(array.get(0), "value1"); }
JSONArray extends JSONGetter<Integer> implements JSON, List<Object> { @Override public Object get(int index) { return this.rawArrayList.get(index); } JSONArray(); JSONArray(JSONTokener x); JSONArray(String source); JSONArray(Object arrayOrCollection); boolean isNull(int index); String join(String separator); @Overri...
@Test public void parseTest(){ String jsonStr = "[\"value1\", \"value2\", \"value3\"]"; JSONArray array = JSONUtil.parseArray(jsonStr); Assert.assertEquals(array.get(0), "value1"); }
JSONObject extends JSONGetter<String> implements JSON, Map<String, Object> { @Override public void putAll(Map<? extends String, ? extends Object> m) { rawHashMap.putAll(m); } JSONObject(); JSONObject(JSONObject jsonObject, String... names); JSONObject(JSONTokener x); JSONObject(Object source); JSONObject(Object poj...
@Test public void putAllTest(){ JSONObject json1 = JSONUtil.createObj(); json1.put("a", "value1"); json1.put("b", "value2"); json1.put("c", "value3"); json1.put("d", true); JSONObject json2 = JSONUtil.createObj(); json2.put("a", "value21"); json2.put("b", "value22"); json1.putAll(json2); Assert.assertEquals(json1.get("...
JSONObject extends JSONGetter<String> implements JSON, Map<String, Object> { @Override public Object get(Object key) { return rawHashMap.get(key); } JSONObject(); JSONObject(JSONObject jsonObject, String... names); JSONObject(JSONTokener x); JSONObject(Object source); JSONObject(Object pojo, String[] names); JSONO...
@Test public void parseTest(){ String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true}"; JSONObject jsonObject = JSONUtil.parseObj(jsonStr); Assert.assertEquals(jsonObject.get("a"), "value1"); Assert.assertEquals(jsonObject.get("b"), "value2"); Assert.assertEquals(jsonObject.get("c"), "value...
JSONObject extends JSONGetter<String> implements JSON, Map<String, Object> { public <T> T toBean(Class<T> clazz) { return toBean(clazz, false); } JSONObject(); JSONObject(JSONObject jsonObject, String... names); JSONObject(JSONTokener x); JSONObject(Object source); JSONObject(Object pojo, String[] names); JSONObje...
@Test public void toBeanTest(){ JSONObject subJson = JSONUtil.createObj().put("value1", "strValue1").put("value2", "234"); JSONObject json = JSONUtil.createObj() .put("strValue", "strTest") .put("intValue", 123) .put("beanValue", subJson) .put("list", JSONUtil.createArray().put("a").put("b")); TestBean bean = json.toBe...
CassandraLoader implements Loader<DecisionTreeRuleSet>, Persister, ComponentLifecycle { public Result<ChangeSet> getChange(final String changeSetName) { try { final ResultSet resultSet = this.session.execute(CQL_GET_ACTIVE_CHANGE, changeSetName); EhSupport.ensure(!resultSet.isExhausted(), "ChangeSet %s does not exist i...
@Test public void testGetChange() { setUpPutChangeMocks(false); final CassandraLoader testInstance = CassandraLoader.instanceOf(this.cluster, "keyspace", RULE_SET_NAME); assertNotNull(testInstance); verify(this.cluster, times(1)).getConfiguration(); final Result<ChangeSet> loadedChangeSet = testInstance.getChange(CHANG...
DecisionTreeRule implements TreeRule { public boolean isDuplicateInputData(final DecisionTreeRule other) { if (other == null || drivers.length != other.drivers.length) { return false; } for (int i = 0; i < drivers.length; i++) { final InputDriver thisValue = drivers[i]; final InputDriver otherValue = other.drivers[i]; ...
@Test public void testRuleDuplicateInputCheck() { final DecisionTreeRule rule = new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(), getInputDriverArray("input1", "input2"), this.outputDriver, null, null); assertTrue(rule.isDuplicateInputData(new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(), getInputDriverArra...
DecisionTreeRule implements TreeRule { public boolean isDuplicateEvaluations(final DecisionTreeRule other) { if (other == null || evaluations == null || other.evaluations == null || evaluations.length != other.evaluations.length) { return false; } for (int i = 0; i < evaluations.length; i++) { final InputDriver thisVal...
@Test public void testRuleDuplicateEvaluationCheck() { final DecisionTreeRule rule = new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(), getInputDriverArray("input1", "input2"), getInputDriverArray("eval1", "eval2"), this.outputDriver, null, null); assertTrue(rule.isDuplicateEvaluations(new DecisionTreeRule(new UUI...
DecisionTreeRule implements TreeRule { public boolean isDuplicateOutputData(final DecisionTreeRule other) { if (other == null || outputs.size() != other.outputs.size()) { return false; } for (final Map.Entry<String, String> entry : outputs.entrySet()) { final String value = other.outputs.get(entry.getKey()); if (!entry...
@Test public void testRuleDuplicateOutputCheck() { final DecisionTreeRule rule = new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(), getInputDriverArray("input1", "input2"), Collections.singletonMap("outputDriver", "result"), null, null); assertTrue(rule.isDuplicateOutputData(new DecisionTreeRule(new UUID(0, 1), UU...
DecisionTreeRule implements TreeRule { public boolean isDuplicateDateRange(final DecisionTreeRule other) { return other != null && start.equals(other.start) && end.equals(other.end); } DecisionTreeRule(final UUID ruleIdentifier, final UUID ruleCode, final InputDriver[] drivers, final InputDr...
@Test public void testDuplicateDateRange() { final Instant startTime = Instant.now().minus(30, ChronoUnit.DAYS); final Instant endTime = Instant.now().plus(180, ChronoUnit.DAYS); final DecisionTreeRule rule = new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(), getInputDriverArray("input1", "input2"), Collections.si...
DecisionTreeRule implements TreeRule { public boolean isDuplicateRule(final DecisionTreeRule other) { if (other == null) { return false; } if (evaluations != null || other.evaluations != null) { return isDuplicateInputData(other) && isDuplicateOutputData(other) && isDuplicateDateRange(other) && isDuplicateEvaluations(o...
@Test public void testDuplicateRuleCheck() { final Instant startTime = Instant.now().minus(30, ChronoUnit.DAYS); final Instant endTime = Instant.now().plus(180, ChronoUnit.DAYS); final DecisionTreeRule rule = new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(), getInputDriverArray("input1", "input2"), Collections.si...
DecisionTreeRule implements TreeRule { void replaceDriversFromCache(final DriverCache cache) { for (int i = 0; i < drivers.length; i++) { final InputDriver driver = drivers[i]; InputDriver cachedDriver = cache.get(driver.getValue(), driver.getType()); if (cachedDriver == null) { cache.put(driver); cachedDriver = cache....
@Test public void testReplaceDriversFromCache() { final DecisionTreeRule decisionTreeRule = new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), getInputDriverArray("input1", "input2"), this.outputDriver, null, null); final DriverCache cache = new DriverCache(); cache.put(new StringDriver("input1")); final InputDriver ...
DecisionTreeRuleSet { @Override public int hashCode() { return name.hashCode(); } DecisionTreeRuleSet(final String name, final Map<UUID, DecisionTreeRule> rules, final List<String> driverNames); DecisionTreeRuleSet(final String name, final Map<UUID, DecisionTreeRule> rules, ...
@Test public void testEquality() { final List<String> driverNames = Arrays.asList("driver1", "driver2"); final DecisionTreeRuleSet ruleSet = new DecisionTreeRuleSet("TestName", null, driverNames); assertEquals(ruleSet, ruleSet); assertEquals(new DecisionTreeRuleSet("TestName", null, driverNames), ruleSet); assertNotEqu...
DecisionTreeRuleSet { public static List<WeightedDriver> convertNamesToWeightedDrivers(final List<String> driverNames) { EhSupport.ensureArg(driverNames.size() < 32, "Maximum number of drivers is 31"); return IntStream.range(0, driverNames.size()) .mapToObj(counter -> new WeightedDriver(driverNames.get(counter), 1 << d...
@Test(expected = IllegalArgumentException.class) public void testTooManyDriversToWeightedDrivers() { final List<String> driverNames = IntStream.range(1, 33).mapToObj(String::valueOf).collect(Collectors.toList()); DecisionTreeRuleSet.convertNamesToWeightedDrivers(driverNames); }
DecisionTreeRuleSet { public Set<ValueGroup> getValueGroups() { return groups.values().stream() .collect(collectingAndThen(Collectors.toSet(), Collections::unmodifiableSet)); } DecisionTreeRuleSet(final String name, final Map<UUID, DecisionTreeRule> rules, final List<String> driverNames); Deci...
@Test(expected = UnsupportedOperationException.class) public void testingImmutableValueGroups() { final DecisionTreeRuleSet commisssionRuleSet = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex().build(); commisssionRuleSet.getValueGroups().clear(); }
DecisionTreeRuleSet { public List<String> getDriverNames() { return driverNames.stream().map(WeightedDriver::getName) .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); } DecisionTreeRuleSet(final String name, final Map<UUID, DecisionTreeRule> rules, final List<Stri...
@Test(expected = UnsupportedOperationException.class) public void testingImmutableDrivers() { final DecisionTreeRuleSet commisssionRuleSet = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex().build(); commisssionRuleSet.getDriverNames().clear(); }
Change implements TreeChange { public boolean addRuleChange(final RuleChange change) { EhSupport.ensureArg(change != null, "Cannot add a null rule change"); return this.ruleChanges.add(change); } Change(final UUID id, final String ruleSetName, final Instant activationTime, ...
@Test(expected = IllegalArgumentException.class) public void cannotAddNullRuleChange() { testConstruction(); getBean().addRuleChange((RuleChange) null); } @Test public void addRuleChange() { testConstruction(); final Instant start = NOW.minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final...
DecisionTreeRuleSet { public List<String> getEvaluationNames() { return Collections.unmodifiableList(evaluationNames); } DecisionTreeRuleSet(final String name, final Map<UUID, DecisionTreeRule> rules, final List<String> driverNames); DecisionTreeRuleSet(final String name, final Map<UUID, Decis...
@Test(expected = UnsupportedOperationException.class) public void testingImmutableEvaluationNames() { final DecisionTreeRuleSet commisssionRuleSet = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex().build(); commisssionRuleSet.getEvaluationNames().clear(); }
DecisionTreeRuleSet { public List<InputDriver> getDriversByType(final InputValueType type) { return cache.findByInputDriverType(type); } DecisionTreeRuleSet(final String name, final Map<UUID, DecisionTreeRule> rules, final List<String> driverNames); DecisionTreeRuleSet(final String name, final...
@Test public void testFindingInputDrivers() { final DecisionTreeRuleSet commisssionRuleSet = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex().build(); List<InputDriver> driversByType = commisssionRuleSet.getDriversByType(InputValueType.STRING); assertNotNull(driversByType); assertEquals(11, driversByType.size()...
ValueGroup implements TreeValueGroup { @Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } final ValueGroup otherGroup = (ValueGroup) other; return getId().equals(otherGroup.getId()) && getName().equals(oth...
@Test public void equalsCorrect() { final UUID uuid = new UUID(0, 1); final DateRange range = new DateRange(NOW, Instant.MAX); final ValueGroup group = new ValueGroup(uuid, "test-group", Arrays.asList("input1", "input2"), range); assertTrue(group.equals(group)); assertFalse(group.equals(null)); assertFalse(group.equals...
ValueGroup implements TreeValueGroup { @Override public int hashCode() { return getId().hashCode() + getName().hashCode() + getValues().hashCode() + getRange().hashCode(); } ValueGroup(final String name, final List<String> values); ValueGroup(final UUID id, final String name, final List<String> values, final DateRange...
@Test public void hashCodeCorrect() { final UUID uuid = new UUID(0, 1); final DateRange range = new DateRange(NOW, Instant.MAX); final ValueGroup group = new ValueGroup(uuid, "test-group", Arrays.asList("input1", "input2"), range); final ValueGroup other = new ValueGroup(new UUID(0, 1), "test-group", Arrays.asList("inp...
ValueGroup implements TreeValueGroup { @Override public String toString() { return GroupDriver.VG_PREFIX + getId(); } ValueGroup(final String name, final List<String> values); ValueGroup(final UUID id, final String name, final List<String> values, final DateRange range); @Override UUID getId(); @Override String getNam...
@Test public void toStringCorrect() { final UUID uuid = new UUID(0, 1); final DateRange range = new DateRange(NOW, Instant.MAX); final ValueGroup group = new ValueGroup(uuid, "test-group", Arrays.asList("input1", "input2"), range); Assert.assertEquals(GroupDriver.VG_PREFIX + new UUID(0, 1), group.toString()); }
RuleSetBuilder { public static Builder<RuleSetBuilder, DecisionTreeRuleSet> creator(final List<String> driverNames) { return creator("", driverNames); } private RuleSetBuilder(final String name, final List<String> driverNames); static Builder<RuleSetBuilder, DecisionTreeRuleSet> creator(final List<String> driverNames)...
@Test public void testRuleSetBuilderFactory() { final Builder<RuleSetBuilder, DecisionTreeRuleSet> instance = RuleSetBuilder.creator(Arrays.asList("input1", "input2", "input3")); assertNotNull(instance); final DecisionTreeRuleSet ruleSet = instance.build(); assertNotNull(ruleSet); assertEquals("", ruleSet.getName()); }...
Change implements TreeChange { public boolean removeRuleChange(final RuleChange change) { return this.ruleChanges.remove(change); } Change(final UUID id, final String ruleSetName, final Instant activationTime, final DateRange changeRange, final Aud...
@Test public void removeRuleChange() { addRuleChange(); assertThat(getBean().getRuleChanges(), hasSize(2)); final Instant start = NOW.minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final InputDriver[] drivers = getInputDriverArray("Test5", "Test6", "Test7"); final Map<String, String> outp...
RuleSetBuilder { public static void addValueGroupsToDriverCache(final DriverCache cache, final Collection<ValueGroup> valueGroups) { valueGroups.forEach(valueGroup -> { GroupDriver existingDriver = getGroupDriver(cache, valueGroup.getId().toString()); if (existingDriver == null) { existingDriver = new GroupDriver(value...
@Test public void testCreatingBasicValueGroupDriversInCache() { final DriverCache cache = new DriverCache(); final Set<ValueGroup> valueGroups = new HashSet<>(1); final ValueGroup group = new ValueGroup("vg1", Arrays.asList("input1", "input2", "input3")); valueGroups.add(group); RuleSetBuilder.addValueGroupsToDriverCac...
InputBuilder { public static String regExInput(final String regex) { return RegexDriver.REGEX_PREFIX + ":" + regex; } private InputBuilder(); static String regExInput(final String regex); static String dateRangeInput(final Range<Instant> range); static String integerRangeInput(final Range<Integer> range); }
@Test public void testRegExInput() { assertThat(InputBuilder.regExInput(".RegEx"), is("RE:.RegEx")); }
InputBuilder { public static String dateRangeInput(final Range<Instant> range) { return DateRangeDriver.DR_PREFIX + ":" + range.getStart() + "|" + range.getFinish(); } private InputBuilder(); static String regExInput(final String regex); static String dateRangeInput(final Range<Instant> range); static String integerRa...
@Test public void testDateRangeInput() { final String startStr = "2013-03-28T00:00:00Z"; final String endStr = "2015-06-01T10:50:00Z"; final Range<Instant> range = new Range<>(Instant.parse(startStr), Instant.parse(endStr)); assertThat(InputBuilder.dateRangeInput(range), is("DR:" + startStr + "|" + endStr)); }
InputBuilder { public static String integerRangeInput(final Range<Integer> range) { return IntegerRangeDriver.IR_PREFIX + ":" + range.getStart() + "|" + range.getFinish(); } private InputBuilder(); static String regExInput(final String regex); static String dateRangeInput(final Range<Instant> range); static String int...
@Test public void testIntegerRangeInput() { assertThat(InputBuilder.integerRangeInput(new Range<>(100, 500)), is("IR:100|500")); }
Change implements TreeChange { public boolean addValueGroupChange(final ValueGroupChange change) { EhSupport.ensureArg(change != null, "Cannot add a null value group change"); return this.valueGroupChanges.add(change); } Change(final UUID id, final String ruleSetName, final Instant a...
@Test public void addValueGroupChange() { testConstruction(); final Instant start = NOW.minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final DateRange range = new DateRange(start, end); final List<String> drivers = Arrays.asList("Test5", "Test6", "Test7"); final ValueGroup valueGroup = ne...
RuleBuilder { public static Builder<RuleBuilder, DecisionTreeRule> creator() { return Builder.instanceOf(RuleBuilder.create(), RuleBuilder.validate(), RuleBuilder::builds); } static Builder<RuleBuilder, DecisionTreeRule> creator(); static DecisionTreeRule builds(final RuleBuilder builder); void setId(final UUID id); v...
@Test public void testBasicConstruction() { final Builder<RuleBuilder, DecisionTreeRule> ruleBuilder = RuleBuilder.creator(); assertNotNull(ruleBuilder); final List<String> testInputs = Arrays.asList("test1", "test2"); ruleBuilder.with(RuleBuilder::input, testInputs); ruleBuilder.with(RuleBuilder::setDriverCount, 2L); ...
DomainSerialiser { public static Supplier<InputDriver> createInputDriver(final String currentDriver, final DriverCache cache) { return () -> { final InputValueType type = INPUT_VALUE_TYPE_FUNCTION.apply(currentDriver); final InputDriver inputDriver; if (InputValueType.VALUE_GROUP.equals(type)) { inputDriver = getValueG...
@Test public void convertStringToDateRangeDriverAndTestDates() { final DriverCache cache = new DriverCache(); final String testString = "DR:2017-07-04T16:00:00.000Z|2017-07-10T16:00:00.000Z"; final Supplier<InputDriver> rangeSupplier = DomainSerialiser.createInputDriver(testString, cache); final InputDriver dateRangeDr...
DomainSerialiser { public static List<String> convertOutputs(final Map<String, String> outputMap) { return outputMap.entrySet().stream().map( entry -> entry.getKey() + ":" + entry.getValue()).collect(Collectors.toList()); } private DomainSerialiser(); static List<String> convertDrivers(final InputDriver[] drivers); st...
@Test public void testOutputConversion() { final Map<String, String> outputMap = Stream.of(new AbstractMap.SimpleEntry<>("Driver1", "Value1"), new AbstractMap.SimpleEntry<>("Driver2", "Value2"), new AbstractMap.SimpleEntry<>("Driver3", "Value3")) .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.Si...
Change implements TreeChange { @Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } final Change otherChange = (Change) other; return this.id.equals(otherChange.getId()) && this.ruleSetName.equals(otherChang...
@Test public void equalsCorrect() { final Set<RuleChange> ruleChanges = null; final Set<ValueGroupChange> valueGroupChanges = null; final UUID id = new UUID(0, 2); final Instant initiatorTime = NOW; final Instant authoriserTime = initiatorTime.plus(Period.ofWeeks(1)); final Audit audit = new Audit("USER1", initiatorTim...
DecisionTree { public static DecisionTree instanceOf(final Loader<DecisionTreeRuleSet> loader, final DecisionTreeType type) { final ActionRetrier<DecisionTreeRuleSet> retrier = Retrier.createNonRetrier(); final Result<DecisionTreeRuleSet> result = retrier.run(loader, booleanResult -> false); EhSupport.checkResult(resul...
@Test public void slicedDecisionTreeEvaluation() { final DecisionTree decisionTree = DecisionTree.instanceOf( new Loader<DecisionTreeRuleSet>() { @Override public boolean test(final Result result) { return false; } @Override public Result<DecisionTreeRuleSet> get() { return Result.success(CommisionRuleSetSupplier.getSl...
Change implements TreeChange { @Override public int hashCode() { return this.id.hashCode() + this.ruleSetName.hashCode(); } Change(final UUID id, final String ruleSetName, final Instant activationTime, final DateRange changeRange, final Audit audit...
@Test public void hashCodeCorrect() { final Set<RuleChange> ruleChanges = null; final Set<ValueGroupChange> valueGroupChanges = null; final Instant initiatorTime = NOW; final Instant authoriserTime = initiatorTime.plus(Period.ofWeeks(1)); final Audit audit = new Audit("USER1", initiatorTime, "USER2", authoriserTime); f...
ValueGroupChange { @Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } final ValueGroupChange change = (ValueGroupChange) other; return this.type == change.getType() && this.valueGroup.equals(change.getValu...
@Test public void testEquals() { final UUID id = new UUID(0, 1); final Instant start = Instant.now().minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final DateRange range = new DateRange(start, end); final List<String> drivers = Arrays.asList("Test1", "Test2", "Test3"); final ValueGroup va...
ValueGroupChange { @Override public int hashCode() { return this.type.hashCode() + this.valueGroup.hashCode(); } ValueGroupChange(final Type type, final ValueGroup valueGroup); Type getType(); ValueGroup getValueGroup(); @Override boolean equals(final Object other); @Override int hashCode(); }
@Test public void hashCodeCorrect() { final UUID id = new UUID(0, 1); final Instant start = Instant.now().minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final DateRange range = new DateRange(start, end); final List<String> drivers = Arrays.asList("Test1", "Test2", "Test3"); final ValueGro...
RuleChange { @Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } final RuleChange otherChange = (RuleChange) other; return this.type == otherChange.getType() && this.getRule().equals(otherChange.getRule());...
@Test public void equalsCorrect() { final Instant start = Instant.now().minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3"); final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result"); fina...
RuleChange { @Override public int hashCode() { return this.type.hashCode() + this.rule.hashCode(); } RuleChange(final Type type, final DecisionTreeRule rule); Type getType(); DecisionTreeRule getRule(); @Override boolean equals(final Object other); @Override int hashCode(); }
@Test public void hashCodeCorrect() { final Instant start = Instant.now().minus(Period.ofWeeks(-1)); final Instant end = start.plus(Period.ofWeeks(5)); final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3"); final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result"); fi...
JsonJacksonParser implements RuleBuilderParser { @Override public DecisionTreeRuleSet parseRuleSet(final InputStream inputStream) { return EhSupport.propagateFn(() -> { try (final JsonParser parser = new JsonFactory().createParser(inputStream)) { EhSupport.ensureArg(parser.nextToken() == JsonToken.START_OBJECT, "InputS...
@Test(expected = IllegalArgumentException.class) public void testInvalidJson() { final String invalidJsonStr = " \"name\": \"FNC_CALCULATION_METHOD_RULESET\",\n" + " \"drivers\": [\n" + " \"CALCULATION_METHOD_NAME\"\n" + " ],\n"; new JsonJacksonParser().parseRuleSet(new ByteArrayInputStream(invalidJsonStr.getBytes(Stan...
ChangeBuilder { public static Builder<ChangeBuilder, Change> creator(final DecisionTreeRuleSet ruleSet) { return Builder.instanceOf(ChangeBuilder.create(ruleSet), ChangeBuilder.validate(), ChangeBuilder::builds); } private ChangeBuilder(final DecisionTreeRuleSet ruleSet); static Builder<ChangeBuilder, Change> creator(...
@Test public void noRuleSet() { final Builder<ChangeBuilder, Change> builder = ChangeBuilder.creator(null); assertNull(builder.build()); } @Test public void createsChangeWithId() { final Builder<ChangeBuilder, Change> builder = ChangeBuilder.creator(this.ruleSet); final UUID changeId = UUID.randomUUID(); builder.with(C...
RuleGroupChangeBuilder extends BaseBuilder<RuleChange, DecisionTreeRule> { public static Builder<RuleGroupChangeBuilder, List<RuleChange>> creator(final List<ValueGroupChange> groupChanges, final DecisionTreeRuleSet ruleSet) { return Builder.instanceOf(RuleGroupChangeBuilder.create(groupChanges, ruleSet), RuleGroupChan...
@Test(expected = IllegalArgumentException.class) public void failsWithNoValueGroupChanges() { this.builder = RuleGroupChangeBuilder.creator(emptyList(), this.ruleSet); this.builder.build(); } @Test(expected = IllegalArgumentException.class) public void failsWithNoRuleset() { final List<ValueGroupChange> changes = getVa...
JsonJacksonSerialiser implements RuleBuilderSerialiser { @Override public void serialiseRuleSet(final OutputStream outputStream, final DecisionTreeRuleSet decisionTreeRuleSet) { toJsonWriter(outputStream, decisionTreeRuleSet); } static void toJsonWriter(final OutputStream out, final DecisionTreeRuleSet ruleSet); @Over...
@Test public void testJsonGenerationWithNonUuidValueGroups() throws IOException { final DecisionTreeRuleSet originalRuleSet = CommisionRuleSetSupplier.getCommisionRuleSet().build(); assertNotNull(originalRuleSet); assertNotNull(originalRuleSet.getRules()); assertNotNull(originalRuleSet.getValueGroups()); final ByteArra...
RuleChangeBuilder extends DomainBuilder<RuleChange, DecisionTreeRule> { public static Builder<RuleChangeBuilder, List<RuleChange>> creator(final UUID ruleCode) { return Builder.instanceOf(RuleChangeBuilder.create(ruleCode), RuleChangeBuilder.validate(), RuleChangeBuilder::builds); } private RuleChangeBuilder(final UUI...
@Test public void createsNewRule() { final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = getRuleSetBuilder(); final DriverCache cache = new DriverCache(); final Set<ValueGroup> groups = ConcurrentHashMap.newKeySet(); final ValueGroup group = new ValueGroup("CMEGroup", Arrays.asList("CME", "CBOT")); grou...
ChangeSetBuilder { public static Builder<ChangeSetBuilder, ChangeSet> creator(final String name) { return Builder.instanceOf(ChangeSetBuilder.create(name), ChangeSetBuilder.validate(), ChangeSetBuilder::builds); } private ChangeSetBuilder(final String name); static Builder<ChangeSetBuilder, ChangeSet> creator(final St...
@Test(expected = IllegalArgumentException.class) public void cannotBuildWithoutName() { final Builder<ChangeSetBuilder, ChangeSet> builder = ChangeSetBuilder.creator(null); builder.build(); } @Test(expected = IllegalArgumentException.class) public void cannotBuildWithBlankName() { final Builder<ChangeSetBuilder, Change...
RollbackChangeBuilder { public static Builder<RollbackChangeBuilder, Change> creator() { return Builder.instanceOf(RollbackChangeBuilder.create(), RollbackChangeBuilder.validate(), RollbackChangeBuilder::builds); } static Builder<RollbackChangeBuilder, Change> creator(); RollbackChangeBuilder change(final Change chang...
@Test public void noChangeInformation() { final Builder<RollbackChangeBuilder, Change> builder = RollbackChangeBuilder.creator(); assertNull(builder.build()); }
ValueGroupChangeBuilder extends DomainBuilder<ValueGroupChange, ValueGroup> { public static Builder<ValueGroupChangeBuilder, List<ValueGroupChange>> creator(final String valueGroupName) { return Builder.instanceOf(ValueGroupChangeBuilder.create(valueGroupName), ValueGroupChangeBuilder::builds); } private ValueGroupCha...
@Test(expected = IllegalArgumentException.class) public void nullNameProvided() { builder = ValueGroupChangeBuilder.creator(null); builder.build(); } @Test(expected = IllegalArgumentException.class) public void blankNameProvided() { builder = ValueGroupChangeBuilder.creator(" "); builder.build(); } @Test(expected = Ill...
ValueGroupChangeBuilder extends DomainBuilder<ValueGroupChange, ValueGroup> { private ValueGroup getValueGroup(final ValueGroupChangeBuilder builder, final UUID id, final String name, final List<String> values, final DateRange range) { final ValueGroup group = new ValueGroup(id, name, values, range); if (builder.driver...
@Test public void createsNewChange() { builder.with(ValueGroupChangeBuilder::drivers, Arrays.asList("Test1", "Test2", "Test4")); builder.with(ValueGroupChangeBuilder::changeRange, new DateRange(NOW, NOW.plus(Period.ofWeeks(1)))); builder.with(ValueGroupChangeBuilder::driver, "TestDriver"); final UUID id = UUID.randomUU...
Audit { @Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } final Audit audit = (Audit) other; return Objects.equals(this.initiator, audit.getInitiator()) && Objects.equals(this.initiatorTime, audit.getInit...
@Test public void equalsCorrect() { final Instant now = Instant.now(); final Audit audit = new Audit("USER1", now, "USER2", now); assertTrue(audit.equals(audit)); assertFalse(audit.equals(null)); assertFalse(audit.equals(Boolean.TRUE)); Audit other = new Audit("USER1", now, "USER2", now); assertTrue(audit.equals(other)...
Audit { @Override public int hashCode() { return Objects.hashCode(this.initiator) + Objects.hashCode(this.initiatorTime) + Objects.hashCode(this.authoriser) + Objects.hashCode(this.authoriserTime); } Audit(final String initiator, final Instant initiatorTime, final String authoriser, ...
@Test public void hashCodeCorrect() { final Instant now = Instant.now(); final Audit audit = new Audit("USER1", now, "USER2", now); final Audit other = new Audit("USER1", now, "USER2", now); assertEquals(audit.hashCode(), other.hashCode()); }
ChangeApplier { public static void apply(final DecisionTreeRuleSet ruleSet, final Change change) { ruleSet.updateRules(change); } private ChangeApplier(); static void apply(final DecisionTreeRuleSet ruleSet, final Change change); }
@Test public void testAppliesChangeToRuleSet() { final DecisionTreeRuleSet ruleSet = mock(DecisionTreeRuleSet.class); final Change change = mock(Change.class); ChangeApplier.apply(ruleSet, change); verify(ruleSet).updateRules(change); }
ChangeableDecisionTree extends DecisionTree { public static ChangeableDecisionTree instanceOf(final Loader<DecisionTreeRuleSet> loader, final DecisionTreeType type, final Persister persister) { final ActionRetrier<DecisionTreeRuleSet> retrier = Retrier.createNonRetrier(); final Result<DecisionTreeRuleSet> result = retr...
@Test public void testDecisionTreeEvaluation() { final DecisionTree decisionTree = ChangeableDecisionTree.instanceOf(new CommisionRuleSetSupplier(), DecisionTreeType.SINGLE); assertNotNull(decisionTree); final Input input = decisionTree.createInputs("VOICE", "CME", "ED", "US", "RATE"); final Optional<OutputResults> res...
Evaluator { public static Optional<UUID> singleEvaluate(final List<String> searchInputs, final Instant time, final TreeNode rootNode) { final List<UUID> results = evaluate(searchInputs, time, Collections.emptyList(), rootNode); if (results.isEmpty()) { return Optional.empty(); } return Optional.of(results.get(0)); } pr...
@Test public void testSimpleEvaluatorWithAllInputs() { final DecisionTreeRuleSet ruleSet = CommisionRuleSetSupplier.getCommisionRuleSet().build(); final TreeNode node = constructTree(ruleSet); Optional<UUID> result = Evaluator.singleEvaluate(Arrays.asList("VOICE", "CME", "ED", "US", "RATE"), null, node); assertTrue(res...
Evaluator { public static List<EvaluationResult> evaluateAllResultsWithWildcards(final List<String> searchInputs, final Instant time, final TreeNode rootNode) { final List<TreeNode> nextNodes = rootNode.getEvaluatedNodesWithWildcards(searchInputs, time); final List<EvaluationResult> results = new ArrayList<>(1); for (f...
@Test public void testEvaluatorWithRegexMultipleRulesAndWildcards() { final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex(); final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build(); final TreeNode node = constructTree(ruleSet); final List<Evaluat...
StreamLoader implements Loader<DecisionTreeRuleSet>, AutoCloseable { public static StreamLoader jsonLoader(final InputStream json, final RuleBuilderParser parser) { return new StreamLoader(json, parser); } private StreamLoader(final InputStream stream, final RuleBuilderParser parser); static StreamLoader jsonLoader(fi...
@Test public void nullInputStream() { String message = null; try { StreamLoader.jsonLoader(null, parser); } catch (final Exception exception) { message = exception.getMessage(); } assertEquals("ruleset input stream is null.", message); }