001package org.unix4j.unix.grep; 002 003import org.unix4j.context.ExecutionContext; 004import org.unix4j.line.Line; 005import org.unix4j.processor.AbstractLineProcessor; 006import org.unix4j.processor.LineProcessor; 007 008abstract class AbstractGrepProcessor extends AbstractLineProcessor<GrepArguments> { 009 010 private final LineMatcher matcher; 011 012 public AbstractGrepProcessor(GrepCommand command, ExecutionContext context, LineProcessor output, LineMatcher matcher) { 013 super(command, context, output); 014 this.matcher = matcher; 015 } 016 017 @Override 018 public boolean processLine(Line line) { 019 final boolean isMatch = matcher.matches(line); 020 return processLine(line, isMatch); 021 } 022 023 @Override 024 public void finish() { 025 getOutput().finish(); 026 } 027 028 abstract protected boolean processLine(Line line, boolean isMatch); 029}