use of suite.primitive.Chars in project suite by stupidsing.
the class MonadIntrinsics method newReader.
private Node newReader(IntrinsicCallback callback, InputStream is) {
BufferedReader br = new BufferedReader(new InputStreamReader(is, Constants.charset));
IPointer<Chars> icrp = Intrinsics.read(br);
return callback.enclose(new CharsIntrinsics().drain, new Data<>(icrp));
}
use of suite.primitive.Chars in project suite by stupidsing.
the class Formatter method format_.
private void format_(Node node, int parentPrec) {
new //
SwitchNode<Node>(//
node).doIf(Atom.class, n -> {
sb.append(quoteAtomIfRequired(n.name));
}).doIf(Data.class, n -> {
Object data = n.data;
if (data instanceof Chars)
sb.append("Chars<" + quoteStringIfRequired(data.toString()) + ">");
else if (data instanceof Node)
sb.append("Data<" + data.toString() + ">");
else
sb.append("Data<" + data.getClass().getSimpleName() + ">");
}).doIf(Dict.class, n -> {
sb.append("dict<");
for (Entry<Node, Reference> e : n.map.entrySet()) {
format(e.getKey(), TermOp.getLeftPrec(TermOp.AND___));
sb.append(":");
format(e.getValue(), TermOp.getLeftPrec(TermOp.AND___));
sb.append(",");
}
sb.append(">");
}).doIf(Int.class, n -> {
sb.append(n.number);
}).doIf(Reference.class, n -> {
sb.append(n.name());
}).doIf(Str.class, n -> {
sb.append(quoteStringIfRequired(n.value));
}).doIf(Tree.class, n -> {
formatTree(parentPrec, n);
}).doIf(Tuple.class, n -> {
sb.append("tuple<");
for (Node n_ : n.nodes) {
format(n_, TermOp.getLeftPrec(TermOp.AND___));
sb.append(", ");
}
sb.append(">");
}).doIf(Node.class, n -> {
sb.append(n.getClass().getSimpleName() + '@' + Integer.toHexString(System.identityHashCode(n)));
}).nonNullResult();
}
use of suite.primitive.Chars in project suite by stupidsing.
the class FactorizeResult method merge.
public static FactorizeResult merge(String name, List<FactorizeResult> list) {
Chars pre = List_.first(list).pre;
Chars post = List_.last(list).post;
List<FPair> pairs = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Chars space;
if (i != list.size() - 1)
space = Chars.of(pre.cs, list.get(i).post.start, list.get(i + 1).pre.end);
else
space = To.chars("");
pairs.add(new FPair(list.get(i).node, space));
}
FNode fn = new FTree(name, pairs);
return new FactorizeResult(pre, fn, post);
}
use of suite.primitive.Chars in project suite by stupidsing.
the class As method utf8decode.
public static Outlet<Chars> utf8decode(Outlet<Bytes> bytesOutlet) {
Source<Bytes> source = bytesOutlet.source();
return Outlet.of(new Source<>() {
private BytesBuilder bb = new BytesBuilder();
public Chars source() {
Chars chars;
while ((chars = decode()).size() == 0) {
Bytes bytes = source.source();
if (bytes != null)
bb.append(bytes);
else if (bb.size() == 0)
return null;
else
return Fail.t();
}
return chars;
}
private Chars decode() {
Bytes bytes = bb.toBytes();
CharsBuilder cb = new CharsBuilder();
int s = 0;
while (s < bytes.size()) {
int b0 = Byte.toUnsignedInt(bytes.get(s++));
int ch, e;
if (b0 < 0x80) {
ch = b0;
e = s;
} else if (b0 < 0xE0) {
ch = b0 & 0x1F;
e = s + 1;
} else if (b0 < 0xF0) {
ch = b0 & 0x0F;
e = s + 2;
} else if (b0 < 0xF8) {
ch = b0 & 0x07;
e = s + 3;
} else if (b0 < 0xFC) {
ch = b0 & 0x03;
e = s + 4;
} else if (b0 < 0xFE) {
ch = b0 & 0x01;
e = s + 5;
} else
throw new RuntimeException();
if (e <= bytes.size()) {
while (s < e) {
int b = Byte.toUnsignedInt(bytes.get(s++));
if ((b & 0xC0) == 0x80)
ch = (ch << 6) + (b & 0x3F);
else
Fail.t();
}
cb.append((char) ch);
} else
break;
}
bb = new BytesBuilder();
bb.append(bytes.range(s));
return cb.toChars();
}
});
}
use of suite.primitive.Chars in project suite by stupidsing.
the class BackTestMain method run.
@Override
protected boolean run(String[] args) {
// BEGIN
// END
String arg0 = 0 < args.length ? args[0] : "";
String arg1 = 1 < args.length ? args[1] : "";
String arg2 = 2 < args.length ? args[2] : "";
Streamlet<String> strategyMatches = !arg0.isEmpty() ? Read.from(arg0.split(",")) : null;
Streamlet<Integer> years = !arg1.isEmpty() ? //
Read.from(//
arg1.split(",")).concatMap(s -> {
Pair<String, String> pair = ParseUtil.search(s, "-", Assoc.RIGHT);
return //
pair != null ? //
Ints_.range(Integer.valueOf(pair.t0), Integer.valueOf(pair.t1)).map(i -> i) : Read.each(Integer.valueOf(s));
}) : //
Ints_.range(2007, Trade_.thisYear).map(i -> i);
Fun<Time, Streamlet<Asset>> fun = //
!arg2.isEmpty() ? //
time -> Read.from(arg2.split(",")).map(cfg::queryCompany).collect(As::streamlet) : cfg::queryCompaniesByMarketCap;
BackAllocConfigurations bac_ = new BackAllocConfigurations(cfg, fun);
Streamlet2<String, BackAllocConfiguration> bacByTag = bac_.bacs().bacByName;
Streamlet2<String, Simulate> simulationByKey = //
bacByTag.filterKey(//
n -> strategyMatches == null || strategyMatches.isAny(sm -> Wildcard.match(sm, n) != null)).map(//
Pair::of).join2(//
years.sort(Object_::compare).map(TimeRange::ofYear)).map2((pair, period) -> pair.t0, (pair, period) -> {
BackAllocConfiguration bac = pair.t1;
Streamlet<Asset> assets = bac.assetsFun.apply(period.from);
return runner.backTest(bac.backAllocator, period, assets);
}).collect(As::streamlet2);
String content0 = //
Read.bytes(//
Paths.get("src/main/java/" + getClass().getName().replace('.', '/') + ".java")).collect(//
As::utf8decode).map(//
Chars::toString).collect(As::joined);
String content1 = ParseUtil.fit(content0, "// BEGIN", "// END")[1];
System.out.println(content1);
System.out.println(runner.conclude(simulationByKey));
return true;
}
Aggregations