id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
22,200
prometheus/client_java
simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/samplebuilder/GraphiteNamePattern.java
GraphiteNamePattern.initializePattern
private void initializePattern(final String pattern) { final String[] split = pattern.split(Pattern.quote("*"), -1); final StringBuilder escapedPattern = new StringBuilder(Pattern.quote(split[0])); for (int i = 1; i < split.length; i++) { String quoted = Pattern.quote(split[i]); escapedPattern.append("([^.]*)").append(quoted); } final String regex = "^" + escapedPattern.toString() + "$"; this.patternStr = regex; this.pattern = Pattern.compile(regex); }
java
private void initializePattern(final String pattern) { final String[] split = pattern.split(Pattern.quote("*"), -1); final StringBuilder escapedPattern = new StringBuilder(Pattern.quote(split[0])); for (int i = 1; i < split.length; i++) { String quoted = Pattern.quote(split[i]); escapedPattern.append("([^.]*)").append(quoted); } final String regex = "^" + escapedPattern.toString() + "$"; this.patternStr = regex; this.pattern = Pattern.compile(regex); }
[ "private", "void", "initializePattern", "(", "final", "String", "pattern", ")", "{", "final", "String", "[", "]", "split", "=", "pattern", ".", "split", "(", "Pattern", ".", "quote", "(", "\"*\"", ")", ",", "-", "1", ")", ";", "final", "StringBuilder", "escapedPattern", "=", "new", "StringBuilder", "(", "Pattern", ".", "quote", "(", "split", "[", "0", "]", ")", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "split", ".", "length", ";", "i", "++", ")", "{", "String", "quoted", "=", "Pattern", ".", "quote", "(", "split", "[", "i", "]", ")", ";", "escapedPattern", ".", "append", "(", "\"([^.]*)\"", ")", ".", "append", "(", "quoted", ")", ";", "}", "final", "String", "regex", "=", "\"^\"", "+", "escapedPattern", ".", "toString", "(", ")", "+", "\"$\"", ";", "this", ".", "patternStr", "=", "regex", ";", "this", ".", "pattern", "=", "Pattern", ".", "compile", "(", "regex", ")", ";", "}" ]
Turns the GLOB pattern into a REGEX. @param pattern The pattern to use
[ "Turns", "the", "GLOB", "pattern", "into", "a", "REGEX", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/samplebuilder/GraphiteNamePattern.java#L78-L89
22,201
prometheus/client_java
simpleclient_graphite_bridge/src/main/java/io/prometheus/client/bridge/Graphite.java
Graphite.push
public void push(CollectorRegistry registry) throws IOException { Socket s = new Socket(host, port); BufferedWriter writer = new BufferedWriter(new PrintWriter(s.getOutputStream())); Matcher m = INVALID_GRAPHITE_CHARS.matcher(""); long now = System.currentTimeMillis() / 1000; for (Collector.MetricFamilySamples metricFamilySamples: Collections.list(registry.metricFamilySamples())) { for (Collector.MetricFamilySamples.Sample sample: metricFamilySamples.samples) { m.reset(sample.name); writer.write(m.replaceAll("_")); for (int i = 0; i < sample.labelNames.size(); ++i) { m.reset(sample.labelValues.get(i)); writer.write("." + sample.labelNames.get(i) + "." + m.replaceAll("_")); } writer.write(" " + sample.value + " " + now + "\n"); } } writer.close(); s.close(); }
java
public void push(CollectorRegistry registry) throws IOException { Socket s = new Socket(host, port); BufferedWriter writer = new BufferedWriter(new PrintWriter(s.getOutputStream())); Matcher m = INVALID_GRAPHITE_CHARS.matcher(""); long now = System.currentTimeMillis() / 1000; for (Collector.MetricFamilySamples metricFamilySamples: Collections.list(registry.metricFamilySamples())) { for (Collector.MetricFamilySamples.Sample sample: metricFamilySamples.samples) { m.reset(sample.name); writer.write(m.replaceAll("_")); for (int i = 0; i < sample.labelNames.size(); ++i) { m.reset(sample.labelValues.get(i)); writer.write("." + sample.labelNames.get(i) + "." + m.replaceAll("_")); } writer.write(" " + sample.value + " " + now + "\n"); } } writer.close(); s.close(); }
[ "public", "void", "push", "(", "CollectorRegistry", "registry", ")", "throws", "IOException", "{", "Socket", "s", "=", "new", "Socket", "(", "host", ",", "port", ")", ";", "BufferedWriter", "writer", "=", "new", "BufferedWriter", "(", "new", "PrintWriter", "(", "s", ".", "getOutputStream", "(", ")", ")", ")", ";", "Matcher", "m", "=", "INVALID_GRAPHITE_CHARS", ".", "matcher", "(", "\"\"", ")", ";", "long", "now", "=", "System", ".", "currentTimeMillis", "(", ")", "/", "1000", ";", "for", "(", "Collector", ".", "MetricFamilySamples", "metricFamilySamples", ":", "Collections", ".", "list", "(", "registry", ".", "metricFamilySamples", "(", ")", ")", ")", "{", "for", "(", "Collector", ".", "MetricFamilySamples", ".", "Sample", "sample", ":", "metricFamilySamples", ".", "samples", ")", "{", "m", ".", "reset", "(", "sample", ".", "name", ")", ";", "writer", ".", "write", "(", "m", ".", "replaceAll", "(", "\"_\"", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "sample", ".", "labelNames", ".", "size", "(", ")", ";", "++", "i", ")", "{", "m", ".", "reset", "(", "sample", ".", "labelValues", ".", "get", "(", "i", ")", ")", ";", "writer", ".", "write", "(", "\".\"", "+", "sample", ".", "labelNames", ".", "get", "(", "i", ")", "+", "\".\"", "+", "m", ".", "replaceAll", "(", "\"_\"", ")", ")", ";", "}", "writer", ".", "write", "(", "\" \"", "+", "sample", ".", "value", "+", "\" \"", "+", "now", "+", "\"\\n\"", ")", ";", "}", "}", "writer", ".", "close", "(", ")", ";", "s", ".", "close", "(", ")", ";", "}" ]
Push samples from the given registry to Graphite.
[ "Push", "samples", "from", "the", "given", "registry", "to", "Graphite", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_graphite_bridge/src/main/java/io/prometheus/client/bridge/Graphite.java#L51-L69
22,202
prometheus/client_java
simpleclient_graphite_bridge/src/main/java/io/prometheus/client/bridge/Graphite.java
Graphite.start
public Thread start(CollectorRegistry registry, int intervalSeconds) { Thread thread = new PushThread(registry, intervalSeconds); thread.setDaemon(true); thread.start(); return thread; }
java
public Thread start(CollectorRegistry registry, int intervalSeconds) { Thread thread = new PushThread(registry, intervalSeconds); thread.setDaemon(true); thread.start(); return thread; }
[ "public", "Thread", "start", "(", "CollectorRegistry", "registry", ",", "int", "intervalSeconds", ")", "{", "Thread", "thread", "=", "new", "PushThread", "(", "registry", ",", "intervalSeconds", ")", ";", "thread", ".", "setDaemon", "(", "true", ")", ";", "thread", ".", "start", "(", ")", ";", "return", "thread", ";", "}" ]
Push samples from the given registry to Graphite at the given interval.
[ "Push", "samples", "from", "the", "given", "registry", "to", "Graphite", "at", "the", "given", "interval", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_graphite_bridge/src/main/java/io/prometheus/client/bridge/Graphite.java#L81-L86
22,203
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java
CKMSQuantiles.insert
public synchronized void insert(double value) { buffer[bufferCount] = value; bufferCount++; if (bufferCount == buffer.length) { insertBatch(); compress(); } }
java
public synchronized void insert(double value) { buffer[bufferCount] = value; bufferCount++; if (bufferCount == buffer.length) { insertBatch(); compress(); } }
[ "public", "synchronized", "void", "insert", "(", "double", "value", ")", "{", "buffer", "[", "bufferCount", "]", "=", "value", ";", "bufferCount", "++", ";", "if", "(", "bufferCount", "==", "buffer", ".", "length", ")", "{", "insertBatch", "(", ")", ";", "compress", "(", ")", ";", "}", "}" ]
Add a new value from the stream. @param value
[ "Add", "a", "new", "value", "from", "the", "stream", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java#L90-L98
22,204
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java
CKMSQuantiles.get
public synchronized double get(double q) { // clear the buffer insertBatch(); compress(); if (sample.size() == 0) { return Double.NaN; } int rankMin = 0; int desired = (int) (q * count); ListIterator<Item> it = sample.listIterator(); Item prev, cur; cur = it.next(); while (it.hasNext()) { prev = cur; cur = it.next(); rankMin += prev.g; if (rankMin + cur.g + cur.delta > desired + (allowableError(desired) / 2)) { return prev.value; } } // edge case of wanting max value return sample.getLast().value; }
java
public synchronized double get(double q) { // clear the buffer insertBatch(); compress(); if (sample.size() == 0) { return Double.NaN; } int rankMin = 0; int desired = (int) (q * count); ListIterator<Item> it = sample.listIterator(); Item prev, cur; cur = it.next(); while (it.hasNext()) { prev = cur; cur = it.next(); rankMin += prev.g; if (rankMin + cur.g + cur.delta > desired + (allowableError(desired) / 2)) { return prev.value; } } // edge case of wanting max value return sample.getLast().value; }
[ "public", "synchronized", "double", "get", "(", "double", "q", ")", "{", "// clear the buffer", "insertBatch", "(", ")", ";", "compress", "(", ")", ";", "if", "(", "sample", ".", "size", "(", ")", "==", "0", ")", "{", "return", "Double", ".", "NaN", ";", "}", "int", "rankMin", "=", "0", ";", "int", "desired", "=", "(", "int", ")", "(", "q", "*", "count", ")", ";", "ListIterator", "<", "Item", ">", "it", "=", "sample", ".", "listIterator", "(", ")", ";", "Item", "prev", ",", "cur", ";", "cur", "=", "it", ".", "next", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "prev", "=", "cur", ";", "cur", "=", "it", ".", "next", "(", ")", ";", "rankMin", "+=", "prev", ".", "g", ";", "if", "(", "rankMin", "+", "cur", ".", "g", "+", "cur", ".", "delta", ">", "desired", "+", "(", "allowableError", "(", "desired", ")", "/", "2", ")", ")", "{", "return", "prev", ".", "value", ";", "}", "}", "// edge case of wanting max value", "return", "sample", ".", "getLast", "(", ")", ".", "value", ";", "}" ]
Get the estimated value at the specified quantile. @param q Queried quantile, e.g. 0.50 or 0.99. @return Estimated value at that quantile.
[ "Get", "the", "estimated", "value", "at", "the", "specified", "quantile", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java#L107-L136
22,205
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java
CKMSQuantiles.allowableError
private double allowableError(int rank) { // NOTE: according to CKMS, this should be count, not size, but this // leads // to error larger than the error bounds. Leaving it like this is // essentially a HACK, and blows up memory, but does "work". // int size = count; int size = sample.size(); double minError = size + 1; for (Quantile q : quantiles) { double error; if (rank <= q.quantile * size) { error = q.u * (size - rank); } else { error = q.v * rank; } if (error < minError) { minError = error; } } return minError; }
java
private double allowableError(int rank) { // NOTE: according to CKMS, this should be count, not size, but this // leads // to error larger than the error bounds. Leaving it like this is // essentially a HACK, and blows up memory, but does "work". // int size = count; int size = sample.size(); double minError = size + 1; for (Quantile q : quantiles) { double error; if (rank <= q.quantile * size) { error = q.u * (size - rank); } else { error = q.v * rank; } if (error < minError) { minError = error; } } return minError; }
[ "private", "double", "allowableError", "(", "int", "rank", ")", "{", "// NOTE: according to CKMS, this should be count, not size, but this", "// leads", "// to error larger than the error bounds. Leaving it like this is", "// essentially a HACK, and blows up memory, but does \"work\".", "// int size = count;", "int", "size", "=", "sample", ".", "size", "(", ")", ";", "double", "minError", "=", "size", "+", "1", ";", "for", "(", "Quantile", "q", ":", "quantiles", ")", "{", "double", "error", ";", "if", "(", "rank", "<=", "q", ".", "quantile", "*", "size", ")", "{", "error", "=", "q", ".", "u", "*", "(", "size", "-", "rank", ")", ";", "}", "else", "{", "error", "=", "q", ".", "v", "*", "rank", ";", "}", "if", "(", "error", "<", "minError", ")", "{", "minError", "=", "error", ";", "}", "}", "return", "minError", ";", "}" ]
Specifies the allowable error for this rank, depending on which quantiles are being targeted. This is the f(r_i, n) function from the CKMS paper. It's basically how wide the range of this rank can be. @param rank the index in the list of samples
[ "Specifies", "the", "allowable", "error", "for", "this", "rank", "depending", "on", "which", "quantiles", "are", "being", "targeted", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java#L148-L170
22,206
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java
CKMSQuantiles.compress
private void compress() { if (sample.size() < 2) { return; } ListIterator<Item> it = sample.listIterator(); int removed = 0; Item prev = null; Item next = it.next(); while (it.hasNext()) { prev = next; next = it.next(); if (prev.g + next.g + next.delta <= allowableError(it.previousIndex())) { next.g += prev.g; // Remove prev. it.remove() kills the last thing returned. it.previous(); it.previous(); it.remove(); // it.next() is now equal to next, skip it back forward again it.next(); removed++; } } }
java
private void compress() { if (sample.size() < 2) { return; } ListIterator<Item> it = sample.listIterator(); int removed = 0; Item prev = null; Item next = it.next(); while (it.hasNext()) { prev = next; next = it.next(); if (prev.g + next.g + next.delta <= allowableError(it.previousIndex())) { next.g += prev.g; // Remove prev. it.remove() kills the last thing returned. it.previous(); it.previous(); it.remove(); // it.next() is now equal to next, skip it back forward again it.next(); removed++; } } }
[ "private", "void", "compress", "(", ")", "{", "if", "(", "sample", ".", "size", "(", ")", "<", "2", ")", "{", "return", ";", "}", "ListIterator", "<", "Item", ">", "it", "=", "sample", ".", "listIterator", "(", ")", ";", "int", "removed", "=", "0", ";", "Item", "prev", "=", "null", ";", "Item", "next", "=", "it", ".", "next", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "prev", "=", "next", ";", "next", "=", "it", ".", "next", "(", ")", ";", "if", "(", "prev", ".", "g", "+", "next", ".", "g", "+", "next", ".", "delta", "<=", "allowableError", "(", "it", ".", "previousIndex", "(", ")", ")", ")", "{", "next", ".", "g", "+=", "prev", ".", "g", ";", "// Remove prev. it.remove() kills the last thing returned.", "it", ".", "previous", "(", ")", ";", "it", ".", "previous", "(", ")", ";", "it", ".", "remove", "(", ")", ";", "// it.next() is now equal to next, skip it back forward again", "it", ".", "next", "(", ")", ";", "removed", "++", ";", "}", "}", "}" ]
Try to remove extraneous items from the set of sampled items. This checks if an item is unnecessary based on the desired error bounds, and merges it with the adjacent item if it is.
[ "Try", "to", "remove", "extraneous", "items", "from", "the", "set", "of", "sampled", "items", ".", "This", "checks", "if", "an", "item", "is", "unnecessary", "based", "on", "the", "desired", "error", "bounds", "and", "merges", "it", "with", "the", "adjacent", "item", "if", "it", "is", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java#L229-L255
22,207
prometheus/client_java
simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/DefaultExports.java
DefaultExports.register
public static void register(CollectorRegistry registry) { new StandardExports().register(registry); new MemoryPoolsExports().register(registry); new MemoryAllocationExports().register(registry); new BufferPoolsExports().register(registry); new GarbageCollectorExports().register(registry); new ThreadExports().register(registry); new ClassLoadingExports().register(registry); new VersionInfoExports().register(registry); }
java
public static void register(CollectorRegistry registry) { new StandardExports().register(registry); new MemoryPoolsExports().register(registry); new MemoryAllocationExports().register(registry); new BufferPoolsExports().register(registry); new GarbageCollectorExports().register(registry); new ThreadExports().register(registry); new ClassLoadingExports().register(registry); new VersionInfoExports().register(registry); }
[ "public", "static", "void", "register", "(", "CollectorRegistry", "registry", ")", "{", "new", "StandardExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "MemoryPoolsExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "MemoryAllocationExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "BufferPoolsExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "GarbageCollectorExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "ThreadExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "ClassLoadingExports", "(", ")", ".", "register", "(", "registry", ")", ";", "new", "VersionInfoExports", "(", ")", ".", "register", "(", "registry", ")", ";", "}" ]
Register the default Hotspot collectors with the given registry.
[ "Register", "the", "default", "Hotspot", "collectors", "with", "the", "given", "registry", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/DefaultExports.java#L36-L45
22,208
prometheus/client_java
simpleclient_common/src/main/java/io/prometheus/client/exporter/common/TextFormat.java
TextFormat.write004
public static void write004(Writer writer, Enumeration<Collector.MetricFamilySamples> mfs) throws IOException { /* See http://prometheus.io/docs/instrumenting/exposition_formats/ * for the output format specification. */ while(mfs.hasMoreElements()) { Collector.MetricFamilySamples metricFamilySamples = mfs.nextElement(); writer.write("# HELP "); writer.write(metricFamilySamples.name); writer.write(' '); writeEscapedHelp(writer, metricFamilySamples.help); writer.write('\n'); writer.write("# TYPE "); writer.write(metricFamilySamples.name); writer.write(' '); writer.write(typeString(metricFamilySamples.type)); writer.write('\n'); for (Collector.MetricFamilySamples.Sample sample: metricFamilySamples.samples) { writer.write(sample.name); if (sample.labelNames.size() > 0) { writer.write('{'); for (int i = 0; i < sample.labelNames.size(); ++i) { writer.write(sample.labelNames.get(i)); writer.write("=\""); writeEscapedLabelValue(writer, sample.labelValues.get(i)); writer.write("\","); } writer.write('}'); } writer.write(' '); writer.write(Collector.doubleToGoString(sample.value)); if (sample.timestampMs != null){ writer.write(' '); writer.write(sample.timestampMs.toString()); } writer.write('\n'); } } }
java
public static void write004(Writer writer, Enumeration<Collector.MetricFamilySamples> mfs) throws IOException { /* See http://prometheus.io/docs/instrumenting/exposition_formats/ * for the output format specification. */ while(mfs.hasMoreElements()) { Collector.MetricFamilySamples metricFamilySamples = mfs.nextElement(); writer.write("# HELP "); writer.write(metricFamilySamples.name); writer.write(' '); writeEscapedHelp(writer, metricFamilySamples.help); writer.write('\n'); writer.write("# TYPE "); writer.write(metricFamilySamples.name); writer.write(' '); writer.write(typeString(metricFamilySamples.type)); writer.write('\n'); for (Collector.MetricFamilySamples.Sample sample: metricFamilySamples.samples) { writer.write(sample.name); if (sample.labelNames.size() > 0) { writer.write('{'); for (int i = 0; i < sample.labelNames.size(); ++i) { writer.write(sample.labelNames.get(i)); writer.write("=\""); writeEscapedLabelValue(writer, sample.labelValues.get(i)); writer.write("\","); } writer.write('}'); } writer.write(' '); writer.write(Collector.doubleToGoString(sample.value)); if (sample.timestampMs != null){ writer.write(' '); writer.write(sample.timestampMs.toString()); } writer.write('\n'); } } }
[ "public", "static", "void", "write004", "(", "Writer", "writer", ",", "Enumeration", "<", "Collector", ".", "MetricFamilySamples", ">", "mfs", ")", "throws", "IOException", "{", "/* See http://prometheus.io/docs/instrumenting/exposition_formats/\n * for the output format specification. */", "while", "(", "mfs", ".", "hasMoreElements", "(", ")", ")", "{", "Collector", ".", "MetricFamilySamples", "metricFamilySamples", "=", "mfs", ".", "nextElement", "(", ")", ";", "writer", ".", "write", "(", "\"# HELP \"", ")", ";", "writer", ".", "write", "(", "metricFamilySamples", ".", "name", ")", ";", "writer", ".", "write", "(", "'", "'", ")", ";", "writeEscapedHelp", "(", "writer", ",", "metricFamilySamples", ".", "help", ")", ";", "writer", ".", "write", "(", "'", "'", ")", ";", "writer", ".", "write", "(", "\"# TYPE \"", ")", ";", "writer", ".", "write", "(", "metricFamilySamples", ".", "name", ")", ";", "writer", ".", "write", "(", "'", "'", ")", ";", "writer", ".", "write", "(", "typeString", "(", "metricFamilySamples", ".", "type", ")", ")", ";", "writer", ".", "write", "(", "'", "'", ")", ";", "for", "(", "Collector", ".", "MetricFamilySamples", ".", "Sample", "sample", ":", "metricFamilySamples", ".", "samples", ")", "{", "writer", ".", "write", "(", "sample", ".", "name", ")", ";", "if", "(", "sample", ".", "labelNames", ".", "size", "(", ")", ">", "0", ")", "{", "writer", ".", "write", "(", "'", "'", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "sample", ".", "labelNames", ".", "size", "(", ")", ";", "++", "i", ")", "{", "writer", ".", "write", "(", "sample", ".", "labelNames", ".", "get", "(", "i", ")", ")", ";", "writer", ".", "write", "(", "\"=\\\"\"", ")", ";", "writeEscapedLabelValue", "(", "writer", ",", "sample", ".", "labelValues", ".", "get", "(", "i", ")", ")", ";", "writer", ".", "write", "(", "\"\\\",\"", ")", ";", "}", "writer", ".", "write", "(", "'", "'", ")", ";", "}", "writer", ".", "write", "(", "'", "'", ")", ";", "writer", ".", "write", "(", "Collector", ".", "doubleToGoString", "(", "sample", ".", "value", ")", ")", ";", "if", "(", "sample", ".", "timestampMs", "!=", "null", ")", "{", "writer", ".", "write", "(", "'", "'", ")", ";", "writer", ".", "write", "(", "sample", ".", "timestampMs", ".", "toString", "(", ")", ")", ";", "}", "writer", ".", "write", "(", "'", "'", ")", ";", "}", "}", "}" ]
Write out the text version 0.0.4 of the given MetricFamilySamples.
[ "Write", "out", "the", "text", "version", "0", ".", "0", ".", "4", "of", "the", "given", "MetricFamilySamples", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_common/src/main/java/io/prometheus/client/exporter/common/TextFormat.java#L18-L56
22,209
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/Collector.java
Collector.sanitizeMetricName
public static String sanitizeMetricName(String metricName) { return SANITIZE_BODY_PATTERN.matcher( SANITIZE_PREFIX_PATTERN.matcher(metricName).replaceFirst("_") ).replaceAll("_"); }
java
public static String sanitizeMetricName(String metricName) { return SANITIZE_BODY_PATTERN.matcher( SANITIZE_PREFIX_PATTERN.matcher(metricName).replaceFirst("_") ).replaceAll("_"); }
[ "public", "static", "String", "sanitizeMetricName", "(", "String", "metricName", ")", "{", "return", "SANITIZE_BODY_PATTERN", ".", "matcher", "(", "SANITIZE_PREFIX_PATTERN", ".", "matcher", "(", "metricName", ")", ".", "replaceFirst", "(", "\"_\"", ")", ")", ".", "replaceAll", "(", "\"_\"", ")", ";", "}" ]
Sanitize metric name
[ "Sanitize", "metric", "name" ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/Collector.java#L192-L196
22,210
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/Collector.java
Collector.checkMetricLabelName
protected static void checkMetricLabelName(String name) { if (!METRIC_LABEL_NAME_RE.matcher(name).matches()) { throw new IllegalArgumentException("Invalid metric label name: " + name); } if (RESERVED_METRIC_LABEL_NAME_RE.matcher(name).matches()) { throw new IllegalArgumentException("Invalid metric label name, reserved for internal use: " + name); } }
java
protected static void checkMetricLabelName(String name) { if (!METRIC_LABEL_NAME_RE.matcher(name).matches()) { throw new IllegalArgumentException("Invalid metric label name: " + name); } if (RESERVED_METRIC_LABEL_NAME_RE.matcher(name).matches()) { throw new IllegalArgumentException("Invalid metric label name, reserved for internal use: " + name); } }
[ "protected", "static", "void", "checkMetricLabelName", "(", "String", "name", ")", "{", "if", "(", "!", "METRIC_LABEL_NAME_RE", ".", "matcher", "(", "name", ")", ".", "matches", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid metric label name: \"", "+", "name", ")", ";", "}", "if", "(", "RESERVED_METRIC_LABEL_NAME_RE", ".", "matcher", "(", "name", ")", ".", "matches", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid metric label name, reserved for internal use: \"", "+", "name", ")", ";", "}", "}" ]
Throw an exception if the metric label name is invalid.
[ "Throw", "an", "exception", "if", "the", "metric", "label", "name", "is", "invalid", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/Collector.java#L201-L208
22,211
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/Collector.java
Collector.doubleToGoString
public static String doubleToGoString(double d) { if (d == Double.POSITIVE_INFINITY) { return "+Inf"; } if (d == Double.NEGATIVE_INFINITY) { return "-Inf"; } if (Double.isNaN(d)) { return "NaN"; } return Double.toString(d); }
java
public static String doubleToGoString(double d) { if (d == Double.POSITIVE_INFINITY) { return "+Inf"; } if (d == Double.NEGATIVE_INFINITY) { return "-Inf"; } if (Double.isNaN(d)) { return "NaN"; } return Double.toString(d); }
[ "public", "static", "String", "doubleToGoString", "(", "double", "d", ")", "{", "if", "(", "d", "==", "Double", ".", "POSITIVE_INFINITY", ")", "{", "return", "\"+Inf\"", ";", "}", "if", "(", "d", "==", "Double", ".", "NEGATIVE_INFINITY", ")", "{", "return", "\"-Inf\"", ";", "}", "if", "(", "Double", ".", "isNaN", "(", "d", ")", ")", "{", "return", "\"NaN\"", ";", "}", "return", "Double", ".", "toString", "(", "d", ")", ";", "}" ]
Convert a double to its string representation in Go.
[ "Convert", "a", "double", "to", "its", "string", "representation", "in", "Go", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/Collector.java#L213-L224
22,212
prometheus/client_java
simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java
HTTPServer.start
private void start(boolean daemon) { if (daemon == Thread.currentThread().isDaemon()) { server.start(); } else { FutureTask<Void> startTask = new FutureTask<Void>(new Runnable() { @Override public void run() { server.start(); } }, null); NamedDaemonThreadFactory.defaultThreadFactory(daemon).newThread(startTask).start(); try { startTask.get(); } catch (ExecutionException e) { throw new RuntimeException("Unexpected exception on starting HTTPSever", e); } catch (InterruptedException e) { // This is possible only if the current tread has been interrupted, // but in real use cases this should not happen. // In any case, there is nothing to do, except to propagate interrupted flag. Thread.currentThread().interrupt(); } } }
java
private void start(boolean daemon) { if (daemon == Thread.currentThread().isDaemon()) { server.start(); } else { FutureTask<Void> startTask = new FutureTask<Void>(new Runnable() { @Override public void run() { server.start(); } }, null); NamedDaemonThreadFactory.defaultThreadFactory(daemon).newThread(startTask).start(); try { startTask.get(); } catch (ExecutionException e) { throw new RuntimeException("Unexpected exception on starting HTTPSever", e); } catch (InterruptedException e) { // This is possible only if the current tread has been interrupted, // but in real use cases this should not happen. // In any case, there is nothing to do, except to propagate interrupted flag. Thread.currentThread().interrupt(); } } }
[ "private", "void", "start", "(", "boolean", "daemon", ")", "{", "if", "(", "daemon", "==", "Thread", ".", "currentThread", "(", ")", ".", "isDaemon", "(", ")", ")", "{", "server", ".", "start", "(", ")", ";", "}", "else", "{", "FutureTask", "<", "Void", ">", "startTask", "=", "new", "FutureTask", "<", "Void", ">", "(", "new", "Runnable", "(", ")", "{", "@", "Override", "public", "void", "run", "(", ")", "{", "server", ".", "start", "(", ")", ";", "}", "}", ",", "null", ")", ";", "NamedDaemonThreadFactory", ".", "defaultThreadFactory", "(", "daemon", ")", ".", "newThread", "(", "startTask", ")", ".", "start", "(", ")", ";", "try", "{", "startTask", ".", "get", "(", ")", ";", "}", "catch", "(", "ExecutionException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Unexpected exception on starting HTTPSever\"", ",", "e", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "// This is possible only if the current tread has been interrupted,", "// but in real use cases this should not happen.", "// In any case, there is nothing to do, except to propagate interrupted flag.", "Thread", ".", "currentThread", "(", ")", ".", "interrupt", "(", ")", ";", "}", "}", "}" ]
Start a HTTP server by making sure that its background thread inherit proper daemon flag.
[ "Start", "a", "HTTP", "server", "by", "making", "sure", "that", "its", "background", "thread", "inherit", "proper", "daemon", "flag", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java#L207-L229
22,213
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/CollectorRegistry.java
CollectorRegistry.unregister
public void unregister(Collector m) { synchronized (collectorsToNames) { List<String> names = collectorsToNames.remove(m); for (String name : names) { namesToCollectors.remove(name); } } }
java
public void unregister(Collector m) { synchronized (collectorsToNames) { List<String> names = collectorsToNames.remove(m); for (String name : names) { namesToCollectors.remove(name); } } }
[ "public", "void", "unregister", "(", "Collector", "m", ")", "{", "synchronized", "(", "collectorsToNames", ")", "{", "List", "<", "String", ">", "names", "=", "collectorsToNames", ".", "remove", "(", "m", ")", ";", "for", "(", "String", "name", ":", "names", ")", "{", "namesToCollectors", ".", "remove", "(", "name", ")", ";", "}", "}", "}" ]
Unregister a Collector.
[ "Unregister", "a", "Collector", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/CollectorRegistry.java#L67-L74
22,214
prometheus/client_java
simpleclient_pushgateway/src/main/java/io/prometheus/client/exporter/PushGateway.java
PushGateway.createURLSneakily
private static URL createURLSneakily(final String urlString) { try { return new URL(urlString); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
java
private static URL createURLSneakily(final String urlString) { try { return new URL(urlString); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
[ "private", "static", "URL", "createURLSneakily", "(", "final", "String", "urlString", ")", "{", "try", "{", "return", "new", "URL", "(", "urlString", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "}" ]
Creates a URL instance from a String representation of a URL without throwing a checked exception. Required because you can't wrap a call to another constructor in a try statement. TODO: Remove this along with other deprecated methods before version 1.0 is released. @param urlString the String representation of the URL. @return The URL instance.
[ "Creates", "a", "URL", "instance", "from", "a", "String", "representation", "of", "a", "URL", "without", "throwing", "a", "checked", "exception", ".", "Required", "because", "you", "can", "t", "wrap", "a", "call", "to", "another", "constructor", "in", "a", "try", "statement", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_pushgateway/src/main/java/io/prometheus/client/exporter/PushGateway.java#L100-L106
22,215
prometheus/client_java
simpleclient/src/main/java/io/prometheus/client/DoubleAdder.java
DoubleAdder.add
public void add(double x) { Cell[] as; long b, v; int[] hc; Cell a; int n; if ((as = cells) != null || !casBase(b = base, Double.doubleToRawLongBits (Double.longBitsToDouble(b) + x))) { boolean uncontended = true; if ((hc = threadHashCode.get()) == null || as == null || (n = as.length) < 1 || (a = as[(n - 1) & hc[0]]) == null || !(uncontended = a.cas(v = a.value, Double.doubleToRawLongBits (Double.longBitsToDouble(v) + x)))) retryUpdate(Double.doubleToRawLongBits(x), hc, uncontended); } }
java
public void add(double x) { Cell[] as; long b, v; int[] hc; Cell a; int n; if ((as = cells) != null || !casBase(b = base, Double.doubleToRawLongBits (Double.longBitsToDouble(b) + x))) { boolean uncontended = true; if ((hc = threadHashCode.get()) == null || as == null || (n = as.length) < 1 || (a = as[(n - 1) & hc[0]]) == null || !(uncontended = a.cas(v = a.value, Double.doubleToRawLongBits (Double.longBitsToDouble(v) + x)))) retryUpdate(Double.doubleToRawLongBits(x), hc, uncontended); } }
[ "public", "void", "add", "(", "double", "x", ")", "{", "Cell", "[", "]", "as", ";", "long", "b", ",", "v", ";", "int", "[", "]", "hc", ";", "Cell", "a", ";", "int", "n", ";", "if", "(", "(", "as", "=", "cells", ")", "!=", "null", "||", "!", "casBase", "(", "b", "=", "base", ",", "Double", ".", "doubleToRawLongBits", "(", "Double", ".", "longBitsToDouble", "(", "b", ")", "+", "x", ")", ")", ")", "{", "boolean", "uncontended", "=", "true", ";", "if", "(", "(", "hc", "=", "threadHashCode", ".", "get", "(", ")", ")", "==", "null", "||", "as", "==", "null", "||", "(", "n", "=", "as", ".", "length", ")", "<", "1", "||", "(", "a", "=", "as", "[", "(", "n", "-", "1", ")", "&", "hc", "[", "0", "]", "]", ")", "==", "null", "||", "!", "(", "uncontended", "=", "a", ".", "cas", "(", "v", "=", "a", ".", "value", ",", "Double", ".", "doubleToRawLongBits", "(", "Double", ".", "longBitsToDouble", "(", "v", ")", "+", "x", ")", ")", ")", ")", "retryUpdate", "(", "Double", ".", "doubleToRawLongBits", "(", "x", ")", ",", "hc", ",", "uncontended", ")", ";", "}", "}" ]
Adds the given value. @param x the value to add
[ "Adds", "the", "given", "value", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient/src/main/java/io/prometheus/client/DoubleAdder.java#L67-L82
22,216
prometheus/client_java
simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java
DropwizardExports.fromSnapshotAndCount
MetricFamilySamples fromSnapshotAndCount(String dropwizardName, Snapshot snapshot, long count, double factor, String helpMessage) { List<MetricFamilySamples.Sample> samples = Arrays.asList( sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.5"), snapshot.getMedian() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.75"), snapshot.get75thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.95"), snapshot.get95thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.98"), snapshot.get98thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.99"), snapshot.get99thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.999"), snapshot.get999thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "_count", new ArrayList<String>(), new ArrayList<String>(), count) ); return new MetricFamilySamples(samples.get(0).name, Type.SUMMARY, helpMessage, samples); }
java
MetricFamilySamples fromSnapshotAndCount(String dropwizardName, Snapshot snapshot, long count, double factor, String helpMessage) { List<MetricFamilySamples.Sample> samples = Arrays.asList( sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.5"), snapshot.getMedian() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.75"), snapshot.get75thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.95"), snapshot.get95thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.98"), snapshot.get98thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.99"), snapshot.get99thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "", Arrays.asList("quantile"), Arrays.asList("0.999"), snapshot.get999thPercentile() * factor), sampleBuilder.createSample(dropwizardName, "_count", new ArrayList<String>(), new ArrayList<String>(), count) ); return new MetricFamilySamples(samples.get(0).name, Type.SUMMARY, helpMessage, samples); }
[ "MetricFamilySamples", "fromSnapshotAndCount", "(", "String", "dropwizardName", ",", "Snapshot", "snapshot", ",", "long", "count", ",", "double", "factor", ",", "String", "helpMessage", ")", "{", "List", "<", "MetricFamilySamples", ".", "Sample", ">", "samples", "=", "Arrays", ".", "asList", "(", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"\"", ",", "Arrays", ".", "asList", "(", "\"quantile\"", ")", ",", "Arrays", ".", "asList", "(", "\"0.5\"", ")", ",", "snapshot", ".", "getMedian", "(", ")", "*", "factor", ")", ",", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"\"", ",", "Arrays", ".", "asList", "(", "\"quantile\"", ")", ",", "Arrays", ".", "asList", "(", "\"0.75\"", ")", ",", "snapshot", ".", "get75thPercentile", "(", ")", "*", "factor", ")", ",", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"\"", ",", "Arrays", ".", "asList", "(", "\"quantile\"", ")", ",", "Arrays", ".", "asList", "(", "\"0.95\"", ")", ",", "snapshot", ".", "get95thPercentile", "(", ")", "*", "factor", ")", ",", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"\"", ",", "Arrays", ".", "asList", "(", "\"quantile\"", ")", ",", "Arrays", ".", "asList", "(", "\"0.98\"", ")", ",", "snapshot", ".", "get98thPercentile", "(", ")", "*", "factor", ")", ",", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"\"", ",", "Arrays", ".", "asList", "(", "\"quantile\"", ")", ",", "Arrays", ".", "asList", "(", "\"0.99\"", ")", ",", "snapshot", ".", "get99thPercentile", "(", ")", "*", "factor", ")", ",", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"\"", ",", "Arrays", ".", "asList", "(", "\"quantile\"", ")", ",", "Arrays", ".", "asList", "(", "\"0.999\"", ")", ",", "snapshot", ".", "get999thPercentile", "(", ")", "*", "factor", ")", ",", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"_count\"", ",", "new", "ArrayList", "<", "String", ">", "(", ")", ",", "new", "ArrayList", "<", "String", ">", "(", ")", ",", "count", ")", ")", ";", "return", "new", "MetricFamilySamples", "(", "samples", ".", "get", "(", "0", ")", ".", "name", ",", "Type", ".", "SUMMARY", ",", "helpMessage", ",", "samples", ")", ";", "}" ]
Export a histogram snapshot as a prometheus SUMMARY. @param dropwizardName metric name. @param snapshot the histogram snapshot. @param count the total sample count for this snapshot. @param factor a factor to apply to histogram values.
[ "Export", "a", "histogram", "snapshot", "as", "a", "prometheus", "SUMMARY", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java#L86-L97
22,217
prometheus/client_java
simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java
DropwizardExports.fromTimer
MetricFamilySamples fromTimer(String dropwizardName, Timer timer) { return fromSnapshotAndCount(dropwizardName, timer.getSnapshot(), timer.getCount(), 1.0D / TimeUnit.SECONDS.toNanos(1L), getHelpMessage(dropwizardName, timer)); }
java
MetricFamilySamples fromTimer(String dropwizardName, Timer timer) { return fromSnapshotAndCount(dropwizardName, timer.getSnapshot(), timer.getCount(), 1.0D / TimeUnit.SECONDS.toNanos(1L), getHelpMessage(dropwizardName, timer)); }
[ "MetricFamilySamples", "fromTimer", "(", "String", "dropwizardName", ",", "Timer", "timer", ")", "{", "return", "fromSnapshotAndCount", "(", "dropwizardName", ",", "timer", ".", "getSnapshot", "(", ")", ",", "timer", ".", "getCount", "(", ")", ",", "1.0D", "/", "TimeUnit", ".", "SECONDS", ".", "toNanos", "(", "1L", ")", ",", "getHelpMessage", "(", "dropwizardName", ",", "timer", ")", ")", ";", "}" ]
Export Dropwizard Timer as a histogram. Use TIME_UNIT as time unit.
[ "Export", "Dropwizard", "Timer", "as", "a", "histogram", ".", "Use", "TIME_UNIT", "as", "time", "unit", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java#L110-L113
22,218
prometheus/client_java
simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java
DropwizardExports.fromMeter
MetricFamilySamples fromMeter(String dropwizardName, Meter meter) { final MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "_total", new ArrayList<String>(), new ArrayList<String>(), meter.getCount()); return new MetricFamilySamples(sample.name, Type.COUNTER, getHelpMessage(dropwizardName, meter), Arrays.asList(sample)); }
java
MetricFamilySamples fromMeter(String dropwizardName, Meter meter) { final MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "_total", new ArrayList<String>(), new ArrayList<String>(), meter.getCount()); return new MetricFamilySamples(sample.name, Type.COUNTER, getHelpMessage(dropwizardName, meter), Arrays.asList(sample)); }
[ "MetricFamilySamples", "fromMeter", "(", "String", "dropwizardName", ",", "Meter", "meter", ")", "{", "final", "MetricFamilySamples", ".", "Sample", "sample", "=", "sampleBuilder", ".", "createSample", "(", "dropwizardName", ",", "\"_total\"", ",", "new", "ArrayList", "<", "String", ">", "(", ")", ",", "new", "ArrayList", "<", "String", ">", "(", ")", ",", "meter", ".", "getCount", "(", ")", ")", ";", "return", "new", "MetricFamilySamples", "(", "sample", ".", "name", ",", "Type", ".", "COUNTER", ",", "getHelpMessage", "(", "dropwizardName", ",", "meter", ")", ",", "Arrays", ".", "asList", "(", "sample", ")", ")", ";", "}" ]
Export a Meter as as prometheus COUNTER.
[ "Export", "a", "Meter", "as", "as", "prometheus", "COUNTER", "." ]
4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f
https://github.com/prometheus/client_java/blob/4e0e7527b048f1ffd0382dcb74c0b9dab23b4d9f/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java#L118-L125
22,219
JodaOrg/joda-time
src/main/java/org/joda/time/format/DateTimeParserBucket.java
DateTimeParserBucket.saveField
public void saveField(DateTimeFieldType fieldType, int value) { obtainSaveField().init(fieldType.getField(iChrono), value); }
java
public void saveField(DateTimeFieldType fieldType, int value) { obtainSaveField().init(fieldType.getField(iChrono), value); }
[ "public", "void", "saveField", "(", "DateTimeFieldType", "fieldType", ",", "int", "value", ")", "{", "obtainSaveField", "(", ")", ".", "init", "(", "fieldType", ".", "getField", "(", "iChrono", ")", ",", "value", ")", ";", "}" ]
Saves a datetime field value. @param fieldType the field type @param value the value
[ "Saves", "a", "datetime", "field", "value", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/DateTimeParserBucket.java#L308-L310
22,220
JodaOrg/joda-time
src/main/java/org/joda/time/format/DateTimeParserBucket.java
DateTimeParserBucket.saveField
public void saveField(DateTimeFieldType fieldType, String text, Locale locale) { obtainSaveField().init(fieldType.getField(iChrono), text, locale); }
java
public void saveField(DateTimeFieldType fieldType, String text, Locale locale) { obtainSaveField().init(fieldType.getField(iChrono), text, locale); }
[ "public", "void", "saveField", "(", "DateTimeFieldType", "fieldType", ",", "String", "text", ",", "Locale", "locale", ")", "{", "obtainSaveField", "(", ")", ".", "init", "(", "fieldType", ".", "getField", "(", "iChrono", ")", ",", "text", ",", "locale", ")", ";", "}" ]
Saves a datetime field text value. @param fieldType the field type @param text the text value @param locale the locale to use
[ "Saves", "a", "datetime", "field", "text", "value", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/DateTimeParserBucket.java#L319-L321
22,221
JodaOrg/joda-time
src/main/java/org/joda/time/format/DateTimeParserBucket.java
DateTimeParserBucket.restoreState
public boolean restoreState(Object savedState) { if (savedState instanceof SavedState) { if (((SavedState) savedState).restoreState(this)) { iSavedState = savedState; return true; } } return false; }
java
public boolean restoreState(Object savedState) { if (savedState instanceof SavedState) { if (((SavedState) savedState).restoreState(this)) { iSavedState = savedState; return true; } } return false; }
[ "public", "boolean", "restoreState", "(", "Object", "savedState", ")", "{", "if", "(", "savedState", "instanceof", "SavedState", ")", "{", "if", "(", "(", "(", "SavedState", ")", "savedState", ")", ".", "restoreState", "(", "this", ")", ")", "{", "iSavedState", "=", "savedState", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Restores the state of this bucket from a previously saved state. The state object passed into this method is not consumed, and it can be used later to restore to that state again. @param savedState opaque saved state, returned from saveState @return true state object is valid and state restored
[ "Restores", "the", "state", "of", "this", "bucket", "from", "a", "previously", "saved", "state", ".", "The", "state", "object", "passed", "into", "this", "method", "is", "not", "consumed", "and", "it", "can", "be", "used", "later", "to", "restore", "to", "that", "state", "again", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/DateTimeParserBucket.java#L367-L375
22,222
JodaOrg/joda-time
src/main/java/org/joda/time/format/DateTimeParserBucket.java
DateTimeParserBucket.computeMillis
public long computeMillis(boolean resetFields, CharSequence text) { SavedField[] savedFields = iSavedFields; int count = iSavedFieldsCount; if (iSavedFieldsShared) { // clone so that sort does not affect saved state iSavedFields = savedFields = (SavedField[])iSavedFields.clone(); iSavedFieldsShared = false; } sort(savedFields, count); if (count > 0) { // alter base year for parsing if first field is month or day DurationField months = DurationFieldType.months().getField(iChrono); DurationField days = DurationFieldType.days().getField(iChrono); DurationField first = savedFields[0].iField.getDurationField(); if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) { saveField(DateTimeFieldType.year(), iDefaultYear); return computeMillis(resetFields, text); } } long millis = iMillis; try { for (int i = 0; i < count; i++) { millis = savedFields[i].set(millis, resetFields); } if (resetFields) { for (int i = 0; i < count; i++) { if (!savedFields[i].iField.isLenient()) { millis = savedFields[i].set(millis, i == (count - 1)); } } } } catch (IllegalFieldValueException e) { if (text != null) { e.prependMessage("Cannot parse \"" + text + '"'); } throw e; } if (iOffset != null) { millis -= iOffset; } else if (iZone != null) { int offset = iZone.getOffsetFromLocal(millis); millis -= offset; if (offset != iZone.getOffset(millis)) { String message = "Illegal instant due to time zone offset transition (" + iZone + ')'; if (text != null) { message = "Cannot parse \"" + text + "\": " + message; } throw new IllegalInstantException(message); } } return millis; }
java
public long computeMillis(boolean resetFields, CharSequence text) { SavedField[] savedFields = iSavedFields; int count = iSavedFieldsCount; if (iSavedFieldsShared) { // clone so that sort does not affect saved state iSavedFields = savedFields = (SavedField[])iSavedFields.clone(); iSavedFieldsShared = false; } sort(savedFields, count); if (count > 0) { // alter base year for parsing if first field is month or day DurationField months = DurationFieldType.months().getField(iChrono); DurationField days = DurationFieldType.days().getField(iChrono); DurationField first = savedFields[0].iField.getDurationField(); if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) { saveField(DateTimeFieldType.year(), iDefaultYear); return computeMillis(resetFields, text); } } long millis = iMillis; try { for (int i = 0; i < count; i++) { millis = savedFields[i].set(millis, resetFields); } if (resetFields) { for (int i = 0; i < count; i++) { if (!savedFields[i].iField.isLenient()) { millis = savedFields[i].set(millis, i == (count - 1)); } } } } catch (IllegalFieldValueException e) { if (text != null) { e.prependMessage("Cannot parse \"" + text + '"'); } throw e; } if (iOffset != null) { millis -= iOffset; } else if (iZone != null) { int offset = iZone.getOffsetFromLocal(millis); millis -= offset; if (offset != iZone.getOffset(millis)) { String message = "Illegal instant due to time zone offset transition (" + iZone + ')'; if (text != null) { message = "Cannot parse \"" + text + "\": " + message; } throw new IllegalInstantException(message); } } return millis; }
[ "public", "long", "computeMillis", "(", "boolean", "resetFields", ",", "CharSequence", "text", ")", "{", "SavedField", "[", "]", "savedFields", "=", "iSavedFields", ";", "int", "count", "=", "iSavedFieldsCount", ";", "if", "(", "iSavedFieldsShared", ")", "{", "// clone so that sort does not affect saved state", "iSavedFields", "=", "savedFields", "=", "(", "SavedField", "[", "]", ")", "iSavedFields", ".", "clone", "(", ")", ";", "iSavedFieldsShared", "=", "false", ";", "}", "sort", "(", "savedFields", ",", "count", ")", ";", "if", "(", "count", ">", "0", ")", "{", "// alter base year for parsing if first field is month or day", "DurationField", "months", "=", "DurationFieldType", ".", "months", "(", ")", ".", "getField", "(", "iChrono", ")", ";", "DurationField", "days", "=", "DurationFieldType", ".", "days", "(", ")", ".", "getField", "(", "iChrono", ")", ";", "DurationField", "first", "=", "savedFields", "[", "0", "]", ".", "iField", ".", "getDurationField", "(", ")", ";", "if", "(", "compareReverse", "(", "first", ",", "months", ")", ">=", "0", "&&", "compareReverse", "(", "first", ",", "days", ")", "<=", "0", ")", "{", "saveField", "(", "DateTimeFieldType", ".", "year", "(", ")", ",", "iDefaultYear", ")", ";", "return", "computeMillis", "(", "resetFields", ",", "text", ")", ";", "}", "}", "long", "millis", "=", "iMillis", ";", "try", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "count", ";", "i", "++", ")", "{", "millis", "=", "savedFields", "[", "i", "]", ".", "set", "(", "millis", ",", "resetFields", ")", ";", "}", "if", "(", "resetFields", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "count", ";", "i", "++", ")", "{", "if", "(", "!", "savedFields", "[", "i", "]", ".", "iField", ".", "isLenient", "(", ")", ")", "{", "millis", "=", "savedFields", "[", "i", "]", ".", "set", "(", "millis", ",", "i", "==", "(", "count", "-", "1", ")", ")", ";", "}", "}", "}", "}", "catch", "(", "IllegalFieldValueException", "e", ")", "{", "if", "(", "text", "!=", "null", ")", "{", "e", ".", "prependMessage", "(", "\"Cannot parse \\\"\"", "+", "text", "+", "'", "'", ")", ";", "}", "throw", "e", ";", "}", "if", "(", "iOffset", "!=", "null", ")", "{", "millis", "-=", "iOffset", ";", "}", "else", "if", "(", "iZone", "!=", "null", ")", "{", "int", "offset", "=", "iZone", ".", "getOffsetFromLocal", "(", "millis", ")", ";", "millis", "-=", "offset", ";", "if", "(", "offset", "!=", "iZone", ".", "getOffset", "(", "millis", ")", ")", "{", "String", "message", "=", "\"Illegal instant due to time zone offset transition (\"", "+", "iZone", "+", "'", "'", ";", "if", "(", "text", "!=", "null", ")", "{", "message", "=", "\"Cannot parse \\\"\"", "+", "text", "+", "\"\\\": \"", "+", "message", ";", "}", "throw", "new", "IllegalInstantException", "(", "message", ")", ";", "}", "}", "return", "millis", ";", "}" ]
Computes the parsed datetime by setting the saved fields. This method is idempotent, but it is not thread-safe. @param resetFields false by default, but when true, unsaved field values are cleared @param text optional text being parsed, to be included in any error message @return milliseconds since 1970-01-01T00:00:00Z @throws IllegalArgumentException if any field is out of range @since 2.4
[ "Computes", "the", "parsed", "datetime", "by", "setting", "the", "saved", "fields", ".", "This", "method", "is", "idempotent", "but", "it", "is", "not", "thread", "-", "safe", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/DateTimeParserBucket.java#L424-L478
22,223
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/ISOChronology.java
ISOChronology.getInstance
public static ISOChronology getInstance(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } ISOChronology chrono = cCache.get(zone); if (chrono == null) { chrono = new ISOChronology(ZonedChronology.getInstance(INSTANCE_UTC, zone)); ISOChronology oldChrono = cCache.putIfAbsent(zone, chrono); if (oldChrono != null) { chrono = oldChrono; } } return chrono; }
java
public static ISOChronology getInstance(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } ISOChronology chrono = cCache.get(zone); if (chrono == null) { chrono = new ISOChronology(ZonedChronology.getInstance(INSTANCE_UTC, zone)); ISOChronology oldChrono = cCache.putIfAbsent(zone, chrono); if (oldChrono != null) { chrono = oldChrono; } } return chrono; }
[ "public", "static", "ISOChronology", "getInstance", "(", "DateTimeZone", "zone", ")", "{", "if", "(", "zone", "==", "null", ")", "{", "zone", "=", "DateTimeZone", ".", "getDefault", "(", ")", ";", "}", "ISOChronology", "chrono", "=", "cCache", ".", "get", "(", "zone", ")", ";", "if", "(", "chrono", "==", "null", ")", "{", "chrono", "=", "new", "ISOChronology", "(", "ZonedChronology", ".", "getInstance", "(", "INSTANCE_UTC", ",", "zone", ")", ")", ";", "ISOChronology", "oldChrono", "=", "cCache", ".", "putIfAbsent", "(", "zone", ",", "chrono", ")", ";", "if", "(", "oldChrono", "!=", "null", ")", "{", "chrono", "=", "oldChrono", ";", "}", "}", "return", "chrono", ";", "}" ]
Gets an instance of the ISOChronology in the given time zone. @param zone the time zone to get the chronology in, null is default @return a chronology in the specified time zone
[ "Gets", "an", "instance", "of", "the", "ISOChronology", "in", "the", "given", "time", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/ISOChronology.java#L88-L101
22,224
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/IslamicChronology.java
IslamicChronology.getInstance
public static IslamicChronology getInstance(DateTimeZone zone, LeapYearPatternType leapYears) { if (zone == null) { zone = DateTimeZone.getDefault(); } IslamicChronology chrono; IslamicChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new IslamicChronology[4]; IslamicChronology[] oldChronos = cCache.putIfAbsent(zone, chronos); if (oldChronos != null) { chronos = oldChronos; } } chrono = chronos[leapYears.index]; if (chrono == null) { synchronized (chronos) { chrono = chronos[leapYears.index]; if (chrono == null) { if (zone == DateTimeZone.UTC) { // First create without a lower limit. chrono = new IslamicChronology(null, null, leapYears); // Impose lower limit and make another IslamicChronology. DateTime lowerLimit = new DateTime(1, 1, 1, 0, 0, 0, 0, chrono); chrono = new IslamicChronology( LimitChronology.getInstance(chrono, lowerLimit, null), null, leapYears); } else { chrono = getInstance(DateTimeZone.UTC, leapYears); chrono = new IslamicChronology (ZonedChronology.getInstance(chrono, zone), null, leapYears); } chronos[leapYears.index] = chrono; } } } return chrono; }
java
public static IslamicChronology getInstance(DateTimeZone zone, LeapYearPatternType leapYears) { if (zone == null) { zone = DateTimeZone.getDefault(); } IslamicChronology chrono; IslamicChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new IslamicChronology[4]; IslamicChronology[] oldChronos = cCache.putIfAbsent(zone, chronos); if (oldChronos != null) { chronos = oldChronos; } } chrono = chronos[leapYears.index]; if (chrono == null) { synchronized (chronos) { chrono = chronos[leapYears.index]; if (chrono == null) { if (zone == DateTimeZone.UTC) { // First create without a lower limit. chrono = new IslamicChronology(null, null, leapYears); // Impose lower limit and make another IslamicChronology. DateTime lowerLimit = new DateTime(1, 1, 1, 0, 0, 0, 0, chrono); chrono = new IslamicChronology( LimitChronology.getInstance(chrono, lowerLimit, null), null, leapYears); } else { chrono = getInstance(DateTimeZone.UTC, leapYears); chrono = new IslamicChronology (ZonedChronology.getInstance(chrono, zone), null, leapYears); } chronos[leapYears.index] = chrono; } } } return chrono; }
[ "public", "static", "IslamicChronology", "getInstance", "(", "DateTimeZone", "zone", ",", "LeapYearPatternType", "leapYears", ")", "{", "if", "(", "zone", "==", "null", ")", "{", "zone", "=", "DateTimeZone", ".", "getDefault", "(", ")", ";", "}", "IslamicChronology", "chrono", ";", "IslamicChronology", "[", "]", "chronos", "=", "cCache", ".", "get", "(", "zone", ")", ";", "if", "(", "chronos", "==", "null", ")", "{", "chronos", "=", "new", "IslamicChronology", "[", "4", "]", ";", "IslamicChronology", "[", "]", "oldChronos", "=", "cCache", ".", "putIfAbsent", "(", "zone", ",", "chronos", ")", ";", "if", "(", "oldChronos", "!=", "null", ")", "{", "chronos", "=", "oldChronos", ";", "}", "}", "chrono", "=", "chronos", "[", "leapYears", ".", "index", "]", ";", "if", "(", "chrono", "==", "null", ")", "{", "synchronized", "(", "chronos", ")", "{", "chrono", "=", "chronos", "[", "leapYears", ".", "index", "]", ";", "if", "(", "chrono", "==", "null", ")", "{", "if", "(", "zone", "==", "DateTimeZone", ".", "UTC", ")", "{", "// First create without a lower limit.", "chrono", "=", "new", "IslamicChronology", "(", "null", ",", "null", ",", "leapYears", ")", ";", "// Impose lower limit and make another IslamicChronology.", "DateTime", "lowerLimit", "=", "new", "DateTime", "(", "1", ",", "1", ",", "1", ",", "0", ",", "0", ",", "0", ",", "0", ",", "chrono", ")", ";", "chrono", "=", "new", "IslamicChronology", "(", "LimitChronology", ".", "getInstance", "(", "chrono", ",", "lowerLimit", ",", "null", ")", ",", "null", ",", "leapYears", ")", ";", "}", "else", "{", "chrono", "=", "getInstance", "(", "DateTimeZone", ".", "UTC", ",", "leapYears", ")", ";", "chrono", "=", "new", "IslamicChronology", "(", "ZonedChronology", ".", "getInstance", "(", "chrono", ",", "zone", ")", ",", "null", ",", "leapYears", ")", ";", "}", "chronos", "[", "leapYears", ".", "index", "]", "=", "chrono", ";", "}", "}", "}", "return", "chrono", ";", "}" ]
Gets an instance of the IslamicChronology in the given time zone. @param zone the time zone to get the chronology in, null is default @param leapYears the type defining the leap year pattern @return a chronology in the specified time zone
[ "Gets", "an", "instance", "of", "the", "IslamicChronology", "in", "the", "given", "time", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/IslamicChronology.java#L190-L226
22,225
JodaOrg/joda-time
src/main/java/org/joda/time/field/StrictDateTimeField.java
StrictDateTimeField.getInstance
public static DateTimeField getInstance(DateTimeField field) { if (field == null) { return null; } if (field instanceof LenientDateTimeField) { field = ((LenientDateTimeField)field).getWrappedField(); } if (!field.isLenient()) { return field; } return new StrictDateTimeField(field); }
java
public static DateTimeField getInstance(DateTimeField field) { if (field == null) { return null; } if (field instanceof LenientDateTimeField) { field = ((LenientDateTimeField)field).getWrappedField(); } if (!field.isLenient()) { return field; } return new StrictDateTimeField(field); }
[ "public", "static", "DateTimeField", "getInstance", "(", "DateTimeField", "field", ")", "{", "if", "(", "field", "==", "null", ")", "{", "return", "null", ";", "}", "if", "(", "field", "instanceof", "LenientDateTimeField", ")", "{", "field", "=", "(", "(", "LenientDateTimeField", ")", "field", ")", ".", "getWrappedField", "(", ")", ";", "}", "if", "(", "!", "field", ".", "isLenient", "(", ")", ")", "{", "return", "field", ";", "}", "return", "new", "StrictDateTimeField", "(", "field", ")", ";", "}" ]
Returns a strict version of the given field. If it is already strict, then it is returned as-is. Otherwise, a new StrictDateTimeField is returned.
[ "Returns", "a", "strict", "version", "of", "the", "given", "field", ".", "If", "it", "is", "already", "strict", "then", "it", "is", "returned", "as", "-", "is", ".", "Otherwise", "a", "new", "StrictDateTimeField", "is", "returned", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/StrictDateTimeField.java#L40-L51
22,226
JodaOrg/joda-time
src/main/java/org/joda/time/field/StrictDateTimeField.java
StrictDateTimeField.set
public long set(long instant, int value) { FieldUtils.verifyValueBounds (this, value, getMinimumValue(instant), getMaximumValue(instant)); return super.set(instant, value); }
java
public long set(long instant, int value) { FieldUtils.verifyValueBounds (this, value, getMinimumValue(instant), getMaximumValue(instant)); return super.set(instant, value); }
[ "public", "long", "set", "(", "long", "instant", ",", "int", "value", ")", "{", "FieldUtils", ".", "verifyValueBounds", "(", "this", ",", "value", ",", "getMinimumValue", "(", "instant", ")", ",", "getMaximumValue", "(", "instant", ")", ")", ";", "return", "super", ".", "set", "(", "instant", ",", "value", ")", ";", "}" ]
Does a bounds check before setting the value. @throws IllegalArgumentException if the value is invalid
[ "Does", "a", "bounds", "check", "before", "setting", "the", "value", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/StrictDateTimeField.java#L66-L70
22,227
JodaOrg/joda-time
src/main/java/org/joda/time/field/PreciseDurationDateTimeField.java
PreciseDurationDateTimeField.set
public long set(long instant, int value) { FieldUtils.verifyValueBounds(this, value, getMinimumValue(), getMaximumValueForSet(instant, value)); return instant + (value - get(instant)) * iUnitMillis; }
java
public long set(long instant, int value) { FieldUtils.verifyValueBounds(this, value, getMinimumValue(), getMaximumValueForSet(instant, value)); return instant + (value - get(instant)) * iUnitMillis; }
[ "public", "long", "set", "(", "long", "instant", ",", "int", "value", ")", "{", "FieldUtils", ".", "verifyValueBounds", "(", "this", ",", "value", ",", "getMinimumValue", "(", ")", ",", "getMaximumValueForSet", "(", "instant", ",", "value", ")", ")", ";", "return", "instant", "+", "(", "value", "-", "get", "(", "instant", ")", ")", "*", "iUnitMillis", ";", "}" ]
Set the specified amount of units to the specified time instant. @param instant the milliseconds from 1970-01-01T00:00:00Z to set in @param value value of units to set. @return the updated time instant. @throws IllegalArgumentException if value is too large or too small.
[ "Set", "the", "specified", "amount", "of", "units", "to", "the", "specified", "time", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/PreciseDurationDateTimeField.java#L78-L82
22,228
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.set
public void set(DateTimeFieldType type, int value) { if (type == null) { throw new IllegalArgumentException("Field must not be null"); } setMillis(type.getField(getChronology()).set(getMillis(), value)); }
java
public void set(DateTimeFieldType type, int value) { if (type == null) { throw new IllegalArgumentException("Field must not be null"); } setMillis(type.getField(getChronology()).set(getMillis(), value)); }
[ "public", "void", "set", "(", "DateTimeFieldType", "type", ",", "int", "value", ")", "{", "if", "(", "type", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Field must not be null\"", ")", ";", "}", "setMillis", "(", "type", ".", "getField", "(", "getChronology", "(", ")", ")", ".", "set", "(", "getMillis", "(", ")", ",", "value", ")", ")", ";", "}" ]
Sets the value of one of the fields of the instant, such as hourOfDay. @param type a field type, usually obtained from DateTimeFieldType, not null @param value the value to set the field to @throws IllegalArgumentException if the value is null or invalid
[ "Sets", "the", "value", "of", "one", "of", "the", "fields", "of", "the", "instant", "such", "as", "hourOfDay", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L619-L624
22,229
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.add
public void add(DurationFieldType type, int amount) { if (type == null) { throw new IllegalArgumentException("Field must not be null"); } if (amount != 0) { setMillis(type.getField(getChronology()).add(getMillis(), amount)); } }
java
public void add(DurationFieldType type, int amount) { if (type == null) { throw new IllegalArgumentException("Field must not be null"); } if (amount != 0) { setMillis(type.getField(getChronology()).add(getMillis(), amount)); } }
[ "public", "void", "add", "(", "DurationFieldType", "type", ",", "int", "amount", ")", "{", "if", "(", "type", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Field must not be null\"", ")", ";", "}", "if", "(", "amount", "!=", "0", ")", "{", "setMillis", "(", "type", ".", "getField", "(", "getChronology", "(", ")", ")", ".", "add", "(", "getMillis", "(", ")", ",", "amount", ")", ")", ";", "}", "}" ]
Adds to the instant specifying the duration and multiple to add. @param type a field type, usually obtained from DateTimeFieldType, not null @param amount the amount to add of this duration @throws IllegalArgumentException if the value is null or invalid @throws ArithmeticException if the result exceeds the capacity of the instant
[ "Adds", "to", "the", "instant", "specifying", "the", "duration", "and", "multiple", "to", "add", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L634-L641
22,230
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.setDate
public void setDate( final int year, final int monthOfYear, final int dayOfMonth) { Chronology c = getChronology(); long instantMidnight = c.getDateTimeMillis(year, monthOfYear, dayOfMonth, 0); setDate(instantMidnight); }
java
public void setDate( final int year, final int monthOfYear, final int dayOfMonth) { Chronology c = getChronology(); long instantMidnight = c.getDateTimeMillis(year, monthOfYear, dayOfMonth, 0); setDate(instantMidnight); }
[ "public", "void", "setDate", "(", "final", "int", "year", ",", "final", "int", "monthOfYear", ",", "final", "int", "dayOfMonth", ")", "{", "Chronology", "c", "=", "getChronology", "(", ")", ";", "long", "instantMidnight", "=", "c", ".", "getDateTimeMillis", "(", "year", ",", "monthOfYear", ",", "dayOfMonth", ",", "0", ")", ";", "setDate", "(", "instantMidnight", ")", ";", "}" ]
Set the date from fields. The time part of this object will be unaffected. @param year the year @param monthOfYear the month of the year @param dayOfMonth the day of the month @throws IllegalArgumentException if the value is invalid
[ "Set", "the", "date", "from", "fields", ".", "The", "time", "part", "of", "this", "object", "will", "be", "unaffected", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L952-L959
22,231
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.setTime
public void setTime(final long millis) { int millisOfDay = ISOChronology.getInstanceUTC().millisOfDay().get(millis); setMillis(getChronology().millisOfDay().set(getMillis(), millisOfDay)); }
java
public void setTime(final long millis) { int millisOfDay = ISOChronology.getInstanceUTC().millisOfDay().get(millis); setMillis(getChronology().millisOfDay().set(getMillis(), millisOfDay)); }
[ "public", "void", "setTime", "(", "final", "long", "millis", ")", "{", "int", "millisOfDay", "=", "ISOChronology", ".", "getInstanceUTC", "(", ")", ".", "millisOfDay", "(", ")", ".", "get", "(", "millis", ")", ";", "setMillis", "(", "getChronology", "(", ")", ".", "millisOfDay", "(", ")", ".", "set", "(", "getMillis", "(", ")", ",", "millisOfDay", ")", ")", ";", "}" ]
Set the time from milliseconds. The date part of this object will be unaffected. @param millis an instant to copy the time from, date part ignored @throws IllegalArgumentException if the value is invalid
[ "Set", "the", "time", "from", "milliseconds", ".", "The", "date", "part", "of", "this", "object", "will", "be", "unaffected", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L969-L972
22,232
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.setTime
public void setTime(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); Chronology instantChrono = DateTimeUtils.getInstantChronology(instant); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(DateTimeZone.UTC, instantMillis); } setTime(instantMillis); }
java
public void setTime(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); Chronology instantChrono = DateTimeUtils.getInstantChronology(instant); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(DateTimeZone.UTC, instantMillis); } setTime(instantMillis); }
[ "public", "void", "setTime", "(", "final", "ReadableInstant", "instant", ")", "{", "long", "instantMillis", "=", "DateTimeUtils", ".", "getInstantMillis", "(", "instant", ")", ";", "Chronology", "instantChrono", "=", "DateTimeUtils", ".", "getInstantChronology", "(", "instant", ")", ";", "DateTimeZone", "zone", "=", "instantChrono", ".", "getZone", "(", ")", ";", "if", "(", "zone", "!=", "null", ")", "{", "instantMillis", "=", "zone", ".", "getMillisKeepLocal", "(", "DateTimeZone", ".", "UTC", ",", "instantMillis", ")", ";", "}", "setTime", "(", "instantMillis", ")", ";", "}" ]
Set the time from another instant. The date part of this object will be unaffected. @param instant an instant to copy the time from, date part ignored @throws IllegalArgumentException if the object is invalid
[ "Set", "the", "time", "from", "another", "instant", ".", "The", "date", "part", "of", "this", "object", "will", "be", "unaffected", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L981-L989
22,233
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.setTime
public void setTime( final int hour, final int minuteOfHour, final int secondOfMinute, final int millisOfSecond) { long instant = getChronology().getDateTimeMillis( getMillis(), hour, minuteOfHour, secondOfMinute, millisOfSecond); setMillis(instant); }
java
public void setTime( final int hour, final int minuteOfHour, final int secondOfMinute, final int millisOfSecond) { long instant = getChronology().getDateTimeMillis( getMillis(), hour, minuteOfHour, secondOfMinute, millisOfSecond); setMillis(instant); }
[ "public", "void", "setTime", "(", "final", "int", "hour", ",", "final", "int", "minuteOfHour", ",", "final", "int", "secondOfMinute", ",", "final", "int", "millisOfSecond", ")", "{", "long", "instant", "=", "getChronology", "(", ")", ".", "getDateTimeMillis", "(", "getMillis", "(", ")", ",", "hour", ",", "minuteOfHour", ",", "secondOfMinute", ",", "millisOfSecond", ")", ";", "setMillis", "(", "instant", ")", ";", "}" ]
Set the time from fields. The date part of this object will be unaffected. @param hour the hour @param minuteOfHour the minute of the hour @param secondOfMinute the second of the minute @param millisOfSecond the millisecond of the second @throws IllegalArgumentException if the value is invalid
[ "Set", "the", "time", "from", "fields", ".", "The", "date", "part", "of", "this", "object", "will", "be", "unaffected", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L1001-L1009
22,234
JodaOrg/joda-time
src/main/java/org/joda/time/MutableDateTime.java
MutableDateTime.setDateTime
public void setDateTime( final int year, final int monthOfYear, final int dayOfMonth, final int hourOfDay, final int minuteOfHour, final int secondOfMinute, final int millisOfSecond) { long instant = getChronology().getDateTimeMillis( year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); setMillis(instant); }
java
public void setDateTime( final int year, final int monthOfYear, final int dayOfMonth, final int hourOfDay, final int minuteOfHour, final int secondOfMinute, final int millisOfSecond) { long instant = getChronology().getDateTimeMillis( year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); setMillis(instant); }
[ "public", "void", "setDateTime", "(", "final", "int", "year", ",", "final", "int", "monthOfYear", ",", "final", "int", "dayOfMonth", ",", "final", "int", "hourOfDay", ",", "final", "int", "minuteOfHour", ",", "final", "int", "secondOfMinute", ",", "final", "int", "millisOfSecond", ")", "{", "long", "instant", "=", "getChronology", "(", ")", ".", "getDateTimeMillis", "(", "year", ",", "monthOfYear", ",", "dayOfMonth", ",", "hourOfDay", ",", "minuteOfHour", ",", "secondOfMinute", ",", "millisOfSecond", ")", ";", "setMillis", "(", "instant", ")", ";", "}" ]
Set the date and time from fields. @param year the year @param monthOfYear the month of the year @param dayOfMonth the day of the month @param hourOfDay the hour of the day @param minuteOfHour the minute of the hour @param secondOfMinute the second of the minute @param millisOfSecond the millisecond of the second @throws IllegalArgumentException if the value is invalid
[ "Set", "the", "date", "and", "time", "from", "fields", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableDateTime.java#L1023-L1034
22,235
JodaOrg/joda-time
src/main/java/org/joda/time/convert/ConverterSet.java
ConverterSet.select
Converter select(Class<?> type) throws IllegalStateException { // Check the hashtable first. Entry[] entries = iSelectEntries; int length = entries.length; int index = type == null ? 0 : type.hashCode() & (length - 1); Entry e; // This loop depends on there being at least one null slot. while ((e = entries[index]) != null) { if (e.iType == type) { return e.iConverter; } if (++index >= length) { index = 0; } } // Not found in the hashtable, so do actual work. Converter converter = selectSlow(this, type); e = new Entry(type, converter); // Save the entry for future selects. This class must be threadsafe, // but there is no synchronization. Since the hashtable is being used // as a cache, it is okay to destroy existing entries. This isn't // likely to occur unless there is a high amount of concurrency. As // time goes on, cache updates will occur less often, and the cache // will fill with all the necessary entries. // Do all updates on a copy: slots in iSelectEntries must not be // updated by multiple threads as this can allow all null slots to be // consumed. entries = (Entry[])entries.clone(); // Add new entry. entries[index] = e; // Verify that at least one null slot exists! for (int i=0; i<length; i++) { if (entries[i] == null) { // Found a null slot, swap in new hashtable. iSelectEntries = entries; return converter; } } // Double capacity and re-hash. int newLength = length << 1; Entry[] newEntries = new Entry[newLength]; for (int i=0; i<length; i++) { e = entries[i]; type = e.iType; index = type == null ? 0 : type.hashCode() & (newLength - 1); while (newEntries[index] != null) { if (++index >= newLength) { index = 0; } } newEntries[index] = e; } // Swap in new hashtable. iSelectEntries = newEntries; return converter; }
java
Converter select(Class<?> type) throws IllegalStateException { // Check the hashtable first. Entry[] entries = iSelectEntries; int length = entries.length; int index = type == null ? 0 : type.hashCode() & (length - 1); Entry e; // This loop depends on there being at least one null slot. while ((e = entries[index]) != null) { if (e.iType == type) { return e.iConverter; } if (++index >= length) { index = 0; } } // Not found in the hashtable, so do actual work. Converter converter = selectSlow(this, type); e = new Entry(type, converter); // Save the entry for future selects. This class must be threadsafe, // but there is no synchronization. Since the hashtable is being used // as a cache, it is okay to destroy existing entries. This isn't // likely to occur unless there is a high amount of concurrency. As // time goes on, cache updates will occur less often, and the cache // will fill with all the necessary entries. // Do all updates on a copy: slots in iSelectEntries must not be // updated by multiple threads as this can allow all null slots to be // consumed. entries = (Entry[])entries.clone(); // Add new entry. entries[index] = e; // Verify that at least one null slot exists! for (int i=0; i<length; i++) { if (entries[i] == null) { // Found a null slot, swap in new hashtable. iSelectEntries = entries; return converter; } } // Double capacity and re-hash. int newLength = length << 1; Entry[] newEntries = new Entry[newLength]; for (int i=0; i<length; i++) { e = entries[i]; type = e.iType; index = type == null ? 0 : type.hashCode() & (newLength - 1); while (newEntries[index] != null) { if (++index >= newLength) { index = 0; } } newEntries[index] = e; } // Swap in new hashtable. iSelectEntries = newEntries; return converter; }
[ "Converter", "select", "(", "Class", "<", "?", ">", "type", ")", "throws", "IllegalStateException", "{", "// Check the hashtable first.", "Entry", "[", "]", "entries", "=", "iSelectEntries", ";", "int", "length", "=", "entries", ".", "length", ";", "int", "index", "=", "type", "==", "null", "?", "0", ":", "type", ".", "hashCode", "(", ")", "&", "(", "length", "-", "1", ")", ";", "Entry", "e", ";", "// This loop depends on there being at least one null slot.", "while", "(", "(", "e", "=", "entries", "[", "index", "]", ")", "!=", "null", ")", "{", "if", "(", "e", ".", "iType", "==", "type", ")", "{", "return", "e", ".", "iConverter", ";", "}", "if", "(", "++", "index", ">=", "length", ")", "{", "index", "=", "0", ";", "}", "}", "// Not found in the hashtable, so do actual work.", "Converter", "converter", "=", "selectSlow", "(", "this", ",", "type", ")", ";", "e", "=", "new", "Entry", "(", "type", ",", "converter", ")", ";", "// Save the entry for future selects. This class must be threadsafe,", "// but there is no synchronization. Since the hashtable is being used", "// as a cache, it is okay to destroy existing entries. This isn't", "// likely to occur unless there is a high amount of concurrency. As", "// time goes on, cache updates will occur less often, and the cache", "// will fill with all the necessary entries.", "// Do all updates on a copy: slots in iSelectEntries must not be", "// updated by multiple threads as this can allow all null slots to be", "// consumed.", "entries", "=", "(", "Entry", "[", "]", ")", "entries", ".", "clone", "(", ")", ";", "// Add new entry.", "entries", "[", "index", "]", "=", "e", ";", "// Verify that at least one null slot exists!", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "if", "(", "entries", "[", "i", "]", "==", "null", ")", "{", "// Found a null slot, swap in new hashtable.", "iSelectEntries", "=", "entries", ";", "return", "converter", ";", "}", "}", "// Double capacity and re-hash.", "int", "newLength", "=", "length", "<<", "1", ";", "Entry", "[", "]", "newEntries", "=", "new", "Entry", "[", "newLength", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "e", "=", "entries", "[", "i", "]", ";", "type", "=", "e", ".", "iType", ";", "index", "=", "type", "==", "null", "?", "0", ":", "type", ".", "hashCode", "(", ")", "&", "(", "newLength", "-", "1", ")", ";", "while", "(", "newEntries", "[", "index", "]", "!=", "null", ")", "{", "if", "(", "++", "index", ">=", "newLength", ")", "{", "index", "=", "0", ";", "}", "}", "newEntries", "[", "index", "]", "=", "e", ";", "}", "// Swap in new hashtable.", "iSelectEntries", "=", "newEntries", ";", "return", "converter", ";", "}" ]
Returns the closest matching converter for the given type, or null if none found. @param type type to select, which may be null @throws IllegalStateException if multiple converters match the type equally well
[ "Returns", "the", "closest", "matching", "converter", "for", "the", "given", "type", "or", "null", "if", "none", "found", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/ConverterSet.java#L47-L112
22,236
JodaOrg/joda-time
src/main/java/org/joda/time/convert/ConverterSet.java
ConverterSet.add
ConverterSet add(Converter converter, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; for (int i=0; i<length; i++) { Converter existing = converters[i]; if (converter.equals(existing)) { // Already in the set. if (removed != null) { removed[0] = null; } return this; } if (converter.getSupportedType() == existing.getSupportedType()) { // Replace the converter. Converter[] copy = new Converter[length]; for (int j=0; j<length; j++) { if (j != i) { copy[j] = converters[j]; } else { copy[j] = converter; } } if (removed != null) { removed[0] = existing; } return new ConverterSet(copy); } } // Not found, so add it. Converter[] copy = new Converter[length + 1]; System.arraycopy(converters, 0, copy, 0, length); copy[length] = converter; if (removed != null) { removed[0] = null; } return new ConverterSet(copy); }
java
ConverterSet add(Converter converter, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; for (int i=0; i<length; i++) { Converter existing = converters[i]; if (converter.equals(existing)) { // Already in the set. if (removed != null) { removed[0] = null; } return this; } if (converter.getSupportedType() == existing.getSupportedType()) { // Replace the converter. Converter[] copy = new Converter[length]; for (int j=0; j<length; j++) { if (j != i) { copy[j] = converters[j]; } else { copy[j] = converter; } } if (removed != null) { removed[0] = existing; } return new ConverterSet(copy); } } // Not found, so add it. Converter[] copy = new Converter[length + 1]; System.arraycopy(converters, 0, copy, 0, length); copy[length] = converter; if (removed != null) { removed[0] = null; } return new ConverterSet(copy); }
[ "ConverterSet", "add", "(", "Converter", "converter", ",", "Converter", "[", "]", "removed", ")", "{", "Converter", "[", "]", "converters", "=", "iConverters", ";", "int", "length", "=", "converters", ".", "length", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "Converter", "existing", "=", "converters", "[", "i", "]", ";", "if", "(", "converter", ".", "equals", "(", "existing", ")", ")", "{", "// Already in the set.", "if", "(", "removed", "!=", "null", ")", "{", "removed", "[", "0", "]", "=", "null", ";", "}", "return", "this", ";", "}", "if", "(", "converter", ".", "getSupportedType", "(", ")", "==", "existing", ".", "getSupportedType", "(", ")", ")", "{", "// Replace the converter.", "Converter", "[", "]", "copy", "=", "new", "Converter", "[", "length", "]", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "length", ";", "j", "++", ")", "{", "if", "(", "j", "!=", "i", ")", "{", "copy", "[", "j", "]", "=", "converters", "[", "j", "]", ";", "}", "else", "{", "copy", "[", "j", "]", "=", "converter", ";", "}", "}", "if", "(", "removed", "!=", "null", ")", "{", "removed", "[", "0", "]", "=", "existing", ";", "}", "return", "new", "ConverterSet", "(", "copy", ")", ";", "}", "}", "// Not found, so add it.", "Converter", "[", "]", "copy", "=", "new", "Converter", "[", "length", "+", "1", "]", ";", "System", ".", "arraycopy", "(", "converters", ",", "0", ",", "copy", ",", "0", ",", "length", ")", ";", "copy", "[", "length", "]", "=", "converter", ";", "if", "(", "removed", "!=", "null", ")", "{", "removed", "[", "0", "]", "=", "null", ";", "}", "return", "new", "ConverterSet", "(", "copy", ")", ";", "}" ]
Returns a copy of this set, with the given converter added. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, the original set is returned. @param converter converter to add, must not be null @param removed if not null, element 0 is set to the removed converter @throws NullPointerException if converter is null
[ "Returns", "a", "copy", "of", "this", "set", "with", "the", "given", "converter", "added", ".", "If", "a", "matching", "converter", "is", "already", "in", "the", "set", "the", "given", "converter", "replaces", "it", ".", "If", "the", "converter", "is", "exactly", "the", "same", "as", "one", "already", "in", "the", "set", "the", "original", "set", "is", "returned", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/ConverterSet.java#L138-L180
22,237
JodaOrg/joda-time
src/main/java/org/joda/time/convert/ConverterSet.java
ConverterSet.remove
ConverterSet remove(Converter converter, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; for (int i=0; i<length; i++) { if (converter.equals(converters[i])) { return remove(i, removed); } } // Not found. if (removed != null) { removed[0] = null; } return this; }
java
ConverterSet remove(Converter converter, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; for (int i=0; i<length; i++) { if (converter.equals(converters[i])) { return remove(i, removed); } } // Not found. if (removed != null) { removed[0] = null; } return this; }
[ "ConverterSet", "remove", "(", "Converter", "converter", ",", "Converter", "[", "]", "removed", ")", "{", "Converter", "[", "]", "converters", "=", "iConverters", ";", "int", "length", "=", "converters", ".", "length", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "if", "(", "converter", ".", "equals", "(", "converters", "[", "i", "]", ")", ")", "{", "return", "remove", "(", "i", ",", "removed", ")", ";", "}", "}", "// Not found.", "if", "(", "removed", "!=", "null", ")", "{", "removed", "[", "0", "]", "=", "null", ";", "}", "return", "this", ";", "}" ]
Returns a copy of this set, with the given converter removed. If the converter was not in the set, the original set is returned. @param converter converter to remove, must not be null @param removed if not null, element 0 is set to the removed converter @throws NullPointerException if converter is null
[ "Returns", "a", "copy", "of", "this", "set", "with", "the", "given", "converter", "removed", ".", "If", "the", "converter", "was", "not", "in", "the", "set", "the", "original", "set", "is", "returned", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/ConverterSet.java#L190-L205
22,238
JodaOrg/joda-time
src/main/java/org/joda/time/convert/ConverterSet.java
ConverterSet.remove
ConverterSet remove(final int index, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; if (index >= length) { throw new IndexOutOfBoundsException(); } if (removed != null) { removed[0] = converters[index]; } Converter[] copy = new Converter[length - 1]; int j = 0; for (int i=0; i<length; i++) { if (i != index) { copy[j++] = converters[i]; } } return new ConverterSet(copy); }
java
ConverterSet remove(final int index, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; if (index >= length) { throw new IndexOutOfBoundsException(); } if (removed != null) { removed[0] = converters[index]; } Converter[] copy = new Converter[length - 1]; int j = 0; for (int i=0; i<length; i++) { if (i != index) { copy[j++] = converters[i]; } } return new ConverterSet(copy); }
[ "ConverterSet", "remove", "(", "final", "int", "index", ",", "Converter", "[", "]", "removed", ")", "{", "Converter", "[", "]", "converters", "=", "iConverters", ";", "int", "length", "=", "converters", ".", "length", ";", "if", "(", "index", ">=", "length", ")", "{", "throw", "new", "IndexOutOfBoundsException", "(", ")", ";", "}", "if", "(", "removed", "!=", "null", ")", "{", "removed", "[", "0", "]", "=", "converters", "[", "index", "]", ";", "}", "Converter", "[", "]", "copy", "=", "new", "Converter", "[", "length", "-", "1", "]", ";", "int", "j", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "if", "(", "i", "!=", "index", ")", "{", "copy", "[", "j", "++", "]", "=", "converters", "[", "i", "]", ";", "}", "}", "return", "new", "ConverterSet", "(", "copy", ")", ";", "}" ]
Returns a copy of this set, with the converter at the given index removed. @param index index of converter to remove @param removed if not null, element 0 is set to the removed converter @throws IndexOutOfBoundsException if the index is invalid
[ "Returns", "a", "copy", "of", "this", "set", "with", "the", "converter", "at", "the", "given", "index", "removed", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/ConverterSet.java#L215-L236
22,239
JodaOrg/joda-time
src/main/java/org/joda/time/convert/ConverterSet.java
ConverterSet.selectSlow
private static Converter selectSlow(ConverterSet set, Class<?> type) { Converter[] converters = set.iConverters; int length = converters.length; Converter converter; for (int i=length; --i>=0; ) { converter = converters[i]; Class<?> supportedType = converter.getSupportedType(); if (supportedType == type) { // Exact match. return converter; } if (supportedType == null || (type != null && !supportedType.isAssignableFrom(type))) { // Eliminate the impossible. set = set.remove(i, null); converters = set.iConverters; length = converters.length; } } // Haven't found exact match, so check what remains in the set. if (type == null || length == 0) { return null; } if (length == 1) { // Found the one best match. return converters[0]; } // At this point, there exist multiple potential converters. // Eliminate supertypes. for (int i=length; --i>=0; ) { converter = converters[i]; Class<?> supportedType = converter.getSupportedType(); for (int j=length; --j>=0; ) { if (j != i && converters[j].getSupportedType().isAssignableFrom(supportedType)) { // Eliminate supertype. set = set.remove(j, null); converters = set.iConverters; length = converters.length; i = length - 1; } } } // Check what remains in the set. if (length == 1) { // Found the one best match. return converters[0]; } // Class c implements a, b {} // Converters exist only for a and b. Which is better? Neither. StringBuilder msg = new StringBuilder(); msg.append("Unable to find best converter for type \""); msg.append(type.getName()); msg.append("\" from remaining set: "); for (int i=0; i<length; i++) { converter = converters[i]; Class<?> supportedType = converter.getSupportedType(); msg.append(converter.getClass().getName()); msg.append('['); msg.append(supportedType == null ? null : supportedType.getName()); msg.append("], "); } throw new IllegalStateException(msg.toString()); }
java
private static Converter selectSlow(ConverterSet set, Class<?> type) { Converter[] converters = set.iConverters; int length = converters.length; Converter converter; for (int i=length; --i>=0; ) { converter = converters[i]; Class<?> supportedType = converter.getSupportedType(); if (supportedType == type) { // Exact match. return converter; } if (supportedType == null || (type != null && !supportedType.isAssignableFrom(type))) { // Eliminate the impossible. set = set.remove(i, null); converters = set.iConverters; length = converters.length; } } // Haven't found exact match, so check what remains in the set. if (type == null || length == 0) { return null; } if (length == 1) { // Found the one best match. return converters[0]; } // At this point, there exist multiple potential converters. // Eliminate supertypes. for (int i=length; --i>=0; ) { converter = converters[i]; Class<?> supportedType = converter.getSupportedType(); for (int j=length; --j>=0; ) { if (j != i && converters[j].getSupportedType().isAssignableFrom(supportedType)) { // Eliminate supertype. set = set.remove(j, null); converters = set.iConverters; length = converters.length; i = length - 1; } } } // Check what remains in the set. if (length == 1) { // Found the one best match. return converters[0]; } // Class c implements a, b {} // Converters exist only for a and b. Which is better? Neither. StringBuilder msg = new StringBuilder(); msg.append("Unable to find best converter for type \""); msg.append(type.getName()); msg.append("\" from remaining set: "); for (int i=0; i<length; i++) { converter = converters[i]; Class<?> supportedType = converter.getSupportedType(); msg.append(converter.getClass().getName()); msg.append('['); msg.append(supportedType == null ? null : supportedType.getName()); msg.append("], "); } throw new IllegalStateException(msg.toString()); }
[ "private", "static", "Converter", "selectSlow", "(", "ConverterSet", "set", ",", "Class", "<", "?", ">", "type", ")", "{", "Converter", "[", "]", "converters", "=", "set", ".", "iConverters", ";", "int", "length", "=", "converters", ".", "length", ";", "Converter", "converter", ";", "for", "(", "int", "i", "=", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "converter", "=", "converters", "[", "i", "]", ";", "Class", "<", "?", ">", "supportedType", "=", "converter", ".", "getSupportedType", "(", ")", ";", "if", "(", "supportedType", "==", "type", ")", "{", "// Exact match.", "return", "converter", ";", "}", "if", "(", "supportedType", "==", "null", "||", "(", "type", "!=", "null", "&&", "!", "supportedType", ".", "isAssignableFrom", "(", "type", ")", ")", ")", "{", "// Eliminate the impossible.", "set", "=", "set", ".", "remove", "(", "i", ",", "null", ")", ";", "converters", "=", "set", ".", "iConverters", ";", "length", "=", "converters", ".", "length", ";", "}", "}", "// Haven't found exact match, so check what remains in the set.", "if", "(", "type", "==", "null", "||", "length", "==", "0", ")", "{", "return", "null", ";", "}", "if", "(", "length", "==", "1", ")", "{", "// Found the one best match.", "return", "converters", "[", "0", "]", ";", "}", "// At this point, there exist multiple potential converters.", "// Eliminate supertypes.", "for", "(", "int", "i", "=", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "converter", "=", "converters", "[", "i", "]", ";", "Class", "<", "?", ">", "supportedType", "=", "converter", ".", "getSupportedType", "(", ")", ";", "for", "(", "int", "j", "=", "length", ";", "--", "j", ">=", "0", ";", ")", "{", "if", "(", "j", "!=", "i", "&&", "converters", "[", "j", "]", ".", "getSupportedType", "(", ")", ".", "isAssignableFrom", "(", "supportedType", ")", ")", "{", "// Eliminate supertype.", "set", "=", "set", ".", "remove", "(", "j", ",", "null", ")", ";", "converters", "=", "set", ".", "iConverters", ";", "length", "=", "converters", ".", "length", ";", "i", "=", "length", "-", "1", ";", "}", "}", "}", "// Check what remains in the set.", "if", "(", "length", "==", "1", ")", "{", "// Found the one best match.", "return", "converters", "[", "0", "]", ";", "}", "// Class c implements a, b {}", "// Converters exist only for a and b. Which is better? Neither.", "StringBuilder", "msg", "=", "new", "StringBuilder", "(", ")", ";", "msg", ".", "append", "(", "\"Unable to find best converter for type \\\"\"", ")", ";", "msg", ".", "append", "(", "type", ".", "getName", "(", ")", ")", ";", "msg", ".", "append", "(", "\"\\\" from remaining set: \"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "converter", "=", "converters", "[", "i", "]", ";", "Class", "<", "?", ">", "supportedType", "=", "converter", ".", "getSupportedType", "(", ")", ";", "msg", ".", "append", "(", "converter", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "msg", ".", "append", "(", "'", "'", ")", ";", "msg", ".", "append", "(", "supportedType", "==", "null", "?", "null", ":", "supportedType", ".", "getName", "(", ")", ")", ";", "msg", ".", "append", "(", "\"], \"", ")", ";", "}", "throw", "new", "IllegalStateException", "(", "msg", ".", "toString", "(", ")", ")", ";", "}" ]
Returns the closest matching converter for the given type, but not very efficiently.
[ "Returns", "the", "closest", "matching", "converter", "for", "the", "given", "type", "but", "not", "very", "efficiently", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/ConverterSet.java#L242-L316
22,240
JodaOrg/joda-time
src/main/java/org/joda/time/convert/ConverterManager.java
ConverterManager.checkAlterIntervalConverters
private void checkAlterIntervalConverters() throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new JodaTimePermission("ConverterManager.alterIntervalConverters")); } }
java
private void checkAlterIntervalConverters() throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new JodaTimePermission("ConverterManager.alterIntervalConverters")); } }
[ "private", "void", "checkAlterIntervalConverters", "(", ")", "throws", "SecurityException", "{", "SecurityManager", "sm", "=", "System", ".", "getSecurityManager", "(", ")", ";", "if", "(", "sm", "!=", "null", ")", "{", "sm", ".", "checkPermission", "(", "new", "JodaTimePermission", "(", "\"ConverterManager.alterIntervalConverters\"", ")", ")", ";", "}", "}" ]
Checks whether the user has permission 'ConverterManager.alterIntervalConverters'. @throws SecurityException if the user does not have the permission
[ "Checks", "whether", "the", "user", "has", "permission", "ConverterManager", ".", "alterIntervalConverters", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/ConverterManager.java#L577-L582
22,241
JodaOrg/joda-time
src/main/java/org/joda/time/field/BaseDateTimeField.java
BaseDateTimeField.roundHalfFloor
public long roundHalfFloor(long instant) { long floor = roundFloor(instant); long ceiling = roundCeiling(instant); long diffFromFloor = instant - floor; long diffToCeiling = ceiling - instant; if (diffFromFloor <= diffToCeiling) { // Closer to the floor, or halfway - round floor return floor; } else { return ceiling; } }
java
public long roundHalfFloor(long instant) { long floor = roundFloor(instant); long ceiling = roundCeiling(instant); long diffFromFloor = instant - floor; long diffToCeiling = ceiling - instant; if (diffFromFloor <= diffToCeiling) { // Closer to the floor, or halfway - round floor return floor; } else { return ceiling; } }
[ "public", "long", "roundHalfFloor", "(", "long", "instant", ")", "{", "long", "floor", "=", "roundFloor", "(", "instant", ")", ";", "long", "ceiling", "=", "roundCeiling", "(", "instant", ")", ";", "long", "diffFromFloor", "=", "instant", "-", "floor", ";", "long", "diffToCeiling", "=", "ceiling", "-", "instant", ";", "if", "(", "diffFromFloor", "<=", "diffToCeiling", ")", "{", "// Closer to the floor, or halfway - round floor", "return", "floor", ";", "}", "else", "{", "return", "ceiling", ";", "}", "}" ]
Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor or is exactly halfway, this function behaves like roundFloor. If the millisecond value is closer to the ceiling, this function behaves like roundCeiling. @param instant the milliseconds from 1970-01-01T00:00:00Z to round @return rounded milliseconds
[ "Round", "to", "the", "nearest", "whole", "unit", "of", "this", "field", ".", "If", "the", "given", "millisecond", "value", "is", "closer", "to", "the", "floor", "or", "is", "exactly", "halfway", "this", "function", "behaves", "like", "roundFloor", ".", "If", "the", "millisecond", "value", "is", "closer", "to", "the", "ceiling", "this", "function", "behaves", "like", "roundCeiling", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/BaseDateTimeField.java#L902-L915
22,242
JodaOrg/joda-time
src/main/java/org/joda/time/field/BaseDateTimeField.java
BaseDateTimeField.roundHalfCeiling
public long roundHalfCeiling(long instant) { long floor = roundFloor(instant); long ceiling = roundCeiling(instant); long diffFromFloor = instant - floor; long diffToCeiling = ceiling - instant; if (diffToCeiling <= diffFromFloor) { // Closer to the ceiling, or halfway - round ceiling return ceiling; } else { return floor; } }
java
public long roundHalfCeiling(long instant) { long floor = roundFloor(instant); long ceiling = roundCeiling(instant); long diffFromFloor = instant - floor; long diffToCeiling = ceiling - instant; if (diffToCeiling <= diffFromFloor) { // Closer to the ceiling, or halfway - round ceiling return ceiling; } else { return floor; } }
[ "public", "long", "roundHalfCeiling", "(", "long", "instant", ")", "{", "long", "floor", "=", "roundFloor", "(", "instant", ")", ";", "long", "ceiling", "=", "roundCeiling", "(", "instant", ")", ";", "long", "diffFromFloor", "=", "instant", "-", "floor", ";", "long", "diffToCeiling", "=", "ceiling", "-", "instant", ";", "if", "(", "diffToCeiling", "<=", "diffFromFloor", ")", "{", "// Closer to the ceiling, or halfway - round ceiling", "return", "ceiling", ";", "}", "else", "{", "return", "floor", ";", "}", "}" ]
Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor, this function behaves like roundFloor. If the millisecond value is closer to the ceiling or is exactly halfway, this function behaves like roundCeiling. @param instant the milliseconds from 1970-01-01T00:00:00Z to round @return rounded milliseconds
[ "Round", "to", "the", "nearest", "whole", "unit", "of", "this", "field", ".", "If", "the", "given", "millisecond", "value", "is", "closer", "to", "the", "floor", "this", "function", "behaves", "like", "roundFloor", ".", "If", "the", "millisecond", "value", "is", "closer", "to", "the", "ceiling", "or", "is", "exactly", "halfway", "this", "function", "behaves", "like", "roundCeiling", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/BaseDateTimeField.java#L926-L939
22,243
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/GJYearOfEraDateTimeField.java
GJYearOfEraDateTimeField.set
public long set(long instant, int year) { FieldUtils.verifyValueBounds(this, year, 1, getMaximumValue()); if (iChronology.getYear(instant) <= 0) { year = 1 - year; } return super.set(instant, year); }
java
public long set(long instant, int year) { FieldUtils.verifyValueBounds(this, year, 1, getMaximumValue()); if (iChronology.getYear(instant) <= 0) { year = 1 - year; } return super.set(instant, year); }
[ "public", "long", "set", "(", "long", "instant", ",", "int", "year", ")", "{", "FieldUtils", ".", "verifyValueBounds", "(", "this", ",", "year", ",", "1", ",", "getMaximumValue", "(", ")", ")", ";", "if", "(", "iChronology", ".", "getYear", "(", "instant", ")", "<=", "0", ")", "{", "year", "=", "1", "-", "year", ";", "}", "return", "super", ".", "set", "(", "instant", ",", "year", ")", ";", "}" ]
Set the year component of the specified time instant. @param instant the time instant in millis to update. @param year the year (0,292278994) to update the time to. @return the updated time instant. @throws IllegalArgumentException if year is invalid.
[ "Set", "the", "year", "component", "of", "the", "specified", "time", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/GJYearOfEraDateTimeField.java#L91-L97
22,244
JodaOrg/joda-time
src/main/java/org/joda/time/base/BaseInterval.java
BaseInterval.setInterval
protected void setInterval(long startInstant, long endInstant, Chronology chrono) { checkInterval(startInstant, endInstant); iStartMillis = startInstant; iEndMillis = endInstant; iChronology = DateTimeUtils.getChronology(chrono); }
java
protected void setInterval(long startInstant, long endInstant, Chronology chrono) { checkInterval(startInstant, endInstant); iStartMillis = startInstant; iEndMillis = endInstant; iChronology = DateTimeUtils.getChronology(chrono); }
[ "protected", "void", "setInterval", "(", "long", "startInstant", ",", "long", "endInstant", ",", "Chronology", "chrono", ")", "{", "checkInterval", "(", "startInstant", ",", "endInstant", ")", ";", "iStartMillis", "=", "startInstant", ";", "iEndMillis", "=", "endInstant", ";", "iChronology", "=", "DateTimeUtils", ".", "getChronology", "(", "chrono", ")", ";", "}" ]
Sets this interval from two millisecond instants and a chronology. @param startInstant the start of the time interval @param endInstant the start of the time interval @param chrono the chronology, not null @throws IllegalArgumentException if the end is before the start
[ "Sets", "this", "interval", "from", "two", "millisecond", "instants", "and", "a", "chronology", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BaseInterval.java#L247-L252
22,245
JodaOrg/joda-time
src/main/java/org/joda/time/convert/DateConverter.java
DateConverter.getInstantMillis
public long getInstantMillis(Object object, Chronology chrono) { Date date = (Date) object; return date.getTime(); }
java
public long getInstantMillis(Object object, Chronology chrono) { Date date = (Date) object; return date.getTime(); }
[ "public", "long", "getInstantMillis", "(", "Object", "object", ",", "Chronology", "chrono", ")", "{", "Date", "date", "=", "(", "Date", ")", "object", ";", "return", "date", ".", "getTime", "(", ")", ";", "}" ]
Gets the millis, which is the Date millis value. @param object the Date to convert, must not be null @param chrono the non-null result of getChronology @return the millisecond value @throws NullPointerException if the object is null @throws ClassCastException if the object is an invalid type
[ "Gets", "the", "millis", "which", "is", "the", "Date", "millis", "value", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/DateConverter.java#L54-L57
22,246
JodaOrg/joda-time
src/main/java/org/joda/time/convert/NullConverter.java
NullConverter.setInto
public void setInto(ReadWritablePeriod duration, Object object, Chronology chrono) { duration.setPeriod((Period) null); }
java
public void setInto(ReadWritablePeriod duration, Object object, Chronology chrono) { duration.setPeriod((Period) null); }
[ "public", "void", "setInto", "(", "ReadWritablePeriod", "duration", ",", "Object", "object", ",", "Chronology", "chrono", ")", "{", "duration", ".", "setPeriod", "(", "(", "Period", ")", "null", ")", ";", "}" ]
Sets the given ReadWritableDuration to zero milliseconds. @param duration duration to get modified @param object the object to convert, which is null @param chrono the chronology to use @throws NullPointerException if the duration is null
[ "Sets", "the", "given", "ReadWritableDuration", "to", "zero", "milliseconds", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/convert/NullConverter.java#L68-L70
22,247
JodaOrg/joda-time
src/main/java/org/joda/time/format/ISOPeriodFormat.java
ISOPeriodFormat.standard
public static PeriodFormatter standard() { if (cStandard == null) { cStandard = new PeriodFormatterBuilder() .appendLiteral("P") .appendYears() .appendSuffix("Y") .appendMonths() .appendSuffix("M") .appendWeeks() .appendSuffix("W") .appendDays() .appendSuffix("D") .appendSeparatorIfFieldsAfter("T") .appendHours() .appendSuffix("H") .appendMinutes() .appendSuffix("M") .appendSecondsWithOptionalMillis() .appendSuffix("S") .toFormatter(); } return cStandard; }
java
public static PeriodFormatter standard() { if (cStandard == null) { cStandard = new PeriodFormatterBuilder() .appendLiteral("P") .appendYears() .appendSuffix("Y") .appendMonths() .appendSuffix("M") .appendWeeks() .appendSuffix("W") .appendDays() .appendSuffix("D") .appendSeparatorIfFieldsAfter("T") .appendHours() .appendSuffix("H") .appendMinutes() .appendSuffix("M") .appendSecondsWithOptionalMillis() .appendSuffix("S") .toFormatter(); } return cStandard; }
[ "public", "static", "PeriodFormatter", "standard", "(", ")", "{", "if", "(", "cStandard", "==", "null", ")", "{", "cStandard", "=", "new", "PeriodFormatterBuilder", "(", ")", ".", "appendLiteral", "(", "\"P\"", ")", ".", "appendYears", "(", ")", ".", "appendSuffix", "(", "\"Y\"", ")", ".", "appendMonths", "(", ")", ".", "appendSuffix", "(", "\"M\"", ")", ".", "appendWeeks", "(", ")", ".", "appendSuffix", "(", "\"W\"", ")", ".", "appendDays", "(", ")", ".", "appendSuffix", "(", "\"D\"", ")", ".", "appendSeparatorIfFieldsAfter", "(", "\"T\"", ")", ".", "appendHours", "(", ")", ".", "appendSuffix", "(", "\"H\"", ")", ".", "appendMinutes", "(", ")", ".", "appendSuffix", "(", "\"M\"", ")", ".", "appendSecondsWithOptionalMillis", "(", ")", ".", "appendSuffix", "(", "\"S\"", ")", ".", "toFormatter", "(", ")", ";", "}", "return", "cStandard", ";", "}" ]
The standard ISO format - PyYmMwWdDThHmMsS. Milliseconds are not output. Note that the ISO8601 standard actually indicates weeks should not be shown if any other field is present and vice versa. @return the formatter
[ "The", "standard", "ISO", "format", "-", "PyYmMwWdDThHmMsS", ".", "Milliseconds", "are", "not", "output", ".", "Note", "that", "the", "ISO8601", "standard", "actually", "indicates", "weeks", "should", "not", "be", "shown", "if", "any", "other", "field", "is", "present", "and", "vice", "versa", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/ISOPeriodFormat.java#L64-L86
22,248
JodaOrg/joda-time
src/main/java/org/joda/time/format/PeriodFormatterBuilder.java
PeriodFormatterBuilder.clear
public void clear() { iMinPrintedDigits = 1; iPrintZeroSetting = PRINT_ZERO_RARELY_LAST; iMaxParsedDigits = 10; iRejectSignedValues = false; iPrefix = null; if (iElementPairs == null) { iElementPairs = new ArrayList<Object>(); } else { iElementPairs.clear(); } iNotPrinter = false; iNotParser = false; iFieldFormatters = new FieldFormatter[10]; }
java
public void clear() { iMinPrintedDigits = 1; iPrintZeroSetting = PRINT_ZERO_RARELY_LAST; iMaxParsedDigits = 10; iRejectSignedValues = false; iPrefix = null; if (iElementPairs == null) { iElementPairs = new ArrayList<Object>(); } else { iElementPairs.clear(); } iNotPrinter = false; iNotParser = false; iFieldFormatters = new FieldFormatter[10]; }
[ "public", "void", "clear", "(", ")", "{", "iMinPrintedDigits", "=", "1", ";", "iPrintZeroSetting", "=", "PRINT_ZERO_RARELY_LAST", ";", "iMaxParsedDigits", "=", "10", ";", "iRejectSignedValues", "=", "false", ";", "iPrefix", "=", "null", ";", "if", "(", "iElementPairs", "==", "null", ")", "{", "iElementPairs", "=", "new", "ArrayList", "<", "Object", ">", "(", ")", ";", "}", "else", "{", "iElementPairs", ".", "clear", "(", ")", ";", "}", "iNotPrinter", "=", "false", ";", "iNotParser", "=", "false", ";", "iFieldFormatters", "=", "new", "FieldFormatter", "[", "10", "]", ";", "}" ]
Clears out all the appended elements, allowing this builder to be reused.
[ "Clears", "out", "all", "the", "appended", "elements", "allowing", "this", "builder", "to", "be", "reused", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/PeriodFormatterBuilder.java#L184-L198
22,249
JodaOrg/joda-time
src/main/java/org/joda/time/format/PeriodFormatterBuilder.java
PeriodFormatterBuilder.append
public PeriodFormatterBuilder append(PeriodFormatter formatter) { if (formatter == null) { throw new IllegalArgumentException("No formatter supplied"); } clearPrefix(); append0(formatter.getPrinter(), formatter.getParser()); return this; }
java
public PeriodFormatterBuilder append(PeriodFormatter formatter) { if (formatter == null) { throw new IllegalArgumentException("No formatter supplied"); } clearPrefix(); append0(formatter.getPrinter(), formatter.getParser()); return this; }
[ "public", "PeriodFormatterBuilder", "append", "(", "PeriodFormatter", "formatter", ")", "{", "if", "(", "formatter", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"No formatter supplied\"", ")", ";", "}", "clearPrefix", "(", ")", ";", "append0", "(", "formatter", ".", "getPrinter", "(", ")", ",", "formatter", ".", "getParser", "(", ")", ")", ";", "return", "this", ";", "}" ]
Appends another formatter. @return this PeriodFormatterBuilder
[ "Appends", "another", "formatter", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/PeriodFormatterBuilder.java#L205-L212
22,250
JodaOrg/joda-time
src/main/java/org/joda/time/tz/ZoneInfoCompiler.java
ZoneInfoCompiler.main
public static void main(String[] args) throws Exception { if (args.length == 0) { printUsage(); return; } File inputDir = null; File outputDir = null; boolean verbose = false; int i; for (i=0; i<args.length; i++) { try { if ("-src".equals(args[i])) { inputDir = new File(args[++i]); } else if ("-dst".equals(args[i])) { outputDir = new File(args[++i]); } else if ("-verbose".equals(args[i])) { verbose = true; } else if ("-?".equals(args[i])) { printUsage(); return; } else { break; } } catch (IndexOutOfBoundsException e) { printUsage(); return; } } if (i >= args.length) { printUsage(); return; } File[] sources = new File[args.length - i]; for (int j=0; i<args.length; i++,j++) { sources[j] = inputDir == null ? new File(args[i]) : new File(inputDir, args[i]); } ZoneInfoLogger.set(verbose); ZoneInfoCompiler zic = new ZoneInfoCompiler(); zic.compile(outputDir, sources); }
java
public static void main(String[] args) throws Exception { if (args.length == 0) { printUsage(); return; } File inputDir = null; File outputDir = null; boolean verbose = false; int i; for (i=0; i<args.length; i++) { try { if ("-src".equals(args[i])) { inputDir = new File(args[++i]); } else if ("-dst".equals(args[i])) { outputDir = new File(args[++i]); } else if ("-verbose".equals(args[i])) { verbose = true; } else if ("-?".equals(args[i])) { printUsage(); return; } else { break; } } catch (IndexOutOfBoundsException e) { printUsage(); return; } } if (i >= args.length) { printUsage(); return; } File[] sources = new File[args.length - i]; for (int j=0; i<args.length; i++,j++) { sources[j] = inputDir == null ? new File(args[i]) : new File(inputDir, args[i]); } ZoneInfoLogger.set(verbose); ZoneInfoCompiler zic = new ZoneInfoCompiler(); zic.compile(outputDir, sources); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "args", ".", "length", "==", "0", ")", "{", "printUsage", "(", ")", ";", "return", ";", "}", "File", "inputDir", "=", "null", ";", "File", "outputDir", "=", "null", ";", "boolean", "verbose", "=", "false", ";", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "try", "{", "if", "(", "\"-src\"", ".", "equals", "(", "args", "[", "i", "]", ")", ")", "{", "inputDir", "=", "new", "File", "(", "args", "[", "++", "i", "]", ")", ";", "}", "else", "if", "(", "\"-dst\"", ".", "equals", "(", "args", "[", "i", "]", ")", ")", "{", "outputDir", "=", "new", "File", "(", "args", "[", "++", "i", "]", ")", ";", "}", "else", "if", "(", "\"-verbose\"", ".", "equals", "(", "args", "[", "i", "]", ")", ")", "{", "verbose", "=", "true", ";", "}", "else", "if", "(", "\"-?\"", ".", "equals", "(", "args", "[", "i", "]", ")", ")", "{", "printUsage", "(", ")", ";", "return", ";", "}", "else", "{", "break", ";", "}", "}", "catch", "(", "IndexOutOfBoundsException", "e", ")", "{", "printUsage", "(", ")", ";", "return", ";", "}", "}", "if", "(", "i", ">=", "args", ".", "length", ")", "{", "printUsage", "(", ")", ";", "return", ";", "}", "File", "[", "]", "sources", "=", "new", "File", "[", "args", ".", "length", "-", "i", "]", ";", "for", "(", "int", "j", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ",", "j", "++", ")", "{", "sources", "[", "j", "]", "=", "inputDir", "==", "null", "?", "new", "File", "(", "args", "[", "i", "]", ")", ":", "new", "File", "(", "inputDir", ",", "args", "[", "i", "]", ")", ";", "}", "ZoneInfoLogger", ".", "set", "(", "verbose", ")", ";", "ZoneInfoCompiler", "zic", "=", "new", "ZoneInfoCompiler", "(", ")", ";", "zic", ".", "compile", "(", "outputDir", ",", "sources", ")", ";", "}" ]
Launches the ZoneInfoCompiler tool. <pre> Usage: java org.joda.time.tz.ZoneInfoCompiler &lt;options&gt; &lt;source files&gt; where possible options include: -src &lt;directory&gt; Specify where to read source files -dst &lt;directory&gt; Specify where to write generated files -verbose Output verbosely (default false) </pre>
[ "Launches", "the", "ZoneInfoCompiler", "tool", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/tz/ZoneInfoCompiler.java#L80-L124
22,251
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setInterval
public void setInterval(ReadableInterval interval) { if (interval == null) { throw new IllegalArgumentException("Interval must not be null"); } long startMillis = interval.getStartMillis(); long endMillis = interval.getEndMillis(); Chronology chrono = interval.getChronology(); super.setInterval(startMillis, endMillis, chrono); }
java
public void setInterval(ReadableInterval interval) { if (interval == null) { throw new IllegalArgumentException("Interval must not be null"); } long startMillis = interval.getStartMillis(); long endMillis = interval.getEndMillis(); Chronology chrono = interval.getChronology(); super.setInterval(startMillis, endMillis, chrono); }
[ "public", "void", "setInterval", "(", "ReadableInterval", "interval", ")", "{", "if", "(", "interval", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Interval must not be null\"", ")", ";", "}", "long", "startMillis", "=", "interval", ".", "getStartMillis", "(", ")", ";", "long", "endMillis", "=", "interval", ".", "getEndMillis", "(", ")", ";", "Chronology", "chrono", "=", "interval", ".", "getChronology", "(", ")", ";", "super", ".", "setInterval", "(", "startMillis", ",", "endMillis", ",", "chrono", ")", ";", "}" ]
Sets this interval to be the same as another. @param interval the interval to copy @throws IllegalArgumentException if the interval is null
[ "Sets", "this", "interval", "to", "be", "the", "same", "as", "another", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L226-L234
22,252
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setInterval
public void setInterval(ReadableInstant start, ReadableInstant end) { if (start == null && end == null) { long now = DateTimeUtils.currentTimeMillis(); setInterval(now, now); } else { long startMillis = DateTimeUtils.getInstantMillis(start); long endMillis = DateTimeUtils.getInstantMillis(end); Chronology chrono = DateTimeUtils.getInstantChronology(start); super.setInterval(startMillis, endMillis, chrono); } }
java
public void setInterval(ReadableInstant start, ReadableInstant end) { if (start == null && end == null) { long now = DateTimeUtils.currentTimeMillis(); setInterval(now, now); } else { long startMillis = DateTimeUtils.getInstantMillis(start); long endMillis = DateTimeUtils.getInstantMillis(end); Chronology chrono = DateTimeUtils.getInstantChronology(start); super.setInterval(startMillis, endMillis, chrono); } }
[ "public", "void", "setInterval", "(", "ReadableInstant", "start", ",", "ReadableInstant", "end", ")", "{", "if", "(", "start", "==", "null", "&&", "end", "==", "null", ")", "{", "long", "now", "=", "DateTimeUtils", ".", "currentTimeMillis", "(", ")", ";", "setInterval", "(", "now", ",", "now", ")", ";", "}", "else", "{", "long", "startMillis", "=", "DateTimeUtils", ".", "getInstantMillis", "(", "start", ")", ";", "long", "endMillis", "=", "DateTimeUtils", ".", "getInstantMillis", "(", "end", ")", ";", "Chronology", "chrono", "=", "DateTimeUtils", ".", "getInstantChronology", "(", "start", ")", ";", "super", ".", "setInterval", "(", "startMillis", ",", "endMillis", ",", "chrono", ")", ";", "}", "}" ]
Sets this interval from two instants, replacing the chronology with that from the start instant. @param start the start of the time interval @param end the start of the time interval @throws IllegalArgumentException if the end is before the start
[ "Sets", "this", "interval", "from", "two", "instants", "replacing", "the", "chronology", "with", "that", "from", "the", "start", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L244-L254
22,253
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setStart
public void setStart(ReadableInstant start) { long startMillis = DateTimeUtils.getInstantMillis(start); super.setInterval(startMillis, getEndMillis(), getChronology()); }
java
public void setStart(ReadableInstant start) { long startMillis = DateTimeUtils.getInstantMillis(start); super.setInterval(startMillis, getEndMillis(), getChronology()); }
[ "public", "void", "setStart", "(", "ReadableInstant", "start", ")", "{", "long", "startMillis", "=", "DateTimeUtils", ".", "getInstantMillis", "(", "start", ")", ";", "super", ".", "setInterval", "(", "startMillis", ",", "getEndMillis", "(", ")", ",", "getChronology", "(", ")", ")", ";", "}" ]
Sets the start of this time interval as an Instant. @param start the start of the time interval, null means now @throws IllegalArgumentException if the end is before the start
[ "Sets", "the", "start", "of", "this", "time", "interval", "as", "an", "Instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L283-L286
22,254
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setEnd
public void setEnd(ReadableInstant end) { long endMillis = DateTimeUtils.getInstantMillis(end); super.setInterval(getStartMillis(), endMillis, getChronology()); }
java
public void setEnd(ReadableInstant end) { long endMillis = DateTimeUtils.getInstantMillis(end); super.setInterval(getStartMillis(), endMillis, getChronology()); }
[ "public", "void", "setEnd", "(", "ReadableInstant", "end", ")", "{", "long", "endMillis", "=", "DateTimeUtils", ".", "getInstantMillis", "(", "end", ")", ";", "super", ".", "setInterval", "(", "getStartMillis", "(", ")", ",", "endMillis", ",", "getChronology", "(", ")", ")", ";", "}" ]
Sets the end of this time interval as an Instant. @param end the end of the time interval, null means now @throws IllegalArgumentException if the end is before the start
[ "Sets", "the", "end", "of", "this", "time", "interval", "as", "an", "Instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L305-L308
22,255
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setDurationAfterStart
public void setDurationAfterStart(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); setEndMillis(FieldUtils.safeAdd(getStartMillis(), durationMillis)); }
java
public void setDurationAfterStart(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); setEndMillis(FieldUtils.safeAdd(getStartMillis(), durationMillis)); }
[ "public", "void", "setDurationAfterStart", "(", "ReadableDuration", "duration", ")", "{", "long", "durationMillis", "=", "DateTimeUtils", ".", "getDurationMillis", "(", "duration", ")", ";", "setEndMillis", "(", "FieldUtils", ".", "safeAdd", "(", "getStartMillis", "(", ")", ",", "durationMillis", ")", ")", ";", "}" ]
Sets the duration of this time interval, preserving the start instant. @param duration new duration for interval, null means zero length @throws IllegalArgumentException if the end is before the start @throws ArithmeticException if the end instant exceeds the capacity of a long
[ "Sets", "the", "duration", "of", "this", "time", "interval", "preserving", "the", "start", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L341-L344
22,256
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setDurationBeforeEnd
public void setDurationBeforeEnd(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); setStartMillis(FieldUtils.safeAdd(getEndMillis(), -durationMillis)); }
java
public void setDurationBeforeEnd(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); setStartMillis(FieldUtils.safeAdd(getEndMillis(), -durationMillis)); }
[ "public", "void", "setDurationBeforeEnd", "(", "ReadableDuration", "duration", ")", "{", "long", "durationMillis", "=", "DateTimeUtils", ".", "getDurationMillis", "(", "duration", ")", ";", "setStartMillis", "(", "FieldUtils", ".", "safeAdd", "(", "getEndMillis", "(", ")", ",", "-", "durationMillis", ")", ")", ";", "}" ]
Sets the duration of this time interval, preserving the end instant. @param duration new duration for interval, null means zero length @throws IllegalArgumentException if the end is before the start @throws ArithmeticException if the start instant exceeds the capacity of a long
[ "Sets", "the", "duration", "of", "this", "time", "interval", "preserving", "the", "end", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L353-L356
22,257
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setPeriodAfterStart
public void setPeriodAfterStart(ReadablePeriod period) { if (period == null) { setEndMillis(getStartMillis()); } else { setEndMillis(getChronology().add(period, getStartMillis(), 1)); } }
java
public void setPeriodAfterStart(ReadablePeriod period) { if (period == null) { setEndMillis(getStartMillis()); } else { setEndMillis(getChronology().add(period, getStartMillis(), 1)); } }
[ "public", "void", "setPeriodAfterStart", "(", "ReadablePeriod", "period", ")", "{", "if", "(", "period", "==", "null", ")", "{", "setEndMillis", "(", "getStartMillis", "(", ")", ")", ";", "}", "else", "{", "setEndMillis", "(", "getChronology", "(", ")", ".", "add", "(", "period", ",", "getStartMillis", "(", ")", ",", "1", ")", ")", ";", "}", "}" ]
Sets the period of this time interval, preserving the start instant and using the ISOChronology in the default zone for calculations. @param period new period for interval, null means zero length @throws IllegalArgumentException if the end is before the start @throws ArithmeticException if the end instant exceeds the capacity of a long
[ "Sets", "the", "period", "of", "this", "time", "interval", "preserving", "the", "start", "instant", "and", "using", "the", "ISOChronology", "in", "the", "default", "zone", "for", "calculations", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L367-L373
22,258
JodaOrg/joda-time
src/main/java/org/joda/time/MutableInterval.java
MutableInterval.setPeriodBeforeEnd
public void setPeriodBeforeEnd(ReadablePeriod period) { if (period == null) { setStartMillis(getEndMillis()); } else { setStartMillis(getChronology().add(period, getEndMillis(), -1)); } }
java
public void setPeriodBeforeEnd(ReadablePeriod period) { if (period == null) { setStartMillis(getEndMillis()); } else { setStartMillis(getChronology().add(period, getEndMillis(), -1)); } }
[ "public", "void", "setPeriodBeforeEnd", "(", "ReadablePeriod", "period", ")", "{", "if", "(", "period", "==", "null", ")", "{", "setStartMillis", "(", "getEndMillis", "(", ")", ")", ";", "}", "else", "{", "setStartMillis", "(", "getChronology", "(", ")", ".", "add", "(", "period", ",", "getEndMillis", "(", ")", ",", "-", "1", ")", ")", ";", "}", "}" ]
Sets the period of this time interval, preserving the end instant and using the ISOChronology in the default zone for calculations. @param period new period for interval, null means zero length @throws IllegalArgumentException if the end is before the start @throws ArithmeticException if the start instant exceeds the capacity of a long
[ "Sets", "the", "period", "of", "this", "time", "interval", "preserving", "the", "end", "instant", "and", "using", "the", "ISOChronology", "in", "the", "default", "zone", "for", "calculations", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/MutableInterval.java#L383-L389
22,259
JodaOrg/joda-time
src/main/java/org/joda/time/format/FormatUtils.java
FormatUtils.appendPaddedInteger
public static void appendPaddedInteger(Appendable appenadble, int value, int size) throws IOException { if (value < 0) { appenadble.append('-'); if (value != Integer.MIN_VALUE) { value = -value; } else { for (; size > 10; size--) { appenadble.append('0'); } appenadble.append("" + -(long)Integer.MIN_VALUE); return; } } if (value < 10) { for (; size > 1; size--) { appenadble.append('0'); } appenadble.append((char)(value + '0')); } else if (value < 100) { for (; size > 2; size--) { appenadble.append('0'); } // Calculate value div/mod by 10 without using two expensive // division operations. (2 ^ 27) / 10 = 13421772. Add one to // value to correct rounding error. int d = ((value + 1) * 13421772) >> 27; appenadble.append((char) (d + '0')); // Append remainder by calculating (value - d * 10). appenadble.append((char) (value - (d << 3) - (d << 1) + '0')); } else { int digits; if (value < 1000) { digits = 3; } else if (value < 10000) { digits = 4; } else { digits = (int)(Math.log(value) / LOG_10) + 1; } for (; size > digits; size--) { appenadble.append('0'); } appenadble.append(Integer.toString(value)); } }
java
public static void appendPaddedInteger(Appendable appenadble, int value, int size) throws IOException { if (value < 0) { appenadble.append('-'); if (value != Integer.MIN_VALUE) { value = -value; } else { for (; size > 10; size--) { appenadble.append('0'); } appenadble.append("" + -(long)Integer.MIN_VALUE); return; } } if (value < 10) { for (; size > 1; size--) { appenadble.append('0'); } appenadble.append((char)(value + '0')); } else if (value < 100) { for (; size > 2; size--) { appenadble.append('0'); } // Calculate value div/mod by 10 without using two expensive // division operations. (2 ^ 27) / 10 = 13421772. Add one to // value to correct rounding error. int d = ((value + 1) * 13421772) >> 27; appenadble.append((char) (d + '0')); // Append remainder by calculating (value - d * 10). appenadble.append((char) (value - (d << 3) - (d << 1) + '0')); } else { int digits; if (value < 1000) { digits = 3; } else if (value < 10000) { digits = 4; } else { digits = (int)(Math.log(value) / LOG_10) + 1; } for (; size > digits; size--) { appenadble.append('0'); } appenadble.append(Integer.toString(value)); } }
[ "public", "static", "void", "appendPaddedInteger", "(", "Appendable", "appenadble", ",", "int", "value", ",", "int", "size", ")", "throws", "IOException", "{", "if", "(", "value", "<", "0", ")", "{", "appenadble", ".", "append", "(", "'", "'", ")", ";", "if", "(", "value", "!=", "Integer", ".", "MIN_VALUE", ")", "{", "value", "=", "-", "value", ";", "}", "else", "{", "for", "(", ";", "size", ">", "10", ";", "size", "--", ")", "{", "appenadble", ".", "append", "(", "'", "'", ")", ";", "}", "appenadble", ".", "append", "(", "\"\"", "+", "-", "(", "long", ")", "Integer", ".", "MIN_VALUE", ")", ";", "return", ";", "}", "}", "if", "(", "value", "<", "10", ")", "{", "for", "(", ";", "size", ">", "1", ";", "size", "--", ")", "{", "appenadble", ".", "append", "(", "'", "'", ")", ";", "}", "appenadble", ".", "append", "(", "(", "char", ")", "(", "value", "+", "'", "'", ")", ")", ";", "}", "else", "if", "(", "value", "<", "100", ")", "{", "for", "(", ";", "size", ">", "2", ";", "size", "--", ")", "{", "appenadble", ".", "append", "(", "'", "'", ")", ";", "}", "// Calculate value div/mod by 10 without using two expensive", "// division operations. (2 ^ 27) / 10 = 13421772. Add one to", "// value to correct rounding error.", "int", "d", "=", "(", "(", "value", "+", "1", ")", "*", "13421772", ")", ">>", "27", ";", "appenadble", ".", "append", "(", "(", "char", ")", "(", "d", "+", "'", "'", ")", ")", ";", "// Append remainder by calculating (value - d * 10).", "appenadble", ".", "append", "(", "(", "char", ")", "(", "value", "-", "(", "d", "<<", "3", ")", "-", "(", "d", "<<", "1", ")", "+", "'", "'", ")", ")", ";", "}", "else", "{", "int", "digits", ";", "if", "(", "value", "<", "1000", ")", "{", "digits", "=", "3", ";", "}", "else", "if", "(", "value", "<", "10000", ")", "{", "digits", "=", "4", ";", "}", "else", "{", "digits", "=", "(", "int", ")", "(", "Math", ".", "log", "(", "value", ")", "/", "LOG_10", ")", "+", "1", ";", "}", "for", "(", ";", "size", ">", "digits", ";", "size", "--", ")", "{", "appenadble", ".", "append", "(", "'", "'", ")", ";", "}", "appenadble", ".", "append", "(", "Integer", ".", "toString", "(", "value", ")", ")", ";", "}", "}" ]
Converts an integer to a string, prepended with a variable amount of '0' pad characters, and appends it to the given appendable. <p>This method is optimized for converting small values to strings. @param appenadble receives integer converted to a string @param value value to convert to a string @param size minimum amount of digits to append @since 2.4
[ "Converts", "an", "integer", "to", "a", "string", "prepended", "with", "a", "variable", "amount", "of", "0", "pad", "characters", "and", "appends", "it", "to", "the", "given", "appendable", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/FormatUtils.java#L68-L111
22,260
JodaOrg/joda-time
src/main/java/org/joda/time/format/FormatUtils.java
FormatUtils.appendUnpaddedInteger
public static void appendUnpaddedInteger(StringBuffer buf, int value) { try { appendUnpaddedInteger((Appendable) buf, value); } catch (IOException e) { // StringBuffer do not throw IOException } }
java
public static void appendUnpaddedInteger(StringBuffer buf, int value) { try { appendUnpaddedInteger((Appendable) buf, value); } catch (IOException e) { // StringBuffer do not throw IOException } }
[ "public", "static", "void", "appendUnpaddedInteger", "(", "StringBuffer", "buf", ",", "int", "value", ")", "{", "try", "{", "appendUnpaddedInteger", "(", "(", "Appendable", ")", "buf", ",", "value", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "// StringBuffer do not throw IOException", "}", "}" ]
Converts an integer to a string, and appends it to the given buffer. <p>This method is optimized for converting small values to strings. @param buf receives integer converted to a string @param value value to convert to a string
[ "Converts", "an", "integer", "to", "a", "string", "and", "appends", "it", "to", "the", "given", "buffer", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/FormatUtils.java#L273-L279
22,261
JodaOrg/joda-time
src/main/java/org/joda/time/format/FormatUtils.java
FormatUtils.calculateDigitCount
public static int calculateDigitCount(long value) { if (value < 0) { if (value != Long.MIN_VALUE) { return calculateDigitCount(-value) + 1; } else { return 20; } } return (value < 10 ? 1 : (value < 100 ? 2 : (value < 1000 ? 3 : (value < 10000 ? 4 : ((int)(Math.log(value) / LOG_10) + 1))))); }
java
public static int calculateDigitCount(long value) { if (value < 0) { if (value != Long.MIN_VALUE) { return calculateDigitCount(-value) + 1; } else { return 20; } } return (value < 10 ? 1 : (value < 100 ? 2 : (value < 1000 ? 3 : (value < 10000 ? 4 : ((int)(Math.log(value) / LOG_10) + 1))))); }
[ "public", "static", "int", "calculateDigitCount", "(", "long", "value", ")", "{", "if", "(", "value", "<", "0", ")", "{", "if", "(", "value", "!=", "Long", ".", "MIN_VALUE", ")", "{", "return", "calculateDigitCount", "(", "-", "value", ")", "+", "1", ";", "}", "else", "{", "return", "20", ";", "}", "}", "return", "(", "value", "<", "10", "?", "1", ":", "(", "value", "<", "100", "?", "2", ":", "(", "value", "<", "1000", "?", "3", ":", "(", "value", "<", "10000", "?", "4", ":", "(", "(", "int", ")", "(", "Math", ".", "log", "(", "value", ")", "/", "LOG_10", ")", "+", "1", ")", ")", ")", ")", ")", ";", "}" ]
Calculates the number of decimal digits for the given value, including the sign.
[ "Calculates", "the", "number", "of", "decimal", "digits", "for", "the", "given", "value", "including", "the", "sign", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/FormatUtils.java#L406-L420
22,262
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/JulianChronology.java
JulianChronology.getInstance
public static JulianChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) { if (zone == null) { zone = DateTimeZone.getDefault(); } JulianChronology chrono; JulianChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new JulianChronology[7]; JulianChronology[] oldChronos = cCache.putIfAbsent(zone, chronos); if (oldChronos != null) { chronos = oldChronos; } } try { chrono = chronos[minDaysInFirstWeek - 1]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid min days in first week: " + minDaysInFirstWeek); } if (chrono == null) { synchronized (chronos) { chrono = chronos[minDaysInFirstWeek - 1]; if (chrono == null) { if (zone == DateTimeZone.UTC) { chrono = new JulianChronology(null, null, minDaysInFirstWeek); } else { chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek); chrono = new JulianChronology (ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek); } chronos[minDaysInFirstWeek - 1] = chrono; } } } return chrono; }
java
public static JulianChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) { if (zone == null) { zone = DateTimeZone.getDefault(); } JulianChronology chrono; JulianChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new JulianChronology[7]; JulianChronology[] oldChronos = cCache.putIfAbsent(zone, chronos); if (oldChronos != null) { chronos = oldChronos; } } try { chrono = chronos[minDaysInFirstWeek - 1]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid min days in first week: " + minDaysInFirstWeek); } if (chrono == null) { synchronized (chronos) { chrono = chronos[minDaysInFirstWeek - 1]; if (chrono == null) { if (zone == DateTimeZone.UTC) { chrono = new JulianChronology(null, null, minDaysInFirstWeek); } else { chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek); chrono = new JulianChronology (ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek); } chronos[minDaysInFirstWeek - 1] = chrono; } } } return chrono; }
[ "public", "static", "JulianChronology", "getInstance", "(", "DateTimeZone", "zone", ",", "int", "minDaysInFirstWeek", ")", "{", "if", "(", "zone", "==", "null", ")", "{", "zone", "=", "DateTimeZone", ".", "getDefault", "(", ")", ";", "}", "JulianChronology", "chrono", ";", "JulianChronology", "[", "]", "chronos", "=", "cCache", ".", "get", "(", "zone", ")", ";", "if", "(", "chronos", "==", "null", ")", "{", "chronos", "=", "new", "JulianChronology", "[", "7", "]", ";", "JulianChronology", "[", "]", "oldChronos", "=", "cCache", ".", "putIfAbsent", "(", "zone", ",", "chronos", ")", ";", "if", "(", "oldChronos", "!=", "null", ")", "{", "chronos", "=", "oldChronos", ";", "}", "}", "try", "{", "chrono", "=", "chronos", "[", "minDaysInFirstWeek", "-", "1", "]", ";", "}", "catch", "(", "ArrayIndexOutOfBoundsException", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid min days in first week: \"", "+", "minDaysInFirstWeek", ")", ";", "}", "if", "(", "chrono", "==", "null", ")", "{", "synchronized", "(", "chronos", ")", "{", "chrono", "=", "chronos", "[", "minDaysInFirstWeek", "-", "1", "]", ";", "if", "(", "chrono", "==", "null", ")", "{", "if", "(", "zone", "==", "DateTimeZone", ".", "UTC", ")", "{", "chrono", "=", "new", "JulianChronology", "(", "null", ",", "null", ",", "minDaysInFirstWeek", ")", ";", "}", "else", "{", "chrono", "=", "getInstance", "(", "DateTimeZone", ".", "UTC", ",", "minDaysInFirstWeek", ")", ";", "chrono", "=", "new", "JulianChronology", "(", "ZonedChronology", ".", "getInstance", "(", "chrono", ",", "zone", ")", ",", "null", ",", "minDaysInFirstWeek", ")", ";", "}", "chronos", "[", "minDaysInFirstWeek", "-", "1", "]", "=", "chrono", ";", "}", "}", "}", "return", "chrono", ";", "}" ]
Gets an instance of the JulianChronology in the given time zone. @param zone the time zone to get the chronology in, null is default @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4 @return a chronology in the specified time zone
[ "Gets", "an", "instance", "of", "the", "JulianChronology", "in", "the", "given", "time", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/JulianChronology.java#L123-L158
22,263
JodaOrg/joda-time
src/main/java/org/joda/time/format/PeriodFormatter.java
PeriodFormatter.printTo
public void printTo(StringBuffer buf, ReadablePeriod period) { checkPrinter(); checkPeriod(period); getPrinter().printTo(buf, period, iLocale); }
java
public void printTo(StringBuffer buf, ReadablePeriod period) { checkPrinter(); checkPeriod(period); getPrinter().printTo(buf, period, iLocale); }
[ "public", "void", "printTo", "(", "StringBuffer", "buf", ",", "ReadablePeriod", "period", ")", "{", "checkPrinter", "(", ")", ";", "checkPeriod", "(", "period", ")", ";", "getPrinter", "(", ")", ".", "printTo", "(", "buf", ",", "period", ",", "iLocale", ")", ";", "}" ]
Prints a ReadablePeriod to a StringBuffer. @param buf the formatted period is appended to this buffer @param period the period to format, not null
[ "Prints", "a", "ReadablePeriod", "to", "a", "StringBuffer", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/PeriodFormatter.java#L213-L218
22,264
JodaOrg/joda-time
src/main/java/org/joda/time/format/PeriodFormatter.java
PeriodFormatter.printTo
public void printTo(Writer out, ReadablePeriod period) throws IOException { checkPrinter(); checkPeriod(period); getPrinter().printTo(out, period, iLocale); }
java
public void printTo(Writer out, ReadablePeriod period) throws IOException { checkPrinter(); checkPeriod(period); getPrinter().printTo(out, period, iLocale); }
[ "public", "void", "printTo", "(", "Writer", "out", ",", "ReadablePeriod", "period", ")", "throws", "IOException", "{", "checkPrinter", "(", ")", ";", "checkPeriod", "(", "period", ")", ";", "getPrinter", "(", ")", ".", "printTo", "(", "out", ",", "period", ",", "iLocale", ")", ";", "}" ]
Prints a ReadablePeriod to a Writer. @param out the formatted period is written out @param period the period to format, not null
[ "Prints", "a", "ReadablePeriod", "to", "a", "Writer", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/PeriodFormatter.java#L226-L231
22,265
JodaOrg/joda-time
src/main/java/org/joda/time/format/PeriodFormatter.java
PeriodFormatter.print
public String print(ReadablePeriod period) { checkPrinter(); checkPeriod(period); PeriodPrinter printer = getPrinter(); StringBuffer buf = new StringBuffer(printer.calculatePrintedLength(period, iLocale)); printer.printTo(buf, period, iLocale); return buf.toString(); }
java
public String print(ReadablePeriod period) { checkPrinter(); checkPeriod(period); PeriodPrinter printer = getPrinter(); StringBuffer buf = new StringBuffer(printer.calculatePrintedLength(period, iLocale)); printer.printTo(buf, period, iLocale); return buf.toString(); }
[ "public", "String", "print", "(", "ReadablePeriod", "period", ")", "{", "checkPrinter", "(", ")", ";", "checkPeriod", "(", "period", ")", ";", "PeriodPrinter", "printer", "=", "getPrinter", "(", ")", ";", "StringBuffer", "buf", "=", "new", "StringBuffer", "(", "printer", ".", "calculatePrintedLength", "(", "period", ",", "iLocale", ")", ")", ";", "printer", ".", "printTo", "(", "buf", ",", "period", ",", "iLocale", ")", ";", "return", "buf", ".", "toString", "(", ")", ";", "}" ]
Prints a ReadablePeriod to a new String. @param period the period to format, not null @return the printed result
[ "Prints", "a", "ReadablePeriod", "to", "a", "new", "String", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/PeriodFormatter.java#L239-L247
22,266
JodaOrg/joda-time
src/main/java/org/joda/time/format/PeriodFormatter.java
PeriodFormatter.parseMutablePeriod
public MutablePeriod parseMutablePeriod(String text) { checkParser(); MutablePeriod period = new MutablePeriod(0, iParseType); int newPos = getParser().parseInto(period, text, 0, iLocale); if (newPos >= 0) { if (newPos >= text.length()) { return period; } } else { newPos = ~newPos; } throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos)); }
java
public MutablePeriod parseMutablePeriod(String text) { checkParser(); MutablePeriod period = new MutablePeriod(0, iParseType); int newPos = getParser().parseInto(period, text, 0, iLocale); if (newPos >= 0) { if (newPos >= text.length()) { return period; } } else { newPos = ~newPos; } throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos)); }
[ "public", "MutablePeriod", "parseMutablePeriod", "(", "String", "text", ")", "{", "checkParser", "(", ")", ";", "MutablePeriod", "period", "=", "new", "MutablePeriod", "(", "0", ",", "iParseType", ")", ";", "int", "newPos", "=", "getParser", "(", ")", ".", "parseInto", "(", "period", ",", "text", ",", "0", ",", "iLocale", ")", ";", "if", "(", "newPos", ">=", "0", ")", "{", "if", "(", "newPos", ">=", "text", ".", "length", "(", ")", ")", "{", "return", "period", ";", "}", "}", "else", "{", "newPos", "=", "~", "newPos", ";", "}", "throw", "new", "IllegalArgumentException", "(", "FormatUtils", ".", "createErrorMessage", "(", "text", ",", "newPos", ")", ")", ";", "}" ]
Parses a period from the given text, returning a new MutablePeriod. @param text text to parse @return parsed value in a MutablePeriod object @throws IllegalArgumentException if any field is out of range
[ "Parses", "a", "period", "from", "the", "given", "text", "returning", "a", "new", "MutablePeriod", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/PeriodFormatter.java#L318-L331
22,267
JodaOrg/joda-time
src/main/java/org/joda/time/LocalDate.java
LocalDate.isSupported
public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } DurationField field = type.getField(getChronology()); if (DATE_DURATION_TYPES.contains(type) || field.getUnitMillis() >= getChronology().days().getUnitMillis()) { return field.isSupported(); } return false; }
java
public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } DurationField field = type.getField(getChronology()); if (DATE_DURATION_TYPES.contains(type) || field.getUnitMillis() >= getChronology().days().getUnitMillis()) { return field.isSupported(); } return false; }
[ "public", "boolean", "isSupported", "(", "DurationFieldType", "type", ")", "{", "if", "(", "type", "==", "null", ")", "{", "return", "false", ";", "}", "DurationField", "field", "=", "type", ".", "getField", "(", "getChronology", "(", ")", ")", ";", "if", "(", "DATE_DURATION_TYPES", ".", "contains", "(", "type", ")", "||", "field", ".", "getUnitMillis", "(", ")", ">=", "getChronology", "(", ")", ".", "days", "(", ")", ".", "getUnitMillis", "(", ")", ")", "{", "return", "field", ".", "isSupported", "(", ")", ";", "}", "return", "false", ";", "}" ]
Checks if the duration type specified is supported by this local date and chronology. @param type a duration type, usually obtained from DurationFieldType @return true if the field type is supported
[ "Checks", "if", "the", "duration", "type", "specified", "is", "supported", "by", "this", "local", "date", "and", "chronology", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/LocalDate.java#L589-L599
22,268
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/LimitChronology.java
LimitChronology.getInstance
public static LimitChronology getInstance(Chronology base, ReadableDateTime lowerLimit, ReadableDateTime upperLimit) { if (base == null) { throw new IllegalArgumentException("Must supply a chronology"); } lowerLimit = lowerLimit == null ? null : lowerLimit.toDateTime(); upperLimit = upperLimit == null ? null : upperLimit.toDateTime(); if (lowerLimit != null && upperLimit != null && !lowerLimit.isBefore(upperLimit)) { throw new IllegalArgumentException ("The lower limit must be come before than the upper limit"); } return new LimitChronology(base, (DateTime)lowerLimit, (DateTime)upperLimit); }
java
public static LimitChronology getInstance(Chronology base, ReadableDateTime lowerLimit, ReadableDateTime upperLimit) { if (base == null) { throw new IllegalArgumentException("Must supply a chronology"); } lowerLimit = lowerLimit == null ? null : lowerLimit.toDateTime(); upperLimit = upperLimit == null ? null : upperLimit.toDateTime(); if (lowerLimit != null && upperLimit != null && !lowerLimit.isBefore(upperLimit)) { throw new IllegalArgumentException ("The lower limit must be come before than the upper limit"); } return new LimitChronology(base, (DateTime)lowerLimit, (DateTime)upperLimit); }
[ "public", "static", "LimitChronology", "getInstance", "(", "Chronology", "base", ",", "ReadableDateTime", "lowerLimit", ",", "ReadableDateTime", "upperLimit", ")", "{", "if", "(", "base", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Must supply a chronology\"", ")", ";", "}", "lowerLimit", "=", "lowerLimit", "==", "null", "?", "null", ":", "lowerLimit", ".", "toDateTime", "(", ")", ";", "upperLimit", "=", "upperLimit", "==", "null", "?", "null", ":", "upperLimit", ".", "toDateTime", "(", ")", ";", "if", "(", "lowerLimit", "!=", "null", "&&", "upperLimit", "!=", "null", "&&", "!", "lowerLimit", ".", "isBefore", "(", "upperLimit", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The lower limit must be come before than the upper limit\"", ")", ";", "}", "return", "new", "LimitChronology", "(", "base", ",", "(", "DateTime", ")", "lowerLimit", ",", "(", "DateTime", ")", "upperLimit", ")", ";", "}" ]
Wraps another chronology, with datetime limits. When withUTC or withZone is called, the returned LimitChronology instance has the same limits, except they are time zone adjusted. @param base base chronology to wrap @param lowerLimit inclusive lower limit, or null if none @param upperLimit exclusive upper limit, or null if none @throws IllegalArgumentException if chronology is null or limits are invalid
[ "Wraps", "another", "chronology", "with", "datetime", "limits", ".", "When", "withUTC", "or", "withZone", "is", "called", "the", "returned", "LimitChronology", "instance", "has", "the", "same", "limits", "except", "they", "are", "time", "zone", "adjusted", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/LimitChronology.java#L64-L80
22,269
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/LimitChronology.java
LimitChronology.withZone
public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } if (zone == DateTimeZone.UTC && iWithUTC != null) { return iWithUTC; } DateTime lowerLimit = iLowerLimit; if (lowerLimit != null) { MutableDateTime mdt = lowerLimit.toMutableDateTime(); mdt.setZoneRetainFields(zone); lowerLimit = mdt.toDateTime(); } DateTime upperLimit = iUpperLimit; if (upperLimit != null) { MutableDateTime mdt = upperLimit.toMutableDateTime(); mdt.setZoneRetainFields(zone); upperLimit = mdt.toDateTime(); } LimitChronology chrono = getInstance (getBase().withZone(zone), lowerLimit, upperLimit); if (zone == DateTimeZone.UTC) { iWithUTC = chrono; } return chrono; }
java
public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } if (zone == DateTimeZone.UTC && iWithUTC != null) { return iWithUTC; } DateTime lowerLimit = iLowerLimit; if (lowerLimit != null) { MutableDateTime mdt = lowerLimit.toMutableDateTime(); mdt.setZoneRetainFields(zone); lowerLimit = mdt.toDateTime(); } DateTime upperLimit = iUpperLimit; if (upperLimit != null) { MutableDateTime mdt = upperLimit.toMutableDateTime(); mdt.setZoneRetainFields(zone); upperLimit = mdt.toDateTime(); } LimitChronology chrono = getInstance (getBase().withZone(zone), lowerLimit, upperLimit); if (zone == DateTimeZone.UTC) { iWithUTC = chrono; } return chrono; }
[ "public", "Chronology", "withZone", "(", "DateTimeZone", "zone", ")", "{", "if", "(", "zone", "==", "null", ")", "{", "zone", "=", "DateTimeZone", ".", "getDefault", "(", ")", ";", "}", "if", "(", "zone", "==", "getZone", "(", ")", ")", "{", "return", "this", ";", "}", "if", "(", "zone", "==", "DateTimeZone", ".", "UTC", "&&", "iWithUTC", "!=", "null", ")", "{", "return", "iWithUTC", ";", "}", "DateTime", "lowerLimit", "=", "iLowerLimit", ";", "if", "(", "lowerLimit", "!=", "null", ")", "{", "MutableDateTime", "mdt", "=", "lowerLimit", ".", "toMutableDateTime", "(", ")", ";", "mdt", ".", "setZoneRetainFields", "(", "zone", ")", ";", "lowerLimit", "=", "mdt", ".", "toDateTime", "(", ")", ";", "}", "DateTime", "upperLimit", "=", "iUpperLimit", ";", "if", "(", "upperLimit", "!=", "null", ")", "{", "MutableDateTime", "mdt", "=", "upperLimit", ".", "toMutableDateTime", "(", ")", ";", "mdt", ".", "setZoneRetainFields", "(", "zone", ")", ";", "upperLimit", "=", "mdt", ".", "toDateTime", "(", ")", ";", "}", "LimitChronology", "chrono", "=", "getInstance", "(", "getBase", "(", ")", ".", "withZone", "(", "zone", ")", ",", "lowerLimit", ",", "upperLimit", ")", ";", "if", "(", "zone", "==", "DateTimeZone", ".", "UTC", ")", "{", "iWithUTC", "=", "chrono", ";", "}", "return", "chrono", ";", "}" ]
If this LimitChronology has the same time zone as the one given, then this is returned. Otherwise, a new instance is returned, with the limits adjusted to the new time zone.
[ "If", "this", "LimitChronology", "has", "the", "same", "time", "zone", "as", "the", "one", "given", "then", "this", "is", "returned", ".", "Otherwise", "a", "new", "instance", "is", "returned", "with", "the", "limits", "adjusted", "to", "the", "new", "time", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/LimitChronology.java#L135-L169
22,270
JodaOrg/joda-time
src/main/java/org/joda/time/base/AbstractInstant.java
AbstractInstant.toDateTime
public DateTime toDateTime(DateTimeZone zone) { Chronology chrono = DateTimeUtils.getChronology(getChronology()); chrono = chrono.withZone(zone); return new DateTime(getMillis(), chrono); }
java
public DateTime toDateTime(DateTimeZone zone) { Chronology chrono = DateTimeUtils.getChronology(getChronology()); chrono = chrono.withZone(zone); return new DateTime(getMillis(), chrono); }
[ "public", "DateTime", "toDateTime", "(", "DateTimeZone", "zone", ")", "{", "Chronology", "chrono", "=", "DateTimeUtils", ".", "getChronology", "(", "getChronology", "(", ")", ")", ";", "chrono", "=", "chrono", ".", "withZone", "(", "zone", ")", ";", "return", "new", "DateTime", "(", "getMillis", "(", ")", ",", "chrono", ")", ";", "}" ]
Get this object as a DateTime using the same chronology but a different zone. @param zone time zone to apply, or default if null @return a DateTime using the same millis
[ "Get", "this", "object", "as", "a", "DateTime", "using", "the", "same", "chronology", "but", "a", "different", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/AbstractInstant.java#L164-L168
22,271
JodaOrg/joda-time
src/main/java/org/joda/time/base/AbstractInstant.java
AbstractInstant.toMutableDateTime
public MutableDateTime toMutableDateTime(DateTimeZone zone) { Chronology chrono = DateTimeUtils.getChronology(getChronology()); chrono = chrono.withZone(zone); return new MutableDateTime(getMillis(), chrono); }
java
public MutableDateTime toMutableDateTime(DateTimeZone zone) { Chronology chrono = DateTimeUtils.getChronology(getChronology()); chrono = chrono.withZone(zone); return new MutableDateTime(getMillis(), chrono); }
[ "public", "MutableDateTime", "toMutableDateTime", "(", "DateTimeZone", "zone", ")", "{", "Chronology", "chrono", "=", "DateTimeUtils", ".", "getChronology", "(", "getChronology", "(", ")", ")", ";", "chrono", "=", "chrono", ".", "withZone", "(", "zone", ")", ";", "return", "new", "MutableDateTime", "(", "getMillis", "(", ")", ",", "chrono", ")", ";", "}" ]
Get this object as a MutableDateTime using the same chronology but a different zone. @param zone time zone to apply, or default if null @return a MutableDateTime using the same millis
[ "Get", "this", "object", "as", "a", "MutableDateTime", "using", "the", "same", "chronology", "but", "a", "different", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/AbstractInstant.java#L209-L213
22,272
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/EthiopicChronology.java
EthiopicChronology.getInstance
public static EthiopicChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) { if (zone == null) { zone = DateTimeZone.getDefault(); } EthiopicChronology chrono; EthiopicChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new EthiopicChronology[7]; EthiopicChronology[] oldChronos = cCache.putIfAbsent(zone, chronos); if (oldChronos != null) { chronos = oldChronos; } } try { chrono = chronos[minDaysInFirstWeek - 1]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid min days in first week: " + minDaysInFirstWeek); } if (chrono == null) { synchronized (chronos) { chrono = chronos[minDaysInFirstWeek - 1]; if (chrono == null) { if (zone == DateTimeZone.UTC) { // First create without a lower limit. chrono = new EthiopicChronology(null, null, minDaysInFirstWeek); // Impose lower limit and make another EthiopicChronology. DateTime lowerLimit = new DateTime(1, 1, 1, 0, 0, 0, 0, chrono); chrono = new EthiopicChronology (LimitChronology.getInstance(chrono, lowerLimit, null), null, minDaysInFirstWeek); } else { chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek); chrono = new EthiopicChronology (ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek); } chronos[minDaysInFirstWeek - 1] = chrono; } } } return chrono; }
java
public static EthiopicChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) { if (zone == null) { zone = DateTimeZone.getDefault(); } EthiopicChronology chrono; EthiopicChronology[] chronos = cCache.get(zone); if (chronos == null) { chronos = new EthiopicChronology[7]; EthiopicChronology[] oldChronos = cCache.putIfAbsent(zone, chronos); if (oldChronos != null) { chronos = oldChronos; } } try { chrono = chronos[minDaysInFirstWeek - 1]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid min days in first week: " + minDaysInFirstWeek); } if (chrono == null) { synchronized (chronos) { chrono = chronos[minDaysInFirstWeek - 1]; if (chrono == null) { if (zone == DateTimeZone.UTC) { // First create without a lower limit. chrono = new EthiopicChronology(null, null, minDaysInFirstWeek); // Impose lower limit and make another EthiopicChronology. DateTime lowerLimit = new DateTime(1, 1, 1, 0, 0, 0, 0, chrono); chrono = new EthiopicChronology (LimitChronology.getInstance(chrono, lowerLimit, null), null, minDaysInFirstWeek); } else { chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek); chrono = new EthiopicChronology (ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek); } chronos[minDaysInFirstWeek - 1] = chrono; } } } return chrono; }
[ "public", "static", "EthiopicChronology", "getInstance", "(", "DateTimeZone", "zone", ",", "int", "minDaysInFirstWeek", ")", "{", "if", "(", "zone", "==", "null", ")", "{", "zone", "=", "DateTimeZone", ".", "getDefault", "(", ")", ";", "}", "EthiopicChronology", "chrono", ";", "EthiopicChronology", "[", "]", "chronos", "=", "cCache", ".", "get", "(", "zone", ")", ";", "if", "(", "chronos", "==", "null", ")", "{", "chronos", "=", "new", "EthiopicChronology", "[", "7", "]", ";", "EthiopicChronology", "[", "]", "oldChronos", "=", "cCache", ".", "putIfAbsent", "(", "zone", ",", "chronos", ")", ";", "if", "(", "oldChronos", "!=", "null", ")", "{", "chronos", "=", "oldChronos", ";", "}", "}", "try", "{", "chrono", "=", "chronos", "[", "minDaysInFirstWeek", "-", "1", "]", ";", "}", "catch", "(", "ArrayIndexOutOfBoundsException", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid min days in first week: \"", "+", "minDaysInFirstWeek", ")", ";", "}", "if", "(", "chrono", "==", "null", ")", "{", "synchronized", "(", "chronos", ")", "{", "chrono", "=", "chronos", "[", "minDaysInFirstWeek", "-", "1", "]", ";", "if", "(", "chrono", "==", "null", ")", "{", "if", "(", "zone", "==", "DateTimeZone", ".", "UTC", ")", "{", "// First create without a lower limit.", "chrono", "=", "new", "EthiopicChronology", "(", "null", ",", "null", ",", "minDaysInFirstWeek", ")", ";", "// Impose lower limit and make another EthiopicChronology.", "DateTime", "lowerLimit", "=", "new", "DateTime", "(", "1", ",", "1", ",", "1", ",", "0", ",", "0", ",", "0", ",", "0", ",", "chrono", ")", ";", "chrono", "=", "new", "EthiopicChronology", "(", "LimitChronology", ".", "getInstance", "(", "chrono", ",", "lowerLimit", ",", "null", ")", ",", "null", ",", "minDaysInFirstWeek", ")", ";", "}", "else", "{", "chrono", "=", "getInstance", "(", "DateTimeZone", ".", "UTC", ",", "minDaysInFirstWeek", ")", ";", "chrono", "=", "new", "EthiopicChronology", "(", "ZonedChronology", ".", "getInstance", "(", "chrono", ",", "zone", ")", ",", "null", ",", "minDaysInFirstWeek", ")", ";", "}", "chronos", "[", "minDaysInFirstWeek", "-", "1", "]", "=", "chrono", ";", "}", "}", "}", "return", "chrono", ";", "}" ]
Gets an instance of the EthiopicChronology in the given time zone. @param zone the time zone to get the chronology in, null is default @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4 @return a chronology in the specified time zone
[ "Gets", "an", "instance", "of", "the", "EthiopicChronology", "in", "the", "given", "time", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/EthiopicChronology.java#L117-L159
22,273
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/GJDayOfWeekDateTimeField.java
GJDayOfWeekDateTimeField.getAsText
public String getAsText(int fieldValue, Locale locale) { return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToText(fieldValue); }
java
public String getAsText(int fieldValue, Locale locale) { return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToText(fieldValue); }
[ "public", "String", "getAsText", "(", "int", "fieldValue", ",", "Locale", "locale", ")", "{", "return", "GJLocaleSymbols", ".", "forLocale", "(", "locale", ")", ".", "dayOfWeekValueToText", "(", "fieldValue", ")", ";", "}" ]
Get the textual value of the specified time instant. @param fieldValue the field value to query @param locale the locale to use @return the day of the week, such as 'Monday'
[ "Get", "the", "textual", "value", "of", "the", "specified", "time", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/GJDayOfWeekDateTimeField.java#L67-L69
22,274
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/GJDayOfWeekDateTimeField.java
GJDayOfWeekDateTimeField.getAsShortText
public String getAsShortText(int fieldValue, Locale locale) { return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToShortText(fieldValue); }
java
public String getAsShortText(int fieldValue, Locale locale) { return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToShortText(fieldValue); }
[ "public", "String", "getAsShortText", "(", "int", "fieldValue", ",", "Locale", "locale", ")", "{", "return", "GJLocaleSymbols", ".", "forLocale", "(", "locale", ")", ".", "dayOfWeekValueToShortText", "(", "fieldValue", ")", ";", "}" ]
Get the abbreviated textual value of the specified time instant. @param fieldValue the field value to query @param locale the locale to use @return the day of the week, such as 'Mon'
[ "Get", "the", "abbreviated", "textual", "value", "of", "the", "specified", "time", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/GJDayOfWeekDateTimeField.java#L78-L80
22,275
JodaOrg/joda-time
src/main/java/org/joda/time/base/BaseSingleFieldPeriod.java
BaseSingleFieldPeriod.between
protected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field) { if (start == null || end == null) { throw new IllegalArgumentException("ReadableInstant objects must not be null"); } Chronology chrono = DateTimeUtils.getInstantChronology(start); int amount = field.getField(chrono).getDifference(end.getMillis(), start.getMillis()); return amount; }
java
protected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field) { if (start == null || end == null) { throw new IllegalArgumentException("ReadableInstant objects must not be null"); } Chronology chrono = DateTimeUtils.getInstantChronology(start); int amount = field.getField(chrono).getDifference(end.getMillis(), start.getMillis()); return amount; }
[ "protected", "static", "int", "between", "(", "ReadableInstant", "start", ",", "ReadableInstant", "end", ",", "DurationFieldType", "field", ")", "{", "if", "(", "start", "==", "null", "||", "end", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"ReadableInstant objects must not be null\"", ")", ";", "}", "Chronology", "chrono", "=", "DateTimeUtils", ".", "getInstantChronology", "(", "start", ")", ";", "int", "amount", "=", "field", ".", "getField", "(", "chrono", ")", ".", "getDifference", "(", "end", ".", "getMillis", "(", ")", ",", "start", ".", "getMillis", "(", ")", ")", ";", "return", "amount", ";", "}" ]
Calculates the number of whole units between the two specified datetimes. @param start the start instant, validated to not be null @param end the end instant, validated to not be null @param field the field type to use, must not be null @return the period @throws IllegalArgumentException if the instants are null or invalid
[ "Calculates", "the", "number", "of", "whole", "units", "between", "the", "two", "specified", "datetimes", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BaseSingleFieldPeriod.java#L67-L74
22,276
JodaOrg/joda-time
src/main/java/org/joda/time/base/BaseSingleFieldPeriod.java
BaseSingleFieldPeriod.compareTo
public int compareTo(BaseSingleFieldPeriod other) { if (other.getClass() != getClass()) { throw new ClassCastException(getClass() + " cannot be compared to " + other.getClass()); } int otherValue = other.getValue(); int thisValue = getValue(); if (thisValue > otherValue) { return 1; } if (thisValue < otherValue) { return -1; } return 0; }
java
public int compareTo(BaseSingleFieldPeriod other) { if (other.getClass() != getClass()) { throw new ClassCastException(getClass() + " cannot be compared to " + other.getClass()); } int otherValue = other.getValue(); int thisValue = getValue(); if (thisValue > otherValue) { return 1; } if (thisValue < otherValue) { return -1; } return 0; }
[ "public", "int", "compareTo", "(", "BaseSingleFieldPeriod", "other", ")", "{", "if", "(", "other", ".", "getClass", "(", ")", "!=", "getClass", "(", ")", ")", "{", "throw", "new", "ClassCastException", "(", "getClass", "(", ")", "+", "\" cannot be compared to \"", "+", "other", ".", "getClass", "(", ")", ")", ";", "}", "int", "otherValue", "=", "other", ".", "getValue", "(", ")", ";", "int", "thisValue", "=", "getValue", "(", ")", ";", "if", "(", "thisValue", ">", "otherValue", ")", "{", "return", "1", ";", "}", "if", "(", "thisValue", "<", "otherValue", ")", "{", "return", "-", "1", ";", "}", "return", "0", ";", "}" ]
Compares this period to another object of the same class. @param other the other period, must not be null @return zero if equal, positive if greater, negative if less @throws NullPointerException if the other period is null @throws ClassCastException if the other period is of a different type
[ "Compares", "this", "period", "to", "another", "object", "of", "the", "same", "class", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BaseSingleFieldPeriod.java#L331-L344
22,277
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/GJEraDateTimeField.java
GJEraDateTimeField.set
public long set(long instant, int era) { FieldUtils.verifyValueBounds(this, era, DateTimeConstants.BCE, DateTimeConstants.CE); int oldEra = get(instant); if (oldEra != era) { int year = iChronology.getYear(instant); return iChronology.setYear(instant, -year); } else { return instant; } }
java
public long set(long instant, int era) { FieldUtils.verifyValueBounds(this, era, DateTimeConstants.BCE, DateTimeConstants.CE); int oldEra = get(instant); if (oldEra != era) { int year = iChronology.getYear(instant); return iChronology.setYear(instant, -year); } else { return instant; } }
[ "public", "long", "set", "(", "long", "instant", ",", "int", "era", ")", "{", "FieldUtils", ".", "verifyValueBounds", "(", "this", ",", "era", ",", "DateTimeConstants", ".", "BCE", ",", "DateTimeConstants", ".", "CE", ")", ";", "int", "oldEra", "=", "get", "(", "instant", ")", ";", "if", "(", "oldEra", "!=", "era", ")", "{", "int", "year", "=", "iChronology", ".", "getYear", "(", "instant", ")", ";", "return", "iChronology", ".", "setYear", "(", "instant", ",", "-", "year", ")", ";", "}", "else", "{", "return", "instant", ";", "}", "}" ]
Set the Era component of the specified time instant. @param instant the time instant in millis to update. @param era the era to update the time to. @return the updated time instant. @throws IllegalArgumentException if era is invalid.
[ "Set", "the", "Era", "component", "of", "the", "specified", "time", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/GJEraDateTimeField.java#L80-L90
22,278
JodaOrg/joda-time
src/main/java/org/joda/time/DateMidnight.java
DateMidnight.withZoneRetainFields
public DateMidnight withZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return this; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); return new DateMidnight(millis, getChronology().withZone(newZone)); }
java
public DateMidnight withZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return this; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); return new DateMidnight(millis, getChronology().withZone(newZone)); }
[ "public", "DateMidnight", "withZoneRetainFields", "(", "DateTimeZone", "newZone", ")", "{", "newZone", "=", "DateTimeUtils", ".", "getZone", "(", "newZone", ")", ";", "DateTimeZone", "originalZone", "=", "DateTimeUtils", ".", "getZone", "(", "getZone", "(", ")", ")", ";", "if", "(", "newZone", "==", "originalZone", ")", "{", "return", "this", ";", "}", "long", "millis", "=", "originalZone", ".", "getMillisKeepLocal", "(", "newZone", ",", "getMillis", "(", ")", ")", ";", "return", "new", "DateMidnight", "(", "millis", ",", "getChronology", "(", ")", ".", "withZone", "(", "newZone", ")", ")", ";", "}" ]
Returns a copy of this date with a different time zone, preserving the day The returned object will have a local time of midnight in the new zone on the same day as the original instant. @param newZone the new time zone, null means default @return a copy of this instant with a different time zone
[ "Returns", "a", "copy", "of", "this", "date", "with", "a", "different", "time", "zone", "preserving", "the", "day", "The", "returned", "object", "will", "have", "a", "local", "time", "of", "midnight", "in", "the", "new", "zone", "on", "the", "same", "day", "as", "the", "original", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/DateMidnight.java#L414-L423
22,279
JodaOrg/joda-time
src/main/java/org/joda/time/field/PreciseDateTimeField.java
PreciseDateTimeField.get
public int get(long instant) { if (instant >= 0) { return (int) ((instant / getUnitMillis()) % iRange); } else { return iRange - 1 + (int) (((instant + 1) / getUnitMillis()) % iRange); } }
java
public int get(long instant) { if (instant >= 0) { return (int) ((instant / getUnitMillis()) % iRange); } else { return iRange - 1 + (int) (((instant + 1) / getUnitMillis()) % iRange); } }
[ "public", "int", "get", "(", "long", "instant", ")", "{", "if", "(", "instant", ">=", "0", ")", "{", "return", "(", "int", ")", "(", "(", "instant", "/", "getUnitMillis", "(", ")", ")", "%", "iRange", ")", ";", "}", "else", "{", "return", "iRange", "-", "1", "+", "(", "int", ")", "(", "(", "(", "instant", "+", "1", ")", "/", "getUnitMillis", "(", ")", ")", "%", "iRange", ")", ";", "}", "}" ]
Get the amount of fractional units from the specified time instant. @param instant the milliseconds from 1970-01-01T00:00:00Z to query @return the amount of fractional units extracted from the input.
[ "Get", "the", "amount", "of", "fractional", "units", "from", "the", "specified", "time", "instant", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/PreciseDateTimeField.java#L79-L85
22,280
JodaOrg/joda-time
src/main/java/org/joda/time/field/PreciseDateTimeField.java
PreciseDateTimeField.addWrapField
public long addWrapField(long instant, int amount) { int thisValue = get(instant); int wrappedValue = FieldUtils.getWrappedValue (thisValue, amount, getMinimumValue(), getMaximumValue()); // copy code from set() to avoid repeat call to get() return instant + (wrappedValue - thisValue) * getUnitMillis(); }
java
public long addWrapField(long instant, int amount) { int thisValue = get(instant); int wrappedValue = FieldUtils.getWrappedValue (thisValue, amount, getMinimumValue(), getMaximumValue()); // copy code from set() to avoid repeat call to get() return instant + (wrappedValue - thisValue) * getUnitMillis(); }
[ "public", "long", "addWrapField", "(", "long", "instant", ",", "int", "amount", ")", "{", "int", "thisValue", "=", "get", "(", "instant", ")", ";", "int", "wrappedValue", "=", "FieldUtils", ".", "getWrappedValue", "(", "thisValue", ",", "amount", ",", "getMinimumValue", "(", ")", ",", "getMaximumValue", "(", ")", ")", ";", "// copy code from set() to avoid repeat call to get()", "return", "instant", "+", "(", "wrappedValue", "-", "thisValue", ")", "*", "getUnitMillis", "(", ")", ";", "}" ]
Add to the component of the specified time instant, wrapping around within that component if necessary. @param instant the milliseconds from 1970-01-01T00:00:00Z to add to @param amount the amount of units to add (can be negative). @return the updated time instant.
[ "Add", "to", "the", "component", "of", "the", "specified", "time", "instant", "wrapping", "around", "within", "that", "component", "if", "necessary", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/PreciseDateTimeField.java#L95-L101
22,281
JodaOrg/joda-time
src/example/org/joda/example/time/DateTimePerformance.java
DateTimePerformance.end
private void end(int count) { end = System.currentTimeMillis(); long time = (end - start); result.time = result.time + time; result.runs = result.runs + count; result.avg = (result.time * 1000000) / result.runs; System.out.print("."); }
java
private void end(int count) { end = System.currentTimeMillis(); long time = (end - start); result.time = result.time + time; result.runs = result.runs + count; result.avg = (result.time * 1000000) / result.runs; System.out.print("."); }
[ "private", "void", "end", "(", "int", "count", ")", "{", "end", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "long", "time", "=", "(", "end", "-", "start", ")", ";", "result", ".", "time", "=", "result", ".", "time", "+", "time", ";", "result", ".", "runs", "=", "result", ".", "runs", "+", "count", ";", "result", ".", "avg", "=", "(", "result", ".", "time", "*", "1000000", ")", "/", "result", ".", "runs", ";", "System", ".", "out", ".", "print", "(", "\".\"", ")", ";", "}" ]
End the stopwatch and print the result.
[ "End", "the", "stopwatch", "and", "print", "the", "result", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/example/org/joda/example/time/DateTimePerformance.java#L891-L898
22,282
JodaOrg/joda-time
src/main/java/org/joda/time/format/DateTimeFormatter.java
DateTimeFormatter.selectChronology
private Chronology selectChronology(Chronology chrono) { chrono = DateTimeUtils.getChronology(chrono); if (iChrono != null) { chrono = iChrono; } if (iZone != null) { chrono = chrono.withZone(iZone); } return chrono; }
java
private Chronology selectChronology(Chronology chrono) { chrono = DateTimeUtils.getChronology(chrono); if (iChrono != null) { chrono = iChrono; } if (iZone != null) { chrono = chrono.withZone(iZone); } return chrono; }
[ "private", "Chronology", "selectChronology", "(", "Chronology", "chrono", ")", "{", "chrono", "=", "DateTimeUtils", ".", "getChronology", "(", "chrono", ")", ";", "if", "(", "iChrono", "!=", "null", ")", "{", "chrono", "=", "iChrono", ";", "}", "if", "(", "iZone", "!=", "null", ")", "{", "chrono", "=", "chrono", ".", "withZone", "(", "iZone", ")", ";", "}", "return", "chrono", ";", "}" ]
Determines the correct chronology to use. @param chrono the proposed chronology @return the actual chronology
[ "Determines", "the", "correct", "chronology", "to", "use", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/format/DateTimeFormatter.java#L1013-L1022
22,283
JodaOrg/joda-time
src/main/java/org/joda/time/IllegalFieldValueException.java
IllegalFieldValueException.getIllegalValueAsString
public String getIllegalValueAsString() { String value = iStringValue; if (value == null) { value = String.valueOf(iNumberValue); } return value; }
java
public String getIllegalValueAsString() { String value = iStringValue; if (value == null) { value = String.valueOf(iNumberValue); } return value; }
[ "public", "String", "getIllegalValueAsString", "(", ")", "{", "String", "value", "=", "iStringValue", ";", "if", "(", "value", "==", "null", ")", "{", "value", "=", "String", ".", "valueOf", "(", "iNumberValue", ")", ";", "}", "return", "value", ";", "}" ]
Returns the illegal value assigned to the field as a non-null string. @return the value
[ "Returns", "the", "illegal", "value", "assigned", "to", "the", "field", "as", "a", "non", "-", "null", "string", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/IllegalFieldValueException.java#L287-L293
22,284
JodaOrg/joda-time
src/main/java/org/joda/time/IllegalFieldValueException.java
IllegalFieldValueException.prependMessage
public void prependMessage(String message) { if (iMessage == null) { iMessage = message; } else if (message != null) { iMessage = message + ": " + iMessage; } }
java
public void prependMessage(String message) { if (iMessage == null) { iMessage = message; } else if (message != null) { iMessage = message + ": " + iMessage; } }
[ "public", "void", "prependMessage", "(", "String", "message", ")", "{", "if", "(", "iMessage", "==", "null", ")", "{", "iMessage", "=", "message", ";", "}", "else", "if", "(", "message", "!=", "null", ")", "{", "iMessage", "=", "message", "+", "\": \"", "+", "iMessage", ";", "}", "}" ]
Provide additional detail by prepending a message to the existing message. A colon is separator is automatically inserted between the messages. @since 1.3
[ "Provide", "additional", "detail", "by", "prepending", "a", "message", "to", "the", "existing", "message", ".", "A", "colon", "is", "separator", "is", "automatically", "inserted", "between", "the", "messages", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/IllegalFieldValueException.java#L322-L328
22,285
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/GJChronology.java
GJChronology.withZone
public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } return getInstance(zone, iCutoverInstant, getMinimumDaysInFirstWeek()); }
java
public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } return getInstance(zone, iCutoverInstant, getMinimumDaysInFirstWeek()); }
[ "public", "Chronology", "withZone", "(", "DateTimeZone", "zone", ")", "{", "if", "(", "zone", "==", "null", ")", "{", "zone", "=", "DateTimeZone", ".", "getDefault", "(", ")", ";", "}", "if", "(", "zone", "==", "getZone", "(", ")", ")", "{", "return", "this", ";", "}", "return", "getInstance", "(", "zone", ",", "iCutoverInstant", ",", "getMinimumDaysInFirstWeek", "(", ")", ")", ";", "}" ]
Gets the Chronology in a specific time zone. @param zone the zone to get the chronology in, null is default @return the chronology
[ "Gets", "the", "Chronology", "in", "a", "specific", "time", "zone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/GJChronology.java#L307-L315
22,286
JodaOrg/joda-time
src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java
DateTimeZoneBuilder.readMillis
static long readMillis(DataInput in) throws IOException { int v = in.readUnsignedByte(); switch (v >> 6) { case 0: default: // Form 00 (6 bits effective precision) v = (v << (32 - 6)) >> (32 - 6); return v * (30 * 60000L); case 1: // Form 01 (30 bits effective precision) v = (v << (32 - 6)) >> (32 - 30); v |= (in.readUnsignedByte()) << 16; v |= (in.readUnsignedByte()) << 8; v |= (in.readUnsignedByte()); return v * 60000L; case 2: // Form 10 (38 bits effective precision) long w = (((long)v) << (64 - 6)) >> (64 - 38); w |= (in.readUnsignedByte()) << 24; w |= (in.readUnsignedByte()) << 16; w |= (in.readUnsignedByte()) << 8; w |= (in.readUnsignedByte()); return w * 1000L; case 3: // Form 11 (64-bits effective precision) return in.readLong(); } }
java
static long readMillis(DataInput in) throws IOException { int v = in.readUnsignedByte(); switch (v >> 6) { case 0: default: // Form 00 (6 bits effective precision) v = (v << (32 - 6)) >> (32 - 6); return v * (30 * 60000L); case 1: // Form 01 (30 bits effective precision) v = (v << (32 - 6)) >> (32 - 30); v |= (in.readUnsignedByte()) << 16; v |= (in.readUnsignedByte()) << 8; v |= (in.readUnsignedByte()); return v * 60000L; case 2: // Form 10 (38 bits effective precision) long w = (((long)v) << (64 - 6)) >> (64 - 38); w |= (in.readUnsignedByte()) << 24; w |= (in.readUnsignedByte()) << 16; w |= (in.readUnsignedByte()) << 8; w |= (in.readUnsignedByte()); return w * 1000L; case 3: // Form 11 (64-bits effective precision) return in.readLong(); } }
[ "static", "long", "readMillis", "(", "DataInput", "in", ")", "throws", "IOException", "{", "int", "v", "=", "in", ".", "readUnsignedByte", "(", ")", ";", "switch", "(", "v", ">>", "6", ")", "{", "case", "0", ":", "default", ":", "// Form 00 (6 bits effective precision)", "v", "=", "(", "v", "<<", "(", "32", "-", "6", ")", ")", ">>", "(", "32", "-", "6", ")", ";", "return", "v", "*", "(", "30", "*", "60000L", ")", ";", "case", "1", ":", "// Form 01 (30 bits effective precision)", "v", "=", "(", "v", "<<", "(", "32", "-", "6", ")", ")", ">>", "(", "32", "-", "30", ")", ";", "v", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", "<<", "16", ";", "v", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", "<<", "8", ";", "v", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", ";", "return", "v", "*", "60000L", ";", "case", "2", ":", "// Form 10 (38 bits effective precision)", "long", "w", "=", "(", "(", "(", "long", ")", "v", ")", "<<", "(", "64", "-", "6", ")", ")", ">>", "(", "64", "-", "38", ")", ";", "w", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", "<<", "24", ";", "w", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", "<<", "16", ";", "w", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", "<<", "8", ";", "w", "|=", "(", "in", ".", "readUnsignedByte", "(", ")", ")", ";", "return", "w", "*", "1000L", ";", "case", "3", ":", "// Form 11 (64-bits effective precision)", "return", "in", ".", "readLong", "(", ")", ";", "}", "}" ]
Reads encoding generated by writeMillis.
[ "Reads", "encoding", "generated", "by", "writeMillis", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java#L183-L212
22,287
JodaOrg/joda-time
src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java
DateTimeZoneBuilder.addCutover
public DateTimeZoneBuilder addCutover(int year, char mode, int monthOfYear, int dayOfMonth, int dayOfWeek, boolean advanceDayOfWeek, int millisOfDay) { if (iRuleSets.size() > 0) { OfYear ofYear = new OfYear (mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay); RuleSet lastRuleSet = iRuleSets.get(iRuleSets.size() - 1); lastRuleSet.setUpperLimit(year, ofYear); } iRuleSets.add(new RuleSet()); return this; }
java
public DateTimeZoneBuilder addCutover(int year, char mode, int monthOfYear, int dayOfMonth, int dayOfWeek, boolean advanceDayOfWeek, int millisOfDay) { if (iRuleSets.size() > 0) { OfYear ofYear = new OfYear (mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay); RuleSet lastRuleSet = iRuleSets.get(iRuleSets.size() - 1); lastRuleSet.setUpperLimit(year, ofYear); } iRuleSets.add(new RuleSet()); return this; }
[ "public", "DateTimeZoneBuilder", "addCutover", "(", "int", "year", ",", "char", "mode", ",", "int", "monthOfYear", ",", "int", "dayOfMonth", ",", "int", "dayOfWeek", ",", "boolean", "advanceDayOfWeek", ",", "int", "millisOfDay", ")", "{", "if", "(", "iRuleSets", ".", "size", "(", ")", ">", "0", ")", "{", "OfYear", "ofYear", "=", "new", "OfYear", "(", "mode", ",", "monthOfYear", ",", "dayOfMonth", ",", "dayOfWeek", ",", "advanceDayOfWeek", ",", "millisOfDay", ")", ";", "RuleSet", "lastRuleSet", "=", "iRuleSets", ".", "get", "(", "iRuleSets", ".", "size", "(", ")", "-", "1", ")", ";", "lastRuleSet", ".", "setUpperLimit", "(", "year", ",", "ofYear", ")", ";", "}", "iRuleSets", ".", "add", "(", "new", "RuleSet", "(", ")", ")", ";", "return", "this", ";", "}" ]
Adds a cutover for added rules. The standard offset at the cutover defaults to 0. Call setStandardOffset afterwards to change it. @param year the year of cutover @param mode 'u' - cutover is measured against UTC, 'w' - against wall offset, 's' - against standard offset @param monthOfYear the month from 1 (January) to 12 (December) @param dayOfMonth if negative, set to ((last day of month) - ~dayOfMonth). For example, if -1, set to last day of month @param dayOfWeek from 1 (Monday) to 7 (Sunday), if 0 then ignore @param advanceDayOfWeek if dayOfMonth does not fall on dayOfWeek, advance to dayOfWeek when true, retreat when false. @param millisOfDay additional precision for specifying time of day of cutover
[ "Adds", "a", "cutover", "for", "added", "rules", ".", "The", "standard", "offset", "at", "the", "cutover", "defaults", "to", "0", ".", "Call", "setStandardOffset", "afterwards", "to", "change", "it", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java#L245-L261
22,288
JodaOrg/joda-time
src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java
DateTimeZoneBuilder.addRecurringSavings
public DateTimeZoneBuilder addRecurringSavings(String nameKey, int saveMillis, int fromYear, int toYear, char mode, int monthOfYear, int dayOfMonth, int dayOfWeek, boolean advanceDayOfWeek, int millisOfDay) { if (fromYear <= toYear) { OfYear ofYear = new OfYear (mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay); Recurrence recurrence = new Recurrence(ofYear, nameKey, saveMillis); Rule rule = new Rule(recurrence, fromYear, toYear); getLastRuleSet().addRule(rule); } return this; }
java
public DateTimeZoneBuilder addRecurringSavings(String nameKey, int saveMillis, int fromYear, int toYear, char mode, int monthOfYear, int dayOfMonth, int dayOfWeek, boolean advanceDayOfWeek, int millisOfDay) { if (fromYear <= toYear) { OfYear ofYear = new OfYear (mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay); Recurrence recurrence = new Recurrence(ofYear, nameKey, saveMillis); Rule rule = new Rule(recurrence, fromYear, toYear); getLastRuleSet().addRule(rule); } return this; }
[ "public", "DateTimeZoneBuilder", "addRecurringSavings", "(", "String", "nameKey", ",", "int", "saveMillis", ",", "int", "fromYear", ",", "int", "toYear", ",", "char", "mode", ",", "int", "monthOfYear", ",", "int", "dayOfMonth", ",", "int", "dayOfWeek", ",", "boolean", "advanceDayOfWeek", ",", "int", "millisOfDay", ")", "{", "if", "(", "fromYear", "<=", "toYear", ")", "{", "OfYear", "ofYear", "=", "new", "OfYear", "(", "mode", ",", "monthOfYear", ",", "dayOfMonth", ",", "dayOfWeek", ",", "advanceDayOfWeek", ",", "millisOfDay", ")", ";", "Recurrence", "recurrence", "=", "new", "Recurrence", "(", "ofYear", ",", "nameKey", ",", "saveMillis", ")", ";", "Rule", "rule", "=", "new", "Rule", "(", "recurrence", ",", "fromYear", ",", "toYear", ")", ";", "getLastRuleSet", "(", ")", ".", "addRule", "(", "rule", ")", ";", "}", "return", "this", ";", "}" ]
Add a recurring daylight saving time rule. @param nameKey the name key of new rule @param saveMillis the milliseconds to add to standard offset @param fromYear the first year that rule is in effect, MIN_VALUE indicates beginning of time @param toYear the last year (inclusive) that rule is in effect, MAX_VALUE indicates end of time @param mode 'u' - transitions are calculated against UTC, 'w' - transitions are calculated against wall offset, 's' - transitions are calculated against standard offset @param monthOfYear the month from 1 (January) to 12 (December) @param dayOfMonth if negative, set to ((last day of month) - ~dayOfMonth). For example, if -1, set to last day of month @param dayOfWeek from 1 (Monday) to 7 (Sunday), if 0 then ignore @param advanceDayOfWeek if dayOfMonth does not fall on dayOfWeek, advance to dayOfWeek when true, retreat when false. @param millisOfDay additional precision for specifying time of day of transitions
[ "Add", "a", "recurring", "daylight", "saving", "time", "rule", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java#L301-L318
22,289
JodaOrg/joda-time
src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java
DateTimeZoneBuilder.toDateTimeZone
public DateTimeZone toDateTimeZone(String id, boolean outputID) { if (id == null) { throw new IllegalArgumentException(); } // Discover where all the transitions occur and store the results in // these lists. ArrayList<Transition> transitions = new ArrayList<Transition>(); // Tail zone picks up remaining transitions in the form of an endless // DST cycle. DSTZone tailZone = null; long millis = Long.MIN_VALUE; int saveMillis = 0; int ruleSetCount = iRuleSets.size(); for (int i=0; i<ruleSetCount; i++) { RuleSet rs = iRuleSets.get(i); Transition next = rs.firstTransition(millis); if (next == null) { continue; } addTransition(transitions, next); millis = next.getMillis(); saveMillis = next.getSaveMillis(); // Copy it since we're going to destroy it. rs = new RuleSet(rs); while ((next = rs.nextTransition(millis, saveMillis)) != null) { if (addTransition(transitions, next) && tailZone != null) { // Got the extra transition before DSTZone. break; } millis = next.getMillis(); saveMillis = next.getSaveMillis(); if (tailZone == null && i == ruleSetCount - 1) { tailZone = rs.buildTailZone(id); // If tailZone is not null, don't break out of main loop until // at least one more transition is calculated. This ensures a // correct 'seam' to the DSTZone. } } millis = rs.getUpperLimit(saveMillis); } // Check if a simpler zone implementation can be returned. if (transitions.size() == 0) { if (tailZone != null) { // This shouldn't happen, but handle just in case. return tailZone; } return buildFixedZone(id, "UTC", 0, 0); } if (transitions.size() == 1 && tailZone == null) { Transition tr = transitions.get(0); return buildFixedZone(id, tr.getNameKey(), tr.getWallOffset(), tr.getStandardOffset()); } PrecalculatedZone zone = PrecalculatedZone.create(id, outputID, transitions, tailZone); if (zone.isCachable()) { return CachedDateTimeZone.forZone(zone); } return zone; }
java
public DateTimeZone toDateTimeZone(String id, boolean outputID) { if (id == null) { throw new IllegalArgumentException(); } // Discover where all the transitions occur and store the results in // these lists. ArrayList<Transition> transitions = new ArrayList<Transition>(); // Tail zone picks up remaining transitions in the form of an endless // DST cycle. DSTZone tailZone = null; long millis = Long.MIN_VALUE; int saveMillis = 0; int ruleSetCount = iRuleSets.size(); for (int i=0; i<ruleSetCount; i++) { RuleSet rs = iRuleSets.get(i); Transition next = rs.firstTransition(millis); if (next == null) { continue; } addTransition(transitions, next); millis = next.getMillis(); saveMillis = next.getSaveMillis(); // Copy it since we're going to destroy it. rs = new RuleSet(rs); while ((next = rs.nextTransition(millis, saveMillis)) != null) { if (addTransition(transitions, next) && tailZone != null) { // Got the extra transition before DSTZone. break; } millis = next.getMillis(); saveMillis = next.getSaveMillis(); if (tailZone == null && i == ruleSetCount - 1) { tailZone = rs.buildTailZone(id); // If tailZone is not null, don't break out of main loop until // at least one more transition is calculated. This ensures a // correct 'seam' to the DSTZone. } } millis = rs.getUpperLimit(saveMillis); } // Check if a simpler zone implementation can be returned. if (transitions.size() == 0) { if (tailZone != null) { // This shouldn't happen, but handle just in case. return tailZone; } return buildFixedZone(id, "UTC", 0, 0); } if (transitions.size() == 1 && tailZone == null) { Transition tr = transitions.get(0); return buildFixedZone(id, tr.getNameKey(), tr.getWallOffset(), tr.getStandardOffset()); } PrecalculatedZone zone = PrecalculatedZone.create(id, outputID, transitions, tailZone); if (zone.isCachable()) { return CachedDateTimeZone.forZone(zone); } return zone; }
[ "public", "DateTimeZone", "toDateTimeZone", "(", "String", "id", ",", "boolean", "outputID", ")", "{", "if", "(", "id", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "// Discover where all the transitions occur and store the results in", "// these lists.", "ArrayList", "<", "Transition", ">", "transitions", "=", "new", "ArrayList", "<", "Transition", ">", "(", ")", ";", "// Tail zone picks up remaining transitions in the form of an endless", "// DST cycle.", "DSTZone", "tailZone", "=", "null", ";", "long", "millis", "=", "Long", ".", "MIN_VALUE", ";", "int", "saveMillis", "=", "0", ";", "int", "ruleSetCount", "=", "iRuleSets", ".", "size", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ruleSetCount", ";", "i", "++", ")", "{", "RuleSet", "rs", "=", "iRuleSets", ".", "get", "(", "i", ")", ";", "Transition", "next", "=", "rs", ".", "firstTransition", "(", "millis", ")", ";", "if", "(", "next", "==", "null", ")", "{", "continue", ";", "}", "addTransition", "(", "transitions", ",", "next", ")", ";", "millis", "=", "next", ".", "getMillis", "(", ")", ";", "saveMillis", "=", "next", ".", "getSaveMillis", "(", ")", ";", "// Copy it since we're going to destroy it.", "rs", "=", "new", "RuleSet", "(", "rs", ")", ";", "while", "(", "(", "next", "=", "rs", ".", "nextTransition", "(", "millis", ",", "saveMillis", ")", ")", "!=", "null", ")", "{", "if", "(", "addTransition", "(", "transitions", ",", "next", ")", "&&", "tailZone", "!=", "null", ")", "{", "// Got the extra transition before DSTZone.", "break", ";", "}", "millis", "=", "next", ".", "getMillis", "(", ")", ";", "saveMillis", "=", "next", ".", "getSaveMillis", "(", ")", ";", "if", "(", "tailZone", "==", "null", "&&", "i", "==", "ruleSetCount", "-", "1", ")", "{", "tailZone", "=", "rs", ".", "buildTailZone", "(", "id", ")", ";", "// If tailZone is not null, don't break out of main loop until", "// at least one more transition is calculated. This ensures a", "// correct 'seam' to the DSTZone.", "}", "}", "millis", "=", "rs", ".", "getUpperLimit", "(", "saveMillis", ")", ";", "}", "// Check if a simpler zone implementation can be returned.", "if", "(", "transitions", ".", "size", "(", ")", "==", "0", ")", "{", "if", "(", "tailZone", "!=", "null", ")", "{", "// This shouldn't happen, but handle just in case.", "return", "tailZone", ";", "}", "return", "buildFixedZone", "(", "id", ",", "\"UTC\"", ",", "0", ",", "0", ")", ";", "}", "if", "(", "transitions", ".", "size", "(", ")", "==", "1", "&&", "tailZone", "==", "null", ")", "{", "Transition", "tr", "=", "transitions", ".", "get", "(", "0", ")", ";", "return", "buildFixedZone", "(", "id", ",", "tr", ".", "getNameKey", "(", ")", ",", "tr", ".", "getWallOffset", "(", ")", ",", "tr", ".", "getStandardOffset", "(", ")", ")", ";", "}", "PrecalculatedZone", "zone", "=", "PrecalculatedZone", ".", "create", "(", "id", ",", "outputID", ",", "transitions", ",", "tailZone", ")", ";", "if", "(", "zone", ".", "isCachable", "(", ")", ")", "{", "return", "CachedDateTimeZone", ".", "forZone", "(", "zone", ")", ";", "}", "return", "zone", ";", "}" ]
Processes all the rules and builds a DateTimeZone. @param id time zone id to assign @param outputID true if the zone id should be output
[ "Processes", "all", "the", "rules", "and", "builds", "a", "DateTimeZone", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java#L333-L400
22,290
JodaOrg/joda-time
src/main/java/org/joda/time/LocalDateTime.java
LocalDateTime.isSupported
public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } return type.getField(getChronology()).isSupported(); }
java
public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } return type.getField(getChronology()).isSupported(); }
[ "public", "boolean", "isSupported", "(", "DurationFieldType", "type", ")", "{", "if", "(", "type", "==", "null", ")", "{", "return", "false", ";", "}", "return", "type", ".", "getField", "(", "getChronology", "(", ")", ")", ".", "isSupported", "(", ")", ";", "}" ]
Checks if the duration type specified is supported by this local datetime and chronology. @param type a duration type, usually obtained from DurationFieldType @return true if the field type is supported
[ "Checks", "if", "the", "duration", "type", "specified", "is", "supported", "by", "this", "local", "datetime", "and", "chronology", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/LocalDateTime.java#L635-L640
22,291
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/ZonedChronology.java
ZonedChronology.getInstance
public static ZonedChronology getInstance(Chronology base, DateTimeZone zone) { if (base == null) { throw new IllegalArgumentException("Must supply a chronology"); } base = base.withUTC(); if (base == null) { throw new IllegalArgumentException("UTC chronology must not be null"); } if (zone == null) { throw new IllegalArgumentException("DateTimeZone must not be null"); } return new ZonedChronology(base, zone); }
java
public static ZonedChronology getInstance(Chronology base, DateTimeZone zone) { if (base == null) { throw new IllegalArgumentException("Must supply a chronology"); } base = base.withUTC(); if (base == null) { throw new IllegalArgumentException("UTC chronology must not be null"); } if (zone == null) { throw new IllegalArgumentException("DateTimeZone must not be null"); } return new ZonedChronology(base, zone); }
[ "public", "static", "ZonedChronology", "getInstance", "(", "Chronology", "base", ",", "DateTimeZone", "zone", ")", "{", "if", "(", "base", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Must supply a chronology\"", ")", ";", "}", "base", "=", "base", ".", "withUTC", "(", ")", ";", "if", "(", "base", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"UTC chronology must not be null\"", ")", ";", "}", "if", "(", "zone", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"DateTimeZone must not be null\"", ")", ";", "}", "return", "new", "ZonedChronology", "(", "base", ",", "zone", ")", ";", "}" ]
Create a ZonedChronology for any chronology, overriding any time zone it may already have. @param base base chronology to wrap @param zone the time zone @throws IllegalArgumentException if chronology or time zone is null
[ "Create", "a", "ZonedChronology", "for", "any", "chronology", "overriding", "any", "time", "zone", "it", "may", "already", "have", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/ZonedChronology.java#L58-L70
22,292
JodaOrg/joda-time
src/main/java/org/joda/time/base/BasePeriod.java
BasePeriod.checkAndUpdate
private void checkAndUpdate(DurationFieldType type, int[] values, int newValue) { int index = indexOf(type); if (index == -1) { if (newValue != 0) { throw new IllegalArgumentException( "Period does not support field '" + type.getName() + "'"); } } else { values[index] = newValue; } }
java
private void checkAndUpdate(DurationFieldType type, int[] values, int newValue) { int index = indexOf(type); if (index == -1) { if (newValue != 0) { throw new IllegalArgumentException( "Period does not support field '" + type.getName() + "'"); } } else { values[index] = newValue; } }
[ "private", "void", "checkAndUpdate", "(", "DurationFieldType", "type", ",", "int", "[", "]", "values", ",", "int", "newValue", ")", "{", "int", "index", "=", "indexOf", "(", "type", ")", ";", "if", "(", "index", "==", "-", "1", ")", "{", "if", "(", "newValue", "!=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Period does not support field '\"", "+", "type", ".", "getName", "(", ")", "+", "\"'\"", ")", ";", "}", "}", "else", "{", "values", "[", "index", "]", "=", "newValue", ";", "}", "}" ]
Checks whether a field type is supported, and if so adds the new value to the relevant index in the specified array. @param type the field type @param values the array to update @param newValue the new value to store if successful
[ "Checks", "whether", "a", "field", "type", "is", "supported", "and", "if", "so", "adds", "the", "new", "value", "to", "the", "relevant", "index", "in", "the", "specified", "array", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BasePeriod.java#L389-L399
22,293
JodaOrg/joda-time
src/main/java/org/joda/time/base/BasePeriod.java
BasePeriod.setPeriod
protected void setPeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis) { int[] newValues = setPeriodInternal(years, months, weeks, days, hours, minutes, seconds, millis); setValues(newValues); }
java
protected void setPeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis) { int[] newValues = setPeriodInternal(years, months, weeks, days, hours, minutes, seconds, millis); setValues(newValues); }
[ "protected", "void", "setPeriod", "(", "int", "years", ",", "int", "months", ",", "int", "weeks", ",", "int", "days", ",", "int", "hours", ",", "int", "minutes", ",", "int", "seconds", ",", "int", "millis", ")", "{", "int", "[", "]", "newValues", "=", "setPeriodInternal", "(", "years", ",", "months", ",", "weeks", ",", "days", ",", "hours", ",", "minutes", ",", "seconds", ",", "millis", ")", ";", "setValues", "(", "newValues", ")", ";", "}" ]
Sets the eight standard the fields in one go. @param years amount of years in this period, which must be zero if unsupported @param months amount of months in this period, which must be zero if unsupported @param weeks amount of weeks in this period, which must be zero if unsupported @param days amount of days in this period, which must be zero if unsupported @param hours amount of hours in this period, which must be zero if unsupported @param minutes amount of minutes in this period, which must be zero if unsupported @param seconds amount of seconds in this period, which must be zero if unsupported @param millis amount of milliseconds in this period, which must be zero if unsupported @throws IllegalArgumentException if an unsupported field's value is non-zero
[ "Sets", "the", "eight", "standard", "the", "fields", "in", "one", "go", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BasePeriod.java#L442-L446
22,294
JodaOrg/joda-time
src/main/java/org/joda/time/base/BasePeriod.java
BasePeriod.setFieldInto
protected void setFieldInto(int[] values, DurationFieldType field, int value) { int index = indexOf(field); if (index == -1) { if (value != 0 || field == null) { throw new IllegalArgumentException( "Period does not support field '" + field + "'"); } } else { values[index] = value; } }
java
protected void setFieldInto(int[] values, DurationFieldType field, int value) { int index = indexOf(field); if (index == -1) { if (value != 0 || field == null) { throw new IllegalArgumentException( "Period does not support field '" + field + "'"); } } else { values[index] = value; } }
[ "protected", "void", "setFieldInto", "(", "int", "[", "]", "values", ",", "DurationFieldType", "field", ",", "int", "value", ")", "{", "int", "index", "=", "indexOf", "(", "field", ")", ";", "if", "(", "index", "==", "-", "1", ")", "{", "if", "(", "value", "!=", "0", "||", "field", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Period does not support field '\"", "+", "field", "+", "\"'\"", ")", ";", "}", "}", "else", "{", "values", "[", "index", "]", "=", "value", ";", "}", "}" ]
Sets the value of a field in this period. @param values the array of values to update @param field the field to set @param value the value to set @throws IllegalArgumentException if field is null or not supported.
[ "Sets", "the", "value", "of", "a", "field", "in", "this", "period", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BasePeriod.java#L485-L495
22,295
JodaOrg/joda-time
src/main/java/org/joda/time/base/BasePeriod.java
BasePeriod.addFieldInto
protected void addFieldInto(int[] values, DurationFieldType field, int value) { int index = indexOf(field); if (index == -1) { if (value != 0 || field == null) { throw new IllegalArgumentException( "Period does not support field '" + field + "'"); } } else { values[index] = FieldUtils.safeAdd(values[index], value); } }
java
protected void addFieldInto(int[] values, DurationFieldType field, int value) { int index = indexOf(field); if (index == -1) { if (value != 0 || field == null) { throw new IllegalArgumentException( "Period does not support field '" + field + "'"); } } else { values[index] = FieldUtils.safeAdd(values[index], value); } }
[ "protected", "void", "addFieldInto", "(", "int", "[", "]", "values", ",", "DurationFieldType", "field", ",", "int", "value", ")", "{", "int", "index", "=", "indexOf", "(", "field", ")", ";", "if", "(", "index", "==", "-", "1", ")", "{", "if", "(", "value", "!=", "0", "||", "field", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Period does not support field '\"", "+", "field", "+", "\"'\"", ")", ";", "}", "}", "else", "{", "values", "[", "index", "]", "=", "FieldUtils", ".", "safeAdd", "(", "values", "[", "index", "]", ",", "value", ")", ";", "}", "}" ]
Adds the value of a field in this period. @param values the array of values to update @param field the field to set @param value the value to set @throws IllegalArgumentException if field is is null or not supported.
[ "Adds", "the", "value", "of", "a", "field", "in", "this", "period", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BasePeriod.java#L516-L526
22,296
JodaOrg/joda-time
src/main/java/org/joda/time/base/BasePeriod.java
BasePeriod.mergePeriodInto
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) { for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); checkAndUpdate(type, values, value); } return values; }
java
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) { for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); checkAndUpdate(type, values, value); } return values; }
[ "protected", "int", "[", "]", "mergePeriodInto", "(", "int", "[", "]", "values", ",", "ReadablePeriod", "period", ")", "{", "for", "(", "int", "i", "=", "0", ",", "isize", "=", "period", ".", "size", "(", ")", ";", "i", "<", "isize", ";", "i", "++", ")", "{", "DurationFieldType", "type", "=", "period", ".", "getFieldType", "(", "i", ")", ";", "int", "value", "=", "period", ".", "getValue", "(", "i", ")", ";", "checkAndUpdate", "(", "type", ",", "values", ",", "value", ")", ";", "}", "return", "values", ";", "}" ]
Merges the fields from another period. @param values the array of values to update @param period the period to add from, not null @return the updated values @throws IllegalArgumentException if an unsupported field's value is non-zero
[ "Merges", "the", "fields", "from", "another", "period", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BasePeriod.java#L548-L555
22,297
JodaOrg/joda-time
src/main/java/org/joda/time/base/BasePeriod.java
BasePeriod.addPeriodInto
protected int[] addPeriodInto(int[] values, ReadablePeriod period) { for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); if (value != 0) { int index = indexOf(type); if (index == -1) { throw new IllegalArgumentException( "Period does not support field '" + type.getName() + "'"); } else { values[index] = FieldUtils.safeAdd(getValue(index), value); } } } return values; }
java
protected int[] addPeriodInto(int[] values, ReadablePeriod period) { for (int i = 0, isize = period.size(); i < isize; i++) { DurationFieldType type = period.getFieldType(i); int value = period.getValue(i); if (value != 0) { int index = indexOf(type); if (index == -1) { throw new IllegalArgumentException( "Period does not support field '" + type.getName() + "'"); } else { values[index] = FieldUtils.safeAdd(getValue(index), value); } } } return values; }
[ "protected", "int", "[", "]", "addPeriodInto", "(", "int", "[", "]", "values", ",", "ReadablePeriod", "period", ")", "{", "for", "(", "int", "i", "=", "0", ",", "isize", "=", "period", ".", "size", "(", ")", ";", "i", "<", "isize", ";", "i", "++", ")", "{", "DurationFieldType", "type", "=", "period", ".", "getFieldType", "(", "i", ")", ";", "int", "value", "=", "period", ".", "getValue", "(", "i", ")", ";", "if", "(", "value", "!=", "0", ")", "{", "int", "index", "=", "indexOf", "(", "type", ")", ";", "if", "(", "index", "==", "-", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Period does not support field '\"", "+", "type", ".", "getName", "(", ")", "+", "\"'\"", ")", ";", "}", "else", "{", "values", "[", "index", "]", "=", "FieldUtils", ".", "safeAdd", "(", "getValue", "(", "index", ")", ",", "value", ")", ";", "}", "}", "}", "return", "values", ";", "}" ]
Adds the fields from another period. @param values the array of values to update @param period the period to add from, not null @return the updated values @throws IllegalArgumentException if an unsupported field's value is non-zero
[ "Adds", "the", "fields", "from", "another", "period", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/base/BasePeriod.java#L577-L592
22,298
JodaOrg/joda-time
src/main/java/org/joda/time/chrono/GJLocaleSymbols.java
GJLocaleSymbols.forLocale
static GJLocaleSymbols forLocale(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } GJLocaleSymbols symbols = cCache.get(locale); if (symbols == null) { symbols = new GJLocaleSymbols(locale); GJLocaleSymbols oldSymbols = cCache.putIfAbsent(locale, symbols); if (oldSymbols != null) { symbols = oldSymbols; } } return symbols; }
java
static GJLocaleSymbols forLocale(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } GJLocaleSymbols symbols = cCache.get(locale); if (symbols == null) { symbols = new GJLocaleSymbols(locale); GJLocaleSymbols oldSymbols = cCache.putIfAbsent(locale, symbols); if (oldSymbols != null) { symbols = oldSymbols; } } return symbols; }
[ "static", "GJLocaleSymbols", "forLocale", "(", "Locale", "locale", ")", "{", "if", "(", "locale", "==", "null", ")", "{", "locale", "=", "Locale", ".", "getDefault", "(", ")", ";", "}", "GJLocaleSymbols", "symbols", "=", "cCache", ".", "get", "(", "locale", ")", ";", "if", "(", "symbols", "==", "null", ")", "{", "symbols", "=", "new", "GJLocaleSymbols", "(", "locale", ")", ";", "GJLocaleSymbols", "oldSymbols", "=", "cCache", ".", "putIfAbsent", "(", "locale", ",", "symbols", ")", ";", "if", "(", "oldSymbols", "!=", "null", ")", "{", "symbols", "=", "oldSymbols", ";", "}", "}", "return", "symbols", ";", "}" ]
Obtains the symbols for a locale. @param locale the locale, null returns default @return the symbols, not null
[ "Obtains", "the", "symbols", "for", "a", "locale", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/chrono/GJLocaleSymbols.java#L44-L57
22,299
JodaOrg/joda-time
src/main/java/org/joda/time/field/FieldUtils.java
FieldUtils.safeAdd
public static int safeAdd(int val1, int val2) { int sum = val1 + val2; // If there is a sign change, but the two values have the same sign... if ((val1 ^ sum) < 0 && (val1 ^ val2) >= 0) { throw new ArithmeticException ("The calculation caused an overflow: " + val1 + " + " + val2); } return sum; }
java
public static int safeAdd(int val1, int val2) { int sum = val1 + val2; // If there is a sign change, but the two values have the same sign... if ((val1 ^ sum) < 0 && (val1 ^ val2) >= 0) { throw new ArithmeticException ("The calculation caused an overflow: " + val1 + " + " + val2); } return sum; }
[ "public", "static", "int", "safeAdd", "(", "int", "val1", ",", "int", "val2", ")", "{", "int", "sum", "=", "val1", "+", "val2", ";", "// If there is a sign change, but the two values have the same sign...", "if", "(", "(", "val1", "^", "sum", ")", "<", "0", "&&", "(", "val1", "^", "val2", ")", ">=", "0", ")", "{", "throw", "new", "ArithmeticException", "(", "\"The calculation caused an overflow: \"", "+", "val1", "+", "\" + \"", "+", "val2", ")", ";", "}", "return", "sum", ";", "}" ]
Add two values throwing an exception if overflow occurs. @param val1 the first value @param val2 the second value @return the new total @throws ArithmeticException if the value is too big or too small
[ "Add", "two", "values", "throwing", "an", "exception", "if", "overflow", "occurs", "." ]
bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42
https://github.com/JodaOrg/joda-time/blob/bd79f1c4245e79b3c2c56d7b04fde2a6e191fa42/src/main/java/org/joda/time/field/FieldUtils.java#L66-L74