target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void test1() { String input = "(1+0*1)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test3() { String input = "0"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",0, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void test4() { String input = "0 * 1 * 1"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",0, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void test5() { String input = "(1+0)"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",1, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void test6() { String input = "!0 * 0 + 1"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",1, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void test7() { String input = "(0+1) * (1+0)"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",1, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void test8() { String input = "((0+0+(1+!1+!(0 + !(0*1+0*1*1+1*0)+1)+0*1)+1*0*0)+0*1)"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",1, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void testTooManyInAFamily() { String names = "A Smith, B Smith, C Smith, D Andersen, E Andersen"; String[] nameList = names.split(","); SecretSantaFinder ssf = new SecretSantaFinder(nameList); assertEquals(ssf.pair(), null); }
public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } SecretSantaFinder(String[] lists); }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } SecretSantaFinder(String[] lists); Map<String, String> pair(); static void main(String[] args); }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } SecretSantaFinder(String[] lists); Map<String, String> pair(); static void main(String[] args); }
@Test public void testUnique() { String names = "A Smith, B Smith, C Smith, D Andersen, E Andersen,F Andersen, G Jackson"; String[] nameList = names.split(","); SecretSantaFinder ssf = new SecretSantaFinder(nameList); Map<String,String> pairs = ssf.pair(); assertEquals(pairs.size(), 7); for(String key: pairs.keySet()) { assertFalse(key.equals(pairs.get(key))); String[] giver = key.split(" "); String[] receiver = pairs.get(key).split(" "); assertFalse(giver[1].equals(receiver[1])); } }
public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } SecretSantaFinder(String[] lists); }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } SecretSantaFinder(String[] lists); Map<String, String> pair(); static void main(String[] args); }
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(totalNames); List<String> sendList = new ArrayList<String>(totalNames); List<String> largestFamilyMembers = new ArrayList<String>(); Map<String, String> secretList = new HashMap<String,String>(); for(int i=0;i < families.size();i++) { List<String> names = families.get(i).members; receiveList.addAll(names); if(i== 0) { largestFamilyMembers = names; } else { sendList.addAll(names); } } sendList.addAll(largestFamilyMembers); for(int i=0;i < sendList.size();i++) { secretList.put(sendList.get(i), receiveList.get(i)); } return secretList; } SecretSantaFinder(String[] lists); Map<String, String> pair(); static void main(String[] args); }
@Test public void testOneCyclicPair() { String[] input = {"abc","acb", "cab"}; CyclicWordsKata tester = new CyclicWordsKata(input); List<List<String>> results = tester.process(); assertEquals("Result", 2, results.size()); }
public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } CyclicWordsKata(String[] input); }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } CyclicWordsKata(String[] input); List<List<String>> process(); Map<Integer,List<String>> separateInputBySize(String[] input); String joinStringArray(List<String> arrayList, String connector); static void main(String[] args); }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } CyclicWordsKata(String[] input); List<List<String>> process(); Map<Integer,List<String>> separateInputBySize(String[] input); String joinStringArray(List<String> arrayList, String connector); static void main(String[] args); }
@Test public void testNull() { String[] input = null; CyclicWordsKata tester = new CyclicWordsKata(input); List<List<String>> results = tester.process(); assertNull("results", results); }
public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } CyclicWordsKata(String[] input); }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } CyclicWordsKata(String[] input); List<List<String>> process(); Map<Integer,List<String>> separateInputBySize(String[] input); String joinStringArray(List<String> arrayList, String connector); static void main(String[] args); }
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements = buckets.get(size); System.out.println("size " + size); while(elements != null && elements.size() > 0) { returnArray = processSameSizeArray(elements); elements = returnArray.get(1) ; processed.add(returnArray.get(0)); } } return processed; } CyclicWordsKata(String[] input); List<List<String>> process(); Map<Integer,List<String>> separateInputBySize(String[] input); String joinStringArray(List<String> arrayList, String connector); static void main(String[] args); }
@Test public void test2() { String input = "(!0)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test1() { int input = 1879; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = tester.parse(); assertEquals("Result","MDCCCLXXIX", testResults ); }
public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
@Test public void test2() { int input = 1; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = tester.parse(); assertEquals("Result","I", testResults ); }
public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
@Test public void test3() { int input = 2010; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = tester.parse(); assertEquals("Result","MMX", testResults ); }
public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
@Test public void test4() { int input = 47; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = tester.parse(); assertEquals("Result","XLVII", testResults ); }
public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
@Test public void test5() { int input = 3888; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = tester.parse(); assertEquals("Result","MMMDCCCLXXXVIII", testResults ); }
public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } returnValue = prefix + parseUnder1000(_input) + suffix + returnValue; returnValue = returnValue.replaceAll("\\(I\\)", "M"); returnValue = returnValue.replaceAll("\\(II\\)", "MM"); returnValue = returnValue.replaceAll("\\(III\\)", "MMM"); return returnValue; } ParseRomanNumerals(int input); String parse(); static void main(String[] args); }
@Test public void test1 () { StateMachine fsm = new StateMachine("0,1", "EVEN:pass,ODD:fail,BAD:fail", "EVEN:ODD:1,ODD:EVEN:1,ODD:BAD:0"); assertEquals("pass", fsm.execute("00110")); assertEquals("fail", fsm.execute("00111")); assertEquals("fail", fsm.execute("001110000110011")); assertEquals("fail", null,fsm.execute("0011100001130011")); }
public String execute(String input) { String startState = entryState; for(int i = 0; i < input.length();i++){ char event = input.charAt(i) ; if(_symbols.indexOf(event) < 0) { return null; } String key = startState + "_" + event; if (endStates.containsKey(key)) { startState = endStates.get(key); } } if (states.containsKey(startState)) { return states.get(startState); } return null; }
StateMachine { public String execute(String input) { String startState = entryState; for(int i = 0; i < input.length();i++){ char event = input.charAt(i) ; if(_symbols.indexOf(event) < 0) { return null; } String key = startState + "_" + event; if (endStates.containsKey(key)) { startState = endStates.get(key); } } if (states.containsKey(startState)) { return states.get(startState); } return null; } }
StateMachine { public String execute(String input) { String startState = entryState; for(int i = 0; i < input.length();i++){ char event = input.charAt(i) ; if(_symbols.indexOf(event) < 0) { return null; } String key = startState + "_" + event; if (endStates.containsKey(key)) { startState = endStates.get(key); } } if (states.containsKey(startState)) { return states.get(startState); } return null; } StateMachine(String symbols, String statesIn, String transitions); }
StateMachine { public String execute(String input) { String startState = entryState; for(int i = 0; i < input.length();i++){ char event = input.charAt(i) ; if(_symbols.indexOf(event) < 0) { return null; } String key = startState + "_" + event; if (endStates.containsKey(key)) { startState = endStates.get(key); } } if (states.containsKey(startState)) { return states.get(startState); } return null; } StateMachine(String symbols, String statesIn, String transitions); String execute(String input); static void main(String[] args); }
StateMachine { public String execute(String input) { String startState = entryState; for(int i = 0; i < input.length();i++){ char event = input.charAt(i) ; if(_symbols.indexOf(event) < 0) { return null; } String key = startState + "_" + event; if (endStates.containsKey(key)) { startState = endStates.get(key); } } if (states.containsKey(startState)) { return states.get(startState); } return null; } StateMachine(String symbols, String statesIn, String transitions); String execute(String input); static void main(String[] args); }
@Test public void test3() { String input = "0"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",0, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test4() { String input = "0 * 1 * 1"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",0, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test5() { String input = "(1+0)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test6() { String input = "!0 * 0 + 1"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test7() { String input = "(0+1) * (1+0)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test8() { String input = "((0+0+(1+!1+!(0 + !(0*1+0*1*1+1*0)+1)+0*1)+1*0*0)+0*1)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
@Test public void test1() { String input = "(1+0*1)"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",1, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test public void test2() { String input = "(!0)"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",1, testResults ); }
public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input); if(m1.find() || m2.find()) { return 1; } Matcher m4 = p4.matcher(_input); String foundInnerLogic; String parsed; while (m4.find()) { foundInnerLogic = m4.group(); if(foundInnerLogic != null){ parsed = parseInnerLogic(foundInnerLogic); String matched = foundInnerLogic; _input = _input.replace(matched, parsed); _input = _input.replace("!0", "1"); _input = _input.replace("!1", "0"); m4 = p4.matcher(_input); } } _input = parseInnerLogic(_input); return Integer.parseInt(_input); } ParseBooleanOriginal(String input); int process(); static void main(String[] args); }
@Test(expected = IllegalArgumentException.class) public void illegalFlagsShouldBeDetected() { ShellMode mode = ShellMode.from("--interactive --foo"); }
public static ShellMode from(String... arguments) { if (runInBatchMode(arguments)) { return new BatchMode(extractCommand(arguments)); } return new InteractiveMode(); }
ShellMode { public static ShellMode from(String... arguments) { if (runInBatchMode(arguments)) { return new BatchMode(extractCommand(arguments)); } return new InteractiveMode(); } }
ShellMode { public static ShellMode from(String... arguments) { if (runInBatchMode(arguments)) { return new BatchMode(extractCommand(arguments)); } return new InteractiveMode(); } }
ShellMode { public static ShellMode from(String... arguments) { if (runInBatchMode(arguments)) { return new BatchMode(extractCommand(arguments)); } return new InteractiveMode(); } static String usage(); static ShellMode from(String... arguments); static ShellMode batch(String command); static ShellMode interactive(); abstract void start(); @Override final boolean equals(Object object); @Override abstract String toString(); }
ShellMode { public static ShellMode from(String... arguments) { if (runInBatchMode(arguments)) { return new BatchMode(extractCommand(arguments)); } return new InteractiveMode(); } static String usage(); static ShellMode from(String... arguments); static ShellMode batch(String command); static ShellMode interactive(); abstract void start(); @Override final boolean equals(Object object); @Override abstract String toString(); }
@Test public void toFileShouldCreateANonEmptyFile() throws FileNotFoundException { final ShellCommand script = script(history(), version(), exit()); final String destination = "test.txt"; script.toFile(destination); File file = new File(destination); assertThat("no file generated!", file.exists()); assertThat("empty file generated!", file.length(), is(greaterThan(0L))); file.delete(); }
public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); @Override void execute(ShellCommandHandler handler); Iterator<ShellCommand> iterator(); @Override int hashCode(); @Override String toString(); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); @Override void execute(ShellCommandHandler handler); Iterator<ShellCommand> iterator(); @Override int hashCode(); @Override String toString(); }
@Test public void generatedScriptsShouldBeReadble() throws Exception { final String destination = "test.txt"; final ShellCommand script = script(history(), version(), exit()); try { script.toFile(destination); final ShellCommand script2 = fromFile(destination); assertThat("Different files", script2, is(equalTo(script))); } catch (Exception e) { throw e; } finally { File file = new File(destination); file.delete(); } }
public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); @Override void execute(ShellCommandHandler handler); Iterator<ShellCommand> iterator(); @Override int hashCode(); @Override String toString(); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); @Override void execute(ShellCommandHandler handler); Iterator<ShellCommand> iterator(); @Override int hashCode(); @Override String toString(); }
@Test public void temporaryAuthToken() throws Exception { SessionManager mockManager = mock(SessionManager.class); when(mockManager.storeNewTempToken()).thenReturn("dummyToken"); AuthResource resource = new AuthResource(mockManager, null, "localhost"); TempTokenResponse response = resource.temporaryAuthToken("doc"); assertNotNull(response.token); assertEquals("xanauth: }
public TempTokenResponse temporaryAuthToken(String scope) throws StorageException, UnsupportedEncodingException { if (Strings.isNullOrEmpty(scope)) { scope = "all"; } String tempToken = sessionManager.storeNewTempToken(); String xanauthURL = "xanauth: + URLEncoder.encode(scope, "UTF-8"); TempTokenResponse tempTokenResponse = new TempTokenResponse(); tempTokenResponse.xanauth = xanauthURL; tempTokenResponse.token = tempToken; return tempTokenResponse; }
AuthResource { public TempTokenResponse temporaryAuthToken(String scope) throws StorageException, UnsupportedEncodingException { if (Strings.isNullOrEmpty(scope)) { scope = "all"; } String tempToken = sessionManager.storeNewTempToken(); String xanauthURL = "xanauth: + URLEncoder.encode(scope, "UTF-8"); TempTokenResponse tempTokenResponse = new TempTokenResponse(); tempTokenResponse.xanauth = xanauthURL; tempTokenResponse.token = tempToken; return tempTokenResponse; } }
AuthResource { public TempTokenResponse temporaryAuthToken(String scope) throws StorageException, UnsupportedEncodingException { if (Strings.isNullOrEmpty(scope)) { scope = "all"; } String tempToken = sessionManager.storeNewTempToken(); String xanauthURL = "xanauth: + URLEncoder.encode(scope, "UTF-8"); TempTokenResponse tempTokenResponse = new TempTokenResponse(); tempTokenResponse.xanauth = xanauthURL; tempTokenResponse.token = tempToken; return tempTokenResponse; } AuthResource(SessionManager sessionManager, ObjectMapper mapper, String host); }
AuthResource { public TempTokenResponse temporaryAuthToken(String scope) throws StorageException, UnsupportedEncodingException { if (Strings.isNullOrEmpty(scope)) { scope = "all"; } String tempToken = sessionManager.storeNewTempToken(); String xanauthURL = "xanauth: + URLEncoder.encode(scope, "UTF-8"); TempTokenResponse tempTokenResponse = new TempTokenResponse(); tempTokenResponse.xanauth = xanauthURL; tempTokenResponse.token = tempToken; return tempTokenResponse; } AuthResource(SessionManager sessionManager, ObjectMapper mapper, String host); SessionResponse getSessionToken(String header64, String claim64, String sig64); TempTokenResponse temporaryAuthToken(String scope); }
AuthResource { public TempTokenResponse temporaryAuthToken(String scope) throws StorageException, UnsupportedEncodingException { if (Strings.isNullOrEmpty(scope)) { scope = "all"; } String tempToken = sessionManager.storeNewTempToken(); String xanauthURL = "xanauth: + URLEncoder.encode(scope, "UTF-8"); TempTokenResponse tempTokenResponse = new TempTokenResponse(); tempTokenResponse.xanauth = xanauthURL; tempTokenResponse.token = tempToken; return tempTokenResponse; } AuthResource(SessionManager sessionManager, ObjectMapper mapper, String host); SessionResponse getSessionToken(String header64, String claim64, String sig64); TempTokenResponse temporaryAuthToken(String scope); }
@Test public void addWeightsOfRightLeaningChildNodesNoChildren() throws Exception { Node<InvariantSpan> x = new Node<>(new InvariantSpan(1, 1, documentHash)); assertEquals(0, RopeUtils.addWeightsOfRightLeaningChildNodes(x)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void addWeightsOfRightLeaningChildNodesNullNode() throws Exception { assertEquals(0, RopeUtils.addWeightsOfRightLeaningChildNodes(null)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void addWeightsOfRightLeaningChildNodesSimple() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> x = new Node.Builder<InvariantSpan>(0).right(right).build(); assertEquals(10, RopeUtils.addWeightsOfRightLeaningChildNodes(x)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void addWeightsOfRightLeaningParentNodesChainedRight() throws Exception { Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(1, 3, documentHash)); Node<InvariantSpan> right = new Node.Builder<InvariantSpan>(1).right(right2).build(); new Node.Builder<InvariantSpan>(1).right(right).build(); assertEquals(2, RopeUtils.addWeightsOfRightLeaningParentNodes(right2)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void addWeightsOfRightLeaningParentNodesLeftNodeChild() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); new Node.Builder<InvariantSpan>(1).left(left).build(); assertEquals(0, RopeUtils.addWeightsOfRightLeaningParentNodes(left)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test(expected = IllegalStateException.class) public void addWeightsOfRightLeaningParentNodesNull() throws Exception { RopeUtils.addWeightsOfRightLeaningParentNodes(null); }
public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void addWeightsOfRightLeaningParentNodesNullParent() throws Exception { Node<InvariantSpan> x = new Node<>(new InvariantSpan(1, 1, documentHash)); assertEquals(0, RopeUtils.addWeightsOfRightLeaningParentNodes(x)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void addWeightsOfRightLeaningParentNodesRightNodeChild() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 1, documentHash)); new Node.Builder<InvariantSpan>(1).right(right).build(); assertEquals(1, RopeUtils.addWeightsOfRightLeaningParentNodes(right)); }
public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParentNodes(child.parent); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void characterCount() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(1, 20, documentHash)); right.right = right2; Node<InvariantSpan> x = new Node.Builder<InvariantSpan>(10).right(right).build(); assertEquals(40, RopeUtils.characterCount(x)); }
public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void characterCountLeafNode() throws Exception { assertEquals(3, RopeUtils.characterCount(new Node<>(new InvariantSpan(1, 3, documentHash)))); }
public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void equalsTrue() throws Exception { ApplyOverlayOp op1 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); ApplyOverlayOp op2 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); assertTrue(op1.equals(op2)); assertTrue(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final Set<Integer> linkTypes; final VariantSpan variantSpan; }
@Test public void characterCountNullNode() throws Exception { assertEquals(0, RopeUtils.characterCount(null)); }
public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void concatLeft() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> parent = RopeUtils.concat(left, null); assertEquals(10, parent.weight); assertNotNull(left.parent); }
public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void concatNullLeftNullRight() throws Exception { assertEquals(0, RopeUtils.concat(null, null).weight); }
public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void concatRight() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> parent = RopeUtils.concat(null, right); assertEquals(0, parent.weight); assertNotNull(right.parent); }
public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void findSearchNode() throws Exception { }
public static <T extends StreamElement> Node<T> findSearchNode(Node<T> x, long weight, Node<T> root) { if (root == null) { throw new IllegalArgumentException("root is null"); } if (x == null) { return root; } if (x.weight > weight) { return x; } return findSearchNode(x.parent, weight, root); }
RopeUtils { public static <T extends StreamElement> Node<T> findSearchNode(Node<T> x, long weight, Node<T> root) { if (root == null) { throw new IllegalArgumentException("root is null"); } if (x == null) { return root; } if (x.weight > weight) { return x; } return findSearchNode(x.parent, weight, root); } }
RopeUtils { public static <T extends StreamElement> Node<T> findSearchNode(Node<T> x, long weight, Node<T> root) { if (root == null) { throw new IllegalArgumentException("root is null"); } if (x == null) { return root; } if (x.weight > weight) { return x; } return findSearchNode(x.parent, weight, root); } }
RopeUtils { public static <T extends StreamElement> Node<T> findSearchNode(Node<T> x, long weight, Node<T> root) { if (root == null) { throw new IllegalArgumentException("root is null"); } if (x == null) { return root; } if (x.weight > weight) { return x; } return findSearchNode(x.parent, weight, root); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> Node<T> findSearchNode(Node<T> x, long weight, Node<T> root) { if (root == null) { throw new IllegalArgumentException("root is null"); } if (x == null) { return root; } if (x.weight > weight) { return x; } return findSearchNode(x.parent, weight, root); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexDisplacement() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(2, 3, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(1).left(left).right(right).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(2, root, 0); assertEquals(1, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexLeft() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(5, root, 0); assertEquals(new InvariantSpan(1, 10, documentHash), index.node.value); assertEquals(0, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexLeftLeftChain() throws Exception { Node<InvariantSpan> left2 = new Node<>(new InvariantSpan(100, 10, documentHash)); Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(200, 5, documentHash)); Node<InvariantSpan> left1 = new Node.Builder<InvariantSpan>(10).left(left2).right(right2).build(); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(15).left(left1).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(10, root, 0); assertEquals(new InvariantSpan(100, 10, documentHash), index.node.value); assertEquals(0, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexLeftLower() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(1, root, 0); assertEquals(new InvariantSpan(1, 10, documentHash), index.node.value); assertEquals(0, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexLeftRightChain() throws Exception { Node<InvariantSpan> left2 = new Node<>(new InvariantSpan(100, 10, documentHash)); Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(200, 5, documentHash)); Node<InvariantSpan> left1 = new Node.Builder<InvariantSpan>(10).left(left2).right(right2).build(); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(15).left(left1).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(11, root, 0); assertEquals(new InvariantSpan(200, 5, documentHash), index.node.value); assertEquals(10, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void equalsVariantsFalse() throws Exception { ApplyOverlayOp op1 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); ApplyOverlayOp op2 = new ApplyOverlayOp(new VariantSpan(2, 100), Sets.newHashSet(1, 10)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final Set<Integer> linkTypes; final VariantSpan variantSpan; }
@Test(expected = IndexOutOfBoundsException.class) public void indexLeftTooHigh() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).build(); RopeUtils.index(11, root, 0); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test(expected = IndexOutOfBoundsException.class) public void indexLeftTooLow() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).build(); RopeUtils.index(0, root, 0); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexLeftUpper() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(10, root, 0); assertEquals(new InvariantSpan(1, 10, documentHash), index.node.value); assertEquals(0, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test(expected = IndexOutOfBoundsException.class) public void indexOutOutBoundsRight() throws Exception { Node<InvariantSpan> left2 = new Node<>(new InvariantSpan(100, 10, documentHash)); Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(200, 5, documentHash)); Node<InvariantSpan> left1 = new Node.Builder<InvariantSpan>(10).left(left2).right(right2).build(); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(15).left(left1).build(); RopeUtils.index(20, root, 0); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void indexRight() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 20, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).right(right).build(); NodeIndex<InvariantSpan> index = RopeUtils.index(15, root, 0); assertEquals(new InvariantSpan(1, 20, documentHash), index.node.value); assertEquals(10, index.displacement); }
public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { return new NodeIndex<T>(x, disp); } if (x.weight < characterPosition) { if (x.right == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } if (x.weight > 0) { disp += x.weight; x.isRed = true; } return index(characterPosition - x.weight, x.right, disp); } else { if (x.left == null) { throw new IndexOutOfBoundsException("Can't find node at position = " + (characterPosition + disp)); } return index(characterPosition, x.left, disp); } } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningParentNodes(Node<T> child); static void adjustWeightOfLeftLeaningParents(Node<T> startNode, long weight); static long characterCount(Node<T> x); static void collectLeafNodes(Node<T> x, Queue<Node<T>> queue); static Node<T> concat(List<Node<T>> orphans); static Node<T> concat(Node<T> left, Node<T> right); static void cutLeftNode(Node<T> x, List<Node<T>> orphans); static void cutRightNode(Node<T> x, List<Node<T>> orphans); static Node<T> findRoot(Node<T> child); static Node<T> findSearchNode(Node<T> x, long weight, Node<T> root); static NodeIndex<T> index(long characterPosition, Node<T> x, long disp); static boolean intersects(long start, long end, long start2, long end2); static Node<T> rebalance(Node<T> x); }
@Test public void append() throws Exception { DefaultOulipoMachine som = DefaultOulipoMachine.createWritableMachine(streamLoader, new MockRemoteFileManager(), documentHash); InvariantSpan span = som.append("Hello"); assertEquals(span.getStart(), 1); assertEquals(span.getWidth(), 5); span = som.append("World"); assertEquals(span.getStart(), 6); assertEquals(span.getWidth(), 5); }
@Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { return iStream.append(text); }
DefaultOulipoMachine implements OulipoMachine { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { return iStream.append(text); } }
DefaultOulipoMachine implements OulipoMachine { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { return iStream.append(text); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); }
DefaultOulipoMachine implements OulipoMachine { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { return iStream.append(text); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachine createWritableMachine(StreamLoader loader, RemoteFileManager remoteFileManager, String documentHash); @Override InvariantSpan append(String text); @Override void applyOverlays(VariantSpan variantSpan, Set<Overlay> links); @Override void copyVariant(long to, VariantSpan variantSpan); @Override void deleteVariant(VariantSpan variantSpan); @Override void flush(); @Override String getDocumentHash(); @Override List<Invariant> getInvariants(); @Override List<Invariant> getInvariants(VariantSpan variantSpan); @Override String getText(InvariantSpan invariantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan invariantSpan); @Override Invariant index(long characterPosition); @Override void insert(long to, String text); @Override void insertEncrypted(long to, String text); @Override void loadDocument(String hash); @Override void moveVariant(long to, VariantSpan variantSpan); @Override void putInvariant(long to, Invariant invariant); @Override void putOverlay(long to, OverlayStream overlayStream); @Override void swapVariants(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay link); }
DefaultOulipoMachine implements OulipoMachine { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { return iStream.append(text); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachine createWritableMachine(StreamLoader loader, RemoteFileManager remoteFileManager, String documentHash); @Override InvariantSpan append(String text); @Override void applyOverlays(VariantSpan variantSpan, Set<Overlay> links); @Override void copyVariant(long to, VariantSpan variantSpan); @Override void deleteVariant(VariantSpan variantSpan); @Override void flush(); @Override String getDocumentHash(); @Override List<Invariant> getInvariants(); @Override List<Invariant> getInvariants(VariantSpan variantSpan); @Override String getText(InvariantSpan invariantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan invariantSpan); @Override Invariant index(long characterPosition); @Override void insert(long to, String text); @Override void insertEncrypted(long to, String text); @Override void loadDocument(String hash); @Override void moveVariant(long to, VariantSpan variantSpan); @Override void putInvariant(long to, Invariant invariant); @Override void putOverlay(long to, OverlayStream overlayStream); @Override void swapVariants(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay link); }
@Test public void getText() throws Exception { DefaultOulipoMachine som = DefaultOulipoMachine.createWritableMachine(streamLoader, new MockRemoteFileManager(), documentHash); som.append("Hello"); som.append("World"); String result = som.getText(new InvariantSpan(5, 5, documentHash)); assertEquals("oWorl", result); }
@Override public String getText(InvariantSpan invariantSpan) throws IOException { assertSpanNotNull(invariantSpan); return iStream.getText(invariantSpan); }
DefaultOulipoMachine implements OulipoMachine { @Override public String getText(InvariantSpan invariantSpan) throws IOException { assertSpanNotNull(invariantSpan); return iStream.getText(invariantSpan); } }
DefaultOulipoMachine implements OulipoMachine { @Override public String getText(InvariantSpan invariantSpan) throws IOException { assertSpanNotNull(invariantSpan); return iStream.getText(invariantSpan); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); }
DefaultOulipoMachine implements OulipoMachine { @Override public String getText(InvariantSpan invariantSpan) throws IOException { assertSpanNotNull(invariantSpan); return iStream.getText(invariantSpan); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachine createWritableMachine(StreamLoader loader, RemoteFileManager remoteFileManager, String documentHash); @Override InvariantSpan append(String text); @Override void applyOverlays(VariantSpan variantSpan, Set<Overlay> links); @Override void copyVariant(long to, VariantSpan variantSpan); @Override void deleteVariant(VariantSpan variantSpan); @Override void flush(); @Override String getDocumentHash(); @Override List<Invariant> getInvariants(); @Override List<Invariant> getInvariants(VariantSpan variantSpan); @Override String getText(InvariantSpan invariantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan invariantSpan); @Override Invariant index(long characterPosition); @Override void insert(long to, String text); @Override void insertEncrypted(long to, String text); @Override void loadDocument(String hash); @Override void moveVariant(long to, VariantSpan variantSpan); @Override void putInvariant(long to, Invariant invariant); @Override void putOverlay(long to, OverlayStream overlayStream); @Override void swapVariants(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay link); }
DefaultOulipoMachine implements OulipoMachine { @Override public String getText(InvariantSpan invariantSpan) throws IOException { assertSpanNotNull(invariantSpan); return iStream.getText(invariantSpan); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachine createWritableMachine(StreamLoader loader, RemoteFileManager remoteFileManager, String documentHash); @Override InvariantSpan append(String text); @Override void applyOverlays(VariantSpan variantSpan, Set<Overlay> links); @Override void copyVariant(long to, VariantSpan variantSpan); @Override void deleteVariant(VariantSpan variantSpan); @Override void flush(); @Override String getDocumentHash(); @Override List<Invariant> getInvariants(); @Override List<Invariant> getInvariants(VariantSpan variantSpan); @Override String getText(InvariantSpan invariantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan invariantSpan); @Override Invariant index(long characterPosition); @Override void insert(long to, String text); @Override void insertEncrypted(long to, String text); @Override void loadDocument(String hash); @Override void moveVariant(long to, VariantSpan variantSpan); @Override void putInvariant(long to, Invariant invariant); @Override void putOverlay(long to, OverlayStream overlayStream); @Override void swapVariants(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay link); }
@Test public void moveVariant() throws Exception { DefaultOulipoMachine machine = DefaultOulipoMachine.createWritableMachine(streamLoader, new MockRemoteFileManager(), documentHash); machine.insert(1, "My first document"); assertEquals("My first document", getText(machine)); machine.moveVariant(1, new VariantSpan(4, 6)); assertEquals("first My document", getText(machine)); }
@Override public void moveVariant(long to, VariantSpan variantSpan) throws MalformedSpanException, IOException { assertGreaterThanZero(to); assertSpanNotNull(variantSpan); vStream.move(to, variantSpan); oStream.move(to, variantSpan); if (writeDocFile) { documentBuilder.moveVariant(to, variantSpan); } }
DefaultOulipoMachine implements OulipoMachine { @Override public void moveVariant(long to, VariantSpan variantSpan) throws MalformedSpanException, IOException { assertGreaterThanZero(to); assertSpanNotNull(variantSpan); vStream.move(to, variantSpan); oStream.move(to, variantSpan); if (writeDocFile) { documentBuilder.moveVariant(to, variantSpan); } } }
DefaultOulipoMachine implements OulipoMachine { @Override public void moveVariant(long to, VariantSpan variantSpan) throws MalformedSpanException, IOException { assertGreaterThanZero(to); assertSpanNotNull(variantSpan); vStream.move(to, variantSpan); oStream.move(to, variantSpan); if (writeDocFile) { documentBuilder.moveVariant(to, variantSpan); } } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); }
DefaultOulipoMachine implements OulipoMachine { @Override public void moveVariant(long to, VariantSpan variantSpan) throws MalformedSpanException, IOException { assertGreaterThanZero(to); assertSpanNotNull(variantSpan); vStream.move(to, variantSpan); oStream.move(to, variantSpan); if (writeDocFile) { documentBuilder.moveVariant(to, variantSpan); } } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachine createWritableMachine(StreamLoader loader, RemoteFileManager remoteFileManager, String documentHash); @Override InvariantSpan append(String text); @Override void applyOverlays(VariantSpan variantSpan, Set<Overlay> links); @Override void copyVariant(long to, VariantSpan variantSpan); @Override void deleteVariant(VariantSpan variantSpan); @Override void flush(); @Override String getDocumentHash(); @Override List<Invariant> getInvariants(); @Override List<Invariant> getInvariants(VariantSpan variantSpan); @Override String getText(InvariantSpan invariantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan invariantSpan); @Override Invariant index(long characterPosition); @Override void insert(long to, String text); @Override void insertEncrypted(long to, String text); @Override void loadDocument(String hash); @Override void moveVariant(long to, VariantSpan variantSpan); @Override void putInvariant(long to, Invariant invariant); @Override void putOverlay(long to, OverlayStream overlayStream); @Override void swapVariants(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay link); }
DefaultOulipoMachine implements OulipoMachine { @Override public void moveVariant(long to, VariantSpan variantSpan) throws MalformedSpanException, IOException { assertGreaterThanZero(to); assertSpanNotNull(variantSpan); vStream.move(to, variantSpan); oStream.move(to, variantSpan); if (writeDocFile) { documentBuilder.moveVariant(to, variantSpan); } } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachine createWritableMachine(StreamLoader loader, RemoteFileManager remoteFileManager, String documentHash); @Override InvariantSpan append(String text); @Override void applyOverlays(VariantSpan variantSpan, Set<Overlay> links); @Override void copyVariant(long to, VariantSpan variantSpan); @Override void deleteVariant(VariantSpan variantSpan); @Override void flush(); @Override String getDocumentHash(); @Override List<Invariant> getInvariants(); @Override List<Invariant> getInvariants(VariantSpan variantSpan); @Override String getText(InvariantSpan invariantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan invariantSpan); @Override Invariant index(long characterPosition); @Override void insert(long to, String text); @Override void insertEncrypted(long to, String text); @Override void loadDocument(String hash); @Override void moveVariant(long to, VariantSpan variantSpan); @Override void putInvariant(long to, Invariant invariant); @Override void putOverlay(long to, OverlayStream overlayStream); @Override void swapVariants(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay link); }
@Test public void hashTrue() throws Exception { ApplyOverlayOp op1 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); ApplyOverlayOp op2 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + linkTypes.hashCode(); result = prime * result + variantSpan.hashCode(); return result; }
ApplyOverlayOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + linkTypes.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } }
ApplyOverlayOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + linkTypes.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); }
ApplyOverlayOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + linkTypes.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
ApplyOverlayOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + linkTypes.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final Set<Integer> linkTypes; final VariantSpan variantSpan; }
@Test public void encodeDecode() throws Exception { SwapVariantOp op = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.SWAP, dis.readByte()); SwapVariantOp decoded = new SwapVariantOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.SWAP); dos.writeLong(v1.start); dos.writeLong(v1.width); dos.writeLong(v2.start); dos.writeLong(v2.width); } os.flush(); return os.toByteArray(); }
SwapVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.SWAP); dos.writeLong(v1.start); dos.writeLong(v1.width); dos.writeLong(v2.start); dos.writeLong(v2.width); } os.flush(); return os.toByteArray(); } }
SwapVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.SWAP); dos.writeLong(v1.start); dos.writeLong(v1.width); dos.writeLong(v2.start); dos.writeLong(v2.width); } os.flush(); return os.toByteArray(); } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); }
SwapVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.SWAP); dos.writeLong(v1.start); dos.writeLong(v1.width); dos.writeLong(v2.start); dos.writeLong(v2.width); } os.flush(); return os.toByteArray(); } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
SwapVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.SWAP); dos.writeLong(v1.start); dos.writeLong(v1.width); dos.writeLong(v2.start); dos.writeLong(v2.width); } os.flush(); return os.toByteArray(); } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan v1; final VariantSpan v2; }
@Test public void equalsFalse() throws Exception { SwapVariantOp op1 = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); SwapVariantOp op2 = new SwapVariantOp(new VariantSpan(100, 10), new VariantSpan(200, 1)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SwapVariantOp other = (SwapVariantOp) obj; if (!v1.equals(other.v1)) return false; if (!v2.equals(other.v2)) return false; return true; }
SwapVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SwapVariantOp other = (SwapVariantOp) obj; if (!v1.equals(other.v1)) return false; if (!v2.equals(other.v2)) return false; return true; } }
SwapVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SwapVariantOp other = (SwapVariantOp) obj; if (!v1.equals(other.v1)) return false; if (!v2.equals(other.v2)) return false; return true; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); }
SwapVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SwapVariantOp other = (SwapVariantOp) obj; if (!v1.equals(other.v1)) return false; if (!v2.equals(other.v2)) return false; return true; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
SwapVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SwapVariantOp other = (SwapVariantOp) obj; if (!v1.equals(other.v1)) return false; if (!v2.equals(other.v2)) return false; return true; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan v1; final VariantSpan v2; }
@Test public void hashFalse() throws Exception { SwapVariantOp op1 = new SwapVariantOp(new VariantSpan(100, 10), new VariantSpan(200, 1)); SwapVariantOp op2 = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan v1; final VariantSpan v2; }
@Test public void hashTrue() throws Exception { SwapVariantOp op1 = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); SwapVariantOp op2 = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan v1; final VariantSpan v2; }
@Test public void encodeDecode() throws Exception { PutOverlayMediaOp op = new PutOverlayMediaOp(1, 1, Sets.newSet(10, 5)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_OVERLAY_MEDIA, dis.readByte()); PutOverlayMediaOp decoded = new PutOverlayMediaOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY_MEDIA); dos.writeLong(to); dos.writeInt(hash); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); }
PutOverlayMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY_MEDIA); dos.writeLong(to); dos.writeInt(hash); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } }
PutOverlayMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY_MEDIA); dos.writeLong(to); dos.writeInt(hash); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); }
PutOverlayMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY_MEDIA); dos.writeLong(to); dos.writeInt(hash); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutOverlayMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY_MEDIA); dos.writeLong(to); dos.writeInt(hash); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int hash; final Set<Integer> linkTypes; final long to; }
@Test public void equalsFalse() throws Exception { PutOverlayMediaOp op1 = new PutOverlayMediaOp(1, 1, Sets.newSet(10, 5)); PutOverlayMediaOp op2 = new PutOverlayMediaOp(2, 1, Sets.newSet(10, 5)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutOverlayMediaOp other = (PutOverlayMediaOp) obj; if (hash != other.hash) return false; if (!linkTypes.equals(other.linkTypes)) return false; if (to != other.to) return false; return true; }
PutOverlayMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutOverlayMediaOp other = (PutOverlayMediaOp) obj; if (hash != other.hash) return false; if (!linkTypes.equals(other.linkTypes)) return false; if (to != other.to) return false; return true; } }
PutOverlayMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutOverlayMediaOp other = (PutOverlayMediaOp) obj; if (hash != other.hash) return false; if (!linkTypes.equals(other.linkTypes)) return false; if (to != other.to) return false; return true; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); }
PutOverlayMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutOverlayMediaOp other = (PutOverlayMediaOp) obj; if (hash != other.hash) return false; if (!linkTypes.equals(other.linkTypes)) return false; if (to != other.to) return false; return true; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutOverlayMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutOverlayMediaOp other = (PutOverlayMediaOp) obj; if (hash != other.hash) return false; if (!linkTypes.equals(other.linkTypes)) return false; if (to != other.to) return false; return true; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int hash; final Set<Integer> linkTypes; final long to; }
@Test public void hashFalse() throws Exception { PutOverlayMediaOp op1 = new PutOverlayMediaOp(1, 1, Sets.newSet(10, 5)); PutOverlayMediaOp op2 = new PutOverlayMediaOp(2, 1, Sets.newSet(10, 5)); assertFalse(op1.hashCode() == op2.hashCode()); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int hash; final Set<Integer> linkTypes; final long to; }
@Test public void delete() throws Exception { TestObject to1 = new TestObject("1", "456"); TestObject to2 = new TestObject("2", "abc"); TestObject to3 = new TestObject("3", "xyz"); service.save(to1); service.save(to2); service.save(to3); service.delete("1", TestObject.class); service.delete("3", TestObject.class); Collection<TestObject> results = service.getAll(TestObject.class); assertEquals(1, results.size()); assertFalse(results.contains(to1)); assertTrue(results.contains(to2)); assertFalse(results.contains(to3)); }
public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } protected StorageService(DB db); StorageService(String name); }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } protected StorageService(DB db); StorageService(String name); void close(); void delete(String id, Class<T> clazz); byte[] get(byte[] key); Collection<T> getAll(Class<T> clazz); T load(String id, Class<T> clazz); void put(byte[] key, byte[] value); void save(Object entity); }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } protected StorageService(DB db); StorageService(String name); void close(); void delete(String id, Class<T> clazz); byte[] get(byte[] key); Collection<T> getAll(Class<T> clazz); T load(String id, Class<T> clazz); void put(byte[] key, byte[] value); void save(Object entity); }
@Test public void hashTrue() throws Exception { PutOverlayMediaOp op1 = new PutOverlayMediaOp(1, 0, Sets.newSet(10, 5)); PutOverlayMediaOp op2 = new PutOverlayMediaOp(1, 0, Sets.newSet(10, 5)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInputStream dis); PutOverlayMediaOp(long to, int hash, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int hash; final Set<Integer> linkTypes; final long to; }
@Test public void encode() throws Exception { DeleteVariantOp op = new DeleteVariantOp(new VariantSpan(1, 100)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.DELETE, dis.read()); assertEquals(1, dis.readLong()); assertEquals(100, dis.readLong()); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.DELETE); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); }
DeleteVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.DELETE); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } }
DeleteVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.DELETE); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); }
DeleteVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.DELETE); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
DeleteVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.DELETE); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan variantSpan; }
@Test public void equalsVariantsFalse() throws Exception { DeleteVariantOp op1 = new DeleteVariantOp(new VariantSpan(1, 100)); DeleteVariantOp op2 = new DeleteVariantOp(new VariantSpan(2, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; DeleteVariantOp other = (DeleteVariantOp) obj; if (!variantSpan.equals(other.variantSpan)) return false; return true; }
DeleteVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; DeleteVariantOp other = (DeleteVariantOp) obj; if (!variantSpan.equals(other.variantSpan)) return false; return true; } }
DeleteVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; DeleteVariantOp other = (DeleteVariantOp) obj; if (!variantSpan.equals(other.variantSpan)) return false; return true; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); }
DeleteVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; DeleteVariantOp other = (DeleteVariantOp) obj; if (!variantSpan.equals(other.variantSpan)) return false; return true; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
DeleteVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; DeleteVariantOp other = (DeleteVariantOp) obj; if (!variantSpan.equals(other.variantSpan)) return false; return true; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan variantSpan; }
@Test public void hashFalse() throws Exception { DeleteVariantOp op1 = new DeleteVariantOp(new VariantSpan(1, 100)); DeleteVariantOp op2 = new DeleteVariantOp(new VariantSpan(2, 100)); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan variantSpan; }
@Test public void hashTrue() throws Exception { DeleteVariantOp op1 = new DeleteVariantOp(new VariantSpan(1, 100)); DeleteVariantOp op2 = new DeleteVariantOp(new VariantSpan(1, 100)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final VariantSpan variantSpan; }
@Test public void encodeDecode() throws Exception { CopyVariantOp op = new CopyVariantOp(100, new VariantSpan(50, 75)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.COPY, dis.readByte()); CopyVariantOp decoded = new CopyVariantOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.COPY); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); }
CopyVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.COPY); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } }
CopyVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.COPY); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); }
CopyVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.COPY); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
CopyVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.COPY); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void equalsPositionsFalse() throws Exception { CopyVariantOp op1 = new CopyVariantOp(1, new VariantSpan(1, 100)); CopyVariantOp op2 = new CopyVariantOp(2, new VariantSpan(1, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void equalsVariantsFalse() throws Exception { CopyVariantOp op1 = new CopyVariantOp(1, new VariantSpan(1, 100)); CopyVariantOp op2 = new CopyVariantOp(1, new VariantSpan(2, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void hashTrue() throws Exception { CopyVariantOp op1 = new CopyVariantOp(1, new VariantSpan(1, 100)); CopyVariantOp op2 = new CopyVariantOp(1, new VariantSpan(1, 100)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; }
CopyVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } }
CopyVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); }
CopyVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
CopyVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void encodeDecode() throws Exception { MoveVariantOp op = new MoveVariantOp(100, new VariantSpan(50, 75)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.MOVE, dis.readByte()); MoveVariantOp decoded = new MoveVariantOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.MOVE); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); }
MoveVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.MOVE); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } }
MoveVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.MOVE); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); }
MoveVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.MOVE); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
MoveVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.MOVE); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteArray(); } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void getAll() throws Exception { TestObject to1 = new TestObject("1", "456"); TestObject to2 = new TestObject("2", "abc"); TestObject to3 = new TestObject("3", "xyz"); service.save(to1); service.save(to2); service.save(to3); Collection<TestObject> results = service.getAll(TestObject.class); assertEquals(3, results.size()); assertTrue(results.contains(to1)); assertTrue(results.contains(to2)); assertTrue(results.contains(to3)); }
public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } protected StorageService(DB db); StorageService(String name); }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } protected StorageService(DB db); StorageService(String name); void close(); void delete(String id, Class<T> clazz); byte[] get(byte[] key); Collection<T> getAll(Class<T> clazz); T load(String id, Class<T> clazz); void put(byte[] key, byte[] value); void save(Object entity); }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } protected StorageService(DB db); StorageService(String name); void close(); void delete(String id, Class<T> clazz); byte[] get(byte[] key); Collection<T> getAll(Class<T> clazz); T load(String id, Class<T> clazz); void put(byte[] key, byte[] value); void save(Object entity); }
@Test public void equalsVariantsFalse() throws Exception { MoveVariantOp op1 = new MoveVariantOp(1, new VariantSpan(1, 100)); MoveVariantOp op2 = new MoveVariantOp(1, new VariantSpan(2, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; MoveVariantOp other = (MoveVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; }
MoveVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; MoveVariantOp other = (MoveVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } }
MoveVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; MoveVariantOp other = (MoveVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); }
MoveVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; MoveVariantOp other = (MoveVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
MoveVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; MoveVariantOp other = (MoveVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return false; return true; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void hashFalse() throws Exception { MoveVariantOp op1 = new MoveVariantOp(1, new VariantSpan(1, 100)); MoveVariantOp op2 = new MoveVariantOp(1, new VariantSpan(2, 100)); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void hashFalse2() throws Exception { MoveVariantOp op1 = new MoveVariantOp(1, new VariantSpan(1, 100)); MoveVariantOp op2 = new MoveVariantOp(2, new VariantSpan(1, 100)); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void hashTrue() throws Exception { MoveVariantOp op1 = new MoveVariantOp(1, new VariantSpan(1, 100)); MoveVariantOp op2 = new MoveVariantOp(1, new VariantSpan(1, 100)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long to; final VariantSpan variantSpan; }
@Test public void encodeDecode() throws Exception { PutInvariantSpanOp op = new PutInvariantSpanOp(100, 50, 1, 0); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_INVARIANT_SPAN, dis.readByte()); PutInvariantSpanOp decoded = new PutInvariantSpanOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_SPAN); dos.writeLong(to); dos.writeLong(invariantStart); dos.writeLong(width); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); }
PutInvariantSpanOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_SPAN); dos.writeLong(to); dos.writeLong(invariantStart); dos.writeLong(width); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } }
PutInvariantSpanOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_SPAN); dos.writeLong(to); dos.writeLong(invariantStart); dos.writeLong(width); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); }
PutInvariantSpanOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_SPAN); dos.writeLong(to); dos.writeLong(invariantStart); dos.writeLong(width); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantSpanOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_SPAN); dos.writeLong(to); dos.writeLong(invariantStart); dos.writeLong(width); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long invariantStart; final int ripIndex; final long to; final long width; }
@Test public void equalsFalse() throws Exception { PutInvariantSpanOp op1 = new PutInvariantSpanOp(100, 50, 1, 0); PutInvariantSpanOp op2 = new PutInvariantSpanOp(101, 50, 1, 0); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantSpanOp other = (PutInvariantSpanOp) obj; if (ripIndex != other.ripIndex) return false; if (invariantStart != other.invariantStart) return false; if (to != other.to) return false; if (width != other.width) return false; return true; }
PutInvariantSpanOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantSpanOp other = (PutInvariantSpanOp) obj; if (ripIndex != other.ripIndex) return false; if (invariantStart != other.invariantStart) return false; if (to != other.to) return false; if (width != other.width) return false; return true; } }
PutInvariantSpanOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantSpanOp other = (PutInvariantSpanOp) obj; if (ripIndex != other.ripIndex) return false; if (invariantStart != other.invariantStart) return false; if (to != other.to) return false; if (width != other.width) return false; return true; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); }
PutInvariantSpanOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantSpanOp other = (PutInvariantSpanOp) obj; if (ripIndex != other.ripIndex) return false; if (invariantStart != other.invariantStart) return false; if (to != other.to) return false; if (width != other.width) return false; return true; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantSpanOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantSpanOp other = (PutInvariantSpanOp) obj; if (ripIndex != other.ripIndex) return false; if (invariantStart != other.invariantStart) return false; if (to != other.to) return false; if (width != other.width) return false; return true; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long invariantStart; final int ripIndex; final long to; final long width; }
@Test public void hashFalse() throws Exception { PutInvariantSpanOp op1 = new PutInvariantSpanOp(100, 50, 1, 0); PutInvariantSpanOp op2 = new PutInvariantSpanOp(101, 50, 1, 0); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long invariantStart; final int ripIndex; final long to; final long width; }
@Test public void hashTrue() throws Exception { PutInvariantSpanOp op1 = new PutInvariantSpanOp(100, 50, 1, 0); PutInvariantSpanOp op2 = new PutInvariantSpanOp(100, 50, 1, 0); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (width ^ (width >>> 32)); return result; } PutInvariantSpanOp(DataInputStream dis); PutInvariantSpanOp(long to, long invariantStart, long width, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final long invariantStart; final int ripIndex; final long to; final long width; }
@Test public void encodeDecode() throws Exception { PutInvariantMediaOp op = new PutInvariantMediaOp(100, 1); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_INVARIANT_MEDIA, dis.readByte()); PutInvariantMediaOp decoded = new PutInvariantMediaOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_MEDIA); dos.writeLong(to); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); }
PutInvariantMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_MEDIA); dos.writeLong(to); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } }
PutInvariantMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_MEDIA); dos.writeLong(to); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); }
PutInvariantMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_MEDIA); dos.writeLong(to); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_MEDIA); dos.writeLong(to); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int ripIndex; final long to; }
@Test public void equalsFalse() throws Exception { PutInvariantMediaOp op1 = new PutInvariantMediaOp(1, 2); PutInvariantMediaOp op2 = new PutInvariantMediaOp(2, 2); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantMediaOp other = (PutInvariantMediaOp) obj; if (ripIndex != other.ripIndex) return false; if (to != other.to) return false; return true; }
PutInvariantMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantMediaOp other = (PutInvariantMediaOp) obj; if (ripIndex != other.ripIndex) return false; if (to != other.to) return false; return true; } }
PutInvariantMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantMediaOp other = (PutInvariantMediaOp) obj; if (ripIndex != other.ripIndex) return false; if (to != other.to) return false; return true; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); }
PutInvariantMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantMediaOp other = (PutInvariantMediaOp) obj; if (ripIndex != other.ripIndex) return false; if (to != other.to) return false; return true; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantMediaOp other = (PutInvariantMediaOp) obj; if (ripIndex != other.ripIndex) return false; if (to != other.to) return false; return true; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int ripIndex; final long to; }
@Test public void addText() throws Exception { DocumentFile.Builder builder = new DocumentFile.Builder("fakeHash"); builder.appendText("Xanadu"); builder.appendText("Green"); DocumentFile file = builder.build(); assertEquals("XanaduGreen", file.getInvariantStream()); }
public String getInvariantStream() { return invariantStream; }
DocumentFile { public String getInvariantStream() { return invariantStream; } }
DocumentFile { public String getInvariantStream() { return invariantStream; } private DocumentFile(); }
DocumentFile { public String getInvariantStream() { return invariantStream; } private DocumentFile(); static org.oulipo.streams.Compiler<DocumentFile> compiler(); static Decompiler<DocumentFile> decompiler(); Map<Integer, String> get(); String getDocumentHash(); String getEncyptedInvariantStream(); String getGenesisHash(); String getHashPreviousBlock(); String getInvariantStream(); int getMajorVersion(); int getMinorVersion(); List<Op> getOps(); Overlay getOverlay(int overlayIndex); Map<Integer, Overlay> getOverlayPool(); Set<Overlay> getOverlays(Set<Integer> indicies); String getString(int stringPoolIndex); long getTimestamp(); boolean hasEncryptedInvariantStream(); boolean hasGenesisHash(); boolean hasHashPreviousBlock(); boolean hasInvariantStream(); int operationCount(); int overlayPoolSize(); int stringPoolSize(); }
DocumentFile { public String getInvariantStream() { return invariantStream; } private DocumentFile(); static org.oulipo.streams.Compiler<DocumentFile> compiler(); static Decompiler<DocumentFile> decompiler(); Map<Integer, String> get(); String getDocumentHash(); String getEncyptedInvariantStream(); String getGenesisHash(); String getHashPreviousBlock(); String getInvariantStream(); int getMajorVersion(); int getMinorVersion(); List<Op> getOps(); Overlay getOverlay(int overlayIndex); Map<Integer, Overlay> getOverlayPool(); Set<Overlay> getOverlays(Set<Integer> indicies); String getString(int stringPoolIndex); long getTimestamp(); boolean hasEncryptedInvariantStream(); boolean hasGenesisHash(); boolean hasHashPreviousBlock(); boolean hasInvariantStream(); int operationCount(); int overlayPoolSize(); int stringPoolSize(); static final byte[] MAGIC; }
@Test public void hashFalse() throws Exception { PutInvariantMediaOp op1 = new PutInvariantMediaOp(1, 2); PutInvariantMediaOp op2 = new PutInvariantMediaOp(2, 2); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int ripIndex; final long to; }
@Test public void hashTrue() throws Exception { PutInvariantMediaOp op1 = new PutInvariantMediaOp(1, 2); PutInvariantMediaOp op2 = new PutInvariantMediaOp(1, 2); assertEquals(op1.hashCode(), op2.hashCode()); ; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final int ripIndex; final long to; }
@Test public void encodeDecode() throws Exception { PutOverlayOp op = new PutOverlayOp(new VariantSpan(100, 1), Sets.newSet(10, 5)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_OVERLAY, dis.readByte()); PutOverlayOp decoded = new PutOverlayOp(dis); assertEquals(op, decoded); }
@Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); }
PutOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } }
PutOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } PutOverlayOp(DataInputStream dis); PutOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); }
PutOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } PutOverlayOp(DataInputStream dis); PutOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); }
PutOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()); for (Integer i : linkTypes) { dos.writeInt(i); } } os.flush(); return os.toByteArray(); } PutOverlayOp(DataInputStream dis); PutOverlayOp(VariantSpan variantSpan, Set<Integer> linkTypes); @Override byte[] encode(); @Override boolean equals(Object obj); @Override int hashCode(); final Set<Integer> linkTypes; final VariantSpan variantSpan; }
@Test public void homeNoMatch() throws Exception { assertFalse(new VariantSpan(1, 9, "fakeHash").equals(new VariantSpan(1, 10))); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); public String documentHash; public long start; public long width; }
@Test public void startNoMatch() throws MalformedSpanException { assertFalse(new VariantSpan(1, 10).equals(new VariantSpan(2, 10))); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); public String documentHash; public long start; public long width; }
@Test public void widthNoMatch() throws MalformedSpanException { assertFalse(new VariantSpan(1, 9).equals(new VariantSpan(1, 10))); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } private VariantSpan(); VariantSpan(DataInputStream dis); VariantSpan(long start, long width); VariantSpan(long start, long width, String documentHash); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); public String documentHash; public long start; public long width; }
@Test public void inequality() throws Exception { InvariantSpan s1 = new InvariantSpan(10, 60, "ted: InvariantSpan s2 = new InvariantSpan(10, 50, "ted: assertFalse(s1.equals(s2)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InvariantSpan other = (InvariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; }
InvariantSpan implements Invariant { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InvariantSpan other = (InvariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } }
InvariantSpan implements Invariant { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InvariantSpan other = (InvariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); }
InvariantSpan implements Invariant { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InvariantSpan other = (InvariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); }
InvariantSpan implements Invariant { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InvariantSpan other = (InvariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.documentHash)) return false; if (start != other.start) return false; if (width != other.width) return false; return true; } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); }
@Test public void split() throws Exception { InvariantSpan span = new InvariantSpan(1, 4, documentHash); StreamElementPartition<InvariantSpan> result = span.split(1); assertEquals(new InvariantSpan(1, 1, documentHash), result.getLeft()); assertEquals(new InvariantSpan(2, 3, documentHash), result.getRight()); }
@Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); }
@Test public void splitEnd() throws Exception { InvariantSpan span = new InvariantSpan(1, 4, documentHash); StreamElementPartition<InvariantSpan> part = span.split(3); assertEquals(new InvariantSpan(1, 3, documentHash), part.getLeft()); assertEquals(new InvariantSpan(4, 1, documentHash), part.getRight()); }
@Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); }
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= leftPartitionWidth) { throw new IndexOutOfBoundsException("Width of left partition is greater than or equal to span: span width =" + width + ", partitionWidth = " + leftPartitionWidth); } return new StreamElementPartition<InvariantSpan>(new InvariantSpan(start, leftPartitionWidth, documentHash), new InvariantSpan(start + leftPartitionWidth, width - leftPartitionWidth, documentHash)); } InvariantSpan(); InvariantSpan(long start, long width, String documentHash); @Override InvariantSpan copy(); @Override boolean equals(Object obj); String getDocumentHash(); long getStart(); @Override long getWidth(); @Override int hashCode(); boolean hashDocumentHash(); void setStart(long start); @Override void setWidth(long width); @Override StreamElementPartition<InvariantSpan> split(long leftPartitionWidth); @Override String toString(); }