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
partition
stringclasses
1 value
jboss/jboss-jsp-api_spec
src/main/java/javax/servlet/jsp/tagext/TagLibraryInfo.java
TagLibraryInfo.getFunction
public FunctionInfo getFunction(String name) { if (functions == null || functions.length == 0) { System.err.println("No functions"); return null; } for (int i=0; i < functions.length; i++) { if (functions[i].getName().equals(name)) { return functions[i]; } } return null; }
java
public FunctionInfo getFunction(String name) { if (functions == null || functions.length == 0) { System.err.println("No functions"); return null; } for (int i=0; i < functions.length; i++) { if (functions[i].getName().equals(name)) { return functions[i]; } } return null; }
[ "public", "FunctionInfo", "getFunction", "(", "String", "name", ")", "{", "if", "(", "functions", "==", "null", "||", "functions", ".", "length", "==", "0", ")", "{", "System", ".", "err", ".", "println", "(", "\"No functions\"", ")", ";", "return", "nul...
Get the FunctionInfo for a given function name, looking through all the functions in this tag library. @param name The name (no prefix) of the function @return the FunctionInfo for the function with the given name, or null if no such function exists @since JSP 2.0
[ "Get", "the", "FunctionInfo", "for", "a", "given", "function", "name", "looking", "through", "all", "the", "functions", "in", "this", "tag", "library", "." ]
da53166619f33a5134dc3315a3264990cc1f541f
https://github.com/jboss/jboss-jsp-api_spec/blob/da53166619f33a5134dc3315a3264990cc1f541f/src/main/java/javax/servlet/jsp/tagext/TagLibraryInfo.java#L245-L258
train
threerings/nenya
core/src/main/java/com/threerings/openal/OggStreamDecoder.java
OggStreamDecoder.readSamples
protected int readSamples () throws IOException { int samples; while ((samples = _dsp.synthesis_pcmout(_pcm, _offsets)) <= 0) { if (samples == 0 && !readPacket()) { return 0; } if (_block.synthesis(_packet) == 0) { _dsp.synthesis_blockin(_block); } } return samples; }
java
protected int readSamples () throws IOException { int samples; while ((samples = _dsp.synthesis_pcmout(_pcm, _offsets)) <= 0) { if (samples == 0 && !readPacket()) { return 0; } if (_block.synthesis(_packet) == 0) { _dsp.synthesis_blockin(_block); } } return samples; }
[ "protected", "int", "readSamples", "(", ")", "throws", "IOException", "{", "int", "samples", ";", "while", "(", "(", "samples", "=", "_dsp", ".", "synthesis_pcmout", "(", "_pcm", ",", "_offsets", ")", ")", "<=", "0", ")", "{", "if", "(", "samples", "==...
Reads a buffer's worth of samples. @return the number of samples read, or zero if we've reached the end of the stream.
[ "Reads", "a", "buffer", "s", "worth", "of", "samples", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/openal/OggStreamDecoder.java#L137-L150
train
threerings/nenya
core/src/main/java/com/threerings/openal/OggStreamDecoder.java
OggStreamDecoder.readPacket
protected boolean readPacket () throws IOException { int result; while ((result = _stream.packetout(_packet)) != 1) { if (result == 0 && !readPage()) { return false; } } return true; }
java
protected boolean readPacket () throws IOException { int result; while ((result = _stream.packetout(_packet)) != 1) { if (result == 0 && !readPage()) { return false; } } return true; }
[ "protected", "boolean", "readPacket", "(", ")", "throws", "IOException", "{", "int", "result", ";", "while", "(", "(", "result", "=", "_stream", ".", "packetout", "(", "_packet", ")", ")", "!=", "1", ")", "{", "if", "(", "result", "==", "0", "&&", "!...
Reads a packet. @return true if a packet was read, false if we've reached the end of the stream.
[ "Reads", "a", "packet", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/openal/OggStreamDecoder.java#L157-L167
train
threerings/nenya
core/src/main/java/com/threerings/openal/OggStreamDecoder.java
OggStreamDecoder.readPage
protected boolean readPage () throws IOException { int result; while ((result = _sync.pageout(_page)) != 1) { if (result == 0 && !readChunk()) { return false; } } _stream.pagein(_page); return true; }
java
protected boolean readPage () throws IOException { int result; while ((result = _sync.pageout(_page)) != 1) { if (result == 0 && !readChunk()) { return false; } } _stream.pagein(_page); return true; }
[ "protected", "boolean", "readPage", "(", ")", "throws", "IOException", "{", "int", "result", ";", "while", "(", "(", "result", "=", "_sync", ".", "pageout", "(", "_page", ")", ")", "!=", "1", ")", "{", "if", "(", "result", "==", "0", "&&", "!", "re...
Reads in a page. @return true if a page was read, false if we've reached the end of the stream.
[ "Reads", "in", "a", "page", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/openal/OggStreamDecoder.java#L174-L185
train
threerings/nenya
core/src/main/java/com/threerings/openal/OggStreamDecoder.java
OggStreamDecoder.readChunk
protected boolean readChunk () throws IOException { int offset = _sync.buffer(BUFFER_SIZE); int bytes = _in.read(_sync.data, offset, BUFFER_SIZE); if (bytes > 0) { _sync.wrote(bytes); return true; } return false; }
java
protected boolean readChunk () throws IOException { int offset = _sync.buffer(BUFFER_SIZE); int bytes = _in.read(_sync.data, offset, BUFFER_SIZE); if (bytes > 0) { _sync.wrote(bytes); return true; } return false; }
[ "protected", "boolean", "readChunk", "(", ")", "throws", "IOException", "{", "int", "offset", "=", "_sync", ".", "buffer", "(", "BUFFER_SIZE", ")", ";", "int", "bytes", "=", "_in", ".", "read", "(", "_sync", ".", "data", ",", "offset", ",", "BUFFER_SIZE"...
Reads in a chunk of data from the underlying input stream. @return true if a chunk was read, false if we've reached the end of the stream.
[ "Reads", "in", "a", "chunk", "of", "data", "from", "the", "underlying", "input", "stream", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/openal/OggStreamDecoder.java#L192-L202
train
threerings/nenya
core/src/main/java/com/threerings/media/tile/TrimmedTileSet.java
TrimmedTileSet.trimTileSet
public static TrimmedTileSet trimTileSet (TileSet source, OutputStream destImage) throws IOException { return trimTileSet(source, destImage, FastImageIO.FILE_SUFFIX); }
java
public static TrimmedTileSet trimTileSet (TileSet source, OutputStream destImage) throws IOException { return trimTileSet(source, destImage, FastImageIO.FILE_SUFFIX); }
[ "public", "static", "TrimmedTileSet", "trimTileSet", "(", "TileSet", "source", ",", "OutputStream", "destImage", ")", "throws", "IOException", "{", "return", "trimTileSet", "(", "source", ",", "destImage", ",", "FastImageIO", ".", "FILE_SUFFIX", ")", ";", "}" ]
Convenience function to trim the tile set and save it using FastImageIO.
[ "Convenience", "function", "to", "trim", "the", "tile", "set", "and", "save", "it", "using", "FastImageIO", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/tile/TrimmedTileSet.java#L67-L71
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.sourceIsReady
public boolean sourceIsReady () { // make a note of our source's last modification time _sourceLastMod = _source.lastModified(); // if we are unpacking files, the time to do so is now if (_unpacked != null && _unpacked.lastModified() != _sourceLastMod) { try { resolveJarFile(); } catch (IOException ioe) { log.warning("Failure resolving jar file", "source", _source, ioe); wipeBundle(true); return false; } log.info("Unpacking into " + _cache + "..."); if (!_cache.exists()) { if (!_cache.mkdir()) { log.warning("Failed to create bundle cache directory", "dir", _cache); closeJar(); // we are hopelessly fucked return false; } } else { FileUtil.recursiveClean(_cache); } // unpack the jar file (this will close the jar when it's done) if (!FileUtil.unpackJar(_jarSource, _cache)) { // if something went awry, delete everything in the hopes // that next time things will work wipeBundle(true); return false; } // if everything unpacked smoothly, create our unpack stamp try { _unpacked.createNewFile(); if (!_unpacked.setLastModified(_sourceLastMod)) { log.warning("Failed to set last mod on stamp file", "file", _unpacked); } } catch (IOException ioe) { log.warning("Failure creating stamp file", "file", _unpacked, ioe); // no need to stick a fork in things at this point } } return true; }
java
public boolean sourceIsReady () { // make a note of our source's last modification time _sourceLastMod = _source.lastModified(); // if we are unpacking files, the time to do so is now if (_unpacked != null && _unpacked.lastModified() != _sourceLastMod) { try { resolveJarFile(); } catch (IOException ioe) { log.warning("Failure resolving jar file", "source", _source, ioe); wipeBundle(true); return false; } log.info("Unpacking into " + _cache + "..."); if (!_cache.exists()) { if (!_cache.mkdir()) { log.warning("Failed to create bundle cache directory", "dir", _cache); closeJar(); // we are hopelessly fucked return false; } } else { FileUtil.recursiveClean(_cache); } // unpack the jar file (this will close the jar when it's done) if (!FileUtil.unpackJar(_jarSource, _cache)) { // if something went awry, delete everything in the hopes // that next time things will work wipeBundle(true); return false; } // if everything unpacked smoothly, create our unpack stamp try { _unpacked.createNewFile(); if (!_unpacked.setLastModified(_sourceLastMod)) { log.warning("Failed to set last mod on stamp file", "file", _unpacked); } } catch (IOException ioe) { log.warning("Failure creating stamp file", "file", _unpacked, ioe); // no need to stick a fork in things at this point } } return true; }
[ "public", "boolean", "sourceIsReady", "(", ")", "{", "// make a note of our source's last modification time", "_sourceLastMod", "=", "_source", ".", "lastModified", "(", ")", ";", "// if we are unpacking files, the time to do so is now", "if", "(", "_unpacked", "!=", "null", ...
Called by the resource manager once it has ensured that our resource jar file is up to date and ready for reading. @return true if we successfully unpacked our resources, false if we encountered errors in doing so.
[ "Called", "by", "the", "resource", "manager", "once", "it", "has", "ensured", "that", "our", "resource", "jar", "file", "is", "up", "to", "date", "and", "ready", "for", "reading", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L124-L172
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.wipeBundle
public void wipeBundle (boolean deleteJar) { // clear out our cache directory if (_cache != null) { FileUtil.recursiveClean(_cache); } // delete our unpack stamp file if (_unpacked != null) { _unpacked.delete(); } // clear out any .jarv file that Getdown might be maintaining so // that we ensure that it is revalidated File vfile = new File(FileUtil.resuffix(_source, ".jar", ".jarv")); if (vfile.exists() && !vfile.delete()) { log.warning("Failed to delete vfile", "file", vfile); } // close and delete our source jar file if (deleteJar && _source != null) { closeJar(); if (!_source.delete()) { log.warning("Failed to delete source", "source", _source, "exists", _source.exists()); } } }
java
public void wipeBundle (boolean deleteJar) { // clear out our cache directory if (_cache != null) { FileUtil.recursiveClean(_cache); } // delete our unpack stamp file if (_unpacked != null) { _unpacked.delete(); } // clear out any .jarv file that Getdown might be maintaining so // that we ensure that it is revalidated File vfile = new File(FileUtil.resuffix(_source, ".jar", ".jarv")); if (vfile.exists() && !vfile.delete()) { log.warning("Failed to delete vfile", "file", vfile); } // close and delete our source jar file if (deleteJar && _source != null) { closeJar(); if (!_source.delete()) { log.warning("Failed to delete source", "source", _source, "exists", _source.exists()); } } }
[ "public", "void", "wipeBundle", "(", "boolean", "deleteJar", ")", "{", "// clear out our cache directory", "if", "(", "_cache", "!=", "null", ")", "{", "FileUtil", ".", "recursiveClean", "(", "_cache", ")", ";", "}", "// delete our unpack stamp file", "if", "(", ...
Clears out everything associated with this resource bundle in the hopes that we can download it afresh and everything will work the next time around.
[ "Clears", "out", "everything", "associated", "with", "this", "resource", "bundle", "in", "the", "hopes", "that", "we", "can", "download", "it", "afresh", "and", "everything", "will", "work", "the", "next", "time", "around", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L178-L205
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.getResourceFile
public File getResourceFile (String path) throws IOException { if (resolveJarFile()) { return null; } // if we have been unpacked, return our unpacked file if (_cache != null) { File cfile = new File(_cache, path); if (cfile.exists()) { return cfile; } else { return null; } } // otherwise, we unpack resources as needed into a temp directory String tpath = StringUtil.md5hex(_source.getPath() + "%" + path); File tfile = new File(getCacheDir(), tpath); if (tfile.exists() && (tfile.lastModified() > _sourceLastMod)) { return tfile; } JarEntry entry = _jarSource.getJarEntry(path); if (entry == null) { // log.info("Couldn't locate path in jar", "path", path, "jar", _jarSource); return null; } // copy the resource into the temporary file BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(tfile)); InputStream jin = _jarSource.getInputStream(entry); StreamUtil.copy(jin, fout); jin.close(); fout.close(); return tfile; }
java
public File getResourceFile (String path) throws IOException { if (resolveJarFile()) { return null; } // if we have been unpacked, return our unpacked file if (_cache != null) { File cfile = new File(_cache, path); if (cfile.exists()) { return cfile; } else { return null; } } // otherwise, we unpack resources as needed into a temp directory String tpath = StringUtil.md5hex(_source.getPath() + "%" + path); File tfile = new File(getCacheDir(), tpath); if (tfile.exists() && (tfile.lastModified() > _sourceLastMod)) { return tfile; } JarEntry entry = _jarSource.getJarEntry(path); if (entry == null) { // log.info("Couldn't locate path in jar", "path", path, "jar", _jarSource); return null; } // copy the resource into the temporary file BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(tfile)); InputStream jin = _jarSource.getInputStream(entry); StreamUtil.copy(jin, fout); jin.close(); fout.close(); return tfile; }
[ "public", "File", "getResourceFile", "(", "String", "path", ")", "throws", "IOException", "{", "if", "(", "resolveJarFile", "(", ")", ")", "{", "return", "null", ";", "}", "// if we have been unpacked, return our unpacked file", "if", "(", "_cache", "!=", "null", ...
Returns a file from which the specified resource can be loaded. This method will unpack the resource into a temporary directory and return a reference to that file. @param path the path to the resource in this jar file. @return a file from which the resource can be loaded or null if no such resource exists.
[ "Returns", "a", "file", "from", "which", "the", "specified", "resource", "can", "be", "loaded", ".", "This", "method", "will", "unpack", "the", "resource", "into", "a", "temporary", "directory", "and", "return", "a", "reference", "to", "that", "file", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L215-L253
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.containsResource
public boolean containsResource (String path) { try { if (resolveJarFile()) { return false; } return (_jarSource.getJarEntry(path) != null); } catch (IOException ioe) { return false; } }
java
public boolean containsResource (String path) { try { if (resolveJarFile()) { return false; } return (_jarSource.getJarEntry(path) != null); } catch (IOException ioe) { return false; } }
[ "public", "boolean", "containsResource", "(", "String", "path", ")", "{", "try", "{", "if", "(", "resolveJarFile", "(", ")", ")", "{", "return", "false", ";", "}", "return", "(", "_jarSource", ".", "getJarEntry", "(", "path", ")", "!=", "null", ")", ";...
Returns true if this resource bundle contains the resource with the specified path. This avoids actually loading the resource, in the event that the caller only cares to know that the resource exists.
[ "Returns", "true", "if", "this", "resource", "bundle", "contains", "the", "resource", "with", "the", "specified", "path", ".", "This", "avoids", "actually", "loading", "the", "resource", "in", "the", "event", "that", "the", "caller", "only", "cares", "to", "...
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L260-L270
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.resolveJarFile
protected boolean resolveJarFile () throws IOException { // if we don't yet have our resource bundle's last mod time, we // have not yet been notified that it is ready if (_sourceLastMod == -1) { return true; } if (!_source.exists()) { throw new IOException("Missing jar file for resource bundle: " + _source + "."); } try { if (_jarSource == null) { _jarSource = new JarFile(_source); } return false; } catch (IOException ioe) { String msg = "Failed to resolve resource bundle jar file '" + _source + "'"; log.warning(msg + ".", ioe); throw (IOException) new IOException(msg).initCause(ioe); } }
java
protected boolean resolveJarFile () throws IOException { // if we don't yet have our resource bundle's last mod time, we // have not yet been notified that it is ready if (_sourceLastMod == -1) { return true; } if (!_source.exists()) { throw new IOException("Missing jar file for resource bundle: " + _source + "."); } try { if (_jarSource == null) { _jarSource = new JarFile(_source); } return false; } catch (IOException ioe) { String msg = "Failed to resolve resource bundle jar file '" + _source + "'"; log.warning(msg + ".", ioe); throw (IOException) new IOException(msg).initCause(ioe); } }
[ "protected", "boolean", "resolveJarFile", "(", ")", "throws", "IOException", "{", "// if we don't yet have our resource bundle's last mod time, we", "// have not yet been notified that it is ready", "if", "(", "_sourceLastMod", "==", "-", "1", ")", "{", "return", "true", ";",...
Creates the internal jar file reference if we've not already got it; we do this lazily so as to avoid any jar- or zip-file-related antics until and unless doing so is required, and because the resource manager would like to be able to create bundles before the associated files have been fully downloaded. @return true if the jar file could not yet be resolved because we haven't yet heard from the resource manager that it is ready for us to access, false if all is cool.
[ "Creates", "the", "internal", "jar", "file", "reference", "if", "we", "ve", "not", "already", "got", "it", ";", "we", "do", "this", "lazily", "so", "as", "to", "avoid", "any", "jar", "-", "or", "zip", "-", "file", "-", "related", "antics", "until", "...
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L294-L318
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.getCacheDir
public static File getCacheDir () { if (_tmpdir == null) { String tmpdir = System.getProperty("java.io.tmpdir"); if (tmpdir == null) { log.info("No system defined temp directory. Faking it."); tmpdir = System.getProperty("user.home"); } setCacheDir(new File(tmpdir)); } return _tmpdir; }
java
public static File getCacheDir () { if (_tmpdir == null) { String tmpdir = System.getProperty("java.io.tmpdir"); if (tmpdir == null) { log.info("No system defined temp directory. Faking it."); tmpdir = System.getProperty("user.home"); } setCacheDir(new File(tmpdir)); } return _tmpdir; }
[ "public", "static", "File", "getCacheDir", "(", ")", "{", "if", "(", "_tmpdir", "==", "null", ")", "{", "String", "tmpdir", "=", "System", ".", "getProperty", "(", "\"java.io.tmpdir\"", ")", ";", "if", "(", "tmpdir", "==", "null", ")", "{", "log", ".",...
Returns the cache directory used for unpacked resources.
[ "Returns", "the", "cache", "directory", "used", "for", "unpacked", "resources", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L337-L348
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.setCacheDir
public static void setCacheDir (File tmpdir) { String rando = Long.toHexString((long)(Math.random() * Long.MAX_VALUE)); _tmpdir = new File(tmpdir, "narcache_" + rando); if (!_tmpdir.exists()) { if (_tmpdir.mkdirs()) { log.debug("Created narya temp cache directory '" + _tmpdir + "'."); } else { log.warning("Failed to create temp cache directory '" + _tmpdir + "'."); } } // add a hook to blow away the temp directory when we exit Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run () { log.info("Clearing narya temp cache '" + _tmpdir + "'."); FileUtil.recursiveDelete(_tmpdir); } }); }
java
public static void setCacheDir (File tmpdir) { String rando = Long.toHexString((long)(Math.random() * Long.MAX_VALUE)); _tmpdir = new File(tmpdir, "narcache_" + rando); if (!_tmpdir.exists()) { if (_tmpdir.mkdirs()) { log.debug("Created narya temp cache directory '" + _tmpdir + "'."); } else { log.warning("Failed to create temp cache directory '" + _tmpdir + "'."); } } // add a hook to blow away the temp directory when we exit Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run () { log.info("Clearing narya temp cache '" + _tmpdir + "'."); FileUtil.recursiveDelete(_tmpdir); } }); }
[ "public", "static", "void", "setCacheDir", "(", "File", "tmpdir", ")", "{", "String", "rando", "=", "Long", ".", "toHexString", "(", "(", "long", ")", "(", "Math", ".", "random", "(", ")", "*", "Long", ".", "MAX_VALUE", ")", ")", ";", "_tmpdir", "=",...
Specifies the directory in which our temporary resource files should be stored.
[ "Specifies", "the", "directory", "in", "which", "our", "temporary", "resource", "files", "should", "be", "stored", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L353-L373
train
threerings/nenya
core/src/main/java/com/threerings/resource/FileResourceBundle.java
FileResourceBundle.stripSuffix
protected static String stripSuffix (String path) { if (path.endsWith(".jar")) { return path.substring(0, path.length()-4); } else { // we have to change the path somehow return path + "-cache"; } }
java
protected static String stripSuffix (String path) { if (path.endsWith(".jar")) { return path.substring(0, path.length()-4); } else { // we have to change the path somehow return path + "-cache"; } }
[ "protected", "static", "String", "stripSuffix", "(", "String", "path", ")", "{", "if", "(", "path", ".", "endsWith", "(", "\".jar\"", ")", ")", "{", "return", "path", ".", "substring", "(", "0", ",", "path", ".", "length", "(", ")", "-", "4", ")", ...
Strips the .jar off of jar file paths.
[ "Strips", "the", ".", "jar", "off", "of", "jar", "file", "paths", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FileResourceBundle.java#L376-L384
train
calrissian/mango
mango-core/src/main/java/org/calrissian/mango/collect/CloseableIterators.java
CloseableIterators.distinct
public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); }
java
public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); }
[ "public", "static", "<", "T", ">", "CloseableIterator", "<", "T", ">", "distinct", "(", "final", "CloseableIterator", "<", "T", ">", "iterator", ")", "{", "return", "wrap", "(", "Iterators2", ".", "distinct", "(", "iterator", ")", ",", "iterator", ")", "...
If we can assume the closeable iterator is sorted, return the distinct elements. This only works if the data provided is sorted.
[ "If", "we", "can", "assume", "the", "closeable", "iterator", "is", "sorted", "return", "the", "distinct", "elements", ".", "This", "only", "works", "if", "the", "data", "provided", "is", "sorted", "." ]
a95aa5e77af9aa0e629787228d80806560023452
https://github.com/calrissian/mango/blob/a95aa5e77af9aa0e629787228d80806560023452/mango-core/src/main/java/org/calrissian/mango/collect/CloseableIterators.java#L91-L93
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.stream
public Stream<RangeWithCount> stream() { return buckets_.stream() .map(bucket -> new RangeWithCount(bucket.getRange(), bucket.getEvents())); }
java
public Stream<RangeWithCount> stream() { return buckets_.stream() .map(bucket -> new RangeWithCount(bucket.getRange(), bucket.getEvents())); }
[ "public", "Stream", "<", "RangeWithCount", ">", "stream", "(", ")", "{", "return", "buckets_", ".", "stream", "(", ")", ".", "map", "(", "bucket", "->", "new", "RangeWithCount", "(", "bucket", ".", "getRange", "(", ")", ",", "bucket", ".", "getEvents", ...
Returns a map of range -&gt; event count. The elements of the stream are a mutable copy of the internal data.
[ "Returns", "a", "map", "of", "range", "-", "&gt", ";", "event", "count", ".", "The", "elements", "of", "the", "stream", "are", "a", "mutable", "copy", "of", "the", "internal", "data", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L79-L82
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.avg
public Optional<Double> avg() { if (isEmpty()) return Optional.empty(); return Optional.of(sum() / getEventCount()); }
java
public Optional<Double> avg() { if (isEmpty()) return Optional.empty(); return Optional.of(sum() / getEventCount()); }
[ "public", "Optional", "<", "Double", ">", "avg", "(", ")", "{", "if", "(", "isEmpty", "(", ")", ")", "return", "Optional", ".", "empty", "(", ")", ";", "return", "Optional", ".", "of", "(", "sum", "(", ")", "/", "getEventCount", "(", ")", ")", ";...
Return the average of the histogram.
[ "Return", "the", "average", "of", "the", "histogram", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L125-L128
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.sum
public double sum() { return buckets_.stream() .mapToDouble(b -> b.getRange().getMidPoint() * b.getEvents()) .sum(); }
java
public double sum() { return buckets_.stream() .mapToDouble(b -> b.getRange().getMidPoint() * b.getEvents()) .sum(); }
[ "public", "double", "sum", "(", ")", "{", "return", "buckets_", ".", "stream", "(", ")", ".", "mapToDouble", "(", "b", "->", "b", ".", "getRange", "(", ")", ".", "getMidPoint", "(", ")", "*", "b", ".", "getEvents", "(", ")", ")", ".", "sum", "(",...
Return the sum of the histogram.
[ "Return", "the", "sum", "of", "the", "histogram", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L133-L137
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.get
public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); // Undo position change made by mid.next(). if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); // Undo position change made by b.next(). final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; }
java
public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); // Undo position change made by mid.next(). if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); // Undo position change made by b.next(). final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; }
[ "public", "double", "get", "(", "double", "index", ")", "{", "ListIterator", "<", "Bucket", ">", "b", "=", "buckets_", ".", "listIterator", "(", "0", ")", ";", "ListIterator", "<", "Bucket", ">", "e", "=", "buckets_", ".", "listIterator", "(", "buckets_"...
Get the value at a given position.
[ "Get", "the", "value", "at", "a", "given", "position", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L142-L171
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.modifyEventCounters
public Histogram modifyEventCounters(BiFunction<Range, Double, Double> fn) { return new Histogram(stream() .map(entry -> { entry.setCount(fn.apply(entry.getRange(), entry.getCount())); return entry; })); }
java
public Histogram modifyEventCounters(BiFunction<Range, Double, Double> fn) { return new Histogram(stream() .map(entry -> { entry.setCount(fn.apply(entry.getRange(), entry.getCount())); return entry; })); }
[ "public", "Histogram", "modifyEventCounters", "(", "BiFunction", "<", "Range", ",", "Double", ",", "Double", ">", "fn", ")", "{", "return", "new", "Histogram", "(", "stream", "(", ")", ".", "map", "(", "entry", "->", "{", "entry", ".", "setCount", "(", ...
Create a new histogram, after applying the function on each of the event counters.
[ "Create", "a", "new", "histogram", "after", "applying", "the", "function", "on", "each", "of", "the", "event", "counters", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L184-L190
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.add
public static Histogram add(Histogram x, Histogram y) { return new Histogram(Stream.concat(x.stream(), y.stream())); }
java
public static Histogram add(Histogram x, Histogram y) { return new Histogram(Stream.concat(x.stream(), y.stream())); }
[ "public", "static", "Histogram", "add", "(", "Histogram", "x", ",", "Histogram", "y", ")", "{", "return", "new", "Histogram", "(", "Stream", ".", "concat", "(", "x", ".", "stream", "(", ")", ",", "y", ".", "stream", "(", ")", ")", ")", ";", "}" ]
Add two histograms together.
[ "Add", "two", "histograms", "together", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L195-L197
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.subtract
public static Histogram subtract(Histogram x, Histogram y) { return new Histogram(Stream.concat( x.stream(), y.stream().map(rwc -> { rwc.setCount(-rwc.getCount()); return rwc; }))); }
java
public static Histogram subtract(Histogram x, Histogram y) { return new Histogram(Stream.concat( x.stream(), y.stream().map(rwc -> { rwc.setCount(-rwc.getCount()); return rwc; }))); }
[ "public", "static", "Histogram", "subtract", "(", "Histogram", "x", ",", "Histogram", "y", ")", "{", "return", "new", "Histogram", "(", "Stream", ".", "concat", "(", "x", ".", "stream", "(", ")", ",", "y", ".", "stream", "(", ")", ".", "map", "(", ...
Subtracts two histograms. @throws IllegalArgumentException If the result contains mixed signs.
[ "Subtracts", "two", "histograms", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L211-L218
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.multiply
public static Histogram multiply(Histogram x, double y) { return x.modifyEventCounters((r, d) -> d * y); }
java
public static Histogram multiply(Histogram x, double y) { return x.modifyEventCounters((r, d) -> d * y); }
[ "public", "static", "Histogram", "multiply", "(", "Histogram", "x", ",", "double", "y", ")", "{", "return", "x", ".", "modifyEventCounters", "(", "(", "r", ",", "d", ")", "->", "d", "*", "y", ")", ";", "}" ]
Multiply histogram by scalar.
[ "Multiply", "histogram", "by", "scalar", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L223-L225
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.divide
public static Histogram divide(Histogram x, double y) { return x.modifyEventCounters((r, d) -> d / y); }
java
public static Histogram divide(Histogram x, double y) { return x.modifyEventCounters((r, d) -> d / y); }
[ "public", "static", "Histogram", "divide", "(", "Histogram", "x", ",", "double", "y", ")", "{", "return", "x", ".", "modifyEventCounters", "(", "(", "r", ",", "d", ")", "->", "d", "/", "y", ")", ";", "}" ]
Divide histogram by scalar.
[ "Divide", "histogram", "by", "scalar", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L230-L232
train
groupon/monsoon
intf/src/main/java/com/groupon/lex/metrics/Histogram.java
Histogram.compareTo
@Override public int compareTo(Histogram o) { int cmp = 0; final Iterator<Bucket> iter = buckets_.iterator(), o_iter = o.buckets_.iterator(); while (cmp == 0 && iter.hasNext() && o_iter.hasNext()) { final Bucket next = iter.next(), o_next = o_iter.next(); cmp = Double.compare(next.getRange().getFloor(), o_next.getRange().getFloor()); if (cmp == 0) cmp = Double.compare(next.getRange().getCeil(), o_next.getRange().getCeil()); if (cmp == 0) cmp = Double.compare(next.getEvents(), o_next.getEvents()); } if (cmp == 0) cmp = (iter.hasNext() ? 1 : (o_iter.hasNext() ? -1 : 0)); return cmp; }
java
@Override public int compareTo(Histogram o) { int cmp = 0; final Iterator<Bucket> iter = buckets_.iterator(), o_iter = o.buckets_.iterator(); while (cmp == 0 && iter.hasNext() && o_iter.hasNext()) { final Bucket next = iter.next(), o_next = o_iter.next(); cmp = Double.compare(next.getRange().getFloor(), o_next.getRange().getFloor()); if (cmp == 0) cmp = Double.compare(next.getRange().getCeil(), o_next.getRange().getCeil()); if (cmp == 0) cmp = Double.compare(next.getEvents(), o_next.getEvents()); } if (cmp == 0) cmp = (iter.hasNext() ? 1 : (o_iter.hasNext() ? -1 : 0)); return cmp; }
[ "@", "Override", "public", "int", "compareTo", "(", "Histogram", "o", ")", "{", "int", "cmp", "=", "0", ";", "final", "Iterator", "<", "Bucket", ">", "iter", "=", "buckets_", ".", "iterator", "(", ")", ",", "o_iter", "=", "o", ".", "buckets_", ".", ...
Compare two histograms.
[ "Compare", "two", "histograms", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/intf/src/main/java/com/groupon/lex/metrics/Histogram.java#L259-L275
train
jdillon/gshell
gshell-util/src/main/java/com/planet57/gshell/util/converter/collections/MapConverterSupport.java
MapConverterSupport.convertToObject
@Override protected final Object convertToObject(final String text) throws Exception { Map map = CollectionUtil.toMap(text, keyEditor, valueEditor); if (map == null) { return null; } return createMap(map); }
java
@Override protected final Object convertToObject(final String text) throws Exception { Map map = CollectionUtil.toMap(text, keyEditor, valueEditor); if (map == null) { return null; } return createMap(map); }
[ "@", "Override", "protected", "final", "Object", "convertToObject", "(", "final", "String", "text", ")", "throws", "Exception", "{", "Map", "map", "=", "CollectionUtil", ".", "toMap", "(", "text", ",", "keyEditor", ",", "valueEditor", ")", ";", "if", "(", ...
Treats the text value of this property as an input stream that is converted into a Property bundle. @return a Properties object @throws ConversionException An error occurred creating the Properties object.
[ "Treats", "the", "text", "value", "of", "this", "property", "as", "an", "input", "stream", "that", "is", "converted", "into", "a", "Property", "bundle", "." ]
b587c1a4672d2e4905871462fa3b38a1f7b94e90
https://github.com/jdillon/gshell/blob/b587c1a4672d2e4905871462fa3b38a1f7b94e90/gshell-util/src/main/java/com/planet57/gshell/util/converter/collections/MapConverterSupport.java#L56-L63
train
Systemdir/GML-Writer-for-yED
Example/src/com/github/systemdir/gml/examples/example1/ExampleGraphicsProvider.java
ExampleGraphicsProvider.getGroupGraphics
@Nullable @Override public NodeGraphicDefinition getGroupGraphics(Object group, Set<String> groupElements) { return null; }
java
@Nullable @Override public NodeGraphicDefinition getGroupGraphics(Object group, Set<String> groupElements) { return null; }
[ "@", "Nullable", "@", "Override", "public", "NodeGraphicDefinition", "getGroupGraphics", "(", "Object", "group", ",", "Set", "<", "String", ">", "groupElements", ")", "{", "return", "null", ";", "}" ]
we have no groups in this example
[ "we", "have", "no", "groups", "in", "this", "example" ]
353ecf132929889cb15968865283ee511f7c8d87
https://github.com/Systemdir/GML-Writer-for-yED/blob/353ecf132929889cb15968865283ee511f7c8d87/Example/src/com/github/systemdir/gml/examples/example1/ExampleGraphicsProvider.java#L36-L40
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.name
public static final String name(SimpleGroupPath group, MetricName metric) { return name(Stream.concat(group.getPath().stream(), metric.getPath().stream()) .collect(Collectors.joining("."))); }
java
public static final String name(SimpleGroupPath group, MetricName metric) { return name(Stream.concat(group.getPath().stream(), metric.getPath().stream()) .collect(Collectors.joining("."))); }
[ "public", "static", "final", "String", "name", "(", "SimpleGroupPath", "group", ",", "MetricName", "metric", ")", "{", "return", "name", "(", "Stream", ".", "concat", "(", "group", ".", "getPath", "(", ")", ".", "stream", "(", ")", ",", "metric", ".", ...
Convert a group+metric to a wavefront name. Concatenates the paths of a Group and a Metric, separating each path element with a dot ('.'). Example: - group path: [ 'example', 'group', 'path' ] - and metric: [ 'metric', 'name' ] are concatenated into "example.group.path.metric.name". The concatenated name is cleaned to only contain characters allowed by wavefront. (See the WavefrontString.name(String) function.)
[ "Convert", "a", "group", "+", "metric", "to", "a", "wavefront", "name", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L80-L83
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.createTagEntry
private static Optional<Map.Entry<String, String>> createTagEntry(Map.Entry<String, MetricValue> tag_entry) { final Optional<String> opt_tag_value = tag_entry.getValue().asString(); return opt_tag_value .map(tag_value -> SimpleMapEntry.create(name(tag_entry.getKey()), escapeTagValue(tag_value))); }
java
private static Optional<Map.Entry<String, String>> createTagEntry(Map.Entry<String, MetricValue> tag_entry) { final Optional<String> opt_tag_value = tag_entry.getValue().asString(); return opt_tag_value .map(tag_value -> SimpleMapEntry.create(name(tag_entry.getKey()), escapeTagValue(tag_value))); }
[ "private", "static", "Optional", "<", "Map", ".", "Entry", "<", "String", ",", "String", ">", ">", "createTagEntry", "(", "Map", ".", "Entry", "<", "String", ",", "MetricValue", ">", "tag_entry", ")", "{", "final", "Optional", "<", "String", ">", "opt_ta...
Transform a tag entry into a wavefront tag. Double quotes in the tag value will be escaped.
[ "Transform", "a", "tag", "entry", "into", "a", "wavefront", "tag", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L100-L104
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.maybeTruncateTagEntry
private static Map.Entry<String, String> maybeTruncateTagEntry(Map.Entry<String, String> tag_entry) { String k = tag_entry.getKey(); String v = tag_entry.getValue(); if (k.length() + v.length() <= MAX_TAG_KEY_VAL_CHARS - 2) // 2 chars for the quotes around the value return tag_entry; if (k.length() > TRUNCATE_TAG_NAME) k = k.substring(0, TRUNCATE_TAG_NAME); if (k.length() + v.length() > MAX_TAG_KEY_VAL_CHARS - 2) v = v.substring(0, MAX_TAG_KEY_VAL_CHARS - 2 - k.length()); return SimpleMapEntry.create(k, v); }
java
private static Map.Entry<String, String> maybeTruncateTagEntry(Map.Entry<String, String> tag_entry) { String k = tag_entry.getKey(); String v = tag_entry.getValue(); if (k.length() + v.length() <= MAX_TAG_KEY_VAL_CHARS - 2) // 2 chars for the quotes around the value return tag_entry; if (k.length() > TRUNCATE_TAG_NAME) k = k.substring(0, TRUNCATE_TAG_NAME); if (k.length() + v.length() > MAX_TAG_KEY_VAL_CHARS - 2) v = v.substring(0, MAX_TAG_KEY_VAL_CHARS - 2 - k.length()); return SimpleMapEntry.create(k, v); }
[ "private", "static", "Map", ".", "Entry", "<", "String", ",", "String", ">", "maybeTruncateTagEntry", "(", "Map", ".", "Entry", "<", "String", ",", "String", ">", "tag_entry", ")", "{", "String", "k", "=", "tag_entry", ".", "getKey", "(", ")", ";", "St...
Truncate tag keys and values, to prevent them from exceeding the max length of a tag entry.
[ "Truncate", "tag", "keys", "and", "values", "to", "prevent", "them", "from", "exceeding", "the", "max", "length", "of", "a", "tag", "entry", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L110-L121
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.tags
public static Map<String, String> tags(Tags tags) { return tags.stream() .map(WavefrontStrings::createTagEntry) .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty)) .map(WavefrontStrings::maybeTruncateTagEntry) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
java
public static Map<String, String> tags(Tags tags) { return tags.stream() .map(WavefrontStrings::createTagEntry) .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty)) .map(WavefrontStrings::maybeTruncateTagEntry) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
[ "public", "static", "Map", "<", "String", ",", "String", ">", "tags", "(", "Tags", "tags", ")", "{", "return", "tags", ".", "stream", "(", ")", ".", "map", "(", "WavefrontStrings", "::", "createTagEntry", ")", ".", "flatMap", "(", "opt", "->", "opt", ...
Create a map of tags for wavefront. The tag values are escaped and should be surrounded by double quotes. This function does not put the surrounding quotes around the tag values.
[ "Create", "a", "map", "of", "tags", "for", "wavefront", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L129-L135
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.wavefrontValue
public static Optional<String> wavefrontValue(MetricValue mv) { // Omit NaN and Inf. if (mv.isInfiniteOrNaN()) return Optional.empty(); return mv.value().map(Number::toString); }
java
public static Optional<String> wavefrontValue(MetricValue mv) { // Omit NaN and Inf. if (mv.isInfiniteOrNaN()) return Optional.empty(); return mv.value().map(Number::toString); }
[ "public", "static", "Optional", "<", "String", ">", "wavefrontValue", "(", "MetricValue", "mv", ")", "{", "// Omit NaN and Inf.", "if", "(", "mv", ".", "isInfiniteOrNaN", "(", ")", ")", "return", "Optional", ".", "empty", "(", ")", ";", "return", "mv", "."...
Create a wavefront compatible string representation of the metric value. If the metric value is empty or not representable in wavefront, an empty optional will be returned.
[ "Create", "a", "wavefront", "compatible", "string", "representation", "of", "the", "metric", "value", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L143-L147
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.extractTagSource
private static String extractTagSource(Map<String, String> tag_map) { return Optional.ofNullable(tag_map.remove("source")) .orElseGet(() -> { return Optional.ofNullable(tag_map.get("cluster")) .map(WavefrontStrings::escapeTagValue) .orElseGet(() -> tag_map.getOrDefault("moncluster", "monsoon")); }); }
java
private static String extractTagSource(Map<String, String> tag_map) { return Optional.ofNullable(tag_map.remove("source")) .orElseGet(() -> { return Optional.ofNullable(tag_map.get("cluster")) .map(WavefrontStrings::escapeTagValue) .orElseGet(() -> tag_map.getOrDefault("moncluster", "monsoon")); }); }
[ "private", "static", "String", "extractTagSource", "(", "Map", "<", "String", ",", "String", ">", "tag_map", ")", "{", "return", "Optional", ".", "ofNullable", "(", "tag_map", ".", "remove", "(", "\"source\"", ")", ")", ".", "orElseGet", "(", "(", ")", "...
Extract the 'source' tag from the tag_map. Wavefront requires the 'source' tag to be the first tag on the line, hence the special handling. It also *must* be present, so we can never return null.
[ "Extract", "the", "source", "tag", "from", "the", "tag_map", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L164-L171
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.wavefrontLine
private static String wavefrontLine(DateTime ts, SimpleGroupPath group, MetricName metric, String value, String source, Map<String, String> tag_map) { return new StringBuilder() .append(name(group, metric)) .append(' ') .append(value) .append(' ') .append(timestamp(ts)) .append(' ') .append("source=").append(source) .append(' ') .append(tag_map.entrySet().stream() .map(entry -> entry.getKey() + "=\"" + entry.getValue() + '\"') .collect(Collectors.joining(" ")) ) .toString(); }
java
private static String wavefrontLine(DateTime ts, SimpleGroupPath group, MetricName metric, String value, String source, Map<String, String> tag_map) { return new StringBuilder() .append(name(group, metric)) .append(' ') .append(value) .append(' ') .append(timestamp(ts)) .append(' ') .append("source=").append(source) .append(' ') .append(tag_map.entrySet().stream() .map(entry -> entry.getKey() + "=\"" + entry.getValue() + '\"') .collect(Collectors.joining(" ")) ) .toString(); }
[ "private", "static", "String", "wavefrontLine", "(", "DateTime", "ts", ",", "SimpleGroupPath", "group", ",", "MetricName", "metric", ",", "String", "value", ",", "String", "source", ",", "Map", "<", "String", ",", "String", ">", "tag_map", ")", "{", "return"...
Build the wavefront line from its parts.
[ "Build", "the", "wavefront", "line", "from", "its", "parts", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L176-L191
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.wavefrontLine
public static Optional<String> wavefrontLine(DateTime ts, GroupName group, MetricName metric, MetricValue metric_value) { return wavefrontValue(metric_value) .map(value -> { final Map<String, String> tag_map = tags(group.getTags()); final String source = extractTagSource(tag_map); // Modifies tag_map. return wavefrontLine(ts, group.getPath(), metric, value, source, tag_map); }); }
java
public static Optional<String> wavefrontLine(DateTime ts, GroupName group, MetricName metric, MetricValue metric_value) { return wavefrontValue(metric_value) .map(value -> { final Map<String, String> tag_map = tags(group.getTags()); final String source = extractTagSource(tag_map); // Modifies tag_map. return wavefrontLine(ts, group.getPath(), metric, value, source, tag_map); }); }
[ "public", "static", "Optional", "<", "String", ">", "wavefrontLine", "(", "DateTime", "ts", ",", "GroupName", "group", ",", "MetricName", "metric", ",", "MetricValue", "metric_value", ")", "{", "return", "wavefrontValue", "(", "metric_value", ")", ".", "map", ...
Convert a metric to a wavefront string. Empty metrics and histograms do not emit a value. Note: the line is not terminated with a newline.
[ "Convert", "a", "metric", "to", "a", "wavefront", "string", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L200-L207
train
groupon/monsoon
processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java
WavefrontStrings.wavefrontLine
public static Stream<String> wavefrontLine(DateTime ts, TimeSeriesValue tsv) { final GroupName group = tsv.getGroup(); return tsv.getMetrics().entrySet().stream() .flatMap(metricEntry -> wavefrontLineForMetric(ts, group, metricEntry)); }
java
public static Stream<String> wavefrontLine(DateTime ts, TimeSeriesValue tsv) { final GroupName group = tsv.getGroup(); return tsv.getMetrics().entrySet().stream() .flatMap(metricEntry -> wavefrontLineForMetric(ts, group, metricEntry)); }
[ "public", "static", "Stream", "<", "String", ">", "wavefrontLine", "(", "DateTime", "ts", ",", "TimeSeriesValue", "tsv", ")", "{", "final", "GroupName", "group", "=", "tsv", ".", "getGroup", "(", ")", ";", "return", "tsv", ".", "getMetrics", "(", ")", "....
Convert a time series value into the string entries for wavefront. Note: the line is not terminated with a newline.
[ "Convert", "a", "time", "series", "value", "into", "the", "string", "entries", "for", "wavefront", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/processors/wavefront/src/main/java/com/groupon/lex/metrics/processors/wavefront/WavefrontStrings.java#L220-L225
train
threerings/nenya
core/src/main/java/com/threerings/media/util/ArcPath.java
ArcPath.getEndPos
public Point getEndPos () { return new Point( (int)(_center.x + Math.round(Math.cos(_sangle + _delta) * _xradius)), (int)(_center.y + Math.round(Math.sin(_sangle + _delta) * _yradius))); }
java
public Point getEndPos () { return new Point( (int)(_center.x + Math.round(Math.cos(_sangle + _delta) * _xradius)), (int)(_center.y + Math.round(Math.sin(_sangle + _delta) * _yradius))); }
[ "public", "Point", "getEndPos", "(", ")", "{", "return", "new", "Point", "(", "(", "int", ")", "(", "_center", ".", "x", "+", "Math", ".", "round", "(", "Math", ".", "cos", "(", "_sangle", "+", "_delta", ")", "*", "_xradius", ")", ")", ",", "(", ...
Returns the position of the end of the path.
[ "Returns", "the", "position", "of", "the", "end", "of", "the", "path", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/util/ArcPath.java#L114-L119
train
threerings/nenya
core/src/main/java/com/threerings/util/CompiledConfig.java
CompiledConfig.loadConfig
public static Serializable loadConfig (InputStream source) throws IOException { try { ObjectInputStream oin = new ObjectInputStream(source); return (Serializable)oin.readObject(); } catch (ClassNotFoundException cnfe) { String errmsg = "Unknown config class"; throw (IOException) new IOException(errmsg).initCause(cnfe); } }
java
public static Serializable loadConfig (InputStream source) throws IOException { try { ObjectInputStream oin = new ObjectInputStream(source); return (Serializable)oin.readObject(); } catch (ClassNotFoundException cnfe) { String errmsg = "Unknown config class"; throw (IOException) new IOException(errmsg).initCause(cnfe); } }
[ "public", "static", "Serializable", "loadConfig", "(", "InputStream", "source", ")", "throws", "IOException", "{", "try", "{", "ObjectInputStream", "oin", "=", "new", "ObjectInputStream", "(", "source", ")", ";", "return", "(", "Serializable", ")", "oin", ".", ...
Unserializes a configuration object from the supplied input stream.
[ "Unserializes", "a", "configuration", "object", "from", "the", "supplied", "input", "stream", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/util/CompiledConfig.java#L39-L49
train
threerings/nenya
core/src/main/java/com/threerings/util/CompiledConfig.java
CompiledConfig.saveConfig
public static void saveConfig (File target, Serializable config) throws IOException { FileOutputStream fout = new FileOutputStream(target); ObjectOutputStream oout = new ObjectOutputStream(fout); oout.writeObject(config); oout.close(); }
java
public static void saveConfig (File target, Serializable config) throws IOException { FileOutputStream fout = new FileOutputStream(target); ObjectOutputStream oout = new ObjectOutputStream(fout); oout.writeObject(config); oout.close(); }
[ "public", "static", "void", "saveConfig", "(", "File", "target", ",", "Serializable", "config", ")", "throws", "IOException", "{", "FileOutputStream", "fout", "=", "new", "FileOutputStream", "(", "target", ")", ";", "ObjectOutputStream", "oout", "=", "new", "Obj...
Serializes the supplied configuration object to the specified file path.
[ "Serializes", "the", "supplied", "configuration", "object", "to", "the", "specified", "file", "path", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/util/CompiledConfig.java#L54-L61
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.historyUpdated
public void historyUpdated (int adjustment) { if (adjustment != 0) { for (int ii = 0, nn = _showingHistory.size(); ii < nn; ii++) { ChatGlyph cg = _showingHistory.get(ii); cg.histIndex -= adjustment; } // some history entries were deleted, we need to re-figure the history scrollbar action resetHistoryOffset(); } if (isLaidOut() && isHistoryMode()) { int val = _historyModel.getValue(); updateHistBar(val - adjustment); // only repaint if we need to if ((val != _historyModel.getValue()) || (adjustment != 0) || !_histOffsetFinal) { figureCurrentHistory(); } } }
java
public void historyUpdated (int adjustment) { if (adjustment != 0) { for (int ii = 0, nn = _showingHistory.size(); ii < nn; ii++) { ChatGlyph cg = _showingHistory.get(ii); cg.histIndex -= adjustment; } // some history entries were deleted, we need to re-figure the history scrollbar action resetHistoryOffset(); } if (isLaidOut() && isHistoryMode()) { int val = _historyModel.getValue(); updateHistBar(val - adjustment); // only repaint if we need to if ((val != _historyModel.getValue()) || (adjustment != 0) || !_histOffsetFinal) { figureCurrentHistory(); } } }
[ "public", "void", "historyUpdated", "(", "int", "adjustment", ")", "{", "if", "(", "adjustment", "!=", "0", ")", "{", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "_showingHistory", ".", "size", "(", ")", ";", "ii", "<", "nn", ";", "ii", "+...
from interface HistoryList.Observer
[ "from", "interface", "HistoryList", ".", "Observer" ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L92-L112
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.displayMessage
public boolean displayMessage (ChatMessage message, boolean alreadyDisplayed) { // nothing doing if we've not been laid out if (!isLaidOut()) { return false; } // possibly display it now Graphics2D gfx = getTargetGraphics(); if (gfx != null) { displayMessage(message, gfx); // display it gfx.dispose(); // clean up return true; } return false; }
java
public boolean displayMessage (ChatMessage message, boolean alreadyDisplayed) { // nothing doing if we've not been laid out if (!isLaidOut()) { return false; } // possibly display it now Graphics2D gfx = getTargetGraphics(); if (gfx != null) { displayMessage(message, gfx); // display it gfx.dispose(); // clean up return true; } return false; }
[ "public", "boolean", "displayMessage", "(", "ChatMessage", "message", ",", "boolean", "alreadyDisplayed", ")", "{", "// nothing doing if we've not been laid out", "if", "(", "!", "isLaidOut", "(", ")", ")", "{", "return", "false", ";", "}", "// possibly display it now...
documentation inherited from superinterface ChatDisplay
[ "documentation", "inherited", "from", "superinterface", "ChatDisplay" ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L130-L145
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.updateDimmed
protected void updateDimmed (List<? extends ChatGlyph> glyphs) { for (ChatGlyph glyph : glyphs) { glyph.setDim(_dimmed); } }
java
protected void updateDimmed (List<? extends ChatGlyph> glyphs) { for (ChatGlyph glyph : glyphs) { glyph.setDim(_dimmed); } }
[ "protected", "void", "updateDimmed", "(", "List", "<", "?", "extends", "ChatGlyph", ">", "glyphs", ")", "{", "for", "(", "ChatGlyph", "glyph", ":", "glyphs", ")", "{", "glyph", ".", "setDim", "(", "_dimmed", ")", ";", "}", "}" ]
Update the chat glyphs in the specified list to be set to the current dimmed setting.
[ "Update", "the", "chat", "glyphs", "in", "the", "specified", "list", "to", "be", "set", "to", "the", "current", "dimmed", "setting", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L284-L289
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.setHistoryEnabled
protected void setHistoryEnabled (boolean historyEnabled) { if (historyEnabled && _historyModel == null) { _historyModel = _scrollbar.getModel(); _historyModel.addChangeListener(this); resetHistoryOffset(); // out with the subtitles, we'll be displaying history clearGlyphs(_subtitles); // "scroll" down to the latest history entry updateHistBar(_history.size() - 1); // refigure our history figureCurrentHistory(); } else if (!historyEnabled && _historyModel != null) { _historyModel.removeChangeListener(this); _historyModel = null; // out with the history, we'll be displaying subtitles clearGlyphs(_showingHistory); } }
java
protected void setHistoryEnabled (boolean historyEnabled) { if (historyEnabled && _historyModel == null) { _historyModel = _scrollbar.getModel(); _historyModel.addChangeListener(this); resetHistoryOffset(); // out with the subtitles, we'll be displaying history clearGlyphs(_subtitles); // "scroll" down to the latest history entry updateHistBar(_history.size() - 1); // refigure our history figureCurrentHistory(); } else if (!historyEnabled && _historyModel != null) { _historyModel.removeChangeListener(this); _historyModel = null; // out with the history, we'll be displaying subtitles clearGlyphs(_showingHistory); } }
[ "protected", "void", "setHistoryEnabled", "(", "boolean", "historyEnabled", ")", "{", "if", "(", "historyEnabled", "&&", "_historyModel", "==", "null", ")", "{", "_historyModel", "=", "_scrollbar", ".", "getModel", "(", ")", ";", "_historyModel", ".", "addChange...
Configures us for display of chat history or not.
[ "Configures", "us", "for", "display", "of", "chat", "history", "or", "not", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L311-L334
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.viewDidScroll
protected void viewDidScroll (List<? extends ChatGlyph> glyphs, int dx, int dy) { for (ChatGlyph glyph : glyphs) { glyph.viewDidScroll(dx, dy); } }
java
protected void viewDidScroll (List<? extends ChatGlyph> glyphs, int dx, int dy) { for (ChatGlyph glyph : glyphs) { glyph.viewDidScroll(dx, dy); } }
[ "protected", "void", "viewDidScroll", "(", "List", "<", "?", "extends", "ChatGlyph", ">", "glyphs", ",", "int", "dx", ",", "int", "dy", ")", "{", "for", "(", "ChatGlyph", "glyph", ":", "glyphs", ")", "{", "glyph", ".", "viewDidScroll", "(", "dx", ",", ...
Helper function for informing glyphs of the scrolled view.
[ "Helper", "function", "for", "informing", "glyphs", "of", "the", "scrolled", "view", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L339-L344
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.updateHistBar
protected void updateHistBar (int val) { // we may need to figure out the new history offset amount.. if (!_histOffsetFinal && _history.size() > _histOffset) { Graphics2D gfx = getTargetGraphics(); if (gfx != null) { figureHistoryOffset(gfx); gfx.dispose(); } } // then figure out the new value and range int oldval = Math.max(_histOffset, val); int newmaxval = Math.max(0, _history.size() - 1); int newval = (oldval >= newmaxval - 1) ? newmaxval : oldval; // and set it, which MAY generate a change event, but we want to ignore it so we use the // _settingBar flag _settingBar = true; _historyModel.setRangeProperties(newval, _historyExtent, _histOffset, newmaxval + _historyExtent, _historyModel.getValueIsAdjusting()); _settingBar = false; }
java
protected void updateHistBar (int val) { // we may need to figure out the new history offset amount.. if (!_histOffsetFinal && _history.size() > _histOffset) { Graphics2D gfx = getTargetGraphics(); if (gfx != null) { figureHistoryOffset(gfx); gfx.dispose(); } } // then figure out the new value and range int oldval = Math.max(_histOffset, val); int newmaxval = Math.max(0, _history.size() - 1); int newval = (oldval >= newmaxval - 1) ? newmaxval : oldval; // and set it, which MAY generate a change event, but we want to ignore it so we use the // _settingBar flag _settingBar = true; _historyModel.setRangeProperties(newval, _historyExtent, _histOffset, newmaxval + _historyExtent, _historyModel.getValueIsAdjusting()); _settingBar = false; }
[ "protected", "void", "updateHistBar", "(", "int", "val", ")", "{", "// we may need to figure out the new history offset amount..", "if", "(", "!", "_histOffsetFinal", "&&", "_history", ".", "size", "(", ")", ">", "_histOffset", ")", "{", "Graphics2D", "gfx", "=", ...
Update the history scrollbar with the specified value.
[ "Update", "the", "history", "scrollbar", "with", "the", "specified", "value", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L349-L372
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.figureHistoryOffset
protected void figureHistoryOffset (Graphics2D gfx) { if (!isLaidOut()) { return; } int hei = _subtitleYSpacing; int hsize = _history.size(); for (int ii = 0; ii < hsize; ii++) { ChatGlyph rec = getHistorySubtitle(ii, gfx); Rectangle r = rec.getBounds(); hei += r.height; // oop, we passed it, it was the last one if (hei >= _subtitleHeight) { _histOffset = Math.max(0, ii - 1); _histOffsetFinal = true; return; } hei += getHistorySubtitleSpacing(ii); } // basically, this means there isn't yet enough history to fill the first 'page' of the // history scrollback, so we set the offset to the max value, but we do not set // _histOffsetFinal to be true so that this will be recalculated _histOffset = hsize - 1; }
java
protected void figureHistoryOffset (Graphics2D gfx) { if (!isLaidOut()) { return; } int hei = _subtitleYSpacing; int hsize = _history.size(); for (int ii = 0; ii < hsize; ii++) { ChatGlyph rec = getHistorySubtitle(ii, gfx); Rectangle r = rec.getBounds(); hei += r.height; // oop, we passed it, it was the last one if (hei >= _subtitleHeight) { _histOffset = Math.max(0, ii - 1); _histOffsetFinal = true; return; } hei += getHistorySubtitleSpacing(ii); } // basically, this means there isn't yet enough history to fill the first 'page' of the // history scrollback, so we set the offset to the max value, but we do not set // _histOffsetFinal to be true so that this will be recalculated _histOffset = hsize - 1; }
[ "protected", "void", "figureHistoryOffset", "(", "Graphics2D", "gfx", ")", "{", "if", "(", "!", "isLaidOut", "(", ")", ")", "{", "return", ";", "}", "int", "hei", "=", "_subtitleYSpacing", ";", "int", "hsize", "=", "_history", ".", "size", "(", ")", ";...
Figure out how many of the first history elements fit in our bounds such that we can set the bounds on the scrollbar correctly such that the scrolling to the smallest value just barely puts the first element onscreen.
[ "Figure", "out", "how", "many", "of", "the", "first", "history", "elements", "fit", "in", "our", "bounds", "such", "that", "we", "can", "set", "the", "bounds", "on", "the", "scrollbar", "correctly", "such", "that", "the", "scrolling", "to", "the", "smalles...
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L388-L415
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.figureCurrentHistory
protected void figureCurrentHistory () { int first = _historyModel.getValue(); int count = 0; Graphics2D gfx = null; if (isLaidOut() && !_history.isEmpty()) { gfx = getTargetGraphics(); if (gfx == null) { log.warning("Can't figure current history, no graphics."); return; } // start from the bottom.. Rectangle vbounds = _target.getViewBounds(); int ypos = vbounds.height - _subtitleYSpacing; for (int ii = first; ii >= 0; ii--, count++) { ChatGlyph rec = getHistorySubtitle(ii, gfx); // see if it will fit Rectangle r = rec.getBounds(); ypos -= r.height; if ((count != 0) && ypos <= (vbounds.height - _subtitleHeight)) { break; // don't add that one.. } // position it rec.setLocation(vbounds.x + _subtitleXSpacing, vbounds.y + ypos); // add space for the next ypos -= getHistorySubtitleSpacing(ii); } } // finally, because we've been adding to the _showingHistory here (via getHistorySubtitle) // and in figureHistoryOffset (possibly called prior to this method) we now need to prune // out the ChatGlyphs that aren't actually needed and make sure the ones that are are // positioned on the screen correctly for (Iterator<ChatGlyph> itr = _showingHistory.iterator(); itr.hasNext(); ) { ChatGlyph cg = itr.next(); boolean managed = (_target != null) && _target.isManaged(cg); if (cg.histIndex <= first && cg.histIndex > (first - count)) { // it should be showing if (!managed) { _target.addAnimation(cg); } } else { // it shouldn't be showing if (managed) { _target.abortAnimation(cg); } itr.remove(); } } if (gfx != null) { gfx.dispose(); } }
java
protected void figureCurrentHistory () { int first = _historyModel.getValue(); int count = 0; Graphics2D gfx = null; if (isLaidOut() && !_history.isEmpty()) { gfx = getTargetGraphics(); if (gfx == null) { log.warning("Can't figure current history, no graphics."); return; } // start from the bottom.. Rectangle vbounds = _target.getViewBounds(); int ypos = vbounds.height - _subtitleYSpacing; for (int ii = first; ii >= 0; ii--, count++) { ChatGlyph rec = getHistorySubtitle(ii, gfx); // see if it will fit Rectangle r = rec.getBounds(); ypos -= r.height; if ((count != 0) && ypos <= (vbounds.height - _subtitleHeight)) { break; // don't add that one.. } // position it rec.setLocation(vbounds.x + _subtitleXSpacing, vbounds.y + ypos); // add space for the next ypos -= getHistorySubtitleSpacing(ii); } } // finally, because we've been adding to the _showingHistory here (via getHistorySubtitle) // and in figureHistoryOffset (possibly called prior to this method) we now need to prune // out the ChatGlyphs that aren't actually needed and make sure the ones that are are // positioned on the screen correctly for (Iterator<ChatGlyph> itr = _showingHistory.iterator(); itr.hasNext(); ) { ChatGlyph cg = itr.next(); boolean managed = (_target != null) && _target.isManaged(cg); if (cg.histIndex <= first && cg.histIndex > (first - count)) { // it should be showing if (!managed) { _target.addAnimation(cg); } } else { // it shouldn't be showing if (managed) { _target.abortAnimation(cg); } itr.remove(); } } if (gfx != null) { gfx.dispose(); } }
[ "protected", "void", "figureCurrentHistory", "(", ")", "{", "int", "first", "=", "_historyModel", ".", "getValue", "(", ")", ";", "int", "count", "=", "0", ";", "Graphics2D", "gfx", "=", "null", ";", "if", "(", "isLaidOut", "(", ")", "&&", "!", "_histo...
Figure out which ChatMessages in the history should currently appear in the showing history.
[ "Figure", "out", "which", "ChatMessages", "in", "the", "history", "should", "currently", "appear", "in", "the", "showing", "history", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L420-L479
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.getHistorySubtitle
protected ChatGlyph getHistorySubtitle (int index, Graphics2D layoutGfx) { // do a brute search (over a small set) for an already-created subtitle for (int ii = 0, nn = _showingHistory.size(); ii < nn; ii++) { ChatGlyph cg = _showingHistory.get(ii); if (cg.histIndex == index) { return cg; } } // it looks like we have to create a new one: expensive! ChatGlyph cg = createHistorySubtitle(index, layoutGfx); cg.histIndex = index; cg.setDim(_dimmed); _showingHistory.add(cg); return cg; }
java
protected ChatGlyph getHistorySubtitle (int index, Graphics2D layoutGfx) { // do a brute search (over a small set) for an already-created subtitle for (int ii = 0, nn = _showingHistory.size(); ii < nn; ii++) { ChatGlyph cg = _showingHistory.get(ii); if (cg.histIndex == index) { return cg; } } // it looks like we have to create a new one: expensive! ChatGlyph cg = createHistorySubtitle(index, layoutGfx); cg.histIndex = index; cg.setDim(_dimmed); _showingHistory.add(cg); return cg; }
[ "protected", "ChatGlyph", "getHistorySubtitle", "(", "int", "index", ",", "Graphics2D", "layoutGfx", ")", "{", "// do a brute search (over a small set) for an already-created subtitle", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "_showingHistory", ".", "size", ...
Get the glyph for the specified history index, creating if necessary.
[ "Get", "the", "glyph", "for", "the", "specified", "history", "index", "creating", "if", "necessary", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L484-L500
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.createHistorySubtitle
protected ChatGlyph createHistorySubtitle (int index, Graphics2D layoutGfx) { ChatMessage message = _history.get(index); int type = getType(message, true); return createSubtitle(message, type, layoutGfx, false); }
java
protected ChatGlyph createHistorySubtitle (int index, Graphics2D layoutGfx) { ChatMessage message = _history.get(index); int type = getType(message, true); return createSubtitle(message, type, layoutGfx, false); }
[ "protected", "ChatGlyph", "createHistorySubtitle", "(", "int", "index", ",", "Graphics2D", "layoutGfx", ")", "{", "ChatMessage", "message", "=", "_history", ".", "get", "(", "index", ")", ";", "int", "type", "=", "getType", "(", "message", ",", "true", ")", ...
Creates a subtitle for display in the history panel. @param index the index of the message in the history list
[ "Creates", "a", "subtitle", "for", "display", "in", "the", "history", "panel", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L507-L512
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.getHistorySubtitleSpacing
protected int getHistorySubtitleSpacing (int index) { ChatMessage message = _history.get(index); return _logic.getSubtitleSpacing(getType(message, true)); }
java
protected int getHistorySubtitleSpacing (int index) { ChatMessage message = _history.get(index); return _logic.getSubtitleSpacing(getType(message, true)); }
[ "protected", "int", "getHistorySubtitleSpacing", "(", "int", "index", ")", "{", "ChatMessage", "message", "=", "_history", ".", "get", "(", "index", ")", ";", "return", "_logic", ".", "getSubtitleSpacing", "(", "getType", "(", "message", ",", "true", ")", ")...
Determines the amount of spacing to put after a history subtitle. @param index the index of the message in the history list
[ "Determines", "the", "amount", "of", "spacing", "to", "put", "after", "a", "history", "subtitle", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L519-L523
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.clearGlyphs
protected void clearGlyphs (List<ChatGlyph> glyphs) { if (_target != null) { for (int ii = 0, nn = glyphs.size(); ii < nn; ii++) { ChatGlyph rec = glyphs.get(ii); _target.abortAnimation(rec); } } else if (!glyphs.isEmpty()) { log.warning("No target to abort chat animations"); } glyphs.clear(); }
java
protected void clearGlyphs (List<ChatGlyph> glyphs) { if (_target != null) { for (int ii = 0, nn = glyphs.size(); ii < nn; ii++) { ChatGlyph rec = glyphs.get(ii); _target.abortAnimation(rec); } } else if (!glyphs.isEmpty()) { log.warning("No target to abort chat animations"); } glyphs.clear(); }
[ "protected", "void", "clearGlyphs", "(", "List", "<", "ChatGlyph", ">", "glyphs", ")", "{", "if", "(", "_target", "!=", "null", ")", "{", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "glyphs", ".", "size", "(", ")", ";", "ii", "<", "nn", ...
Clears out the supplied list of chat glyphs.
[ "Clears", "out", "the", "supplied", "list", "of", "chat", "glyphs", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L542-L554
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.displayMessage
protected void displayMessage (ChatMessage message, Graphics2D gfx) { // get the non-history message type... int type = getType(message, false); if (type != ChatLogic.IGNORECHAT) { // display it now displayMessage(message, type, gfx); } }
java
protected void displayMessage (ChatMessage message, Graphics2D gfx) { // get the non-history message type... int type = getType(message, false); if (type != ChatLogic.IGNORECHAT) { // display it now displayMessage(message, type, gfx); } }
[ "protected", "void", "displayMessage", "(", "ChatMessage", "message", ",", "Graphics2D", "gfx", ")", "{", "// get the non-history message type...", "int", "type", "=", "getType", "(", "message", ",", "false", ")", ";", "if", "(", "type", "!=", "ChatLogic", ".", ...
Display the specified message now, unless we are to ignore it.
[ "Display", "the", "specified", "message", "now", "unless", "we", "are", "to", "ignore", "it", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L559-L567
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.displayMessage
protected void displayMessage (ChatMessage message, int type, Graphics2D layoutGfx) { // if we're in history mode, this will show up in the history and we'll rebuild our // subtitle list if and when history goes away if (isHistoryMode()) { return; } addSubtitle(createSubtitle(message, type, layoutGfx, true)); }
java
protected void displayMessage (ChatMessage message, int type, Graphics2D layoutGfx) { // if we're in history mode, this will show up in the history and we'll rebuild our // subtitle list if and when history goes away if (isHistoryMode()) { return; } addSubtitle(createSubtitle(message, type, layoutGfx, true)); }
[ "protected", "void", "displayMessage", "(", "ChatMessage", "message", ",", "int", "type", ",", "Graphics2D", "layoutGfx", ")", "{", "// if we're in history mode, this will show up in the history and we'll rebuild our", "// subtitle list if and when history goes away", "if", "(", ...
Display the message after we've decided which type it is.
[ "Display", "the", "message", "after", "we", "ve", "decided", "which", "type", "it", "is", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L572-L580
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.addSubtitle
protected void addSubtitle (ChatGlyph rec) { // scroll up the old subtitles Rectangle r = rec.getBounds(); scrollUpSubtitles(-r.height - _logic.getSubtitleSpacing(rec.getType())); // put this one in place Rectangle vbounds = _target.getViewBounds(); rec.setLocation(vbounds.x + _subtitleXSpacing, vbounds.y + vbounds.height - _subtitleYSpacing - r.height); // add it to our list and to our media panel rec.setDim(_dimmed); _subtitles.add(rec); _target.addAnimation(rec); }
java
protected void addSubtitle (ChatGlyph rec) { // scroll up the old subtitles Rectangle r = rec.getBounds(); scrollUpSubtitles(-r.height - _logic.getSubtitleSpacing(rec.getType())); // put this one in place Rectangle vbounds = _target.getViewBounds(); rec.setLocation(vbounds.x + _subtitleXSpacing, vbounds.y + vbounds.height - _subtitleYSpacing - r.height); // add it to our list and to our media panel rec.setDim(_dimmed); _subtitles.add(rec); _target.addAnimation(rec); }
[ "protected", "void", "addSubtitle", "(", "ChatGlyph", "rec", ")", "{", "// scroll up the old subtitles", "Rectangle", "r", "=", "rec", ".", "getBounds", "(", ")", ";", "scrollUpSubtitles", "(", "-", "r", ".", "height", "-", "_logic", ".", "getSubtitleSpacing", ...
Add a subtitle for display now.
[ "Add", "a", "subtitle", "for", "display", "now", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L585-L600
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.createSubtitle
protected ChatGlyph createSubtitle (ChatMessage message, int type, Graphics2D layoutGfx, boolean expires) { // we might need to modify the textual part with translations, but we can't do that to the // message object, since other chatdisplays also get it. String text = message.message; Tuple<String, Boolean> finfo = _logic.decodeFormat(type, message.getFormat()); String format = finfo.left; boolean quotes = finfo.right; // now format the text if (format != null) { if (quotes) { text = "\"" + text + "\""; } text = " " + text; text = xlate(MessageBundle.tcompose( format, ((UserMessage) message).getSpeakerDisplayName())) + text; } return createSubtitle(layoutGfx, type, message.timestamp, null, 0, text, expires); }
java
protected ChatGlyph createSubtitle (ChatMessage message, int type, Graphics2D layoutGfx, boolean expires) { // we might need to modify the textual part with translations, but we can't do that to the // message object, since other chatdisplays also get it. String text = message.message; Tuple<String, Boolean> finfo = _logic.decodeFormat(type, message.getFormat()); String format = finfo.left; boolean quotes = finfo.right; // now format the text if (format != null) { if (quotes) { text = "\"" + text + "\""; } text = " " + text; text = xlate(MessageBundle.tcompose( format, ((UserMessage) message).getSpeakerDisplayName())) + text; } return createSubtitle(layoutGfx, type, message.timestamp, null, 0, text, expires); }
[ "protected", "ChatGlyph", "createSubtitle", "(", "ChatMessage", "message", ",", "int", "type", ",", "Graphics2D", "layoutGfx", ",", "boolean", "expires", ")", "{", "// we might need to modify the textual part with translations, but we can't do that to the", "// message object, si...
Create a subtitle, but don't do anything funny with it.
[ "Create", "a", "subtitle", "but", "don", "t", "do", "anything", "funny", "with", "it", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L605-L626
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.createSubtitle
protected ChatGlyph createSubtitle (Graphics2D gfx, int type, long timestamp, Icon icon, int indent, String text, boolean expires) { Dimension is = new Dimension(); if (icon != null) { is.setSize(icon.getIconWidth(), icon.getIconHeight()); } Rectangle vbounds = _target.getViewBounds(); Label label = _logic.createLabel(text); label.setFont(_logic.getFont(type)); int paddedIconWidth = (icon == null) ? 0 : is.width + ICON_PADDING; label.setTargetWidth( vbounds.width - indent - paddedIconWidth - 2 * (_subtitleXSpacing + Math.max(UIManager.getInt("ScrollBar.width"), PAD))); label.layout(gfx); gfx.dispose(); Dimension ls = label.getSize(); Rectangle r = new Rectangle(0, 0, ls.width + indent + paddedIconWidth, Math.max(is.height, ls.height)); r.grow(0, 1); Point iconpos = r.getLocation(); iconpos.translate(indent, r.height - is.height - 1); Point labelpos = r.getLocation(); labelpos.translate(indent + paddedIconWidth, 1); Rectangle lr = new Rectangle(r.x + indent + paddedIconWidth, r.y, r.width - indent - paddedIconWidth, ls.height + 2); // last a really long time if we're not supposed to expire long lifetime = Integer.MAX_VALUE; if (expires) { lifetime = getChatExpire(timestamp, label.getText()) - timestamp; } Shape shape = _logic.getSubtitleShape(type, lr, r); return new ChatGlyph(this, type, lifetime, r.union(shape.getBounds()), shape, icon, iconpos, label, labelpos, _logic.getOutlineColor(type)); }
java
protected ChatGlyph createSubtitle (Graphics2D gfx, int type, long timestamp, Icon icon, int indent, String text, boolean expires) { Dimension is = new Dimension(); if (icon != null) { is.setSize(icon.getIconWidth(), icon.getIconHeight()); } Rectangle vbounds = _target.getViewBounds(); Label label = _logic.createLabel(text); label.setFont(_logic.getFont(type)); int paddedIconWidth = (icon == null) ? 0 : is.width + ICON_PADDING; label.setTargetWidth( vbounds.width - indent - paddedIconWidth - 2 * (_subtitleXSpacing + Math.max(UIManager.getInt("ScrollBar.width"), PAD))); label.layout(gfx); gfx.dispose(); Dimension ls = label.getSize(); Rectangle r = new Rectangle(0, 0, ls.width + indent + paddedIconWidth, Math.max(is.height, ls.height)); r.grow(0, 1); Point iconpos = r.getLocation(); iconpos.translate(indent, r.height - is.height - 1); Point labelpos = r.getLocation(); labelpos.translate(indent + paddedIconWidth, 1); Rectangle lr = new Rectangle(r.x + indent + paddedIconWidth, r.y, r.width - indent - paddedIconWidth, ls.height + 2); // last a really long time if we're not supposed to expire long lifetime = Integer.MAX_VALUE; if (expires) { lifetime = getChatExpire(timestamp, label.getText()) - timestamp; } Shape shape = _logic.getSubtitleShape(type, lr, r); return new ChatGlyph(this, type, lifetime, r.union(shape.getBounds()), shape, icon, iconpos, label, labelpos, _logic.getOutlineColor(type)); }
[ "protected", "ChatGlyph", "createSubtitle", "(", "Graphics2D", "gfx", ",", "int", "type", ",", "long", "timestamp", ",", "Icon", "icon", ",", "int", "indent", ",", "String", "text", ",", "boolean", "expires", ")", "{", "Dimension", "is", "=", "new", "Dimen...
Create a subtitle- a line of text that goes on the bottom.
[ "Create", "a", "subtitle", "-", "a", "line", "of", "text", "that", "goes", "on", "the", "bottom", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L631-L668
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.getChatExpire
protected long getChatExpire (long timestamp, String text) { long[] durations = _logic.getDisplayDurations(getDisplayDurationOffset()); // start the computation from the maximum of the timestamp or our last expire time long start = Math.max(timestamp, _lastExpire); // set the next expire to a time proportional to the text length _lastExpire = start + Math.min(text.length() * durations[0], durations[2]); // but don't let it be longer than the maximum display time _lastExpire = Math.min(timestamp + durations[2], _lastExpire); // and be sure to pop up the returned time so that it is above the min return Math.max(timestamp + durations[1], _lastExpire); }
java
protected long getChatExpire (long timestamp, String text) { long[] durations = _logic.getDisplayDurations(getDisplayDurationOffset()); // start the computation from the maximum of the timestamp or our last expire time long start = Math.max(timestamp, _lastExpire); // set the next expire to a time proportional to the text length _lastExpire = start + Math.min(text.length() * durations[0], durations[2]); // but don't let it be longer than the maximum display time _lastExpire = Math.min(timestamp + durations[2], _lastExpire); // and be sure to pop up the returned time so that it is above the min return Math.max(timestamp + durations[1], _lastExpire); }
[ "protected", "long", "getChatExpire", "(", "long", "timestamp", ",", "String", "text", ")", "{", "long", "[", "]", "durations", "=", "_logic", ".", "getDisplayDurations", "(", "getDisplayDurationOffset", "(", ")", ")", ";", "// start the computation from the maximum...
Get the expire time for the specified chat.
[ "Get", "the", "expire", "time", "for", "the", "specified", "chat", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L673-L684
train
threerings/nenya
core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java
SubtitleChatOverlay.scrollUpSubtitles
protected void scrollUpSubtitles (int dy) { // dirty and move all the old glyphs Rectangle vbounds = _target.getViewBounds(); int miny = vbounds.y + vbounds.height - _subtitleHeight; for (Iterator<ChatGlyph> iter = _subtitles.iterator(); iter.hasNext();) { ChatGlyph sub = iter.next(); sub.translate(0, dy); if (sub.getBounds().y <= miny) { iter.remove(); _target.abortAnimation(sub); } } }
java
protected void scrollUpSubtitles (int dy) { // dirty and move all the old glyphs Rectangle vbounds = _target.getViewBounds(); int miny = vbounds.y + vbounds.height - _subtitleHeight; for (Iterator<ChatGlyph> iter = _subtitles.iterator(); iter.hasNext();) { ChatGlyph sub = iter.next(); sub.translate(0, dy); if (sub.getBounds().y <= miny) { iter.remove(); _target.abortAnimation(sub); } } }
[ "protected", "void", "scrollUpSubtitles", "(", "int", "dy", ")", "{", "// dirty and move all the old glyphs", "Rectangle", "vbounds", "=", "_target", ".", "getViewBounds", "(", ")", ";", "int", "miny", "=", "vbounds", ".", "y", "+", "vbounds", ".", "height", "...
Scroll all the subtitles up by the specified amount.
[ "Scroll", "all", "the", "subtitles", "up", "by", "the", "specified", "amount", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/chat/SubtitleChatOverlay.java#L762-L775
train
jdillon/gshell
gshell-core/src/main/java/com/planet57/gshell/internal/completer/ShellCompleter.java
ShellCompleter.extractCommandArguments
private static ParsedLine extractCommandArguments(final ParsedLine line) { // copy the list, so we can mutate and pop the first item off LinkedList<String> words = Lists.newLinkedList(line.words()); String remove = words.pop(); String rawLine = line.line(); // rebuild that list sans the first argument if (remove.length() > rawLine.length()) { return new DefaultParser.ArgumentList( rawLine.substring(remove.length() + 1, rawLine.length()), words, line.wordIndex() - 1, line.wordCursor(), line.cursor() - remove.length() + 1 ); } else { return new DefaultParser.ArgumentList("", Collections.emptyList(), 0, 0, 0); } }
java
private static ParsedLine extractCommandArguments(final ParsedLine line) { // copy the list, so we can mutate and pop the first item off LinkedList<String> words = Lists.newLinkedList(line.words()); String remove = words.pop(); String rawLine = line.line(); // rebuild that list sans the first argument if (remove.length() > rawLine.length()) { return new DefaultParser.ArgumentList( rawLine.substring(remove.length() + 1, rawLine.length()), words, line.wordIndex() - 1, line.wordCursor(), line.cursor() - remove.length() + 1 ); } else { return new DefaultParser.ArgumentList("", Collections.emptyList(), 0, 0, 0); } }
[ "private", "static", "ParsedLine", "extractCommandArguments", "(", "final", "ParsedLine", "line", ")", "{", "// copy the list, so we can mutate and pop the first item off", "LinkedList", "<", "String", ">", "words", "=", "Lists", ".", "newLinkedList", "(", "line", ".", ...
Extract the command specific portions of the given line. This is everything past the first word.
[ "Extract", "the", "command", "specific", "portions", "of", "the", "given", "line", "." ]
b587c1a4672d2e4905871462fa3b38a1f7b94e90
https://github.com/jdillon/gshell/blob/b587c1a4672d2e4905871462fa3b38a1f7b94e90/gshell-core/src/main/java/com/planet57/gshell/internal/completer/ShellCompleter.java#L120-L139
train
threerings/nenya
tools/src/main/java/com/threerings/media/tools/RecolorImage.java
RecolorImage.convert
protected void convert () { if (_image == null) { return; } // obtain the target color and offset try { BufferedImage image; if (_tabs.getSelectedIndex() == 0) { // All recolorings from file. image = getAllRecolors(_labelColors.isSelected()); if (image == null) { return; } } else if (_tabs.getSelectedIndex() == 1) { ArrayList<Colorization> zations = Lists.newArrayList(); if (_classList1.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList1.getSelectedItem(), (String)_colorList1.getSelectedItem())); } if (_classList2.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList2.getSelectedItem(), (String)_colorList2.getSelectedItem())); } if (_classList3.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList3.getSelectedItem(), (String)_colorList3.getSelectedItem())); } if (_classList4.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList4.getSelectedItem(), (String)_colorList4.getSelectedItem())); } image = ImageUtil.recolorImage(_image, zations.toArray(new Colorization[zations.size()])); } else { // Manual recoloring int color = Integer.parseInt(_source.getText(), 16); float hueD = _hueD.getValue(); float satD = _saturationD.getValue(); float valD = _valueD.getValue(); float[] dists = new float[] { hueD, satD, valD }; float hueO = _hueO.getValue(); float satO = _saturationO.getValue(); float valO = _valueO.getValue(); float[] offsets = new float[] { hueO, satO, valO }; image = ImageUtil.recolorImage(_image, new Color(color), dists, offsets); } _newImage.setIcon(new ImageIcon(image)); _status.setText("Recolored image."); repaint(); } catch (NumberFormatException nfe) { _status.setText("Invalid value: " + nfe.getMessage()); } }
java
protected void convert () { if (_image == null) { return; } // obtain the target color and offset try { BufferedImage image; if (_tabs.getSelectedIndex() == 0) { // All recolorings from file. image = getAllRecolors(_labelColors.isSelected()); if (image == null) { return; } } else if (_tabs.getSelectedIndex() == 1) { ArrayList<Colorization> zations = Lists.newArrayList(); if (_classList1.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList1.getSelectedItem(), (String)_colorList1.getSelectedItem())); } if (_classList2.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList2.getSelectedItem(), (String)_colorList2.getSelectedItem())); } if (_classList3.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList3.getSelectedItem(), (String)_colorList3.getSelectedItem())); } if (_classList4.getSelectedItem() != NONE) { zations.add(_colRepo.getColorization((String)_classList4.getSelectedItem(), (String)_colorList4.getSelectedItem())); } image = ImageUtil.recolorImage(_image, zations.toArray(new Colorization[zations.size()])); } else { // Manual recoloring int color = Integer.parseInt(_source.getText(), 16); float hueD = _hueD.getValue(); float satD = _saturationD.getValue(); float valD = _valueD.getValue(); float[] dists = new float[] { hueD, satD, valD }; float hueO = _hueO.getValue(); float satO = _saturationO.getValue(); float valO = _valueO.getValue(); float[] offsets = new float[] { hueO, satO, valO }; image = ImageUtil.recolorImage(_image, new Color(color), dists, offsets); } _newImage.setIcon(new ImageIcon(image)); _status.setText("Recolored image."); repaint(); } catch (NumberFormatException nfe) { _status.setText("Invalid value: " + nfe.getMessage()); } }
[ "protected", "void", "convert", "(", ")", "{", "if", "(", "_image", "==", "null", ")", "{", "return", ";", "}", "// obtain the target color and offset", "try", "{", "BufferedImage", "image", ";", "if", "(", "_tabs", ".", "getSelectedIndex", "(", ")", "==", ...
Performs colorizations.
[ "Performs", "colorizations", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/tools/src/main/java/com/threerings/media/tools/RecolorImage.java#L227-L286
train
threerings/nenya
tools/src/main/java/com/threerings/media/tools/RecolorImage.java
RecolorImage.getAllRecolors
public BufferedImage getAllRecolors (boolean label) { if (_colRepo == null) { return null; } ColorPository.ClassRecord colClass = _colRepo.getClassRecord((String)_classList.getSelectedItem()); int classId = colClass.classId; BufferedImage img = new BufferedImage(_image.getWidth(), _image.getHeight()*colClass.colors.size(), BufferedImage.TYPE_INT_ARGB); Graphics gfx = img.getGraphics(); gfx.setColor(Color.BLACK); int y = 0; Integer[] sortedKeys = colClass.colors.keySet().toArray(new Integer[colClass.colors.size()]); Arrays.sort(sortedKeys); for (int key : sortedKeys) { Colorization coloriz = _colRepo.getColorization(classId, key); BufferedImage subImg = ImageUtil.recolorImage( _image, coloriz.rootColor, coloriz.range, coloriz.offsets); gfx.drawImage(subImg, 0, y, null, null); if (label) { ColorRecord crec = _colRepo.getColorRecord(classId, key); gfx.drawString(crec.name, 2, y + gfx.getFontMetrics().getHeight() + 2); gfx.drawRect(0, y, _image.getWidth() - 1, _image.getHeight()); } y += subImg.getHeight(); } return img; }
java
public BufferedImage getAllRecolors (boolean label) { if (_colRepo == null) { return null; } ColorPository.ClassRecord colClass = _colRepo.getClassRecord((String)_classList.getSelectedItem()); int classId = colClass.classId; BufferedImage img = new BufferedImage(_image.getWidth(), _image.getHeight()*colClass.colors.size(), BufferedImage.TYPE_INT_ARGB); Graphics gfx = img.getGraphics(); gfx.setColor(Color.BLACK); int y = 0; Integer[] sortedKeys = colClass.colors.keySet().toArray(new Integer[colClass.colors.size()]); Arrays.sort(sortedKeys); for (int key : sortedKeys) { Colorization coloriz = _colRepo.getColorization(classId, key); BufferedImage subImg = ImageUtil.recolorImage( _image, coloriz.rootColor, coloriz.range, coloriz.offsets); gfx.drawImage(subImg, 0, y, null, null); if (label) { ColorRecord crec = _colRepo.getColorRecord(classId, key); gfx.drawString(crec.name, 2, y + gfx.getFontMetrics().getHeight() + 2); gfx.drawRect(0, y, _image.getWidth() - 1, _image.getHeight()); } y += subImg.getHeight(); } return img; }
[ "public", "BufferedImage", "getAllRecolors", "(", "boolean", "label", ")", "{", "if", "(", "_colRepo", "==", "null", ")", "{", "return", "null", ";", "}", "ColorPository", ".", "ClassRecord", "colClass", "=", "_colRepo", ".", "getClassRecord", "(", "(", "Str...
Gets an image with all recolorings of the selection colorization class.
[ "Gets", "an", "image", "with", "all", "recolorings", "of", "the", "selection", "colorization", "class", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/tools/src/main/java/com/threerings/media/tools/RecolorImage.java#L291-L329
train
threerings/nenya
tools/src/main/java/com/threerings/media/tools/RecolorImage.java
RecolorImage.setColorizeFile
public void setColorizeFile (File path) { try { if (path.getName().endsWith("xml")) { ColorPositoryParser parser = new ColorPositoryParser(); _colRepo = (ColorPository)(parser.parseConfig(path)); } else { _colRepo = ColorPository.loadColorPository(new FileInputStream(path)); } _classList.removeAllItems(); _classList1.removeAllItems(); _classList1.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList1, (String)_classList1.getSelectedItem()); } }); _classList2.removeAllItems(); _classList2.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList2, (String)_classList2.getSelectedItem()); } }); _classList3.removeAllItems(); _classList3.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList3, (String)_classList3.getSelectedItem()); } }); _classList4.removeAllItems(); _classList4.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList4, (String)_classList4.getSelectedItem()); } }); Iterator<ColorPository.ClassRecord> iter = _colRepo.enumerateClasses(); ArrayList<String> names = Lists.newArrayList(); while (iter.hasNext()) { String str = iter.next().name; names.add(str); } _classList1.addItem(NONE); _classList2.addItem(NONE); _classList3.addItem(NONE); _classList4.addItem(NONE); Collections.sort(names); for (String name : names) { _classList.addItem(name); _classList1.addItem(name); _classList2.addItem(name); _classList3.addItem(name); _classList4.addItem(name); } _classList.setSelectedIndex(0); _classList1.setSelectedIndex(0); _classList2.setSelectedIndex(0); _classList3.setSelectedIndex(0); _classList4.setSelectedIndex(0); _colFilePath.setText(path.getPath()); CONFIG.setValue(LAST_COLORIZATION_KEY, path.getAbsolutePath()); } catch (Exception ex) { _status.setText("Error opening colorization file: " + ex); } }
java
public void setColorizeFile (File path) { try { if (path.getName().endsWith("xml")) { ColorPositoryParser parser = new ColorPositoryParser(); _colRepo = (ColorPository)(parser.parseConfig(path)); } else { _colRepo = ColorPository.loadColorPository(new FileInputStream(path)); } _classList.removeAllItems(); _classList1.removeAllItems(); _classList1.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList1, (String)_classList1.getSelectedItem()); } }); _classList2.removeAllItems(); _classList2.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList2, (String)_classList2.getSelectedItem()); } }); _classList3.removeAllItems(); _classList3.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList3, (String)_classList3.getSelectedItem()); } }); _classList4.removeAllItems(); _classList4.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { setupColors(_colorList4, (String)_classList4.getSelectedItem()); } }); Iterator<ColorPository.ClassRecord> iter = _colRepo.enumerateClasses(); ArrayList<String> names = Lists.newArrayList(); while (iter.hasNext()) { String str = iter.next().name; names.add(str); } _classList1.addItem(NONE); _classList2.addItem(NONE); _classList3.addItem(NONE); _classList4.addItem(NONE); Collections.sort(names); for (String name : names) { _classList.addItem(name); _classList1.addItem(name); _classList2.addItem(name); _classList3.addItem(name); _classList4.addItem(name); } _classList.setSelectedIndex(0); _classList1.setSelectedIndex(0); _classList2.setSelectedIndex(0); _classList3.setSelectedIndex(0); _classList4.setSelectedIndex(0); _colFilePath.setText(path.getPath()); CONFIG.setValue(LAST_COLORIZATION_KEY, path.getAbsolutePath()); } catch (Exception ex) { _status.setText("Error opening colorization file: " + ex); } }
[ "public", "void", "setColorizeFile", "(", "File", "path", ")", "{", "try", "{", "if", "(", "path", ".", "getName", "(", ")", ".", "endsWith", "(", "\"xml\"", ")", ")", "{", "ColorPositoryParser", "parser", "=", "new", "ColorPositoryParser", "(", ")", ";"...
Loads up the colorization classes from the specified file.
[ "Loads", "up", "the", "colorization", "classes", "from", "the", "specified", "file", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/tools/src/main/java/com/threerings/media/tools/RecolorImage.java#L426-L493
train
kaazing/java.client
ws/ws/src/main/java/org/kaazing/gateway/client/util/StringUtils.java
StringUtils.stripControlCharacters
public static String stripControlCharacters(String rawValue) { if (rawValue == null) { return null; } String value = replaceEntities(rawValue); boolean hasControlChars = false; for (int i = value.length() - 1; i >= 0; i--) { if (Character.isISOControl(value.charAt(i))) { hasControlChars = true; break; } } if (!hasControlChars) { return value; } StringBuilder buf = new StringBuilder(value.length()); int i = 0; // Skip initial control characters (i.e. left trim) for (; i < value.length(); i++) { if (!Character.isISOControl(value.charAt(i))) { break; } } // Copy non control characters and substitute control characters with // a space. The last control characters are trimmed. boolean suppressingControlChars = false; for (; i < value.length(); i++) { if (Character.isISOControl(value.charAt(i))) { suppressingControlChars = true; continue; } else { if (suppressingControlChars) { suppressingControlChars = false; buf.append(' '); } buf.append(value.charAt(i)); } } return buf.toString(); }
java
public static String stripControlCharacters(String rawValue) { if (rawValue == null) { return null; } String value = replaceEntities(rawValue); boolean hasControlChars = false; for (int i = value.length() - 1; i >= 0; i--) { if (Character.isISOControl(value.charAt(i))) { hasControlChars = true; break; } } if (!hasControlChars) { return value; } StringBuilder buf = new StringBuilder(value.length()); int i = 0; // Skip initial control characters (i.e. left trim) for (; i < value.length(); i++) { if (!Character.isISOControl(value.charAt(i))) { break; } } // Copy non control characters and substitute control characters with // a space. The last control characters are trimmed. boolean suppressingControlChars = false; for (; i < value.length(); i++) { if (Character.isISOControl(value.charAt(i))) { suppressingControlChars = true; continue; } else { if (suppressingControlChars) { suppressingControlChars = false; buf.append(' '); } buf.append(value.charAt(i)); } } return buf.toString(); }
[ "public", "static", "String", "stripControlCharacters", "(", "String", "rawValue", ")", "{", "if", "(", "rawValue", "==", "null", ")", "{", "return", "null", ";", "}", "String", "value", "=", "replaceEntities", "(", "rawValue", ")", ";", "boolean", "hasContr...
Strip a String of it's ISO control characters. @param value The String that should be stripped. @return {@code String} A new String instance with its hexadecimal control characters replaced by a space. Or the unmodified String if it does not contain any ISO control characters.
[ "Strip", "a", "String", "of", "it", "s", "ISO", "control", "characters", "." ]
25ad2ae5bb24aa9d6b79400fce649b518dcfbe26
https://github.com/kaazing/java.client/blob/25ad2ae5bb24aa9d6b79400fce649b518dcfbe26/ws/ws/src/main/java/org/kaazing/gateway/client/util/StringUtils.java#L49-L95
train
threerings/nenya
core/src/main/java/com/threerings/resource/FastImageIO.java
FastImageIO.write
public static void write (BufferedImage image, OutputStream out) throws IOException { DataOutputStream dout = new DataOutputStream(out); // write the image dimensions int width = image.getWidth(), height = image.getHeight(); dout.writeInt(width); dout.writeInt(height); // write the color model information IndexColorModel cmodel = (IndexColorModel)image.getColorModel(); int tpixel = cmodel.getTransparentPixel(); dout.writeInt(tpixel); int msize = cmodel.getMapSize(); int[] map = new int[msize]; cmodel.getRGBs(map); dout.writeInt(msize); for (int element : map) { dout.writeInt(element); } // write the raster data DataBufferByte dbuf = (DataBufferByte)image.getRaster().getDataBuffer(); byte[] data = dbuf.getData(); if (data.length != width * height) { String errmsg = "Raster data not same size as image! [" + width + "x" + height + " != " + data.length + "]"; throw new IllegalStateException(errmsg); } dout.write(data); dout.flush(); }
java
public static void write (BufferedImage image, OutputStream out) throws IOException { DataOutputStream dout = new DataOutputStream(out); // write the image dimensions int width = image.getWidth(), height = image.getHeight(); dout.writeInt(width); dout.writeInt(height); // write the color model information IndexColorModel cmodel = (IndexColorModel)image.getColorModel(); int tpixel = cmodel.getTransparentPixel(); dout.writeInt(tpixel); int msize = cmodel.getMapSize(); int[] map = new int[msize]; cmodel.getRGBs(map); dout.writeInt(msize); for (int element : map) { dout.writeInt(element); } // write the raster data DataBufferByte dbuf = (DataBufferByte)image.getRaster().getDataBuffer(); byte[] data = dbuf.getData(); if (data.length != width * height) { String errmsg = "Raster data not same size as image! [" + width + "x" + height + " != " + data.length + "]"; throw new IllegalStateException(errmsg); } dout.write(data); dout.flush(); }
[ "public", "static", "void", "write", "(", "BufferedImage", "image", ",", "OutputStream", "out", ")", "throws", "IOException", "{", "DataOutputStream", "dout", "=", "new", "DataOutputStream", "(", "out", ")", ";", "// write the image dimensions", "int", "width", "=...
Writes the supplied image to the supplied output stream. @exception IOException thrown if an error occurs writing to the output stream.
[ "Writes", "the", "supplied", "image", "to", "the", "supplied", "output", "stream", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/resource/FastImageIO.java#L71-L103
train
kaazing/java.client
amqp-0-9-1/amqp/src/main/java/org/kaazing/net/ws/amqp/AmqpArguments.java
AmqpArguments.getEntries
public List<AmqpTableEntry> getEntries(String key) { if ((key == null) || (tableEntryArray == null)) { return null; } List<AmqpTableEntry> entries = new ArrayList<AmqpTableEntry>(); for (AmqpTableEntry entry : tableEntryArray) { if (entry.key.equals(key)) { entries.add(entry); } } return entries; }
java
public List<AmqpTableEntry> getEntries(String key) { if ((key == null) || (tableEntryArray == null)) { return null; } List<AmqpTableEntry> entries = new ArrayList<AmqpTableEntry>(); for (AmqpTableEntry entry : tableEntryArray) { if (entry.key.equals(key)) { entries.add(entry); } } return entries; }
[ "public", "List", "<", "AmqpTableEntry", ">", "getEntries", "(", "String", "key", ")", "{", "if", "(", "(", "key", "==", "null", ")", "||", "(", "tableEntryArray", "==", "null", ")", ")", "{", "return", "null", ";", "}", "List", "<", "AmqpTableEntry", ...
Returns a list of AmqpTableEntry objects that matches the specified key. If a null key is passed in, then a null is returned. Also, if the internal structure is null, then a null is returned. @param key name of the entry @return List<AmqpTableEntry> object with matching key
[ "Returns", "a", "list", "of", "AmqpTableEntry", "objects", "that", "matches", "the", "specified", "key", ".", "If", "a", "null", "key", "is", "passed", "in", "then", "a", "null", "is", "returned", ".", "Also", "if", "the", "internal", "structure", "is", ...
25ad2ae5bb24aa9d6b79400fce649b518dcfbe26
https://github.com/kaazing/java.client/blob/25ad2ae5bb24aa9d6b79400fce649b518dcfbe26/amqp-0-9-1/amqp/src/main/java/org/kaazing/net/ws/amqp/AmqpArguments.java#L158-L170
train
vdurmont/etaprinter
src/main/java/com/vdurmont/etaprinter/ETAPrinter.java
ETAPrinter.update
public void update(long numProcessedDuringStep) { if (this.closed) { throw new ETAPrinterException("You cannot update a closed ETAPrinter!"); } DateTime now = DateTime.now(); ItemsDuration itemsDuration = null; if (numProcessedDuringStep > 0) { long stepDuration = new Duration(this.lastStep, now).getMillis(); int numItems = 1; do { long duration = stepDuration / (numProcessedDuringStep / numItems); itemsDuration = new ItemsDuration(numItems, duration); numItems++; } while (itemsDuration.durationMillis == 0); } this.lastStep = now; this.numProcessed += numProcessedDuringStep; if (this.numProcessed == this.totalElementsToProcess) { this.close(); } else { this.print(itemsDuration); } }
java
public void update(long numProcessedDuringStep) { if (this.closed) { throw new ETAPrinterException("You cannot update a closed ETAPrinter!"); } DateTime now = DateTime.now(); ItemsDuration itemsDuration = null; if (numProcessedDuringStep > 0) { long stepDuration = new Duration(this.lastStep, now).getMillis(); int numItems = 1; do { long duration = stepDuration / (numProcessedDuringStep / numItems); itemsDuration = new ItemsDuration(numItems, duration); numItems++; } while (itemsDuration.durationMillis == 0); } this.lastStep = now; this.numProcessed += numProcessedDuringStep; if (this.numProcessed == this.totalElementsToProcess) { this.close(); } else { this.print(itemsDuration); } }
[ "public", "void", "update", "(", "long", "numProcessedDuringStep", ")", "{", "if", "(", "this", ".", "closed", ")", "{", "throw", "new", "ETAPrinterException", "(", "\"You cannot update a closed ETAPrinter!\"", ")", ";", "}", "DateTime", "now", "=", "DateTime", ...
Updates and prints the progress bar with the new values. @param numProcessedDuringStep the number of items processed during the elapsed step
[ "Updates", "and", "prints", "the", "progress", "bar", "with", "the", "new", "values", "." ]
19039bdbbece8b05ceab2a23757f4e1e8b6872cb
https://github.com/vdurmont/etaprinter/blob/19039bdbbece8b05ceab2a23757f4e1e8b6872cb/src/main/java/com/vdurmont/etaprinter/ETAPrinter.java#L109-L131
train
jboss/jboss-jsp-api_spec
src/main/java/javax/servlet/jsp/tagext/TagAttributeInfo.java
TagAttributeInfo.getIdAttribute
public static TagAttributeInfo getIdAttribute(TagAttributeInfo a[]) { for (int i=0; i<a.length; i++) { if (a[i].getName().equals(ID)) { return a[i]; } } return null; // no such attribute }
java
public static TagAttributeInfo getIdAttribute(TagAttributeInfo a[]) { for (int i=0; i<a.length; i++) { if (a[i].getName().equals(ID)) { return a[i]; } } return null; // no such attribute }
[ "public", "static", "TagAttributeInfo", "getIdAttribute", "(", "TagAttributeInfo", "a", "[", "]", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "a", ".", "length", ";", "i", "++", ")", "{", "if", "(", "a", "[", "i", "]", ".", "getNam...
Convenience static method that goes through an array of TagAttributeInfo objects and looks for "id". @param a An array of TagAttributeInfo @return The TagAttributeInfo reference with name "id"
[ "Convenience", "static", "method", "that", "goes", "through", "an", "array", "of", "TagAttributeInfo", "objects", "and", "looks", "for", "id", "." ]
da53166619f33a5134dc3315a3264990cc1f541f
https://github.com/jboss/jboss-jsp-api_spec/blob/da53166619f33a5134dc3315a3264990cc1f541f/src/main/java/javax/servlet/jsp/tagext/TagAttributeInfo.java#L221-L228
train
calrissian/mango
mango-criteria/src/main/java/org/calrissian/mango/criteria/domain/TypedTermLeaf.java
TypedTermLeaf.firstKnownType
protected static <T> Class<T> firstKnownType(T... objects) { for (T obj : objects) if (obj != null) return (Class<T>) obj.getClass(); return null; }
java
protected static <T> Class<T> firstKnownType(T... objects) { for (T obj : objects) if (obj != null) return (Class<T>) obj.getClass(); return null; }
[ "protected", "static", "<", "T", ">", "Class", "<", "T", ">", "firstKnownType", "(", "T", "...", "objects", ")", "{", "for", "(", "T", "obj", ":", "objects", ")", "if", "(", "obj", "!=", "null", ")", "return", "(", "Class", "<", "T", ">", ")", ...
Utility method to allow subclasses to extract type from known variables.
[ "Utility", "method", "to", "allow", "subclasses", "to", "extract", "type", "from", "known", "variables", "." ]
a95aa5e77af9aa0e629787228d80806560023452
https://github.com/calrissian/mango/blob/a95aa5e77af9aa0e629787228d80806560023452/mango-criteria/src/main/java/org/calrissian/mango/criteria/domain/TypedTermLeaf.java#L24-L29
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.enumerateColors
public ColorRecord[] enumerateColors (String className) { // make sure the class exists ClassRecord record = getClassRecord(className); if (record == null) { return null; } // create the array ColorRecord[] crecs = new ColorRecord[record.colors.size()]; Iterator<ColorRecord> iter = record.colors.values().iterator(); for (int ii = 0; iter.hasNext(); ii++) { crecs[ii] = iter.next(); } return crecs; }
java
public ColorRecord[] enumerateColors (String className) { // make sure the class exists ClassRecord record = getClassRecord(className); if (record == null) { return null; } // create the array ColorRecord[] crecs = new ColorRecord[record.colors.size()]; Iterator<ColorRecord> iter = record.colors.values().iterator(); for (int ii = 0; iter.hasNext(); ii++) { crecs[ii] = iter.next(); } return crecs; }
[ "public", "ColorRecord", "[", "]", "enumerateColors", "(", "String", "className", ")", "{", "// make sure the class exists", "ClassRecord", "record", "=", "getClassRecord", "(", "className", ")", ";", "if", "(", "record", "==", "null", ")", "{", "return", "null"...
Returns an array containing the records for the colors in the specified class.
[ "Returns", "an", "array", "containing", "the", "records", "for", "the", "colors", "in", "the", "specified", "class", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L288-L303
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.enumerateColorIds
public int[] enumerateColorIds (String className) { // make sure the class exists ClassRecord record = getClassRecord(className); if (record == null) { return null; } int[] cids = new int[record.colors.size()]; Iterator<ColorRecord> crecs = record.colors.values().iterator(); for (int ii = 0; crecs.hasNext(); ii++) { cids[ii] = crecs.next().colorId; } return cids; }
java
public int[] enumerateColorIds (String className) { // make sure the class exists ClassRecord record = getClassRecord(className); if (record == null) { return null; } int[] cids = new int[record.colors.size()]; Iterator<ColorRecord> crecs = record.colors.values().iterator(); for (int ii = 0; crecs.hasNext(); ii++) { cids[ii] = crecs.next().colorId; } return cids; }
[ "public", "int", "[", "]", "enumerateColorIds", "(", "String", "className", ")", "{", "// make sure the class exists", "ClassRecord", "record", "=", "getClassRecord", "(", "className", ")", ";", "if", "(", "record", "==", "null", ")", "{", "return", "null", ";...
Returns an array containing the ids of the colors in the specified class.
[ "Returns", "an", "array", "containing", "the", "ids", "of", "the", "colors", "in", "the", "specified", "class", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L308-L322
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getRandomStartingColor
public ColorRecord getRandomStartingColor (String className, Random rand) { // make sure the class exists ClassRecord record = getClassRecord(className); return (record == null) ? null : record.randomStartingColor(rand); }
java
public ColorRecord getRandomStartingColor (String className, Random rand) { // make sure the class exists ClassRecord record = getClassRecord(className); return (record == null) ? null : record.randomStartingColor(rand); }
[ "public", "ColorRecord", "getRandomStartingColor", "(", "String", "className", ",", "Random", "rand", ")", "{", "// make sure the class exists", "ClassRecord", "record", "=", "getClassRecord", "(", "className", ")", ";", "return", "(", "record", "==", "null", ")", ...
Returns a random starting color from the specified color class.
[ "Returns", "a", "random", "starting", "color", "from", "the", "specified", "color", "class", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L354-L359
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getColorization
public Colorization getColorization (int classId, int colorId) { ColorRecord color = getColorRecord(classId, colorId); return (color == null) ? null : color.getColorization(); }
java
public Colorization getColorization (int classId, int colorId) { ColorRecord color = getColorRecord(classId, colorId); return (color == null) ? null : color.getColorization(); }
[ "public", "Colorization", "getColorization", "(", "int", "classId", ",", "int", "colorId", ")", "{", "ColorRecord", "color", "=", "getColorRecord", "(", "classId", ",", "colorId", ")", ";", "return", "(", "color", "==", "null", ")", "?", "null", ":", "colo...
Looks up a colorization by id.
[ "Looks", "up", "a", "colorization", "by", "id", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L364-L368
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getColorization
public Colorization getColorization (String className, int colorId) { ClassRecord crec = getClassRecord(className); if (crec != null) { ColorRecord color = crec.colors.get(colorId); if (color != null) { return color.getColorization(); } } return null; }
java
public Colorization getColorization (String className, int colorId) { ClassRecord crec = getClassRecord(className); if (crec != null) { ColorRecord color = crec.colors.get(colorId); if (color != null) { return color.getColorization(); } } return null; }
[ "public", "Colorization", "getColorization", "(", "String", "className", ",", "int", "colorId", ")", "{", "ClassRecord", "crec", "=", "getClassRecord", "(", "className", ")", ";", "if", "(", "crec", "!=", "null", ")", "{", "ColorRecord", "color", "=", "crec"...
Looks up a colorization by name.
[ "Looks", "up", "a", "colorization", "by", "name", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L381-L391
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getColorization
public Colorization getColorization (String className, String colorName) { ClassRecord crec = getClassRecord(className); if (crec != null) { int colorId = 0; try { colorId = crec.getColorId(colorName); } catch (ParseException pe) { log.info("Error getting colorization by name", "error", pe); return null; } ColorRecord color = crec.colors.get(colorId); if (color != null) { return color.getColorization(); } } return null; }
java
public Colorization getColorization (String className, String colorName) { ClassRecord crec = getClassRecord(className); if (crec != null) { int colorId = 0; try { colorId = crec.getColorId(colorName); } catch (ParseException pe) { log.info("Error getting colorization by name", "error", pe); return null; } ColorRecord color = crec.colors.get(colorId); if (color != null) { return color.getColorization(); } } return null; }
[ "public", "Colorization", "getColorization", "(", "String", "className", ",", "String", "colorName", ")", "{", "ClassRecord", "crec", "=", "getClassRecord", "(", "className", ")", ";", "if", "(", "crec", "!=", "null", ")", "{", "int", "colorId", "=", "0", ...
Looks up a colorization by class and color names.
[ "Looks", "up", "a", "colorization", "by", "class", "and", "color", "names", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L396-L414
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getClassRecord
public ClassRecord getClassRecord (String className) { Iterator<ClassRecord> iter = _classes.values().iterator(); while (iter.hasNext()) { ClassRecord crec = iter.next(); if (crec.name.equals(className)) { return crec; } } log.warning("No such color class", "class", className, new Exception()); return null; }
java
public ClassRecord getClassRecord (String className) { Iterator<ClassRecord> iter = _classes.values().iterator(); while (iter.hasNext()) { ClassRecord crec = iter.next(); if (crec.name.equals(className)) { return crec; } } log.warning("No such color class", "class", className, new Exception()); return null; }
[ "public", "ClassRecord", "getClassRecord", "(", "String", "className", ")", "{", "Iterator", "<", "ClassRecord", ">", "iter", "=", "_classes", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "iter", ".", "hasNext", "(", ")", ")", ...
Loads up a colorization class by name and logs a warning if it doesn't exist.
[ "Loads", "up", "a", "colorization", "class", "by", "name", "and", "logs", "a", "warning", "if", "it", "doesn", "t", "exist", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L419-L430
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getColorRecord
public ColorRecord getColorRecord (int classId, int colorId) { ClassRecord record = getClassRecord(classId); if (record == null) { // if they request color class zero, we assume they're just // decoding a blank colorprint, otherwise we complain if (classId != 0) { log.warning("Requested unknown color class", "classId", classId, "colorId", colorId, new Exception()); } return null; } return record.colors.get(colorId); }
java
public ColorRecord getColorRecord (int classId, int colorId) { ClassRecord record = getClassRecord(classId); if (record == null) { // if they request color class zero, we assume they're just // decoding a blank colorprint, otherwise we complain if (classId != 0) { log.warning("Requested unknown color class", "classId", classId, "colorId", colorId, new Exception()); } return null; } return record.colors.get(colorId); }
[ "public", "ColorRecord", "getColorRecord", "(", "int", "classId", ",", "int", "colorId", ")", "{", "ClassRecord", "record", "=", "getClassRecord", "(", "classId", ")", ";", "if", "(", "record", "==", "null", ")", "{", "// if they request color class zero, we assum...
Looks up the requested color record.
[ "Looks", "up", "the", "requested", "color", "record", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L435-L448
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.getColorRecord
public ColorRecord getColorRecord (String className, String colorName) { ClassRecord record = getClassRecord(className); if (record == null) { log.warning("Requested unknown color class", "className", className, "colorName", colorName, new Exception()); return null; } int colorId = 0; try { colorId = record.getColorId(colorName); } catch (ParseException pe) { log.info("Error getting color record by name", "error", pe); return null; } return record.colors.get(colorId); }
java
public ColorRecord getColorRecord (String className, String colorName) { ClassRecord record = getClassRecord(className); if (record == null) { log.warning("Requested unknown color class", "className", className, "colorName", colorName, new Exception()); return null; } int colorId = 0; try { colorId = record.getColorId(colorName); } catch (ParseException pe) { log.info("Error getting color record by name", "error", pe); return null; } return record.colors.get(colorId); }
[ "public", "ColorRecord", "getColorRecord", "(", "String", "className", ",", "String", "colorName", ")", "{", "ClassRecord", "record", "=", "getClassRecord", "(", "className", ")", ";", "if", "(", "record", "==", "null", ")", "{", "log", ".", "warning", "(", ...
Looks up the requested color record by class and color names.
[ "Looks", "up", "the", "requested", "color", "record", "by", "class", "and", "color", "names", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L453-L471
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.addClass
public void addClass (ClassRecord record) { // validate the class id if (record.classId > 255) { log.warning("Refusing to add class; classId > 255 " + record + "."); } else { _classes.put(record.classId, record); } }
java
public void addClass (ClassRecord record) { // validate the class id if (record.classId > 255) { log.warning("Refusing to add class; classId > 255 " + record + "."); } else { _classes.put(record.classId, record); } }
[ "public", "void", "addClass", "(", "ClassRecord", "record", ")", "{", "// validate the class id", "if", "(", "record", ".", "classId", ">", "255", ")", "{", "log", ".", "warning", "(", "\"Refusing to add class; classId > 255 \"", "+", "record", "+", "\".\"", ")"...
Adds a fully configured color class record to the pository. This is only called by the XML parsing code, so pay it no mind.
[ "Adds", "a", "fully", "configured", "color", "class", "record", "to", "the", "pository", ".", "This", "is", "only", "called", "by", "the", "XML", "parsing", "code", "so", "pay", "it", "no", "mind", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L485-L493
train
threerings/nenya
core/src/main/java/com/threerings/media/image/ColorPository.java
ColorPository.saveColorPository
public static void saveColorPository (ColorPository posit, File root) { File path = new File(root, CONFIG_PATH); try { CompiledConfig.saveConfig(path, posit); } catch (IOException ioe) { log.warning("Failure saving color pository", "path", path, "error", ioe); } }
java
public static void saveColorPository (ColorPository posit, File root) { File path = new File(root, CONFIG_PATH); try { CompiledConfig.saveConfig(path, posit); } catch (IOException ioe) { log.warning("Failure saving color pository", "path", path, "error", ioe); } }
[ "public", "static", "void", "saveColorPository", "(", "ColorPository", "posit", ",", "File", "root", ")", "{", "File", "path", "=", "new", "File", "(", "root", ",", "CONFIG_PATH", ")", ";", "try", "{", "CompiledConfig", ".", "saveConfig", "(", "path", ",",...
Serializes and saves color pository to the supplied file.
[ "Serializes", "and", "saves", "color", "pository", "to", "the", "supplied", "file", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/image/ColorPository.java#L524-L532
train
threerings/nenya
core/src/main/java/com/threerings/cast/CharacterSprite.java
CharacterSprite.init
public void init (CharacterDescriptor descrip, CharacterManager charmgr) { // keep track of this stuff _descrip = descrip; _charmgr = charmgr; // sanity check our values sanityCheckDescrip(); // assign an arbitrary starting orientation _orient = SOUTHWEST; // pass the buck to derived classes didInit(); }
java
public void init (CharacterDescriptor descrip, CharacterManager charmgr) { // keep track of this stuff _descrip = descrip; _charmgr = charmgr; // sanity check our values sanityCheckDescrip(); // assign an arbitrary starting orientation _orient = SOUTHWEST; // pass the buck to derived classes didInit(); }
[ "public", "void", "init", "(", "CharacterDescriptor", "descrip", ",", "CharacterManager", "charmgr", ")", "{", "// keep track of this stuff", "_descrip", "=", "descrip", ";", "_charmgr", "=", "charmgr", ";", "// sanity check our values", "sanityCheckDescrip", "(", ")", ...
Initializes this character sprite with the specified character descriptor and character manager. It will obtain animation data from the supplied character manager.
[ "Initializes", "this", "character", "sprite", "with", "the", "specified", "character", "descriptor", "and", "character", "manager", ".", "It", "will", "obtain", "animation", "data", "from", "the", "supplied", "character", "manager", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/cast/CharacterSprite.java#L42-L56
train
threerings/nenya
core/src/main/java/com/threerings/cast/CharacterSprite.java
CharacterSprite.setActionSequence
public void setActionSequence (String action) { // sanity check if (action == null) { log.warning("Refusing to set null action sequence " + this + ".", new Exception()); return; } // no need to noop if (action.equals(_action)) { return; } _action = action; updateActionFrames(); }
java
public void setActionSequence (String action) { // sanity check if (action == null) { log.warning("Refusing to set null action sequence " + this + ".", new Exception()); return; } // no need to noop if (action.equals(_action)) { return; } _action = action; updateActionFrames(); }
[ "public", "void", "setActionSequence", "(", "String", "action", ")", "{", "// sanity check", "if", "(", "action", "==", "null", ")", "{", "log", ".", "warning", "(", "\"Refusing to set null action sequence \"", "+", "this", "+", "\".\"", ",", "new", "Exception",...
Sets the action sequence used when rendering the character, from the set of available sequences.
[ "Sets", "the", "action", "sequence", "used", "when", "rendering", "the", "character", "from", "the", "set", "of", "available", "sequences", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/cast/CharacterSprite.java#L121-L135
train
threerings/nenya
core/src/main/java/com/threerings/cast/CharacterSprite.java
CharacterSprite.updateActionFrames
protected void updateActionFrames () { // get a reference to the action sequence so that we can obtain // our animation frames and configure our frames per second ActionSequence actseq = _charmgr.getActionSequence(_action); if (actseq == null) { String errmsg = "No such action '" + _action + "'."; throw new IllegalArgumentException(errmsg); } try { // obtain our animation frames for this action sequence _aframes = _charmgr.getActionFrames(_descrip, _action); // clear out our frames so that we recomposite on next tick _frames = null; // update the sprite render attributes setFrameRate(actseq.framesPerSecond); } catch (NoSuchComponentException nsce) { log.warning("Character sprite references non-existent component", "sprite", this, "err", nsce); } catch (Exception e) { log.warning("Failed to obtain action frames", "sprite", this, "descrip", _descrip, "action", _action, e); } }
java
protected void updateActionFrames () { // get a reference to the action sequence so that we can obtain // our animation frames and configure our frames per second ActionSequence actseq = _charmgr.getActionSequence(_action); if (actseq == null) { String errmsg = "No such action '" + _action + "'."; throw new IllegalArgumentException(errmsg); } try { // obtain our animation frames for this action sequence _aframes = _charmgr.getActionFrames(_descrip, _action); // clear out our frames so that we recomposite on next tick _frames = null; // update the sprite render attributes setFrameRate(actseq.framesPerSecond); } catch (NoSuchComponentException nsce) { log.warning("Character sprite references non-existent component", "sprite", this, "err", nsce); } catch (Exception e) { log.warning("Failed to obtain action frames", "sprite", this, "descrip", _descrip, "action", _action, e); } }
[ "protected", "void", "updateActionFrames", "(", ")", "{", "// get a reference to the action sequence so that we can obtain", "// our animation frames and configure our frames per second", "ActionSequence", "actseq", "=", "_charmgr", ".", "getActionSequence", "(", "_action", ")", ";...
Rebuilds our action frames given our current character descriptor and action sequence. This is called when either of those two things changes.
[ "Rebuilds", "our", "action", "frames", "given", "our", "current", "character", "descriptor", "and", "action", "sequence", ".", "This", "is", "called", "when", "either", "of", "those", "two", "things", "changes", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/cast/CharacterSprite.java#L229-L257
train
threerings/nenya
core/src/main/java/com/threerings/cast/CharacterSprite.java
CharacterSprite.sanityCheckDescrip
protected void sanityCheckDescrip () { if (_descrip.getComponentIds() == null || _descrip.getComponentIds().length == 0) { log.warning("Invalid character descriptor [sprite=" + this + ", descrip=" + _descrip + "].", new Exception()); } }
java
protected void sanityCheckDescrip () { if (_descrip.getComponentIds() == null || _descrip.getComponentIds().length == 0) { log.warning("Invalid character descriptor [sprite=" + this + ", descrip=" + _descrip + "].", new Exception()); } }
[ "protected", "void", "sanityCheckDescrip", "(", ")", "{", "if", "(", "_descrip", ".", "getComponentIds", "(", ")", "==", "null", "||", "_descrip", ".", "getComponentIds", "(", ")", ".", "length", "==", "0", ")", "{", "log", ".", "warning", "(", "\"Invali...
Makes it easier to track down problems with bogus character descriptors.
[ "Makes", "it", "easier", "to", "track", "down", "problems", "with", "bogus", "character", "descriptors", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/cast/CharacterSprite.java#L270-L277
train
threerings/nenya
core/src/main/java/com/threerings/cast/CharacterSprite.java
CharacterSprite.halt
protected void halt () { // only do something if we're actually animating if (_animMode != NO_ANIMATION) { // disable animation setAnimationMode(NO_ANIMATION); // come to a halt looking settled and at peace String rest = getRestingAction(); if (rest != null) { setActionSequence(rest); } } }
java
protected void halt () { // only do something if we're actually animating if (_animMode != NO_ANIMATION) { // disable animation setAnimationMode(NO_ANIMATION); // come to a halt looking settled and at peace String rest = getRestingAction(); if (rest != null) { setActionSequence(rest); } } }
[ "protected", "void", "halt", "(", ")", "{", "// only do something if we're actually animating", "if", "(", "_animMode", "!=", "NO_ANIMATION", ")", "{", "// disable animation", "setAnimationMode", "(", "NO_ANIMATION", ")", ";", "// come to a halt looking settled and at peace",...
Updates the sprite animation frame to reflect the cessation of movement and disables any further animation.
[ "Updates", "the", "sprite", "animation", "frame", "to", "reflect", "the", "cessation", "of", "movement", "and", "disables", "any", "further", "animation", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/cast/CharacterSprite.java#L348-L360
train
kaazing/java.client
ws/ws/src/main/java/org/kaazing/gateway/client/impl/wsn/WebSocketNativeEncoderImpl.java
WebSocketNativeEncoderImpl.unmask
public static void unmask(WrappedByteBuffer buf, int mask) { byte b; int remainder = buf.remaining() % 4; int remaining = buf.remaining() - remainder; int end = remaining + buf.position(); // xor a 32bit word at a time as long as possible while (buf.position() < end) { int plaintext = buf.getIntAt(buf.position()) ^ mask; buf.putInt(plaintext); } // xor the remaining 3, 2, or 1 bytes switch (remainder) { case 3: b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 24) & 0xff)); buf.put(b); b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 16) & 0xff)); buf.put(b); b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 8) & 0xff)); buf.put(b); break; case 2: b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 24) & 0xff)); buf.put(b); b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 16) & 0xff)); buf.put(b); break; case 1: b = (byte) (buf.getAt(buf.position()) ^ (mask >> 24)); buf.put(b); break; case 0: default: break; } //buf.position(start); }
java
public static void unmask(WrappedByteBuffer buf, int mask) { byte b; int remainder = buf.remaining() % 4; int remaining = buf.remaining() - remainder; int end = remaining + buf.position(); // xor a 32bit word at a time as long as possible while (buf.position() < end) { int plaintext = buf.getIntAt(buf.position()) ^ mask; buf.putInt(plaintext); } // xor the remaining 3, 2, or 1 bytes switch (remainder) { case 3: b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 24) & 0xff)); buf.put(b); b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 16) & 0xff)); buf.put(b); b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 8) & 0xff)); buf.put(b); break; case 2: b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 24) & 0xff)); buf.put(b); b = (byte) (buf.getAt(buf.position()) ^ ((mask >> 16) & 0xff)); buf.put(b); break; case 1: b = (byte) (buf.getAt(buf.position()) ^ (mask >> 24)); buf.put(b); break; case 0: default: break; } //buf.position(start); }
[ "public", "static", "void", "unmask", "(", "WrappedByteBuffer", "buf", ",", "int", "mask", ")", "{", "byte", "b", ";", "int", "remainder", "=", "buf", ".", "remaining", "(", ")", "%", "4", ";", "int", "remaining", "=", "buf", ".", "remaining", "(", "...
Performs an in-situ unmasking of the readable buf bytes. Preserves the position of the buffer whilst unmasking all the readable bytes, such that the unmasked bytes will be readable after this invocation. @param buf the buffer containing readable bytes to be unmasked. @param mask the mask to apply against the readable bytes of buffer.
[ "Performs", "an", "in", "-", "situ", "unmasking", "of", "the", "readable", "buf", "bytes", ".", "Preserves", "the", "position", "of", "the", "buffer", "whilst", "unmasking", "all", "the", "readable", "bytes", "such", "that", "the", "unmasked", "bytes", "will...
25ad2ae5bb24aa9d6b79400fce649b518dcfbe26
https://github.com/kaazing/java.client/blob/25ad2ae5bb24aa9d6b79400fce649b518dcfbe26/ws/ws/src/main/java/org/kaazing/gateway/client/impl/wsn/WebSocketNativeEncoderImpl.java#L156-L193
train
groupon/monsoon
remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java
AbstractServer.newTscStream
private static stream_response newTscStream(Stream<TimeSeriesCollection> tsc, int fetch) { final BufferedIterator<TimeSeriesCollection> iter = new BufferedIterator(tsc.iterator(), TSC_QUEUE_SIZE); final long idx = TSC_ITERS_ALLOC.getAndIncrement(); final IteratorAndCookie<TimeSeriesCollection> iterAndCookie = new IteratorAndCookie<>(iter); TSC_ITERS.put(idx, iterAndCookie); final List<TimeSeriesCollection> result = fetchFromIter(iter, fetch, MAX_TSC_FETCH); EncDec.NewIterResponse<TimeSeriesCollection> responseObj = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie()); LOG.log(Level.FINE, "responseObj = {0}", responseObj); return EncDec.encodeStreamResponse(responseObj); }
java
private static stream_response newTscStream(Stream<TimeSeriesCollection> tsc, int fetch) { final BufferedIterator<TimeSeriesCollection> iter = new BufferedIterator(tsc.iterator(), TSC_QUEUE_SIZE); final long idx = TSC_ITERS_ALLOC.getAndIncrement(); final IteratorAndCookie<TimeSeriesCollection> iterAndCookie = new IteratorAndCookie<>(iter); TSC_ITERS.put(idx, iterAndCookie); final List<TimeSeriesCollection> result = fetchFromIter(iter, fetch, MAX_TSC_FETCH); EncDec.NewIterResponse<TimeSeriesCollection> responseObj = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie()); LOG.log(Level.FINE, "responseObj = {0}", responseObj); return EncDec.encodeStreamResponse(responseObj); }
[ "private", "static", "stream_response", "newTscStream", "(", "Stream", "<", "TimeSeriesCollection", ">", "tsc", ",", "int", "fetch", ")", "{", "final", "BufferedIterator", "<", "TimeSeriesCollection", ">", "iter", "=", "new", "BufferedIterator", "(", "tsc", ".", ...
Create a new TimeSeriesCollection iterator from the given stream.
[ "Create", "a", "new", "TimeSeriesCollection", "iterator", "from", "the", "given", "stream", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java#L167-L178
train
groupon/monsoon
remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java
AbstractServer.newEvalStream
private static evaluate_response newEvalStream(Stream<Collection<CollectHistory.NamedEvaluation>> tsc, int fetch) { final BufferedIterator<Collection<CollectHistory.NamedEvaluation>> iter = new BufferedIterator(tsc.iterator(), EVAL_QUEUE_SIZE); final long idx = EVAL_ITERS_ALLOC.getAndIncrement(); final IteratorAndCookie<Collection<CollectHistory.NamedEvaluation>> iterAndCookie = new IteratorAndCookie<>(iter); EVAL_ITERS.put(idx, iterAndCookie); final List<Collection<CollectHistory.NamedEvaluation>> result = fetchFromIter(iter, fetch, MAX_EVAL_FETCH); EncDec.NewIterResponse<Collection<CollectHistory.NamedEvaluation>> responseObj = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie()); LOG.log(Level.FINE, "responseObj = {0}", responseObj); return EncDec.encodeEvaluateResponse(responseObj); }
java
private static evaluate_response newEvalStream(Stream<Collection<CollectHistory.NamedEvaluation>> tsc, int fetch) { final BufferedIterator<Collection<CollectHistory.NamedEvaluation>> iter = new BufferedIterator(tsc.iterator(), EVAL_QUEUE_SIZE); final long idx = EVAL_ITERS_ALLOC.getAndIncrement(); final IteratorAndCookie<Collection<CollectHistory.NamedEvaluation>> iterAndCookie = new IteratorAndCookie<>(iter); EVAL_ITERS.put(idx, iterAndCookie); final List<Collection<CollectHistory.NamedEvaluation>> result = fetchFromIter(iter, fetch, MAX_EVAL_FETCH); EncDec.NewIterResponse<Collection<CollectHistory.NamedEvaluation>> responseObj = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie()); LOG.log(Level.FINE, "responseObj = {0}", responseObj); return EncDec.encodeEvaluateResponse(responseObj); }
[ "private", "static", "evaluate_response", "newEvalStream", "(", "Stream", "<", "Collection", "<", "CollectHistory", ".", "NamedEvaluation", ">", ">", "tsc", ",", "int", "fetch", ")", "{", "final", "BufferedIterator", "<", "Collection", "<", "CollectHistory", ".", ...
Create a new evaluation iterator from the given stream.
[ "Create", "a", "new", "evaluation", "iterator", "from", "the", "given", "stream", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java#L183-L194
train
groupon/monsoon
remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java
AbstractServer.newGroupStream
private static group_stream_response newGroupStream(Stream<Map.Entry<DateTime, TimeSeriesValue>> tsc, int fetch) { final BufferedIterator<Map.Entry<DateTime, TimeSeriesValue>> iter = new BufferedIterator<>(tsc.iterator(), GROUP_STREAM_QUEUE_SIZE); final long idx = GROUP_STREAM_ITERS_ALLOC.getAndIncrement(); final IteratorAndCookie<Map.Entry<DateTime, TimeSeriesValue>> iterAndCookie = new IteratorAndCookie<>(iter); GROUP_STREAM_ITERS.put(idx, iterAndCookie); final List<Map.Entry<DateTime, TimeSeriesValue>> result = fetchFromIter(iter, fetch, MAX_GROUP_STREAM_FETCH); EncDec.NewIterResponse<Map.Entry<DateTime, TimeSeriesValue>> responseObj = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie()); LOG.log(Level.FINE, "responseObj = {0}", responseObj); return EncDec.encodeStreamGroupResponse(responseObj); }
java
private static group_stream_response newGroupStream(Stream<Map.Entry<DateTime, TimeSeriesValue>> tsc, int fetch) { final BufferedIterator<Map.Entry<DateTime, TimeSeriesValue>> iter = new BufferedIterator<>(tsc.iterator(), GROUP_STREAM_QUEUE_SIZE); final long idx = GROUP_STREAM_ITERS_ALLOC.getAndIncrement(); final IteratorAndCookie<Map.Entry<DateTime, TimeSeriesValue>> iterAndCookie = new IteratorAndCookie<>(iter); GROUP_STREAM_ITERS.put(idx, iterAndCookie); final List<Map.Entry<DateTime, TimeSeriesValue>> result = fetchFromIter(iter, fetch, MAX_GROUP_STREAM_FETCH); EncDec.NewIterResponse<Map.Entry<DateTime, TimeSeriesValue>> responseObj = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie()); LOG.log(Level.FINE, "responseObj = {0}", responseObj); return EncDec.encodeStreamGroupResponse(responseObj); }
[ "private", "static", "group_stream_response", "newGroupStream", "(", "Stream", "<", "Map", ".", "Entry", "<", "DateTime", ",", "TimeSeriesValue", ">", ">", "tsc", ",", "int", "fetch", ")", "{", "final", "BufferedIterator", "<", "Map", ".", "Entry", "<", "Dat...
Create a new group iterator from the given stream.
[ "Create", "a", "new", "group", "iterator", "from", "the", "given", "stream", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java#L199-L210
train
groupon/monsoon
remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java
AbstractServer.fetchFromIter
private static <T> List<T> fetchFromIter(BufferedIterator<T> iter, int fetch, int max_fetch) { final long t0 = System.currentTimeMillis(); assert (max_fetch >= 1); if (fetch < 0 || fetch > max_fetch) fetch = max_fetch; final List<T> result = new ArrayList<>(fetch); for (int i = 0; i < fetch && !iter.atEnd(); ++i) { if (iter.nextAvail()) result.add(iter.next()); // Decide if we should cut the fetch short. // We stop fetching more items if the time delay exceeds the deadline. final long tCur = System.currentTimeMillis(); if (!result.isEmpty() && tCur - t0 >= MIN_REQUEST_DURATION.getMillis()) break; else if (tCur - t0 >= MAX_REQUEST_DURATION.getMillis()) break; else if (!iter.nextAvail()) { // Block until next is available, or until deadline is exceeded. try { iter.waitAvail((t0 + MAX_REQUEST_DURATION.getMillis() - tCur), TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { /* SKIP */ } } } return result; }
java
private static <T> List<T> fetchFromIter(BufferedIterator<T> iter, int fetch, int max_fetch) { final long t0 = System.currentTimeMillis(); assert (max_fetch >= 1); if (fetch < 0 || fetch > max_fetch) fetch = max_fetch; final List<T> result = new ArrayList<>(fetch); for (int i = 0; i < fetch && !iter.atEnd(); ++i) { if (iter.nextAvail()) result.add(iter.next()); // Decide if we should cut the fetch short. // We stop fetching more items if the time delay exceeds the deadline. final long tCur = System.currentTimeMillis(); if (!result.isEmpty() && tCur - t0 >= MIN_REQUEST_DURATION.getMillis()) break; else if (tCur - t0 >= MAX_REQUEST_DURATION.getMillis()) break; else if (!iter.nextAvail()) { // Block until next is available, or until deadline is exceeded. try { iter.waitAvail((t0 + MAX_REQUEST_DURATION.getMillis() - tCur), TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { /* SKIP */ } } } return result; }
[ "private", "static", "<", "T", ">", "List", "<", "T", ">", "fetchFromIter", "(", "BufferedIterator", "<", "T", ">", "iter", ",", "int", "fetch", ",", "int", "max_fetch", ")", "{", "final", "long", "t0", "=", "System", ".", "currentTimeMillis", "(", ")"...
Fetch up to a given amount of items from the iterator. @param <T> The type of elements in the iterator. @param iter The iterator supplying items. @param fetch The requested number of items to fetch (user supplied parameter). @param max_fetch The hard limit on how many items to fetch. @return A list with items fetched from the iterator.
[ "Fetch", "up", "to", "a", "given", "amount", "of", "items", "from", "the", "iterator", "." ]
eb68d72ba4c01fe018dc981097dbee033908f5c7
https://github.com/groupon/monsoon/blob/eb68d72ba4c01fe018dc981097dbee033908f5c7/remote_history/src/main/java/com/groupon/monsoon/remote/history/AbstractServer.java#L222-L248
train
threerings/nenya
core/src/main/java/com/threerings/cast/bundle/BundleUtil.java
BundleUtil.loadObject
public static Object loadObject (ResourceBundle bundle, String path, boolean wipeOnFailure) throws IOException, ClassNotFoundException { InputStream bin = null; try { bin = bundle.getResource(path); if (bin == null) { return null; } return new ObjectInputStream(bin).readObject(); } catch (InvalidClassException ice) { log.warning("Aiya! Serialized object is hosed [bundle=" + bundle + ", element=" + path + ", error=" + ice.getMessage() + "]."); return null; } catch (IOException ioe) { log.warning("Error reading resource from bundle [bundle=" + bundle + ", path=" + path + ", wiping?=" + wipeOnFailure + "]."); if (wipeOnFailure) { StreamUtil.close(bin); bin = null; if (bundle instanceof FileResourceBundle) { ((FileResourceBundle)bundle).wipeBundle(false); } } throw ioe; } finally { StreamUtil.close(bin); } }
java
public static Object loadObject (ResourceBundle bundle, String path, boolean wipeOnFailure) throws IOException, ClassNotFoundException { InputStream bin = null; try { bin = bundle.getResource(path); if (bin == null) { return null; } return new ObjectInputStream(bin).readObject(); } catch (InvalidClassException ice) { log.warning("Aiya! Serialized object is hosed [bundle=" + bundle + ", element=" + path + ", error=" + ice.getMessage() + "]."); return null; } catch (IOException ioe) { log.warning("Error reading resource from bundle [bundle=" + bundle + ", path=" + path + ", wiping?=" + wipeOnFailure + "]."); if (wipeOnFailure) { StreamUtil.close(bin); bin = null; if (bundle instanceof FileResourceBundle) { ((FileResourceBundle)bundle).wipeBundle(false); } } throw ioe; } finally { StreamUtil.close(bin); } }
[ "public", "static", "Object", "loadObject", "(", "ResourceBundle", "bundle", ",", "String", "path", ",", "boolean", "wipeOnFailure", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "InputStream", "bin", "=", "null", ";", "try", "{", "bin", "=",...
Attempts to load an object from the supplied resource bundle with the specified path. @param wipeOnFailure if there is an error reading the object from the bundle and this parameter is true, we will instruct the bundle to delete its underlying jar file before propagating the exception with the expectation that it will be redownloaded and repaired the next time the application is run. @return the unserialized object in question. @exception IOException thrown if an I/O error occurs while reading the object from the bundle.
[ "Attempts", "to", "load", "an", "object", "from", "the", "supplied", "resource", "bundle", "with", "the", "specified", "path", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/cast/bundle/BundleUtil.java#L70-L101
train
threerings/nenya
tools/src/main/java/com/threerings/media/tile/bundle/tools/TileSetBundlerTask.java
TileSetBundlerTask.getTargetPath
protected String getTargetPath (File fromDir, String path) { return path.substring(0, path.length()-4) + ".jar"; }
java
protected String getTargetPath (File fromDir, String path) { return path.substring(0, path.length()-4) + ".jar"; }
[ "protected", "String", "getTargetPath", "(", "File", "fromDir", ",", "String", "path", ")", "{", "return", "path", ".", "substring", "(", "0", ",", "path", ".", "length", "(", ")", "-", "4", ")", "+", "\".jar\"", ";", "}" ]
Returns the target path in which our bundler will write the tile set.
[ "Returns", "the", "target", "path", "in", "which", "our", "bundler", "will", "write", "the", "tile", "set", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/tools/src/main/java/com/threerings/media/tile/bundle/tools/TileSetBundlerTask.java#L162-L165
train
threerings/nenya
core/src/main/java/com/threerings/media/sprite/ButtonSprite.java
ButtonSprite.updateBounds
public void updateBounds () { // invalidate the old... invalidate(); // size the bounds to fit our label Dimension size = _label.getSize(); _bounds.width = size.width + PADDING*2 + (_style == ROUNDED ? _arcWidth : 0); _bounds.height = size.height + PADDING*2; // ...and the new invalidate(); }
java
public void updateBounds () { // invalidate the old... invalidate(); // size the bounds to fit our label Dimension size = _label.getSize(); _bounds.width = size.width + PADDING*2 + (_style == ROUNDED ? _arcWidth : 0); _bounds.height = size.height + PADDING*2; // ...and the new invalidate(); }
[ "public", "void", "updateBounds", "(", ")", "{", "// invalidate the old...", "invalidate", "(", ")", ";", "// size the bounds to fit our label", "Dimension", "size", "=", "_label", ".", "getSize", "(", ")", ";", "_bounds", ".", "width", "=", "size", ".", "width"...
Updates this sprite's bounds after a change to the label.
[ "Updates", "this", "sprite", "s", "bounds", "after", "a", "change", "to", "the", "label", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/sprite/ButtonSprite.java#L103-L116
train
threerings/nenya
core/src/main/java/com/threerings/util/DirectionUtil.java
DirectionUtil.getClosest
public static int getClosest (int direction, int[] possible, boolean preferCW) { // rotate a tick at a time, looking for matches int first = direction; int second = direction; for (int ii = 0; ii <= FINE_DIRECTION_COUNT / 2; ii++) { if (IntListUtil.contains(possible, first)) { return first; } if (ii != 0 && IntListUtil.contains(possible, second)) { return second; } first = preferCW ? rotateCW(first, 1) : rotateCCW(first, 1); second = preferCW ? rotateCCW(second, 1) : rotateCW(second, 1); } return NONE; }
java
public static int getClosest (int direction, int[] possible, boolean preferCW) { // rotate a tick at a time, looking for matches int first = direction; int second = direction; for (int ii = 0; ii <= FINE_DIRECTION_COUNT / 2; ii++) { if (IntListUtil.contains(possible, first)) { return first; } if (ii != 0 && IntListUtil.contains(possible, second)) { return second; } first = preferCW ? rotateCW(first, 1) : rotateCCW(first, 1); second = preferCW ? rotateCCW(second, 1) : rotateCW(second, 1); } return NONE; }
[ "public", "static", "int", "getClosest", "(", "int", "direction", ",", "int", "[", "]", "possible", ",", "boolean", "preferCW", ")", "{", "// rotate a tick at a time, looking for matches", "int", "first", "=", "direction", ";", "int", "second", "=", "direction", ...
Get the direction closest to the specified direction, out of the directions in the possible list. @param preferCW whether to prefer a clockwise match or a counter-clockwise match.
[ "Get", "the", "direction", "closest", "to", "the", "specified", "direction", "out", "of", "the", "directions", "in", "the", "possible", "list", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/util/DirectionUtil.java#L156-L176
train
threerings/nenya
core/src/main/java/com/threerings/util/DirectionUtil.java
DirectionUtil.moveDirection
public static void moveDirection (Point p, int direction, int dx, int dy) { if (direction >= DIRECTION_COUNT) { throw new IllegalArgumentException("Fine coordinates not supported."); } switch (direction) { case NORTH: case NORTHWEST: case NORTHEAST: p.y -= dy; } switch (direction) { case SOUTH: case SOUTHWEST: case SOUTHEAST: p.y += dy; } switch (direction) { case WEST: case SOUTHWEST: case NORTHWEST: p.x -= dx; } switch (direction) { case EAST: case SOUTHEAST: case NORTHEAST: p.x += dx; } }
java
public static void moveDirection (Point p, int direction, int dx, int dy) { if (direction >= DIRECTION_COUNT) { throw new IllegalArgumentException("Fine coordinates not supported."); } switch (direction) { case NORTH: case NORTHWEST: case NORTHEAST: p.y -= dy; } switch (direction) { case SOUTH: case SOUTHWEST: case SOUTHEAST: p.y += dy; } switch (direction) { case WEST: case SOUTHWEST: case NORTHWEST: p.x -= dx; } switch (direction) { case EAST: case SOUTHEAST: case NORTHEAST: p.x += dx; } }
[ "public", "static", "void", "moveDirection", "(", "Point", "p", ",", "int", "direction", ",", "int", "dx", ",", "int", "dy", ")", "{", "if", "(", "direction", ">=", "DIRECTION_COUNT", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Fine coordin...
Move the specified point in the specified screen direction, adjusting by the specified adjustments. Fine directions are not supported.
[ "Move", "the", "specified", "point", "in", "the", "specified", "screen", "direction", "adjusting", "by", "the", "specified", "adjustments", ".", "Fine", "directions", "are", "not", "supported", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/util/DirectionUtil.java#L264-L282
train
threerings/nenya
core/src/main/java/com/threerings/media/ActiveRepaintManager.java
ActiveRepaintManager.getRoot
protected Component getRoot (Component comp) { for (Component c = comp; c != null; c = c.getParent()) { boolean hidden = !c.isDisplayable(); // on the mac, the JRootPane is invalidated before it is visible and is never again // invalidated or repainted, so we punt and allow all invisible components to be // invalidated and revalidated if (!RunAnywhere.isMacOS()) { hidden |= !c.isVisible(); } if (hidden) { return null; } if (c instanceof Window || c instanceof Applet) { return c; } } return null; }
java
protected Component getRoot (Component comp) { for (Component c = comp; c != null; c = c.getParent()) { boolean hidden = !c.isDisplayable(); // on the mac, the JRootPane is invalidated before it is visible and is never again // invalidated or repainted, so we punt and allow all invisible components to be // invalidated and revalidated if (!RunAnywhere.isMacOS()) { hidden |= !c.isVisible(); } if (hidden) { return null; } if (c instanceof Window || c instanceof Applet) { return c; } } return null; }
[ "protected", "Component", "getRoot", "(", "Component", "comp", ")", "{", "for", "(", "Component", "c", "=", "comp", ";", "c", "!=", "null", ";", "c", "=", "c", ".", "getParent", "(", ")", ")", "{", "boolean", "hidden", "=", "!", "c", ".", "isDispla...
Returns the root component for the supplied component or null if it is not part of a rooted hierarchy or if any parent along the way is found to be hidden or without a peer.
[ "Returns", "the", "root", "component", "for", "the", "supplied", "component", "or", "null", "if", "it", "is", "not", "part", "of", "a", "rooted", "hierarchy", "or", "if", "any", "parent", "along", "the", "way", "is", "found", "to", "be", "hidden", "or", ...
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/ActiveRepaintManager.java#L166-L184
train
threerings/nenya
core/src/main/java/com/threerings/media/ActiveRepaintManager.java
ActiveRepaintManager.validateComponents
public void validateComponents () { // swap out our invalid array Object[] invalid = null; synchronized (this) { invalid = _invalid; _invalid = null; } // if there's nothing to validate, we're home free if (invalid == null) { return; } // validate everything therein int icount = invalid.length; for (int ii = 0; ii < icount; ii++) { if (invalid[ii] != null) { if (DEBUG) { log.info("Validating " + invalid[ii]); } ((Component)invalid[ii]).validate(); } } }
java
public void validateComponents () { // swap out our invalid array Object[] invalid = null; synchronized (this) { invalid = _invalid; _invalid = null; } // if there's nothing to validate, we're home free if (invalid == null) { return; } // validate everything therein int icount = invalid.length; for (int ii = 0; ii < icount; ii++) { if (invalid[ii] != null) { if (DEBUG) { log.info("Validating " + invalid[ii]); } ((Component)invalid[ii]).validate(); } } }
[ "public", "void", "validateComponents", "(", ")", "{", "// swap out our invalid array", "Object", "[", "]", "invalid", "=", "null", ";", "synchronized", "(", "this", ")", "{", "invalid", "=", "_invalid", ";", "_invalid", "=", "null", ";", "}", "// if there's n...
Validates the invalid components that have been queued up since the last frame tick.
[ "Validates", "the", "invalid", "components", "that", "have", "been", "queued", "up", "since", "the", "last", "frame", "tick", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/ActiveRepaintManager.java#L204-L228
train
threerings/nenya
core/src/main/java/com/threerings/media/ActiveRepaintManager.java
ActiveRepaintManager.dumpHierarchy
protected static void dumpHierarchy (Component comp) { for (String indent = ""; comp != null; indent += " ") { log.info(indent + toString(comp)); comp = comp.getParent(); } }
java
protected static void dumpHierarchy (Component comp) { for (String indent = ""; comp != null; indent += " ") { log.info(indent + toString(comp)); comp = comp.getParent(); } }
[ "protected", "static", "void", "dumpHierarchy", "(", "Component", "comp", ")", "{", "for", "(", "String", "indent", "=", "\"\"", ";", "comp", "!=", "null", ";", "indent", "+=", "\" \"", ")", "{", "log", ".", "info", "(", "indent", "+", "toString", "(",...
Dumps the containment hierarchy for the supplied component.
[ "Dumps", "the", "containment", "hierarchy", "for", "the", "supplied", "component", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/ActiveRepaintManager.java#L426-L432
train
threerings/nenya
core/src/main/java/com/threerings/media/util/LineSegmentPath.java
LineSegmentPath.addNode
public void addNode (int x, int y, int dir) { _nodes.add(new PathNode(x, y, dir)); }
java
public void addNode (int x, int y, int dir) { _nodes.add(new PathNode(x, y, dir)); }
[ "public", "void", "addNode", "(", "int", "x", ",", "int", "y", ",", "int", "dir", ")", "{", "_nodes", ".", "add", "(", "new", "PathNode", "(", "x", ",", "y", ",", "dir", ")", ")", ";", "}" ]
Add a node to the path with the specified destination point and facing direction. @param x the x-position. @param y the y-position. @param dir the facing direction.
[ "Add", "a", "node", "to", "the", "path", "with", "the", "specified", "destination", "point", "and", "facing", "direction", "." ]
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/util/LineSegmentPath.java#L102-L105
train
threerings/nenya
core/src/main/java/com/threerings/media/util/LineSegmentPath.java
LineSegmentPath.setDuration
public void setDuration (long millis) { // if we have only zero or one nodes, we don't have enough // information to compute our velocity int ncount = _nodes.size(); if (ncount < 2) { log.warning("Requested to set duration of bogus path", "path", this, "duration", millis); return; } // compute the total distance along our path float distance = 0; PathNode start = _nodes.get(0); for (int ii = 1; ii < ncount; ii++) { PathNode end = _nodes.get(ii); distance += MathUtil.distance(start.loc.x, start.loc.y, end.loc.x, end.loc.y); start = end; } // set the velocity accordingly setVelocity(distance/millis); }
java
public void setDuration (long millis) { // if we have only zero or one nodes, we don't have enough // information to compute our velocity int ncount = _nodes.size(); if (ncount < 2) { log.warning("Requested to set duration of bogus path", "path", this, "duration", millis); return; } // compute the total distance along our path float distance = 0; PathNode start = _nodes.get(0); for (int ii = 1; ii < ncount; ii++) { PathNode end = _nodes.get(ii); distance += MathUtil.distance(start.loc.x, start.loc.y, end.loc.x, end.loc.y); start = end; } // set the velocity accordingly setVelocity(distance/millis); }
[ "public", "void", "setDuration", "(", "long", "millis", ")", "{", "// if we have only zero or one nodes, we don't have enough", "// information to compute our velocity", "int", "ncount", "=", "_nodes", ".", "size", "(", ")", ";", "if", "(", "ncount", "<", "2", ")", ...
Computes the velocity at which the pathable will need to travel along this path such that it will arrive at the destination in approximately the specified number of milliseconds. Efforts are taken to get the pathable there as close to the desired time as possible, but framerate variation may prevent it from arriving exactly on time.
[ "Computes", "the", "velocity", "at", "which", "the", "pathable", "will", "need", "to", "travel", "along", "this", "path", "such", "that", "it", "will", "arrive", "at", "the", "destination", "in", "approximately", "the", "specified", "number", "of", "millisecon...
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/util/LineSegmentPath.java#L146-L168
train
threerings/nenya
core/src/main/java/com/threerings/media/util/LineSegmentPath.java
LineSegmentPath.headToNextNode
protected boolean headToNextNode (Pathable pable, long startstamp, long now) { if (_niter == null) { throw new IllegalStateException("headToNextNode() called before init()"); } // check to see if we've completed our path if (!_niter.hasNext()) { // move the pathable to the location of our last destination pable.setLocation(_dest.loc.x, _dest.loc.y); pable.pathCompleted(now); return true; } // our previous destination is now our source _src = _dest; // pop the next node off the path _dest = getNextNode(); // adjust the pathable's orientation if (_dest.dir != NONE) { pable.setOrientation(_dest.dir); } // make a note of when we started traversing this node _nodestamp = startstamp; // figure out the distance from source to destination _seglength = MathUtil.distance( _src.loc.x, _src.loc.y, _dest.loc.x, _dest.loc.y); // if we're already there (the segment length is zero), we skip to // the next segment if (_seglength == 0) { return headToNextNode(pable, startstamp, now); } // now update the pathable's position based on our progress thus far return tick(pable, now); }
java
protected boolean headToNextNode (Pathable pable, long startstamp, long now) { if (_niter == null) { throw new IllegalStateException("headToNextNode() called before init()"); } // check to see if we've completed our path if (!_niter.hasNext()) { // move the pathable to the location of our last destination pable.setLocation(_dest.loc.x, _dest.loc.y); pable.pathCompleted(now); return true; } // our previous destination is now our source _src = _dest; // pop the next node off the path _dest = getNextNode(); // adjust the pathable's orientation if (_dest.dir != NONE) { pable.setOrientation(_dest.dir); } // make a note of when we started traversing this node _nodestamp = startstamp; // figure out the distance from source to destination _seglength = MathUtil.distance( _src.loc.x, _src.loc.y, _dest.loc.x, _dest.loc.y); // if we're already there (the segment length is zero), we skip to // the next segment if (_seglength == 0) { return headToNextNode(pable, startstamp, now); } // now update the pathable's position based on our progress thus far return tick(pable, now); }
[ "protected", "boolean", "headToNextNode", "(", "Pathable", "pable", ",", "long", "startstamp", ",", "long", "now", ")", "{", "if", "(", "_niter", "==", "null", ")", "{", "throw", "new", "IllegalStateException", "(", "\"headToNextNode() called before init()\"", ")"...
Place the pathable moving along the path at the end of the previous path node, face it appropriately for the next node, and start it on its way. Returns whether the pathable position moved.
[ "Place", "the", "pathable", "moving", "along", "the", "path", "at", "the", "end", "of", "the", "previous", "path", "node", "face", "it", "appropriately", "for", "the", "next", "node", "and", "start", "it", "on", "its", "way", ".", "Returns", "whether", "...
3165a012fd859009db3367f87bd2a5b820cc760a
https://github.com/threerings/nenya/blob/3165a012fd859009db3367f87bd2a5b820cc760a/core/src/main/java/com/threerings/media/util/LineSegmentPath.java#L251-L291
train