Java tutorial
/* * Copyright 2011 Roman Stepanenko * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package brainleg.app.engine.visitor; import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import brainleg.app.engine.EData; import brainleg.app.engine.EDataVisitor; import brainleg.app.engine.ELine; import java.util.Collection; /** * You must manually mask the data first prior to running this visitor. * @author Roman Stepanenko */ public class WebSearchStringGeneratorVisitor implements EDataVisitor { public void visit(EData data) { Collection<ELine> lines = Lists.newArrayList(Iterables.concat(data.getHeaders(), data.getTraces())); //remove disabled lines lines = Collections2.filter(lines, new Predicate<ELine>() { public boolean apply(ELine line) { return line.enabled; } }); sb.append(Joiner.on("").join(Collections2.transform(lines, new Function<ELine, String>() { public String apply(ELine line) { return line.submissionText; } }))); } public String getGeneratedString() { return sb.toString(); } private StringBuilder sb = new StringBuilder(); }