public String indent() { return IndentUtils.tab(level); }
@Test public void testIncrease() throws Exception { IndentUtils sut=new IndentUtils(); sut.increase(); assertThat(sut.indent(),equalTo(SINGLE_TAB)); }
@Test public void testIndentUtils$positiveLevel() throws Exception { String tabs = "\t\t\t\t\t"; for(int i=0;i<tabs.length();i++) { IndentUtils sut=new IndentUtils(i+1); assertThat(sut.indent(),equalTo(tabs.substring(0,i+1))); } }
private void indent(String format, Object... args) { if(LOGGER.isTraceEnabled()) { LOGGER.trace(String.format(ind.indent().concat(format),args)); } } private void log(Object obj) {
GraphRenderer(Graph graph, boolean enableFolding) { this.disableFolding = !enableFolding; this.graph = graph; this.base = graph.getBase(); this.namespaces = graph.getNamespaces(); this.builder = new StringBuilder(); this.utils = new TurtleValueUtils((URI)base,namespaces); this.indenter = new IndentUtils(1); }
private List<String> doChaining(IndentUtils indenter, String item) { List<String> result=new ArrayList<String>(); List<String> toProcess=new ArrayList<String>(); toProcess.add(item); for(Iterator<String> it=patterns.iterator();it.hasNext();) { indenter.increase(); String nextPattern = it.next(); List<String> tmp=new ArrayList<String>(); for(String nextItem:toProcess) { tmp.addAll(doFilter(indenter,nextItem,nextPattern)); } toProcess=tmp; if(it.hasNext()) { if(toProcess.isEmpty()) { trace(indenter,"Nothing to refine"); } else { trace(indenter,"Refining: %s",toProcess); } } else { result.addAll(toProcess); } } return result; }
private void renderPredicateValues(Individual individual, URI predicate) { Assertions assertions=individual.getAssertions(predicate); Resource subject=individual.getSubject(); builder.append(NL).append(indenter.indent()).append(utils.toString(predicate)); String statementSeparator=" "; if(assertions.size()>3) { indenter.increase(); statementSeparator=NL.concat(indenter.indent()); } Iterator<Value> objectIterator = assertions.iterator(); String valueSeparator; do { builder.append(statementSeparator); Value object = objectIterator.next(); if(tryRenderingFolded(subject,object)) { valueSeparator=" ,"; } else { builder.append(utils.toString(object)); valueSeparator=","; } if(objectIterator.hasNext()) { builder.append(valueSeparator); } } while(objectIterator.hasNext()); if(assertions.size()>3) { indenter.decrease(); } }
@Test public void testIndentUtils$negativeLevel() throws Exception { IndentUtils sut=new IndentUtils(-1); assertThat(sut.indent(),isEmptyString()); }
private void indent(String format, Object... args) { if(LOGGER.isTraceEnabled()) { LOGGER.trace(String.format(ind.indent().concat(format),args)); } }
public List<String> extract(String item) { List<String> result = doChaining(new IndentUtils(), item); if(LOGGER.isDebugEnabled()) { debug(new IndentUtils(),"Extraction completed:\n-Data:\n%s\n-Result: %s",item,result); } return result; }
@Test public void testIndentUtils$noLevel() throws Exception { IndentUtils sut=new IndentUtils(); assertThat(sut.indent(),isEmptyString()); }
/** * @param indenter * @param format * @param args * @return */ private String block(IndentUtils indenter, String format, Object... args) { String indentation = indenter.indent(); String newLine = "\n\t".concat(indentation); String rawText = String.format(indentation.concat(format),args); String block = rawText.replaceAll("\n", newLine); return block; }
String query(String query) { LOGGER.info("Using JENA:"); Query q=QueryFactory.create(query); LOGGER.info("-- Query:\n"+q); LOGGER.info("-- Base: "+q.getBaseURI()); LOGGER.info("-- Prefixes: "+q.getPrefixMapping()); LOGGER.info("-- Variables: "+q.getProjectVars()); Set<Var> variables=new HashSet<Var>(q.getProjectVars()); for(Entry<Var, Expr> entry:q.getProject().getExprs().entrySet()) { Var shadowing = entry.getKey(); VariableShadowingDetector detector = new VariableShadowingDetector(new IndentUtils(),shadowing); entry.getValue().visit(detector); if(detector.isShadowing()) { variables.remove(shadowing); variables.add(detector.getShadowed()); } } LOGGER.info("-- Graph URIS: "+q.getGraphURIs()); LOGGER.info("-- Named graphd URIS: "+q.getNamedGraphURIs()); List<String> search=q.getNamedGraphURIs(); q.getQueryPattern().visit(new ElementVisitorImplementation(search,variables)); return null; }
public void visit(ElementNamedGraph arg0) { log(arg0); ind.increase(); arg0.getElement().visit(this); com.hp.hpl.jena.graph.Node graphNameNode = arg0.getGraphNameNode(); if(graphNameNode.isURI() && graphs.contains(graphNameNode.getURI())) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("Need to relocate graph: "+graphNameNode.getURI()); } } else { if(graphNameNode.isVariable() && variables.contains((Var)graphNameNode)) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("Need to filter result: "+graphNameNode); } } } ind.decrease(); }