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
144,900
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.errorf
public final void errorf(Throwable cause, String message, Object... args) { logf(Level.ERROR, cause, message, args); }
java
public final void errorf(Throwable cause, String message, Object... args) { logf(Level.ERROR, cause, message, args); }
[ "public", "final", "void", "errorf", "(", "Throwable", "cause", ",", "String", "message", ",", "Object", "...", "args", ")", "{", "logf", "(", "Level", ".", "ERROR", ",", "cause", ",", "message", ",", "args", ")", ";", "}" ]
Logs a formatted message and stack trace if ERROR logging is enabled. @param cause an exception to print stack trace of @param message a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax">format string</a> @param args arguments referenced by the format specifiers in the format string.
[ "Logs", "a", "formatted", "message", "and", "stack", "trace", "if", "ERROR", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L267-L270
144,901
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.errorf
public final void errorf(String message, Object... args) { logf(Level.ERROR, null, message, args); }
java
public final void errorf(String message, Object... args) { logf(Level.ERROR, null, message, args); }
[ "public", "final", "void", "errorf", "(", "String", "message", ",", "Object", "...", "args", ")", "{", "logf", "(", "Level", ".", "ERROR", ",", "null", ",", "message", ",", "args", ")", ";", "}" ]
Logs a formatted message if ERROR logging is enabled. @param message a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax">format string</a> @param args arguments referenced by the format specifiers in the format string.
[ "Logs", "a", "formatted", "message", "if", "ERROR", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L278-L281
144,902
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.infoDebugf
public final void infoDebugf(final Throwable cause, final String message, final Object... args) { logDebugf(Level.INFO, cause, message, args); }
java
public final void infoDebugf(final Throwable cause, final String message, final Object... args) { logDebugf(Level.INFO, cause, message, args); }
[ "public", "final", "void", "infoDebugf", "(", "final", "Throwable", "cause", ",", "final", "String", "message", ",", "final", "Object", "...", "args", ")", "{", "logDebugf", "(", "Level", ".", "INFO", ",", "cause", ",", "message", ",", "args", ")", ";", "}" ]
Logs a formatted message and stack trace if DEBUG logging is enabled or a formatted message and exception description if INFO logging is enabled. @param cause an exception to print stack trace of if DEBUG logging is enabled @param message a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax">format string</a> @param args arguments referenced by the format specifiers in the format string.
[ "Logs", "a", "formatted", "message", "and", "stack", "trace", "if", "DEBUG", "logging", "is", "enabled", "or", "a", "formatted", "message", "and", "exception", "description", "if", "INFO", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L333-L336
144,903
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.infoDebug
public final void infoDebug(final Throwable cause, final String message) { logDebug(Level.INFO, cause, message); }
java
public final void infoDebug(final Throwable cause, final String message) { logDebug(Level.INFO, cause, message); }
[ "public", "final", "void", "infoDebug", "(", "final", "Throwable", "cause", ",", "final", "String", "message", ")", "{", "logDebug", "(", "Level", ".", "INFO", ",", "cause", ",", "message", ")", ";", "}" ]
Logs a message and stack trace if DEBUG logging is enabled or a formatted message and exception description if INFO logging is enabled. @param cause an exception to print stack trace of if DEBUG logging is enabled @param message a message
[ "Logs", "a", "message", "and", "stack", "trace", "if", "DEBUG", "logging", "is", "enabled", "or", "a", "formatted", "message", "and", "exception", "description", "if", "INFO", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L345-L348
144,904
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.warnDebugf
public final void warnDebugf(final Throwable cause, final String message, final Object... args) { logDebugf(Level.WARN, cause, message, args); }
java
public final void warnDebugf(final Throwable cause, final String message, final Object... args) { logDebugf(Level.WARN, cause, message, args); }
[ "public", "final", "void", "warnDebugf", "(", "final", "Throwable", "cause", ",", "final", "String", "message", ",", "final", "Object", "...", "args", ")", "{", "logDebugf", "(", "Level", ".", "WARN", ",", "cause", ",", "message", ",", "args", ")", ";", "}" ]
Logs a formatted message and stack trace if DEBUG logging is enabled or a formatted message and exception description if WARN logging is enabled. @param cause an exception to print stack trace of if DEBUG logging is enabled @param message a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax">format string</a> @param args arguments referenced by the format specifiers in the format string.
[ "Logs", "a", "formatted", "message", "and", "stack", "trace", "if", "DEBUG", "logging", "is", "enabled", "or", "a", "formatted", "message", "and", "exception", "description", "if", "WARN", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L369-L372
144,905
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.warnDebug
public final void warnDebug(final Throwable cause, final String message) { logDebug(Level.WARN, cause, message); }
java
public final void warnDebug(final Throwable cause, final String message) { logDebug(Level.WARN, cause, message); }
[ "public", "final", "void", "warnDebug", "(", "final", "Throwable", "cause", ",", "final", "String", "message", ")", "{", "logDebug", "(", "Level", ".", "WARN", ",", "cause", ",", "message", ")", ";", "}" ]
Logs a message and stack trace if DEBUG logging is enabled or a formatted message and exception description if WARN logging is enabled. @param cause an exception to print stack trace of if DEBUG logging is enabled @param message a message
[ "Logs", "a", "message", "and", "stack", "trace", "if", "DEBUG", "logging", "is", "enabled", "or", "a", "formatted", "message", "and", "exception", "description", "if", "WARN", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L381-L384
144,906
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.errorDebugf
public final void errorDebugf(final Throwable cause, final String message, final Object... args) { logDebugf(Level.ERROR, cause, message, args); }
java
public final void errorDebugf(final Throwable cause, final String message, final Object... args) { logDebugf(Level.ERROR, cause, message, args); }
[ "public", "final", "void", "errorDebugf", "(", "final", "Throwable", "cause", ",", "final", "String", "message", ",", "final", "Object", "...", "args", ")", "{", "logDebugf", "(", "Level", ".", "ERROR", ",", "cause", ",", "message", ",", "args", ")", ";", "}" ]
Logs a formatted message and stack trace if DEBUG logging is enabled or a formatted message and exception description if ERROR logging is enabled. @param cause an exception to print stack trace of if DEBUG logging is enabled @param message a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax">format string</a> @param args arguments referenced by the format specifiers in the format string.
[ "Logs", "a", "formatted", "message", "and", "stack", "trace", "if", "DEBUG", "logging", "is", "enabled", "or", "a", "formatted", "message", "and", "exception", "description", "if", "ERROR", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L405-L408
144,907
twilliamson/mogwee-logging
src/main/java/com/mogwee/logging/Logger.java
Logger.errorDebug
public final void errorDebug(final Throwable cause, final String message) { logDebug(Level.ERROR, cause, message); }
java
public final void errorDebug(final Throwable cause, final String message) { logDebug(Level.ERROR, cause, message); }
[ "public", "final", "void", "errorDebug", "(", "final", "Throwable", "cause", ",", "final", "String", "message", ")", "{", "logDebug", "(", "Level", ".", "ERROR", ",", "cause", ",", "message", ")", ";", "}" ]
Logs a message and stack trace if DEBUG logging is enabled or a formatted message and exception description if ERROR logging is enabled. @param cause an exception to print stack trace of if DEBUG logging is enabled @param message a message
[ "Logs", "a", "message", "and", "stack", "trace", "if", "DEBUG", "logging", "is", "enabled", "or", "a", "formatted", "message", "and", "exception", "description", "if", "ERROR", "logging", "is", "enabled", "." ]
30b99c2649de455432d956a8f6a74316de4cd62c
https://github.com/twilliamson/mogwee-logging/blob/30b99c2649de455432d956a8f6a74316de4cd62c/src/main/java/com/mogwee/logging/Logger.java#L417-L420
144,908
dbracewell/mango
src/main/java/com/davidbracewell/reflection/ReflectionUtils.java
ReflectionUtils.bestMatchingMethod
public static Method bestMatchingMethod(Collection<Method> methods, String methodName, Class[] types) { if (methods == null || StringUtils.isNullOrBlank(methodName) || types == null) { return null; } for (Method method : methods) { if (method.getName().equals(methodName) && typesMatch(method.getParameterTypes(), types)) { return method; } } return null; }
java
public static Method bestMatchingMethod(Collection<Method> methods, String methodName, Class[] types) { if (methods == null || StringUtils.isNullOrBlank(methodName) || types == null) { return null; } for (Method method : methods) { if (method.getName().equals(methodName) && typesMatch(method.getParameterTypes(), types)) { return method; } } return null; }
[ "public", "static", "Method", "bestMatchingMethod", "(", "Collection", "<", "Method", ">", "methods", ",", "String", "methodName", ",", "Class", "[", "]", "types", ")", "{", "if", "(", "methods", "==", "null", "||", "StringUtils", ".", "isNullOrBlank", "(", "methodName", ")", "||", "types", "==", "null", ")", "{", "return", "null", ";", "}", "for", "(", "Method", "method", ":", "methods", ")", "{", "if", "(", "method", ".", "getName", "(", ")", ".", "equals", "(", "methodName", ")", "&&", "typesMatch", "(", "method", ".", "getParameterTypes", "(", ")", ",", "types", ")", ")", "{", "return", "method", ";", "}", "}", "return", "null", ";", "}" ]
Finds the best Method match for a given method name and types against a collection of methods. @param methods The collections of methods to choose from @param methodName The name of the method we want to match @param types The types that we want to pass to the method. @return Null if there is no match, otherwise the Method which bests fits the given method name and types
[ "Finds", "the", "best", "Method", "match", "for", "a", "given", "method", "name", "and", "types", "against", "a", "collection", "of", "methods", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/reflection/ReflectionUtils.java#L58-L68
144,909
dbracewell/mango
src/main/java/com/davidbracewell/reflection/ReflectionUtils.java
ReflectionUtils.getTypes
public static Class[] getTypes(Object... args) { if (args.length == 0) { return new Class[0]; } Class[] types = new Class[args.length]; for (int i = 0; i < args.length; i++) { types[i] = args[i] == null ? Object.class : args[i].getClass(); } return types; }
java
public static Class[] getTypes(Object... args) { if (args.length == 0) { return new Class[0]; } Class[] types = new Class[args.length]; for (int i = 0; i < args.length; i++) { types[i] = args[i] == null ? Object.class : args[i].getClass(); } return types; }
[ "public", "static", "Class", "[", "]", "getTypes", "(", "Object", "...", "args", ")", "{", "if", "(", "args", ".", "length", "==", "0", ")", "{", "return", "new", "Class", "[", "0", "]", ";", "}", "Class", "[", "]", "types", "=", "new", "Class", "[", "args", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "types", "[", "i", "]", "=", "args", "[", "i", "]", "==", "null", "?", "Object", ".", "class", ":", "args", "[", "i", "]", ".", "getClass", "(", ")", ";", "}", "return", "types", ";", "}" ]
Gets the types for an array of objects @param args The arguments to get types for @return A 0 sized array if the array is null, otherwise an array of class equalling the classes of the given args or <code>Object.cass</code> if the arg is null.
[ "Gets", "the", "types", "for", "an", "array", "of", "objects" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/reflection/ReflectionUtils.java#L326-L335
144,910
dbracewell/mango
src/main/java/com/davidbracewell/reflection/ReflectionUtils.java
ReflectionUtils.typesMatch
@SuppressWarnings("unchecked") public static boolean typesMatch(Class<?>[] c1, Class[] c2) { if (c1.length != c2.length) { return false; } for (int i = 0; i < c1.length; i++) { if (!inSameHierarchy(c1[i], c2[i]) && !isConvertible(c1[i], c2[i])) { return false; } } return true; }
java
@SuppressWarnings("unchecked") public static boolean typesMatch(Class<?>[] c1, Class[] c2) { if (c1.length != c2.length) { return false; } for (int i = 0; i < c1.length; i++) { if (!inSameHierarchy(c1[i], c2[i]) && !isConvertible(c1[i], c2[i])) { return false; } } return true; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "boolean", "typesMatch", "(", "Class", "<", "?", ">", "[", "]", "c1", ",", "Class", "[", "]", "c2", ")", "{", "if", "(", "c1", ".", "length", "!=", "c2", ".", "length", ")", "{", "return", "false", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "c1", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "inSameHierarchy", "(", "c1", "[", "i", "]", ",", "c2", "[", "i", "]", ")", "&&", "!", "isConvertible", "(", "c1", "[", "i", "]", ",", "c2", "[", "i", "]", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Determines if the two given arrays of class are compatible with one another. @param c1 array 1 @param c2 array 2 @return True if all classes are the same or those c1 are assignable from c2, otherwise false
[ "Determines", "if", "the", "two", "given", "arrays", "of", "class", "are", "compatible", "with", "one", "another", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/reflection/ReflectionUtils.java#L376-L387
144,911
duraspace/fcrepo-cloudsync
fcrepo-cloudsync-service/src/main/java/org/duraspace/fcrepo/cloudsync/service/backend/StoreConnector.java
StoreConnector.execute
private HttpResponse execute(HttpClient client, HttpUriRequest request) throws IOException { if (localContext != null) { return client.execute(request, localContext); } else { return client.execute(request); } }
java
private HttpResponse execute(HttpClient client, HttpUriRequest request) throws IOException { if (localContext != null) { return client.execute(request, localContext); } else { return client.execute(request); } }
[ "private", "HttpResponse", "execute", "(", "HttpClient", "client", ",", "HttpUriRequest", "request", ")", "throws", "IOException", "{", "if", "(", "localContext", "!=", "null", ")", "{", "return", "client", ".", "execute", "(", "request", ",", "localContext", ")", ";", "}", "else", "{", "return", "client", ".", "execute", "(", "request", ")", ";", "}", "}" ]
executes a request with the localContext, if set
[ "executes", "a", "request", "with", "the", "localContext", "if", "set" ]
2d90e2c9c84a827f2605607ff40e116c67eff9b9
https://github.com/duraspace/fcrepo-cloudsync/blob/2d90e2c9c84a827f2605607ff40e116c67eff9b9/fcrepo-cloudsync-service/src/main/java/org/duraspace/fcrepo/cloudsync/service/backend/StoreConnector.java#L191-L197
144,912
dbracewell/mango
src/main/java/com/davidbracewell/collection/map/LRUMap.java
LRUMap.create
public static <K, V> LRUMap<K, V> create(int maxSize) { Preconditions.checkArgument(maxSize > 0, "Max size must be greater than zero."); return new LRUMap<>(maxSize); }
java
public static <K, V> LRUMap<K, V> create(int maxSize) { Preconditions.checkArgument(maxSize > 0, "Max size must be greater than zero."); return new LRUMap<>(maxSize); }
[ "public", "static", "<", "K", ",", "V", ">", "LRUMap", "<", "K", ",", "V", ">", "create", "(", "int", "maxSize", ")", "{", "Preconditions", ".", "checkArgument", "(", "maxSize", ">", "0", ",", "\"Max size must be greater than zero.\"", ")", ";", "return", "new", "LRUMap", "<>", "(", "maxSize", ")", ";", "}" ]
Creates a new LRU Map. @param <K> the key type @param <V> the value type @return the map
[ "Creates", "a", "new", "LRU", "Map", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/collection/map/LRUMap.java#L49-L52
144,913
triceo/splitlog
splitlog-core/src/main/java/org/apache/commons/io/input/fork/Tailer.java
Tailer.create
public static Tailer create(final File file, final TailerListener listener) { return Tailer.create(file, listener, Tailer.DEFAULT_DELAY_MILLIS, false); }
java
public static Tailer create(final File file, final TailerListener listener) { return Tailer.create(file, listener, Tailer.DEFAULT_DELAY_MILLIS, false); }
[ "public", "static", "Tailer", "create", "(", "final", "File", "file", ",", "final", "TailerListener", "listener", ")", "{", "return", "Tailer", ".", "create", "(", "file", ",", "listener", ",", "Tailer", ".", "DEFAULT_DELAY_MILLIS", ",", "false", ")", ";", "}" ]
Creates and starts a Tailer for the given file, starting at the beginning of the file with the default delay of 1.0s @param file the file to follow. @param listener the TailerListener to use. @return The new tailer
[ "Creates", "and", "starts", "a", "Tailer", "for", "the", "given", "file", "starting", "at", "the", "beginning", "of", "the", "file", "with", "the", "default", "delay", "of", "1", ".", "0s" ]
4e1b188e8c814119f5cf7343bbc53917843d68a2
https://github.com/triceo/splitlog/blob/4e1b188e8c814119f5cf7343bbc53917843d68a2/splitlog-core/src/main/java/org/apache/commons/io/input/fork/Tailer.java#L191-L193
144,914
triceo/splitlog
splitlog-core/src/main/java/org/apache/commons/io/input/fork/Tailer.java
Tailer.create
public static Tailer create(final File file, final TailerListener listener, final long delayMillis, final boolean end) { return Tailer.create(file, listener, delayMillis, end, Tailer.DEFAULT_BUFSIZE); }
java
public static Tailer create(final File file, final TailerListener listener, final long delayMillis, final boolean end) { return Tailer.create(file, listener, delayMillis, end, Tailer.DEFAULT_BUFSIZE); }
[ "public", "static", "Tailer", "create", "(", "final", "File", "file", ",", "final", "TailerListener", "listener", ",", "final", "long", "delayMillis", ",", "final", "boolean", "end", ")", "{", "return", "Tailer", ".", "create", "(", "file", ",", "listener", ",", "delayMillis", ",", "end", ",", "Tailer", ".", "DEFAULT_BUFSIZE", ")", ";", "}" ]
Creates and starts a Tailer for the given file with default buffer size. @param file the file to follow. @param listener the TailerListener to use. @param delayMillis the delay between checks of the file for new content in milliseconds. @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. @return The new tailer
[ "Creates", "and", "starts", "a", "Tailer", "for", "the", "given", "file", "with", "default", "buffer", "size", "." ]
4e1b188e8c814119f5cf7343bbc53917843d68a2
https://github.com/triceo/splitlog/blob/4e1b188e8c814119f5cf7343bbc53917843d68a2/splitlog-core/src/main/java/org/apache/commons/io/input/fork/Tailer.java#L227-L230
144,915
triceo/splitlog
splitlog-core/src/main/java/org/apache/commons/io/input/fork/Tailer.java
Tailer.run
@Override public void run() { final ScheduledFuture<?> future = this.executor.scheduleWithFixedDelay(this.scheduled, 0, this.delayMillis, TimeUnit.MILLISECONDS); try { this.runTrigger.await(); } catch (final InterruptedException e) { this.listener.handle(e); } finally { future.cancel(true); // stop the periodic reading this.scheduled.cleanup(); this.executor.shutdownNow(); this.listener.destroy(); } }
java
@Override public void run() { final ScheduledFuture<?> future = this.executor.scheduleWithFixedDelay(this.scheduled, 0, this.delayMillis, TimeUnit.MILLISECONDS); try { this.runTrigger.await(); } catch (final InterruptedException e) { this.listener.handle(e); } finally { future.cancel(true); // stop the periodic reading this.scheduled.cleanup(); this.executor.shutdownNow(); this.listener.destroy(); } }
[ "@", "Override", "public", "void", "run", "(", ")", "{", "final", "ScheduledFuture", "<", "?", ">", "future", "=", "this", ".", "executor", ".", "scheduleWithFixedDelay", "(", "this", ".", "scheduled", ",", "0", ",", "this", ".", "delayMillis", ",", "TimeUnit", ".", "MILLISECONDS", ")", ";", "try", "{", "this", ".", "runTrigger", ".", "await", "(", ")", ";", "}", "catch", "(", "final", "InterruptedException", "e", ")", "{", "this", ".", "listener", ".", "handle", "(", "e", ")", ";", "}", "finally", "{", "future", ".", "cancel", "(", "true", ")", ";", "// stop the periodic reading", "this", ".", "scheduled", ".", "cleanup", "(", ")", ";", "this", ".", "executor", ".", "shutdownNow", "(", ")", ";", "this", ".", "listener", ".", "destroy", "(", ")", ";", "}", "}" ]
Follows changes in the file, calling the TailerListener's handle method for each new line.
[ "Follows", "changes", "in", "the", "file", "calling", "the", "TailerListener", "s", "handle", "method", "for", "each", "new", "line", "." ]
4e1b188e8c814119f5cf7343bbc53917843d68a2
https://github.com/triceo/splitlog/blob/4e1b188e8c814119f5cf7343bbc53917843d68a2/splitlog-core/src/main/java/org/apache/commons/io/input/fork/Tailer.java#L492-L506
144,916
fuinorg/utils4j
src/main/java/org/fuin/utils4j/VariableResolver.java
VariableResolver.references
public static Set<String> references(final String value) { final HashSet<String> names = new HashSet<String>(); if ((value == null) || (value.length() == 0)) { return names; } int end = -1; int from = 0; int start = -1; while ((start = value.indexOf("${", from)) > -1) { end = value.indexOf('}', start + 1); if (end == -1) { // No closing bracket found... from = value.length(); } else { names.add(value.substring(start + 2, end)); from = end + 1; } } return names; }
java
public static Set<String> references(final String value) { final HashSet<String> names = new HashSet<String>(); if ((value == null) || (value.length() == 0)) { return names; } int end = -1; int from = 0; int start = -1; while ((start = value.indexOf("${", from)) > -1) { end = value.indexOf('}', start + 1); if (end == -1) { // No closing bracket found... from = value.length(); } else { names.add(value.substring(start + 2, end)); from = end + 1; } } return names; }
[ "public", "static", "Set", "<", "String", ">", "references", "(", "final", "String", "value", ")", "{", "final", "HashSet", "<", "String", ">", "names", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "if", "(", "(", "value", "==", "null", ")", "||", "(", "value", ".", "length", "(", ")", "==", "0", ")", ")", "{", "return", "names", ";", "}", "int", "end", "=", "-", "1", ";", "int", "from", "=", "0", ";", "int", "start", "=", "-", "1", ";", "while", "(", "(", "start", "=", "value", ".", "indexOf", "(", "\"${\"", ",", "from", ")", ")", ">", "-", "1", ")", "{", "end", "=", "value", ".", "indexOf", "(", "'", "'", ",", "start", "+", "1", ")", ";", "if", "(", "end", "==", "-", "1", ")", "{", "// No closing bracket found...\r", "from", "=", "value", ".", "length", "(", ")", ";", "}", "else", "{", "names", ".", "add", "(", "value", ".", "substring", "(", "start", "+", "2", ",", "end", ")", ")", ";", "from", "=", "end", "+", "1", ";", "}", "}", "return", "names", ";", "}" ]
Returns a set of references variables. @param value Value to parse - May be <code>null</code>. @return Referenced variable names - Never <code>null</code>, but may be empty.
[ "Returns", "a", "set", "of", "references", "variables", "." ]
71cf88e0a8d8ed67bbac513bf3cab165cd7e3280
https://github.com/fuinorg/utils4j/blob/71cf88e0a8d8ed67bbac513bf3cab165cd7e3280/src/main/java/org/fuin/utils4j/VariableResolver.java#L154-L177
144,917
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.get
public static void get(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.GET, url, endpoint, mediaTypes); }
java
public static void get(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.GET, url, endpoint, mediaTypes); }
[ "public", "static", "void", "get", "(", "String", "url", ",", "HttpConsumer", "<", "HttpExchange", ">", "endpoint", ",", "MediaTypes", "...", "mediaTypes", ")", "{", "addResource", "(", "Methods", ".", "GET", ",", "url", ",", "endpoint", ",", "mediaTypes", ")", ";", "}" ]
Define a REST endpoint mapped to HTTP GET @param url The relative URL to be map this endpoint. @param endpoint The endpoint handler @param mediaTypes (Optional) The accepted and returned types for this endpoint
[ "Define", "a", "REST", "endpoint", "mapped", "to", "HTTP", "GET" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L338-L340
144,918
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.post
public static void post(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.POST, url, endpoint, mediaTypes); }
java
public static void post(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.POST, url, endpoint, mediaTypes); }
[ "public", "static", "void", "post", "(", "String", "url", ",", "HttpConsumer", "<", "HttpExchange", ">", "endpoint", ",", "MediaTypes", "...", "mediaTypes", ")", "{", "addResource", "(", "Methods", ".", "POST", ",", "url", ",", "endpoint", ",", "mediaTypes", ")", ";", "}" ]
Define a REST endpoint mapped to HTTP POST @param url The relative URL to be map this endpoint. @param endpoint The endpoint handler @param mediaTypes (Optional) The accepted and returned types for this endpoint
[ "Define", "a", "REST", "endpoint", "mapped", "to", "HTTP", "POST" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L349-L351
144,919
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.put
public static void put(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.PUT, url, endpoint, mediaTypes); }
java
public static void put(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.PUT, url, endpoint, mediaTypes); }
[ "public", "static", "void", "put", "(", "String", "url", ",", "HttpConsumer", "<", "HttpExchange", ">", "endpoint", ",", "MediaTypes", "...", "mediaTypes", ")", "{", "addResource", "(", "Methods", ".", "PUT", ",", "url", ",", "endpoint", ",", "mediaTypes", ")", ";", "}" ]
Define a REST endpoint mapped to HTTP PUT @param url The relative URL to be map this endpoint. @param endpoint The endpoint handler @param mediaTypes (Optional) The accepted and returned types for this endpoint
[ "Define", "a", "REST", "endpoint", "mapped", "to", "HTTP", "PUT" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L360-L362
144,920
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.delete
public static void delete(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.DELETE, url, endpoint, mediaTypes); }
java
public static void delete(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.DELETE, url, endpoint, mediaTypes); }
[ "public", "static", "void", "delete", "(", "String", "url", ",", "HttpConsumer", "<", "HttpExchange", ">", "endpoint", ",", "MediaTypes", "...", "mediaTypes", ")", "{", "addResource", "(", "Methods", ".", "DELETE", ",", "url", ",", "endpoint", ",", "mediaTypes", ")", ";", "}" ]
Define a REST endpoint mapped to HTTP DELETE @param url The relative URL to be map this endpoint. @param endpoint The endpoint handler @param mediaTypes (Optional) The accepted and returned types for this endpoint
[ "Define", "a", "REST", "endpoint", "mapped", "to", "HTTP", "DELETE" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L371-L373
144,921
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.options
public static void options(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.OPTIONS, url, endpoint, mediaTypes); }
java
public static void options(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) { addResource(Methods.OPTIONS, url, endpoint, mediaTypes); }
[ "public", "static", "void", "options", "(", "String", "url", ",", "HttpConsumer", "<", "HttpExchange", ">", "endpoint", ",", "MediaTypes", "...", "mediaTypes", ")", "{", "addResource", "(", "Methods", ".", "OPTIONS", ",", "url", ",", "endpoint", ",", "mediaTypes", ")", ";", "}" ]
Define a REST endpoint mapped to HTTP OPTIONS @param url The relative URL to be map this endpoint. @param endpoint The endpoint handler @param mediaTypes (Optional) The accepted and returned types for this endpoint
[ "Define", "a", "REST", "endpoint", "mapped", "to", "HTTP", "OPTIONS" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L382-L384
144,922
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.websocket
public static synchronized void websocket(String url, AbstractReceiveListener endpoint) { checkStarted(); instance().endpoints.add(HandlerUtil.websocket(url, endpoint)); }
java
public static synchronized void websocket(String url, AbstractReceiveListener endpoint) { checkStarted(); instance().endpoints.add(HandlerUtil.websocket(url, endpoint)); }
[ "public", "static", "synchronized", "void", "websocket", "(", "String", "url", ",", "AbstractReceiveListener", "endpoint", ")", "{", "checkStarted", "(", ")", ";", "instance", "(", ")", ".", "endpoints", ".", "add", "(", "HandlerUtil", ".", "websocket", "(", "url", ",", "endpoint", ")", ")", ";", "}" ]
Define a Websocket endpoint. Supports path variables @param url The relative URL to be map this endpoint. @param endpoint The endpoint handler
[ "Define", "a", "Websocket", "endpoint", ".", "Supports", "path", "variables" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L501-L504
144,923
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.websocket
public static synchronized void websocket(String url, BiConsumer<WebSocketChannel, BufferedTextMessage> onMessage) { checkStarted(); instance().endpoints.add(HandlerUtil.websocket(url, new WebsocketEndpoint() { @Override public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) { } @Override protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) throws IOException { onMessage.accept(channel, message); } })); }
java
public static synchronized void websocket(String url, BiConsumer<WebSocketChannel, BufferedTextMessage> onMessage) { checkStarted(); instance().endpoints.add(HandlerUtil.websocket(url, new WebsocketEndpoint() { @Override public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) { } @Override protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) throws IOException { onMessage.accept(channel, message); } })); }
[ "public", "static", "synchronized", "void", "websocket", "(", "String", "url", ",", "BiConsumer", "<", "WebSocketChannel", ",", "BufferedTextMessage", ">", "onMessage", ")", "{", "checkStarted", "(", ")", ";", "instance", "(", ")", ".", "endpoints", ".", "add", "(", "HandlerUtil", ".", "websocket", "(", "url", ",", "new", "WebsocketEndpoint", "(", ")", "{", "@", "Override", "public", "void", "onConnect", "(", "WebSocketHttpExchange", "exchange", ",", "WebSocketChannel", "channel", ")", "{", "}", "@", "Override", "protected", "void", "onFullTextMessage", "(", "WebSocketChannel", "channel", ",", "BufferedTextMessage", "message", ")", "throws", "IOException", "{", "onMessage", ".", "accept", "(", "channel", ",", "message", ")", ";", "}", "}", ")", ")", ";", "}" ]
A simplified Websocket endpoint. Supports path variables @param url The relative URL to be map this endpoint. @param onMessage The handler for when a new message is received
[ "A", "simplified", "Websocket", "endpoint", ".", "Supports", "path", "variables" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L512-L525
144,924
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.staticFiles
public static synchronized void staticFiles(String url, String docPath) { checkStarted(); instance().endpoints.add(HandlerUtil.staticFiles(url, docPath)); }
java
public static synchronized void staticFiles(String url, String docPath) { checkStarted(); instance().endpoints.add(HandlerUtil.staticFiles(url, docPath)); }
[ "public", "static", "synchronized", "void", "staticFiles", "(", "String", "url", ",", "String", "docPath", ")", "{", "checkStarted", "(", ")", ";", "instance", "(", ")", ".", "endpoints", ".", "add", "(", "HandlerUtil", ".", "staticFiles", "(", "url", ",", "docPath", ")", ")", ";", "}" ]
Serve static files from a given url. Path variables are not supported. @param url The relative URL to be map this endpoint. @param docPath The relative path to the classpath.
[ "Serve", "static", "files", "from", "a", "given", "url", ".", "Path", "variables", "are", "not", "supported", "." ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L599-L602
144,925
josueeduardo/snappy
snappy/src/main/java/io/joshworks/snappy/SnappyServer.java
SnappyServer.exportDefaultProperties
private void exportDefaultProperties() { AppProperties.set(PropertyKey.HTTP_PORT, String.valueOf(this.port)); AppProperties.set(PropertyKey.ADMIN_HTTP_PORT, String.valueOf(this.adminManager.getPort())); }
java
private void exportDefaultProperties() { AppProperties.set(PropertyKey.HTTP_PORT, String.valueOf(this.port)); AppProperties.set(PropertyKey.ADMIN_HTTP_PORT, String.valueOf(this.adminManager.getPort())); }
[ "private", "void", "exportDefaultProperties", "(", ")", "{", "AppProperties", ".", "set", "(", "PropertyKey", ".", "HTTP_PORT", ",", "String", ".", "valueOf", "(", "this", ".", "port", ")", ")", ";", "AppProperties", ".", "set", "(", "PropertyKey", ".", "ADMIN_HTTP_PORT", ",", "String", ".", "valueOf", "(", "this", ".", "adminManager", ".", "getPort", "(", ")", ")", ")", ";", "}" ]
sets the properties that are may be useful outside the application
[ "sets", "the", "properties", "that", "are", "may", "be", "useful", "outside", "the", "application" ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/snappy/src/main/java/io/joshworks/snappy/SnappyServer.java#L783-L786
144,926
theisenp/harbor
src/main/java/com/theisenp/harbor/Harbor.java
Harbor.open
public void open() { Futures.transform(lcm, new Subscribe(subscriber)); publishTask = Futures.transform(lcm, publisher); }
java
public void open() { Futures.transform(lcm, new Subscribe(subscriber)); publishTask = Futures.transform(lcm, publisher); }
[ "public", "void", "open", "(", ")", "{", "Futures", ".", "transform", "(", "lcm", ",", "new", "Subscribe", "(", "subscriber", ")", ")", ";", "publishTask", "=", "Futures", ".", "transform", "(", "lcm", ",", "publisher", ")", ";", "}" ]
Starts the publish and subscribe tasks
[ "Starts", "the", "publish", "and", "subscribe", "tasks" ]
59a6d373a709e10ddf0945475b95394f3f7a8254
https://github.com/theisenp/harbor/blob/59a6d373a709e10ddf0945475b95394f3f7a8254/src/main/java/com/theisenp/harbor/Harbor.java#L149-L152
144,927
theisenp/harbor
src/main/java/com/theisenp/harbor/Harbor.java
Harbor.close
public void close() { Futures.transform(lcm, new Unsubscribe(subscriber)); subscriber.clear(); publishTask.cancel(true); }
java
public void close() { Futures.transform(lcm, new Unsubscribe(subscriber)); subscriber.clear(); publishTask.cancel(true); }
[ "public", "void", "close", "(", ")", "{", "Futures", ".", "transform", "(", "lcm", ",", "new", "Unsubscribe", "(", "subscriber", ")", ")", ";", "subscriber", ".", "clear", "(", ")", ";", "publishTask", ".", "cancel", "(", "true", ")", ";", "}" ]
Stops the publish and subscribe tasks
[ "Stops", "the", "publish", "and", "subscribe", "tasks" ]
59a6d373a709e10ddf0945475b95394f3f7a8254
https://github.com/theisenp/harbor/blob/59a6d373a709e10ddf0945475b95394f3f7a8254/src/main/java/com/theisenp/harbor/Harbor.java#L157-L161
144,928
keenon/loglinear
src/main/java/com/github/keenon/loglinear/model/NDArrayDoubles.java
NDArrayDoubles.deepCopy
public NDArrayDoubles deepCopy() { int[] dimensions = new int[this.dimensions.length]; System.arraycopy(this.dimensions, 0, dimensions, 0, this.dimensions.length); double[] values = new double[this.values.length]; System.arraycopy(this.values, 0, values, 0, this.values.length); return new NDArrayDoubles(dimensions, values); }
java
public NDArrayDoubles deepCopy() { int[] dimensions = new int[this.dimensions.length]; System.arraycopy(this.dimensions, 0, dimensions, 0, this.dimensions.length); double[] values = new double[this.values.length]; System.arraycopy(this.values, 0, values, 0, this.values.length); return new NDArrayDoubles(dimensions, values); }
[ "public", "NDArrayDoubles", "deepCopy", "(", ")", "{", "int", "[", "]", "dimensions", "=", "new", "int", "[", "this", ".", "dimensions", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "this", ".", "dimensions", ",", "0", ",", "dimensions", ",", "0", ",", "this", ".", "dimensions", ".", "length", ")", ";", "double", "[", "]", "values", "=", "new", "double", "[", "this", ".", "values", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "this", ".", "values", ",", "0", ",", "values", ",", "0", ",", "this", ".", "values", ".", "length", ")", ";", "return", "new", "NDArrayDoubles", "(", "dimensions", ",", "values", ")", ";", "}" ]
Copy this array.
[ "Copy", "this", "array", "." ]
fa0c370ab6782015412f676ef2ab11c97be58e29
https://github.com/keenon/loglinear/blob/fa0c370ab6782015412f676ef2ab11c97be58e29/src/main/java/com/github/keenon/loglinear/model/NDArrayDoubles.java#L57-L63
144,929
keenon/loglinear
src/main/java/com/github/keenon/loglinear/model/NDArrayDoubles.java
NDArrayDoubles.setAssignmentValue
public void setAssignmentValue(int[] assignment, double value) { assert !Double.isNaN(value); values[getTableAccessOffset(assignment)] = value; }
java
public void setAssignmentValue(int[] assignment, double value) { assert !Double.isNaN(value); values[getTableAccessOffset(assignment)] = value; }
[ "public", "void", "setAssignmentValue", "(", "int", "[", "]", "assignment", ",", "double", "value", ")", "{", "assert", "!", "Double", ".", "isNaN", "(", "value", ")", ";", "values", "[", "getTableAccessOffset", "(", "assignment", ")", "]", "=", "value", ";", "}" ]
Set a single value in the factor table. @param assignment a list of variable settings, in the same order as the neighbors array of the factor @param value the value to put into the factor table
[ "Set", "a", "single", "value", "in", "the", "factor", "table", "." ]
fa0c370ab6782015412f676ef2ab11c97be58e29
https://github.com/keenon/loglinear/blob/fa0c370ab6782015412f676ef2ab11c97be58e29/src/main/java/com/github/keenon/loglinear/model/NDArrayDoubles.java#L71-L74
144,930
keenon/loglinear
src/main/java/com/github/keenon/loglinear/model/NDArrayDoubles.java
NDArrayDoubles.valueEquals
public boolean valueEquals(NDArrayDoubles other, double tolerance) { if (!Arrays.equals(dimensions, other.dimensions)) return false; if (dimensions.length != other.dimensions.length) return false; for (int i = 0; i < dimensions.length; i++) { if (Math.abs(dimensions[i] - other.dimensions[i]) > tolerance) return false; } return true; }
java
public boolean valueEquals(NDArrayDoubles other, double tolerance) { if (!Arrays.equals(dimensions, other.dimensions)) return false; if (dimensions.length != other.dimensions.length) return false; for (int i = 0; i < dimensions.length; i++) { if (Math.abs(dimensions[i] - other.dimensions[i]) > tolerance) return false; } return true; }
[ "public", "boolean", "valueEquals", "(", "NDArrayDoubles", "other", ",", "double", "tolerance", ")", "{", "if", "(", "!", "Arrays", ".", "equals", "(", "dimensions", ",", "other", ".", "dimensions", ")", ")", "return", "false", ";", "if", "(", "dimensions", ".", "length", "!=", "other", ".", "dimensions", ".", "length", ")", "return", "false", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dimensions", ".", "length", ";", "i", "++", ")", "{", "if", "(", "Math", ".", "abs", "(", "dimensions", "[", "i", "]", "-", "other", ".", "dimensions", "[", "i", "]", ")", ">", "tolerance", ")", "return", "false", ";", "}", "return", "true", ";", "}" ]
Does a deep comparison, using equality with tolerance checks against the vector table of values. @param other the factor to compare to @param tolerance the tolerance to accept in differences @return whether the two factors are within tolerance of one another
[ "Does", "a", "deep", "comparison", "using", "equality", "with", "tolerance", "checks", "against", "the", "vector", "table", "of", "values", "." ]
fa0c370ab6782015412f676ef2ab11c97be58e29
https://github.com/keenon/loglinear/blob/fa0c370ab6782015412f676ef2ab11c97be58e29/src/main/java/com/github/keenon/loglinear/model/NDArrayDoubles.java#L164-L171
144,931
HsiangLeekwok/hlklib
hlklib/src/main/java/com/hlk/hlklib/etc/Cryptography.java
Cryptography.stringMessageDigest
private static String stringMessageDigest(String source, String algorithm) { return getMessageDigest(source.getBytes(), algorithm); }
java
private static String stringMessageDigest(String source, String algorithm) { return getMessageDigest(source.getBytes(), algorithm); }
[ "private", "static", "String", "stringMessageDigest", "(", "String", "source", ",", "String", "algorithm", ")", "{", "return", "getMessageDigest", "(", "source", ".", "getBytes", "(", ")", ",", "algorithm", ")", ";", "}" ]
Get the sha1 value of a string @param source string @return the sha value
[ "Get", "the", "sha1", "value", "of", "a", "string" ]
b122f6dcab7cec60c8e5455e0c31613d08bec6ad
https://github.com/HsiangLeekwok/hlklib/blob/b122f6dcab7cec60c8e5455e0c31613d08bec6ad/hlklib/src/main/java/com/hlk/hlklib/etc/Cryptography.java#L142-L144
144,932
josueeduardo/snappy
plugin-parent/snappy-loader/src/main/java/io/joshworks/snappy/loader/Launcher.java
Launcher.launch
protected void launch(String[] args, String mainClass, ClassLoader classLoader) throws Exception { Runnable runner = createMainMethodRunner(mainClass, args, classLoader); Thread.currentThread().setContextClassLoader(classLoader); runner.run(); }
java
protected void launch(String[] args, String mainClass, ClassLoader classLoader) throws Exception { Runnable runner = createMainMethodRunner(mainClass, args, classLoader); Thread.currentThread().setContextClassLoader(classLoader); runner.run(); }
[ "protected", "void", "launch", "(", "String", "[", "]", "args", ",", "String", "mainClass", ",", "ClassLoader", "classLoader", ")", "throws", "Exception", "{", "Runnable", "runner", "=", "createMainMethodRunner", "(", "mainClass", ",", "args", ",", "classLoader", ")", ";", "Thread", ".", "currentThread", "(", ")", ".", "setContextClassLoader", "(", "classLoader", ")", ";", "runner", ".", "run", "(", ")", ";", "}" ]
Launch the application given the archive file and a fully configured classloader. @param args the incoming arguments @param mainClass the main class to run @param classLoader the classloader @throws Exception if the launch fails
[ "Launch", "the", "application", "given", "the", "archive", "file", "and", "a", "fully", "configured", "classloader", "." ]
d95a9e811eda3c24a5e53086369208819884fa49
https://github.com/josueeduardo/snappy/blob/d95a9e811eda3c24a5e53086369208819884fa49/plugin-parent/snappy-loader/src/main/java/io/joshworks/snappy/loader/Launcher.java#L102-L107
144,933
chr78rm/tracelogger
src/main/java/de/christofreichardt/diagnosis/QueueTracer.java
QueueTracer.logException
@Override public void logException(LogLevel logLevel, Throwable throwable, Class clazz, String methodName) { this.tracer.logException(logLevel, throwable, clazz, methodName); }
java
@Override public void logException(LogLevel logLevel, Throwable throwable, Class clazz, String methodName) { this.tracer.logException(logLevel, throwable, clazz, methodName); }
[ "@", "Override", "public", "void", "logException", "(", "LogLevel", "logLevel", ",", "Throwable", "throwable", ",", "Class", "clazz", ",", "String", "methodName", ")", "{", "this", ".", "tracer", ".", "logException", "(", "logLevel", ",", "throwable", ",", "clazz", ",", "methodName", ")", ";", "}" ]
Delegates to the corresponding method of the wrapped tracer. @param logLevel one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVERE @param throwable the to be logged throwable @param clazz the originating class @param methodName the name of the relevant method
[ "Delegates", "to", "the", "corresponding", "method", "of", "the", "wrapped", "tracer", "." ]
ad22452b20f8111ad4d367302c2b26a100a20200
https://github.com/chr78rm/tracelogger/blob/ad22452b20f8111ad4d367302c2b26a100a20200/src/main/java/de/christofreichardt/diagnosis/QueueTracer.java#L205-L208
144,934
chr78rm/tracelogger
src/main/java/de/christofreichardt/diagnosis/QueueTracer.java
QueueTracer.wayout
@Override public TraceMethod wayout() { TraceMethod traceMethod = this.tracer.wayout(); if (getThreadMap().getCurrentStackSize() == 0) { clearCurrentTracingContext(); if (!TracerFactory.getInstance().offerTracer(this)) System.err.printf("WARNING: Offer failed. Possible queue corruption.%n"); } return traceMethod; }
java
@Override public TraceMethod wayout() { TraceMethod traceMethod = this.tracer.wayout(); if (getThreadMap().getCurrentStackSize() == 0) { clearCurrentTracingContext(); if (!TracerFactory.getInstance().offerTracer(this)) System.err.printf("WARNING: Offer failed. Possible queue corruption.%n"); } return traceMethod; }
[ "@", "Override", "public", "TraceMethod", "wayout", "(", ")", "{", "TraceMethod", "traceMethod", "=", "this", ".", "tracer", ".", "wayout", "(", ")", ";", "if", "(", "getThreadMap", "(", ")", ".", "getCurrentStackSize", "(", ")", "==", "0", ")", "{", "clearCurrentTracingContext", "(", ")", ";", "if", "(", "!", "TracerFactory", ".", "getInstance", "(", ")", ".", "offerTracer", "(", "this", ")", ")", "System", ".", "err", ".", "printf", "(", "\"WARNING: Offer failed. Possible queue corruption.%n\"", ")", ";", "}", "return", "traceMethod", ";", "}" ]
Delegates to the corresponding method of the wrapped tracer. Besides it checks if the stack size of the current tracing context has decreased to zero. If so then the current tracing context will be cleared. @return the TraceMethod which has been popped from the stack - a mere data object for internal use primarily. May be null.
[ "Delegates", "to", "the", "corresponding", "method", "of", "the", "wrapped", "tracer", ".", "Besides", "it", "checks", "if", "the", "stack", "size", "of", "the", "current", "tracing", "context", "has", "decreased", "to", "zero", ".", "If", "so", "then", "the", "current", "tracing", "context", "will", "be", "cleared", "." ]
ad22452b20f8111ad4d367302c2b26a100a20200
https://github.com/chr78rm/tracelogger/blob/ad22452b20f8111ad4d367302c2b26a100a20200/src/main/java/de/christofreichardt/diagnosis/QueueTracer.java#L226-L235
144,935
fuinorg/srcgen4j-commons
src/main/java/org/fuin/srcgen4j/commons/Folder.java
Folder.overrideAllowed
public final boolean overrideAllowed(final File file) { if (isOverride()) { // In general it's allowed to recreate existing files if (overrideExclude == null) { return true; } else { return !getOverrideExcludeFilter().accept(file); } } else { // It's NOT allowed to recreate existing files if (overrideInclude == null) { return false; } else { return getOverrideIncludeFilter().accept(file); } } }
java
public final boolean overrideAllowed(final File file) { if (isOverride()) { // In general it's allowed to recreate existing files if (overrideExclude == null) { return true; } else { return !getOverrideExcludeFilter().accept(file); } } else { // It's NOT allowed to recreate existing files if (overrideInclude == null) { return false; } else { return getOverrideIncludeFilter().accept(file); } } }
[ "public", "final", "boolean", "overrideAllowed", "(", "final", "File", "file", ")", "{", "if", "(", "isOverride", "(", ")", ")", "{", "// In general it's allowed to recreate existing files\r", "if", "(", "overrideExclude", "==", "null", ")", "{", "return", "true", ";", "}", "else", "{", "return", "!", "getOverrideExcludeFilter", "(", ")", ".", "accept", "(", "file", ")", ";", "}", "}", "else", "{", "// It's NOT allowed to recreate existing files\r", "if", "(", "overrideInclude", "==", "null", ")", "{", "return", "false", ";", "}", "else", "{", "return", "getOverrideIncludeFilter", "(", ")", ".", "accept", "(", "file", ")", ";", "}", "}", "}" ]
Checks if a file can be overridden. @param file File to check against the exclude condition. @return TRUE if the file can be overridden.
[ "Checks", "if", "a", "file", "can", "be", "overridden", "." ]
bce26fd3167ea91fb2f3ad3fc9a1836d3d9fb14b
https://github.com/fuinorg/srcgen4j-commons/blob/bce26fd3167ea91fb2f3ad3fc9a1836d3d9fb14b/src/main/java/org/fuin/srcgen4j/commons/Folder.java#L291-L307
144,936
fuinorg/srcgen4j-commons
src/main/java/org/fuin/srcgen4j/commons/Folder.java
Folder.cleanAllowed
public final boolean cleanAllowed(final File file) { if (cleanExclude == null) { return true; } if (cleanExcludeFilter == null) { cleanExcludeFilter = new RegexFileFilter(cleanExclude); } return !cleanExcludeFilter.accept(file); }
java
public final boolean cleanAllowed(final File file) { if (cleanExclude == null) { return true; } if (cleanExcludeFilter == null) { cleanExcludeFilter = new RegexFileFilter(cleanExclude); } return !cleanExcludeFilter.accept(file); }
[ "public", "final", "boolean", "cleanAllowed", "(", "final", "File", "file", ")", "{", "if", "(", "cleanExclude", "==", "null", ")", "{", "return", "true", ";", "}", "if", "(", "cleanExcludeFilter", "==", "null", ")", "{", "cleanExcludeFilter", "=", "new", "RegexFileFilter", "(", "cleanExclude", ")", ";", "}", "return", "!", "cleanExcludeFilter", ".", "accept", "(", "file", ")", ";", "}" ]
Checks if a file should be excluded from cleaning. @param file File to check against the exlcude condition. @return TRUE if the file can be cleaned.
[ "Checks", "if", "a", "file", "should", "be", "excluded", "from", "cleaning", "." ]
bce26fd3167ea91fb2f3ad3fc9a1836d3d9fb14b
https://github.com/fuinorg/srcgen4j-commons/blob/bce26fd3167ea91fb2f3ad3fc9a1836d3d9fb14b/src/main/java/org/fuin/srcgen4j/commons/Folder.java#L351-L359
144,937
fuinorg/srcgen4j-commons
src/main/java/org/fuin/srcgen4j/commons/Folder.java
Folder.getCanonicalDir
@Nullable public final File getCanonicalDir() { final String dir = getDirectory(); if (dir == null) { return null; } try { return new File(dir).getCanonicalFile(); } catch (final IOException ex) { throw new RuntimeException("Couldn't determine canonical file: " + dir, ex); } }
java
@Nullable public final File getCanonicalDir() { final String dir = getDirectory(); if (dir == null) { return null; } try { return new File(dir).getCanonicalFile(); } catch (final IOException ex) { throw new RuntimeException("Couldn't determine canonical file: " + dir, ex); } }
[ "@", "Nullable", "public", "final", "File", "getCanonicalDir", "(", ")", "{", "final", "String", "dir", "=", "getDirectory", "(", ")", ";", "if", "(", "dir", "==", "null", ")", "{", "return", "null", ";", "}", "try", "{", "return", "new", "File", "(", "dir", ")", ".", "getCanonicalFile", "(", ")", ";", "}", "catch", "(", "final", "IOException", "ex", ")", "{", "throw", "new", "RuntimeException", "(", "\"Couldn't determine canonical file: \"", "+", "dir", ",", "ex", ")", ";", "}", "}" ]
Returns the full path from project and folder. @return Directory.
[ "Returns", "the", "full", "path", "from", "project", "and", "folder", "." ]
bce26fd3167ea91fb2f3ad3fc9a1836d3d9fb14b
https://github.com/fuinorg/srcgen4j-commons/blob/bce26fd3167ea91fb2f3ad3fc9a1836d3d9fb14b/src/main/java/org/fuin/srcgen4j/commons/Folder.java#L408-L419
144,938
akberc/ceylon-maven-plugin
src/main/java/com/dgwave/car/maven/CeylonSdkDownload.java
CeylonSdkDownload.downloadSdk
private File downloadSdk(final String path) throws MojoExecutionException { File dotCeylon = new File(path); // or some other directory if (!dotCeylon.exists()) { dotCeylon.mkdirs(); } String[] segments = this.fromURL.split("/"); String file = segments[segments.length - 1]; String repoUrl = this.fromURL.substring(0, this.fromURL.length() - file.length()); String version = FileUtils.basename(file); File home = new File(dotCeylon, version); if (home.exists()) { getLog().info("Skipping download: Folder " + version + " corresponding to SDK already exists " + " in " + dotCeylon.getAbsolutePath()); return new File(home, "repo"); } File outputFile = new File(dotCeylon, file); if (outputFile.exists()) { throw new MojoExecutionException("Downloaded file " + outputFile.getAbsolutePath() + " exists. Please remove it and try again"); } try { doGet(outputFile, repoUrl); } catch (Exception e) { throw new MojoExecutionException("Error downloading SDK" + e.getLocalizedMessage(), e); } CeylonUtil.extract(outputFile, dotCeylon); outputFile.delete(); return new File(home, "repo"); }
java
private File downloadSdk(final String path) throws MojoExecutionException { File dotCeylon = new File(path); // or some other directory if (!dotCeylon.exists()) { dotCeylon.mkdirs(); } String[] segments = this.fromURL.split("/"); String file = segments[segments.length - 1]; String repoUrl = this.fromURL.substring(0, this.fromURL.length() - file.length()); String version = FileUtils.basename(file); File home = new File(dotCeylon, version); if (home.exists()) { getLog().info("Skipping download: Folder " + version + " corresponding to SDK already exists " + " in " + dotCeylon.getAbsolutePath()); return new File(home, "repo"); } File outputFile = new File(dotCeylon, file); if (outputFile.exists()) { throw new MojoExecutionException("Downloaded file " + outputFile.getAbsolutePath() + " exists. Please remove it and try again"); } try { doGet(outputFile, repoUrl); } catch (Exception e) { throw new MojoExecutionException("Error downloading SDK" + e.getLocalizedMessage(), e); } CeylonUtil.extract(outputFile, dotCeylon); outputFile.delete(); return new File(home, "repo"); }
[ "private", "File", "downloadSdk", "(", "final", "String", "path", ")", "throws", "MojoExecutionException", "{", "File", "dotCeylon", "=", "new", "File", "(", "path", ")", ";", "// or some other directory\r", "if", "(", "!", "dotCeylon", ".", "exists", "(", ")", ")", "{", "dotCeylon", ".", "mkdirs", "(", ")", ";", "}", "String", "[", "]", "segments", "=", "this", ".", "fromURL", ".", "split", "(", "\"/\"", ")", ";", "String", "file", "=", "segments", "[", "segments", ".", "length", "-", "1", "]", ";", "String", "repoUrl", "=", "this", ".", "fromURL", ".", "substring", "(", "0", ",", "this", ".", "fromURL", ".", "length", "(", ")", "-", "file", ".", "length", "(", ")", ")", ";", "String", "version", "=", "FileUtils", ".", "basename", "(", "file", ")", ";", "File", "home", "=", "new", "File", "(", "dotCeylon", ",", "version", ")", ";", "if", "(", "home", ".", "exists", "(", ")", ")", "{", "getLog", "(", ")", ".", "info", "(", "\"Skipping download: Folder \"", "+", "version", "+", "\" corresponding to SDK already exists \"", "+", "\" in \"", "+", "dotCeylon", ".", "getAbsolutePath", "(", ")", ")", ";", "return", "new", "File", "(", "home", ",", "\"repo\"", ")", ";", "}", "File", "outputFile", "=", "new", "File", "(", "dotCeylon", ",", "file", ")", ";", "if", "(", "outputFile", ".", "exists", "(", ")", ")", "{", "throw", "new", "MojoExecutionException", "(", "\"Downloaded file \"", "+", "outputFile", ".", "getAbsolutePath", "(", ")", "+", "\" exists. Please remove it and try again\"", ")", ";", "}", "try", "{", "doGet", "(", "outputFile", ",", "repoUrl", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "MojoExecutionException", "(", "\"Error downloading SDK\"", "+", "e", ".", "getLocalizedMessage", "(", ")", ",", "e", ")", ";", "}", "CeylonUtil", ".", "extract", "(", "outputFile", ",", "dotCeylon", ")", ";", "outputFile", ".", "delete", "(", ")", ";", "return", "new", "File", "(", "home", ",", "\"repo\"", ")", ";", "}" ]
Download the Ceylon SDK. @param path Where to download @return File The location of the SDK @throws MojoExecutionException In case of download error
[ "Download", "the", "Ceylon", "SDK", "." ]
b7f6c4a2b24f2fa237350c9e715f4193e83415ef
https://github.com/akberc/ceylon-maven-plugin/blob/b7f6c4a2b24f2fa237350c9e715f4193e83415ef/src/main/java/com/dgwave/car/maven/CeylonSdkDownload.java#L100-L138
144,939
akberc/ceylon-maven-plugin
src/main/java/com/dgwave/car/maven/CeylonSdkDownload.java
CeylonSdkDownload.doGet
private void doGet(final File outputFile, final String repoUrl) throws Exception { int readTimeOut = 5 * 60 * 1000; Repository repository = new Repository(repoUrl, repoUrl); wagon.setReadTimeout(readTimeOut); getLog().info("Read Timeout is set to " + readTimeOut + " milliseconds"); wagon.connect(repository); wagon.get(outputFile.getName(), outputFile); wagon.disconnect(); }
java
private void doGet(final File outputFile, final String repoUrl) throws Exception { int readTimeOut = 5 * 60 * 1000; Repository repository = new Repository(repoUrl, repoUrl); wagon.setReadTimeout(readTimeOut); getLog().info("Read Timeout is set to " + readTimeOut + " milliseconds"); wagon.connect(repository); wagon.get(outputFile.getName(), outputFile); wagon.disconnect(); }
[ "private", "void", "doGet", "(", "final", "File", "outputFile", ",", "final", "String", "repoUrl", ")", "throws", "Exception", "{", "int", "readTimeOut", "=", "5", "*", "60", "*", "1000", ";", "Repository", "repository", "=", "new", "Repository", "(", "repoUrl", ",", "repoUrl", ")", ";", "wagon", ".", "setReadTimeout", "(", "readTimeOut", ")", ";", "getLog", "(", ")", ".", "info", "(", "\"Read Timeout is set to \"", "+", "readTimeOut", "+", "\" milliseconds\"", ")", ";", "wagon", ".", "connect", "(", "repository", ")", ";", "wagon", ".", "get", "(", "outputFile", ".", "getName", "(", ")", ",", "outputFile", ")", ";", "wagon", ".", "disconnect", "(", ")", ";", "}" ]
Does the actual retrieval. @param outputFile The file to write to @param repoUrl @throws Exception When SDK cannot be retrieved TODO add proxy and listener and externalize timeout
[ "Does", "the", "actual", "retrieval", "." ]
b7f6c4a2b24f2fa237350c9e715f4193e83415ef
https://github.com/akberc/ceylon-maven-plugin/blob/b7f6c4a2b24f2fa237350c9e715f4193e83415ef/src/main/java/com/dgwave/car/maven/CeylonSdkDownload.java#L147-L157
144,940
jukta/j-tahoe
j-tahoe-maven/src/main/java/com/jukta/maven/CodeGenMojo.java
CodeGenMojo.execute
public void execute() throws MojoExecutionException, MojoFailureException { try { removeFromResources(blocksDir); removeFromResources(resourcesDir); File targetDir = new File(outputDir); boolean jar = "jar".equalsIgnoreCase(mavenProject.getPackaging()); if (jar) { JarBuilder builder = new JarBuilder(blocksDir, resourcesDir, targetDir, mavenProject, mavenSession, getLog()); builder.generate(); } else { WarBuilder builder = new WarBuilder(blocksDir, resourcesDir, targetDir, mavenProject, mavenSession, getLog()); builder.generate(); } } catch (Exception e) { throw new MojoFailureException("Source generator error", e); } }
java
public void execute() throws MojoExecutionException, MojoFailureException { try { removeFromResources(blocksDir); removeFromResources(resourcesDir); File targetDir = new File(outputDir); boolean jar = "jar".equalsIgnoreCase(mavenProject.getPackaging()); if (jar) { JarBuilder builder = new JarBuilder(blocksDir, resourcesDir, targetDir, mavenProject, mavenSession, getLog()); builder.generate(); } else { WarBuilder builder = new WarBuilder(blocksDir, resourcesDir, targetDir, mavenProject, mavenSession, getLog()); builder.generate(); } } catch (Exception e) { throw new MojoFailureException("Source generator error", e); } }
[ "public", "void", "execute", "(", ")", "throws", "MojoExecutionException", ",", "MojoFailureException", "{", "try", "{", "removeFromResources", "(", "blocksDir", ")", ";", "removeFromResources", "(", "resourcesDir", ")", ";", "File", "targetDir", "=", "new", "File", "(", "outputDir", ")", ";", "boolean", "jar", "=", "\"jar\"", ".", "equalsIgnoreCase", "(", "mavenProject", ".", "getPackaging", "(", ")", ")", ";", "if", "(", "jar", ")", "{", "JarBuilder", "builder", "=", "new", "JarBuilder", "(", "blocksDir", ",", "resourcesDir", ",", "targetDir", ",", "mavenProject", ",", "mavenSession", ",", "getLog", "(", ")", ")", ";", "builder", ".", "generate", "(", ")", ";", "}", "else", "{", "WarBuilder", "builder", "=", "new", "WarBuilder", "(", "blocksDir", ",", "resourcesDir", ",", "targetDir", ",", "mavenProject", ",", "mavenSession", ",", "getLog", "(", ")", ")", ";", "builder", ".", "generate", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "MojoFailureException", "(", "\"Source generator error\"", ",", "e", ")", ";", "}", "}" ]
protected MojoExecutor.ExecutionEnvironment _pluginEnv;
[ "protected", "MojoExecutor", ".", "ExecutionEnvironment", "_pluginEnv", ";" ]
6b41882aa1542f5c533331104216143c5c9ce46f
https://github.com/jukta/j-tahoe/blob/6b41882aa1542f5c533331104216143c5c9ce46f/j-tahoe-maven/src/main/java/com/jukta/maven/CodeGenMojo.java#L41-L57
144,941
wcm-io-caravan/caravan-hal
resource/src/main/java/io/wcm/caravan/hal/resource/HalResourceFactory.java
HalResourceFactory.getStateAsObject
@Deprecated public static <T> T getStateAsObject(HalResource halResource, Class<T> type) { return halResource.adaptTo(type); }
java
@Deprecated public static <T> T getStateAsObject(HalResource halResource, Class<T> type) { return halResource.adaptTo(type); }
[ "@", "Deprecated", "public", "static", "<", "T", ">", "T", "getStateAsObject", "(", "HalResource", "halResource", ",", "Class", "<", "T", ">", "type", ")", "{", "return", "halResource", ".", "adaptTo", "(", "type", ")", ";", "}" ]
Converts the JSON model to an object of the given type. @param halResource HAL resource with model to convert @param type Type of the requested object @param <T> Output type @return State as object @deprecated use {@link HalResource#adaptTo(Class)}
[ "Converts", "the", "JSON", "model", "to", "an", "object", "of", "the", "given", "type", "." ]
25d58756b58c70c8c48a17fe781e673dd93d5085
https://github.com/wcm-io-caravan/caravan-hal/blob/25d58756b58c70c8c48a17fe781e673dd93d5085/resource/src/main/java/io/wcm/caravan/hal/resource/HalResourceFactory.java#L104-L107
144,942
pressgang-ccms/PressGangCCMSCommonUtilities
src/main/java/org/jboss/pressgang/ccms/utils/common/InetUtilities.java
InetUtilities.getURLData
public static byte[] getURLData(final String url) { final int readBytes = 1000; URL u; InputStream is = null; final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); // See http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } }}; // Install the all-trusting trust manager // FIXME from Lee: This doesn't seem like a wise idea to install an all-trusting cert manager by default try { final SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (final Exception ex) { LOG.error("Unable to install the all-trust SSL Manager", ex); } try { u = new URL(url); is = u.openStream(); // throws an IOException int nRead; byte[] data = new byte[readBytes]; while ((nRead = is.read(data, 0, readBytes)) != -1) { buffer.write(data, 0, nRead); } } catch (final Exception ex) { LOG.error("Unable to read data from URL", ex); } finally { try { buffer.flush(); if (is != null) is.close(); } catch (final Exception ex) { LOG.error("Unable to flush and close URL Input Stream", ex); } } return buffer.toByteArray(); }
java
public static byte[] getURLData(final String url) { final int readBytes = 1000; URL u; InputStream is = null; final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); // See http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } }}; // Install the all-trusting trust manager // FIXME from Lee: This doesn't seem like a wise idea to install an all-trusting cert manager by default try { final SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (final Exception ex) { LOG.error("Unable to install the all-trust SSL Manager", ex); } try { u = new URL(url); is = u.openStream(); // throws an IOException int nRead; byte[] data = new byte[readBytes]; while ((nRead = is.read(data, 0, readBytes)) != -1) { buffer.write(data, 0, nRead); } } catch (final Exception ex) { LOG.error("Unable to read data from URL", ex); } finally { try { buffer.flush(); if (is != null) is.close(); } catch (final Exception ex) { LOG.error("Unable to flush and close URL Input Stream", ex); } } return buffer.toByteArray(); }
[ "public", "static", "byte", "[", "]", "getURLData", "(", "final", "String", "url", ")", "{", "final", "int", "readBytes", "=", "1000", ";", "URL", "u", ";", "InputStream", "is", "=", "null", ";", "final", "ByteArrayOutputStream", "buffer", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "// See http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html", "// Create a trust manager that does not validate certificate chains", "final", "TrustManager", "[", "]", "trustAllCerts", "=", "new", "TrustManager", "[", "]", "{", "new", "X509TrustManager", "(", ")", "{", "public", "java", ".", "security", ".", "cert", ".", "X509Certificate", "[", "]", "getAcceptedIssuers", "(", ")", "{", "return", "null", ";", "}", "public", "void", "checkClientTrusted", "(", "java", ".", "security", ".", "cert", ".", "X509Certificate", "[", "]", "certs", ",", "String", "authType", ")", "{", "}", "public", "void", "checkServerTrusted", "(", "java", ".", "security", ".", "cert", ".", "X509Certificate", "[", "]", "certs", ",", "String", "authType", ")", "{", "}", "}", "}", ";", "// Install the all-trusting trust manager", "// FIXME from Lee: This doesn't seem like a wise idea to install an all-trusting cert manager by default", "try", "{", "final", "SSLContext", "sc", "=", "SSLContext", ".", "getInstance", "(", "\"SSL\"", ")", ";", "sc", ".", "init", "(", "null", ",", "trustAllCerts", ",", "new", "java", ".", "security", ".", "SecureRandom", "(", ")", ")", ";", "HttpsURLConnection", ".", "setDefaultSSLSocketFactory", "(", "sc", ".", "getSocketFactory", "(", ")", ")", ";", "}", "catch", "(", "final", "Exception", "ex", ")", "{", "LOG", ".", "error", "(", "\"Unable to install the all-trust SSL Manager\"", ",", "ex", ")", ";", "}", "try", "{", "u", "=", "new", "URL", "(", "url", ")", ";", "is", "=", "u", ".", "openStream", "(", ")", ";", "// throws an IOException", "int", "nRead", ";", "byte", "[", "]", "data", "=", "new", "byte", "[", "readBytes", "]", ";", "while", "(", "(", "nRead", "=", "is", ".", "read", "(", "data", ",", "0", ",", "readBytes", ")", ")", "!=", "-", "1", ")", "{", "buffer", ".", "write", "(", "data", ",", "0", ",", "nRead", ")", ";", "}", "}", "catch", "(", "final", "Exception", "ex", ")", "{", "LOG", ".", "error", "(", "\"Unable to read data from URL\"", ",", "ex", ")", ";", "}", "finally", "{", "try", "{", "buffer", ".", "flush", "(", ")", ";", "if", "(", "is", "!=", "null", ")", "is", ".", "close", "(", ")", ";", "}", "catch", "(", "final", "Exception", "ex", ")", "{", "LOG", ".", "error", "(", "\"Unable to flush and close URL Input Stream\"", ",", "ex", ")", ";", "}", "}", "return", "buffer", ".", "toByteArray", "(", ")", ";", "}" ]
Downloads a file as a byte array @param url The URL of the resource to download @return The byte array containing the data of the downloaded file
[ "Downloads", "a", "file", "as", "a", "byte", "array" ]
5ebf5ed30a94c34c33f4708caa04a8da99cbb15c
https://github.com/pressgang-ccms/PressGangCCMSCommonUtilities/blob/5ebf5ed30a94c34c33f4708caa04a8da99cbb15c/src/main/java/org/jboss/pressgang/ccms/utils/common/InetUtilities.java#L42-L97
144,943
gsi-upm/Shanks
shanks-core/src/main/java/es/upm/dit/gsi/shanks/model/element/device/portrayal/Device2DPortrayal.java
Device2DPortrayal.putImage
public void putImage(String path, int x, int y, int w, int h, Graphics2D graphics) { ImageIcon i = new ImageIcon(path); Image image = i.getImage(); ImageObserver io = new ImageObserver() { @Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { return false; } }; graphics.drawImage(image, x, y, w * 3, h * 3, io); }
java
public void putImage(String path, int x, int y, int w, int h, Graphics2D graphics) { ImageIcon i = new ImageIcon(path); Image image = i.getImage(); ImageObserver io = new ImageObserver() { @Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { return false; } }; graphics.drawImage(image, x, y, w * 3, h * 3, io); }
[ "public", "void", "putImage", "(", "String", "path", ",", "int", "x", ",", "int", "y", ",", "int", "w", ",", "int", "h", ",", "Graphics2D", "graphics", ")", "{", "ImageIcon", "i", "=", "new", "ImageIcon", "(", "path", ")", ";", "Image", "image", "=", "i", ".", "getImage", "(", ")", ";", "ImageObserver", "io", "=", "new", "ImageObserver", "(", ")", "{", "@", "Override", "public", "boolean", "imageUpdate", "(", "Image", "img", ",", "int", "infoflags", ",", "int", "x", ",", "int", "y", ",", "int", "width", ",", "int", "height", ")", "{", "return", "false", ";", "}", "}", ";", "graphics", ".", "drawImage", "(", "image", ",", "x", ",", "y", ",", "w", "*", "3", ",", "h", "*", "3", ",", "io", ")", ";", "}" ]
The portrayal of the current device can draw a geometric figure or print a predefine image. This method is called when the device has been linked to be draw as an image. @param path path to the file that contains the image. @param x the X position coordinate. @param y the Y position coordinate. @param w the wide of the portrayal. @param h the height of the portrayal. @param graphics the graphics object to draw the image on.
[ "The", "portrayal", "of", "the", "current", "device", "can", "draw", "a", "geometric", "figure", "or", "print", "a", "predefine", "image", ".", "This", "method", "is", "called", "when", "the", "device", "has", "been", "linked", "to", "be", "draw", "as", "an", "image", "." ]
35d87a81c22731f4f83bbd0571c9c6d466bd16be
https://github.com/gsi-upm/Shanks/blob/35d87a81c22731f4f83bbd0571c9c6d466bd16be/shanks-core/src/main/java/es/upm/dit/gsi/shanks/model/element/device/portrayal/Device2DPortrayal.java#L88-L102
144,944
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.beginArray
public JsonWriter beginArray(String arrayName) throws IOException { writeName(arrayName); writer.beginArray(); writeStack.add(JsonTokenType.BEGIN_ARRAY); return this; }
java
public JsonWriter beginArray(String arrayName) throws IOException { writeName(arrayName); writer.beginArray(); writeStack.add(JsonTokenType.BEGIN_ARRAY); return this; }
[ "public", "JsonWriter", "beginArray", "(", "String", "arrayName", ")", "throws", "IOException", "{", "writeName", "(", "arrayName", ")", ";", "writer", ".", "beginArray", "(", ")", ";", "writeStack", ".", "add", "(", "JsonTokenType", ".", "BEGIN_ARRAY", ")", ";", "return", "this", ";", "}" ]
Begins a new array with given name @param arrayName the name @return This structured writer @throws IOException Something went wrong writing
[ "Begins", "a", "new", "array", "with", "given", "name" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L82-L87
144,945
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.beginObject
public JsonWriter beginObject(String objectName) throws IOException { writeName(objectName); writer.beginObject(); writeStack.add(JsonTokenType.BEGIN_OBJECT); return this; }
java
public JsonWriter beginObject(String objectName) throws IOException { writeName(objectName); writer.beginObject(); writeStack.add(JsonTokenType.BEGIN_OBJECT); return this; }
[ "public", "JsonWriter", "beginObject", "(", "String", "objectName", ")", "throws", "IOException", "{", "writeName", "(", "objectName", ")", ";", "writer", ".", "beginObject", "(", ")", ";", "writeStack", ".", "add", "(", "JsonTokenType", ".", "BEGIN_OBJECT", ")", ";", "return", "this", ";", "}" ]
Begins a new object with a given name @param objectName the name @return This structured writer @throws IOException Something went wrong writing
[ "Begins", "a", "new", "object", "with", "a", "given", "name" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L136-L141
144,946
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.endArray
public JsonWriter endArray() throws IOException { checkAndPop(JsonTokenType.BEGIN_ARRAY); popIf(JsonTokenType.NAME); writer.endArray(); return this; }
java
public JsonWriter endArray() throws IOException { checkAndPop(JsonTokenType.BEGIN_ARRAY); popIf(JsonTokenType.NAME); writer.endArray(); return this; }
[ "public", "JsonWriter", "endArray", "(", ")", "throws", "IOException", "{", "checkAndPop", "(", "JsonTokenType", ".", "BEGIN_ARRAY", ")", ";", "popIf", "(", "JsonTokenType", ".", "NAME", ")", ";", "writer", ".", "endArray", "(", ")", ";", "return", "this", ";", "}" ]
Ends the current array @return This structured writer @throws IOException Something went wrong writing
[ "Ends", "the", "current", "array" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L161-L166
144,947
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.endObject
public JsonWriter endObject() throws IOException { checkAndPop(JsonTokenType.BEGIN_OBJECT); popIf(JsonTokenType.NAME); writer.endObject(); return this; }
java
public JsonWriter endObject() throws IOException { checkAndPop(JsonTokenType.BEGIN_OBJECT); popIf(JsonTokenType.NAME); writer.endObject(); return this; }
[ "public", "JsonWriter", "endObject", "(", ")", "throws", "IOException", "{", "checkAndPop", "(", "JsonTokenType", ".", "BEGIN_OBJECT", ")", ";", "popIf", "(", "JsonTokenType", ".", "NAME", ")", ";", "writer", ".", "endObject", "(", ")", ";", "return", "this", ";", "}" ]
Ends the current object @return This structured writer @throws IOException Something went wrong writing
[ "Ends", "the", "current", "object" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L188-L193
144,948
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.inArray
public boolean inArray() { return writeStack.peek() == JsonTokenType.BEGIN_ARRAY || (writeStack.peek() == JsonTokenType.BEGIN_DOCUMENT && isArray); }
java
public boolean inArray() { return writeStack.peek() == JsonTokenType.BEGIN_ARRAY || (writeStack.peek() == JsonTokenType.BEGIN_DOCUMENT && isArray); }
[ "public", "boolean", "inArray", "(", ")", "{", "return", "writeStack", ".", "peek", "(", ")", "==", "JsonTokenType", ".", "BEGIN_ARRAY", "||", "(", "writeStack", ".", "peek", "(", ")", "==", "JsonTokenType", ".", "BEGIN_DOCUMENT", "&&", "isArray", ")", ";", "}" ]
Determines if the writer is currently in an array @return True if in an array, False if not
[ "Determines", "if", "the", "writer", "is", "currently", "in", "an", "array" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L209-L211
144,949
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.inObject
public boolean inObject() { return writeStack.peek() == JsonTokenType.BEGIN_OBJECT || (writeStack.peek() == JsonTokenType.BEGIN_DOCUMENT && !isArray); }
java
public boolean inObject() { return writeStack.peek() == JsonTokenType.BEGIN_OBJECT || (writeStack.peek() == JsonTokenType.BEGIN_DOCUMENT && !isArray); }
[ "public", "boolean", "inObject", "(", ")", "{", "return", "writeStack", ".", "peek", "(", ")", "==", "JsonTokenType", ".", "BEGIN_OBJECT", "||", "(", "writeStack", ".", "peek", "(", ")", "==", "JsonTokenType", ".", "BEGIN_DOCUMENT", "&&", "!", "isArray", ")", ";", "}" ]
Determines if the writer is currently in an object @return True if in an object, False if not
[ "Determines", "if", "the", "writer", "is", "currently", "in", "an", "object" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L218-L220
144,950
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.property
protected JsonWriter property(String key, Object[] array) throws IOException { return property(key, Arrays.asList(array)); }
java
protected JsonWriter property(String key, Object[] array) throws IOException { return property(key, Arrays.asList(array)); }
[ "protected", "JsonWriter", "property", "(", "String", "key", ",", "Object", "[", "]", "array", ")", "throws", "IOException", "{", "return", "property", "(", "key", ",", "Arrays", ".", "asList", "(", "array", ")", ")", ";", "}" ]
Writes an array with the given key name @param key the key name for the array @param array the array to be written @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "an", "array", "with", "the", "given", "key", "name" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L250-L252
144,951
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.property
protected JsonWriter property(String key, Iterable<?> iterable) throws IOException { Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array."); beginArray(key); for (Object o : iterable) { value(o); } endArray(); return this; }
java
protected JsonWriter property(String key, Iterable<?> iterable) throws IOException { Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array."); beginArray(key); for (Object o : iterable) { value(o); } endArray(); return this; }
[ "protected", "JsonWriter", "property", "(", "String", "key", ",", "Iterable", "<", "?", ">", "iterable", ")", "throws", "IOException", "{", "Preconditions", ".", "checkArgument", "(", "!", "inArray", "(", ")", ",", "\"Cannot write a property inside an array.\"", ")", ";", "beginArray", "(", "key", ")", ";", "for", "(", "Object", "o", ":", "iterable", ")", "{", "value", "(", "o", ")", ";", "}", "endArray", "(", ")", ";", "return", "this", ";", "}" ]
Writes an iterable with the given key name @param key the key name for the collection @param iterable the iterable to be written @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "an", "iterable", "with", "the", "given", "key", "name" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L262-L270
144,952
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.property
protected JsonWriter property(String key, Iterator<?> iterator) throws IOException { return property(key, Collect.asIterable(iterator)); }
java
protected JsonWriter property(String key, Iterator<?> iterator) throws IOException { return property(key, Collect.asIterable(iterator)); }
[ "protected", "JsonWriter", "property", "(", "String", "key", ",", "Iterator", "<", "?", ">", "iterator", ")", "throws", "IOException", "{", "return", "property", "(", "key", ",", "Collect", ".", "asIterable", "(", "iterator", ")", ")", ";", "}" ]
Writes an iterator with the given key name @param key the key name for the collection @param iterator the iterator to be written @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "an", "iterator", "with", "the", "given", "key", "name" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L280-L282
144,953
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.property
public JsonWriter property(String key, Object value) throws IOException { Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array."); writeName(key); value(value); return this; }
java
public JsonWriter property(String key, Object value) throws IOException { Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array."); writeName(key); value(value); return this; }
[ "public", "JsonWriter", "property", "(", "String", "key", ",", "Object", "value", ")", "throws", "IOException", "{", "Preconditions", ".", "checkArgument", "(", "!", "inArray", "(", ")", ",", "\"Cannot write a property inside an array.\"", ")", ";", "writeName", "(", "key", ")", ";", "value", "(", "value", ")", ";", "return", "this", ";", "}" ]
Writes a key value pair @param key the key @param value the value @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "a", "key", "value", "pair" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L292-L297
144,954
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.property
public JsonWriter property(String key, Map<String, ?> map) throws IOException { Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array."); writeName(key); value(map); return this; }
java
public JsonWriter property(String key, Map<String, ?> map) throws IOException { Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array."); writeName(key); value(map); return this; }
[ "public", "JsonWriter", "property", "(", "String", "key", ",", "Map", "<", "String", ",", "?", ">", "map", ")", "throws", "IOException", "{", "Preconditions", ".", "checkArgument", "(", "!", "inArray", "(", ")", ",", "\"Cannot write a property inside an array.\"", ")", ";", "writeName", "(", "key", ")", ";", "value", "(", "map", ")", ";", "return", "this", ";", "}" ]
Writes a map with the given key name @param key the key name for the map @param map the map to be written @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "a", "map", "with", "the", "given", "key", "name" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L307-L312
144,955
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.value
public JsonWriter value(Map<String, ?> map) throws IOException { if (map == null) { nullValue(); } else { boolean inObject = inObject(); if (!inObject) beginObject(); for (Map.Entry<String, ?> entry : map.entrySet()) { property(entry.getKey(), entry.getValue()); } if (!inObject) endObject(); } popIf(JsonTokenType.NAME); return this; }
java
public JsonWriter value(Map<String, ?> map) throws IOException { if (map == null) { nullValue(); } else { boolean inObject = inObject(); if (!inObject) beginObject(); for (Map.Entry<String, ?> entry : map.entrySet()) { property(entry.getKey(), entry.getValue()); } if (!inObject) endObject(); } popIf(JsonTokenType.NAME); return this; }
[ "public", "JsonWriter", "value", "(", "Map", "<", "String", ",", "?", ">", "map", ")", "throws", "IOException", "{", "if", "(", "map", "==", "null", ")", "{", "nullValue", "(", ")", ";", "}", "else", "{", "boolean", "inObject", "=", "inObject", "(", ")", ";", "if", "(", "!", "inObject", ")", "beginObject", "(", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "?", ">", "entry", ":", "map", ".", "entrySet", "(", ")", ")", "{", "property", "(", "entry", ".", "getKey", "(", ")", ",", "entry", ".", "getValue", "(", ")", ")", ";", "}", "if", "(", "!", "inObject", ")", "endObject", "(", ")", ";", "}", "popIf", "(", "JsonTokenType", ".", "NAME", ")", ";", "return", "this", ";", "}" ]
Writes a map @param map the map to be written @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "a", "map" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L403-L416
144,956
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.value
public JsonWriter value(Number number) throws IOException { Preconditions.checkArgument(inArray() || writeStack.peek() == JsonTokenType.NAME, "Expecting an array or a name, but found " + writeStack.peek()); popIf(JsonTokenType.NAME); writer.value(number); return this; }
java
public JsonWriter value(Number number) throws IOException { Preconditions.checkArgument(inArray() || writeStack.peek() == JsonTokenType.NAME, "Expecting an array or a name, but found " + writeStack.peek()); popIf(JsonTokenType.NAME); writer.value(number); return this; }
[ "public", "JsonWriter", "value", "(", "Number", "number", ")", "throws", "IOException", "{", "Preconditions", ".", "checkArgument", "(", "inArray", "(", ")", "||", "writeStack", ".", "peek", "(", ")", "==", "JsonTokenType", ".", "NAME", ",", "\"Expecting an array or a name, but found \"", "+", "writeStack", ".", "peek", "(", ")", ")", ";", "popIf", "(", "JsonTokenType", ".", "NAME", ")", ";", "writer", ".", "value", "(", "number", ")", ";", "return", "this", ";", "}" ]
Writes a number @param number the number @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "a", "number" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L425-L431
144,957
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.value
public JsonWriter value(Object value) throws IOException { Preconditions.checkArgument(inArray() || writeStack.peek() == JsonTokenType.NAME, "Expecting an array or a name, but found " + writeStack.peek()); writeObject(value); popIf(JsonTokenType.NAME); return this; }
java
public JsonWriter value(Object value) throws IOException { Preconditions.checkArgument(inArray() || writeStack.peek() == JsonTokenType.NAME, "Expecting an array or a name, but found " + writeStack.peek()); writeObject(value); popIf(JsonTokenType.NAME); return this; }
[ "public", "JsonWriter", "value", "(", "Object", "value", ")", "throws", "IOException", "{", "Preconditions", ".", "checkArgument", "(", "inArray", "(", ")", "||", "writeStack", ".", "peek", "(", ")", "==", "JsonTokenType", ".", "NAME", ",", "\"Expecting an array or a name, but found \"", "+", "writeStack", ".", "peek", "(", ")", ")", ";", "writeObject", "(", "value", ")", ";", "popIf", "(", "JsonTokenType", ".", "NAME", ")", ";", "return", "this", ";", "}" ]
Writes an array value @param value the value @return This structured writer @throws IOException Something went wrong writing
[ "Writes", "an", "array", "value" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L452-L458
144,958
dbracewell/mango
src/main/java/com/davidbracewell/json/JsonWriter.java
JsonWriter.writeObject
protected JsonWriter writeObject(Object object) throws IOException { if (object == null) { nullValue(); } else if (object instanceof JsonSerializable) { JsonSerializable structuredSerializable = Cast.as(object); if (object instanceof JsonArraySerializable) { beginArray(); } else { beginObject(); } structuredSerializable.toJson(this); if (object instanceof JsonArraySerializable) { endArray(); } else { endObject(); } } else if (object instanceof Number) { value(Cast.<Number>as(object)); } else if (object instanceof String) { value(Cast.<String>as(object)); } else if (object instanceof Boolean) { value(Cast.<Boolean>as(object).toString()); } else if (object instanceof Enum) { value(Cast.<Enum>as(object).name()); } else if (object instanceof EnumValue) { value(Cast.<EnumValue>as(object).name()); } else if (object instanceof Map) { value(Cast.<Map<String, ?>>as(object)); } else if (object.getClass().isArray()) { value(Cast.<Object[]>as(object)); } else if (object instanceof Multimap) { value(Cast.<Multimap<String, ?>>as(object).asMap()); } else if (object instanceof Counter) { value(Cast.<Counter<String>>as(object).asMap()); } else if (object instanceof Iterable) { value(Cast.<Iterable>as(object)); } else if (object instanceof Iterator) { value(Cast.<Iterator>as(object)); } else { value(Convert.convert(object, String.class)); } return this; }
java
protected JsonWriter writeObject(Object object) throws IOException { if (object == null) { nullValue(); } else if (object instanceof JsonSerializable) { JsonSerializable structuredSerializable = Cast.as(object); if (object instanceof JsonArraySerializable) { beginArray(); } else { beginObject(); } structuredSerializable.toJson(this); if (object instanceof JsonArraySerializable) { endArray(); } else { endObject(); } } else if (object instanceof Number) { value(Cast.<Number>as(object)); } else if (object instanceof String) { value(Cast.<String>as(object)); } else if (object instanceof Boolean) { value(Cast.<Boolean>as(object).toString()); } else if (object instanceof Enum) { value(Cast.<Enum>as(object).name()); } else if (object instanceof EnumValue) { value(Cast.<EnumValue>as(object).name()); } else if (object instanceof Map) { value(Cast.<Map<String, ?>>as(object)); } else if (object.getClass().isArray()) { value(Cast.<Object[]>as(object)); } else if (object instanceof Multimap) { value(Cast.<Multimap<String, ?>>as(object).asMap()); } else if (object instanceof Counter) { value(Cast.<Counter<String>>as(object).asMap()); } else if (object instanceof Iterable) { value(Cast.<Iterable>as(object)); } else if (object instanceof Iterator) { value(Cast.<Iterator>as(object)); } else { value(Convert.convert(object, String.class)); } return this; }
[ "protected", "JsonWriter", "writeObject", "(", "Object", "object", ")", "throws", "IOException", "{", "if", "(", "object", "==", "null", ")", "{", "nullValue", "(", ")", ";", "}", "else", "if", "(", "object", "instanceof", "JsonSerializable", ")", "{", "JsonSerializable", "structuredSerializable", "=", "Cast", ".", "as", "(", "object", ")", ";", "if", "(", "object", "instanceof", "JsonArraySerializable", ")", "{", "beginArray", "(", ")", ";", "}", "else", "{", "beginObject", "(", ")", ";", "}", "structuredSerializable", ".", "toJson", "(", "this", ")", ";", "if", "(", "object", "instanceof", "JsonArraySerializable", ")", "{", "endArray", "(", ")", ";", "}", "else", "{", "endObject", "(", ")", ";", "}", "}", "else", "if", "(", "object", "instanceof", "Number", ")", "{", "value", "(", "Cast", ".", "<", "Number", ">", "as", "(", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "String", ")", "{", "value", "(", "Cast", ".", "<", "String", ">", "as", "(", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Boolean", ")", "{", "value", "(", "Cast", ".", "<", "Boolean", ">", "as", "(", "object", ")", ".", "toString", "(", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Enum", ")", "{", "value", "(", "Cast", ".", "<", "Enum", ">", "as", "(", "object", ")", ".", "name", "(", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "EnumValue", ")", "{", "value", "(", "Cast", ".", "<", "EnumValue", ">", "as", "(", "object", ")", ".", "name", "(", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Map", ")", "{", "value", "(", "Cast", ".", "<", "Map", "<", "String", ",", "?", ">", ">", "as", "(", "object", ")", ")", ";", "}", "else", "if", "(", "object", ".", "getClass", "(", ")", ".", "isArray", "(", ")", ")", "{", "value", "(", "Cast", ".", "<", "Object", "[", "]", ">", "as", "(", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Multimap", ")", "{", "value", "(", "Cast", ".", "<", "Multimap", "<", "String", ",", "?", ">", ">", "as", "(", "object", ")", ".", "asMap", "(", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Counter", ")", "{", "value", "(", "Cast", ".", "<", "Counter", "<", "String", ">", ">", "as", "(", "object", ")", ".", "asMap", "(", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Iterable", ")", "{", "value", "(", "Cast", ".", "<", "Iterable", ">", "as", "(", "object", ")", ")", ";", "}", "else", "if", "(", "object", "instanceof", "Iterator", ")", "{", "value", "(", "Cast", ".", "<", "Iterator", ">", "as", "(", "object", ")", ")", ";", "}", "else", "{", "value", "(", "Convert", ".", "convert", "(", "object", ",", "String", ".", "class", ")", ")", ";", "}", "return", "this", ";", "}" ]
Serializes an object @param object the object to serialize @return This structured writer @throws IOException Something went wrong writing
[ "Serializes", "an", "object" ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/json/JsonWriter.java#L475-L517
144,959
lightszentip/logmanagement-plugin
src/main/java/com/lightszentip/module/logmanagement/plugin/logback/LogManagementPluginLogbackImpl.java
LogManagementPluginLogbackImpl.mapLogLevel
private Level mapLogLevel(final LogLevel logLevel) { if (LogLevel.DEBUG.equals(logLevel)) { return Level.DEBUG; } else if (LogLevel.TRACE.equals(logLevel)) { return Level.TRACE; } else if (LogLevel.INFO.equals(logLevel)) { return Level.INFO; } else if (LogLevel.WARN.equals(logLevel)) { return Level.WARN; } else if (LogLevel.ERROR.equals(logLevel)) { return Level.ERROR; } return null; }
java
private Level mapLogLevel(final LogLevel logLevel) { if (LogLevel.DEBUG.equals(logLevel)) { return Level.DEBUG; } else if (LogLevel.TRACE.equals(logLevel)) { return Level.TRACE; } else if (LogLevel.INFO.equals(logLevel)) { return Level.INFO; } else if (LogLevel.WARN.equals(logLevel)) { return Level.WARN; } else if (LogLevel.ERROR.equals(logLevel)) { return Level.ERROR; } return null; }
[ "private", "Level", "mapLogLevel", "(", "final", "LogLevel", "logLevel", ")", "{", "if", "(", "LogLevel", ".", "DEBUG", ".", "equals", "(", "logLevel", ")", ")", "{", "return", "Level", ".", "DEBUG", ";", "}", "else", "if", "(", "LogLevel", ".", "TRACE", ".", "equals", "(", "logLevel", ")", ")", "{", "return", "Level", ".", "TRACE", ";", "}", "else", "if", "(", "LogLevel", ".", "INFO", ".", "equals", "(", "logLevel", ")", ")", "{", "return", "Level", ".", "INFO", ";", "}", "else", "if", "(", "LogLevel", ".", "WARN", ".", "equals", "(", "logLevel", ")", ")", "{", "return", "Level", ".", "WARN", ";", "}", "else", "if", "(", "LogLevel", ".", "ERROR", ".", "equals", "(", "logLevel", ")", ")", "{", "return", "Level", ".", "ERROR", ";", "}", "return", "null", ";", "}" ]
Map the plugin log level to logback log level. @param logLevel The plugin log level. @return The logback log level.
[ "Map", "the", "plugin", "log", "level", "to", "logback", "log", "level", "." ]
acd648a88c2d261848088a29787f09fc0818d369
https://github.com/lightszentip/logmanagement-plugin/blob/acd648a88c2d261848088a29787f09fc0818d369/src/main/java/com/lightszentip/module/logmanagement/plugin/logback/LogManagementPluginLogbackImpl.java#L71-L84
144,960
devcon5io/common
classutils/src/main/java/io/devcon5/classutils/ResourceResolver.java
ResourceResolver.resolve
public URL resolve(String resource, Class consumer){ final ClassLoader ccl = Thread.currentThread().getContextClassLoader(); final String resourcePath = resolvePath(resource, consumer); URL contentUrl = null; if (ccl != null) { contentUrl = ccl.getResource(resourcePath); } if (contentUrl == null) { contentUrl = consumer.getResource(resourcePath); } if(failOnMissingResource && contentUrl == null){ throw new AssertionError("Resource " + resource + " not found"); } return contentUrl; }
java
public URL resolve(String resource, Class consumer){ final ClassLoader ccl = Thread.currentThread().getContextClassLoader(); final String resourcePath = resolvePath(resource, consumer); URL contentUrl = null; if (ccl != null) { contentUrl = ccl.getResource(resourcePath); } if (contentUrl == null) { contentUrl = consumer.getResource(resourcePath); } if(failOnMissingResource && contentUrl == null){ throw new AssertionError("Resource " + resource + " not found"); } return contentUrl; }
[ "public", "URL", "resolve", "(", "String", "resource", ",", "Class", "consumer", ")", "{", "final", "ClassLoader", "ccl", "=", "Thread", ".", "currentThread", "(", ")", ".", "getContextClassLoader", "(", ")", ";", "final", "String", "resourcePath", "=", "resolvePath", "(", "resource", ",", "consumer", ")", ";", "URL", "contentUrl", "=", "null", ";", "if", "(", "ccl", "!=", "null", ")", "{", "contentUrl", "=", "ccl", ".", "getResource", "(", "resourcePath", ")", ";", "}", "if", "(", "contentUrl", "==", "null", ")", "{", "contentUrl", "=", "consumer", ".", "getResource", "(", "resourcePath", ")", ";", "}", "if", "(", "failOnMissingResource", "&&", "contentUrl", "==", "null", ")", "{", "throw", "new", "AssertionError", "(", "\"Resource \"", "+", "resource", "+", "\" not found\"", ")", ";", "}", "return", "contentUrl", ";", "}" ]
Resolves a URL of the resource specified using the provided class as hint to start the search. For searching the resource the consumer's classloader is used. @param resource the path the resource. The path can be either absolute or relative to the consumers location. @param consumer the consumer class of the resource. It's classloader is used for the lookup and it's location is used as reference point for resolving relative path names @return a URL to the resolved resource
[ "Resolves", "a", "URL", "of", "the", "resource", "specified", "using", "the", "provided", "class", "as", "hint", "to", "start", "the", "search", ".", "For", "searching", "the", "resource", "the", "consumer", "s", "classloader", "is", "used", "." ]
363688e0dc904d559682bf796bd6c836b4e0efc7
https://github.com/devcon5io/common/blob/363688e0dc904d559682bf796bd6c836b4e0efc7/classutils/src/main/java/io/devcon5/classutils/ResourceResolver.java#L72-L87
144,961
LevelFourAB/commons
commons-serialization/src/main/java/se/l4/commons/serialization/spi/SerializerResolverRegistry.java
SerializerResolverRegistry.bind
public <T> void bind(Class<T> type, SerializerResolver<? extends T> resolver) { typeToResolverCache.put(type, Optional.<SerializerResolver<?>>of(resolver)); boundTypeToResolver.put(type, resolver); }
java
public <T> void bind(Class<T> type, SerializerResolver<? extends T> resolver) { typeToResolverCache.put(type, Optional.<SerializerResolver<?>>of(resolver)); boundTypeToResolver.put(type, resolver); }
[ "public", "<", "T", ">", "void", "bind", "(", "Class", "<", "T", ">", "type", ",", "SerializerResolver", "<", "?", "extends", "T", ">", "resolver", ")", "{", "typeToResolverCache", ".", "put", "(", "type", ",", "Optional", ".", "<", "SerializerResolver", "<", "?", ">", ">", "of", "(", "resolver", ")", ")", ";", "boundTypeToResolver", ".", "put", "(", "type", ",", "resolver", ")", ";", "}" ]
Bind a resolver for the given type. @param type @param resolver
[ "Bind", "a", "resolver", "for", "the", "given", "type", "." ]
aa121b3a5504b43d0c10450a1b984694fcd2b8ee
https://github.com/LevelFourAB/commons/blob/aa121b3a5504b43d0c10450a1b984694fcd2b8ee/commons-serialization/src/main/java/se/l4/commons/serialization/spi/SerializerResolverRegistry.java#L66-L70
144,962
misha/iroh
src/main/java/com/github/msoliter/iroh/container/services/Injector.java
Injector.eagerlyInject
public void eagerlyInject(Object target, Field field) { /** * We only ever inject fields marked with the correct annotation. */ if (field.getAnnotation(Autowired.class) != null) { field.setAccessible(true); Autowired autowired = field.getAnnotation(Autowired.class); /** * If the field isn't marked for lazy injection, go ahead and inject * it immediately. Otherwise, nullify it with a local "null" * reference of the field's required type. */ if (autowired.lazy() == false) { inject(target, field); } else { nullify(target, field); } } }
java
public void eagerlyInject(Object target, Field field) { /** * We only ever inject fields marked with the correct annotation. */ if (field.getAnnotation(Autowired.class) != null) { field.setAccessible(true); Autowired autowired = field.getAnnotation(Autowired.class); /** * If the field isn't marked for lazy injection, go ahead and inject * it immediately. Otherwise, nullify it with a local "null" * reference of the field's required type. */ if (autowired.lazy() == false) { inject(target, field); } else { nullify(target, field); } } }
[ "public", "void", "eagerlyInject", "(", "Object", "target", ",", "Field", "field", ")", "{", "/**\n * We only ever inject fields marked with the correct annotation.\n */", "if", "(", "field", ".", "getAnnotation", "(", "Autowired", ".", "class", ")", "!=", "null", ")", "{", "field", ".", "setAccessible", "(", "true", ")", ";", "Autowired", "autowired", "=", "field", ".", "getAnnotation", "(", "Autowired", ".", "class", ")", ";", "/**\n * If the field isn't marked for lazy injection, go ahead and inject\n * it immediately. Otherwise, nullify it with a local \"null\"\n * reference of the field's required type.\n */", "if", "(", "autowired", ".", "lazy", "(", ")", "==", "false", ")", "{", "inject", "(", "target", ",", "field", ")", ";", "}", "else", "{", "nullify", "(", "target", ",", "field", ")", ";", "}", "}", "}" ]
Eagerly injects the target object's target field. Note that if the field is marked for lazy injection, we still inject it, but with a "null" reference. This reference is never seen by user code, and is used internally by Iroh to detect when eager injection has delegated the injection process to lazy injection, thus preventing multiple injection. @param target The target object containing the field to be injected. @param field The target field to be injected in the target object.
[ "Eagerly", "injects", "the", "target", "object", "s", "target", "field", ".", "Note", "that", "if", "the", "field", "is", "marked", "for", "lazy", "injection", "we", "still", "inject", "it", "but", "with", "a", "null", "reference", ".", "This", "reference", "is", "never", "seen", "by", "user", "code", "and", "is", "used", "internally", "by", "Iroh", "to", "detect", "when", "eager", "injection", "has", "delegated", "the", "injection", "process", "to", "lazy", "injection", "thus", "preventing", "multiple", "injection", "." ]
5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a
https://github.com/misha/iroh/blob/5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a/src/main/java/com/github/msoliter/iroh/container/services/Injector.java#L75-L96
144,963
misha/iroh
src/main/java/com/github/msoliter/iroh/container/services/Injector.java
Injector.lazilyInject
public void lazilyInject(Object target, Field field) { field.setAccessible(true); /** * We don't need to check for an * {@link com.github.msoliter.iroh.container.annotations.Autowired} * annotation because only those fields are capable of having a * reference to one of our local "null" references to begin with. * Directly checking if the object in the field and the null point to * the same location is sufficient for determining whether or not to * inject the field. */ if (isNullified(target, field)) { inject(target, field); } }
java
public void lazilyInject(Object target, Field field) { field.setAccessible(true); /** * We don't need to check for an * {@link com.github.msoliter.iroh.container.annotations.Autowired} * annotation because only those fields are capable of having a * reference to one of our local "null" references to begin with. * Directly checking if the object in the field and the null point to * the same location is sufficient for determining whether or not to * inject the field. */ if (isNullified(target, field)) { inject(target, field); } }
[ "public", "void", "lazilyInject", "(", "Object", "target", ",", "Field", "field", ")", "{", "field", ".", "setAccessible", "(", "true", ")", ";", "/**\n * We don't need to check for an \n * {@link com.github.msoliter.iroh.container.annotations.Autowired}\n * annotation because only those fields are capable of having a \n * reference to one of our local \"null\" references to begin with. \n * Directly checking if the object in the field and the null point to\n * the same location is sufficient for determining whether or not to\n * inject the field.\n */", "if", "(", "isNullified", "(", "target", ",", "field", ")", ")", "{", "inject", "(", "target", ",", "field", ")", ";", "}", "}" ]
Lazily injects the target object's target field. @param target The target object containing the field to be injected. @param field The target field to be injected in the target object.
[ "Lazily", "injects", "the", "target", "object", "s", "target", "field", "." ]
5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a
https://github.com/misha/iroh/blob/5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a/src/main/java/com/github/msoliter/iroh/container/services/Injector.java#L104-L119
144,964
misha/iroh
src/main/java/com/github/msoliter/iroh/container/services/Injector.java
Injector.inject
private void inject(Object target, Field field) { try { /** * Injection is actually quite a simple process. We resolve the * field into a source of instances, and ask it to generate one. */ field.set(target, registrar.resolve(field).getInstance()); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IrohException(e); } }
java
private void inject(Object target, Field field) { try { /** * Injection is actually quite a simple process. We resolve the * field into a source of instances, and ask it to generate one. */ field.set(target, registrar.resolve(field).getInstance()); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IrohException(e); } }
[ "private", "void", "inject", "(", "Object", "target", ",", "Field", "field", ")", "{", "try", "{", "/**\n * Injection is actually quite a simple process. We resolve the\n * field into a source of instances, and ask it to generate one.\n */", "field", ".", "set", "(", "target", ",", "registrar", ".", "resolve", "(", "field", ")", ".", "getInstance", "(", ")", ")", ";", "}", "catch", "(", "IllegalArgumentException", "|", "IllegalAccessException", "e", ")", "{", "throw", "new", "IrohException", "(", "e", ")", ";", "}", "}" ]
Performs the actual instance injection. @param target The target object containing the field to be injected. @param field The target field to be injected in the target object.
[ "Performs", "the", "actual", "instance", "injection", "." ]
5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a
https://github.com/misha/iroh/blob/5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a/src/main/java/com/github/msoliter/iroh/container/services/Injector.java#L127-L139
144,965
misha/iroh
src/main/java/com/github/msoliter/iroh/container/services/Injector.java
Injector.isNullified
private boolean isNullified(Object target, Field field) { Class<?> type = field.getType(); Object value = null; try { value = field.get(target); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IrohException(e); } if (nulls.containsKey(type)) { /** * Very purposefully compare the locations rather than their values, * since we totally cheated with Objenesis obtaining instances of * these local nulls. All hell would likely break loose if we tried * to use the methods defined in the actual objects... */ if (nulls.get(type) == value) { return true; } } return false; }
java
private boolean isNullified(Object target, Field field) { Class<?> type = field.getType(); Object value = null; try { value = field.get(target); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IrohException(e); } if (nulls.containsKey(type)) { /** * Very purposefully compare the locations rather than their values, * since we totally cheated with Objenesis obtaining instances of * these local nulls. All hell would likely break loose if we tried * to use the methods defined in the actual objects... */ if (nulls.get(type) == value) { return true; } } return false; }
[ "private", "boolean", "isNullified", "(", "Object", "target", ",", "Field", "field", ")", "{", "Class", "<", "?", ">", "type", "=", "field", ".", "getType", "(", ")", ";", "Object", "value", "=", "null", ";", "try", "{", "value", "=", "field", ".", "get", "(", "target", ")", ";", "}", "catch", "(", "IllegalArgumentException", "|", "IllegalAccessException", "e", ")", "{", "throw", "new", "IrohException", "(", "e", ")", ";", "}", "if", "(", "nulls", ".", "containsKey", "(", "type", ")", ")", "{", "/**\n * Very purposefully compare the locations rather than their values,\n * since we totally cheated with Objenesis obtaining instances of\n * these local nulls. All hell would likely break loose if we tried\n * to use the methods defined in the actual objects...\n */", "if", "(", "nulls", ".", "get", "(", "type", ")", "==", "value", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks whether or not the field value object's reference points to one of our local null object references. If so, this indicates that the field was nullified during eager injection, and is now eligible for lazy injection. @param target The target object containing the field to be checked. @param field The target field who object reference will be checked. @return True if the field's object reference is one of our local nulls, false otherwise.
[ "Checks", "whether", "or", "not", "the", "field", "value", "object", "s", "reference", "points", "to", "one", "of", "our", "local", "null", "object", "references", ".", "If", "so", "this", "indicates", "that", "the", "field", "was", "nullified", "during", "eager", "injection", "and", "is", "now", "eligible", "for", "lazy", "injection", "." ]
5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a
https://github.com/misha/iroh/blob/5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a/src/main/java/com/github/msoliter/iroh/container/services/Injector.java#L152-L177
144,966
misha/iroh
src/main/java/com/github/msoliter/iroh/container/services/Injector.java
Injector.nullify
private void nullify(Object target, Field field) { Class<?> type = field.getType(); if (!nulls.containsKey(type)) { nulls.put( type, objenesis.newInstance(registrar.resolve(field).getType())); } try { field.set(target, nulls.get(type)); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IrohException(e); } }
java
private void nullify(Object target, Field field) { Class<?> type = field.getType(); if (!nulls.containsKey(type)) { nulls.put( type, objenesis.newInstance(registrar.resolve(field).getType())); } try { field.set(target, nulls.get(type)); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IrohException(e); } }
[ "private", "void", "nullify", "(", "Object", "target", ",", "Field", "field", ")", "{", "Class", "<", "?", ">", "type", "=", "field", ".", "getType", "(", ")", ";", "if", "(", "!", "nulls", ".", "containsKey", "(", "type", ")", ")", "{", "nulls", ".", "put", "(", "type", ",", "objenesis", ".", "newInstance", "(", "registrar", ".", "resolve", "(", "field", ")", ".", "getType", "(", ")", ")", ")", ";", "}", "try", "{", "field", ".", "set", "(", "target", ",", "nulls", ".", "get", "(", "type", ")", ")", ";", "}", "catch", "(", "IllegalArgumentException", "|", "IllegalAccessException", "e", ")", "{", "throw", "new", "IrohException", "(", "e", ")", ";", "}", "}" ]
Implements lazy injection by filling in a "local null" instance of the type required by the field. The original idea was to just define a new location of null itself, but Java didn't like that very much, so now Iroh will generate a reference for every type it encounters to act as the null for fields of that particular type. @param target The target object containing the field to be nullified via injection with a local null generated with Objenesis. @param field The target field in the target object to be nullified.
[ "Implements", "lazy", "injection", "by", "filling", "in", "a", "local", "null", "instance", "of", "the", "type", "required", "by", "the", "field", ".", "The", "original", "idea", "was", "to", "just", "define", "a", "new", "location", "of", "null", "itself", "but", "Java", "didn", "t", "like", "that", "very", "much", "so", "now", "Iroh", "will", "generate", "a", "reference", "for", "every", "type", "it", "encounters", "to", "act", "as", "the", "null", "for", "fields", "of", "that", "particular", "type", "." ]
5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a
https://github.com/misha/iroh/blob/5dc92a01d3b2f3ba63e8ad1bf9b5fe342d0b679a/src/main/java/com/github/msoliter/iroh/container/services/Injector.java#L190-L205
144,967
cycorp/model-generator-suite
model-generator/src/main/java/com/cyc/model/objects/ModelConstants.java
ModelConstants.getInstance
public static ModelConstants getInstance() throws KbRuntimeException { try { if (instance == null) { instance = new ModelConstants(); } return instance; } catch (KbException e) { throw new KbRuntimeException( "Once of the private final fields in com.cyc.library.model.ModelConstants could not be instantiated, can not proceed further.", e); } }
java
public static ModelConstants getInstance() throws KbRuntimeException { try { if (instance == null) { instance = new ModelConstants(); } return instance; } catch (KbException e) { throw new KbRuntimeException( "Once of the private final fields in com.cyc.library.model.ModelConstants could not be instantiated, can not proceed further.", e); } }
[ "public", "static", "ModelConstants", "getInstance", "(", ")", "throws", "KbRuntimeException", "{", "try", "{", "if", "(", "instance", "==", "null", ")", "{", "instance", "=", "new", "ModelConstants", "(", ")", ";", "}", "return", "instance", ";", "}", "catch", "(", "KbException", "e", ")", "{", "throw", "new", "KbRuntimeException", "(", "\"Once of the private final fields in com.cyc.library.model.ModelConstants could not be instantiated, can not proceed further.\"", ",", "e", ")", ";", "}", "}" ]
This is not part of the KB API
[ "This", "is", "not", "part", "of", "the", "KB", "API" ]
8995984c5dcf668acad813d24e4fe9c544b7aa91
https://github.com/cycorp/model-generator-suite/blob/8995984c5dcf668acad813d24e4fe9c544b7aa91/model-generator/src/main/java/com/cyc/model/objects/ModelConstants.java#L53-L64
144,968
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.isAllowed
private boolean isAllowed(Field field) { return ClassUtils.isPrimitiveOrWrapper(field.getType()) || CharSequence.class.isAssignableFrom(field.getType()) || List.class.isAssignableFrom(field.getType()); }
java
private boolean isAllowed(Field field) { return ClassUtils.isPrimitiveOrWrapper(field.getType()) || CharSequence.class.isAssignableFrom(field.getType()) || List.class.isAssignableFrom(field.getType()); }
[ "private", "boolean", "isAllowed", "(", "Field", "field", ")", "{", "return", "ClassUtils", ".", "isPrimitiveOrWrapper", "(", "field", ".", "getType", "(", ")", ")", "||", "CharSequence", ".", "class", ".", "isAssignableFrom", "(", "field", ".", "getType", "(", ")", ")", "||", "List", ".", "class", ".", "isAssignableFrom", "(", "field", ".", "getType", "(", ")", ")", ";", "}" ]
Verifies if the given field follow the rules. @param field Field to be verified @return True if field is allowed and false otherwise.
[ "Verifies", "if", "the", "given", "field", "follow", "the", "rules", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L73-L77
144,969
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.evaluateObject
private void evaluateObject() { if (evaluatedClasses.contains(clazz)) { return; } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(ModelField.class) && !isAllowed(field)) { throw new RuntimeException("Field '" + field.getName() + "' has type '" + field.getType().getSimpleName() + "' that is not allowed!"); } } evaluatedClasses.add(clazz); }
java
private void evaluateObject() { if (evaluatedClasses.contains(clazz)) { return; } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(ModelField.class) && !isAllowed(field)) { throw new RuntimeException("Field '" + field.getName() + "' has type '" + field.getType().getSimpleName() + "' that is not allowed!"); } } evaluatedClasses.add(clazz); }
[ "private", "void", "evaluateObject", "(", ")", "{", "if", "(", "evaluatedClasses", ".", "contains", "(", "clazz", ")", ")", "{", "return", ";", "}", "Field", "[", "]", "fields", "=", "clazz", ".", "getDeclaredFields", "(", ")", ";", "for", "(", "Field", "field", ":", "fields", ")", "{", "if", "(", "field", ".", "isAnnotationPresent", "(", "ModelField", ".", "class", ")", "&&", "!", "isAllowed", "(", "field", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Field '\"", "+", "field", ".", "getName", "(", ")", "+", "\"' has type '\"", "+", "field", ".", "getType", "(", ")", ".", "getSimpleName", "(", ")", "+", "\"' that is not allowed!\"", ")", ";", "}", "}", "evaluatedClasses", ".", "add", "(", "clazz", ")", ";", "}" ]
Evaluates the object if not yet evaluated. @throws RuntimeException in case object don't follow the rules.
[ "Evaluates", "the", "object", "if", "not", "yet", "evaluated", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L84-L102
144,970
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.toFieldEnum
private static Fields toFieldEnum(Field field) { Class<?> clazz = field.getType(); String name = clazz.getSimpleName().toLowerCase(); if (name.equals("int") || name.equals("integer")) { return Fields.INT; } else if (name.equals("long")) { return Fields.LONG; } else if (name.equals("float")) { return Fields.FLOAT; } else if (name.equals("double")) { return Fields.DOUBLE; } else if (CharSequence.class.isAssignableFrom(clazz)) { return Fields.STRING; } else if (name.equals("boolean")) { return Fields.BOOLEAN; } else if (clazz.isAssignableFrom(List.class)) { ParameterizedType listType = (ParameterizedType) field.getGenericType(); Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0]; if (listClass.toString().equals("class java.lang.String")) { return Fields.LIST; } } throw new RuntimeException("Field not found!"); }
java
private static Fields toFieldEnum(Field field) { Class<?> clazz = field.getType(); String name = clazz.getSimpleName().toLowerCase(); if (name.equals("int") || name.equals("integer")) { return Fields.INT; } else if (name.equals("long")) { return Fields.LONG; } else if (name.equals("float")) { return Fields.FLOAT; } else if (name.equals("double")) { return Fields.DOUBLE; } else if (CharSequence.class.isAssignableFrom(clazz)) { return Fields.STRING; } else if (name.equals("boolean")) { return Fields.BOOLEAN; } else if (clazz.isAssignableFrom(List.class)) { ParameterizedType listType = (ParameterizedType) field.getGenericType(); Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0]; if (listClass.toString().equals("class java.lang.String")) { return Fields.LIST; } } throw new RuntimeException("Field not found!"); }
[ "private", "static", "Fields", "toFieldEnum", "(", "Field", "field", ")", "{", "Class", "<", "?", ">", "clazz", "=", "field", ".", "getType", "(", ")", ";", "String", "name", "=", "clazz", ".", "getSimpleName", "(", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "name", ".", "equals", "(", "\"int\"", ")", "||", "name", ".", "equals", "(", "\"integer\"", ")", ")", "{", "return", "Fields", ".", "INT", ";", "}", "else", "if", "(", "name", ".", "equals", "(", "\"long\"", ")", ")", "{", "return", "Fields", ".", "LONG", ";", "}", "else", "if", "(", "name", ".", "equals", "(", "\"float\"", ")", ")", "{", "return", "Fields", ".", "FLOAT", ";", "}", "else", "if", "(", "name", ".", "equals", "(", "\"double\"", ")", ")", "{", "return", "Fields", ".", "DOUBLE", ";", "}", "else", "if", "(", "CharSequence", ".", "class", ".", "isAssignableFrom", "(", "clazz", ")", ")", "{", "return", "Fields", ".", "STRING", ";", "}", "else", "if", "(", "name", ".", "equals", "(", "\"boolean\"", ")", ")", "{", "return", "Fields", ".", "BOOLEAN", ";", "}", "else", "if", "(", "clazz", ".", "isAssignableFrom", "(", "List", ".", "class", ")", ")", "{", "ParameterizedType", "listType", "=", "(", "ParameterizedType", ")", "field", ".", "getGenericType", "(", ")", ";", "Class", "<", "?", ">", "listClass", "=", "(", "Class", "<", "?", ">", ")", "listType", ".", "getActualTypeArguments", "(", ")", "[", "0", "]", ";", "if", "(", "listClass", ".", "toString", "(", ")", ".", "equals", "(", "\"class java.lang.String\"", ")", ")", "{", "return", "Fields", ".", "LIST", ";", "}", "}", "throw", "new", "RuntimeException", "(", "\"Field not found!\"", ")", ";", "}" ]
Return a Fields object for a given field's Class. @param field The class that will be used. @throws RuntimeException in case the field type is not found. @return A Fields type if found.
[ "Return", "a", "Fields", "object", "for", "a", "given", "field", "s", "Class", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L145-L171
144,971
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.fromJson
public T fromJson(JSONObject json) { T object = null; try { object = clazz.newInstance(); ((Model) object).setContext(context); Field[] fields = clazz.getDeclaredFields(); try { for (Field field : fields) { if (!field.isAnnotationPresent(ModelField.class)) { continue; } String name = field.getName(); boolean was = field.isAccessible(); field.setAccessible(true); switch (toFieldEnum(field)) { case INT: field.setInt(object, json.optInt(name, 0)); break; case LONG: field.setLong(object, json.optLong(name, 0)); break; case FLOAT: field.setFloat(object, json.optLong(name, 0)); break; case DOUBLE: field.setDouble(object, json.optDouble(name, 0)); break; case STRING: field.set(object, json.opt(name)); break; case BOOLEAN: field.setBoolean(object, json.optBoolean(name, false)); break; case LIST: JSONArray list = json.optJSONArray(name); try { if (list != null) { List<String> stringList = new ArrayList<>(); for (int i = 0; i < list.length(); i++) { stringList.add(list.getString(i)); } field.set(object, stringList); } } catch (JSONException e) { // TODO. } break; } field.setAccessible(was); } } catch (IllegalAccessException e) { e.printStackTrace(); } } catch (IllegalAccessException | InstantiationException e) { e.printStackTrace(); } return object; }
java
public T fromJson(JSONObject json) { T object = null; try { object = clazz.newInstance(); ((Model) object).setContext(context); Field[] fields = clazz.getDeclaredFields(); try { for (Field field : fields) { if (!field.isAnnotationPresent(ModelField.class)) { continue; } String name = field.getName(); boolean was = field.isAccessible(); field.setAccessible(true); switch (toFieldEnum(field)) { case INT: field.setInt(object, json.optInt(name, 0)); break; case LONG: field.setLong(object, json.optLong(name, 0)); break; case FLOAT: field.setFloat(object, json.optLong(name, 0)); break; case DOUBLE: field.setDouble(object, json.optDouble(name, 0)); break; case STRING: field.set(object, json.opt(name)); break; case BOOLEAN: field.setBoolean(object, json.optBoolean(name, false)); break; case LIST: JSONArray list = json.optJSONArray(name); try { if (list != null) { List<String> stringList = new ArrayList<>(); for (int i = 0; i < list.length(); i++) { stringList.add(list.getString(i)); } field.set(object, stringList); } } catch (JSONException e) { // TODO. } break; } field.setAccessible(was); } } catch (IllegalAccessException e) { e.printStackTrace(); } } catch (IllegalAccessException | InstantiationException e) { e.printStackTrace(); } return object; }
[ "public", "T", "fromJson", "(", "JSONObject", "json", ")", "{", "T", "object", "=", "null", ";", "try", "{", "object", "=", "clazz", ".", "newInstance", "(", ")", ";", "(", "(", "Model", ")", "object", ")", ".", "setContext", "(", "context", ")", ";", "Field", "[", "]", "fields", "=", "clazz", ".", "getDeclaredFields", "(", ")", ";", "try", "{", "for", "(", "Field", "field", ":", "fields", ")", "{", "if", "(", "!", "field", ".", "isAnnotationPresent", "(", "ModelField", ".", "class", ")", ")", "{", "continue", ";", "}", "String", "name", "=", "field", ".", "getName", "(", ")", ";", "boolean", "was", "=", "field", ".", "isAccessible", "(", ")", ";", "field", ".", "setAccessible", "(", "true", ")", ";", "switch", "(", "toFieldEnum", "(", "field", ")", ")", "{", "case", "INT", ":", "field", ".", "setInt", "(", "object", ",", "json", ".", "optInt", "(", "name", ",", "0", ")", ")", ";", "break", ";", "case", "LONG", ":", "field", ".", "setLong", "(", "object", ",", "json", ".", "optLong", "(", "name", ",", "0", ")", ")", ";", "break", ";", "case", "FLOAT", ":", "field", ".", "setFloat", "(", "object", ",", "json", ".", "optLong", "(", "name", ",", "0", ")", ")", ";", "break", ";", "case", "DOUBLE", ":", "field", ".", "setDouble", "(", "object", ",", "json", ".", "optDouble", "(", "name", ",", "0", ")", ")", ";", "break", ";", "case", "STRING", ":", "field", ".", "set", "(", "object", ",", "json", ".", "opt", "(", "name", ")", ")", ";", "break", ";", "case", "BOOLEAN", ":", "field", ".", "setBoolean", "(", "object", ",", "json", ".", "optBoolean", "(", "name", ",", "false", ")", ")", ";", "break", ";", "case", "LIST", ":", "JSONArray", "list", "=", "json", ".", "optJSONArray", "(", "name", ")", ";", "try", "{", "if", "(", "list", "!=", "null", ")", "{", "List", "<", "String", ">", "stringList", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "list", ".", "length", "(", ")", ";", "i", "++", ")", "{", "stringList", ".", "add", "(", "list", ".", "getString", "(", "i", ")", ")", ";", "}", "field", ".", "set", "(", "object", ",", "stringList", ")", ";", "}", "}", "catch", "(", "JSONException", "e", ")", "{", "// TODO.", "}", "break", ";", "}", "field", ".", "setAccessible", "(", "was", ")", ";", "}", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "catch", "(", "IllegalAccessException", "|", "InstantiationException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "object", ";", "}" ]
Analyzes the entire json object and creates a brand-new... instance from its representation. TODO: Figure out how to make this accesible without... creating a dummy instance. @param json The JSONObject representation of the object. @return The object T if able to convert and null otherwise.
[ "Analyzes", "the", "entire", "json", "object", "and", "creates", "a", "brand", "-", "new", "...", "instance", "from", "its", "representation", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L183-L254
144,972
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.toJson
public JSONObject toJson() { JSONObject json = new JSONObject(); Field[] fields = clazz.getDeclaredFields(); try { for (Field field : fields) { if (!field.isAnnotationPresent(ModelField.class)) { continue; } String name = field.getName(); boolean was = field.isAccessible(); field.setAccessible(true); switch (toFieldEnum(field)) { case INT: json.put(name, field.getInt(this)); break; case LONG: json.put(name, field.getLong(this)); break; case FLOAT: json.put(name, field.getFloat(this)); break; case DOUBLE: json.put(name, field.getDouble(this)); break; case STRING: json.put(name, field.get(this)); break; case BOOLEAN: json.put(name, field.getBoolean(this)); break; case LIST: JSONArray list = new JSONArray(); List<String> stringList = (List<String>) field.get(this); if (stringList != null) { for (String value : stringList) { list.put(value); } } json.put(name, list); break; } field.setAccessible(was); } } catch (IllegalAccessException | JSONException e) { e.printStackTrace(); } return json; }
java
public JSONObject toJson() { JSONObject json = new JSONObject(); Field[] fields = clazz.getDeclaredFields(); try { for (Field field : fields) { if (!field.isAnnotationPresent(ModelField.class)) { continue; } String name = field.getName(); boolean was = field.isAccessible(); field.setAccessible(true); switch (toFieldEnum(field)) { case INT: json.put(name, field.getInt(this)); break; case LONG: json.put(name, field.getLong(this)); break; case FLOAT: json.put(name, field.getFloat(this)); break; case DOUBLE: json.put(name, field.getDouble(this)); break; case STRING: json.put(name, field.get(this)); break; case BOOLEAN: json.put(name, field.getBoolean(this)); break; case LIST: JSONArray list = new JSONArray(); List<String> stringList = (List<String>) field.get(this); if (stringList != null) { for (String value : stringList) { list.put(value); } } json.put(name, list); break; } field.setAccessible(was); } } catch (IllegalAccessException | JSONException e) { e.printStackTrace(); } return json; }
[ "public", "JSONObject", "toJson", "(", ")", "{", "JSONObject", "json", "=", "new", "JSONObject", "(", ")", ";", "Field", "[", "]", "fields", "=", "clazz", ".", "getDeclaredFields", "(", ")", ";", "try", "{", "for", "(", "Field", "field", ":", "fields", ")", "{", "if", "(", "!", "field", ".", "isAnnotationPresent", "(", "ModelField", ".", "class", ")", ")", "{", "continue", ";", "}", "String", "name", "=", "field", ".", "getName", "(", ")", ";", "boolean", "was", "=", "field", ".", "isAccessible", "(", ")", ";", "field", ".", "setAccessible", "(", "true", ")", ";", "switch", "(", "toFieldEnum", "(", "field", ")", ")", "{", "case", "INT", ":", "json", ".", "put", "(", "name", ",", "field", ".", "getInt", "(", "this", ")", ")", ";", "break", ";", "case", "LONG", ":", "json", ".", "put", "(", "name", ",", "field", ".", "getLong", "(", "this", ")", ")", ";", "break", ";", "case", "FLOAT", ":", "json", ".", "put", "(", "name", ",", "field", ".", "getFloat", "(", "this", ")", ")", ";", "break", ";", "case", "DOUBLE", ":", "json", ".", "put", "(", "name", ",", "field", ".", "getDouble", "(", "this", ")", ")", ";", "break", ";", "case", "STRING", ":", "json", ".", "put", "(", "name", ",", "field", ".", "get", "(", "this", ")", ")", ";", "break", ";", "case", "BOOLEAN", ":", "json", ".", "put", "(", "name", ",", "field", ".", "getBoolean", "(", "this", ")", ")", ";", "break", ";", "case", "LIST", ":", "JSONArray", "list", "=", "new", "JSONArray", "(", ")", ";", "List", "<", "String", ">", "stringList", "=", "(", "List", "<", "String", ">", ")", "field", ".", "get", "(", "this", ")", ";", "if", "(", "stringList", "!=", "null", ")", "{", "for", "(", "String", "value", ":", "stringList", ")", "{", "list", ".", "put", "(", "value", ")", ";", "}", "}", "json", ".", "put", "(", "name", ",", "list", ")", ";", "break", ";", "}", "field", ".", "setAccessible", "(", "was", ")", ";", "}", "}", "catch", "(", "IllegalAccessException", "|", "JSONException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "json", ";", "}" ]
Analyzes the entire object and creates a brand-new json... representation. @return The JSONObject representation of the object.
[ "Analyzes", "the", "entire", "object", "and", "creates", "a", "brand", "-", "new", "json", "...", "representation", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L262-L319
144,973
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.loadSharedPreferences
protected SharedPreferences loadSharedPreferences(String namespace) { if (context == null) { throw new NoContextFoundException(); } return context.getSharedPreferences(clazz.getPackage().getName() + "." + clazz.getName() + "." + namespace, Context.MODE_PRIVATE); }
java
protected SharedPreferences loadSharedPreferences(String namespace) { if (context == null) { throw new NoContextFoundException(); } return context.getSharedPreferences(clazz.getPackage().getName() + "." + clazz.getName() + "." + namespace, Context.MODE_PRIVATE); }
[ "protected", "SharedPreferences", "loadSharedPreferences", "(", "String", "namespace", ")", "{", "if", "(", "context", "==", "null", ")", "{", "throw", "new", "NoContextFoundException", "(", ")", ";", "}", "return", "context", ".", "getSharedPreferences", "(", "clazz", ".", "getPackage", "(", ")", ".", "getName", "(", ")", "+", "\".\"", "+", "clazz", ".", "getName", "(", ")", "+", "\".\"", "+", "namespace", ",", "Context", ".", "MODE_PRIVATE", ")", ";", "}" ]
Loads a reference to the SharedPreferences for a given... namespace. @param namespace The namespace to be used. @return The sharedPreferences object. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Loads", "a", "reference", "to", "the", "SharedPreferences", "for", "a", "given", "...", "namespace", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L349-L357
144,974
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.getObjectList
private List<String> getObjectList() { if (cachedIds != null) return cachedIds; SharedPreferences prefs = loadSharedPreferences("objectList"); String list = prefs.getString("list", null); cachedIds = (list == null) ? new ArrayList<String>() : new ArrayList<>(Arrays.asList(list.split(","))); return cachedIds; }
java
private List<String> getObjectList() { if (cachedIds != null) return cachedIds; SharedPreferences prefs = loadSharedPreferences("objectList"); String list = prefs.getString("list", null); cachedIds = (list == null) ? new ArrayList<String>() : new ArrayList<>(Arrays.asList(list.split(","))); return cachedIds; }
[ "private", "List", "<", "String", ">", "getObjectList", "(", ")", "{", "if", "(", "cachedIds", "!=", "null", ")", "return", "cachedIds", ";", "SharedPreferences", "prefs", "=", "loadSharedPreferences", "(", "\"objectList\"", ")", ";", "String", "list", "=", "prefs", ".", "getString", "(", "\"list\"", ",", "null", ")", ";", "cachedIds", "=", "(", "list", "==", "null", ")", "?", "new", "ArrayList", "<", "String", ">", "(", ")", ":", "new", "ArrayList", "<>", "(", "Arrays", ".", "asList", "(", "list", ".", "split", "(", "\",\"", ")", ")", ")", ";", "return", "cachedIds", ";", "}" ]
Get a list of objects ids. @return The list of all object ids. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Get", "a", "list", "of", "objects", "ids", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L365-L374
144,975
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.addObject
private void addObject() { SharedPreferences prefs = loadSharedPreferences("objectList"); List<String> objects = getObjectList(); objects.add(getId()); prefs.edit().putString("list", StringUtils.join(objects, ",")).commit(); }
java
private void addObject() { SharedPreferences prefs = loadSharedPreferences("objectList"); List<String> objects = getObjectList(); objects.add(getId()); prefs.edit().putString("list", StringUtils.join(objects, ",")).commit(); }
[ "private", "void", "addObject", "(", ")", "{", "SharedPreferences", "prefs", "=", "loadSharedPreferences", "(", "\"objectList\"", ")", ";", "List", "<", "String", ">", "objects", "=", "getObjectList", "(", ")", ";", "objects", ".", "add", "(", "getId", "(", ")", ")", ";", "prefs", ".", "edit", "(", ")", ".", "putString", "(", "\"list\"", ",", "StringUtils", ".", "join", "(", "objects", ",", "\",\"", ")", ")", ".", "commit", "(", ")", ";", "}" ]
Adds the object to the ids list. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Adds", "the", "object", "to", "the", "ids", "list", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L381-L388
144,976
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.removeObject
private boolean removeObject() { SharedPreferences prefs = loadSharedPreferences("objectList"); List<String> objects = getObjectList(); int index = objects.indexOf(getId()); if (index == ArrayUtils.INDEX_NOT_FOUND) return false; objects.remove(getId()); if (objects.size() == 0) { prefs.edit().putString("list", null).commit(); } else { prefs.edit().putString("list", StringUtils.join(objects, ",")).commit(); } return true; }
java
private boolean removeObject() { SharedPreferences prefs = loadSharedPreferences("objectList"); List<String> objects = getObjectList(); int index = objects.indexOf(getId()); if (index == ArrayUtils.INDEX_NOT_FOUND) return false; objects.remove(getId()); if (objects.size() == 0) { prefs.edit().putString("list", null).commit(); } else { prefs.edit().putString("list", StringUtils.join(objects, ",")).commit(); } return true; }
[ "private", "boolean", "removeObject", "(", ")", "{", "SharedPreferences", "prefs", "=", "loadSharedPreferences", "(", "\"objectList\"", ")", ";", "List", "<", "String", ">", "objects", "=", "getObjectList", "(", ")", ";", "int", "index", "=", "objects", ".", "indexOf", "(", "getId", "(", ")", ")", ";", "if", "(", "index", "==", "ArrayUtils", ".", "INDEX_NOT_FOUND", ")", "return", "false", ";", "objects", ".", "remove", "(", "getId", "(", ")", ")", ";", "if", "(", "objects", ".", "size", "(", ")", "==", "0", ")", "{", "prefs", ".", "edit", "(", ")", ".", "putString", "(", "\"list\"", ",", "null", ")", ".", "commit", "(", ")", ";", "}", "else", "{", "prefs", ".", "edit", "(", ")", ".", "putString", "(", "\"list\"", ",", "StringUtils", ".", "join", "(", "objects", ",", "\",\"", ")", ")", ".", "commit", "(", ")", ";", "}", "return", "true", ";", "}" ]
Removes the object from the ids list. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context. @return True if removed successfully and false otherwise.
[ "Removes", "the", "object", "from", "the", "ids", "list", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L396-L414
144,977
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.save
public synchronized void save() { SharedPreferences prefs = loadSharedPreferences("object"); if (find(getId()) == null) { addObject(); modelListenerHandler.execOnUpdateListeners(this, OnUpdateListener.Status.CREATED); if (cache && cachedObjects != null) { cachedObjects.add((T) this); } } else { modelListenerHandler.execOnUpdateListeners(this, OnUpdateListener.Status.UPDATED); } prefs.edit().putString(String.valueOf(getId()), toJson().toString()).commit(); }
java
public synchronized void save() { SharedPreferences prefs = loadSharedPreferences("object"); if (find(getId()) == null) { addObject(); modelListenerHandler.execOnUpdateListeners(this, OnUpdateListener.Status.CREATED); if (cache && cachedObjects != null) { cachedObjects.add((T) this); } } else { modelListenerHandler.execOnUpdateListeners(this, OnUpdateListener.Status.UPDATED); } prefs.edit().putString(String.valueOf(getId()), toJson().toString()).commit(); }
[ "public", "synchronized", "void", "save", "(", ")", "{", "SharedPreferences", "prefs", "=", "loadSharedPreferences", "(", "\"object\"", ")", ";", "if", "(", "find", "(", "getId", "(", ")", ")", "==", "null", ")", "{", "addObject", "(", ")", ";", "modelListenerHandler", ".", "execOnUpdateListeners", "(", "this", ",", "OnUpdateListener", ".", "Status", ".", "CREATED", ")", ";", "if", "(", "cache", "&&", "cachedObjects", "!=", "null", ")", "{", "cachedObjects", ".", "add", "(", "(", "T", ")", "this", ")", ";", "}", "}", "else", "{", "modelListenerHandler", ".", "execOnUpdateListeners", "(", "this", ",", "OnUpdateListener", ".", "Status", ".", "UPDATED", ")", ";", "}", "prefs", ".", "edit", "(", ")", ".", "putString", "(", "String", ".", "valueOf", "(", "getId", "(", ")", ")", ",", "toJson", "(", ")", ".", "toString", "(", ")", ")", ".", "commit", "(", ")", ";", "}" ]
Saves the current object. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Saves", "the", "current", "object", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L421-L437
144,978
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.remove
public synchronized boolean remove() { SharedPreferences prefs = loadSharedPreferences("object"); if (find(getId()) != null) { if (!removeObject()) return false; modelListenerHandler.execOnUpdateListeners(this, OnUpdateListener.Status.REMOVED); prefs.edit().putString(String.valueOf(getId()), null).commit(); return true; } return false; }
java
public synchronized boolean remove() { SharedPreferences prefs = loadSharedPreferences("object"); if (find(getId()) != null) { if (!removeObject()) return false; modelListenerHandler.execOnUpdateListeners(this, OnUpdateListener.Status.REMOVED); prefs.edit().putString(String.valueOf(getId()), null).commit(); return true; } return false; }
[ "public", "synchronized", "boolean", "remove", "(", ")", "{", "SharedPreferences", "prefs", "=", "loadSharedPreferences", "(", "\"object\"", ")", ";", "if", "(", "find", "(", "getId", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "!", "removeObject", "(", ")", ")", "return", "false", ";", "modelListenerHandler", ".", "execOnUpdateListeners", "(", "this", ",", "OnUpdateListener", ".", "Status", ".", "REMOVED", ")", ";", "prefs", ".", "edit", "(", ")", ".", "putString", "(", "String", ".", "valueOf", "(", "getId", "(", ")", ")", ",", "null", ")", ".", "commit", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Removes the current object. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Removes", "the", "current", "object", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L444-L458
144,979
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.find
public T find(String id) { SharedPreferences prefs = loadSharedPreferences("object"); JSONObject object = null; try { String json = prefs.getString(String.valueOf(id), null); if (json == null) return null; object = new JSONObject(json); } catch (JSONException e) { e.printStackTrace(); } return fromJson(object); }
java
public T find(String id) { SharedPreferences prefs = loadSharedPreferences("object"); JSONObject object = null; try { String json = prefs.getString(String.valueOf(id), null); if (json == null) return null; object = new JSONObject(json); } catch (JSONException e) { e.printStackTrace(); } return fromJson(object); }
[ "public", "T", "find", "(", "String", "id", ")", "{", "SharedPreferences", "prefs", "=", "loadSharedPreferences", "(", "\"object\"", ")", ";", "JSONObject", "object", "=", "null", ";", "try", "{", "String", "json", "=", "prefs", ".", "getString", "(", "String", ".", "valueOf", "(", "id", ")", ",", "null", ")", ";", "if", "(", "json", "==", "null", ")", "return", "null", ";", "object", "=", "new", "JSONObject", "(", "json", ")", ";", "}", "catch", "(", "JSONException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "fromJson", "(", "object", ")", ";", "}" ]
Find a specific object from its id. TODO: Figure out how to make this accesible without... creating a dummy instance. @param id Object's id. @return The object if found, null otherwise. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Find", "a", "specific", "object", "from", "its", "id", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L470-L487
144,980
mauriciogior/android-easy-db
src/main/java/com/mauriciogiordano/easydb/bean/Model.java
Model.findAll
public List<T> findAll() { if (cache && cachedObjects != null) { return cachedObjects; } List<String> ids = getObjectList(); List<T> listT = new ArrayList<>(); for (String id : ids) { listT.add(find(id)); } if (cache) { cachedObjects = listT; } return listT; }
java
public List<T> findAll() { if (cache && cachedObjects != null) { return cachedObjects; } List<String> ids = getObjectList(); List<T> listT = new ArrayList<>(); for (String id : ids) { listT.add(find(id)); } if (cache) { cachedObjects = listT; } return listT; }
[ "public", "List", "<", "T", ">", "findAll", "(", ")", "{", "if", "(", "cache", "&&", "cachedObjects", "!=", "null", ")", "{", "return", "cachedObjects", ";", "}", "List", "<", "String", ">", "ids", "=", "getObjectList", "(", ")", ";", "List", "<", "T", ">", "listT", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "String", "id", ":", "ids", ")", "{", "listT", ".", "add", "(", "find", "(", "id", ")", ")", ";", "}", "if", "(", "cache", ")", "{", "cachedObjects", "=", "listT", ";", "}", "return", "listT", ";", "}" ]
Find all objects of type T. TODO: Add offset. @return A list of all objects on the database. @throws com.mauriciogiordano.easydb.exception.NoContextFoundException in case of null context.
[ "Find", "all", "objects", "of", "type", "T", "." ]
2284524ed2ab3678a3a87b2dbe62e4402a876049
https://github.com/mauriciogior/android-easy-db/blob/2284524ed2ab3678a3a87b2dbe62e4402a876049/src/main/java/com/mauriciogiordano/easydb/bean/Model.java#L497-L515
144,981
dbracewell/mango
src/main/java/com/davidbracewell/cli/CommandLineParser.java
CommandLineParser.showHelp
public void showHelp() { System.err.println(applicationDescription); System.err.println("==============================================="); Map<NamedOption, String> optionNames = new HashMap<>(); optionSet.forEach(option -> { String out = Stream.concat( Stream.of(option.getAliasSpecifications()), Stream.of(option.getSpecification())) .sorted((s1, s2) -> Integer.compare(s1.length(), s2.length())) .collect(Collectors.joining(", ")); if (option.isRequired()) { out += " *"; } optionNames.put(option, out); }); int maxArgName = optionNames.values().stream().mapToInt(String::length).max().orElse(10); optionNames.entrySet().stream() .sorted(Map.Entry.comparingByValue()) .forEach(entry -> { String arg = entry.getValue(); boolean insertSpace = !arg.startsWith("--"); if (insertSpace) { System.err.print(" "); } System.err.printf("%1$-" + maxArgName + "s\t", arg); System.err.println(entry.getKey().getDescription()); }); System.err.println("==============================================="); System.err.println("* = Required"); }
java
public void showHelp() { System.err.println(applicationDescription); System.err.println("==============================================="); Map<NamedOption, String> optionNames = new HashMap<>(); optionSet.forEach(option -> { String out = Stream.concat( Stream.of(option.getAliasSpecifications()), Stream.of(option.getSpecification())) .sorted((s1, s2) -> Integer.compare(s1.length(), s2.length())) .collect(Collectors.joining(", ")); if (option.isRequired()) { out += " *"; } optionNames.put(option, out); }); int maxArgName = optionNames.values().stream().mapToInt(String::length).max().orElse(10); optionNames.entrySet().stream() .sorted(Map.Entry.comparingByValue()) .forEach(entry -> { String arg = entry.getValue(); boolean insertSpace = !arg.startsWith("--"); if (insertSpace) { System.err.print(" "); } System.err.printf("%1$-" + maxArgName + "s\t", arg); System.err.println(entry.getKey().getDescription()); }); System.err.println("==============================================="); System.err.println("* = Required"); }
[ "public", "void", "showHelp", "(", ")", "{", "System", ".", "err", ".", "println", "(", "applicationDescription", ")", ";", "System", ".", "err", ".", "println", "(", "\"===============================================\"", ")", ";", "Map", "<", "NamedOption", ",", "String", ">", "optionNames", "=", "new", "HashMap", "<>", "(", ")", ";", "optionSet", ".", "forEach", "(", "option", "->", "{", "String", "out", "=", "Stream", ".", "concat", "(", "Stream", ".", "of", "(", "option", ".", "getAliasSpecifications", "(", ")", ")", ",", "Stream", ".", "of", "(", "option", ".", "getSpecification", "(", ")", ")", ")", ".", "sorted", "(", "(", "s1", ",", "s2", ")", "->", "Integer", ".", "compare", "(", "s1", ".", "length", "(", ")", ",", "s2", ".", "length", "(", ")", ")", ")", ".", "collect", "(", "Collectors", ".", "joining", "(", "\", \"", ")", ")", ";", "if", "(", "option", ".", "isRequired", "(", ")", ")", "{", "out", "+=", "\" *\"", ";", "}", "optionNames", ".", "put", "(", "option", ",", "out", ")", ";", "}", ")", ";", "int", "maxArgName", "=", "optionNames", ".", "values", "(", ")", ".", "stream", "(", ")", ".", "mapToInt", "(", "String", "::", "length", ")", ".", "max", "(", ")", ".", "orElse", "(", "10", ")", ";", "optionNames", ".", "entrySet", "(", ")", ".", "stream", "(", ")", ".", "sorted", "(", "Map", ".", "Entry", ".", "comparingByValue", "(", ")", ")", ".", "forEach", "(", "entry", "->", "{", "String", "arg", "=", "entry", ".", "getValue", "(", ")", ";", "boolean", "insertSpace", "=", "!", "arg", ".", "startsWith", "(", "\"--\"", ")", ";", "if", "(", "insertSpace", ")", "{", "System", ".", "err", ".", "print", "(", "\" \"", ")", ";", "}", "System", ".", "err", ".", "printf", "(", "\"%1$-\"", "+", "maxArgName", "+", "\"s\\t\"", ",", "arg", ")", ";", "System", ".", "err", ".", "println", "(", "entry", ".", "getKey", "(", ")", ".", "getDescription", "(", ")", ")", ";", "}", ")", ";", "System", ".", "err", ".", "println", "(", "\"===============================================\"", ")", ";", "System", ".", "err", ".", "println", "(", "\"* = Required\"", ")", ";", "}" ]
Prints help to standard error showing the application description, if set, and the list of valid command line arguments with those required arguments marked with an asterisk.
[ "Prints", "help", "to", "standard", "error", "showing", "the", "application", "description", "if", "set", "and", "the", "list", "of", "valid", "command", "line", "arguments", "with", "those", "required", "arguments", "marked", "with", "an", "asterisk", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/cli/CommandLineParser.java#L238-L272
144,982
dbracewell/mango
src/main/java/com/davidbracewell/cli/CommandLineParser.java
CommandLineParser.getSetEntries
public Set<Map.Entry<String, String>> getSetEntries() { Set<Map.Entry<String, String>> entries = optionSet.stream() .filter(this::isSet) .map(no -> Tuple2.of(no.getName(), Convert.convert(no.getValue(), String.class))) .collect(Collectors.toSet()); entries.addAll(unamedOptions.entrySet()); return entries; }
java
public Set<Map.Entry<String, String>> getSetEntries() { Set<Map.Entry<String, String>> entries = optionSet.stream() .filter(this::isSet) .map(no -> Tuple2.of(no.getName(), Convert.convert(no.getValue(), String.class))) .collect(Collectors.toSet()); entries.addAll(unamedOptions.entrySet()); return entries; }
[ "public", "Set", "<", "Map", ".", "Entry", "<", "String", ",", "String", ">", ">", "getSetEntries", "(", ")", "{", "Set", "<", "Map", ".", "Entry", "<", "String", ",", "String", ">", ">", "entries", "=", "optionSet", ".", "stream", "(", ")", ".", "filter", "(", "this", "::", "isSet", ")", ".", "map", "(", "no", "->", "Tuple2", ".", "of", "(", "no", ".", "getName", "(", ")", ",", "Convert", ".", "convert", "(", "no", ".", "getValue", "(", ")", ",", "String", ".", "class", ")", ")", ")", ".", "collect", "(", "Collectors", ".", "toSet", "(", ")", ")", ";", "entries", ".", "addAll", "(", "unamedOptions", ".", "entrySet", "(", ")", ")", ";", "return", "entries", ";", "}" ]
Gets options and values for everything passed in to the command line including unamed options. @return An <code>Map.Entry</code> of options and values for everything passed in to the command line including unamed options.
[ "Gets", "options", "and", "values", "for", "everything", "passed", "in", "to", "the", "command", "line", "including", "unamed", "options", "." ]
2cec08826f1fccd658694dd03abce10fc97618ec
https://github.com/dbracewell/mango/blob/2cec08826f1fccd658694dd03abce10fc97618ec/src/main/java/com/davidbracewell/cli/CommandLineParser.java#L383-L392
144,983
gdfm/shobai-dogu
src/main/java/com/github/gdfm/shobaidogu/IOUtils.java
IOUtils.readStopwords
public static Set<String> readStopwords(BufferedReader reader) throws IOException { HashSet<String> words = new HashSet<String>(); String nextLine; while (((nextLine = reader.readLine()) != null)) { words.add(nextLine.trim().toLowerCase()); } return words; }
java
public static Set<String> readStopwords(BufferedReader reader) throws IOException { HashSet<String> words = new HashSet<String>(); String nextLine; while (((nextLine = reader.readLine()) != null)) { words.add(nextLine.trim().toLowerCase()); } return words; }
[ "public", "static", "Set", "<", "String", ">", "readStopwords", "(", "BufferedReader", "reader", ")", "throws", "IOException", "{", "HashSet", "<", "String", ">", "words", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "String", "nextLine", ";", "while", "(", "(", "(", "nextLine", "=", "reader", ".", "readLine", "(", ")", ")", "!=", "null", ")", ")", "{", "words", ".", "add", "(", "nextLine", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", ")", ";", "}", "return", "words", ";", "}" ]
Read stopwords in memory from a file, one per line. Stopwords are converted to lowercase when read. @param reader the input reader. @return a set of stopwords. @throws IOException
[ "Read", "stopwords", "in", "memory", "from", "a", "file", "one", "per", "line", ".", "Stopwords", "are", "converted", "to", "lowercase", "when", "read", "." ]
2de6bd1afb870ede2e4f75f1ae82c85745367dd9
https://github.com/gdfm/shobai-dogu/blob/2de6bd1afb870ede2e4f75f1ae82c85745367dd9/src/main/java/com/github/gdfm/shobaidogu/IOUtils.java#L76-L83
144,984
gdfm/shobai-dogu
src/main/java/com/github/gdfm/shobaidogu/IOUtils.java
IOUtils.readIdfs
public static Map<String, Double> readIdfs(BufferedReader reader, int N) throws IOException { HashMap<String, Double> idfs = new HashMap<String, Double>(); String nextLine; while (((nextLine = reader.readLine()) != null)) { String[] parts = nextLine.split("\\t+"); checkArgument(parts.length >= 2); Double df = Double.parseDouble(parts[1]); idfs.put(parts[0], Math.log(1.0 + N / df)); // idf } return idfs; }
java
public static Map<String, Double> readIdfs(BufferedReader reader, int N) throws IOException { HashMap<String, Double> idfs = new HashMap<String, Double>(); String nextLine; while (((nextLine = reader.readLine()) != null)) { String[] parts = nextLine.split("\\t+"); checkArgument(parts.length >= 2); Double df = Double.parseDouble(parts[1]); idfs.put(parts[0], Math.log(1.0 + N / df)); // idf } return idfs; }
[ "public", "static", "Map", "<", "String", ",", "Double", ">", "readIdfs", "(", "BufferedReader", "reader", ",", "int", "N", ")", "throws", "IOException", "{", "HashMap", "<", "String", ",", "Double", ">", "idfs", "=", "new", "HashMap", "<", "String", ",", "Double", ">", "(", ")", ";", "String", "nextLine", ";", "while", "(", "(", "(", "nextLine", "=", "reader", ".", "readLine", "(", ")", ")", "!=", "null", ")", ")", "{", "String", "[", "]", "parts", "=", "nextLine", ".", "split", "(", "\"\\\\t+\"", ")", ";", "checkArgument", "(", "parts", ".", "length", ">=", "2", ")", ";", "Double", "df", "=", "Double", ".", "parseDouble", "(", "parts", "[", "1", "]", ")", ";", "idfs", ".", "put", "(", "parts", "[", "0", "]", ",", "Math", ".", "log", "(", "1.0", "+", "N", "/", "df", ")", ")", ";", "// idf", "}", "return", "idfs", ";", "}" ]
Computes inverse document frequencies as a map of Strings to Doubles from a tab separated file of term document frequencies. @param reader the input reader. @param N the number of documents in the collection. @return the inverse document frequencies. @throws IOException
[ "Computes", "inverse", "document", "frequencies", "as", "a", "map", "of", "Strings", "to", "Doubles", "from", "a", "tab", "separated", "file", "of", "term", "document", "frequencies", "." ]
2de6bd1afb870ede2e4f75f1ae82c85745367dd9
https://github.com/gdfm/shobai-dogu/blob/2de6bd1afb870ede2e4f75f1ae82c85745367dd9/src/main/java/com/github/gdfm/shobaidogu/IOUtils.java#L96-L106
144,985
gdfm/shobai-dogu
src/main/java/com/github/gdfm/shobaidogu/IOUtils.java
IOUtils.getNumberOfLines
public static int getNumberOfLines(Reader in) throws IOException { LineNumberReader lnr = new LineNumberReader(in); lnr.skip(Long.MAX_VALUE); in.close(); return lnr.getLineNumber(); }
java
public static int getNumberOfLines(Reader in) throws IOException { LineNumberReader lnr = new LineNumberReader(in); lnr.skip(Long.MAX_VALUE); in.close(); return lnr.getLineNumber(); }
[ "public", "static", "int", "getNumberOfLines", "(", "Reader", "in", ")", "throws", "IOException", "{", "LineNumberReader", "lnr", "=", "new", "LineNumberReader", "(", "in", ")", ";", "lnr", ".", "skip", "(", "Long", ".", "MAX_VALUE", ")", ";", "in", ".", "close", "(", ")", ";", "return", "lnr", ".", "getLineNumber", "(", ")", ";", "}" ]
Computes the number of files in the input Reader. @param in the reader. @return the number of lines. @throws IOException
[ "Computes", "the", "number", "of", "files", "in", "the", "input", "Reader", "." ]
2de6bd1afb870ede2e4f75f1ae82c85745367dd9
https://github.com/gdfm/shobai-dogu/blob/2de6bd1afb870ede2e4f75f1ae82c85745367dd9/src/main/java/com/github/gdfm/shobaidogu/IOUtils.java#L116-L121
144,986
gsi-upm/Shanks
shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java
ShanksAgentPerceptionCapability.getDistanceTo
public static double getDistanceTo(ShanksSimulation simulation, PercipientShanksAgent agent, Object o) { Location agentLocation = agent.getCurrentLocation(); if (agentLocation.is3DLocation()) { try { ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Double3D objectLocation = devicesField .getObjectLocationAsDouble3D(o); return agentLocation.getLocation3D().distance(objectLocation); } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } if (agentLocation.is2DLocation()) { try { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Double2D objectLocation = devicesField.getObjectLocation(o); return agentLocation.getLocation2D().distance(objectLocation); } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } return Double.MAX_VALUE; }
java
public static double getDistanceTo(ShanksSimulation simulation, PercipientShanksAgent agent, Object o) { Location agentLocation = agent.getCurrentLocation(); if (agentLocation.is3DLocation()) { try { ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Double3D objectLocation = devicesField .getObjectLocationAsDouble3D(o); return agentLocation.getLocation3D().distance(objectLocation); } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } if (agentLocation.is2DLocation()) { try { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Double2D objectLocation = devicesField.getObjectLocation(o); return agentLocation.getLocation2D().distance(objectLocation); } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } return Double.MAX_VALUE; }
[ "public", "static", "double", "getDistanceTo", "(", "ShanksSimulation", "simulation", ",", "PercipientShanksAgent", "agent", ",", "Object", "o", ")", "{", "Location", "agentLocation", "=", "agent", ".", "getCurrentLocation", "(", ")", ";", "if", "(", "agentLocation", ".", "is3DLocation", "(", ")", ")", "{", "try", "{", "ContinuousPortrayal3D", "devicesPortrayal", "=", "(", "ContinuousPortrayal3D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario3DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous3D", "devicesField", "=", "(", "Continuous3D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Double3D", "objectLocation", "=", "devicesField", ".", "getObjectLocationAsDouble3D", "(", "o", ")", ";", "return", "agentLocation", ".", "getLocation3D", "(", ")", ".", "distance", "(", "objectLocation", ")", ";", "}", "catch", "(", "DuplicatedPortrayalIDException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ScenarioNotFoundException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ShanksException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "if", "(", "agentLocation", ".", "is2DLocation", "(", ")", ")", "{", "try", "{", "ContinuousPortrayal2D", "devicesPortrayal", "=", "(", "ContinuousPortrayal2D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario2DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous2D", "devicesField", "=", "(", "Continuous2D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Double2D", "objectLocation", "=", "devicesField", ".", "getObjectLocation", "(", "o", ")", ";", "return", "agentLocation", ".", "getLocation2D", "(", ")", ".", "distance", "(", "objectLocation", ")", ";", "}", "catch", "(", "DuplicatedPortrayalIDException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ScenarioNotFoundException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ShanksException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "return", "Double", ".", "MAX_VALUE", ";", "}" ]
Get the distance from the agent to an object in the simulation @param simulation @param agent @param o object to measure the distance between the agent and the object @return the distance
[ "Get", "the", "distance", "from", "the", "agent", "to", "an", "object", "in", "the", "simulation" ]
35d87a81c22731f4f83bbd0571c9c6d466bd16be
https://github.com/gsi-upm/Shanks/blob/35d87a81c22731f4f83bbd0571c9c6d466bd16be/shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java#L113-L154
144,987
gsi-upm/Shanks
shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java
ShanksAgentPerceptionCapability.getObjectLocation
public static Location getObjectLocation(ShanksSimulation simulation, PercipientShanksAgent agent, Object object) { try { if (agent.getCurrentLocation().is3DLocation()) { ContinuousPortrayal3D devicesPortrayal; devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Double3D loc = devicesField.getObjectLocation(object); return new Location(loc); } else if (agent.getCurrentLocation().is2DLocation()) { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Double2D loc = devicesField.getObjectLocation(object); return new Location(loc); } } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } return null; }
java
public static Location getObjectLocation(ShanksSimulation simulation, PercipientShanksAgent agent, Object object) { try { if (agent.getCurrentLocation().is3DLocation()) { ContinuousPortrayal3D devicesPortrayal; devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Double3D loc = devicesField.getObjectLocation(object); return new Location(loc); } else if (agent.getCurrentLocation().is2DLocation()) { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Double2D loc = devicesField.getObjectLocation(object); return new Location(loc); } } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } return null; }
[ "public", "static", "Location", "getObjectLocation", "(", "ShanksSimulation", "simulation", ",", "PercipientShanksAgent", "agent", ",", "Object", "object", ")", "{", "try", "{", "if", "(", "agent", ".", "getCurrentLocation", "(", ")", ".", "is3DLocation", "(", ")", ")", "{", "ContinuousPortrayal3D", "devicesPortrayal", ";", "devicesPortrayal", "=", "(", "ContinuousPortrayal3D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario3DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous3D", "devicesField", "=", "(", "Continuous3D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Double3D", "loc", "=", "devicesField", ".", "getObjectLocation", "(", "object", ")", ";", "return", "new", "Location", "(", "loc", ")", ";", "}", "else", "if", "(", "agent", ".", "getCurrentLocation", "(", ")", ".", "is2DLocation", "(", ")", ")", "{", "ContinuousPortrayal2D", "devicesPortrayal", "=", "(", "ContinuousPortrayal2D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario2DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous2D", "devicesField", "=", "(", "Continuous2D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Double2D", "loc", "=", "devicesField", ".", "getObjectLocation", "(", "object", ")", ";", "return", "new", "Location", "(", "loc", ")", ";", "}", "}", "catch", "(", "DuplicatedPortrayalIDException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ScenarioNotFoundException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ShanksException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "null", ";", "}" ]
Get the location of an object in the simulation @param object @return the Location object that represent the position of the object
[ "Get", "the", "location", "of", "an", "object", "in", "the", "simulation" ]
35d87a81c22731f4f83bbd0571c9c6d466bd16be
https://github.com/gsi-upm/Shanks/blob/35d87a81c22731f4f83bbd0571c9c6d466bd16be/shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java#L213-L245
144,988
gsi-upm/Shanks
shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java
ShanksAgentPerceptionCapability.getRandomObjectLocationInPerceptionRange
public static Location getRandomObjectLocationInPerceptionRange( ShanksSimulation simulation, PercipientShanksAgent agent) { Location agentLocation = agent.getCurrentLocation(); try { if (agentLocation.is3DLocation()) { ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Bag objects = devicesField.getObjectsWithinDistance( agentLocation.getLocation3D(), agent.getPerceptionRange(), false); if (objects.size() == 1 && objects.get(0).equals(agent)) { return null; } Object o; Double3D newTarget = null; do { int size = objects.size(); o = objects.get(simulation.random.nextInt(size)); newTarget = devicesField.getObjectLocation(o); } while (o.equals(agent)); return new Location(newTarget); } else if (agentLocation.is2DLocation()) { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Bag objects = devicesField.getObjectsWithinDistance( agentLocation.getLocation2D(), agent.getPerceptionRange(), false); Object o; Double2D newTarget = null; do { int size = objects.size(); o = objects.get(simulation.random.nextInt(size)); newTarget = devicesField.getObjectLocation(o); } while (o.equals(agent)); return new Location(newTarget); } } catch (Exception e) { e.printStackTrace(); } return null; }
java
public static Location getRandomObjectLocationInPerceptionRange( ShanksSimulation simulation, PercipientShanksAgent agent) { Location agentLocation = agent.getCurrentLocation(); try { if (agentLocation.is3DLocation()) { ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Bag objects = devicesField.getObjectsWithinDistance( agentLocation.getLocation3D(), agent.getPerceptionRange(), false); if (objects.size() == 1 && objects.get(0).equals(agent)) { return null; } Object o; Double3D newTarget = null; do { int size = objects.size(); o = objects.get(simulation.random.nextInt(size)); newTarget = devicesField.getObjectLocation(o); } while (o.equals(agent)); return new Location(newTarget); } else if (agentLocation.is2DLocation()) { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Bag objects = devicesField.getObjectsWithinDistance( agentLocation.getLocation2D(), agent.getPerceptionRange(), false); Object o; Double2D newTarget = null; do { int size = objects.size(); o = objects.get(simulation.random.nextInt(size)); newTarget = devicesField.getObjectLocation(o); } while (o.equals(agent)); return new Location(newTarget); } } catch (Exception e) { e.printStackTrace(); } return null; }
[ "public", "static", "Location", "getRandomObjectLocationInPerceptionRange", "(", "ShanksSimulation", "simulation", ",", "PercipientShanksAgent", "agent", ")", "{", "Location", "agentLocation", "=", "agent", ".", "getCurrentLocation", "(", ")", ";", "try", "{", "if", "(", "agentLocation", ".", "is3DLocation", "(", ")", ")", "{", "ContinuousPortrayal3D", "devicesPortrayal", "=", "(", "ContinuousPortrayal3D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario3DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous3D", "devicesField", "=", "(", "Continuous3D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Bag", "objects", "=", "devicesField", ".", "getObjectsWithinDistance", "(", "agentLocation", ".", "getLocation3D", "(", ")", ",", "agent", ".", "getPerceptionRange", "(", ")", ",", "false", ")", ";", "if", "(", "objects", ".", "size", "(", ")", "==", "1", "&&", "objects", ".", "get", "(", "0", ")", ".", "equals", "(", "agent", ")", ")", "{", "return", "null", ";", "}", "Object", "o", ";", "Double3D", "newTarget", "=", "null", ";", "do", "{", "int", "size", "=", "objects", ".", "size", "(", ")", ";", "o", "=", "objects", ".", "get", "(", "simulation", ".", "random", ".", "nextInt", "(", "size", ")", ")", ";", "newTarget", "=", "devicesField", ".", "getObjectLocation", "(", "o", ")", ";", "}", "while", "(", "o", ".", "equals", "(", "agent", ")", ")", ";", "return", "new", "Location", "(", "newTarget", ")", ";", "}", "else", "if", "(", "agentLocation", ".", "is2DLocation", "(", ")", ")", "{", "ContinuousPortrayal2D", "devicesPortrayal", "=", "(", "ContinuousPortrayal2D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario2DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous2D", "devicesField", "=", "(", "Continuous2D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Bag", "objects", "=", "devicesField", ".", "getObjectsWithinDistance", "(", "agentLocation", ".", "getLocation2D", "(", ")", ",", "agent", ".", "getPerceptionRange", "(", ")", ",", "false", ")", ";", "Object", "o", ";", "Double2D", "newTarget", "=", "null", ";", "do", "{", "int", "size", "=", "objects", ".", "size", "(", ")", ";", "o", "=", "objects", ".", "get", "(", "simulation", ".", "random", ".", "nextInt", "(", "size", ")", ")", ";", "newTarget", "=", "devicesField", ".", "getObjectLocation", "(", "o", ")", ";", "}", "while", "(", "o", ".", "equals", "(", "agent", ")", ")", ";", "return", "new", "Location", "(", "newTarget", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "null", ";", "}" ]
Get a random object location in the perception range of the agent. @param simulation @param agent @return A random object location within the perception range of the agent. This location never will be the location of the agent. If the location is the unique object in the perception range, return null.
[ "Get", "a", "random", "object", "location", "in", "the", "perception", "range", "of", "the", "agent", "." ]
35d87a81c22731f4f83bbd0571c9c6d466bd16be
https://github.com/gsi-upm/Shanks/blob/35d87a81c22731f4f83bbd0571c9c6d466bd16be/shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java#L257-L305
144,989
gsi-upm/Shanks
shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java
ShanksAgentPerceptionCapability.getAllObjects
public static Bag getAllObjects(ShanksSimulation simulation, PercipientShanksAgent agent) { Location agentLocation = agent.getCurrentLocation(); if (agentLocation.is3DLocation()) { try { ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Bag objects = devicesField.getAllObjects(); return objects; } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } else if (agentLocation.is2DLocation()) { try { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Bag objects = devicesField.getAllObjects(); return objects; } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } return null; }
java
public static Bag getAllObjects(ShanksSimulation simulation, PercipientShanksAgent agent) { Location agentLocation = agent.getCurrentLocation(); if (agentLocation.is3DLocation()) { try { ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario3DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous3D devicesField = (Continuous3D) devicesPortrayal .getField(); Bag objects = devicesField.getAllObjects(); return objects; } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } else if (agentLocation.is2DLocation()) { try { ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation .getScenarioPortrayal().getPortrayals() .get(Scenario2DPortrayal.MAIN_DISPLAY_ID) .get(ScenarioPortrayal.DEVICES_PORTRAYAL); Continuous2D devicesField = (Continuous2D) devicesPortrayal .getField(); Bag objects = devicesField.getAllObjects(); return objects; } catch (DuplicatedPortrayalIDException e) { e.printStackTrace(); } catch (ScenarioNotFoundException e) { e.printStackTrace(); } catch (ShanksException e) { e.printStackTrace(); } } return null; }
[ "public", "static", "Bag", "getAllObjects", "(", "ShanksSimulation", "simulation", ",", "PercipientShanksAgent", "agent", ")", "{", "Location", "agentLocation", "=", "agent", ".", "getCurrentLocation", "(", ")", ";", "if", "(", "agentLocation", ".", "is3DLocation", "(", ")", ")", "{", "try", "{", "ContinuousPortrayal3D", "devicesPortrayal", "=", "(", "ContinuousPortrayal3D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario3DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous3D", "devicesField", "=", "(", "Continuous3D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Bag", "objects", "=", "devicesField", ".", "getAllObjects", "(", ")", ";", "return", "objects", ";", "}", "catch", "(", "DuplicatedPortrayalIDException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ScenarioNotFoundException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ShanksException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "else", "if", "(", "agentLocation", ".", "is2DLocation", "(", ")", ")", "{", "try", "{", "ContinuousPortrayal2D", "devicesPortrayal", "=", "(", "ContinuousPortrayal2D", ")", "simulation", ".", "getScenarioPortrayal", "(", ")", ".", "getPortrayals", "(", ")", ".", "get", "(", "Scenario2DPortrayal", ".", "MAIN_DISPLAY_ID", ")", ".", "get", "(", "ScenarioPortrayal", ".", "DEVICES_PORTRAYAL", ")", ";", "Continuous2D", "devicesField", "=", "(", "Continuous2D", ")", "devicesPortrayal", ".", "getField", "(", ")", ";", "Bag", "objects", "=", "devicesField", ".", "getAllObjects", "(", ")", ";", "return", "objects", ";", "}", "catch", "(", "DuplicatedPortrayalIDException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ScenarioNotFoundException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ShanksException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "return", "null", ";", "}" ]
To obtain all objects in the simulation @param simulation @param agent @return the objects that are in the simulation
[ "To", "obtain", "all", "objects", "in", "the", "simulation" ]
35d87a81c22731f4f83bbd0571c9c6d466bd16be
https://github.com/gsi-upm/Shanks/blob/35d87a81c22731f4f83bbd0571c9c6d466bd16be/shanks-core/src/main/java/es/upm/dit/gsi/shanks/agent/capability/perception/ShanksAgentPerceptionCapability.java#L314-L353
144,990
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.hash
public static byte[] hash(byte[] data, String alg) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(alg); return md.digest(data); }
java
public static byte[] hash(byte[] data, String alg) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(alg); return md.digest(data); }
[ "public", "static", "byte", "[", "]", "hash", "(", "byte", "[", "]", "data", ",", "String", "alg", ")", "throws", "NoSuchAlgorithmException", "{", "MessageDigest", "md", "=", "MessageDigest", ".", "getInstance", "(", "alg", ")", ";", "return", "md", ".", "digest", "(", "data", ")", ";", "}" ]
Hashes data with the specified hashing algorithm. @since 1.1 @param data the data to hash @param alg the hashing algorithm to use @return the hash of the data @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "data", "with", "the", "specified", "hashing", "algorithm", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L36-L39
144,991
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.md2Hash
public static byte[] md2Hash(String data, Charset charset) throws NoSuchAlgorithmException { return md2Hash(data.getBytes(charset)); }
java
public static byte[] md2Hash(String data, Charset charset) throws NoSuchAlgorithmException { return md2Hash(data.getBytes(charset)); }
[ "public", "static", "byte", "[", "]", "md2Hash", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "md2Hash", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the MD2 algorithm. @since 1.1 @param data the string to hash @param charset the charset of the string @return the MD2 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "MD2", "algorithm", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L101-L103
144,992
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.md2Hex
public static String md2Hex(String data, Charset charset) throws NoSuchAlgorithmException { return md2Hex(data.getBytes(charset)); }
java
public static String md2Hex(String data, Charset charset) throws NoSuchAlgorithmException { return md2Hex(data.getBytes(charset)); }
[ "public", "static", "String", "md2Hex", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "md2Hex", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the MD2 algorithm. Returns a hexadecimal result. @since 1.1 @param data the string to hash @param charset the charset of the string @return the hexadecimal MD2 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "MD2", "algorithm", ".", "Returns", "a", "hexadecimal", "result", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L138-L140
144,993
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.md5Hash
public static byte[] md5Hash(String data, Charset charset) throws NoSuchAlgorithmException { return md5Hash(data.getBytes(charset)); }
java
public static byte[] md5Hash(String data, Charset charset) throws NoSuchAlgorithmException { return md5Hash(data.getBytes(charset)); }
[ "public", "static", "byte", "[", "]", "md5Hash", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "md5Hash", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the MD5 algorithm. @since 1.1 @param data the string to hash @param charset the charset of the string @return the MD5 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "MD5", "algorithm", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L175-L177
144,994
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.md5Hex
public static String md5Hex(String data, Charset charset) throws NoSuchAlgorithmException { return md5Hex(data.getBytes(charset)); }
java
public static String md5Hex(String data, Charset charset) throws NoSuchAlgorithmException { return md5Hex(data.getBytes(charset)); }
[ "public", "static", "String", "md5Hex", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "md5Hex", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the MD5 algorithm. Returns a hexadecimal result. @since 1.1 @param data the string to hash @param charset the charset of the string @return the hexadecimal MD5 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "MD5", "algorithm", ".", "Returns", "a", "hexadecimal", "result", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L212-L214
144,995
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.sha1Hash
public static byte[] sha1Hash(String data, Charset charset) throws NoSuchAlgorithmException { return sha1Hash(data.getBytes(charset)); }
java
public static byte[] sha1Hash(String data, Charset charset) throws NoSuchAlgorithmException { return sha1Hash(data.getBytes(charset)); }
[ "public", "static", "byte", "[", "]", "sha1Hash", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "sha1Hash", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the SHA-1 algorithm. @since 1.1 @param data the string to hash @param charset the charset of the string @return the SHA-1 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "SHA", "-", "1", "algorithm", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L249-L251
144,996
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.sha1Hex
public static String sha1Hex(String data, Charset charset) throws NoSuchAlgorithmException { return sha1Hex(data.getBytes(charset)); }
java
public static String sha1Hex(String data, Charset charset) throws NoSuchAlgorithmException { return sha1Hex(data.getBytes(charset)); }
[ "public", "static", "String", "sha1Hex", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "sha1Hex", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the SHA-1 algorithm. Returns a hexadecimal result. @since 1.1 @param data the string to hash @param charset the charset of the string @return the hexadecimal SHA-1 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "SHA", "-", "1", "algorithm", ".", "Returns", "a", "hexadecimal", "result", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L286-L288
144,997
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.sha224Hash
public static byte[] sha224Hash(String data, Charset charset) throws NoSuchAlgorithmException { return sha224Hash(data.getBytes(charset)); }
java
public static byte[] sha224Hash(String data, Charset charset) throws NoSuchAlgorithmException { return sha224Hash(data.getBytes(charset)); }
[ "public", "static", "byte", "[", "]", "sha224Hash", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "sha224Hash", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the SHA-224 algorithm. @since 1.1 @param data the string to hash @param charset the charset of the string @return the SHA-224 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "SHA", "-", "224", "algorithm", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L323-L325
144,998
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.sha224Hex
public static String sha224Hex(String data, Charset charset) throws NoSuchAlgorithmException { return sha224Hex(data.getBytes(charset)); }
java
public static String sha224Hex(String data, Charset charset) throws NoSuchAlgorithmException { return sha224Hex(data.getBytes(charset)); }
[ "public", "static", "String", "sha224Hex", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "sha224Hex", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the SHA-224 algorithm. Returns a hexadecimal result. @since 1.1 @param data the string to hash @param charset the charset of the string @return the hexadecimal SHA-224 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "SHA", "-", "224", "algorithm", ".", "Returns", "a", "hexadecimal", "result", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L360-L362
144,999
Mthwate/DatLib
src/main/java/com/mthwate/datlib/HashUtils.java
HashUtils.sha256Hash
public static byte[] sha256Hash(String data, Charset charset) throws NoSuchAlgorithmException { return sha256Hash(data.getBytes(charset)); }
java
public static byte[] sha256Hash(String data, Charset charset) throws NoSuchAlgorithmException { return sha256Hash(data.getBytes(charset)); }
[ "public", "static", "byte", "[", "]", "sha256Hash", "(", "String", "data", ",", "Charset", "charset", ")", "throws", "NoSuchAlgorithmException", "{", "return", "sha256Hash", "(", "data", ".", "getBytes", "(", "charset", ")", ")", ";", "}" ]
Hashes a string using the SHA-256 algorithm. @since 1.1 @param data the string to hash @param charset the charset of the string @return the SHA-256 hash of the string @throws NoSuchAlgorithmException the algorithm is not supported by existing providers
[ "Hashes", "a", "string", "using", "the", "SHA", "-", "256", "algorithm", "." ]
f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077
https://github.com/Mthwate/DatLib/blob/f0b3a9f9cf6fdc773d4f86234ebd95986c9b6077/src/main/java/com/mthwate/datlib/HashUtils.java#L397-L399