void verify(String s) { if (begin < 0 || end <= begin || end > s.length()) { thrownew InternalError("Bad Range: " + s + "[" + begin + "," + end + "]");
}
}
@Override public String toString() { return"Range[" + begin + "," + end + ")";
}
}
publicstaticclass CompoundWrap extends Wrap {
final Object[] os; final String wrapped; finalint snidxFirst; finalint snidxLast; finalint snlineFirst; finalint snlineLast;
CompoundWrap(Object... os) { this.os = os; int sniFirst = Integer.MAX_VALUE; int sniLast = Integer.MIN_VALUE; int snlnFirst = Integer.MAX_VALUE; int snlnLast = Integer.MIN_VALUE;
StringBuilder sb = new StringBuilder(); for (Object o : os) { if (o instanceof String) {
String s = (String) o;
sb.append(s);
} elseif (o instanceof Wrap) {
Wrap w = (Wrap) o; if (w.firstSnippetIndex() < sniFirst) {
sniFirst = w.firstSnippetIndex();
} if (w.lastSnippetIndex() > sniLast) {
sniLast = w.lastSnippetIndex();
} if (w.firstSnippetLine() < snlnFirst) {
snlnFirst = w.firstSnippetLine();
} if (w.lastSnippetLine() > snlnLast) {
snlnLast = w.lastSnippetLine();
}
sb.append(w.wrapped());
} else { thrownew InternalError("Bad object in CommoundWrap: " + o);
}
} this.wrapped = sb.toString(); this.snidxFirst = sniFirst; this.snidxLast = sniLast; this.snlineFirst = snlnFirst; this.snlineLast = snlnLast;
}
@Override public String wrapped() { return wrapped;
}
@Override publicint snippetIndexToWrapIndex(int sni) { int before = 0; for (Object o : os) { if (o instanceof String) {
String s = (String) o;
before += s.length();
} elseif (o instanceof Wrap) {
Wrap w = (Wrap) o; if (sni >= w.firstSnippetIndex() && sni < w.lastSnippetIndex()) { int wwi = w.snippetIndexToWrapIndex(sni);
debugWrap("\nCommoundWrap.snippetIndexToWrapIndex: SnippetIndex(%d) -> WrapIndex(%d + %d = %d)"
+ "\n === %s",
sni, wwi, before, wwi + before, wrapped()); return wwi + before;
}
before += w.wrapped().length();
}
} return0;
}
Wrap wrapIndexToWrap(long wi) { int before = 0;
Wrap w = null; for (Object o : os) { if (o instanceof String) {
String s = (String) o;
before += s.length();
} elseif (o instanceof Wrap) {
w = (Wrap) o; int len = w.wrapped().length(); if ((wi - before) <= len) {
debugWrap("CommoundWrap.wrapIndexToWrap: Defer to wrap %s - wi: %d. before; %d >>> %s\n",
w, wi, before, w.wrapped()); return w;
}
before += len;
}
} return w;
}
@Override publicint wrapIndexToSnippetIndex(int wi) { int before = 0; for (Object o : os) { if (o instanceof String) {
String s = (String) o;
before += s.length();
} elseif (o instanceof Wrap) {
Wrap w = (Wrap) o; int len = w.wrapped().length(); if ((wi - before) <= len) { int si = w.wrapIndexToSnippetIndex(wi - before);
debugWrap("\nCommoundWrap.wrapIndexToSnippetIndex: WrapIndex(%d) -> SnippetIndex(%d)\n",
wi, si); return si;
}
before += len;
}
} return lastSnippetIndex();
}
@Override publicint snippetLineToWrapLine(int snline) { int before = 0; for (Object o : os) { if (o instanceof String) {
String s = (String) o;
before += countLines(s);
} elseif (o instanceof Wrap) {
Wrap w = (Wrap) o; if (snline >= w.firstSnippetLine() && snline <= w.lastSnippetLine()) { return w.snippetLineToWrapLine(snline) + before;
}
before += countLines(w.wrapped());
}
} return0;
}
Wrap wrapLineToWrap(int wline) { int before = 0;
Wrap w = null; for (Object o : os) { if (o instanceof String) {
String s = (String) o;
before += countLines(s);
} elseif (o instanceof Wrap) {
w = (Wrap) o; int lns = countLines(w.wrapped()); if ((wline - before) <= lns) { return w;
}
before += lns;
}
} return w;
}
@Override publicint wrapLineToSnippetLine(int wline) { int before = 0; for (Object o : os) { if (o instanceof String) {
String s = (String) o;
before += countLines(s);
} elseif (o instanceof Wrap) {
Wrap w = (Wrap) o; int lns = countLines(w.wrapped()); if ((wline - before) <= lns) { return w.wrapLineToSnippetLine(wline - before);
}
before += lns;
}
} return0;
}
@Override public String toString() { return"CompoundWrap(" + Arrays.stream(os)
.map(o -> (o instanceof String)
? "\"" + o + "\""
: o.toString())
.collect(joining(","))
+ ")";
}
}
staticclass RangeWrap extends Wrap {
final Range range; final String wrapped; // The snippet portion of the source finalint firstSnline; // Line count to start of snippet portion finalint lastSnline; // Line count to end of snippet portion
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.