@Test public void testCompatibilitySinglesUnit() { Assert.assertTrue(codec.areOutcomesCompatible(new String[] {B_UNIT})); Assert.assertTrue(codec.areOutcomesCompatible(new String[] {A_UNIT, B_UNIT})); Assert.assertTrue(codec.areOutcomesCompatible(new String[] {A_START, A_LAST, B_UNIT})); }
@Override public boolean areOutcomesCompatible(String[] outcomes) { Set<String> start = new HashSet<>(); Set<String> cont = new HashSet<>(); Set<String> last = new HashSet<>(); Set<String> unit = new HashSet<>(); for (int i = 0; i < outcomes.length; i++) { String outcome = outcomes[i]; if (outcome.endsWith(BilouCodec.START)) { start.add(outcome.substring(0, outcome.length() - BilouCodec.START.length())); } else if (outcome.endsWith(BilouCodec.CONTINUE)) { cont.add(outcome.substring(0, outcome.length() - BilouCodec.CONTINUE.length())); } else if (outcome.endsWith(BilouCodec.LAST)) { last.add(outcome.substring(0, outcome.length() - BilouCodec.LAST.length())); } else if (outcome.endsWith(BilouCodec.UNIT)) { unit.add(outcome.substring(0, outcome.length() - BilouCodec.UNIT.length())); } else if (!outcome.equals(BilouCodec.OTHER)) { return false; } } if (start.size() == 0 && unit.size() == 0) { return false; } else { for (String startPrefix : start) { if (!last.contains(startPrefix)) { return false; } } for (String contPrefix : cont) { if (!start.contains(contPrefix) && !last.contains(contPrefix)) { return false; } } for (String lastPrefix : last) { if (!start.contains(lastPrefix)) { return false; } } } return true; }
BilouCodec implements SequenceCodec<String> { @Override public boolean areOutcomesCompatible(String[] outcomes) { Set<String> start = new HashSet<>(); Set<String> cont = new HashSet<>(); Set<String> last = new HashSet<>(); Set<String> unit = new HashSet<>(); for (int i = 0; i < outcomes.length; i++) { String outcome = outcomes[i]; if (outcome.endsWith(BilouCodec.START)) { start.add(outcome.substring(0, outcome.length() - BilouCodec.START.length())); } else if (outcome.endsWith(BilouCodec.CONTINUE)) { cont.add(outcome.substring(0, outcome.length() - BilouCodec.CONTINUE.length())); } else if (outcome.endsWith(BilouCodec.LAST)) { last.add(outcome.substring(0, outcome.length() - BilouCodec.LAST.length())); } else if (outcome.endsWith(BilouCodec.UNIT)) { unit.add(outcome.substring(0, outcome.length() - BilouCodec.UNIT.length())); } else if (!outcome.equals(BilouCodec.OTHER)) { return false; } } if (start.size() == 0 && unit.size() == 0) { return false; } else { for (String startPrefix : start) { if (!last.contains(startPrefix)) { return false; } } for (String contPrefix : cont) { if (!start.contains(contPrefix) && !last.contains(contPrefix)) { return false; } } for (String lastPrefix : last) { if (!start.contains(lastPrefix)) { return false; } } } return true; } }
BilouCodec implements SequenceCodec<String> { @Override public boolean areOutcomesCompatible(String[] outcomes) { Set<String> start = new HashSet<>(); Set<String> cont = new HashSet<>(); Set<String> last = new HashSet<>(); Set<String> unit = new HashSet<>(); for (int i = 0; i < outcomes.length; i++) { String outcome = outcomes[i]; if (outcome.endsWith(BilouCodec.START)) { start.add(outcome.substring(0, outcome.length() - BilouCodec.START.length())); } else if (outcome.endsWith(BilouCodec.CONTINUE)) { cont.add(outcome.substring(0, outcome.length() - BilouCodec.CONTINUE.length())); } else if (outcome.endsWith(BilouCodec.LAST)) { last.add(outcome.substring(0, outcome.length() - BilouCodec.LAST.length())); } else if (outcome.endsWith(BilouCodec.UNIT)) { unit.add(outcome.substring(0, outcome.length() - BilouCodec.UNIT.length())); } else if (!outcome.equals(BilouCodec.OTHER)) { return false; } } if (start.size() == 0 && unit.size() == 0) { return false; } else { for (String startPrefix : start) { if (!last.contains(startPrefix)) { return false; } } for (String contPrefix : cont) { if (!start.contains(contPrefix) && !last.contains(contPrefix)) { return false; } } for (String lastPrefix : last) { if (!start.contains(lastPrefix)) { return false; } } } return true; }  }
BilouCodec implements SequenceCodec<String> { @Override public boolean areOutcomesCompatible(String[] outcomes) { Set<String> start = new HashSet<>(); Set<String> cont = new HashSet<>(); Set<String> last = new HashSet<>(); Set<String> unit = new HashSet<>(); for (int i = 0; i < outcomes.length; i++) { String outcome = outcomes[i]; if (outcome.endsWith(BilouCodec.START)) { start.add(outcome.substring(0, outcome.length() - BilouCodec.START.length())); } else if (outcome.endsWith(BilouCodec.CONTINUE)) { cont.add(outcome.substring(0, outcome.length() - BilouCodec.CONTINUE.length())); } else if (outcome.endsWith(BilouCodec.LAST)) { last.add(outcome.substring(0, outcome.length() - BilouCodec.LAST.length())); } else if (outcome.endsWith(BilouCodec.UNIT)) { unit.add(outcome.substring(0, outcome.length() - BilouCodec.UNIT.length())); } else if (!outcome.equals(BilouCodec.OTHER)) { return false; } } if (start.size() == 0 && unit.size() == 0) { return false; } else { for (String startPrefix : start) { if (!last.contains(startPrefix)) { return false; } } for (String contPrefix : cont) { if (!start.contains(contPrefix) && !last.contains(contPrefix)) { return false; } } for (String lastPrefix : last) { if (!start.contains(lastPrefix)) { return false; } } } return true; }  @Override Span[] decode(List<String> c); @Override String[] encode(Span[] names, int length); @Override SequenceValidator<String> createSequenceValidator(); @Override boolean areOutcomesCompatible(String[] outcomes); }
BilouCodec implements SequenceCodec<String> { @Override public boolean areOutcomesCompatible(String[] outcomes) { Set<String> start = new HashSet<>(); Set<String> cont = new HashSet<>(); Set<String> last = new HashSet<>(); Set<String> unit = new HashSet<>(); for (int i = 0; i < outcomes.length; i++) { String outcome = outcomes[i]; if (outcome.endsWith(BilouCodec.START)) { start.add(outcome.substring(0, outcome.length() - BilouCodec.START.length())); } else if (outcome.endsWith(BilouCodec.CONTINUE)) { cont.add(outcome.substring(0, outcome.length() - BilouCodec.CONTINUE.length())); } else if (outcome.endsWith(BilouCodec.LAST)) { last.add(outcome.substring(0, outcome.length() - BilouCodec.LAST.length())); } else if (outcome.endsWith(BilouCodec.UNIT)) { unit.add(outcome.substring(0, outcome.length() - BilouCodec.UNIT.length())); } else if (!outcome.equals(BilouCodec.OTHER)) { return false; } } if (start.size() == 0 && unit.size() == 0) { return false; } else { for (String startPrefix : start) { if (!last.contains(startPrefix)) { return false; } } for (String contPrefix : cont) { if (!start.contains(contPrefix) && !last.contains(contPrefix)) { return false; } } for (String lastPrefix : last) { if (!start.contains(lastPrefix)) { return false; } } } return true; }  @Override Span[] decode(List<String> c); @Override String[] encode(Span[] names, int length); @Override SequenceValidator<String> createSequenceValidator(); @Override boolean areOutcomesCompatible(String[] outcomes); static final String START; static final String CONTINUE; static final String LAST; static final String UNIT; static final String OTHER; }