ProductInventoryMapper extends Mapper<NullWritable, NullWritable, Text /*product name*/, Text /*inventory entry CSV*/> { static boolean isWholeLineSuspect(int[] invalidFlags, int[] suspectFlags) { int state = 0; for (int i = 0; i < invalidFlags.length; i++) { boolean isInvalid = invalidFlags[i] != 0; boolean isSuspect = suspectFlags[i] != 0; if ((state == 0 || state == 1) && isInvalid && !isSuspect) { state = 1; } else if ((state == 1 || state == 2) && !isInvalid && isSuspect) { state = 2; } else if (state == 3 && i == (invalidFlags.length-1)) { return true; } else if ((state == 2 || state == 3) && isInvalid && !isSuspect) { state = 3; } else { return false; } } return false; }  @Override void run(Context context); static BandMathsOp createBooleanExpressionBand(String expression, Product sourceProduct);  }
@Test public void testIsWholeLineSuspect() throws Exception { int[] invalidFlags = new int[]{1, 1, 1, 0, 0, 0, 1, 1, 1}; int[] suspectFlags = new int[]{0, 0, 0, 1, 1, 1, 0, 0, 0}; assertTrue(ProductInventoryMapper.isWholeLineSuspect(invalidFlags, suspectFlags)); assertFalse(ProductInventoryMapper.isWholeLineSuspect(invalidFlags, new int[]{0, 0, 0, 0, 1, 1, 0, 0, 0})); assertFalse(ProductInventoryMapper.isWholeLineSuspect(invalidFlags, new int[]{0, 0, 0, 1, 1, 0, 0, 0, 0})); assertFalse(ProductInventoryMapper.isWholeLineSuspect(invalidFlags, new int[]{0, 0, 0, 0, 1, 0, 0, 0, 0})); assertFalse(ProductInventoryMapper.isWholeLineSuspect(invalidFlags, new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0})); assertFalse(ProductInventoryMapper.isWholeLineSuspect(invalidFlags, new int[]{1, 0, 0, 1, 1, 1, 0, 0, 0})); }