@Test public void groupsToFields() throws Exception { RegexBundleizer bundleizer = decodeObject(RegexBundleizer.class, "regex = \"(?<digits>\\\\d+) (?<rest>.*)\""); Bundle bundle = bundleizer.bundleize(new ListBundle(), "12345 HELLO WORLD"); AutoField digits = AutoField.newAutoField("digits"); AutoField rest = AutoField.newAutoField("rest"); Assert.assertEquals("12345", digits.getString(bundle).get()); Assert.assertEquals("HELLO WORLD", rest.getString(bundle).get()); }
@Override public Bundle bundleize(Bundle next, String line) { Matcher lineMatcher = regex.matcher(line); if (lineMatcher.matches()) { for (int i = 0; i < fields.size(); i++) { fields.get(i).setValue(next, ValueFactory.create(lineMatcher.group(i + 1))); } } else { return null; } return next; }
RegexBundleizer extends NewlineBundleizer { @Override public Bundle bundleize(Bundle next, String line) { Matcher lineMatcher = regex.matcher(line); if (lineMatcher.matches()) { for (int i = 0; i < fields.size(); i++) { fields.get(i).setValue(next, ValueFactory.create(lineMatcher.group(i + 1))); } } else { return null; } return next; } }
RegexBundleizer extends NewlineBundleizer { @Override public Bundle bundleize(Bundle next, String line) { Matcher lineMatcher = regex.matcher(line); if (lineMatcher.matches()) { for (int i = 0; i < fields.size(); i++) { fields.get(i).setValue(next, ValueFactory.create(lineMatcher.group(i + 1))); } } else { return null; } return next; } RegexBundleizer(@JsonProperty("fields") ImmutableList<AutoField> fields,
                           @JsonProperty("regex") Pattern regex); }
RegexBundleizer extends NewlineBundleizer { @Override public Bundle bundleize(Bundle next, String line) { Matcher lineMatcher = regex.matcher(line); if (lineMatcher.matches()) { for (int i = 0; i < fields.size(); i++) { fields.get(i).setValue(next, ValueFactory.create(lineMatcher.group(i + 1))); } } else { return null; } return next; } RegexBundleizer(@JsonProperty("fields") ImmutableList<AutoField> fields,
                           @JsonProperty("regex") Pattern regex); @Override Bundle bundleize(Bundle next, String line); }
RegexBundleizer extends NewlineBundleizer { @Override public Bundle bundleize(Bundle next, String line) { Matcher lineMatcher = regex.matcher(line); if (lineMatcher.matches()) { for (int i = 0; i < fields.size(); i++) { fields.get(i).setValue(next, ValueFactory.create(lineMatcher.group(i + 1))); } } else { return null; } return next; } RegexBundleizer(@JsonProperty("fields") ImmutableList<AutoField> fields,
                           @JsonProperty("regex") Pattern regex); @Override Bundle bundleize(Bundle next, String line);  }