PatchLine (final String line, final int prefixLength, boolean expectMeaningfulLines) { if (!expectMeaningfulLines) return null; PatchLine.Type type; if (line.startsWith("+")) { type = PatchLine.Type.ADD; } else if (line.startsWith("-")) { type = PatchLine.Type.REMOVE; } else if (line.isEmpty() || line.startsWith(" ")) { type = PatchLine.Type.CONTEXT; } else { return null; } String lineText; if (line.length() < prefixLength) { lineText = ""; } else { lineText = line.substring(prefixLength); } return new PatchLine(type, lineText); }