public Counts getCounts(SecurityContext sec) { Counts c = new Counts(); c.predictions = db.getPredictionCount(isAdmin(sec)); c.users = db.getUserCount(); c.visitors = db.getVisitorCount(); return c; }
public static final class Builder<OriginalInput, Output> implements ProcessingResultListener<OriginalInput, Output> { private final Counts.Builder fetch = Counts.builder(); private final Counts.Builder processing = Counts.builder(); private boolean hasListenerDelegationFailures = false; public ResultStatistics build() { return new ResultStatistics(fetch.build(), processing.build(), hasListenerDelegationFailures); } public void setListenerDelegationFailures(final boolean b) { hasListenerDelegationFailures = b; } @Override public void onFetchResult(final Result<FetchedItem<OriginalInput>, OriginalInput> result) { fetch.add(result); } @Override public void onProcessingResult(final Result<FetchedItem<OriginalInput>, Output> result) { processing.add(result); } }
/** * Create a suffix array from a given reference sequence. * * @param sequence The reference sequence to use when building the suffix array. * @return a constructed suffix array. */ public static SuffixArray createFromReferenceSequence(byte[] sequence) { // The builder for the suffix array. Use an integer in this case because // Java arrays can only hold an integer. TreeSet<Integer> suffixArrayBuilder = new TreeSet<Integer>(new SuffixArrayComparator(sequence)); Counts occurrences = new Counts(); for (byte base : sequence) occurrences.increment(base); // Build out the suffix array using a custom comparator. for (int i = 0; i <= sequence.length; i++) suffixArrayBuilder.add(i); // Copy the suffix array into an array. long[] suffixArray = new long[suffixArrayBuilder.size()]; int i = 0; for (Integer element : suffixArrayBuilder) suffixArray[i++] = element; // Find the first element in the inverse suffix array. long inverseSA0 = -1; for (i = 0; i < suffixArray.length; i++) { if (suffixArray[i] == 0) inverseSA0 = i; } if (inverseSA0 < 0) throw new ReviewedStingException( "Unable to find first inverse SA entry in generated suffix array."); return new SuffixArray(inverseSA0, occurrences, suffixArray); }
private boolean autoAssignFalse(Picks picks) throws IllegalPicksStateException { Counts values = getValueCounts(picks); if (values.allTrueButOneUnassigned()) { return values.onlyUnassigned.autoAssign(picks, false); } else if (values.allTrue()) { throw new IllegalPicksStateException(); } else { return false; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.COUNT); counts.toXContent(builder, params); builder.endObject(); builder.startArray(Fields.VERSIONS); for (Version v : versions) { builder.value(v.toString()); } builder.endArray(); builder.startObject(Fields.OS); os.toXContent(builder, params); builder.endObject(); builder.startObject(Fields.PROCESS); process.toXContent(builder, params); builder.endObject(); builder.startObject(Fields.JVM); jvm.toXContent(builder, params); builder.endObject(); builder.field(Fields.FS); fs.toXContent(builder, params); builder.startArray(Fields.PLUGINS); for (PluginInfo pluginInfo : plugins) { pluginInfo.toXContent(builder, params); } builder.endArray(); return builder; }
@Override public void startCounts(final Counts counts, final BufferedWriter out) throws IOException { out.write("<counts "); out.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); out.write("xsi:noNamespaceSchemaLocation=\"http://matsim.org/files/dtd/counts_v1.xsd\"\n"); if (counts.getName() != null) { out.write(" name=\"" + counts.getName() + "\""); } else { out.write(" name=\"\""); } if (counts.getDescription() != null) { out.write(" desc=\"" + counts.getDescription() + "\""); } out.write(" year=\"" + counts.getYear() + "\" "); out.write(" > \n"); }
/** * this method gets the count of nodes and the bytes under a subtree * * @param path the path to be used * @param bytes the long bytes * @param count the int count */ private void getCounts(String path, Counts counts) { DataNode node = getNode(path); if (node == null) { return; } String[] children = null; synchronized (node) { children = node.children.toArray(new String[node.children.size()]); } // add itself counts.count += 1; counts.bytes += (long) node.data.length; if (children.length == 0) { return; } for (String child : children) { getCounts(path + "/" + child, counts); } }
/* Added by Rick Mugridge */ private void interpretTables(FitDocument documents) { for (FitTable table : documents.tables()) { try { Fixture fixture = getLinkedFixtureWithArgs(table); fixture.doTable(table); counts.tally(table.getCounts()); } catch (Throwable e) { table.exception(e); counts.exceptions++; } } }
@Override public void writeTo(StreamOutput out) throws IOException { counts.writeTo(out); out.writeVInt(versions.size()); for (Version v : versions) Version.writeVersion(v, out); os.writeTo(out); process.writeTo(out); jvm.writeTo(out); fs.writeTo(out); out.writeVInt(plugins.size()); for (PluginInfo p : plugins) { p.writeTo(out); } }
@Override public void readFrom(StreamInput in) throws IOException { counts = Counts.readCounts(in); int size = in.readVInt(); versions = new HashSet<Version>(size); for (; size > 0; size--) { versions.add(Version.readVersion(in)); } os = OsStats.readOsStats(in); process = ProcessStats.readStats(in); jvm = JvmStats.readJvmStats(in); fs = FsStats.Info.readInfoFrom(in); size = in.readVInt(); plugins = new HashSet<PluginInfo>(size); for (; size > 0; size--) { plugins.add(PluginInfo.readPluginInfo(in)); } }
public ClusterStatsNodes(ClusterStatsNodeResponse[] nodeResponses) { this.counts = new Counts(); this.versions = new HashSet<Version>(); this.os = new OsStats(); this.jvm = new JvmStats(); this.fs = new FsStats.Info(); this.plugins = new HashSet<PluginInfo>(); this.process = new ProcessStats(); Set<InetAddress> seenAddresses = new HashSet<InetAddress>(nodeResponses.length); for (ClusterStatsNodeResponse nodeResponse : nodeResponses) { counts.addNodeInfo(nodeResponse.nodeInfo()); versions.add(nodeResponse.nodeInfo().getVersion()); process.addNodeStats(nodeResponse.nodeStats()); jvm.addNodeInfoStats(nodeResponse.nodeInfo(), nodeResponse.nodeStats()); plugins.addAll(nodeResponse.nodeInfo().getPlugins().getInfos()); // now do the stats that should be deduped by hardware (implemented by ip deduping) TransportAddress publishAddress = nodeResponse.nodeInfo().getTransport().address().publishAddress(); InetAddress inetAddress = null; if (publishAddress.uniqueAddressTypeId() == 1) { inetAddress = ((InetSocketTransportAddress) publishAddress).address().getAddress(); } if (!seenAddresses.add(inetAddress)) { continue; } os.addNodeInfo(nodeResponse.nodeInfo()); if (nodeResponse.nodeStats().getFs() != null) { fs.add(nodeResponse.nodeStats().getFs().total()); } } }
public String counts() { return counts.toString(); }
public static Counts readCounts(StreamInput in) throws IOException { Counts c = new Counts(); c.readFrom(in); return c; }
private static boolean allSuccess(final Counts counts) { return counts.getError() == 0; }
private static boolean allFailed(final Counts counts) { return counts.getError() != 0 && counts.getSuccess() == 0; }
@Override public CountsResponse counts(final GeneralRequest request) { return countsProvider.counts(request); }