id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
143,800
sebastiangraf/treetank
coremodules/node/src/main/java/org/treetank/access/NodeWriteTrx.java
NodeWriteTrx.rollingRemove
private void rollingRemove() throws TTException { final ITreeData startNode = mDelegate.getCurrentNode(); long hashToRemove = startNode.getHash(); long hashToAdd = 0; long newHash = 0; // go the path to the root do { synchronized (mDelegate.getCurrentNode()) { getPtx().getData(mDelegate.getCurrentNode().getDataKey()); if (mDelegate.getCurrentNode().getDataKey() == startNode.getDataKey()) { // the begin node is always null newHash = 0; } else if (mDelegate.getCurrentNode().getDataKey() == startNode.getParentKey()) { // the parent node is just removed newHash = mDelegate.getCurrentNode().getHash() - (hashToRemove * PRIME); hashToRemove = mDelegate.getCurrentNode().getHash(); } else { // the ancestors are all touched regarding the modification newHash = mDelegate.getCurrentNode().getHash() - (hashToRemove * PRIME); newHash = newHash + hashToAdd * PRIME; hashToRemove = mDelegate.getCurrentNode().getHash(); } mDelegate.getCurrentNode().setHash(newHash); hashToAdd = newHash; getPtx().setData(mDelegate.getCurrentNode()); } } while (moveTo(mDelegate.getCurrentNode().getParentKey())); mDelegate.setCurrentNode(startNode); }
java
private void rollingRemove() throws TTException { final ITreeData startNode = mDelegate.getCurrentNode(); long hashToRemove = startNode.getHash(); long hashToAdd = 0; long newHash = 0; // go the path to the root do { synchronized (mDelegate.getCurrentNode()) { getPtx().getData(mDelegate.getCurrentNode().getDataKey()); if (mDelegate.getCurrentNode().getDataKey() == startNode.getDataKey()) { // the begin node is always null newHash = 0; } else if (mDelegate.getCurrentNode().getDataKey() == startNode.getParentKey()) { // the parent node is just removed newHash = mDelegate.getCurrentNode().getHash() - (hashToRemove * PRIME); hashToRemove = mDelegate.getCurrentNode().getHash(); } else { // the ancestors are all touched regarding the modification newHash = mDelegate.getCurrentNode().getHash() - (hashToRemove * PRIME); newHash = newHash + hashToAdd * PRIME; hashToRemove = mDelegate.getCurrentNode().getHash(); } mDelegate.getCurrentNode().setHash(newHash); hashToAdd = newHash; getPtx().setData(mDelegate.getCurrentNode()); } } while (moveTo(mDelegate.getCurrentNode().getParentKey())); mDelegate.setCurrentNode(startNode); }
[ "private", "void", "rollingRemove", "(", ")", "throws", "TTException", "{", "final", "ITreeData", "startNode", "=", "mDelegate", ".", "getCurrentNode", "(", ")", ";", "long", "hashToRemove", "=", "startNode", ".", "getHash", "(", ")", ";", "long", "hashToAdd", "=", "0", ";", "long", "newHash", "=", "0", ";", "// go the path to the root", "do", "{", "synchronized", "(", "mDelegate", ".", "getCurrentNode", "(", ")", ")", "{", "getPtx", "(", ")", ".", "getData", "(", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getDataKey", "(", ")", ")", ";", "if", "(", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getDataKey", "(", ")", "==", "startNode", ".", "getDataKey", "(", ")", ")", "{", "// the begin node is always null", "newHash", "=", "0", ";", "}", "else", "if", "(", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getDataKey", "(", ")", "==", "startNode", ".", "getParentKey", "(", ")", ")", "{", "// the parent node is just removed", "newHash", "=", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getHash", "(", ")", "-", "(", "hashToRemove", "*", "PRIME", ")", ";", "hashToRemove", "=", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getHash", "(", ")", ";", "}", "else", "{", "// the ancestors are all touched regarding the modification", "newHash", "=", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getHash", "(", ")", "-", "(", "hashToRemove", "*", "PRIME", ")", ";", "newHash", "=", "newHash", "+", "hashToAdd", "*", "PRIME", ";", "hashToRemove", "=", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getHash", "(", ")", ";", "}", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "setHash", "(", "newHash", ")", ";", "hashToAdd", "=", "newHash", ";", "getPtx", "(", ")", ".", "setData", "(", "mDelegate", ".", "getCurrentNode", "(", ")", ")", ";", "}", "}", "while", "(", "moveTo", "(", "mDelegate", ".", "getCurrentNode", "(", ")", ".", "getParentKey", "(", ")", ")", ")", ";", "mDelegate", ".", "setCurrentNode", "(", "startNode", ")", ";", "}" ]
Adapting the structure with a rolling hash for all ancestors only with remove. @throws TTIOException if anything weird happened
[ "Adapting", "the", "structure", "with", "a", "rolling", "hash", "for", "all", "ancestors", "only", "with", "remove", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/node/src/main/java/org/treetank/access/NodeWriteTrx.java#L780-L809
143,801
sebastiangraf/treetank
coremodules/node/src/main/java/org/treetank/access/NodeWriteTrx.java
NodeWriteTrx.buildName
public static String buildName(final QName pQName) { if (pQName == null) { throw new NullPointerException("mQName must not be null!"); } String name; if (pQName.getPrefix().isEmpty()) { name = pQName.getLocalPart(); } else { name = new StringBuilder(pQName.getPrefix()).append(":").append(pQName.getLocalPart()).toString(); } return name; }
java
public static String buildName(final QName pQName) { if (pQName == null) { throw new NullPointerException("mQName must not be null!"); } String name; if (pQName.getPrefix().isEmpty()) { name = pQName.getLocalPart(); } else { name = new StringBuilder(pQName.getPrefix()).append(":").append(pQName.getLocalPart()).toString(); } return name; }
[ "public", "static", "String", "buildName", "(", "final", "QName", "pQName", ")", "{", "if", "(", "pQName", "==", "null", ")", "{", "throw", "new", "NullPointerException", "(", "\"mQName must not be null!\"", ")", ";", "}", "String", "name", ";", "if", "(", "pQName", ".", "getPrefix", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "name", "=", "pQName", ".", "getLocalPart", "(", ")", ";", "}", "else", "{", "name", "=", "new", "StringBuilder", "(", "pQName", ".", "getPrefix", "(", ")", ")", ".", "append", "(", "\":\"", ")", ".", "append", "(", "pQName", ".", "getLocalPart", "(", ")", ")", ".", "toString", "(", ")", ";", "}", "return", "name", ";", "}" ]
Building name consisting out of prefix and name. NamespaceUri is not used over here. @param pQName the {@link QName} of an element @return a string with [prefix:]localname
[ "Building", "name", "consisting", "out", "of", "prefix", "and", "name", ".", "NamespaceUri", "is", "not", "used", "over", "here", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/node/src/main/java/org/treetank/access/NodeWriteTrx.java#L939-L950
143,802
sebastiangraf/treetank
coremodules/commons/src/main/java/org/treetank/exception/TTException.java
TTException.concat
public static StringBuilder concat(final String... message) { final StringBuilder builder = new StringBuilder(); for (final String mess : message) { builder.append(mess); builder.append(" "); } return builder; }
java
public static StringBuilder concat(final String... message) { final StringBuilder builder = new StringBuilder(); for (final String mess : message) { builder.append(mess); builder.append(" "); } return builder; }
[ "public", "static", "StringBuilder", "concat", "(", "final", "String", "...", "message", ")", "{", "final", "StringBuilder", "builder", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "final", "String", "mess", ":", "message", ")", "{", "builder", ".", "append", "(", "mess", ")", ";", "builder", ".", "append", "(", "\" \"", ")", ";", "}", "return", "builder", ";", "}" ]
Util method to provide StringBuilder functionality. @param message to be concatenated @return the StringBuilder for the combined string
[ "Util", "method", "to", "provide", "StringBuilder", "functionality", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/commons/src/main/java/org/treetank/exception/TTException.java#L79-L86
143,803
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/bucket/MetaBucket.java
MetaBucket.put
public IMetaEntry put(final IMetaEntry pKey, final IMetaEntry pVal) { return mMetaMap.put(pKey, pVal); }
java
public IMetaEntry put(final IMetaEntry pKey, final IMetaEntry pVal) { return mMetaMap.put(pKey, pVal); }
[ "public", "IMetaEntry", "put", "(", "final", "IMetaEntry", "pKey", ",", "final", "IMetaEntry", "pVal", ")", "{", "return", "mMetaMap", ".", "put", "(", "pKey", ",", "pVal", ")", ";", "}" ]
Putting an entry to the map. @param pKey to be stored. @param pVal to be stored. @return if entry already existing, return that one. @see ConcurrentHashMap#put(Object, Object)
[ "Putting", "an", "entry", "to", "the", "map", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/bucket/MetaBucket.java#L85-L87
143,804
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.call
@Override public Void call() throws TTException { updateOnly(); if (mCommit == EShredderCommit.COMMIT) { mWtx.commit(); } return null; }
java
@Override public Void call() throws TTException { updateOnly(); if (mCommit == EShredderCommit.COMMIT) { mWtx.commit(); } return null; }
[ "@", "Override", "public", "Void", "call", "(", ")", "throws", "TTException", "{", "updateOnly", "(", ")", ";", "if", "(", "mCommit", "==", "EShredderCommit", ".", "COMMIT", ")", "{", "mWtx", ".", "commit", "(", ")", ";", "}", "return", "null", ";", "}" ]
Invoking the shredder. @throws TTException if Treetank encounters something went wrong @return revision of last revision (before commit)
[ "Invoking", "the", "shredder", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L270-L277
143,805
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.updateOnly
private void updateOnly() throws TTException { try { // Initialize variables. mLevelInToShredder = 0; // mElemsParsed = 0; // mIsLastNode = false; mMovedToRightSibling = false; boolean firstEvent = true; // // If structure already exists, make a sync against the current // // structure. // if (mMaxNodeKey == 0) { // // If no content is in the XML, a normal insertNewContent is // // executed. // insertNewContent(); // } else { if (mWtx.getNode().getKind() == IConstants.ROOT) { // Find the start key for the update operation. long startkey = ROOT_NODE + 1; while (!mWtx.moveTo(startkey)) { startkey++; } } XMLEvent event = null; StringBuilder sBuilder = new StringBuilder(); final XMLEventFactory fac = XMLEventFactory.newInstance(); // Iterate over all nodes. while (mReader.hasNext()) { // Parsing the next event. if (mDelete == EDelete.ATSTARTMIDDLE) { /* * Do not move StAX parser forward if nodes have been * deleted at the start or in the middle of a subtree. */ mDelete = EDelete.NODELETE; } else { // After an insert or after nodes were equal. event = mReader.nextEvent(); if (event.isCharacters() && event.asCharacters().isWhiteSpace()) { continue; } // mElemsParsed++; assert event != null; if (firstEvent) { // Setup start element from StAX parser. firstEvent = false; if (event.getEventType() == XMLStreamConstants.START_DOCUMENT) { while (mReader.hasNext() && event.getEventType() != XMLStreamConstants.START_ELEMENT) { event = mReader.nextEvent(); } assert event.getEventType() == XMLStreamConstants.START_ELEMENT; // mElemsParsed++; } checkState(event.getEventType() == XMLStreamConstants.START_ELEMENT, "StAX parser has to be on START_DOCUMENT or START_ELEMENT event!"); // Get root element of subtree or whole XML document // to shredder. mRootElem = event.asStartElement().getName(); } else if (event != null && event.isEndElement() && mRootElem.equals(event.asEndElement().getName()) && mLevelInToShredder == 1) { // End with shredding if end_elem equals root-elem. break; } } assert event != null; switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: processStartTag(event.asStartElement()); break; case XMLStreamConstants.CHARACTERS: sBuilder.append(event.asCharacters().getData()); while (mReader.peek().getEventType() == XMLStreamConstants.CHARACTERS) { sBuilder.append(mReader.nextEvent().asCharacters().getData()); } final Characters text = fac.createCharacters(sBuilder.toString().trim()); processCharacters(text); sBuilder = new StringBuilder(); break; case XMLStreamConstants.END_ELEMENT: processEndTag(); break; default: // Other nodes which are currently not supported by // Treetank. } // } // if (!mIsLastNode) { // if (mInserted) { // // Remove next node after node, which was inserted, because // it must have been deleted. // if (mWtx.moveToRightSibling()) { // mWtx.remove(); // } // } else { // // Remove current node (cursor has been moved to the next // node already). // mWtx.remove(); // } // // // Also remove any siblings. // boolean hasRightSibling = false; // while (mWtx.getStructuralNode().hasRightSibling()) { // hasRightSibling = true; // mWtx.remove(); // } // if (hasRightSibling) { // mWtx.remove(); // } // } mReader.close(); } // TODO: use Java7 multi-catch feature. } catch (final XMLStreamException e) { throw new TTIOException(e); } catch (final IOException e) { throw new TTIOException(e); } }
java
private void updateOnly() throws TTException { try { // Initialize variables. mLevelInToShredder = 0; // mElemsParsed = 0; // mIsLastNode = false; mMovedToRightSibling = false; boolean firstEvent = true; // // If structure already exists, make a sync against the current // // structure. // if (mMaxNodeKey == 0) { // // If no content is in the XML, a normal insertNewContent is // // executed. // insertNewContent(); // } else { if (mWtx.getNode().getKind() == IConstants.ROOT) { // Find the start key for the update operation. long startkey = ROOT_NODE + 1; while (!mWtx.moveTo(startkey)) { startkey++; } } XMLEvent event = null; StringBuilder sBuilder = new StringBuilder(); final XMLEventFactory fac = XMLEventFactory.newInstance(); // Iterate over all nodes. while (mReader.hasNext()) { // Parsing the next event. if (mDelete == EDelete.ATSTARTMIDDLE) { /* * Do not move StAX parser forward if nodes have been * deleted at the start or in the middle of a subtree. */ mDelete = EDelete.NODELETE; } else { // After an insert or after nodes were equal. event = mReader.nextEvent(); if (event.isCharacters() && event.asCharacters().isWhiteSpace()) { continue; } // mElemsParsed++; assert event != null; if (firstEvent) { // Setup start element from StAX parser. firstEvent = false; if (event.getEventType() == XMLStreamConstants.START_DOCUMENT) { while (mReader.hasNext() && event.getEventType() != XMLStreamConstants.START_ELEMENT) { event = mReader.nextEvent(); } assert event.getEventType() == XMLStreamConstants.START_ELEMENT; // mElemsParsed++; } checkState(event.getEventType() == XMLStreamConstants.START_ELEMENT, "StAX parser has to be on START_DOCUMENT or START_ELEMENT event!"); // Get root element of subtree or whole XML document // to shredder. mRootElem = event.asStartElement().getName(); } else if (event != null && event.isEndElement() && mRootElem.equals(event.asEndElement().getName()) && mLevelInToShredder == 1) { // End with shredding if end_elem equals root-elem. break; } } assert event != null; switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: processStartTag(event.asStartElement()); break; case XMLStreamConstants.CHARACTERS: sBuilder.append(event.asCharacters().getData()); while (mReader.peek().getEventType() == XMLStreamConstants.CHARACTERS) { sBuilder.append(mReader.nextEvent().asCharacters().getData()); } final Characters text = fac.createCharacters(sBuilder.toString().trim()); processCharacters(text); sBuilder = new StringBuilder(); break; case XMLStreamConstants.END_ELEMENT: processEndTag(); break; default: // Other nodes which are currently not supported by // Treetank. } // } // if (!mIsLastNode) { // if (mInserted) { // // Remove next node after node, which was inserted, because // it must have been deleted. // if (mWtx.moveToRightSibling()) { // mWtx.remove(); // } // } else { // // Remove current node (cursor has been moved to the next // node already). // mWtx.remove(); // } // // // Also remove any siblings. // boolean hasRightSibling = false; // while (mWtx.getStructuralNode().hasRightSibling()) { // hasRightSibling = true; // mWtx.remove(); // } // if (hasRightSibling) { // mWtx.remove(); // } // } mReader.close(); } // TODO: use Java7 multi-catch feature. } catch (final XMLStreamException e) { throw new TTIOException(e); } catch (final IOException e) { throw new TTIOException(e); } }
[ "private", "void", "updateOnly", "(", ")", "throws", "TTException", "{", "try", "{", "// Initialize variables.", "mLevelInToShredder", "=", "0", ";", "// mElemsParsed = 0;", "// mIsLastNode = false;", "mMovedToRightSibling", "=", "false", ";", "boolean", "firstEvent", "=", "true", ";", "// // If structure already exists, make a sync against the current", "// // structure.", "// if (mMaxNodeKey == 0) {", "// // If no content is in the XML, a normal insertNewContent is", "// // executed.", "// insertNewContent();", "// } else {", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", "==", "IConstants", ".", "ROOT", ")", "{", "// Find the start key for the update operation.", "long", "startkey", "=", "ROOT_NODE", "+", "1", ";", "while", "(", "!", "mWtx", ".", "moveTo", "(", "startkey", ")", ")", "{", "startkey", "++", ";", "}", "}", "XMLEvent", "event", "=", "null", ";", "StringBuilder", "sBuilder", "=", "new", "StringBuilder", "(", ")", ";", "final", "XMLEventFactory", "fac", "=", "XMLEventFactory", ".", "newInstance", "(", ")", ";", "// Iterate over all nodes.", "while", "(", "mReader", ".", "hasNext", "(", ")", ")", "{", "// Parsing the next event.", "if", "(", "mDelete", "==", "EDelete", ".", "ATSTARTMIDDLE", ")", "{", "/*\n * Do not move StAX parser forward if nodes have been\n * deleted at the start or in the middle of a subtree.\n */", "mDelete", "=", "EDelete", ".", "NODELETE", ";", "}", "else", "{", "// After an insert or after nodes were equal.", "event", "=", "mReader", ".", "nextEvent", "(", ")", ";", "if", "(", "event", ".", "isCharacters", "(", ")", "&&", "event", ".", "asCharacters", "(", ")", ".", "isWhiteSpace", "(", ")", ")", "{", "continue", ";", "}", "// mElemsParsed++;", "assert", "event", "!=", "null", ";", "if", "(", "firstEvent", ")", "{", "// Setup start element from StAX parser.", "firstEvent", "=", "false", ";", "if", "(", "event", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "START_DOCUMENT", ")", "{", "while", "(", "mReader", ".", "hasNext", "(", ")", "&&", "event", ".", "getEventType", "(", ")", "!=", "XMLStreamConstants", ".", "START_ELEMENT", ")", "{", "event", "=", "mReader", ".", "nextEvent", "(", ")", ";", "}", "assert", "event", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "START_ELEMENT", ";", "// mElemsParsed++;", "}", "checkState", "(", "event", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "START_ELEMENT", ",", "\"StAX parser has to be on START_DOCUMENT or START_ELEMENT event!\"", ")", ";", "// Get root element of subtree or whole XML document", "// to shredder.", "mRootElem", "=", "event", ".", "asStartElement", "(", ")", ".", "getName", "(", ")", ";", "}", "else", "if", "(", "event", "!=", "null", "&&", "event", ".", "isEndElement", "(", ")", "&&", "mRootElem", ".", "equals", "(", "event", ".", "asEndElement", "(", ")", ".", "getName", "(", ")", ")", "&&", "mLevelInToShredder", "==", "1", ")", "{", "// End with shredding if end_elem equals root-elem.", "break", ";", "}", "}", "assert", "event", "!=", "null", ";", "switch", "(", "event", ".", "getEventType", "(", ")", ")", "{", "case", "XMLStreamConstants", ".", "START_ELEMENT", ":", "processStartTag", "(", "event", ".", "asStartElement", "(", ")", ")", ";", "break", ";", "case", "XMLStreamConstants", ".", "CHARACTERS", ":", "sBuilder", ".", "append", "(", "event", ".", "asCharacters", "(", ")", ".", "getData", "(", ")", ")", ";", "while", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "CHARACTERS", ")", "{", "sBuilder", ".", "append", "(", "mReader", ".", "nextEvent", "(", ")", ".", "asCharacters", "(", ")", ".", "getData", "(", ")", ")", ";", "}", "final", "Characters", "text", "=", "fac", ".", "createCharacters", "(", "sBuilder", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "processCharacters", "(", "text", ")", ";", "sBuilder", "=", "new", "StringBuilder", "(", ")", ";", "break", ";", "case", "XMLStreamConstants", ".", "END_ELEMENT", ":", "processEndTag", "(", ")", ";", "break", ";", "default", ":", "// Other nodes which are currently not supported by", "// Treetank.", "}", "// }", "// if (!mIsLastNode) {", "// if (mInserted) {", "// // Remove next node after node, which was inserted, because", "// it must have been deleted.", "// if (mWtx.moveToRightSibling()) {", "// mWtx.remove();", "// }", "// } else {", "// // Remove current node (cursor has been moved to the next", "// node already).", "// mWtx.remove();", "// }", "//", "// // Also remove any siblings.", "// boolean hasRightSibling = false;", "// while (mWtx.getStructuralNode().hasRightSibling()) {", "// hasRightSibling = true;", "// mWtx.remove();", "// }", "// if (hasRightSibling) {", "// mWtx.remove();", "// }", "// }", "mReader", ".", "close", "(", ")", ";", "}", "// TODO: use Java7 multi-catch feature.", "}", "catch", "(", "final", "XMLStreamException", "e", ")", "{", "throw", "new", "TTIOException", "(", "e", ")", ";", "}", "catch", "(", "final", "IOException", "e", ")", "{", "throw", "new", "TTIOException", "(", "e", ")", ";", "}", "}" ]
Update a shreddered file. @throws TTException if Treetank encounters something went wrong
[ "Update", "a", "shreddered", "file", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L285-L413
143,806
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.processStartTag
private void processStartTag(final StartElement paramElem) throws IOException, XMLStreamException, TTException { assert paramElem != null; // Initialize variables. initializeVars(); // Main algorithm to determine if same, insert or a delete has to be // made. algorithm(paramElem); if (mFound && mIsRightSibling) { mDelete = EDelete.ATSTARTMIDDLE; deleteNode(); } else if (!mFound) { // Increment levels. mLevelInToShredder++; insertElementNode(paramElem); } else if (mFound) { // Increment levels. mLevelInToShredder++; sameElementNode(); } }
java
private void processStartTag(final StartElement paramElem) throws IOException, XMLStreamException, TTException { assert paramElem != null; // Initialize variables. initializeVars(); // Main algorithm to determine if same, insert or a delete has to be // made. algorithm(paramElem); if (mFound && mIsRightSibling) { mDelete = EDelete.ATSTARTMIDDLE; deleteNode(); } else if (!mFound) { // Increment levels. mLevelInToShredder++; insertElementNode(paramElem); } else if (mFound) { // Increment levels. mLevelInToShredder++; sameElementNode(); } }
[ "private", "void", "processStartTag", "(", "final", "StartElement", "paramElem", ")", "throws", "IOException", ",", "XMLStreamException", ",", "TTException", "{", "assert", "paramElem", "!=", "null", ";", "// Initialize variables.", "initializeVars", "(", ")", ";", "// Main algorithm to determine if same, insert or a delete has to be", "// made.", "algorithm", "(", "paramElem", ")", ";", "if", "(", "mFound", "&&", "mIsRightSibling", ")", "{", "mDelete", "=", "EDelete", ".", "ATSTARTMIDDLE", ";", "deleteNode", "(", ")", ";", "}", "else", "if", "(", "!", "mFound", ")", "{", "// Increment levels.", "mLevelInToShredder", "++", ";", "insertElementNode", "(", "paramElem", ")", ";", "}", "else", "if", "(", "mFound", ")", "{", "// Increment levels.", "mLevelInToShredder", "++", ";", "sameElementNode", "(", ")", ";", "}", "}" ]
Process start tag. @param paramElem {@link StartElement} currently parsed. @throws XMLStreamException In case of any StAX parsing error. @throws IOException In case of any I/O error. @throws TTException In case of any Treetank error.
[ "Process", "start", "tag", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L427-L452
143,807
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.processCharacters
private void processCharacters(final Characters paramText) throws IOException, XMLStreamException, TTException { assert paramText != null; // Initialize variables. initializeVars(); final String text = paramText.getData().toString(); if (!text.isEmpty()) { // Main algorithm to determine if same, insert or a delete has to be // made. algorithm(paramText); if (mFound && mIsRightSibling) { /* * Cannot happen because if text node after end tag get's * deleted it's done already while parsing the end tag. If text * node should be deleted at the top of a subtree (right after a * start tag has been parsed) it's done in * processStartTag(StartElement). */ // mDelete = EDelete.ATSTARTMIDDLE; // deleteNode(); throw new AssertionError(""); } else if (!mFound) { insertTextNode(paramText); } else if (mFound) { sameTextNode(); } } }
java
private void processCharacters(final Characters paramText) throws IOException, XMLStreamException, TTException { assert paramText != null; // Initialize variables. initializeVars(); final String text = paramText.getData().toString(); if (!text.isEmpty()) { // Main algorithm to determine if same, insert or a delete has to be // made. algorithm(paramText); if (mFound && mIsRightSibling) { /* * Cannot happen because if text node after end tag get's * deleted it's done already while parsing the end tag. If text * node should be deleted at the top of a subtree (right after a * start tag has been parsed) it's done in * processStartTag(StartElement). */ // mDelete = EDelete.ATSTARTMIDDLE; // deleteNode(); throw new AssertionError(""); } else if (!mFound) { insertTextNode(paramText); } else if (mFound) { sameTextNode(); } } }
[ "private", "void", "processCharacters", "(", "final", "Characters", "paramText", ")", "throws", "IOException", ",", "XMLStreamException", ",", "TTException", "{", "assert", "paramText", "!=", "null", ";", "// Initialize variables.", "initializeVars", "(", ")", ";", "final", "String", "text", "=", "paramText", ".", "getData", "(", ")", ".", "toString", "(", ")", ";", "if", "(", "!", "text", ".", "isEmpty", "(", ")", ")", "{", "// Main algorithm to determine if same, insert or a delete has to be", "// made.", "algorithm", "(", "paramText", ")", ";", "if", "(", "mFound", "&&", "mIsRightSibling", ")", "{", "/*\n * Cannot happen because if text node after end tag get's\n * deleted it's done already while parsing the end tag. If text\n * node should be deleted at the top of a subtree (right after a\n * start tag has been parsed) it's done in\n * processStartTag(StartElement).\n */", "// mDelete = EDelete.ATSTARTMIDDLE;", "// deleteNode();", "throw", "new", "AssertionError", "(", "\"\"", ")", ";", "}", "else", "if", "(", "!", "mFound", ")", "{", "insertTextNode", "(", "paramText", ")", ";", "}", "else", "if", "(", "mFound", ")", "{", "sameTextNode", "(", ")", ";", "}", "}", "}" ]
Process characters. @param paramText {@link Characters} currently parsed. @throws XMLStreamException In case of any StAX parsing error. @throws IOException In case of any I/O error. @throws TTException In case of any Treetank error.
[ "Process", "characters", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L466-L494
143,808
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.processEndTag
private void processEndTag() throws XMLStreamException, TTException { mLevelInToShredder--; if (mInserted) { mInsertedEndTag = true; } if (mRemovedNode) { mRemovedNode = false; } else { // Move cursor to parent. if (mWtx.getNode().getDataKey() == mLastNodeKey) { /* * An end tag must have been parsed immediately before and it * must have been an empty element at the end of a subtree, thus * move this time to parent node. */ assert mWtx.getNode().hasParent() && mWtx.getNode().getKind() == IConstants.ELEMENT; mWtx.moveTo(mWtx.getNode().getParentKey()); } else { if (mWtx.getNode().getKind() == IConstants.ELEMENT) { final ElementNode element = (ElementNode)mWtx.getNode(); if (element.hasFirstChild() && element.hasParent()) { // It's not an empty element, thus move to parent. mWtx.moveTo(mWtx.getNode().getParentKey()); } // } else { // checkIfLastNode(true); // } } else if (((ITreeStructData)mWtx.getNode()).hasParent()) { if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); /* * Means next event is an end tag in StAX reader, but * something different where the Treetank transaction * points to, which also means it has to be deleted. */ mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } mWtx.moveTo(mWtx.getNode().getParentKey()); } } mLastNodeKey = mWtx.getNode().getDataKey(); // Move cursor to right sibling if it has one. if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); mMovedToRightSibling = true; skipWhitespaces(mReader); if (mReader.peek().getEventType() == XMLStreamConstants.END_ELEMENT) { /* * Means next event is an end tag in StAX reader, but * something different where the Treetank transaction points * to, which also means it has to be deleted. */ mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } } else { mMovedToRightSibling = false; } } }
java
private void processEndTag() throws XMLStreamException, TTException { mLevelInToShredder--; if (mInserted) { mInsertedEndTag = true; } if (mRemovedNode) { mRemovedNode = false; } else { // Move cursor to parent. if (mWtx.getNode().getDataKey() == mLastNodeKey) { /* * An end tag must have been parsed immediately before and it * must have been an empty element at the end of a subtree, thus * move this time to parent node. */ assert mWtx.getNode().hasParent() && mWtx.getNode().getKind() == IConstants.ELEMENT; mWtx.moveTo(mWtx.getNode().getParentKey()); } else { if (mWtx.getNode().getKind() == IConstants.ELEMENT) { final ElementNode element = (ElementNode)mWtx.getNode(); if (element.hasFirstChild() && element.hasParent()) { // It's not an empty element, thus move to parent. mWtx.moveTo(mWtx.getNode().getParentKey()); } // } else { // checkIfLastNode(true); // } } else if (((ITreeStructData)mWtx.getNode()).hasParent()) { if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); /* * Means next event is an end tag in StAX reader, but * something different where the Treetank transaction * points to, which also means it has to be deleted. */ mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } mWtx.moveTo(mWtx.getNode().getParentKey()); } } mLastNodeKey = mWtx.getNode().getDataKey(); // Move cursor to right sibling if it has one. if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); mMovedToRightSibling = true; skipWhitespaces(mReader); if (mReader.peek().getEventType() == XMLStreamConstants.END_ELEMENT) { /* * Means next event is an end tag in StAX reader, but * something different where the Treetank transaction points * to, which also means it has to be deleted. */ mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } } else { mMovedToRightSibling = false; } } }
[ "private", "void", "processEndTag", "(", ")", "throws", "XMLStreamException", ",", "TTException", "{", "mLevelInToShredder", "--", ";", "if", "(", "mInserted", ")", "{", "mInsertedEndTag", "=", "true", ";", "}", "if", "(", "mRemovedNode", ")", "{", "mRemovedNode", "=", "false", ";", "}", "else", "{", "// Move cursor to parent.", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", "==", "mLastNodeKey", ")", "{", "/*\n * An end tag must have been parsed immediately before and it\n * must have been an empty element at the end of a subtree, thus\n * move this time to parent node.\n */", "assert", "mWtx", ".", "getNode", "(", ")", ".", "hasParent", "(", ")", "&&", "mWtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", "==", "IConstants", ".", "ELEMENT", ";", "mWtx", ".", "moveTo", "(", "mWtx", ".", "getNode", "(", ")", ".", "getParentKey", "(", ")", ")", ";", "}", "else", "{", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", "==", "IConstants", ".", "ELEMENT", ")", "{", "final", "ElementNode", "element", "=", "(", "ElementNode", ")", "mWtx", ".", "getNode", "(", ")", ";", "if", "(", "element", ".", "hasFirstChild", "(", ")", "&&", "element", ".", "hasParent", "(", ")", ")", "{", "// It's not an empty element, thus move to parent.", "mWtx", ".", "moveTo", "(", "mWtx", ".", "getNode", "(", ")", ".", "getParentKey", "(", ")", ")", ";", "}", "// } else {", "// checkIfLastNode(true);", "// }", "}", "else", "if", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "hasParent", "(", ")", ")", "{", "if", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "hasRightSibling", "(", ")", ")", "{", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ";", "/*\n * Means next event is an end tag in StAX reader, but\n * something different where the Treetank transaction\n * points to, which also means it has to be deleted.\n */", "mKeyMatches", "=", "-", "1", ";", "mDelete", "=", "EDelete", ".", "ATBOTTOM", ";", "deleteNode", "(", ")", ";", "}", "mWtx", ".", "moveTo", "(", "mWtx", ".", "getNode", "(", ")", ".", "getParentKey", "(", ")", ")", ";", "}", "}", "mLastNodeKey", "=", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ";", "// Move cursor to right sibling if it has one.", "if", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "hasRightSibling", "(", ")", ")", "{", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ";", "mMovedToRightSibling", "=", "true", ";", "skipWhitespaces", "(", "mReader", ")", ";", "if", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "END_ELEMENT", ")", "{", "/*\n * Means next event is an end tag in StAX reader, but\n * something different where the Treetank transaction points\n * to, which also means it has to be deleted.\n */", "mKeyMatches", "=", "-", "1", ";", "mDelete", "=", "EDelete", ".", "ATBOTTOM", ";", "deleteNode", "(", ")", ";", "}", "}", "else", "{", "mMovedToRightSibling", "=", "false", ";", "}", "}", "}" ]
Process end tag. @throws XMLStreamException In case of any parsing error. @throws TTException In case anything went wrong while moving/deleting nodes in Treetank.
[ "Process", "end", "tag", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L505-L574
143,809
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.algorithm
private void algorithm(final XMLEvent paramEvent) throws IOException, XMLStreamException, TTIOException { assert paramEvent != null; do { /* * Check if a node in the shreddered file on the same level equals * the current element node. */ if (paramEvent.isStartElement()) { mFound = checkElement(paramEvent.asStartElement()); } else if (paramEvent.isCharacters()) { mFound = checkText(paramEvent.asCharacters()); } if (mWtx.getNode().getDataKey() != mNodeKey) { mIsRightSibling = true; } mKeyMatches = mWtx.getNode().getDataKey(); // // if (mFound && mIsRightSibling) { // /* // * Root element of next subtree in shreddered file matches // * so check all descendants. If they match the node must be // * inserted. // */ // switch (paramEvent.getEventType()) { // case XMLStreamConstants.START_ELEMENT: // mMoved = EMoved.FIRSTNODE; // //mFound = checkDescendants(paramEvent.asStartElement()); // mFound = checkDescendants(paramEvent.asStartElement()); // break; // case XMLStreamConstants.CHARACTERS: // mFound = checkText(paramEvent.asCharacters()); // break; // default: // // throw new // AssertionError("Node type not known or not implemented!"); // } // mWtx.moveTo(mKeyMatches); // } } while (!mFound && mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())); mWtx.moveTo(mNodeKey); }
java
private void algorithm(final XMLEvent paramEvent) throws IOException, XMLStreamException, TTIOException { assert paramEvent != null; do { /* * Check if a node in the shreddered file on the same level equals * the current element node. */ if (paramEvent.isStartElement()) { mFound = checkElement(paramEvent.asStartElement()); } else if (paramEvent.isCharacters()) { mFound = checkText(paramEvent.asCharacters()); } if (mWtx.getNode().getDataKey() != mNodeKey) { mIsRightSibling = true; } mKeyMatches = mWtx.getNode().getDataKey(); // // if (mFound && mIsRightSibling) { // /* // * Root element of next subtree in shreddered file matches // * so check all descendants. If they match the node must be // * inserted. // */ // switch (paramEvent.getEventType()) { // case XMLStreamConstants.START_ELEMENT: // mMoved = EMoved.FIRSTNODE; // //mFound = checkDescendants(paramEvent.asStartElement()); // mFound = checkDescendants(paramEvent.asStartElement()); // break; // case XMLStreamConstants.CHARACTERS: // mFound = checkText(paramEvent.asCharacters()); // break; // default: // // throw new // AssertionError("Node type not known or not implemented!"); // } // mWtx.moveTo(mKeyMatches); // } } while (!mFound && mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())); mWtx.moveTo(mNodeKey); }
[ "private", "void", "algorithm", "(", "final", "XMLEvent", "paramEvent", ")", "throws", "IOException", ",", "XMLStreamException", ",", "TTIOException", "{", "assert", "paramEvent", "!=", "null", ";", "do", "{", "/*\n * Check if a node in the shreddered file on the same level equals\n * the current element node.\n */", "if", "(", "paramEvent", ".", "isStartElement", "(", ")", ")", "{", "mFound", "=", "checkElement", "(", "paramEvent", ".", "asStartElement", "(", ")", ")", ";", "}", "else", "if", "(", "paramEvent", ".", "isCharacters", "(", ")", ")", "{", "mFound", "=", "checkText", "(", "paramEvent", ".", "asCharacters", "(", ")", ")", ";", "}", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", "!=", "mNodeKey", ")", "{", "mIsRightSibling", "=", "true", ";", "}", "mKeyMatches", "=", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ";", "//", "// if (mFound && mIsRightSibling) {", "// /*", "// * Root element of next subtree in shreddered file matches", "// * so check all descendants. If they match the node must be", "// * inserted.", "// */", "// switch (paramEvent.getEventType()) {", "// case XMLStreamConstants.START_ELEMENT:", "// mMoved = EMoved.FIRSTNODE;", "// //mFound = checkDescendants(paramEvent.asStartElement());", "// mFound = checkDescendants(paramEvent.asStartElement());", "// break;", "// case XMLStreamConstants.CHARACTERS:", "// mFound = checkText(paramEvent.asCharacters());", "// break;", "// default:", "// // throw new", "// AssertionError(\"Node type not known or not implemented!\");", "// }", "// mWtx.moveTo(mKeyMatches);", "// }", "}", "while", "(", "!", "mFound", "&&", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ")", ";", "mWtx", ".", "moveTo", "(", "mNodeKey", ")", ";", "}" ]
Main algorithm to determine if nodes are equal, have to be inserted, or have to be removed. @param paramEvent The currently parsed StAX event. @throws IOException In case the open operation fails (delegated from checkDescendants(...)). @throws XMLStreamException In case any StAX parser problem occurs. @throws TTIOException
[ "Main", "algorithm", "to", "determine", "if", "nodes", "are", "equal", "have", "to", "be", "inserted", "or", "have", "to", "be", "removed", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L589-L630
143,810
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.checkText
private boolean checkText(final Characters paramEvent) { assert paramEvent != null; final String text = paramEvent.getData().trim(); return mWtx.getNode().getKind() == IConstants.TEXT && mWtx.getValueOfCurrentNode().equals(text); }
java
private boolean checkText(final Characters paramEvent) { assert paramEvent != null; final String text = paramEvent.getData().trim(); return mWtx.getNode().getKind() == IConstants.TEXT && mWtx.getValueOfCurrentNode().equals(text); }
[ "private", "boolean", "checkText", "(", "final", "Characters", "paramEvent", ")", "{", "assert", "paramEvent", "!=", "null", ";", "final", "String", "text", "=", "paramEvent", ".", "getData", "(", ")", ".", "trim", "(", ")", ";", "return", "mWtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", "==", "IConstants", ".", "TEXT", "&&", "mWtx", ".", "getValueOfCurrentNode", "(", ")", ".", "equals", "(", "text", ")", ";", "}" ]
Check if text event and text in Treetank storage match. @param paramEvent {@link XMLEvent}. @return true if they match, otherwise false.
[ "Check", "if", "text", "event", "and", "text", "in", "Treetank", "storage", "match", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L639-L643
143,811
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.sameTextNode
private void sameTextNode() throws TTIOException, XMLStreamException { // Update variables. mInsert = EInsert.NOINSERT; mDelete = EDelete.NODELETE; mInserted = false; mInsertedEndTag = false; mRemovedNode = false; // Check if last node reached. // checkIfLastNode(false); // Skip whitespace events. skipWhitespaces(mReader); // Move to right sibling if next node isn't an end tag. if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { // // Check if next node matches or not. // boolean found = false; // if (mReader.peek().getEventType() == // XMLStreamConstants.START_ELEMENT) { // found = checkElement(mReader.peek().asStartElement()); // } else if (mReader.peek().getEventType() == // XMLStreamConstants.CHARACTERS) { // found = checkText(mReader.peek().asCharacters()); // } // // // If next node doesn't match/isn't the same move on. // if (!found) { if (mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())) { mMovedToRightSibling = true; } else { mMovedToRightSibling = false; } // } } mInsert = EInsert.ATMIDDLEBOTTOM; }
java
private void sameTextNode() throws TTIOException, XMLStreamException { // Update variables. mInsert = EInsert.NOINSERT; mDelete = EDelete.NODELETE; mInserted = false; mInsertedEndTag = false; mRemovedNode = false; // Check if last node reached. // checkIfLastNode(false); // Skip whitespace events. skipWhitespaces(mReader); // Move to right sibling if next node isn't an end tag. if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { // // Check if next node matches or not. // boolean found = false; // if (mReader.peek().getEventType() == // XMLStreamConstants.START_ELEMENT) { // found = checkElement(mReader.peek().asStartElement()); // } else if (mReader.peek().getEventType() == // XMLStreamConstants.CHARACTERS) { // found = checkText(mReader.peek().asCharacters()); // } // // // If next node doesn't match/isn't the same move on. // if (!found) { if (mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())) { mMovedToRightSibling = true; } else { mMovedToRightSibling = false; } // } } mInsert = EInsert.ATMIDDLEBOTTOM; }
[ "private", "void", "sameTextNode", "(", ")", "throws", "TTIOException", ",", "XMLStreamException", "{", "// Update variables.", "mInsert", "=", "EInsert", ".", "NOINSERT", ";", "mDelete", "=", "EDelete", ".", "NODELETE", ";", "mInserted", "=", "false", ";", "mInsertedEndTag", "=", "false", ";", "mRemovedNode", "=", "false", ";", "// Check if last node reached.", "// checkIfLastNode(false);", "// Skip whitespace events.", "skipWhitespaces", "(", "mReader", ")", ";", "// Move to right sibling if next node isn't an end tag.", "if", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "!=", "XMLStreamConstants", ".", "END_ELEMENT", ")", "{", "// // Check if next node matches or not.", "// boolean found = false;", "// if (mReader.peek().getEventType() ==", "// XMLStreamConstants.START_ELEMENT) {", "// found = checkElement(mReader.peek().asStartElement());", "// } else if (mReader.peek().getEventType() ==", "// XMLStreamConstants.CHARACTERS) {", "// found = checkText(mReader.peek().asCharacters());", "// }", "//", "// // If next node doesn't match/isn't the same move on.", "// if (!found) {", "if", "(", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ")", "{", "mMovedToRightSibling", "=", "true", ";", "}", "else", "{", "mMovedToRightSibling", "=", "false", ";", "}", "// }", "}", "mInsert", "=", "EInsert", ".", "ATMIDDLEBOTTOM", ";", "}" ]
In case they are the same nodes move cursor to next node and update stack. @throws TTIOException In case of any Treetank error. @throws XMLStreamException In case of any StAX parsing error.
[ "In", "case", "they", "are", "the", "same", "nodes", "move", "cursor", "to", "next", "node", "and", "update", "stack", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L654-L691
143,812
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.sameElementNode
private void sameElementNode() throws XMLStreamException, TTException { // Update variables. mInsert = EInsert.NOINSERT; mDelete = EDelete.NODELETE; mInserted = false; mInsertedEndTag = false; mRemovedNode = false; // Check if last node reached. // checkIfLastNode(false); // Skip whitespace events. skipWhitespaces(mReader); // Move transaction. final ElementNode element = (ElementNode)mWtx.getNode(); if (element.hasFirstChild()) { /* * If next event needs to be inserted, it has to be inserted at the * top of the subtree, as first child. */ mInsert = EInsert.ATTOP; mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getFirstChildKey()); if (mReader.peek().getEventType() == XMLStreamConstants.END_ELEMENT) { /* * Next event is an end tag, so the current child element, where * the transaction currently is located needs to be removed. */ mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } // } else if (mReader.peek().getEventType() == // XMLStreamConstants.END_ELEMENT // && // !mReader.peek().asEndElement().getName().equals(mWtx.getQNameOfCurrentNode())) // { // /* // * Node must be removed when next end tag doesn't match the // current name and it has no children. // */ // mKeyMatches = -1; // mDelete = EDelete.ATBOTTOM; // deleteNode(); } else if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { /* * Treetank transaction can't find a child node, but StAX parser * finds one, so it must be inserted as a first child of the current * node. */ mInsert = EInsert.ATTOP; mEmptyElement = true; } else { mInsert = EInsert.ATMIDDLEBOTTOM; } }
java
private void sameElementNode() throws XMLStreamException, TTException { // Update variables. mInsert = EInsert.NOINSERT; mDelete = EDelete.NODELETE; mInserted = false; mInsertedEndTag = false; mRemovedNode = false; // Check if last node reached. // checkIfLastNode(false); // Skip whitespace events. skipWhitespaces(mReader); // Move transaction. final ElementNode element = (ElementNode)mWtx.getNode(); if (element.hasFirstChild()) { /* * If next event needs to be inserted, it has to be inserted at the * top of the subtree, as first child. */ mInsert = EInsert.ATTOP; mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getFirstChildKey()); if (mReader.peek().getEventType() == XMLStreamConstants.END_ELEMENT) { /* * Next event is an end tag, so the current child element, where * the transaction currently is located needs to be removed. */ mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } // } else if (mReader.peek().getEventType() == // XMLStreamConstants.END_ELEMENT // && // !mReader.peek().asEndElement().getName().equals(mWtx.getQNameOfCurrentNode())) // { // /* // * Node must be removed when next end tag doesn't match the // current name and it has no children. // */ // mKeyMatches = -1; // mDelete = EDelete.ATBOTTOM; // deleteNode(); } else if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { /* * Treetank transaction can't find a child node, but StAX parser * finds one, so it must be inserted as a first child of the current * node. */ mInsert = EInsert.ATTOP; mEmptyElement = true; } else { mInsert = EInsert.ATMIDDLEBOTTOM; } }
[ "private", "void", "sameElementNode", "(", ")", "throws", "XMLStreamException", ",", "TTException", "{", "// Update variables.", "mInsert", "=", "EInsert", ".", "NOINSERT", ";", "mDelete", "=", "EDelete", ".", "NODELETE", ";", "mInserted", "=", "false", ";", "mInsertedEndTag", "=", "false", ";", "mRemovedNode", "=", "false", ";", "// Check if last node reached.", "// checkIfLastNode(false);", "// Skip whitespace events.", "skipWhitespaces", "(", "mReader", ")", ";", "// Move transaction.", "final", "ElementNode", "element", "=", "(", "ElementNode", ")", "mWtx", ".", "getNode", "(", ")", ";", "if", "(", "element", ".", "hasFirstChild", "(", ")", ")", "{", "/*\n * If next event needs to be inserted, it has to be inserted at the\n * top of the subtree, as first child.\n */", "mInsert", "=", "EInsert", ".", "ATTOP", ";", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getFirstChildKey", "(", ")", ")", ";", "if", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "END_ELEMENT", ")", "{", "/*\n * Next event is an end tag, so the current child element, where\n * the transaction currently is located needs to be removed.\n */", "mKeyMatches", "=", "-", "1", ";", "mDelete", "=", "EDelete", ".", "ATBOTTOM", ";", "deleteNode", "(", ")", ";", "}", "// } else if (mReader.peek().getEventType() ==", "// XMLStreamConstants.END_ELEMENT", "// &&", "// !mReader.peek().asEndElement().getName().equals(mWtx.getQNameOfCurrentNode()))", "// {", "// /*", "// * Node must be removed when next end tag doesn't match the", "// current name and it has no children.", "// */", "// mKeyMatches = -1;", "// mDelete = EDelete.ATBOTTOM;", "// deleteNode();", "}", "else", "if", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "!=", "XMLStreamConstants", ".", "END_ELEMENT", ")", "{", "/*\n * Treetank transaction can't find a child node, but StAX parser\n * finds one, so it must be inserted as a first child of the current\n * node.\n */", "mInsert", "=", "EInsert", ".", "ATTOP", ";", "mEmptyElement", "=", "true", ";", "}", "else", "{", "mInsert", "=", "EInsert", ".", "ATMIDDLEBOTTOM", ";", "}", "}" ]
Nodes match, thus update stack and move cursor to first child if it is not a leaf node. @throws XMLStreamException In case of any StAX parsing error. @throws TTException In case anything went wrong while moving the Treetank transaction.
[ "Nodes", "match", "thus", "update", "stack", "and", "move", "cursor", "to", "first", "child", "if", "it", "is", "not", "a", "leaf", "node", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L741-L798
143,813
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.skipWhitespaces
private void skipWhitespaces(final XMLEventReader paramReader) throws XMLStreamException { while (paramReader.peek().getEventType() == XMLStreamConstants.CHARACTERS && paramReader.peek().asCharacters().isWhiteSpace()) { paramReader.nextEvent(); } }
java
private void skipWhitespaces(final XMLEventReader paramReader) throws XMLStreamException { while (paramReader.peek().getEventType() == XMLStreamConstants.CHARACTERS && paramReader.peek().asCharacters().isWhiteSpace()) { paramReader.nextEvent(); } }
[ "private", "void", "skipWhitespaces", "(", "final", "XMLEventReader", "paramReader", ")", "throws", "XMLStreamException", "{", "while", "(", "paramReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "==", "XMLStreamConstants", ".", "CHARACTERS", "&&", "paramReader", ".", "peek", "(", ")", ".", "asCharacters", "(", ")", ".", "isWhiteSpace", "(", ")", ")", "{", "paramReader", ".", "nextEvent", "(", ")", ";", "}", "}" ]
Skip any whitespace event. @param paramReader the StAX {@link XMLEventReader} to use @throws XMLStreamException if any parsing error occurs while moving the StAX parser
[ "Skip", "any", "whitespace", "event", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L808-L813
143,814
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.insertElementNode
private void insertElementNode(final StartElement paramElement) throws TTException, XMLStreamException { assert paramElement != null; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * found in the structure and it is a new last right sibling. */ mDelete = EDelete.NODELETE; mRemovedNode = false; switch (mInsert) { case ATTOP: // We are at the top of a subtree, no end tag has been parsed // before. if (!mEmptyElement) { // Has to be inserted on the parent node. mWtx.moveTo(mWtx.getNode().getParentKey()); } // Insert element as first child. addNewElement(EAdd.ASFIRSTCHILD, paramElement); mInsert = EInsert.INTERMEDIATE; break; case INTERMEDIATE: // Inserts have been made before. EAdd insertNode = EAdd.ASFIRSTCHILD; if (mInsertedEndTag) { /* * An end tag has been read while inserting, thus insert node as * right sibling of parent node. */ mInsertedEndTag = false; insertNode = EAdd.ASRIGHTSIBLING; } // Possibly move one sibling back if transaction already moved to // next node. if (mMovedToRightSibling) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } // Make sure if transaction is on a text node the node is inserted // as a right sibling. if (mWtx.getNode().getKind() == IConstants.TEXT) { insertNode = EAdd.ASRIGHTSIBLING; } addNewElement(insertNode, paramElement); break; case ATMIDDLEBOTTOM: // Insert occurs at the middle or end of a subtree. // Move one sibling back. if (mMovedToRightSibling) { mMovedToRightSibling = false; mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } // Insert element as right sibling. addNewElement(EAdd.ASRIGHTSIBLING, paramElement); mInsert = EInsert.INTERMEDIATE; break; default: throw new AssertionError("Enum value not known!"); } mInserted = true; }
java
private void insertElementNode(final StartElement paramElement) throws TTException, XMLStreamException { assert paramElement != null; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * found in the structure and it is a new last right sibling. */ mDelete = EDelete.NODELETE; mRemovedNode = false; switch (mInsert) { case ATTOP: // We are at the top of a subtree, no end tag has been parsed // before. if (!mEmptyElement) { // Has to be inserted on the parent node. mWtx.moveTo(mWtx.getNode().getParentKey()); } // Insert element as first child. addNewElement(EAdd.ASFIRSTCHILD, paramElement); mInsert = EInsert.INTERMEDIATE; break; case INTERMEDIATE: // Inserts have been made before. EAdd insertNode = EAdd.ASFIRSTCHILD; if (mInsertedEndTag) { /* * An end tag has been read while inserting, thus insert node as * right sibling of parent node. */ mInsertedEndTag = false; insertNode = EAdd.ASRIGHTSIBLING; } // Possibly move one sibling back if transaction already moved to // next node. if (mMovedToRightSibling) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } // Make sure if transaction is on a text node the node is inserted // as a right sibling. if (mWtx.getNode().getKind() == IConstants.TEXT) { insertNode = EAdd.ASRIGHTSIBLING; } addNewElement(insertNode, paramElement); break; case ATMIDDLEBOTTOM: // Insert occurs at the middle or end of a subtree. // Move one sibling back. if (mMovedToRightSibling) { mMovedToRightSibling = false; mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } // Insert element as right sibling. addNewElement(EAdd.ASRIGHTSIBLING, paramElement); mInsert = EInsert.INTERMEDIATE; break; default: throw new AssertionError("Enum value not known!"); } mInserted = true; }
[ "private", "void", "insertElementNode", "(", "final", "StartElement", "paramElement", ")", "throws", "TTException", ",", "XMLStreamException", "{", "assert", "paramElement", "!=", "null", ";", "/*\n * Add node if it's either not found among right siblings (and the\n * cursor on the shreddered file is on a right sibling) or if it's not\n * found in the structure and it is a new last right sibling.\n */", "mDelete", "=", "EDelete", ".", "NODELETE", ";", "mRemovedNode", "=", "false", ";", "switch", "(", "mInsert", ")", "{", "case", "ATTOP", ":", "// We are at the top of a subtree, no end tag has been parsed", "// before.", "if", "(", "!", "mEmptyElement", ")", "{", "// Has to be inserted on the parent node.", "mWtx", ".", "moveTo", "(", "mWtx", ".", "getNode", "(", ")", ".", "getParentKey", "(", ")", ")", ";", "}", "// Insert element as first child.", "addNewElement", "(", "EAdd", ".", "ASFIRSTCHILD", ",", "paramElement", ")", ";", "mInsert", "=", "EInsert", ".", "INTERMEDIATE", ";", "break", ";", "case", "INTERMEDIATE", ":", "// Inserts have been made before.", "EAdd", "insertNode", "=", "EAdd", ".", "ASFIRSTCHILD", ";", "if", "(", "mInsertedEndTag", ")", "{", "/*\n * An end tag has been read while inserting, thus insert node as\n * right sibling of parent node.\n */", "mInsertedEndTag", "=", "false", ";", "insertNode", "=", "EAdd", ".", "ASRIGHTSIBLING", ";", "}", "// Possibly move one sibling back if transaction already moved to", "// next node.", "if", "(", "mMovedToRightSibling", ")", "{", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getLeftSiblingKey", "(", ")", ")", ";", "}", "// Make sure if transaction is on a text node the node is inserted", "// as a right sibling.", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", "==", "IConstants", ".", "TEXT", ")", "{", "insertNode", "=", "EAdd", ".", "ASRIGHTSIBLING", ";", "}", "addNewElement", "(", "insertNode", ",", "paramElement", ")", ";", "break", ";", "case", "ATMIDDLEBOTTOM", ":", "// Insert occurs at the middle or end of a subtree.", "// Move one sibling back.", "if", "(", "mMovedToRightSibling", ")", "{", "mMovedToRightSibling", "=", "false", ";", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getLeftSiblingKey", "(", ")", ")", ";", "}", "// Insert element as right sibling.", "addNewElement", "(", "EAdd", ".", "ASRIGHTSIBLING", ",", "paramElement", ")", ";", "mInsert", "=", "EInsert", ".", "INTERMEDIATE", ";", "break", ";", "default", ":", "throw", "new", "AssertionError", "(", "\"Enum value not known!\"", ")", ";", "}", "mInserted", "=", "true", ";", "}" ]
Insert an element node. @param paramElement {@link StartElement}, which is going to be inserted. @throws TTException In case any exception occurs while moving the cursor or deleting nodes in Treetank. @throws XMLStreamException In case of any StAX parsing error.
[ "Insert", "an", "element", "node", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L826-L894
143,815
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.insertTextNode
private void insertTextNode(final Characters paramText) throws TTException, XMLStreamException { assert paramText != null; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * found in the structure and it is a new last right sibling. */ mDelete = EDelete.NODELETE; mRemovedNode = false; switch (mInsert) { case ATTOP: // Insert occurs at the top of a subtree (no end tag has been parsed // immediately before). // Move to parent. mWtx.moveTo(mWtx.getNode().getParentKey()); // Insert as first child. addNewText(EAdd.ASFIRSTCHILD, paramText); // Move to next node if no end tag follows (thus cursor isn't moved // to parent in processEndTag()). if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { if (mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())) { mMovedToRightSibling = true; } else { mMovedToRightSibling = false; } } else if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { mMovedToRightSibling = false; mInserted = true; mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } mInsert = EInsert.INTERMEDIATE; break; case INTERMEDIATE: // Inserts have been made before. EAdd addNode = EAdd.ASFIRSTCHILD; if (mInsertedEndTag) { /* * An end tag has been read while inserting, so move back to * left sibling if there is one and insert as right sibling. */ if (mMovedToRightSibling) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } addNode = EAdd.ASRIGHTSIBLING; mInsertedEndTag = false; } // Insert element as right sibling. addNewText(addNode, paramText); // Move to next node if no end tag follows (thus cursor isn't moved // to parent in processEndTag()). if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { if (mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())) { mMovedToRightSibling = true; } else { mMovedToRightSibling = false; } } break; case ATMIDDLEBOTTOM: // Insert occurs in the middle or end of a subtree. // Move one sibling back. if (mMovedToRightSibling) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } // Insert element as right sibling. addNewText(EAdd.ASRIGHTSIBLING, paramText); // Move to next node. mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); mInsert = EInsert.INTERMEDIATE; break; default: throw new AssertionError("Enum value not known!"); } mInserted = true; }
java
private void insertTextNode(final Characters paramText) throws TTException, XMLStreamException { assert paramText != null; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * found in the structure and it is a new last right sibling. */ mDelete = EDelete.NODELETE; mRemovedNode = false; switch (mInsert) { case ATTOP: // Insert occurs at the top of a subtree (no end tag has been parsed // immediately before). // Move to parent. mWtx.moveTo(mWtx.getNode().getParentKey()); // Insert as first child. addNewText(EAdd.ASFIRSTCHILD, paramText); // Move to next node if no end tag follows (thus cursor isn't moved // to parent in processEndTag()). if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { if (mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())) { mMovedToRightSibling = true; } else { mMovedToRightSibling = false; } } else if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { mMovedToRightSibling = false; mInserted = true; mKeyMatches = -1; mDelete = EDelete.ATBOTTOM; deleteNode(); } mInsert = EInsert.INTERMEDIATE; break; case INTERMEDIATE: // Inserts have been made before. EAdd addNode = EAdd.ASFIRSTCHILD; if (mInsertedEndTag) { /* * An end tag has been read while inserting, so move back to * left sibling if there is one and insert as right sibling. */ if (mMovedToRightSibling) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } addNode = EAdd.ASRIGHTSIBLING; mInsertedEndTag = false; } // Insert element as right sibling. addNewText(addNode, paramText); // Move to next node if no end tag follows (thus cursor isn't moved // to parent in processEndTag()). if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) { if (mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey())) { mMovedToRightSibling = true; } else { mMovedToRightSibling = false; } } break; case ATMIDDLEBOTTOM: // Insert occurs in the middle or end of a subtree. // Move one sibling back. if (mMovedToRightSibling) { mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getLeftSiblingKey()); } // Insert element as right sibling. addNewText(EAdd.ASRIGHTSIBLING, paramText); // Move to next node. mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); mInsert = EInsert.INTERMEDIATE; break; default: throw new AssertionError("Enum value not known!"); } mInserted = true; }
[ "private", "void", "insertTextNode", "(", "final", "Characters", "paramText", ")", "throws", "TTException", ",", "XMLStreamException", "{", "assert", "paramText", "!=", "null", ";", "/*\n * Add node if it's either not found among right siblings (and the\n * cursor on the shreddered file is on a right sibling) or if it's not\n * found in the structure and it is a new last right sibling.\n */", "mDelete", "=", "EDelete", ".", "NODELETE", ";", "mRemovedNode", "=", "false", ";", "switch", "(", "mInsert", ")", "{", "case", "ATTOP", ":", "// Insert occurs at the top of a subtree (no end tag has been parsed", "// immediately before).", "// Move to parent.", "mWtx", ".", "moveTo", "(", "mWtx", ".", "getNode", "(", ")", ".", "getParentKey", "(", ")", ")", ";", "// Insert as first child.", "addNewText", "(", "EAdd", ".", "ASFIRSTCHILD", ",", "paramText", ")", ";", "// Move to next node if no end tag follows (thus cursor isn't moved", "// to parent in processEndTag()).", "if", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "!=", "XMLStreamConstants", ".", "END_ELEMENT", ")", "{", "if", "(", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ")", "{", "mMovedToRightSibling", "=", "true", ";", "}", "else", "{", "mMovedToRightSibling", "=", "false", ";", "}", "}", "else", "if", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "hasRightSibling", "(", ")", ")", "{", "mMovedToRightSibling", "=", "false", ";", "mInserted", "=", "true", ";", "mKeyMatches", "=", "-", "1", ";", "mDelete", "=", "EDelete", ".", "ATBOTTOM", ";", "deleteNode", "(", ")", ";", "}", "mInsert", "=", "EInsert", ".", "INTERMEDIATE", ";", "break", ";", "case", "INTERMEDIATE", ":", "// Inserts have been made before.", "EAdd", "addNode", "=", "EAdd", ".", "ASFIRSTCHILD", ";", "if", "(", "mInsertedEndTag", ")", "{", "/*\n * An end tag has been read while inserting, so move back to\n * left sibling if there is one and insert as right sibling.\n */", "if", "(", "mMovedToRightSibling", ")", "{", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getLeftSiblingKey", "(", ")", ")", ";", "}", "addNode", "=", "EAdd", ".", "ASRIGHTSIBLING", ";", "mInsertedEndTag", "=", "false", ";", "}", "// Insert element as right sibling.", "addNewText", "(", "addNode", ",", "paramText", ")", ";", "// Move to next node if no end tag follows (thus cursor isn't moved", "// to parent in processEndTag()).", "if", "(", "mReader", ".", "peek", "(", ")", ".", "getEventType", "(", ")", "!=", "XMLStreamConstants", ".", "END_ELEMENT", ")", "{", "if", "(", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ")", "{", "mMovedToRightSibling", "=", "true", ";", "}", "else", "{", "mMovedToRightSibling", "=", "false", ";", "}", "}", "break", ";", "case", "ATMIDDLEBOTTOM", ":", "// Insert occurs in the middle or end of a subtree.", "// Move one sibling back.", "if", "(", "mMovedToRightSibling", ")", "{", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getLeftSiblingKey", "(", ")", ")", ";", "}", "// Insert element as right sibling.", "addNewText", "(", "EAdd", ".", "ASRIGHTSIBLING", ",", "paramText", ")", ";", "// Move to next node.", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ";", "mInsert", "=", "EInsert", ".", "INTERMEDIATE", ";", "break", ";", "default", ":", "throw", "new", "AssertionError", "(", "\"Enum value not known!\"", ")", ";", "}", "mInserted", "=", "true", ";", "}" ]
Insert a text node. @param paramText {@link Characters}, which is going to be inserted. @throws TTException In case any exception occurs while moving the cursor or deleting nodes in Treetank. @throws XMLStreamException In case of any StAX parsing error.
[ "Insert", "a", "text", "node", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L907-L996
143,816
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.deleteNode
private void deleteNode() throws TTException { /* * If found in one of the rightsiblings in the current shreddered * structure remove all nodes until the transaction points to the found * node (keyMatches). */ if (mInserted && !mMovedToRightSibling) { mInserted = false; if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { // Cursor is on the inserted node, so move to right sibling. mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); } } // // Check if transaction is on the last node in the shreddered file. // checkIfLastNode(true); // Determines if transaction has moved to the parent node after a delete // operation. boolean movedToParent = false; // Determines if ldeleteNodeast node in a subtree is going to be // deleted. boolean isLast = false; do { if (mWtx.getNode().getDataKey() != mKeyMatches) { final ITreeStructData node = (ITreeStructData)mWtx.getNode(); if (!node.hasRightSibling() && !node.hasLeftSibling()) { // if (mDelete == EDelete.ATSTARTMIDDLE) { // // If the delete occurs right before an end tag the // // level hasn't been incremented. // mLevelInShreddered--; // } /* * Node has no right and no left sibling, so the transaction * moves to the parent after the delete. */ movedToParent = true; } else if (!node.hasRightSibling()) { // Last node has been reached, which means that the // transaction moves to the left sibling. isLast = true; } mWtx.remove(); } } while (mWtx.getNode().getDataKey() != mKeyMatches && !movedToParent && !isLast); if (movedToParent) { if (mDelete == EDelete.ATBOTTOM) { /* * Deleted right before an end tag has been parsed, thus don't * move transaction to next node in processEndTag(). */ mRemovedNode = true; } /* * Treetank transaction has been moved to parent, because all child * nodes have been deleted, thus to right sibling. */ mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); } else { if (((ITreeStructData)mWtx.getNode()).hasFirstChild()) { if (mDelete == EDelete.ATBOTTOM && isLast) { /* * Deleted right before an end tag has been parsed, thus * don't move transaction to next node in processEndTag(). */ mRemovedNode = true; } if (isLast) { // If last node of a subtree has been removed, move to // parent and right sibling. mWtx.moveTo(mWtx.getNode().getParentKey()); mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); // // If the delete occurs right before an end tag the level // // hasn't been incremented. // if (mDelete == EDelete.ATSTARTMIDDLE) { // mLevelInShreddered--; // } } } } // Check if transaction is on the last node in the shreddered file. // checkIfLastNode(true); mInsert = EInsert.NOINSERT; }
java
private void deleteNode() throws TTException { /* * If found in one of the rightsiblings in the current shreddered * structure remove all nodes until the transaction points to the found * node (keyMatches). */ if (mInserted && !mMovedToRightSibling) { mInserted = false; if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) { // Cursor is on the inserted node, so move to right sibling. mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); } } // // Check if transaction is on the last node in the shreddered file. // checkIfLastNode(true); // Determines if transaction has moved to the parent node after a delete // operation. boolean movedToParent = false; // Determines if ldeleteNodeast node in a subtree is going to be // deleted. boolean isLast = false; do { if (mWtx.getNode().getDataKey() != mKeyMatches) { final ITreeStructData node = (ITreeStructData)mWtx.getNode(); if (!node.hasRightSibling() && !node.hasLeftSibling()) { // if (mDelete == EDelete.ATSTARTMIDDLE) { // // If the delete occurs right before an end tag the // // level hasn't been incremented. // mLevelInShreddered--; // } /* * Node has no right and no left sibling, so the transaction * moves to the parent after the delete. */ movedToParent = true; } else if (!node.hasRightSibling()) { // Last node has been reached, which means that the // transaction moves to the left sibling. isLast = true; } mWtx.remove(); } } while (mWtx.getNode().getDataKey() != mKeyMatches && !movedToParent && !isLast); if (movedToParent) { if (mDelete == EDelete.ATBOTTOM) { /* * Deleted right before an end tag has been parsed, thus don't * move transaction to next node in processEndTag(). */ mRemovedNode = true; } /* * Treetank transaction has been moved to parent, because all child * nodes have been deleted, thus to right sibling. */ mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); } else { if (((ITreeStructData)mWtx.getNode()).hasFirstChild()) { if (mDelete == EDelete.ATBOTTOM && isLast) { /* * Deleted right before an end tag has been parsed, thus * don't move transaction to next node in processEndTag(). */ mRemovedNode = true; } if (isLast) { // If last node of a subtree has been removed, move to // parent and right sibling. mWtx.moveTo(mWtx.getNode().getParentKey()); mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey()); // // If the delete occurs right before an end tag the level // // hasn't been incremented. // if (mDelete == EDelete.ATSTARTMIDDLE) { // mLevelInShreddered--; // } } } } // Check if transaction is on the last node in the shreddered file. // checkIfLastNode(true); mInsert = EInsert.NOINSERT; }
[ "private", "void", "deleteNode", "(", ")", "throws", "TTException", "{", "/*\n * If found in one of the rightsiblings in the current shreddered\n * structure remove all nodes until the transaction points to the found\n * node (keyMatches).\n */", "if", "(", "mInserted", "&&", "!", "mMovedToRightSibling", ")", "{", "mInserted", "=", "false", ";", "if", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "hasRightSibling", "(", ")", ")", "{", "// Cursor is on the inserted node, so move to right sibling.", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ";", "}", "}", "// // Check if transaction is on the last node in the shreddered file.", "// checkIfLastNode(true);", "// Determines if transaction has moved to the parent node after a delete", "// operation.", "boolean", "movedToParent", "=", "false", ";", "// Determines if ldeleteNodeast node in a subtree is going to be", "// deleted.", "boolean", "isLast", "=", "false", ";", "do", "{", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", "!=", "mKeyMatches", ")", "{", "final", "ITreeStructData", "node", "=", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ";", "if", "(", "!", "node", ".", "hasRightSibling", "(", ")", "&&", "!", "node", ".", "hasLeftSibling", "(", ")", ")", "{", "// if (mDelete == EDelete.ATSTARTMIDDLE) {", "// // If the delete occurs right before an end tag the", "// // level hasn't been incremented.", "// mLevelInShreddered--;", "// }", "/*\n * Node has no right and no left sibling, so the transaction\n * moves to the parent after the delete.\n */", "movedToParent", "=", "true", ";", "}", "else", "if", "(", "!", "node", ".", "hasRightSibling", "(", ")", ")", "{", "// Last node has been reached, which means that the", "// transaction moves to the left sibling.", "isLast", "=", "true", ";", "}", "mWtx", ".", "remove", "(", ")", ";", "}", "}", "while", "(", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", "!=", "mKeyMatches", "&&", "!", "movedToParent", "&&", "!", "isLast", ")", ";", "if", "(", "movedToParent", ")", "{", "if", "(", "mDelete", "==", "EDelete", ".", "ATBOTTOM", ")", "{", "/*\n * Deleted right before an end tag has been parsed, thus don't\n * move transaction to next node in processEndTag().\n */", "mRemovedNode", "=", "true", ";", "}", "/*\n * Treetank transaction has been moved to parent, because all child\n * nodes have been deleted, thus to right sibling.\n */", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ";", "}", "else", "{", "if", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "hasFirstChild", "(", ")", ")", "{", "if", "(", "mDelete", "==", "EDelete", ".", "ATBOTTOM", "&&", "isLast", ")", "{", "/*\n * Deleted right before an end tag has been parsed, thus\n * don't move transaction to next node in processEndTag().\n */", "mRemovedNode", "=", "true", ";", "}", "if", "(", "isLast", ")", "{", "// If last node of a subtree has been removed, move to", "// parent and right sibling.", "mWtx", ".", "moveTo", "(", "mWtx", ".", "getNode", "(", ")", ".", "getParentKey", "(", ")", ")", ";", "mWtx", ".", "moveTo", "(", "(", "(", "ITreeStructData", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getRightSiblingKey", "(", ")", ")", ";", "// // If the delete occurs right before an end tag the level", "// // hasn't been incremented.", "// if (mDelete == EDelete.ATSTARTMIDDLE) {", "// mLevelInShreddered--;", "// }", "}", "}", "}", "// Check if transaction is on the last node in the shreddered file.", "// checkIfLastNode(true);", "mInsert", "=", "EInsert", ".", "NOINSERT", ";", "}" ]
Delete node. @throws TTException In case any exception occurs while moving the cursor or deleting nodes in Treetank.
[ "Delete", "node", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L1005-L1095
143,817
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.initializeVars
private void initializeVars() { mNodeKey = mWtx.getNode().getDataKey(); mFound = false; mIsRightSibling = false; mKeyMatches = -1; }
java
private void initializeVars() { mNodeKey = mWtx.getNode().getDataKey(); mFound = false; mIsRightSibling = false; mKeyMatches = -1; }
[ "private", "void", "initializeVars", "(", ")", "{", "mNodeKey", "=", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ";", "mFound", "=", "false", ";", "mIsRightSibling", "=", "false", ";", "mKeyMatches", "=", "-", "1", ";", "}" ]
Initialize variables needed for the main algorithm.
[ "Initialize", "variables", "needed", "for", "the", "main", "algorithm", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L1100-L1105
143,818
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java
XMLUpdateShredder.checkElement
private boolean checkElement(final StartElement mEvent) throws TTIOException { assert mEvent != null; boolean retVal = false; // Matching element names? if (mWtx.getNode().getKind() == IConstants.ELEMENT && mWtx.getQNameOfCurrentNode().equals(mEvent.getName())) { // Check if atts and namespaces are the same. final long nodeKey = mWtx.getNode().getDataKey(); // Check attributes. boolean foundAtts = false; boolean hasAtts = false; for (final Iterator<?> it = mEvent.getAttributes(); it.hasNext();) { hasAtts = true; final Attribute attribute = (Attribute)it.next(); for (int i = 0, attCount = ((ElementNode)mWtx.getNode()).getAttributeCount(); i < attCount; i++) { mWtx.moveToAttribute(i); if (attribute.getName().equals(mWtx.getQNameOfCurrentNode()) && attribute.getValue().equals(mWtx.getValueOfCurrentNode())) { foundAtts = true; mWtx.moveTo(nodeKey); break; } mWtx.moveTo(nodeKey); } if (!foundAtts) { break; } } if (!hasAtts && ((ElementNode)mWtx.getNode()).getAttributeCount() == 0) { foundAtts = true; } // Check namespaces. boolean foundNamesps = false; boolean hasNamesps = false; for (final Iterator<?> namespIt = mEvent.getNamespaces(); namespIt.hasNext();) { hasNamesps = true; final Namespace namespace = (Namespace)namespIt.next(); for (int i = 0, namespCount = ((ElementNode)mWtx.getNode()).getNamespaceCount(); i < namespCount; i++) { mWtx.moveToNamespace(i); final ITreeNameData namenode = (ITreeNameData)mWtx.getNode(); if (namespace.getNamespaceURI().equals(mWtx.nameForKey(namenode.getURIKey())) && namespace.getPrefix().equals(mWtx.nameForKey(namenode.getNameKey()))) { foundNamesps = true; mWtx.moveTo(nodeKey); break; } mWtx.moveTo(nodeKey); } if (!foundNamesps) { break; } } if (!hasNamesps && ((ElementNode)mWtx.getNode()).getNamespaceCount() == 0) { foundNamesps = true; } // Check if atts and namespaces are the same. if (foundAtts && foundNamesps) { retVal = true; } else { retVal = false; } } return retVal; }
java
private boolean checkElement(final StartElement mEvent) throws TTIOException { assert mEvent != null; boolean retVal = false; // Matching element names? if (mWtx.getNode().getKind() == IConstants.ELEMENT && mWtx.getQNameOfCurrentNode().equals(mEvent.getName())) { // Check if atts and namespaces are the same. final long nodeKey = mWtx.getNode().getDataKey(); // Check attributes. boolean foundAtts = false; boolean hasAtts = false; for (final Iterator<?> it = mEvent.getAttributes(); it.hasNext();) { hasAtts = true; final Attribute attribute = (Attribute)it.next(); for (int i = 0, attCount = ((ElementNode)mWtx.getNode()).getAttributeCount(); i < attCount; i++) { mWtx.moveToAttribute(i); if (attribute.getName().equals(mWtx.getQNameOfCurrentNode()) && attribute.getValue().equals(mWtx.getValueOfCurrentNode())) { foundAtts = true; mWtx.moveTo(nodeKey); break; } mWtx.moveTo(nodeKey); } if (!foundAtts) { break; } } if (!hasAtts && ((ElementNode)mWtx.getNode()).getAttributeCount() == 0) { foundAtts = true; } // Check namespaces. boolean foundNamesps = false; boolean hasNamesps = false; for (final Iterator<?> namespIt = mEvent.getNamespaces(); namespIt.hasNext();) { hasNamesps = true; final Namespace namespace = (Namespace)namespIt.next(); for (int i = 0, namespCount = ((ElementNode)mWtx.getNode()).getNamespaceCount(); i < namespCount; i++) { mWtx.moveToNamespace(i); final ITreeNameData namenode = (ITreeNameData)mWtx.getNode(); if (namespace.getNamespaceURI().equals(mWtx.nameForKey(namenode.getURIKey())) && namespace.getPrefix().equals(mWtx.nameForKey(namenode.getNameKey()))) { foundNamesps = true; mWtx.moveTo(nodeKey); break; } mWtx.moveTo(nodeKey); } if (!foundNamesps) { break; } } if (!hasNamesps && ((ElementNode)mWtx.getNode()).getNamespaceCount() == 0) { foundNamesps = true; } // Check if atts and namespaces are the same. if (foundAtts && foundNamesps) { retVal = true; } else { retVal = false; } } return retVal; }
[ "private", "boolean", "checkElement", "(", "final", "StartElement", "mEvent", ")", "throws", "TTIOException", "{", "assert", "mEvent", "!=", "null", ";", "boolean", "retVal", "=", "false", ";", "// Matching element names?", "if", "(", "mWtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", "==", "IConstants", ".", "ELEMENT", "&&", "mWtx", ".", "getQNameOfCurrentNode", "(", ")", ".", "equals", "(", "mEvent", ".", "getName", "(", ")", ")", ")", "{", "// Check if atts and namespaces are the same.", "final", "long", "nodeKey", "=", "mWtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ";", "// Check attributes.", "boolean", "foundAtts", "=", "false", ";", "boolean", "hasAtts", "=", "false", ";", "for", "(", "final", "Iterator", "<", "?", ">", "it", "=", "mEvent", ".", "getAttributes", "(", ")", ";", "it", ".", "hasNext", "(", ")", ";", ")", "{", "hasAtts", "=", "true", ";", "final", "Attribute", "attribute", "=", "(", "Attribute", ")", "it", ".", "next", "(", ")", ";", "for", "(", "int", "i", "=", "0", ",", "attCount", "=", "(", "(", "ElementNode", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getAttributeCount", "(", ")", ";", "i", "<", "attCount", ";", "i", "++", ")", "{", "mWtx", ".", "moveToAttribute", "(", "i", ")", ";", "if", "(", "attribute", ".", "getName", "(", ")", ".", "equals", "(", "mWtx", ".", "getQNameOfCurrentNode", "(", ")", ")", "&&", "attribute", ".", "getValue", "(", ")", ".", "equals", "(", "mWtx", ".", "getValueOfCurrentNode", "(", ")", ")", ")", "{", "foundAtts", "=", "true", ";", "mWtx", ".", "moveTo", "(", "nodeKey", ")", ";", "break", ";", "}", "mWtx", ".", "moveTo", "(", "nodeKey", ")", ";", "}", "if", "(", "!", "foundAtts", ")", "{", "break", ";", "}", "}", "if", "(", "!", "hasAtts", "&&", "(", "(", "ElementNode", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getAttributeCount", "(", ")", "==", "0", ")", "{", "foundAtts", "=", "true", ";", "}", "// Check namespaces.", "boolean", "foundNamesps", "=", "false", ";", "boolean", "hasNamesps", "=", "false", ";", "for", "(", "final", "Iterator", "<", "?", ">", "namespIt", "=", "mEvent", ".", "getNamespaces", "(", ")", ";", "namespIt", ".", "hasNext", "(", ")", ";", ")", "{", "hasNamesps", "=", "true", ";", "final", "Namespace", "namespace", "=", "(", "Namespace", ")", "namespIt", ".", "next", "(", ")", ";", "for", "(", "int", "i", "=", "0", ",", "namespCount", "=", "(", "(", "ElementNode", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getNamespaceCount", "(", ")", ";", "i", "<", "namespCount", ";", "i", "++", ")", "{", "mWtx", ".", "moveToNamespace", "(", "i", ")", ";", "final", "ITreeNameData", "namenode", "=", "(", "ITreeNameData", ")", "mWtx", ".", "getNode", "(", ")", ";", "if", "(", "namespace", ".", "getNamespaceURI", "(", ")", ".", "equals", "(", "mWtx", ".", "nameForKey", "(", "namenode", ".", "getURIKey", "(", ")", ")", ")", "&&", "namespace", ".", "getPrefix", "(", ")", ".", "equals", "(", "mWtx", ".", "nameForKey", "(", "namenode", ".", "getNameKey", "(", ")", ")", ")", ")", "{", "foundNamesps", "=", "true", ";", "mWtx", ".", "moveTo", "(", "nodeKey", ")", ";", "break", ";", "}", "mWtx", ".", "moveTo", "(", "nodeKey", ")", ";", "}", "if", "(", "!", "foundNamesps", ")", "{", "break", ";", "}", "}", "if", "(", "!", "hasNamesps", "&&", "(", "(", "ElementNode", ")", "mWtx", ".", "getNode", "(", ")", ")", ".", "getNamespaceCount", "(", ")", "==", "0", ")", "{", "foundNamesps", "=", "true", ";", "}", "// Check if atts and namespaces are the same.", "if", "(", "foundAtts", "&&", "foundNamesps", ")", "{", "retVal", "=", "true", ";", "}", "else", "{", "retVal", "=", "false", ";", "}", "}", "return", "retVal", ";", "}" ]
Check if current element matches the element in the shreddered file. @param mEvent StartElement event, from the XML file to shredder. @return true if they are equal, false otherwise. @throws TTIOException
[ "Check", "if", "current", "element", "matches", "the", "element", "in", "the", "shreddered", "file", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/shredder/XMLUpdateShredder.java#L1179-L1249
143,819
centic9/commons-dost
src/main/java/org/dstadler/commons/util/SortedProperties.java
SortedProperties.keys
@Override @SuppressWarnings({ "unchecked" }) public synchronized Enumeration<Object> keys() { Enumeration<Object> keysEnum = super.keys(); @SuppressWarnings("rawtypes") Vector keyList = new Vector<>(); // NOPMD - vector used on purpose here... while (keysEnum.hasMoreElements()) { keyList.add(keysEnum.nextElement()); } Collections.sort(keyList); // reverse this list to have the newest items on top Collections.reverse(keyList); return keyList.elements(); }
java
@Override @SuppressWarnings({ "unchecked" }) public synchronized Enumeration<Object> keys() { Enumeration<Object> keysEnum = super.keys(); @SuppressWarnings("rawtypes") Vector keyList = new Vector<>(); // NOPMD - vector used on purpose here... while (keysEnum.hasMoreElements()) { keyList.add(keysEnum.nextElement()); } Collections.sort(keyList); // reverse this list to have the newest items on top Collections.reverse(keyList); return keyList.elements(); }
[ "@", "Override", "@", "SuppressWarnings", "(", "{", "\"unchecked\"", "}", ")", "public", "synchronized", "Enumeration", "<", "Object", ">", "keys", "(", ")", "{", "Enumeration", "<", "Object", ">", "keysEnum", "=", "super", ".", "keys", "(", ")", ";", "@", "SuppressWarnings", "(", "\"rawtypes\"", ")", "Vector", "keyList", "=", "new", "Vector", "<>", "(", ")", ";", "// NOPMD - vector used on purpose here...", "while", "(", "keysEnum", ".", "hasMoreElements", "(", ")", ")", "{", "keyList", ".", "add", "(", "keysEnum", ".", "nextElement", "(", ")", ")", ";", "}", "Collections", ".", "sort", "(", "keyList", ")", ";", "// reverse this list to have the newest items on top", "Collections", ".", "reverse", "(", "keyList", ")", ";", "return", "keyList", ".", "elements", "(", ")", ";", "}" ]
Overrides, called by the store method.
[ "Overrides", "called", "by", "the", "store", "method", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/util/SortedProperties.java#L22-L38
143,820
Bedework/bw-util
bw-util-struts/src/main/java/org/bedework/util/struts/UtilActionForm.java
UtilActionForm.setException
public void setException(Throwable t) { if (err == null) { t.printStackTrace(); } else { err.emit(t); } }
java
public void setException(Throwable t) { if (err == null) { t.printStackTrace(); } else { err.emit(t); } }
[ "public", "void", "setException", "(", "Throwable", "t", ")", "{", "if", "(", "err", "==", "null", ")", "{", "t", ".", "printStackTrace", "(", ")", ";", "}", "else", "{", "err", ".", "emit", "(", "t", ")", ";", "}", "}" ]
Can be called by a page to signal an exceptiuon @param t
[ "Can", "be", "called", "by", "a", "page", "to", "signal", "an", "exceptiuon" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-struts/src/main/java/org/bedework/util/struts/UtilActionForm.java#L323-L329
143,821
Bedework/bw-util
bw-util-struts/src/main/java/org/bedework/util/struts/UtilActionForm.java
UtilActionForm.processErrors
public boolean processErrors(MessageEmit err) { if (valErrors.size() == 0) { return false; } for (ValError ve: valErrors) { processError(err, ve); } valErrors.clear(); return true; }
java
public boolean processErrors(MessageEmit err) { if (valErrors.size() == 0) { return false; } for (ValError ve: valErrors) { processError(err, ve); } valErrors.clear(); return true; }
[ "public", "boolean", "processErrors", "(", "MessageEmit", "err", ")", "{", "if", "(", "valErrors", ".", "size", "(", ")", "==", "0", ")", "{", "return", "false", ";", "}", "for", "(", "ValError", "ve", ":", "valErrors", ")", "{", "processError", "(", "err", ",", "ve", ")", ";", "}", "valErrors", ".", "clear", "(", ")", ";", "return", "true", ";", "}" ]
processErrors is called to determine if there were any errors. If so processError is called for each error adn the errors vector is cleared. Override the processError method to emit custom messages. @param err MessageEmit object @return boolean True if there were errors
[ "processErrors", "is", "called", "to", "determine", "if", "there", "were", "any", "errors", ".", "If", "so", "processError", "is", "called", "for", "each", "error", "adn", "the", "errors", "vector", "is", "cleared", ".", "Override", "the", "processError", "method", "to", "emit", "custom", "messages", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-struts/src/main/java/org/bedework/util/struts/UtilActionForm.java#L616-L627
143,822
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java
StorageManager.createResource
public static boolean createResource(String name, AbstractModule module) throws StorageAlreadyExistsException, TTException { File file = new File(ROOT_PATH); File storageFile = new File(STORAGE_PATH); if (!file.exists() || !storageFile.exists()) { file.mkdirs(); StorageConfiguration configuration = new StorageConfiguration(storageFile); // Creating and opening the storage. // Making it ready for usage. Storage.truncateStorage(configuration); Storage.createStorage(configuration); } IStorage storage = Storage.openStorage(storageFile); Injector injector = Guice.createInjector(module); IBackendFactory backend = injector.getInstance(IBackendFactory.class); IRevisioning revision = injector.getInstance(IRevisioning.class); Properties props = StandardSettings.getProps(storageFile.getAbsolutePath(), name); ResourceConfiguration mResourceConfig = new ResourceConfiguration(props, backend, revision, new FileDataFactory(), new FilelistenerMetaDataFactory()); storage.createResource(mResourceConfig); return true; }
java
public static boolean createResource(String name, AbstractModule module) throws StorageAlreadyExistsException, TTException { File file = new File(ROOT_PATH); File storageFile = new File(STORAGE_PATH); if (!file.exists() || !storageFile.exists()) { file.mkdirs(); StorageConfiguration configuration = new StorageConfiguration(storageFile); // Creating and opening the storage. // Making it ready for usage. Storage.truncateStorage(configuration); Storage.createStorage(configuration); } IStorage storage = Storage.openStorage(storageFile); Injector injector = Guice.createInjector(module); IBackendFactory backend = injector.getInstance(IBackendFactory.class); IRevisioning revision = injector.getInstance(IRevisioning.class); Properties props = StandardSettings.getProps(storageFile.getAbsolutePath(), name); ResourceConfiguration mResourceConfig = new ResourceConfiguration(props, backend, revision, new FileDataFactory(), new FilelistenerMetaDataFactory()); storage.createResource(mResourceConfig); return true; }
[ "public", "static", "boolean", "createResource", "(", "String", "name", ",", "AbstractModule", "module", ")", "throws", "StorageAlreadyExistsException", ",", "TTException", "{", "File", "file", "=", "new", "File", "(", "ROOT_PATH", ")", ";", "File", "storageFile", "=", "new", "File", "(", "STORAGE_PATH", ")", ";", "if", "(", "!", "file", ".", "exists", "(", ")", "||", "!", "storageFile", ".", "exists", "(", ")", ")", "{", "file", ".", "mkdirs", "(", ")", ";", "StorageConfiguration", "configuration", "=", "new", "StorageConfiguration", "(", "storageFile", ")", ";", "// Creating and opening the storage.", "// Making it ready for usage.", "Storage", ".", "truncateStorage", "(", "configuration", ")", ";", "Storage", ".", "createStorage", "(", "configuration", ")", ";", "}", "IStorage", "storage", "=", "Storage", ".", "openStorage", "(", "storageFile", ")", ";", "Injector", "injector", "=", "Guice", ".", "createInjector", "(", "module", ")", ";", "IBackendFactory", "backend", "=", "injector", ".", "getInstance", "(", "IBackendFactory", ".", "class", ")", ";", "IRevisioning", "revision", "=", "injector", ".", "getInstance", "(", "IRevisioning", ".", "class", ")", ";", "Properties", "props", "=", "StandardSettings", ".", "getProps", "(", "storageFile", ".", "getAbsolutePath", "(", ")", ",", "name", ")", ";", "ResourceConfiguration", "mResourceConfig", "=", "new", "ResourceConfiguration", "(", "props", ",", "backend", ",", "revision", ",", "new", "FileDataFactory", "(", ")", ",", "new", "FilelistenerMetaDataFactory", "(", ")", ")", ";", "storage", ".", "createResource", "(", "mResourceConfig", ")", ";", "return", "true", ";", "}" ]
Create a new storage with the given name and backend. @param name @param module @return true if successful @throws StorageAlreadyExistsException @throws TTException
[ "Create", "a", "new", "storage", "with", "the", "given", "name", "and", "backend", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java#L60-L91
143,823
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java
StorageManager.getResources
public static List<String> getResources() { File resources = new File(STORAGE_PATH + File.separator + "/resources"); File[] children = resources.listFiles(); if (children == null) { return new ArrayList<String>(); } List<String> storages = new ArrayList<String>(); for (int i = 0; i < children.length; i++) { if (children[i].isDirectory()) storages.add(children[i].getName()); } return storages; }
java
public static List<String> getResources() { File resources = new File(STORAGE_PATH + File.separator + "/resources"); File[] children = resources.listFiles(); if (children == null) { return new ArrayList<String>(); } List<String> storages = new ArrayList<String>(); for (int i = 0; i < children.length; i++) { if (children[i].isDirectory()) storages.add(children[i].getName()); } return storages; }
[ "public", "static", "List", "<", "String", ">", "getResources", "(", ")", "{", "File", "resources", "=", "new", "File", "(", "STORAGE_PATH", "+", "File", ".", "separator", "+", "\"/resources\"", ")", ";", "File", "[", "]", "children", "=", "resources", ".", "listFiles", "(", ")", ";", "if", "(", "children", "==", "null", ")", "{", "return", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "}", "List", "<", "String", ">", "storages", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "children", ".", "length", ";", "i", "++", ")", "{", "if", "(", "children", "[", "i", "]", ".", "isDirectory", "(", ")", ")", "storages", ".", "add", "(", "children", "[", "i", "]", ".", "getName", "(", ")", ")", ";", "}", "return", "storages", ";", "}" ]
Retrieve a list of all storages. @return a list of all storage names
[ "Retrieve", "a", "list", "of", "all", "storages", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java#L98-L114
143,824
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java
StorageManager.getSession
public static ISession getSession(String resourceName) throws ResourceNotExistingException, TTException { File storageFile = new File(STORAGE_PATH); ISession session = null; if (!storageFile.exists()) { throw new ResourceNotExistingException(); } else { new StorageConfiguration(storageFile); IStorage storage = Storage.openStorage(storageFile); session = storage.getSession(new SessionConfiguration(resourceName, null)); } return session; }
java
public static ISession getSession(String resourceName) throws ResourceNotExistingException, TTException { File storageFile = new File(STORAGE_PATH); ISession session = null; if (!storageFile.exists()) { throw new ResourceNotExistingException(); } else { new StorageConfiguration(storageFile); IStorage storage = Storage.openStorage(storageFile); session = storage.getSession(new SessionConfiguration(resourceName, null)); } return session; }
[ "public", "static", "ISession", "getSession", "(", "String", "resourceName", ")", "throws", "ResourceNotExistingException", ",", "TTException", "{", "File", "storageFile", "=", "new", "File", "(", "STORAGE_PATH", ")", ";", "ISession", "session", "=", "null", ";", "if", "(", "!", "storageFile", ".", "exists", "(", ")", ")", "{", "throw", "new", "ResourceNotExistingException", "(", ")", ";", "}", "else", "{", "new", "StorageConfiguration", "(", "storageFile", ")", ";", "IStorage", "storage", "=", "Storage", ".", "openStorage", "(", "storageFile", ")", ";", "session", "=", "storage", ".", "getSession", "(", "new", "SessionConfiguration", "(", "resourceName", ",", "null", ")", ")", ";", "}", "return", "session", ";", "}" ]
Retrieve a session from the system for the given Storagename @param resourceName @return a new {@link ISession} for the resource @throws ResourceNotExistingException @throws TTException
[ "Retrieve", "a", "session", "from", "the", "system", "for", "the", "given", "Storagename" ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java#L124-L141
143,825
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java
StorageManager.removeResource
public static void removeResource(String pResourceName) throws TTException, ResourceNotExistingException { ISession session = getSession(pResourceName); session.truncate(); }
java
public static void removeResource(String pResourceName) throws TTException, ResourceNotExistingException { ISession session = getSession(pResourceName); session.truncate(); }
[ "public", "static", "void", "removeResource", "(", "String", "pResourceName", ")", "throws", "TTException", ",", "ResourceNotExistingException", "{", "ISession", "session", "=", "getSession", "(", "pResourceName", ")", ";", "session", ".", "truncate", "(", ")", ";", "}" ]
Via this method you can remove a storage from the system. It will delete the whole folder of the configuration. @param pResourceName @throws TTException @throws ResourceNotExistingException
[ "Via", "this", "method", "you", "can", "remove", "a", "storage", "from", "the", "system", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/StorageManager.java#L153-L156
143,826
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/serialize/SAXSerializer.java
SAXSerializer.generateElement
private void generateElement(final INodeReadTrx paramRtx) throws TTIOException { final AttributesImpl atts = new AttributesImpl(); final long key = paramRtx.getNode().getDataKey(); try { // Process namespace nodes. for (int i = 0, namesCount = ((ElementNode)paramRtx.getNode()).getNamespaceCount(); i < namesCount; i++) { paramRtx.moveToNamespace(i); final QName qName = paramRtx.getQNameOfCurrentNode(); mContHandler.startPrefixMapping(qName.getPrefix(), qName.getNamespaceURI()); final String mURI = qName.getNamespaceURI(); if (qName.getLocalPart().length() == 0) { atts.addAttribute(mURI, "xmlns", "xmlns", "CDATA", mURI); } else { atts.addAttribute(mURI, "xmlns", "xmlns:" + paramRtx.getQNameOfCurrentNode().getLocalPart(), "CDATA", mURI); } paramRtx.moveTo(key); } // Process attributes. for (int i = 0, attCount = ((ElementNode)paramRtx.getNode()).getAttributeCount(); i < attCount; i++) { paramRtx.moveToAttribute(i); final QName qName = paramRtx.getQNameOfCurrentNode(); final String mURI = qName.getNamespaceURI(); atts.addAttribute(mURI, qName.getLocalPart(), NodeWriteTrx.buildName(qName), paramRtx .getTypeOfCurrentNode(), paramRtx.getValueOfCurrentNode()); paramRtx.moveTo(key); } // Create SAX events. final QName qName = paramRtx.getQNameOfCurrentNode(); mContHandler.startElement(qName.getNamespaceURI(), qName.getLocalPart(), NodeWriteTrx .buildName(qName), atts); // Empty elements. if (!((ElementNode)paramRtx.getNode()).hasFirstChild()) { mContHandler.endElement(qName.getNamespaceURI(), qName.getLocalPart(), NodeWriteTrx .buildName(qName)); } } catch (final SAXException exc) { exc.printStackTrace(); } }
java
private void generateElement(final INodeReadTrx paramRtx) throws TTIOException { final AttributesImpl atts = new AttributesImpl(); final long key = paramRtx.getNode().getDataKey(); try { // Process namespace nodes. for (int i = 0, namesCount = ((ElementNode)paramRtx.getNode()).getNamespaceCount(); i < namesCount; i++) { paramRtx.moveToNamespace(i); final QName qName = paramRtx.getQNameOfCurrentNode(); mContHandler.startPrefixMapping(qName.getPrefix(), qName.getNamespaceURI()); final String mURI = qName.getNamespaceURI(); if (qName.getLocalPart().length() == 0) { atts.addAttribute(mURI, "xmlns", "xmlns", "CDATA", mURI); } else { atts.addAttribute(mURI, "xmlns", "xmlns:" + paramRtx.getQNameOfCurrentNode().getLocalPart(), "CDATA", mURI); } paramRtx.moveTo(key); } // Process attributes. for (int i = 0, attCount = ((ElementNode)paramRtx.getNode()).getAttributeCount(); i < attCount; i++) { paramRtx.moveToAttribute(i); final QName qName = paramRtx.getQNameOfCurrentNode(); final String mURI = qName.getNamespaceURI(); atts.addAttribute(mURI, qName.getLocalPart(), NodeWriteTrx.buildName(qName), paramRtx .getTypeOfCurrentNode(), paramRtx.getValueOfCurrentNode()); paramRtx.moveTo(key); } // Create SAX events. final QName qName = paramRtx.getQNameOfCurrentNode(); mContHandler.startElement(qName.getNamespaceURI(), qName.getLocalPart(), NodeWriteTrx .buildName(qName), atts); // Empty elements. if (!((ElementNode)paramRtx.getNode()).hasFirstChild()) { mContHandler.endElement(qName.getNamespaceURI(), qName.getLocalPart(), NodeWriteTrx .buildName(qName)); } } catch (final SAXException exc) { exc.printStackTrace(); } }
[ "private", "void", "generateElement", "(", "final", "INodeReadTrx", "paramRtx", ")", "throws", "TTIOException", "{", "final", "AttributesImpl", "atts", "=", "new", "AttributesImpl", "(", ")", ";", "final", "long", "key", "=", "paramRtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ";", "try", "{", "// Process namespace nodes.", "for", "(", "int", "i", "=", "0", ",", "namesCount", "=", "(", "(", "ElementNode", ")", "paramRtx", ".", "getNode", "(", ")", ")", ".", "getNamespaceCount", "(", ")", ";", "i", "<", "namesCount", ";", "i", "++", ")", "{", "paramRtx", ".", "moveToNamespace", "(", "i", ")", ";", "final", "QName", "qName", "=", "paramRtx", ".", "getQNameOfCurrentNode", "(", ")", ";", "mContHandler", ".", "startPrefixMapping", "(", "qName", ".", "getPrefix", "(", ")", ",", "qName", ".", "getNamespaceURI", "(", ")", ")", ";", "final", "String", "mURI", "=", "qName", ".", "getNamespaceURI", "(", ")", ";", "if", "(", "qName", ".", "getLocalPart", "(", ")", ".", "length", "(", ")", "==", "0", ")", "{", "atts", ".", "addAttribute", "(", "mURI", ",", "\"xmlns\"", ",", "\"xmlns\"", ",", "\"CDATA\"", ",", "mURI", ")", ";", "}", "else", "{", "atts", ".", "addAttribute", "(", "mURI", ",", "\"xmlns\"", ",", "\"xmlns:\"", "+", "paramRtx", ".", "getQNameOfCurrentNode", "(", ")", ".", "getLocalPart", "(", ")", ",", "\"CDATA\"", ",", "mURI", ")", ";", "}", "paramRtx", ".", "moveTo", "(", "key", ")", ";", "}", "// Process attributes.", "for", "(", "int", "i", "=", "0", ",", "attCount", "=", "(", "(", "ElementNode", ")", "paramRtx", ".", "getNode", "(", ")", ")", ".", "getAttributeCount", "(", ")", ";", "i", "<", "attCount", ";", "i", "++", ")", "{", "paramRtx", ".", "moveToAttribute", "(", "i", ")", ";", "final", "QName", "qName", "=", "paramRtx", ".", "getQNameOfCurrentNode", "(", ")", ";", "final", "String", "mURI", "=", "qName", ".", "getNamespaceURI", "(", ")", ";", "atts", ".", "addAttribute", "(", "mURI", ",", "qName", ".", "getLocalPart", "(", ")", ",", "NodeWriteTrx", ".", "buildName", "(", "qName", ")", ",", "paramRtx", ".", "getTypeOfCurrentNode", "(", ")", ",", "paramRtx", ".", "getValueOfCurrentNode", "(", ")", ")", ";", "paramRtx", ".", "moveTo", "(", "key", ")", ";", "}", "// Create SAX events.", "final", "QName", "qName", "=", "paramRtx", ".", "getQNameOfCurrentNode", "(", ")", ";", "mContHandler", ".", "startElement", "(", "qName", ".", "getNamespaceURI", "(", ")", ",", "qName", ".", "getLocalPart", "(", ")", ",", "NodeWriteTrx", ".", "buildName", "(", "qName", ")", ",", "atts", ")", ";", "// Empty elements.", "if", "(", "!", "(", "(", "ElementNode", ")", "paramRtx", ".", "getNode", "(", ")", ")", ".", "hasFirstChild", "(", ")", ")", "{", "mContHandler", ".", "endElement", "(", "qName", ".", "getNamespaceURI", "(", ")", ",", "qName", ".", "getLocalPart", "(", ")", ",", "NodeWriteTrx", ".", "buildName", "(", "qName", ")", ")", ";", "}", "}", "catch", "(", "final", "SAXException", "exc", ")", "{", "exc", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Generate a start element event. @param paramRtx Read Transaction @throws TTIOException
[ "Generate", "a", "start", "element", "event", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/serialize/SAXSerializer.java#L166-L209
143,827
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/serialize/SAXSerializer.java
SAXSerializer.generateText
private void generateText(final INodeReadTrx paramRtx) { try { mContHandler.characters(paramRtx.getValueOfCurrentNode().toCharArray(), 0, paramRtx .getValueOfCurrentNode().length()); } catch (final SAXException exc) { exc.printStackTrace(); } }
java
private void generateText(final INodeReadTrx paramRtx) { try { mContHandler.characters(paramRtx.getValueOfCurrentNode().toCharArray(), 0, paramRtx .getValueOfCurrentNode().length()); } catch (final SAXException exc) { exc.printStackTrace(); } }
[ "private", "void", "generateText", "(", "final", "INodeReadTrx", "paramRtx", ")", "{", "try", "{", "mContHandler", ".", "characters", "(", "paramRtx", ".", "getValueOfCurrentNode", "(", ")", ".", "toCharArray", "(", ")", ",", "0", ",", "paramRtx", ".", "getValueOfCurrentNode", "(", ")", ".", "length", "(", ")", ")", ";", "}", "catch", "(", "final", "SAXException", "exc", ")", "{", "exc", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Generate a text event. @param mRtx Read Transaction.
[ "Generate", "a", "text", "event", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/serialize/SAXSerializer.java#L217-L224
143,828
Bedework/bw-util
bw-util-jmx/src/main/java/org/bedework/util/jmx/MBeanUtil.java
MBeanUtil.getMBean
@SuppressWarnings("unchecked") public static Object getMBean(final Class c, final String name) throws Throwable { final MBeanServer server = getMbeanServer(); // return MBeanProxyExt.create(c, name, server); return JMX.newMBeanProxy(server, new ObjectName(name), c); }
java
@SuppressWarnings("unchecked") public static Object getMBean(final Class c, final String name) throws Throwable { final MBeanServer server = getMbeanServer(); // return MBeanProxyExt.create(c, name, server); return JMX.newMBeanProxy(server, new ObjectName(name), c); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "Object", "getMBean", "(", "final", "Class", "c", ",", "final", "String", "name", ")", "throws", "Throwable", "{", "final", "MBeanServer", "server", "=", "getMbeanServer", "(", ")", ";", "// return MBeanProxyExt.create(c, name, server);", "return", "JMX", ".", "newMBeanProxy", "(", "server", ",", "new", "ObjectName", "(", "name", ")", ",", "c", ")", ";", "}" ]
Create a proxy to the given mbean @param c @param name @return proxy to the mbean @throws Throwable
[ "Create", "a", "proxy", "to", "the", "given", "mbean" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-jmx/src/main/java/org/bedework/util/jmx/MBeanUtil.java#L44-L51
143,829
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/JettyServer.java
JettyServer.register
public static void register(final Server s) { final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", "org.jaxrx.resource"); new Context(s, "/", Context.SESSIONS).addServlet(sh, "/"); }
java
public static void register(final Server s) { final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", "org.jaxrx.resource"); new Context(s, "/", Context.SESSIONS).addServlet(sh, "/"); }
[ "public", "static", "void", "register", "(", "final", "Server", "s", ")", "{", "final", "ServletHolder", "sh", "=", "new", "ServletHolder", "(", "ServletContainer", ".", "class", ")", ";", "sh", ".", "setInitParameter", "(", "\"com.sun.jersey.config.property.resourceConfigClass\"", ",", "\"com.sun.jersey.api.core.PackagesResourceConfig\"", ")", ";", "sh", ".", "setInitParameter", "(", "\"com.sun.jersey.config.property.packages\"", ",", "\"org.jaxrx.resource\"", ")", ";", "new", "Context", "(", "s", ",", "\"/\"", ",", "Context", ".", "SESSIONS", ")", ".", "addServlet", "(", "sh", ",", "\"/\"", ")", ";", "}" ]
Constructor, attaching JAX-RX to the specified server. @param s server instance
[ "Constructor", "attaching", "JAX", "-", "RX", "to", "the", "specified", "server", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/JettyServer.java#L70-L77
143,830
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java
BucketReadTrx.getData
public IData getData(final long pDataKey) throws TTIOException { checkArgument(pDataKey >= 0); checkState(!mClose, "Transaction already closed"); // Calculate bucket and data part for given datakey. final long seqBucketKey = pDataKey >> IConstants.INDIRECT_BUCKET_COUNT[3]; final int dataBucketOffset = dataBucketOffset(pDataKey); DataBucket bucket = mCache.getIfPresent(seqBucketKey); if (bucket == null) { final List<DataBucket> listRevs = getSnapshotBuckets(seqBucketKey); final DataBucket[] revs = listRevs.toArray(new DataBucket[listRevs.size()]); checkState(revs.length > 0, "Number of Buckets to reconstruct must be larger than 0"); // Build up the complete bucket. final IRevisioning revision = mSession.getConfig().mRevision; bucket = revision.combineBuckets(revs); mCache.put(seqBucketKey, bucket); } final IData returnVal = bucket.getData(dataBucketOffset); // root-fsys is excluded from the checkagainst deletion based on the necesssity of the data-layer to // reference against this data while creation of the transaction if (pDataKey == 0) { return returnVal; } else { return checkItemIfDeleted(returnVal); } }
java
public IData getData(final long pDataKey) throws TTIOException { checkArgument(pDataKey >= 0); checkState(!mClose, "Transaction already closed"); // Calculate bucket and data part for given datakey. final long seqBucketKey = pDataKey >> IConstants.INDIRECT_BUCKET_COUNT[3]; final int dataBucketOffset = dataBucketOffset(pDataKey); DataBucket bucket = mCache.getIfPresent(seqBucketKey); if (bucket == null) { final List<DataBucket> listRevs = getSnapshotBuckets(seqBucketKey); final DataBucket[] revs = listRevs.toArray(new DataBucket[listRevs.size()]); checkState(revs.length > 0, "Number of Buckets to reconstruct must be larger than 0"); // Build up the complete bucket. final IRevisioning revision = mSession.getConfig().mRevision; bucket = revision.combineBuckets(revs); mCache.put(seqBucketKey, bucket); } final IData returnVal = bucket.getData(dataBucketOffset); // root-fsys is excluded from the checkagainst deletion based on the necesssity of the data-layer to // reference against this data while creation of the transaction if (pDataKey == 0) { return returnVal; } else { return checkItemIfDeleted(returnVal); } }
[ "public", "IData", "getData", "(", "final", "long", "pDataKey", ")", "throws", "TTIOException", "{", "checkArgument", "(", "pDataKey", ">=", "0", ")", ";", "checkState", "(", "!", "mClose", ",", "\"Transaction already closed\"", ")", ";", "// Calculate bucket and data part for given datakey.", "final", "long", "seqBucketKey", "=", "pDataKey", ">>", "IConstants", ".", "INDIRECT_BUCKET_COUNT", "[", "3", "]", ";", "final", "int", "dataBucketOffset", "=", "dataBucketOffset", "(", "pDataKey", ")", ";", "DataBucket", "bucket", "=", "mCache", ".", "getIfPresent", "(", "seqBucketKey", ")", ";", "if", "(", "bucket", "==", "null", ")", "{", "final", "List", "<", "DataBucket", ">", "listRevs", "=", "getSnapshotBuckets", "(", "seqBucketKey", ")", ";", "final", "DataBucket", "[", "]", "revs", "=", "listRevs", ".", "toArray", "(", "new", "DataBucket", "[", "listRevs", ".", "size", "(", ")", "]", ")", ";", "checkState", "(", "revs", ".", "length", ">", "0", ",", "\"Number of Buckets to reconstruct must be larger than 0\"", ")", ";", "// Build up the complete bucket.", "final", "IRevisioning", "revision", "=", "mSession", ".", "getConfig", "(", ")", ".", "mRevision", ";", "bucket", "=", "revision", ".", "combineBuckets", "(", "revs", ")", ";", "mCache", ".", "put", "(", "seqBucketKey", ",", "bucket", ")", ";", "}", "final", "IData", "returnVal", "=", "bucket", ".", "getData", "(", "dataBucketOffset", ")", ";", "// root-fsys is excluded from the checkagainst deletion based on the necesssity of the data-layer to", "// reference against this data while creation of the transaction", "if", "(", "pDataKey", "==", "0", ")", "{", "return", "returnVal", ";", "}", "else", "{", "return", "checkItemIfDeleted", "(", "returnVal", ")", ";", "}", "}" ]
Getting the data related to the given data key. @param pDataKey searched for @return the related data @throws TTIOException if the read to the persistent storage fails
[ "Getting", "the", "data", "related", "to", "the", "given", "data", "key", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java#L132-L157
143,831
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java
BucketReadTrx.close
public boolean close() throws TTIOException { if (!mClose) { mSession.deregisterBucketTrx(this); mBucketReader.close(); mClose = true; return true; } else { return false; } }
java
public boolean close() throws TTIOException { if (!mClose) { mSession.deregisterBucketTrx(this); mBucketReader.close(); mClose = true; return true; } else { return false; } }
[ "public", "boolean", "close", "(", ")", "throws", "TTIOException", "{", "if", "(", "!", "mClose", ")", "{", "mSession", ".", "deregisterBucketTrx", "(", "this", ")", ";", "mBucketReader", ".", "close", "(", ")", ";", "mClose", "=", "true", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Closing this Readtransaction. @throws TTIOException if the closing to the persistent storage fails.
[ "Closing", "this", "Readtransaction", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java#L165-L175
143,832
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java
BucketReadTrx.getSnapshotBuckets
protected final List<DataBucket> getSnapshotBuckets(final long pSeqDataBucketKey) throws TTIOException { // Return Value, since the revision iterates a flexible number of version, this has to be a list // first. final List<DataBucket> dataBuckets = new ArrayList<DataBucket>(); // Getting the keys for the revRoots final long[] pathToRoot = BucketReadTrx.dereferenceLeafOfTree(mBucketReader, mUberBucket.getReferenceKeys()[IReferenceBucket.GUARANTEED_INDIRECT_OFFSET], mRootBucket .getRevision()); final RevisionRootBucket rootBucket = (RevisionRootBucket)mBucketReader.read(pathToRoot[IConstants.INDIRECT_BUCKET_COUNT.length]); final int numbersToRestore = Integer.parseInt(mSession.getConfig().mProperties.getProperty(ConstructorProps.NUMBERTORESTORE)); // starting from the current databucket final long[] pathToRecentBucket = dereferenceLeafOfTree(mBucketReader, rootBucket.getReferenceKeys()[IReferenceBucket.GUARANTEED_INDIRECT_OFFSET], pSeqDataBucketKey); DataBucket bucket; long bucketKey = pathToRecentBucket[IConstants.INDIRECT_BUCKET_COUNT.length]; // jumping through the databuckets based on the pointers while (dataBuckets.size() < numbersToRestore && bucketKey > -1) { bucket = (DataBucket)mBucketReader.read(bucketKey); dataBuckets.add(bucket); bucketKey = bucket.getLastBucketPointer(); } // check if bucket was ever written before to perform check if (bucketKey > -1) { checkStructure(mBucketReader, pathToRecentBucket, rootBucket, pSeqDataBucketKey); checkStructure(mBucketReader, pathToRoot, mUberBucket, mRootBucket.getRevision()); } return dataBuckets; }
java
protected final List<DataBucket> getSnapshotBuckets(final long pSeqDataBucketKey) throws TTIOException { // Return Value, since the revision iterates a flexible number of version, this has to be a list // first. final List<DataBucket> dataBuckets = new ArrayList<DataBucket>(); // Getting the keys for the revRoots final long[] pathToRoot = BucketReadTrx.dereferenceLeafOfTree(mBucketReader, mUberBucket.getReferenceKeys()[IReferenceBucket.GUARANTEED_INDIRECT_OFFSET], mRootBucket .getRevision()); final RevisionRootBucket rootBucket = (RevisionRootBucket)mBucketReader.read(pathToRoot[IConstants.INDIRECT_BUCKET_COUNT.length]); final int numbersToRestore = Integer.parseInt(mSession.getConfig().mProperties.getProperty(ConstructorProps.NUMBERTORESTORE)); // starting from the current databucket final long[] pathToRecentBucket = dereferenceLeafOfTree(mBucketReader, rootBucket.getReferenceKeys()[IReferenceBucket.GUARANTEED_INDIRECT_OFFSET], pSeqDataBucketKey); DataBucket bucket; long bucketKey = pathToRecentBucket[IConstants.INDIRECT_BUCKET_COUNT.length]; // jumping through the databuckets based on the pointers while (dataBuckets.size() < numbersToRestore && bucketKey > -1) { bucket = (DataBucket)mBucketReader.read(bucketKey); dataBuckets.add(bucket); bucketKey = bucket.getLastBucketPointer(); } // check if bucket was ever written before to perform check if (bucketKey > -1) { checkStructure(mBucketReader, pathToRecentBucket, rootBucket, pSeqDataBucketKey); checkStructure(mBucketReader, pathToRoot, mUberBucket, mRootBucket.getRevision()); } return dataBuckets; }
[ "protected", "final", "List", "<", "DataBucket", ">", "getSnapshotBuckets", "(", "final", "long", "pSeqDataBucketKey", ")", "throws", "TTIOException", "{", "// Return Value, since the revision iterates a flexible number of version, this has to be a list", "// first.", "final", "List", "<", "DataBucket", ">", "dataBuckets", "=", "new", "ArrayList", "<", "DataBucket", ">", "(", ")", ";", "// Getting the keys for the revRoots", "final", "long", "[", "]", "pathToRoot", "=", "BucketReadTrx", ".", "dereferenceLeafOfTree", "(", "mBucketReader", ",", "mUberBucket", ".", "getReferenceKeys", "(", ")", "[", "IReferenceBucket", ".", "GUARANTEED_INDIRECT_OFFSET", "]", ",", "mRootBucket", ".", "getRevision", "(", ")", ")", ";", "final", "RevisionRootBucket", "rootBucket", "=", "(", "RevisionRootBucket", ")", "mBucketReader", ".", "read", "(", "pathToRoot", "[", "IConstants", ".", "INDIRECT_BUCKET_COUNT", ".", "length", "]", ")", ";", "final", "int", "numbersToRestore", "=", "Integer", ".", "parseInt", "(", "mSession", ".", "getConfig", "(", ")", ".", "mProperties", ".", "getProperty", "(", "ConstructorProps", ".", "NUMBERTORESTORE", ")", ")", ";", "// starting from the current databucket", "final", "long", "[", "]", "pathToRecentBucket", "=", "dereferenceLeafOfTree", "(", "mBucketReader", ",", "rootBucket", ".", "getReferenceKeys", "(", ")", "[", "IReferenceBucket", ".", "GUARANTEED_INDIRECT_OFFSET", "]", ",", "pSeqDataBucketKey", ")", ";", "DataBucket", "bucket", ";", "long", "bucketKey", "=", "pathToRecentBucket", "[", "IConstants", ".", "INDIRECT_BUCKET_COUNT", ".", "length", "]", ";", "// jumping through the databuckets based on the pointers", "while", "(", "dataBuckets", ".", "size", "(", ")", "<", "numbersToRestore", "&&", "bucketKey", ">", "-", "1", ")", "{", "bucket", "=", "(", "DataBucket", ")", "mBucketReader", ".", "read", "(", "bucketKey", ")", ";", "dataBuckets", ".", "add", "(", "bucket", ")", ";", "bucketKey", "=", "bucket", ".", "getLastBucketPointer", "(", ")", ";", "}", "// check if bucket was ever written before to perform check", "if", "(", "bucketKey", ">", "-", "1", ")", "{", "checkStructure", "(", "mBucketReader", ",", "pathToRecentBucket", ",", "rootBucket", ",", "pSeqDataBucketKey", ")", ";", "checkStructure", "(", "mBucketReader", ",", "pathToRoot", ",", "mUberBucket", ",", "mRootBucket", ".", "getRevision", "(", ")", ")", ";", "}", "return", "dataBuckets", ";", "}" ]
Dereference data bucket reference. @param pSeqDataBucketKey Key of data bucket. @return Dereferenced bucket. @throws TTIOException if something odd happens within the creation process.
[ "Dereference", "data", "bucket", "reference", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java#L229-L267
143,833
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java
BucketReadTrx.dataBucketOffset
protected static final int dataBucketOffset(final long pDataKey) { // INDIRECT_BUCKET_COUNT[3] is only taken to get the difference between 2^7 and the actual // datakey as offset. It has nothing to do with the levels. final long dataBucketOffset = (pDataKey - ((pDataKey >> IConstants.INDIRECT_BUCKET_COUNT[3]) << IConstants.INDIRECT_BUCKET_COUNT[3])); return (int)dataBucketOffset; }
java
protected static final int dataBucketOffset(final long pDataKey) { // INDIRECT_BUCKET_COUNT[3] is only taken to get the difference between 2^7 and the actual // datakey as offset. It has nothing to do with the levels. final long dataBucketOffset = (pDataKey - ((pDataKey >> IConstants.INDIRECT_BUCKET_COUNT[3]) << IConstants.INDIRECT_BUCKET_COUNT[3])); return (int)dataBucketOffset; }
[ "protected", "static", "final", "int", "dataBucketOffset", "(", "final", "long", "pDataKey", ")", "{", "// INDIRECT_BUCKET_COUNT[3] is only taken to get the difference between 2^7 and the actual", "// datakey as offset. It has nothing to do with the levels.", "final", "long", "dataBucketOffset", "=", "(", "pDataKey", "-", "(", "(", "pDataKey", ">>", "IConstants", ".", "INDIRECT_BUCKET_COUNT", "[", "3", "]", ")", "<<", "IConstants", ".", "INDIRECT_BUCKET_COUNT", "[", "3", "]", ")", ")", ";", "return", "(", "int", ")", "dataBucketOffset", ";", "}" ]
Calculate data bucket offset for a given data key. @param pDataKey data key to find offset for. @return Offset into data bucket.
[ "Calculate", "data", "bucket", "offset", "for", "a", "given", "data", "key", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java#L276-L282
143,834
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java
BucketReadTrx.dereferenceLeafOfTree
protected static final long[] dereferenceLeafOfTree(final IBackendReader pReader, final long pStartKey, final long pSeqBucketKey) throws TTIOException { final long[] orderNumber = getOrderNumbers(pSeqBucketKey); // Initial state pointing to the indirect bucket of level 0. final long[] keys = new long[IConstants.INDIRECT_BUCKET_COUNT.length + 1]; IndirectBucket bucket = null; keys[0] = pStartKey; // Iterate through all levels... for (int level = 0; level < orderNumber.length; level++) { // ..read the buckets and.. bucket = (IndirectBucket)pReader.read(keys[level]); // ..compute the offsets out of the order-numbers pre-computed before and store it in the // key-array. keys[level + 1] = bucket.getReferenceKeys()[dataBucketOffset(orderNumber[level])]; // if the bucketKey is 0, return -1 to distinguish mark non-written buckets explicitly. if (keys[level + 1] == 0) { Arrays.fill(keys, -1); return keys; } } // Return reference to leaf of indirect tree. return keys; }
java
protected static final long[] dereferenceLeafOfTree(final IBackendReader pReader, final long pStartKey, final long pSeqBucketKey) throws TTIOException { final long[] orderNumber = getOrderNumbers(pSeqBucketKey); // Initial state pointing to the indirect bucket of level 0. final long[] keys = new long[IConstants.INDIRECT_BUCKET_COUNT.length + 1]; IndirectBucket bucket = null; keys[0] = pStartKey; // Iterate through all levels... for (int level = 0; level < orderNumber.length; level++) { // ..read the buckets and.. bucket = (IndirectBucket)pReader.read(keys[level]); // ..compute the offsets out of the order-numbers pre-computed before and store it in the // key-array. keys[level + 1] = bucket.getReferenceKeys()[dataBucketOffset(orderNumber[level])]; // if the bucketKey is 0, return -1 to distinguish mark non-written buckets explicitly. if (keys[level + 1] == 0) { Arrays.fill(keys, -1); return keys; } } // Return reference to leaf of indirect tree. return keys; }
[ "protected", "static", "final", "long", "[", "]", "dereferenceLeafOfTree", "(", "final", "IBackendReader", "pReader", ",", "final", "long", "pStartKey", ",", "final", "long", "pSeqBucketKey", ")", "throws", "TTIOException", "{", "final", "long", "[", "]", "orderNumber", "=", "getOrderNumbers", "(", "pSeqBucketKey", ")", ";", "// Initial state pointing to the indirect bucket of level 0.", "final", "long", "[", "]", "keys", "=", "new", "long", "[", "IConstants", ".", "INDIRECT_BUCKET_COUNT", ".", "length", "+", "1", "]", ";", "IndirectBucket", "bucket", "=", "null", ";", "keys", "[", "0", "]", "=", "pStartKey", ";", "// Iterate through all levels...", "for", "(", "int", "level", "=", "0", ";", "level", "<", "orderNumber", ".", "length", ";", "level", "++", ")", "{", "// ..read the buckets and..", "bucket", "=", "(", "IndirectBucket", ")", "pReader", ".", "read", "(", "keys", "[", "level", "]", ")", ";", "// ..compute the offsets out of the order-numbers pre-computed before and store it in the", "// key-array.", "keys", "[", "level", "+", "1", "]", "=", "bucket", ".", "getReferenceKeys", "(", ")", "[", "dataBucketOffset", "(", "orderNumber", "[", "level", "]", ")", "]", ";", "// if the bucketKey is 0, return -1 to distinguish mark non-written buckets explicitly.", "if", "(", "keys", "[", "level", "+", "1", "]", "==", "0", ")", "{", "Arrays", ".", "fill", "(", "keys", ",", "-", "1", ")", ";", "return", "keys", ";", "}", "}", "// Return reference to leaf of indirect tree.", "return", "keys", ";", "}" ]
Find reference pointing to leaf bucket of an indirect tree. @param pStartKey Start reference pointing to the indirect tree. @param pSeqBucketKey Key to look up in the indirect tree. @return Reference denoted by key pointing to the leaf bucket. @throws TTIOException if something odd happens within the creation process.
[ "Find", "reference", "pointing", "to", "leaf", "bucket", "of", "an", "indirect", "tree", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/BucketReadTrx.java#L296-L321
143,835
Bedework/bw-util
bw-util-options/src/main/java/org/bedework/util/options/OptionsFactory.java
OptionsFactory.getOptions
public static OptionsI getOptions(final String globalPrefix, final String appPrefix, final String optionsFile, final String outerTagName) throws OptionsException { try { Object o = Class.forName(envclass).newInstance(); if (o == null) { throw new OptionsException("Class " + envclass + " not found"); } if (!(o instanceof OptionsI)) { throw new OptionsException("Class " + envclass + " is not a subclass of " + OptionsI.class.getName()); } OptionsI options = (OptionsI)o; options.init(globalPrefix, appPrefix, optionsFile, outerTagName); return options; } catch (OptionsException ce) { throw ce; } catch (Throwable t) { throw new OptionsException(t); } }
java
public static OptionsI getOptions(final String globalPrefix, final String appPrefix, final String optionsFile, final String outerTagName) throws OptionsException { try { Object o = Class.forName(envclass).newInstance(); if (o == null) { throw new OptionsException("Class " + envclass + " not found"); } if (!(o instanceof OptionsI)) { throw new OptionsException("Class " + envclass + " is not a subclass of " + OptionsI.class.getName()); } OptionsI options = (OptionsI)o; options.init(globalPrefix, appPrefix, optionsFile, outerTagName); return options; } catch (OptionsException ce) { throw ce; } catch (Throwable t) { throw new OptionsException(t); } }
[ "public", "static", "OptionsI", "getOptions", "(", "final", "String", "globalPrefix", ",", "final", "String", "appPrefix", ",", "final", "String", "optionsFile", ",", "final", "String", "outerTagName", ")", "throws", "OptionsException", "{", "try", "{", "Object", "o", "=", "Class", ".", "forName", "(", "envclass", ")", ".", "newInstance", "(", ")", ";", "if", "(", "o", "==", "null", ")", "{", "throw", "new", "OptionsException", "(", "\"Class \"", "+", "envclass", "+", "\" not found\"", ")", ";", "}", "if", "(", "!", "(", "o", "instanceof", "OptionsI", ")", ")", "{", "throw", "new", "OptionsException", "(", "\"Class \"", "+", "envclass", "+", "\" is not a subclass of \"", "+", "OptionsI", ".", "class", ".", "getName", "(", ")", ")", ";", "}", "OptionsI", "options", "=", "(", "OptionsI", ")", "o", ";", "options", ".", "init", "(", "globalPrefix", ",", "appPrefix", ",", "optionsFile", ",", "outerTagName", ")", ";", "return", "options", ";", "}", "catch", "(", "OptionsException", "ce", ")", "{", "throw", "ce", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "throw", "new", "OptionsException", "(", "t", ")", ";", "}", "}" ]
Obtain and initialise an options object. @param globalPrefix @param appPrefix @param optionsFile - path to file e.g. /properties/calendar/options.xml @param outerTagName - surrounding tag in options file e.g. bedework-options @return CalOptionsI @throws OptionsException
[ "Obtain", "and", "initialise", "an", "options", "object", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-options/src/main/java/org/bedework/util/options/OptionsFactory.java#L38-L65
143,836
Bedework/bw-util
bw-util-options/src/main/java/org/bedework/util/options/OptionsFactory.java
OptionsFactory.fromStream
public static Options fromStream(final String globalPrefix, final String appPrefix, final String outerTagName, final InputStream is) throws OptionsException { Options opts = new Options(); opts.init(globalPrefix, appPrefix, is, outerTagName); return opts; }
java
public static Options fromStream(final String globalPrefix, final String appPrefix, final String outerTagName, final InputStream is) throws OptionsException { Options opts = new Options(); opts.init(globalPrefix, appPrefix, is, outerTagName); return opts; }
[ "public", "static", "Options", "fromStream", "(", "final", "String", "globalPrefix", ",", "final", "String", "appPrefix", ",", "final", "String", "outerTagName", ",", "final", "InputStream", "is", ")", "throws", "OptionsException", "{", "Options", "opts", "=", "new", "Options", "(", ")", ";", "opts", ".", "init", "(", "globalPrefix", ",", "appPrefix", ",", "is", ",", "outerTagName", ")", ";", "return", "opts", ";", "}" ]
Return an object that uses a local set of options parsed from the input stream. @param globalPrefix @param appPrefix @param outerTagName @param is @return CalOptions @throws OptionsException
[ "Return", "an", "object", "that", "uses", "a", "local", "set", "of", "options", "parsed", "from", "the", "input", "stream", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-options/src/main/java/org/bedework/util/options/OptionsFactory.java#L76-L85
143,837
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/diff/algorithm/fmes/LabelFMESVisitor.java
LabelFMESVisitor.addLeafLabel
private void addLeafLabel() { final int nodeKind = mRtx.getNode().getKind(); if (!mLeafLabels.containsKey(nodeKind)) { mLeafLabels.put(nodeKind, new ArrayList<ITreeData>()); } mLeafLabels.get(nodeKind).add(mRtx.getNode()); }
java
private void addLeafLabel() { final int nodeKind = mRtx.getNode().getKind(); if (!mLeafLabels.containsKey(nodeKind)) { mLeafLabels.put(nodeKind, new ArrayList<ITreeData>()); } mLeafLabels.get(nodeKind).add(mRtx.getNode()); }
[ "private", "void", "addLeafLabel", "(", ")", "{", "final", "int", "nodeKind", "=", "mRtx", ".", "getNode", "(", ")", ".", "getKind", "(", ")", ";", "if", "(", "!", "mLeafLabels", ".", "containsKey", "(", "nodeKind", ")", ")", "{", "mLeafLabels", ".", "put", "(", "nodeKind", ",", "new", "ArrayList", "<", "ITreeData", ">", "(", ")", ")", ";", "}", "mLeafLabels", ".", "get", "(", "nodeKind", ")", ".", "add", "(", "mRtx", ".", "getNode", "(", ")", ")", ";", "}" ]
Add leaf node label.
[ "Add", "leaf", "node", "label", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/diff/algorithm/fmes/LabelFMESVisitor.java#L117-L123
143,838
Bedework/bw-util
bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/AbstractFilter.java
AbstractFilter.getGlobals
public FilterGlobals getGlobals(final HttpServletRequest req) { HttpSession sess = req.getSession(); if (sess == null) { // We're screwed return null; } Object o = sess.getAttribute(globalsName); FilterGlobals fg; if (o == null) { fg = newFilterGlobals(); sess.setAttribute(globalsName, fg); if (debug()) { debug("Created new FilterGlobals from session " + sess.getId()); } } else { fg = (FilterGlobals)o; //if (debug()) { // getLogger().debug("Obtained FilterGlobals from session with id " + // sess.getId()); //} } return fg; }
java
public FilterGlobals getGlobals(final HttpServletRequest req) { HttpSession sess = req.getSession(); if (sess == null) { // We're screwed return null; } Object o = sess.getAttribute(globalsName); FilterGlobals fg; if (o == null) { fg = newFilterGlobals(); sess.setAttribute(globalsName, fg); if (debug()) { debug("Created new FilterGlobals from session " + sess.getId()); } } else { fg = (FilterGlobals)o; //if (debug()) { // getLogger().debug("Obtained FilterGlobals from session with id " + // sess.getId()); //} } return fg; }
[ "public", "FilterGlobals", "getGlobals", "(", "final", "HttpServletRequest", "req", ")", "{", "HttpSession", "sess", "=", "req", ".", "getSession", "(", ")", ";", "if", "(", "sess", "==", "null", ")", "{", "// We're screwed", "return", "null", ";", "}", "Object", "o", "=", "sess", ".", "getAttribute", "(", "globalsName", ")", ";", "FilterGlobals", "fg", ";", "if", "(", "o", "==", "null", ")", "{", "fg", "=", "newFilterGlobals", "(", ")", ";", "sess", ".", "setAttribute", "(", "globalsName", ",", "fg", ")", ";", "if", "(", "debug", "(", ")", ")", "{", "debug", "(", "\"Created new FilterGlobals from session \"", "+", "sess", ".", "getId", "(", ")", ")", ";", "}", "}", "else", "{", "fg", "=", "(", "FilterGlobals", ")", "o", ";", "//if (debug()) {", "// getLogger().debug(\"Obtained FilterGlobals from session with id \" +", "// sess.getId());", "//}", "}", "return", "fg", ";", "}" ]
Get the globals from the session @param req @return globals object
[ "Get", "the", "globals", "from", "the", "session" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/AbstractFilter.java#L74-L101
143,839
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/resource/XMLResource.java
XMLResource.putResource
@PUT @Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML }) public Response putResource(@PathParam(JaxRxConstants.SYSTEM) final String system, @PathParam(JaxRxConstants.RESOURCE) final String resource, @Context final HttpHeaders headers, final InputStream xml) { final JaxRx impl = Systems.getInstance(system); final String info = impl.update(xml, new ResourcePath(resource, headers)); return Response.created(null).entity(info).build(); }
java
@PUT @Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML }) public Response putResource(@PathParam(JaxRxConstants.SYSTEM) final String system, @PathParam(JaxRxConstants.RESOURCE) final String resource, @Context final HttpHeaders headers, final InputStream xml) { final JaxRx impl = Systems.getInstance(system); final String info = impl.update(xml, new ResourcePath(resource, headers)); return Response.created(null).entity(info).build(); }
[ "@", "PUT", "@", "Consumes", "(", "{", "MediaType", ".", "TEXT_XML", ",", "MediaType", ".", "APPLICATION_XML", "}", ")", "public", "Response", "putResource", "(", "@", "PathParam", "(", "JaxRxConstants", ".", "SYSTEM", ")", "final", "String", "system", ",", "@", "PathParam", "(", "JaxRxConstants", ".", "RESOURCE", ")", "final", "String", "resource", ",", "@", "Context", "final", "HttpHeaders", "headers", ",", "final", "InputStream", "xml", ")", "{", "final", "JaxRx", "impl", "=", "Systems", ".", "getInstance", "(", "system", ")", ";", "final", "String", "info", "=", "impl", ".", "update", "(", "xml", ",", "new", "ResourcePath", "(", "resource", ",", "headers", ")", ")", ";", "return", "Response", ".", "created", "(", "null", ")", ".", "entity", "(", "info", ")", ".", "build", "(", ")", ";", "}" ]
This method will be called when a new XML file has to be stored within the database. The user request will be forwarded to this method. Afterwards it creates a response message with the 'created' HTTP status code, if the storing has been successful. @param system The associated system with this request. @param resource The name of the new resource. @param headers HTTP header attributes. @param xml The XML file as {@link InputStream} that will be stored. @return The HTTP status code as response.
[ "This", "method", "will", "be", "called", "when", "a", "new", "XML", "file", "has", "to", "be", "stored", "within", "the", "database", ".", "The", "user", "request", "will", "be", "forwarded", "to", "this", "method", ".", "Afterwards", "it", "creates", "a", "response", "message", "with", "the", "created", "HTTP", "status", "code", "if", "the", "storing", "has", "been", "successful", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/resource/XMLResource.java#L152-L163
143,840
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/resource/XMLResource.java
XMLResource.deleteResource
@DELETE public Response deleteResource(@PathParam(JaxRxConstants.SYSTEM) final String system, @PathParam(JaxRxConstants.RESOURCE) final String resource, @Context final HttpHeaders headers) { final JaxRx impl = Systems.getInstance(system); final String info = impl.delete(new ResourcePath(resource, headers)); return Response.ok().entity(info).build(); }
java
@DELETE public Response deleteResource(@PathParam(JaxRxConstants.SYSTEM) final String system, @PathParam(JaxRxConstants.RESOURCE) final String resource, @Context final HttpHeaders headers) { final JaxRx impl = Systems.getInstance(system); final String info = impl.delete(new ResourcePath(resource, headers)); return Response.ok().entity(info).build(); }
[ "@", "DELETE", "public", "Response", "deleteResource", "(", "@", "PathParam", "(", "JaxRxConstants", ".", "SYSTEM", ")", "final", "String", "system", ",", "@", "PathParam", "(", "JaxRxConstants", ".", "RESOURCE", ")", "final", "String", "resource", ",", "@", "Context", "final", "HttpHeaders", "headers", ")", "{", "final", "JaxRx", "impl", "=", "Systems", ".", "getInstance", "(", "system", ")", ";", "final", "String", "info", "=", "impl", ".", "delete", "(", "new", "ResourcePath", "(", "resource", ",", "headers", ")", ")", ";", "return", "Response", ".", "ok", "(", ")", ".", "entity", "(", "info", ")", ".", "build", "(", ")", ";", "}" ]
This method will be called when an HTTP client sends a DELETE request to delete an existing resource. @param system The associated system with this request. @param resource The name of the existing resource that has to be deleted. @param headers HTTP header attributes. @return The HTTP response code for this call.
[ "This", "method", "will", "be", "called", "when", "an", "HTTP", "client", "sends", "a", "DELETE", "request", "to", "delete", "an", "existing", "resource", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/resource/XMLResource.java#L177-L184
143,841
centic9/commons-dost
src/main/java/org/dstadler/commons/exec/ExecutionHelper.java
ExecutionHelper.getCommandResult
public static InputStream getCommandResult( CommandLine cmdLine, File dir, int expectedExit, long timeout, InputStream input) throws IOException { DefaultExecutor executor = getDefaultExecutor(dir, expectedExit, timeout); try (ByteArrayOutputStream outStr = new ByteArrayOutputStream()) { executor.setStreamHandler(new PumpStreamHandler(outStr, outStr, input)); try { execute(cmdLine, dir, executor, null); return new ByteArrayInputStream(outStr.toByteArray()); } catch (IOException e) { log.warning("Had output before error: " + new String(outStr.toByteArray())); throw new IOException(e); } } }
java
public static InputStream getCommandResult( CommandLine cmdLine, File dir, int expectedExit, long timeout, InputStream input) throws IOException { DefaultExecutor executor = getDefaultExecutor(dir, expectedExit, timeout); try (ByteArrayOutputStream outStr = new ByteArrayOutputStream()) { executor.setStreamHandler(new PumpStreamHandler(outStr, outStr, input)); try { execute(cmdLine, dir, executor, null); return new ByteArrayInputStream(outStr.toByteArray()); } catch (IOException e) { log.warning("Had output before error: " + new String(outStr.toByteArray())); throw new IOException(e); } } }
[ "public", "static", "InputStream", "getCommandResult", "(", "CommandLine", "cmdLine", ",", "File", "dir", ",", "int", "expectedExit", ",", "long", "timeout", ",", "InputStream", "input", ")", "throws", "IOException", "{", "DefaultExecutor", "executor", "=", "getDefaultExecutor", "(", "dir", ",", "expectedExit", ",", "timeout", ")", ";", "try", "(", "ByteArrayOutputStream", "outStr", "=", "new", "ByteArrayOutputStream", "(", ")", ")", "{", "executor", ".", "setStreamHandler", "(", "new", "PumpStreamHandler", "(", "outStr", ",", "outStr", ",", "input", ")", ")", ";", "try", "{", "execute", "(", "cmdLine", ",", "dir", ",", "executor", ",", "null", ")", ";", "return", "new", "ByteArrayInputStream", "(", "outStr", ".", "toByteArray", "(", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "log", ".", "warning", "(", "\"Had output before error: \"", "+", "new", "String", "(", "outStr", ".", "toByteArray", "(", ")", ")", ")", ";", "throw", "new", "IOException", "(", "e", ")", ";", "}", "}", "}" ]
Run the given commandline in the given directory and provide the given input to the command. Also verify that the tool has the expected exit code and does finish in the timeout. Note: The resulting output is stored in memory, running a command which prints out a huge amount of data to stdout or stderr will cause memory problems. @param cmdLine The commandline object filled with the executable and command line arguments @param dir The working directory for the command @param expectedExit The expected exit value or -1 to not fail on any exit value @param timeout The timeout in milliseconds or ExecuteWatchdog.INFINITE_TIMEOUT @param input Input for the command-execution @return An InputStream which provides the output of the command. @throws IOException Execution of sub-process failed or the sub-process returned a exit value indicating a failure
[ "Run", "the", "given", "commandline", "in", "the", "given", "directory", "and", "provide", "the", "given", "input", "to", "the", "command", ".", "Also", "verify", "that", "the", "tool", "has", "the", "expected", "exit", "code", "and", "does", "finish", "in", "the", "timeout", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/exec/ExecutionHelper.java#L70-L86
143,842
sebastiangraf/treetank
coremodules/node/src/main/java/org/treetank/data/NodeMetaPageFactory.java
NodeMetaPageFactory.deserializeEntry
public IMetaEntry deserializeEntry(final DataInput pData) throws TTIOException { try { final int kind = pData.readInt(); switch (kind) { case KEY: return new MetaKey(pData.readInt()); case VALUE: final int valSize = pData.readInt(); final byte[] bytes = new byte[valSize]; pData.readFully(bytes); return new MetaValue(new String(bytes)); default: throw new IllegalStateException("Kind not defined."); } } catch (final IOException exc) { throw new TTIOException(exc); } }
java
public IMetaEntry deserializeEntry(final DataInput pData) throws TTIOException { try { final int kind = pData.readInt(); switch (kind) { case KEY: return new MetaKey(pData.readInt()); case VALUE: final int valSize = pData.readInt(); final byte[] bytes = new byte[valSize]; pData.readFully(bytes); return new MetaValue(new String(bytes)); default: throw new IllegalStateException("Kind not defined."); } } catch (final IOException exc) { throw new TTIOException(exc); } }
[ "public", "IMetaEntry", "deserializeEntry", "(", "final", "DataInput", "pData", ")", "throws", "TTIOException", "{", "try", "{", "final", "int", "kind", "=", "pData", ".", "readInt", "(", ")", ";", "switch", "(", "kind", ")", "{", "case", "KEY", ":", "return", "new", "MetaKey", "(", "pData", ".", "readInt", "(", ")", ")", ";", "case", "VALUE", ":", "final", "int", "valSize", "=", "pData", ".", "readInt", "(", ")", ";", "final", "byte", "[", "]", "bytes", "=", "new", "byte", "[", "valSize", "]", ";", "pData", ".", "readFully", "(", "bytes", ")", ";", "return", "new", "MetaValue", "(", "new", "String", "(", "bytes", ")", ")", ";", "default", ":", "throw", "new", "IllegalStateException", "(", "\"Kind not defined.\"", ")", ";", "}", "}", "catch", "(", "final", "IOException", "exc", ")", "{", "throw", "new", "TTIOException", "(", "exc", ")", ";", "}", "}" ]
Create a meta-entry out of a serialized byte-representation. @param pData byte representation. @return the created metaEntry. @throws TTIOException if anything weird happens
[ "Create", "a", "meta", "-", "entry", "out", "of", "a", "serialized", "byte", "-", "representation", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/node/src/main/java/org/treetank/data/NodeMetaPageFactory.java#L35-L52
143,843
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.isZip
public static boolean isZip(String fileName) { if (fileName == null) { return false; } String tl = fileName.toLowerCase(); for (String element : ZIP_EXTENSIONS) { if (tl.endsWith(element)) { return true; } } return false; }
java
public static boolean isZip(String fileName) { if (fileName == null) { return false; } String tl = fileName.toLowerCase(); for (String element : ZIP_EXTENSIONS) { if (tl.endsWith(element)) { return true; } } return false; }
[ "public", "static", "boolean", "isZip", "(", "String", "fileName", ")", "{", "if", "(", "fileName", "==", "null", ")", "{", "return", "false", ";", "}", "String", "tl", "=", "fileName", ".", "toLowerCase", "(", ")", ";", "for", "(", "String", "element", ":", "ZIP_EXTENSIONS", ")", "{", "if", "(", "tl", ".", "endsWith", "(", "element", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Determines if the file has an extension known to be a ZIP file, currently this includes .zip, .jar, .war, .ear, .aar @param fileName The name of the file to check. @return True if the filename is of an extension that is a known zip file, false otherwise.
[ "Determines", "if", "the", "file", "has", "an", "extension", "known", "to", "be", "a", "ZIP", "file", "currently", "this", "includes", ".", "zip", ".", "jar", ".", "war", ".", "ear", ".", "aar" ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L63-L75
143,844
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.findZip
public static void findZip(String zipName, InputStream zipInput, FileFilter searchFilter, List<String> results) throws IOException { ZipInputStream zin = new ZipInputStream(zipInput); while (true) { final ZipEntry en; try { en = zin.getNextEntry(); } catch (IOException | IllegalArgumentException e) { throw new IOException("While handling file " + zipName, e); } if(en == null) { break; } if (searchFilter.accept(new File(en.getName()))) { results.add(zipName + ZIP_DELIMITER + en); } if (ZipUtils.isZip(en.getName())) { findZip(zipName + ZIP_DELIMITER + en, zin, searchFilter, results); } } }
java
public static void findZip(String zipName, InputStream zipInput, FileFilter searchFilter, List<String> results) throws IOException { ZipInputStream zin = new ZipInputStream(zipInput); while (true) { final ZipEntry en; try { en = zin.getNextEntry(); } catch (IOException | IllegalArgumentException e) { throw new IOException("While handling file " + zipName, e); } if(en == null) { break; } if (searchFilter.accept(new File(en.getName()))) { results.add(zipName + ZIP_DELIMITER + en); } if (ZipUtils.isZip(en.getName())) { findZip(zipName + ZIP_DELIMITER + en, zin, searchFilter, results); } } }
[ "public", "static", "void", "findZip", "(", "String", "zipName", ",", "InputStream", "zipInput", ",", "FileFilter", "searchFilter", ",", "List", "<", "String", ">", "results", ")", "throws", "IOException", "{", "ZipInputStream", "zin", "=", "new", "ZipInputStream", "(", "zipInput", ")", ";", "while", "(", "true", ")", "{", "final", "ZipEntry", "en", ";", "try", "{", "en", "=", "zin", ".", "getNextEntry", "(", ")", ";", "}", "catch", "(", "IOException", "|", "IllegalArgumentException", "e", ")", "{", "throw", "new", "IOException", "(", "\"While handling file \"", "+", "zipName", ",", "e", ")", ";", "}", "if", "(", "en", "==", "null", ")", "{", "break", ";", "}", "if", "(", "searchFilter", ".", "accept", "(", "new", "File", "(", "en", ".", "getName", "(", ")", ")", ")", ")", "{", "results", ".", "add", "(", "zipName", "+", "ZIP_DELIMITER", "+", "en", ")", ";", "}", "if", "(", "ZipUtils", ".", "isZip", "(", "en", ".", "getName", "(", ")", ")", ")", "{", "findZip", "(", "zipName", "+", "ZIP_DELIMITER", "+", "en", ",", "zin", ",", "searchFilter", ",", "results", ")", ";", "}", "}", "}" ]
Looks in the ZIP file available via zipInput for files matching the provided file-filter, recursing into sub-ZIP files. @param zipName Name of the file to read, mainly used for building the resulting pointer into the zip-file @param zipInput An InputStream which is positioned at the beginning of the zip-file contents @param searchFilter A {@link FileFilter} which determines if files in the zip-file are matched @param results A existing list where found matches are added to. @throws IOException If the ZIP file cannot be read, e.g. if it is corrupted.
[ "Looks", "in", "the", "ZIP", "file", "available", "via", "zipInput", "for", "files", "matching", "the", "provided", "file", "-", "filter", "recursing", "into", "sub", "-", "ZIP", "files", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L109-L129
143,845
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.getZipContentsRecursive
@SuppressWarnings("resource") public static InputStream getZipContentsRecursive(final String file) throws IOException { // return local file directly int pos = file.indexOf('!'); if (pos == -1) { if (!new File(file).exists()) { throw new IOException("File " + file + " does not exist"); } try { return new FileInputStream(file); } catch (IOException e) { // filter out locked errors if (e.getMessage().contains("because another process has locked")) { logger.warning("Could not read file: " + file + " because it is locked."); return new ByteArrayInputStream(new byte[] {}); } throw e; } } String zip = file.substring(0, pos); String subfile = file.substring(pos + 1); if (logger.isLoggable(Level.FINE)) { logger.fine("Trying to read zipfile: " + zip + " subfile: " + subfile); } // open original zip if (!new File(zip).exists() || !new File(zip).isFile() || !new File(zip).canRead() || new File(zip).length() == 0) { throw new IOException("ZIP file: " + zip + " does not exist or is empty or not a readable file."); } ZipFile zipfile = new ZipFile(zip); // is the target file in yet another ZIP file? pos = subfile.indexOf('!'); if (pos != -1) { // find out first ZIP file and remainder String remainder = subfile.substring(pos + 1); File subzipfile = File.createTempFile("ZipUtils", ".zip"); try { readToTemporaryFile(pos, zip, subfile, zipfile, subzipfile); // start another recursion with the temporary file and the remainder return new DeleteOnCloseInputStream( new ZipFileCloseInputStream(getZipContentsRecursive(subzipfile.getAbsolutePath() + ZIP_DELIMITER + remainder), zipfile), subzipfile); } catch (IOException e) { // need to close the zipfile here as we do not put it into a ZipFileCloseInputStream zipfile.close(); throw e; } finally { if (!subzipfile.delete()) { logger.warning("Could not delete file " + subzipfile); } } } ZipEntry entry = zipfile.getEntry(subfile); return new ZipFileCloseInputStream(zipfile.getInputStream(entry), zipfile); }
java
@SuppressWarnings("resource") public static InputStream getZipContentsRecursive(final String file) throws IOException { // return local file directly int pos = file.indexOf('!'); if (pos == -1) { if (!new File(file).exists()) { throw new IOException("File " + file + " does not exist"); } try { return new FileInputStream(file); } catch (IOException e) { // filter out locked errors if (e.getMessage().contains("because another process has locked")) { logger.warning("Could not read file: " + file + " because it is locked."); return new ByteArrayInputStream(new byte[] {}); } throw e; } } String zip = file.substring(0, pos); String subfile = file.substring(pos + 1); if (logger.isLoggable(Level.FINE)) { logger.fine("Trying to read zipfile: " + zip + " subfile: " + subfile); } // open original zip if (!new File(zip).exists() || !new File(zip).isFile() || !new File(zip).canRead() || new File(zip).length() == 0) { throw new IOException("ZIP file: " + zip + " does not exist or is empty or not a readable file."); } ZipFile zipfile = new ZipFile(zip); // is the target file in yet another ZIP file? pos = subfile.indexOf('!'); if (pos != -1) { // find out first ZIP file and remainder String remainder = subfile.substring(pos + 1); File subzipfile = File.createTempFile("ZipUtils", ".zip"); try { readToTemporaryFile(pos, zip, subfile, zipfile, subzipfile); // start another recursion with the temporary file and the remainder return new DeleteOnCloseInputStream( new ZipFileCloseInputStream(getZipContentsRecursive(subzipfile.getAbsolutePath() + ZIP_DELIMITER + remainder), zipfile), subzipfile); } catch (IOException e) { // need to close the zipfile here as we do not put it into a ZipFileCloseInputStream zipfile.close(); throw e; } finally { if (!subzipfile.delete()) { logger.warning("Could not delete file " + subzipfile); } } } ZipEntry entry = zipfile.getEntry(subfile); return new ZipFileCloseInputStream(zipfile.getInputStream(entry), zipfile); }
[ "@", "SuppressWarnings", "(", "\"resource\"", ")", "public", "static", "InputStream", "getZipContentsRecursive", "(", "final", "String", "file", ")", "throws", "IOException", "{", "// return local file directly", "int", "pos", "=", "file", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "pos", "==", "-", "1", ")", "{", "if", "(", "!", "new", "File", "(", "file", ")", ".", "exists", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"File \"", "+", "file", "+", "\" does not exist\"", ")", ";", "}", "try", "{", "return", "new", "FileInputStream", "(", "file", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "// filter out locked errors", "if", "(", "e", ".", "getMessage", "(", ")", ".", "contains", "(", "\"because another process has locked\"", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not read file: \"", "+", "file", "+", "\" because it is locked.\"", ")", ";", "return", "new", "ByteArrayInputStream", "(", "new", "byte", "[", "]", "{", "}", ")", ";", "}", "throw", "e", ";", "}", "}", "String", "zip", "=", "file", ".", "substring", "(", "0", ",", "pos", ")", ";", "String", "subfile", "=", "file", ".", "substring", "(", "pos", "+", "1", ")", ";", "if", "(", "logger", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "logger", ".", "fine", "(", "\"Trying to read zipfile: \"", "+", "zip", "+", "\" subfile: \"", "+", "subfile", ")", ";", "}", "// open original zip", "if", "(", "!", "new", "File", "(", "zip", ")", ".", "exists", "(", ")", "||", "!", "new", "File", "(", "zip", ")", ".", "isFile", "(", ")", "||", "!", "new", "File", "(", "zip", ")", ".", "canRead", "(", ")", "||", "new", "File", "(", "zip", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IOException", "(", "\"ZIP file: \"", "+", "zip", "+", "\" does not exist or is empty or not a readable file.\"", ")", ";", "}", "ZipFile", "zipfile", "=", "new", "ZipFile", "(", "zip", ")", ";", "// is the target file in yet another ZIP file?", "pos", "=", "subfile", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "pos", "!=", "-", "1", ")", "{", "// find out first ZIP file and remainder", "String", "remainder", "=", "subfile", ".", "substring", "(", "pos", "+", "1", ")", ";", "File", "subzipfile", "=", "File", ".", "createTempFile", "(", "\"ZipUtils\"", ",", "\".zip\"", ")", ";", "try", "{", "readToTemporaryFile", "(", "pos", ",", "zip", ",", "subfile", ",", "zipfile", ",", "subzipfile", ")", ";", "// start another recursion with the temporary file and the remainder", "return", "new", "DeleteOnCloseInputStream", "(", "new", "ZipFileCloseInputStream", "(", "getZipContentsRecursive", "(", "subzipfile", ".", "getAbsolutePath", "(", ")", "+", "ZIP_DELIMITER", "+", "remainder", ")", ",", "zipfile", ")", ",", "subzipfile", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "// need to close the zipfile here as we do not put it into a ZipFileCloseInputStream", "zipfile", ".", "close", "(", ")", ";", "throw", "e", ";", "}", "finally", "{", "if", "(", "!", "subzipfile", ".", "delete", "(", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not delete file \"", "+", "subzipfile", ")", ";", "}", "}", "}", "ZipEntry", "entry", "=", "zipfile", ".", "getEntry", "(", "subfile", ")", ";", "return", "new", "ZipFileCloseInputStream", "(", "zipfile", ".", "getInputStream", "(", "entry", ")", ",", "zipfile", ")", ";", "}" ]
Get a stream of the noted file which potentially resides inside ZIP files. An exclamation mark '!' denotes a zip-entry. ZIP files can be nested inside one another. e.g. c:\temp\test.zip!sample.zip!my.zip!somefile.txt If there is no exclamation mark contained in the file-parameter, an input stream to this file is returned directly. means that there is a zip file c:\temp\test.zip which contains a file "sample.zip", which itself contains a file "my.zip" which finally contains a file "somefile.txt" @param file The name of the file to read, files inside zip files are denoted with '!'. @return A stream that points to the file inside the ZIP file. @throws IOException If the file cannot be found or an error occurs while opening the file.
[ "Get", "a", "stream", "of", "the", "noted", "file", "which", "potentially", "resides", "inside", "ZIP", "files", ".", "An", "exclamation", "mark", "!", "denotes", "a", "zip", "-", "entry", ".", "ZIP", "files", "can", "be", "nested", "inside", "one", "another", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L151-L214
143,846
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.getZipStringContentsRecursive
public static String getZipStringContentsRecursive(final String file) throws IOException { // return local file directly int pos = file.indexOf('!'); if (pos == -1) { if (!new File(file).exists()) { throw new IOException("File " + file + " does not exist"); } try { try (InputStream str = new FileInputStream(file)) { if (str.available() > 0) { return IOUtils.toString(str, "UTF-8"); } return ""; } } catch (IOException e) { // filter out locked errors if (e.getMessage().contains("because another process has locked")) { logger.warning("Could not read file: " + file + " because it is locked."); return ""; } throw e; } } String zip = file.substring(0, pos); String subfile = file.substring(pos + 1); if (logger.isLoggable(Level.FINE)) { logger.fine("Trying to read zipfile: " + zip + " subfile: " + subfile); } // open original zip if (!new File(zip).exists() || !new File(zip).isFile() || !new File(zip).canRead() || new File(zip).length() == 0) { throw new IOException("ZIP file: " + zip + " does not exist or is empty or not a readable file."); } try (ZipFile zipfile = new ZipFile(zip)) { // is the target file in yet another ZIP file? pos = subfile.indexOf('!'); if (pos != -1) { // find out first ZIP file and remainder String remainder = subfile.substring(pos + 1); File subzipfile = File.createTempFile("SearchZip", ".zip"); try { readToTemporaryFile(pos, zip, subfile, zipfile, subzipfile); // start another recursion with the temporary file and the remainder return getZipStringContentsRecursive(subzipfile.getAbsolutePath() + ZIP_DELIMITER + remainder); } finally { if (!subzipfile.delete()) { logger.warning("Could not delete file " + subzipfile); } } } ZipEntry entry = zipfile.getEntry(subfile); try (InputStream str = zipfile.getInputStream(entry)) { if (str.available() > 0) { return IOUtils.toString(str, "UTF-8"); } return ""; } } }
java
public static String getZipStringContentsRecursive(final String file) throws IOException { // return local file directly int pos = file.indexOf('!'); if (pos == -1) { if (!new File(file).exists()) { throw new IOException("File " + file + " does not exist"); } try { try (InputStream str = new FileInputStream(file)) { if (str.available() > 0) { return IOUtils.toString(str, "UTF-8"); } return ""; } } catch (IOException e) { // filter out locked errors if (e.getMessage().contains("because another process has locked")) { logger.warning("Could not read file: " + file + " because it is locked."); return ""; } throw e; } } String zip = file.substring(0, pos); String subfile = file.substring(pos + 1); if (logger.isLoggable(Level.FINE)) { logger.fine("Trying to read zipfile: " + zip + " subfile: " + subfile); } // open original zip if (!new File(zip).exists() || !new File(zip).isFile() || !new File(zip).canRead() || new File(zip).length() == 0) { throw new IOException("ZIP file: " + zip + " does not exist or is empty or not a readable file."); } try (ZipFile zipfile = new ZipFile(zip)) { // is the target file in yet another ZIP file? pos = subfile.indexOf('!'); if (pos != -1) { // find out first ZIP file and remainder String remainder = subfile.substring(pos + 1); File subzipfile = File.createTempFile("SearchZip", ".zip"); try { readToTemporaryFile(pos, zip, subfile, zipfile, subzipfile); // start another recursion with the temporary file and the remainder return getZipStringContentsRecursive(subzipfile.getAbsolutePath() + ZIP_DELIMITER + remainder); } finally { if (!subzipfile.delete()) { logger.warning("Could not delete file " + subzipfile); } } } ZipEntry entry = zipfile.getEntry(subfile); try (InputStream str = zipfile.getInputStream(entry)) { if (str.available() > 0) { return IOUtils.toString(str, "UTF-8"); } return ""; } } }
[ "public", "static", "String", "getZipStringContentsRecursive", "(", "final", "String", "file", ")", "throws", "IOException", "{", "// return local file directly", "int", "pos", "=", "file", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "pos", "==", "-", "1", ")", "{", "if", "(", "!", "new", "File", "(", "file", ")", ".", "exists", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"File \"", "+", "file", "+", "\" does not exist\"", ")", ";", "}", "try", "{", "try", "(", "InputStream", "str", "=", "new", "FileInputStream", "(", "file", ")", ")", "{", "if", "(", "str", ".", "available", "(", ")", ">", "0", ")", "{", "return", "IOUtils", ".", "toString", "(", "str", ",", "\"UTF-8\"", ")", ";", "}", "return", "\"\"", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "// filter out locked errors", "if", "(", "e", ".", "getMessage", "(", ")", ".", "contains", "(", "\"because another process has locked\"", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not read file: \"", "+", "file", "+", "\" because it is locked.\"", ")", ";", "return", "\"\"", ";", "}", "throw", "e", ";", "}", "}", "String", "zip", "=", "file", ".", "substring", "(", "0", ",", "pos", ")", ";", "String", "subfile", "=", "file", ".", "substring", "(", "pos", "+", "1", ")", ";", "if", "(", "logger", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "logger", ".", "fine", "(", "\"Trying to read zipfile: \"", "+", "zip", "+", "\" subfile: \"", "+", "subfile", ")", ";", "}", "// open original zip", "if", "(", "!", "new", "File", "(", "zip", ")", ".", "exists", "(", ")", "||", "!", "new", "File", "(", "zip", ")", ".", "isFile", "(", ")", "||", "!", "new", "File", "(", "zip", ")", ".", "canRead", "(", ")", "||", "new", "File", "(", "zip", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IOException", "(", "\"ZIP file: \"", "+", "zip", "+", "\" does not exist or is empty or not a readable file.\"", ")", ";", "}", "try", "(", "ZipFile", "zipfile", "=", "new", "ZipFile", "(", "zip", ")", ")", "{", "// is the target file in yet another ZIP file?", "pos", "=", "subfile", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "pos", "!=", "-", "1", ")", "{", "// find out first ZIP file and remainder", "String", "remainder", "=", "subfile", ".", "substring", "(", "pos", "+", "1", ")", ";", "File", "subzipfile", "=", "File", ".", "createTempFile", "(", "\"SearchZip\"", ",", "\".zip\"", ")", ";", "try", "{", "readToTemporaryFile", "(", "pos", ",", "zip", ",", "subfile", ",", "zipfile", ",", "subzipfile", ")", ";", "// start another recursion with the temporary file and the remainder", "return", "getZipStringContentsRecursive", "(", "subzipfile", ".", "getAbsolutePath", "(", ")", "+", "ZIP_DELIMITER", "+", "remainder", ")", ";", "}", "finally", "{", "if", "(", "!", "subzipfile", ".", "delete", "(", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not delete file \"", "+", "subzipfile", ")", ";", "}", "}", "}", "ZipEntry", "entry", "=", "zipfile", ".", "getEntry", "(", "subfile", ")", ";", "try", "(", "InputStream", "str", "=", "zipfile", ".", "getInputStream", "(", "entry", ")", ")", "{", "if", "(", "str", ".", "available", "(", ")", ">", "0", ")", "{", "return", "IOUtils", ".", "toString", "(", "str", ",", "\"UTF-8\"", ")", ";", "}", "return", "\"\"", ";", "}", "}", "}" ]
Get the text-contents of the noted file. An exclamation mark '!' denotes a zip-entry. ZIP files can be nested inside one another. e.g. c:\temp\test.zip!sample.zip!my.zip!somefile.txt If there is no exclamation mark contained in the file-parameter, an input stream to this file is returned directly. means that there is a zip file c:\temp\test.zip which contains a file "sample.zip", which itself contains a file "my.zip" which finally contains a file "somefile.txt" @param file The name of the file to read, files inside zip files are denoted with '!'. @return The text-contents of the file @throws IOException If the file cannot be found or an error occurs while opening the file.
[ "Get", "the", "text", "-", "contents", "of", "the", "noted", "file", ".", "An", "exclamation", "mark", "!", "denotes", "a", "zip", "-", "entry", ".", "ZIP", "files", "can", "be", "nested", "inside", "one", "another", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L256-L325
143,847
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.extractZip
public static void extractZip(File zip, File toDir) throws IOException{ if(!toDir.exists()) { throw new IOException("Directory '" + toDir + "' does not exist."); } try (ZipFile zipFile = new ZipFile(zip)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File target = new File(toDir, entry.getName()); if (entry.isDirectory()) { // Assume directories are stored parents first then children. //logger.info("Extracting directory: " + entry.getName()); // This is not robust, just for demonstration purposes. if(!target.mkdirs()) { logger.warning("Could not create directory " + target); } continue; } // zips can contain nested files in sub-dirs without separate entries for the directories if(!target.getParentFile().exists() && !target.getParentFile().mkdirs()) { logger.warning("Could not create directory " + target.getParentFile()); } //logger.info("Extracting file: " + entry.getName()); try (InputStream inputStream = zipFile.getInputStream(entry)) { try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target))) { IOUtils.copy(inputStream, outputStream); } } } } catch (FileNotFoundException | NoSuchFileException e) { throw e; } catch (IOException e) { throw new IOException("While extracting file " + zip + " to " + toDir, e); } }
java
public static void extractZip(File zip, File toDir) throws IOException{ if(!toDir.exists()) { throw new IOException("Directory '" + toDir + "' does not exist."); } try (ZipFile zipFile = new ZipFile(zip)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File target = new File(toDir, entry.getName()); if (entry.isDirectory()) { // Assume directories are stored parents first then children. //logger.info("Extracting directory: " + entry.getName()); // This is not robust, just for demonstration purposes. if(!target.mkdirs()) { logger.warning("Could not create directory " + target); } continue; } // zips can contain nested files in sub-dirs without separate entries for the directories if(!target.getParentFile().exists() && !target.getParentFile().mkdirs()) { logger.warning("Could not create directory " + target.getParentFile()); } //logger.info("Extracting file: " + entry.getName()); try (InputStream inputStream = zipFile.getInputStream(entry)) { try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target))) { IOUtils.copy(inputStream, outputStream); } } } } catch (FileNotFoundException | NoSuchFileException e) { throw e; } catch (IOException e) { throw new IOException("While extracting file " + zip + " to " + toDir, e); } }
[ "public", "static", "void", "extractZip", "(", "File", "zip", ",", "File", "toDir", ")", "throws", "IOException", "{", "if", "(", "!", "toDir", ".", "exists", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"Directory '\"", "+", "toDir", "+", "\"' does not exist.\"", ")", ";", "}", "try", "(", "ZipFile", "zipFile", "=", "new", "ZipFile", "(", "zip", ")", ")", "{", "Enumeration", "<", "?", "extends", "ZipEntry", ">", "entries", "=", "zipFile", ".", "entries", "(", ")", ";", "while", "(", "entries", ".", "hasMoreElements", "(", ")", ")", "{", "ZipEntry", "entry", "=", "entries", ".", "nextElement", "(", ")", ";", "File", "target", "=", "new", "File", "(", "toDir", ",", "entry", ".", "getName", "(", ")", ")", ";", "if", "(", "entry", ".", "isDirectory", "(", ")", ")", "{", "// Assume directories are stored parents first then children.", "//logger.info(\"Extracting directory: \" + entry.getName());", "// This is not robust, just for demonstration purposes.", "if", "(", "!", "target", ".", "mkdirs", "(", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not create directory \"", "+", "target", ")", ";", "}", "continue", ";", "}", "// zips can contain nested files in sub-dirs without separate entries for the directories", "if", "(", "!", "target", ".", "getParentFile", "(", ")", ".", "exists", "(", ")", "&&", "!", "target", ".", "getParentFile", "(", ")", ".", "mkdirs", "(", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not create directory \"", "+", "target", ".", "getParentFile", "(", ")", ")", ";", "}", "//logger.info(\"Extracting file: \" + entry.getName());", "try", "(", "InputStream", "inputStream", "=", "zipFile", ".", "getInputStream", "(", "entry", ")", ")", "{", "try", "(", "BufferedOutputStream", "outputStream", "=", "new", "BufferedOutputStream", "(", "new", "FileOutputStream", "(", "target", ")", ")", ")", "{", "IOUtils", ".", "copy", "(", "inputStream", ",", "outputStream", ")", ";", "}", "}", "}", "}", "catch", "(", "FileNotFoundException", "|", "NoSuchFileException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "IOException", "(", "\"While extracting file \"", "+", "zip", "+", "\" to \"", "+", "toDir", ",", "e", ")", ";", "}", "}" ]
Extracts all files in the specified ZIP file and stores them in the denoted directory. The directory needs to exist before running this method. Note: nested ZIP files are not extracted here. @param zip The zip-file to process @param toDir Target directory, should already exist. @throws IOException Thrown if files can not be read or any other error occurs while handling the Zip-files
[ "Extracts", "all", "files", "in", "the", "specified", "ZIP", "file", "and", "stores", "them", "in", "the", "denoted", "directory", ".", "The", "directory", "needs", "to", "exist", "before", "running", "this", "method", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L338-L377
143,848
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.extractZip
public static void extractZip(InputStream zip, final File toDir) throws IOException{ if(!toDir.exists()) { throw new IOException("Directory '" + toDir + "' does not exist."); } // Use the ZipFileVisitor to walk all the entries in the Zip-Stream and create // directories and files accordingly new ZipFileVisitor() { @Override public void visit(ZipEntry entry, InputStream data) throws IOException { File target = new File(toDir, entry.getName()); if (entry.isDirectory()) { // Assume directories are stored parents first then children. //logger.info("Extracting directory: " + entry.getName() + " to " + target); // This is not robust, just for demonstration purposes. if(!target.mkdirs()) { logger.warning("Could not create directory " + target); } return; } // zips can contain nested files in sub-dirs without separate entries for the directories if(!target.getParentFile().exists() && !target.getParentFile().mkdirs()) { logger.warning("Could not create directory " + target.getParentFile()); } // it seems we cannot use IOUtils/FileUtils to copy as they close the stream int size; byte[] buffer = new byte[2048]; try (OutputStream fout = new BufferedOutputStream(new FileOutputStream(target), buffer.length)) { while ((size = data.read(buffer, 0, buffer.length)) != -1) { fout.write(buffer, 0, size); } } } }.walk(zip); }
java
public static void extractZip(InputStream zip, final File toDir) throws IOException{ if(!toDir.exists()) { throw new IOException("Directory '" + toDir + "' does not exist."); } // Use the ZipFileVisitor to walk all the entries in the Zip-Stream and create // directories and files accordingly new ZipFileVisitor() { @Override public void visit(ZipEntry entry, InputStream data) throws IOException { File target = new File(toDir, entry.getName()); if (entry.isDirectory()) { // Assume directories are stored parents first then children. //logger.info("Extracting directory: " + entry.getName() + " to " + target); // This is not robust, just for demonstration purposes. if(!target.mkdirs()) { logger.warning("Could not create directory " + target); } return; } // zips can contain nested files in sub-dirs without separate entries for the directories if(!target.getParentFile().exists() && !target.getParentFile().mkdirs()) { logger.warning("Could not create directory " + target.getParentFile()); } // it seems we cannot use IOUtils/FileUtils to copy as they close the stream int size; byte[] buffer = new byte[2048]; try (OutputStream fout = new BufferedOutputStream(new FileOutputStream(target), buffer.length)) { while ((size = data.read(buffer, 0, buffer.length)) != -1) { fout.write(buffer, 0, size); } } } }.walk(zip); }
[ "public", "static", "void", "extractZip", "(", "InputStream", "zip", ",", "final", "File", "toDir", ")", "throws", "IOException", "{", "if", "(", "!", "toDir", ".", "exists", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"Directory '\"", "+", "toDir", "+", "\"' does not exist.\"", ")", ";", "}", "// Use the ZipFileVisitor to walk all the entries in the Zip-Stream and create", "// directories and files accordingly", "new", "ZipFileVisitor", "(", ")", "{", "@", "Override", "public", "void", "visit", "(", "ZipEntry", "entry", ",", "InputStream", "data", ")", "throws", "IOException", "{", "File", "target", "=", "new", "File", "(", "toDir", ",", "entry", ".", "getName", "(", ")", ")", ";", "if", "(", "entry", ".", "isDirectory", "(", ")", ")", "{", "// Assume directories are stored parents first then children.", "//logger.info(\"Extracting directory: \" + entry.getName() + \" to \" + target);", "// This is not robust, just for demonstration purposes.", "if", "(", "!", "target", ".", "mkdirs", "(", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not create directory \"", "+", "target", ")", ";", "}", "return", ";", "}", "// zips can contain nested files in sub-dirs without separate entries for the directories", "if", "(", "!", "target", ".", "getParentFile", "(", ")", ".", "exists", "(", ")", "&&", "!", "target", ".", "getParentFile", "(", ")", ".", "mkdirs", "(", ")", ")", "{", "logger", ".", "warning", "(", "\"Could not create directory \"", "+", "target", ".", "getParentFile", "(", ")", ")", ";", "}", "// it seems we cannot use IOUtils/FileUtils to copy as they close the stream", "int", "size", ";", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "2048", "]", ";", "try", "(", "OutputStream", "fout", "=", "new", "BufferedOutputStream", "(", "new", "FileOutputStream", "(", "target", ")", ",", "buffer", ".", "length", ")", ")", "{", "while", "(", "(", "size", "=", "data", ".", "read", "(", "buffer", ",", "0", ",", "buffer", ".", "length", ")", ")", "!=", "-", "1", ")", "{", "fout", ".", "write", "(", "buffer", ",", "0", ",", "size", ")", ";", "}", "}", "}", "}", ".", "walk", "(", "zip", ")", ";", "}" ]
Extracts all files in the ZIP file passed as InputStream and stores them in the denoted directory. The directory needs to exist before running this method. Note: nested ZIP files are not extracted here. @param zip An {@link InputStream} to read zipped files from @param toDir Target directory, should already exist. @throws IOException Thrown if files can not be read or any other error occurs while handling the Zip-files
[ "Extracts", "all", "files", "in", "the", "ZIP", "file", "passed", "as", "InputStream", "and", "stores", "them", "in", "the", "denoted", "directory", ".", "The", "directory", "needs", "to", "exist", "before", "running", "this", "method", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L390-L426
143,849
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.replaceInZip
public static void replaceInZip(String zipFile, String data, String encoding) throws IOException { if(!isFileInZip(zipFile)) { throw new IOException("Parameter should specify a file inside a ZIP file, but had: " + zipFile); } File zip = new File(zipFile.substring(0, zipFile.indexOf(ZIP_DELIMITER))); String zipOut = zipFile.substring(zipFile.indexOf(ZIP_DELIMITER)+1); logger.info("Updating containing Zip " + zip + " to " + zipOut); // replace in zip ZipUtils.replaceInZip(zip, zipOut, data, encoding); }
java
public static void replaceInZip(String zipFile, String data, String encoding) throws IOException { if(!isFileInZip(zipFile)) { throw new IOException("Parameter should specify a file inside a ZIP file, but had: " + zipFile); } File zip = new File(zipFile.substring(0, zipFile.indexOf(ZIP_DELIMITER))); String zipOut = zipFile.substring(zipFile.indexOf(ZIP_DELIMITER)+1); logger.info("Updating containing Zip " + zip + " to " + zipOut); // replace in zip ZipUtils.replaceInZip(zip, zipOut, data, encoding); }
[ "public", "static", "void", "replaceInZip", "(", "String", "zipFile", ",", "String", "data", ",", "String", "encoding", ")", "throws", "IOException", "{", "if", "(", "!", "isFileInZip", "(", "zipFile", ")", ")", "{", "throw", "new", "IOException", "(", "\"Parameter should specify a file inside a ZIP file, but had: \"", "+", "zipFile", ")", ";", "}", "File", "zip", "=", "new", "File", "(", "zipFile", ".", "substring", "(", "0", ",", "zipFile", ".", "indexOf", "(", "ZIP_DELIMITER", ")", ")", ")", ";", "String", "zipOut", "=", "zipFile", ".", "substring", "(", "zipFile", ".", "indexOf", "(", "ZIP_DELIMITER", ")", "+", "1", ")", ";", "logger", ".", "info", "(", "\"Updating containing Zip \"", "+", "zip", "+", "\" to \"", "+", "zipOut", ")", ";", "// replace in zip", "ZipUtils", ".", "replaceInZip", "(", "zip", ",", "zipOut", ",", "data", ",", "encoding", ")", ";", "}" ]
Replace the file denoted by the zipFile with the provided data. The zipFile specifies both the zip and the file inside the zip using '!' as separator. @param zipFile The zip-file to process @param data The string-data to replace @param encoding The encoding that should be used when writing the string data to the file @throws IOException Thrown if files can not be read or any other error occurs while handling the Zip-files
[ "Replace", "the", "file", "denoted", "by", "the", "zipFile", "with", "the", "provided", "data", ".", "The", "zipFile", "specifies", "both", "the", "zip", "and", "the", "file", "inside", "the", "zip", "using", "!", "as", "separator", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L437-L449
143,850
centic9/commons-dost
src/main/java/org/dstadler/commons/zip/ZipUtils.java
ZipUtils.replaceInZip
public static void replaceInZip(File zip, String file, String data, String encoding) throws IOException { // open the output side File zipOutFile = File.createTempFile("ZipReplace", ".zip"); try { FileOutputStream fos = new FileOutputStream(zipOutFile); try (ZipOutputStream zos = new ZipOutputStream(fos)) { // open the input side try (ZipFile zipFile = new ZipFile(zip)) { boolean found = false; // walk all entries and copy them into the new file Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); try { if (entry.getName().equals(file)) { zos.putNextEntry(new ZipEntry(entry.getName())); IOUtils.write(data, zos, encoding); found = true; } else { zos.putNextEntry(entry); IOUtils.copy(zipFile.getInputStream(entry), zos); } } finally { zos.closeEntry(); } } if(!found) { zos.putNextEntry(new ZipEntry(file)); try { IOUtils.write(data, zos, "UTF-8"); } finally { zos.closeEntry(); } } } } // copy over the data FileUtils.copyFile(zipOutFile, zip); } finally { if(!zipOutFile.delete()) { //noinspection ThrowFromFinallyBlock throw new IOException("Error deleting file: " + zipOutFile); } } }
java
public static void replaceInZip(File zip, String file, String data, String encoding) throws IOException { // open the output side File zipOutFile = File.createTempFile("ZipReplace", ".zip"); try { FileOutputStream fos = new FileOutputStream(zipOutFile); try (ZipOutputStream zos = new ZipOutputStream(fos)) { // open the input side try (ZipFile zipFile = new ZipFile(zip)) { boolean found = false; // walk all entries and copy them into the new file Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); try { if (entry.getName().equals(file)) { zos.putNextEntry(new ZipEntry(entry.getName())); IOUtils.write(data, zos, encoding); found = true; } else { zos.putNextEntry(entry); IOUtils.copy(zipFile.getInputStream(entry), zos); } } finally { zos.closeEntry(); } } if(!found) { zos.putNextEntry(new ZipEntry(file)); try { IOUtils.write(data, zos, "UTF-8"); } finally { zos.closeEntry(); } } } } // copy over the data FileUtils.copyFile(zipOutFile, zip); } finally { if(!zipOutFile.delete()) { //noinspection ThrowFromFinallyBlock throw new IOException("Error deleting file: " + zipOutFile); } } }
[ "public", "static", "void", "replaceInZip", "(", "File", "zip", ",", "String", "file", ",", "String", "data", ",", "String", "encoding", ")", "throws", "IOException", "{", "// open the output side", "File", "zipOutFile", "=", "File", ".", "createTempFile", "(", "\"ZipReplace\"", ",", "\".zip\"", ")", ";", "try", "{", "FileOutputStream", "fos", "=", "new", "FileOutputStream", "(", "zipOutFile", ")", ";", "try", "(", "ZipOutputStream", "zos", "=", "new", "ZipOutputStream", "(", "fos", ")", ")", "{", "// open the input side", "try", "(", "ZipFile", "zipFile", "=", "new", "ZipFile", "(", "zip", ")", ")", "{", "boolean", "found", "=", "false", ";", "// walk all entries and copy them into the new file", "Enumeration", "<", "?", "extends", "ZipEntry", ">", "entries", "=", "zipFile", ".", "entries", "(", ")", ";", "while", "(", "entries", ".", "hasMoreElements", "(", ")", ")", "{", "ZipEntry", "entry", "=", "entries", ".", "nextElement", "(", ")", ";", "try", "{", "if", "(", "entry", ".", "getName", "(", ")", ".", "equals", "(", "file", ")", ")", "{", "zos", ".", "putNextEntry", "(", "new", "ZipEntry", "(", "entry", ".", "getName", "(", ")", ")", ")", ";", "IOUtils", ".", "write", "(", "data", ",", "zos", ",", "encoding", ")", ";", "found", "=", "true", ";", "}", "else", "{", "zos", ".", "putNextEntry", "(", "entry", ")", ";", "IOUtils", ".", "copy", "(", "zipFile", ".", "getInputStream", "(", "entry", ")", ",", "zos", ")", ";", "}", "}", "finally", "{", "zos", ".", "closeEntry", "(", ")", ";", "}", "}", "if", "(", "!", "found", ")", "{", "zos", ".", "putNextEntry", "(", "new", "ZipEntry", "(", "file", ")", ")", ";", "try", "{", "IOUtils", ".", "write", "(", "data", ",", "zos", ",", "\"UTF-8\"", ")", ";", "}", "finally", "{", "zos", ".", "closeEntry", "(", ")", ";", "}", "}", "}", "}", "// copy over the data", "FileUtils", ".", "copyFile", "(", "zipOutFile", ",", "zip", ")", ";", "}", "finally", "{", "if", "(", "!", "zipOutFile", ".", "delete", "(", ")", ")", "{", "//noinspection ThrowFromFinallyBlock", "throw", "new", "IOException", "(", "\"Error deleting file: \"", "+", "zipOutFile", ")", ";", "}", "}", "}" ]
Replaces the specified file in the provided ZIP file with the provided content. @param zip The zip-file to process @param file The file to look for @param data The string-data to replace @param encoding The encoding that should be used when writing the string data to the file @throws IOException Thrown if files can not be read or any other error occurs while handling the Zip-files
[ "Replaces", "the", "specified", "file", "in", "the", "provided", "ZIP", "file", "with", "the", "provided", "content", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/zip/ZipUtils.java#L461-L509
143,851
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/util/GeoUtil.java
GeoUtil.getPosition
public static GeoPosition getPosition(Point2D pixelCoordinate, int zoom, TileFactoryInfo info) { // p(" --bitmap to latlon : " + coord + " " + zoom); double wx = pixelCoordinate.getX(); double wy = pixelCoordinate.getY(); // this reverses getBitmapCoordinates double flon = (wx - info.getMapCenterInPixelsAtZoom(zoom).getX()) / info.getLongitudeDegreeWidthInPixels(zoom); double e1 = (wy - info.getMapCenterInPixelsAtZoom(zoom).getY()) / (-1 * info.getLongitudeRadianWidthInPixels(zoom)); double e2 = (2 * Math.atan(Math.exp(e1)) - Math.PI / 2) / (Math.PI / 180.0); double flat = e2; GeoPosition wc = new GeoPosition(flat, flon); return wc; }
java
public static GeoPosition getPosition(Point2D pixelCoordinate, int zoom, TileFactoryInfo info) { // p(" --bitmap to latlon : " + coord + " " + zoom); double wx = pixelCoordinate.getX(); double wy = pixelCoordinate.getY(); // this reverses getBitmapCoordinates double flon = (wx - info.getMapCenterInPixelsAtZoom(zoom).getX()) / info.getLongitudeDegreeWidthInPixels(zoom); double e1 = (wy - info.getMapCenterInPixelsAtZoom(zoom).getY()) / (-1 * info.getLongitudeRadianWidthInPixels(zoom)); double e2 = (2 * Math.atan(Math.exp(e1)) - Math.PI / 2) / (Math.PI / 180.0); double flat = e2; GeoPosition wc = new GeoPosition(flat, flon); return wc; }
[ "public", "static", "GeoPosition", "getPosition", "(", "Point2D", "pixelCoordinate", ",", "int", "zoom", ",", "TileFactoryInfo", "info", ")", "{", "// p(\" --bitmap to latlon : \" + coord + \" \" + zoom);", "double", "wx", "=", "pixelCoordinate", ".", "getX", "(", ")", ";", "double", "wy", "=", "pixelCoordinate", ".", "getY", "(", ")", ";", "// this reverses getBitmapCoordinates", "double", "flon", "=", "(", "wx", "-", "info", ".", "getMapCenterInPixelsAtZoom", "(", "zoom", ")", ".", "getX", "(", ")", ")", "/", "info", ".", "getLongitudeDegreeWidthInPixels", "(", "zoom", ")", ";", "double", "e1", "=", "(", "wy", "-", "info", ".", "getMapCenterInPixelsAtZoom", "(", "zoom", ")", ".", "getY", "(", ")", ")", "/", "(", "-", "1", "*", "info", ".", "getLongitudeRadianWidthInPixels", "(", "zoom", ")", ")", ";", "double", "e2", "=", "(", "2", "*", "Math", ".", "atan", "(", "Math", ".", "exp", "(", "e1", ")", ")", "-", "Math", ".", "PI", "/", "2", ")", "/", "(", "Math", ".", "PI", "/", "180.0", ")", ";", "double", "flat", "=", "e2", ";", "GeoPosition", "wc", "=", "new", "GeoPosition", "(", "flat", ",", "flon", ")", ";", "return", "wc", ";", "}" ]
Convert an on screen pixel coordinate and a zoom level to a geo position @param pixelCoordinate the coordinate in pixels @param zoom the zoom level @param info the tile factory info @return a geo position
[ "Convert", "an", "on", "screen", "pixel", "coordinate", "and", "a", "zoom", "level", "to", "a", "geo", "position" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/util/GeoUtil.java#L123-L136
143,852
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/TileFactory.java
TileFactory.pixelToGeo
public GeoPosition pixelToGeo(Point2D pixelCoordinate, int zoom) { return GeoUtil.getPosition(pixelCoordinate, zoom, getInfo()); }
java
public GeoPosition pixelToGeo(Point2D pixelCoordinate, int zoom) { return GeoUtil.getPosition(pixelCoordinate, zoom, getInfo()); }
[ "public", "GeoPosition", "pixelToGeo", "(", "Point2D", "pixelCoordinate", ",", "int", "zoom", ")", "{", "return", "GeoUtil", ".", "getPosition", "(", "pixelCoordinate", ",", "zoom", ",", "getInfo", "(", ")", ")", ";", "}" ]
Convert a pixel in the world bitmap at the specified zoom level into a GeoPosition @param pixelCoordinate a Point2D representing a pixel in the world bitmap @param zoom the zoom level of the world bitmap @return the converted GeoPosition
[ "Convert", "a", "pixel", "in", "the", "world", "bitmap", "at", "the", "specified", "zoom", "level", "into", "a", "GeoPosition" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/TileFactory.java#L79-L82
143,853
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/TileFactory.java
TileFactory.geoToPixel
public Point2D geoToPixel(GeoPosition c, int zoomLevel) { return GeoUtil.getBitmapCoordinate(c, zoomLevel, getInfo()); }
java
public Point2D geoToPixel(GeoPosition c, int zoomLevel) { return GeoUtil.getBitmapCoordinate(c, zoomLevel, getInfo()); }
[ "public", "Point2D", "geoToPixel", "(", "GeoPosition", "c", ",", "int", "zoomLevel", ")", "{", "return", "GeoUtil", ".", "getBitmapCoordinate", "(", "c", ",", "zoomLevel", ",", "getInfo", "(", ")", ")", ";", "}" ]
Convert a GeoPosition to a pixel position in the world bitmap a the specified zoom level. @param c a GeoPosition @param zoomLevel the zoom level to extract the pixel coordinate for @return the pixel point
[ "Convert", "a", "GeoPosition", "to", "a", "pixel", "position", "in", "the", "world", "bitmap", "a", "the", "specified", "zoom", "level", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/TileFactory.java#L90-L93
143,854
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.doPaintComponent
private void doPaintComponent(Graphics g) {/* * if (isOpaque() || isDesignTime()) { g.setColor(getBackground()); g.fillRect(0,0,getWidth(),getHeight()); } */ if (isDesignTime()) { // do nothing } else { int z = getZoom(); Rectangle viewportBounds = getViewportBounds(); drawMapTiles(g, z, viewportBounds); drawOverlays(z, g, viewportBounds); } super.paintBorder(g); }
java
private void doPaintComponent(Graphics g) {/* * if (isOpaque() || isDesignTime()) { g.setColor(getBackground()); g.fillRect(0,0,getWidth(),getHeight()); } */ if (isDesignTime()) { // do nothing } else { int z = getZoom(); Rectangle viewportBounds = getViewportBounds(); drawMapTiles(g, z, viewportBounds); drawOverlays(z, g, viewportBounds); } super.paintBorder(g); }
[ "private", "void", "doPaintComponent", "(", "Graphics", "g", ")", "{", "/*\r\n * if (isOpaque() || isDesignTime()) { g.setColor(getBackground()); g.fillRect(0,0,getWidth(),getHeight()); }\r\n */", "if", "(", "isDesignTime", "(", ")", ")", "{", "// do nothing\r", "}", "else", "{", "int", "z", "=", "getZoom", "(", ")", ";", "Rectangle", "viewportBounds", "=", "getViewportBounds", "(", ")", ";", "drawMapTiles", "(", "g", ",", "z", ",", "viewportBounds", ")", ";", "drawOverlays", "(", "z", ",", "g", ",", "viewportBounds", ")", ";", "}", "super", ".", "paintBorder", "(", "g", ")", ";", "}" ]
the method that does the actual painting
[ "the", "method", "that", "does", "the", "actual", "painting" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L155-L173
143,855
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.setZoom
public void setZoom(int zoom) { if (zoom == this.zoomLevel) { return; } TileFactoryInfo info = getTileFactory().getInfo(); // don't repaint if we are out of the valid zoom levels if (info != null && (zoom < info.getMinimumZoomLevel() || zoom > info.getMaximumZoomLevel())) { return; } // if(zoom >= 0 && zoom <= 15 && zoom != this.zoom) { int oldzoom = this.zoomLevel; Point2D oldCenter = getCenter(); Dimension oldMapSize = getTileFactory().getMapSize(oldzoom); this.zoomLevel = zoom; this.firePropertyChange("zoom", oldzoom, zoom); Dimension mapSize = getTileFactory().getMapSize(zoom); setCenter(new Point2D.Double(oldCenter.getX() * (mapSize.getWidth() / oldMapSize.getWidth()), oldCenter.getY() * (mapSize.getHeight() / oldMapSize.getHeight()))); repaint(); }
java
public void setZoom(int zoom) { if (zoom == this.zoomLevel) { return; } TileFactoryInfo info = getTileFactory().getInfo(); // don't repaint if we are out of the valid zoom levels if (info != null && (zoom < info.getMinimumZoomLevel() || zoom > info.getMaximumZoomLevel())) { return; } // if(zoom >= 0 && zoom <= 15 && zoom != this.zoom) { int oldzoom = this.zoomLevel; Point2D oldCenter = getCenter(); Dimension oldMapSize = getTileFactory().getMapSize(oldzoom); this.zoomLevel = zoom; this.firePropertyChange("zoom", oldzoom, zoom); Dimension mapSize = getTileFactory().getMapSize(zoom); setCenter(new Point2D.Double(oldCenter.getX() * (mapSize.getWidth() / oldMapSize.getWidth()), oldCenter.getY() * (mapSize.getHeight() / oldMapSize.getHeight()))); repaint(); }
[ "public", "void", "setZoom", "(", "int", "zoom", ")", "{", "if", "(", "zoom", "==", "this", ".", "zoomLevel", ")", "{", "return", ";", "}", "TileFactoryInfo", "info", "=", "getTileFactory", "(", ")", ".", "getInfo", "(", ")", ";", "// don't repaint if we are out of the valid zoom levels\r", "if", "(", "info", "!=", "null", "&&", "(", "zoom", "<", "info", ".", "getMinimumZoomLevel", "(", ")", "||", "zoom", ">", "info", ".", "getMaximumZoomLevel", "(", ")", ")", ")", "{", "return", ";", "}", "// if(zoom >= 0 && zoom <= 15 && zoom != this.zoom) {\r", "int", "oldzoom", "=", "this", ".", "zoomLevel", ";", "Point2D", "oldCenter", "=", "getCenter", "(", ")", ";", "Dimension", "oldMapSize", "=", "getTileFactory", "(", ")", ".", "getMapSize", "(", "oldzoom", ")", ";", "this", ".", "zoomLevel", "=", "zoom", ";", "this", ".", "firePropertyChange", "(", "\"zoom\"", ",", "oldzoom", ",", "zoom", ")", ";", "Dimension", "mapSize", "=", "getTileFactory", "(", ")", ".", "getMapSize", "(", "zoom", ")", ";", "setCenter", "(", "new", "Point2D", ".", "Double", "(", "oldCenter", ".", "getX", "(", ")", "*", "(", "mapSize", ".", "getWidth", "(", ")", "/", "oldMapSize", ".", "getWidth", "(", ")", ")", ",", "oldCenter", ".", "getY", "(", ")", "*", "(", "mapSize", ".", "getHeight", "(", ")", "/", "oldMapSize", ".", "getHeight", "(", ")", ")", ")", ")", ";", "repaint", "(", ")", ";", "}" ]
Set the current zoom level @param zoom the new zoom level
[ "Set", "the", "current", "zoom", "level" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L383-L410
143,856
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.setAddressLocation
public void setAddressLocation(GeoPosition addressLocation) { GeoPosition old = getAddressLocation(); this.addressLocation = addressLocation; setCenter(getTileFactory().geoToPixel(addressLocation, getZoom())); firePropertyChange("addressLocation", old, getAddressLocation()); repaint(); }
java
public void setAddressLocation(GeoPosition addressLocation) { GeoPosition old = getAddressLocation(); this.addressLocation = addressLocation; setCenter(getTileFactory().geoToPixel(addressLocation, getZoom())); firePropertyChange("addressLocation", old, getAddressLocation()); repaint(); }
[ "public", "void", "setAddressLocation", "(", "GeoPosition", "addressLocation", ")", "{", "GeoPosition", "old", "=", "getAddressLocation", "(", ")", ";", "this", ".", "addressLocation", "=", "addressLocation", ";", "setCenter", "(", "getTileFactory", "(", ")", ".", "geoToPixel", "(", "addressLocation", ",", "getZoom", "(", ")", ")", ")", ";", "firePropertyChange", "(", "\"addressLocation\"", ",", "old", ",", "getAddressLocation", "(", ")", ")", ";", "repaint", "(", ")", ";", "}" ]
Gets the current address location of the map @param addressLocation the new address location
[ "Gets", "the", "current", "address", "location", "of", "the", "map" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L435-L443
143,857
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.setDrawTileBorders
public void setDrawTileBorders(boolean drawTileBorders) { boolean old = isDrawTileBorders(); this.drawTileBorders = drawTileBorders; firePropertyChange("drawTileBorders", old, isDrawTileBorders()); repaint(); }
java
public void setDrawTileBorders(boolean drawTileBorders) { boolean old = isDrawTileBorders(); this.drawTileBorders = drawTileBorders; firePropertyChange("drawTileBorders", old, isDrawTileBorders()); repaint(); }
[ "public", "void", "setDrawTileBorders", "(", "boolean", "drawTileBorders", ")", "{", "boolean", "old", "=", "isDrawTileBorders", "(", ")", ";", "this", ".", "drawTileBorders", "=", "drawTileBorders", ";", "firePropertyChange", "(", "\"drawTileBorders\"", ",", "old", ",", "isDrawTileBorders", "(", ")", ")", ";", "repaint", "(", ")", ";", "}" ]
Set if the tile borders should be drawn. Mainly used for debugging. @param drawTileBorders new value of this drawTileBorders
[ "Set", "if", "the", "tile", "borders", "should", "be", "drawn", ".", "Mainly", "used", "for", "debugging", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L468-L474
143,858
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.setCenterPosition
public void setCenterPosition(GeoPosition geoPosition) { GeoPosition oldVal = getCenterPosition(); setCenter(getTileFactory().geoToPixel(geoPosition, zoomLevel)); repaint(); GeoPosition newVal = getCenterPosition(); firePropertyChange("centerPosition", oldVal, newVal); }
java
public void setCenterPosition(GeoPosition geoPosition) { GeoPosition oldVal = getCenterPosition(); setCenter(getTileFactory().geoToPixel(geoPosition, zoomLevel)); repaint(); GeoPosition newVal = getCenterPosition(); firePropertyChange("centerPosition", oldVal, newVal); }
[ "public", "void", "setCenterPosition", "(", "GeoPosition", "geoPosition", ")", "{", "GeoPosition", "oldVal", "=", "getCenterPosition", "(", ")", ";", "setCenter", "(", "getTileFactory", "(", ")", ".", "geoToPixel", "(", "geoPosition", ",", "zoomLevel", ")", ")", ";", "repaint", "(", ")", ";", "GeoPosition", "newVal", "=", "getCenterPosition", "(", ")", ";", "firePropertyChange", "(", "\"centerPosition\"", ",", "oldVal", ",", "newVal", ")", ";", "}" ]
A property indicating the center position of the map @param geoPosition the new property value
[ "A", "property", "indicating", "the", "center", "position", "of", "the", "map" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L480-L487
143,859
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.setCenter
public void setCenter(Point2D center) { Point2D old = this.getCenter(); double centerX = center.getX(); double centerY = center.getY(); Dimension mapSize = getTileFactory().getMapSize(getZoom()); int mapHeight = (int) mapSize.getHeight() * getTileFactory().getTileSize(getZoom()); int mapWidth = (int) mapSize.getWidth() * getTileFactory().getTileSize(getZoom()); if (isRestrictOutsidePanning()) { Insets insets = getInsets(); int viewportHeight = getHeight() - insets.top - insets.bottom; int viewportWidth = getWidth() - insets.left - insets.right; // don't let the user pan over the top edge Rectangle newVP = calculateViewportBounds(center); if (newVP.getY() < 0) { centerY = viewportHeight / 2; } // don't let the user pan over the left edge if (!isHorizontalWrapped() && newVP.getX() < 0) { centerX = viewportWidth / 2; } // don't let the user pan over the bottom edge if (newVP.getY() + newVP.getHeight() > mapHeight) { centerY = mapHeight - viewportHeight / 2; } // don't let the user pan over the right edge if (!isHorizontalWrapped() && (newVP.getX() + newVP.getWidth() > mapWidth)) { centerX = mapWidth - viewportWidth / 2; } // if map is to small then just center it vert if (mapHeight < newVP.getHeight()) { centerY = mapHeight / 2;// viewportHeight/2;// - mapHeight/2; } // if map is too small then just center it horiz if (!isHorizontalWrapped() && mapWidth < newVP.getWidth()) { centerX = mapWidth / 2; } } // If center is outside (0, 0,mapWidth, mapHeight) // compute modulo to get it back in. { centerX = centerX % mapWidth; centerY = centerY % mapHeight; if (centerX < 0) centerX += mapWidth; if (centerY < 0) centerY += mapHeight; } GeoPosition oldGP = this.getCenterPosition(); this.center = new Point2D.Double(centerX, centerY); firePropertyChange("center", old, this.center); firePropertyChange("centerPosition", oldGP, this.getCenterPosition()); repaint(); }
java
public void setCenter(Point2D center) { Point2D old = this.getCenter(); double centerX = center.getX(); double centerY = center.getY(); Dimension mapSize = getTileFactory().getMapSize(getZoom()); int mapHeight = (int) mapSize.getHeight() * getTileFactory().getTileSize(getZoom()); int mapWidth = (int) mapSize.getWidth() * getTileFactory().getTileSize(getZoom()); if (isRestrictOutsidePanning()) { Insets insets = getInsets(); int viewportHeight = getHeight() - insets.top - insets.bottom; int viewportWidth = getWidth() - insets.left - insets.right; // don't let the user pan over the top edge Rectangle newVP = calculateViewportBounds(center); if (newVP.getY() < 0) { centerY = viewportHeight / 2; } // don't let the user pan over the left edge if (!isHorizontalWrapped() && newVP.getX() < 0) { centerX = viewportWidth / 2; } // don't let the user pan over the bottom edge if (newVP.getY() + newVP.getHeight() > mapHeight) { centerY = mapHeight - viewportHeight / 2; } // don't let the user pan over the right edge if (!isHorizontalWrapped() && (newVP.getX() + newVP.getWidth() > mapWidth)) { centerX = mapWidth - viewportWidth / 2; } // if map is to small then just center it vert if (mapHeight < newVP.getHeight()) { centerY = mapHeight / 2;// viewportHeight/2;// - mapHeight/2; } // if map is too small then just center it horiz if (!isHorizontalWrapped() && mapWidth < newVP.getWidth()) { centerX = mapWidth / 2; } } // If center is outside (0, 0,mapWidth, mapHeight) // compute modulo to get it back in. { centerX = centerX % mapWidth; centerY = centerY % mapHeight; if (centerX < 0) centerX += mapWidth; if (centerY < 0) centerY += mapHeight; } GeoPosition oldGP = this.getCenterPosition(); this.center = new Point2D.Double(centerX, centerY); firePropertyChange("center", old, this.center); firePropertyChange("centerPosition", oldGP, this.getCenterPosition()); repaint(); }
[ "public", "void", "setCenter", "(", "Point2D", "center", ")", "{", "Point2D", "old", "=", "this", ".", "getCenter", "(", ")", ";", "double", "centerX", "=", "center", ".", "getX", "(", ")", ";", "double", "centerY", "=", "center", ".", "getY", "(", ")", ";", "Dimension", "mapSize", "=", "getTileFactory", "(", ")", ".", "getMapSize", "(", "getZoom", "(", ")", ")", ";", "int", "mapHeight", "=", "(", "int", ")", "mapSize", ".", "getHeight", "(", ")", "*", "getTileFactory", "(", ")", ".", "getTileSize", "(", "getZoom", "(", ")", ")", ";", "int", "mapWidth", "=", "(", "int", ")", "mapSize", ".", "getWidth", "(", ")", "*", "getTileFactory", "(", ")", ".", "getTileSize", "(", "getZoom", "(", ")", ")", ";", "if", "(", "isRestrictOutsidePanning", "(", ")", ")", "{", "Insets", "insets", "=", "getInsets", "(", ")", ";", "int", "viewportHeight", "=", "getHeight", "(", ")", "-", "insets", ".", "top", "-", "insets", ".", "bottom", ";", "int", "viewportWidth", "=", "getWidth", "(", ")", "-", "insets", ".", "left", "-", "insets", ".", "right", ";", "// don't let the user pan over the top edge\r", "Rectangle", "newVP", "=", "calculateViewportBounds", "(", "center", ")", ";", "if", "(", "newVP", ".", "getY", "(", ")", "<", "0", ")", "{", "centerY", "=", "viewportHeight", "/", "2", ";", "}", "// don't let the user pan over the left edge\r", "if", "(", "!", "isHorizontalWrapped", "(", ")", "&&", "newVP", ".", "getX", "(", ")", "<", "0", ")", "{", "centerX", "=", "viewportWidth", "/", "2", ";", "}", "// don't let the user pan over the bottom edge\r", "if", "(", "newVP", ".", "getY", "(", ")", "+", "newVP", ".", "getHeight", "(", ")", ">", "mapHeight", ")", "{", "centerY", "=", "mapHeight", "-", "viewportHeight", "/", "2", ";", "}", "// don't let the user pan over the right edge\r", "if", "(", "!", "isHorizontalWrapped", "(", ")", "&&", "(", "newVP", ".", "getX", "(", ")", "+", "newVP", ".", "getWidth", "(", ")", ">", "mapWidth", ")", ")", "{", "centerX", "=", "mapWidth", "-", "viewportWidth", "/", "2", ";", "}", "// if map is to small then just center it vert\r", "if", "(", "mapHeight", "<", "newVP", ".", "getHeight", "(", ")", ")", "{", "centerY", "=", "mapHeight", "/", "2", ";", "// viewportHeight/2;// - mapHeight/2;\r", "}", "// if map is too small then just center it horiz\r", "if", "(", "!", "isHorizontalWrapped", "(", ")", "&&", "mapWidth", "<", "newVP", ".", "getWidth", "(", ")", ")", "{", "centerX", "=", "mapWidth", "/", "2", ";", "}", "}", "// If center is outside (0, 0,mapWidth, mapHeight)\r", "// compute modulo to get it back in.\r", "{", "centerX", "=", "centerX", "%", "mapWidth", ";", "centerY", "=", "centerY", "%", "mapHeight", ";", "if", "(", "centerX", "<", "0", ")", "centerX", "+=", "mapWidth", ";", "if", "(", "centerY", "<", "0", ")", "centerY", "+=", "mapHeight", ";", "}", "GeoPosition", "oldGP", "=", "this", ".", "getCenterPosition", "(", ")", ";", "this", ".", "center", "=", "new", "Point2D", ".", "Double", "(", "centerX", ",", "centerY", ")", ";", "firePropertyChange", "(", "\"center\"", ",", "old", ",", "this", ".", "center", ")", ";", "firePropertyChange", "(", "\"centerPosition\"", ",", "oldGP", ",", "this", ".", "getCenterPosition", "(", ")", ")", ";", "repaint", "(", ")", ";", "}" ]
Sets the new center of the map in pixel coordinates. @param center the new center of the map in pixel coordinates
[ "Sets", "the", "new", "center", "of", "the", "map", "in", "pixel", "coordinates", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L558-L631
143,860
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.calculateZoomFrom
public void calculateZoomFrom(Set<GeoPosition> positions) { // u.p("calculating a zoom based on: "); // u.p(positions); if (positions.size() < 2) { return; } int zoom = getZoom(); Rectangle2D rect = generateBoundingRect(positions, zoom); // Rectangle2D viewport = map.getViewportBounds(); int count = 0; while (!getViewportBounds().contains(rect)) { // u.p("not contained"); Point2D centr = new Point2D.Double(rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2); GeoPosition px = getTileFactory().pixelToGeo(centr, zoom); // u.p("new geo = " + px); setCenterPosition(px); count++; if (count > 30) break; if (getViewportBounds().contains(rect)) { // u.p("did it finally"); break; } zoom = zoom + 1; if (zoom > 15) //TODO: use maxZoom of the tfInfo { break; } setZoom(zoom); rect = generateBoundingRect(positions, zoom); } }
java
public void calculateZoomFrom(Set<GeoPosition> positions) { // u.p("calculating a zoom based on: "); // u.p(positions); if (positions.size() < 2) { return; } int zoom = getZoom(); Rectangle2D rect = generateBoundingRect(positions, zoom); // Rectangle2D viewport = map.getViewportBounds(); int count = 0; while (!getViewportBounds().contains(rect)) { // u.p("not contained"); Point2D centr = new Point2D.Double(rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2); GeoPosition px = getTileFactory().pixelToGeo(centr, zoom); // u.p("new geo = " + px); setCenterPosition(px); count++; if (count > 30) break; if (getViewportBounds().contains(rect)) { // u.p("did it finally"); break; } zoom = zoom + 1; if (zoom > 15) //TODO: use maxZoom of the tfInfo { break; } setZoom(zoom); rect = generateBoundingRect(positions, zoom); } }
[ "public", "void", "calculateZoomFrom", "(", "Set", "<", "GeoPosition", ">", "positions", ")", "{", "// u.p(\"calculating a zoom based on: \");\r", "// u.p(positions);\r", "if", "(", "positions", ".", "size", "(", ")", "<", "2", ")", "{", "return", ";", "}", "int", "zoom", "=", "getZoom", "(", ")", ";", "Rectangle2D", "rect", "=", "generateBoundingRect", "(", "positions", ",", "zoom", ")", ";", "// Rectangle2D viewport = map.getViewportBounds();\r", "int", "count", "=", "0", ";", "while", "(", "!", "getViewportBounds", "(", ")", ".", "contains", "(", "rect", ")", ")", "{", "// u.p(\"not contained\");\r", "Point2D", "centr", "=", "new", "Point2D", ".", "Double", "(", "rect", ".", "getX", "(", ")", "+", "rect", ".", "getWidth", "(", ")", "/", "2", ",", "rect", ".", "getY", "(", ")", "+", "rect", ".", "getHeight", "(", ")", "/", "2", ")", ";", "GeoPosition", "px", "=", "getTileFactory", "(", ")", ".", "pixelToGeo", "(", "centr", ",", "zoom", ")", ";", "// u.p(\"new geo = \" + px);\r", "setCenterPosition", "(", "px", ")", ";", "count", "++", ";", "if", "(", "count", ">", "30", ")", "break", ";", "if", "(", "getViewportBounds", "(", ")", ".", "contains", "(", "rect", ")", ")", "{", "// u.p(\"did it finally\");\r", "break", ";", "}", "zoom", "=", "zoom", "+", "1", ";", "if", "(", "zoom", ">", "15", ")", "//TODO: use maxZoom of the tfInfo\r", "{", "break", ";", "}", "setZoom", "(", "zoom", ")", ";", "rect", "=", "generateBoundingRect", "(", "positions", ",", "zoom", ")", ";", "}", "}" ]
Calculates a zoom level so that all points in the specified set will be visible on screen. This is useful if you have a bunch of points in an area like a city and you want to zoom out so that the entire city and it's points are visible without panning. @param positions A set of GeoPositions to calculate the new zoom from
[ "Calculates", "a", "zoom", "level", "so", "that", "all", "points", "in", "the", "specified", "set", "will", "be", "visible", "on", "screen", ".", "This", "is", "useful", "if", "you", "have", "a", "bunch", "of", "points", "in", "an", "area", "like", "a", "city", "and", "you", "want", "to", "zoom", "out", "so", "that", "the", "entire", "city", "and", "it", "s", "points", "are", "visible", "without", "panning", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L639-L676
143,861
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.zoomToBestFit
public void zoomToBestFit(Set<GeoPosition> positions, double maxFraction) { if (positions.isEmpty()) return; if (maxFraction <= 0 || maxFraction > 1) throw new IllegalArgumentException("maxFraction must be between 0 and 1"); TileFactory tileFactory = getTileFactory(); TileFactoryInfo info = tileFactory.getInfo(); if(info == null) return; // set to central position initially GeoPosition centre = computeGeoCenter(positions); setCenterPosition(centre); if (positions.size() == 1) return; // repeatedly zoom in until we find the first zoom level where either the width or height // of the points takes up more than the max fraction of the viewport // start with zoomed out at maximum int bestZoom = info.getMaximumZoomLevel(); Rectangle2D viewport = getViewportBounds(); Rectangle2D bounds = generateBoundingRect(positions, bestZoom); // is this zoom still OK? while (bestZoom >= info.getMinimumZoomLevel() && bounds.getWidth() < viewport.getWidth() * maxFraction && bounds.getHeight() < viewport.getHeight() * maxFraction) { bestZoom--; bounds = generateBoundingRect(positions, bestZoom); } setZoom(bestZoom + 1); }
java
public void zoomToBestFit(Set<GeoPosition> positions, double maxFraction) { if (positions.isEmpty()) return; if (maxFraction <= 0 || maxFraction > 1) throw new IllegalArgumentException("maxFraction must be between 0 and 1"); TileFactory tileFactory = getTileFactory(); TileFactoryInfo info = tileFactory.getInfo(); if(info == null) return; // set to central position initially GeoPosition centre = computeGeoCenter(positions); setCenterPosition(centre); if (positions.size() == 1) return; // repeatedly zoom in until we find the first zoom level where either the width or height // of the points takes up more than the max fraction of the viewport // start with zoomed out at maximum int bestZoom = info.getMaximumZoomLevel(); Rectangle2D viewport = getViewportBounds(); Rectangle2D bounds = generateBoundingRect(positions, bestZoom); // is this zoom still OK? while (bestZoom >= info.getMinimumZoomLevel() && bounds.getWidth() < viewport.getWidth() * maxFraction && bounds.getHeight() < viewport.getHeight() * maxFraction) { bestZoom--; bounds = generateBoundingRect(positions, bestZoom); } setZoom(bestZoom + 1); }
[ "public", "void", "zoomToBestFit", "(", "Set", "<", "GeoPosition", ">", "positions", ",", "double", "maxFraction", ")", "{", "if", "(", "positions", ".", "isEmpty", "(", ")", ")", "return", ";", "if", "(", "maxFraction", "<=", "0", "||", "maxFraction", ">", "1", ")", "throw", "new", "IllegalArgumentException", "(", "\"maxFraction must be between 0 and 1\"", ")", ";", "TileFactory", "tileFactory", "=", "getTileFactory", "(", ")", ";", "TileFactoryInfo", "info", "=", "tileFactory", ".", "getInfo", "(", ")", ";", "if", "(", "info", "==", "null", ")", "return", ";", "// set to central position initially\r", "GeoPosition", "centre", "=", "computeGeoCenter", "(", "positions", ")", ";", "setCenterPosition", "(", "centre", ")", ";", "if", "(", "positions", ".", "size", "(", ")", "==", "1", ")", "return", ";", "// repeatedly zoom in until we find the first zoom level where either the width or height\r", "// of the points takes up more than the max fraction of the viewport\r", "// start with zoomed out at maximum\r", "int", "bestZoom", "=", "info", ".", "getMaximumZoomLevel", "(", ")", ";", "Rectangle2D", "viewport", "=", "getViewportBounds", "(", ")", ";", "Rectangle2D", "bounds", "=", "generateBoundingRect", "(", "positions", ",", "bestZoom", ")", ";", "// is this zoom still OK?\r", "while", "(", "bestZoom", ">=", "info", ".", "getMinimumZoomLevel", "(", ")", "&&", "bounds", ".", "getWidth", "(", ")", "<", "viewport", ".", "getWidth", "(", ")", "*", "maxFraction", "&&", "bounds", ".", "getHeight", "(", ")", "<", "viewport", ".", "getHeight", "(", ")", "*", "maxFraction", ")", "{", "bestZoom", "--", ";", "bounds", "=", "generateBoundingRect", "(", "positions", ",", "bestZoom", ")", ";", "}", "setZoom", "(", "bestZoom", "+", "1", ")", ";", "}" ]
Zoom and center the map to a best fit around the input GeoPositions. Best fit is defined as the most zoomed-in possible view where both the width and height of a bounding box around the positions take up no more than maxFraction of the viewport width or height respectively. @param positions A set of GeoPositions to calculate the new zoom from @param maxFraction the maximum fraction of the viewport that should be covered
[ "Zoom", "and", "center", "the", "map", "to", "a", "best", "fit", "around", "the", "input", "GeoPositions", ".", "Best", "fit", "is", "defined", "as", "the", "most", "zoomed", "-", "in", "possible", "view", "where", "both", "the", "width", "and", "height", "of", "a", "bounding", "box", "around", "the", "positions", "take", "up", "no", "more", "than", "maxFraction", "of", "the", "viewport", "width", "or", "height", "respectively", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L686-L727
143,862
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java
JXMapViewer.convertPointToGeoPosition
public GeoPosition convertPointToGeoPosition(Point2D pt) { // convert from local to world bitmap Rectangle bounds = getViewportBounds(); Point2D pt2 = new Point2D.Double(pt.getX() + bounds.getX(), pt.getY() + bounds.getY()); // convert from world bitmap to geo GeoPosition pos = getTileFactory().pixelToGeo(pt2, getZoom()); return pos; }
java
public GeoPosition convertPointToGeoPosition(Point2D pt) { // convert from local to world bitmap Rectangle bounds = getViewportBounds(); Point2D pt2 = new Point2D.Double(pt.getX() + bounds.getX(), pt.getY() + bounds.getY()); // convert from world bitmap to geo GeoPosition pos = getTileFactory().pixelToGeo(pt2, getZoom()); return pos; }
[ "public", "GeoPosition", "convertPointToGeoPosition", "(", "Point2D", "pt", ")", "{", "// convert from local to world bitmap\r", "Rectangle", "bounds", "=", "getViewportBounds", "(", ")", ";", "Point2D", "pt2", "=", "new", "Point2D", ".", "Double", "(", "pt", ".", "getX", "(", ")", "+", "bounds", ".", "getX", "(", ")", ",", "pt", ".", "getY", "(", ")", "+", "bounds", ".", "getY", "(", ")", ")", ";", "// convert from world bitmap to geo\r", "GeoPosition", "pos", "=", "getTileFactory", "(", ")", ".", "pixelToGeo", "(", "pt2", ",", "getZoom", "(", ")", ")", ";", "return", "pos", ";", "}" ]
Converts the specified Point2D in the JXMapViewer's local coordinate space to a GeoPosition on the map. This method is especially useful for determining the GeoPosition under the mouse cursor. @param pt a point in the local coordinate space of the map @return the point converted to a GeoPosition
[ "Converts", "the", "specified", "Point2D", "in", "the", "JXMapViewer", "s", "local", "coordinate", "space", "to", "a", "GeoPosition", "on", "the", "map", ".", "This", "method", "is", "especially", "useful", "for", "determining", "the", "GeoPosition", "under", "the", "mouse", "cursor", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapViewer.java#L857-L866
143,863
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/TileCache.java
TileCache.put
public void put(URI uri, byte[] bimg, BufferedImage img) { synchronized (bytemap) { while (bytesize > 1000 * 1000 * 50) { URI olduri = bytemapAccessQueue.removeFirst(); byte[] oldbimg = bytemap.remove(olduri); bytesize -= oldbimg.length; log("removed 1 img from byte cache"); } bytemap.put(uri, bimg); bytesize += bimg.length; bytemapAccessQueue.addLast(uri); } addToImageCache(uri, img); }
java
public void put(URI uri, byte[] bimg, BufferedImage img) { synchronized (bytemap) { while (bytesize > 1000 * 1000 * 50) { URI olduri = bytemapAccessQueue.removeFirst(); byte[] oldbimg = bytemap.remove(olduri); bytesize -= oldbimg.length; log("removed 1 img from byte cache"); } bytemap.put(uri, bimg); bytesize += bimg.length; bytemapAccessQueue.addLast(uri); } addToImageCache(uri, img); }
[ "public", "void", "put", "(", "URI", "uri", ",", "byte", "[", "]", "bimg", ",", "BufferedImage", "img", ")", "{", "synchronized", "(", "bytemap", ")", "{", "while", "(", "bytesize", ">", "1000", "*", "1000", "*", "50", ")", "{", "URI", "olduri", "=", "bytemapAccessQueue", ".", "removeFirst", "(", ")", ";", "byte", "[", "]", "oldbimg", "=", "bytemap", ".", "remove", "(", "olduri", ")", ";", "bytesize", "-=", "oldbimg", ".", "length", ";", "log", "(", "\"removed 1 img from byte cache\"", ")", ";", "}", "bytemap", ".", "put", "(", "uri", ",", "bimg", ")", ";", "bytesize", "+=", "bimg", ".", "length", ";", "bytemapAccessQueue", ".", "addLast", "(", "uri", ")", ";", "}", "addToImageCache", "(", "uri", ",", "img", ")", ";", "}" ]
Put a tile image into the cache. This puts both a buffered image and array of bytes that make up the compressed image. @param uri URI of image that is being stored in the cache @param bimg bytes of the compressed image, ie: the image file that was loaded over the network @param img image to store in the cache
[ "Put", "a", "tile", "image", "into", "the", "cache", ".", "This", "puts", "both", "a", "buffered", "image", "and", "array", "of", "bytes", "that", "make", "up", "the", "compressed", "image", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/TileCache.java#L54-L71
143,864
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/AbstractTileFactory.java
AbstractTileFactory.getService
protected synchronized ExecutorService getService() { if (service == null) { // System.out.println("creating an executor service with a threadpool of size " + threadPoolSize); service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() { private int count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, "tile-pool-" + count++); t.setPriority(Thread.MIN_PRIORITY); t.setDaemon(true); return t; } }); } return service; }
java
protected synchronized ExecutorService getService() { if (service == null) { // System.out.println("creating an executor service with a threadpool of size " + threadPoolSize); service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() { private int count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, "tile-pool-" + count++); t.setPriority(Thread.MIN_PRIORITY); t.setDaemon(true); return t; } }); } return service; }
[ "protected", "synchronized", "ExecutorService", "getService", "(", ")", "{", "if", "(", "service", "==", "null", ")", "{", "// System.out.println(\"creating an executor service with a threadpool of size \" + threadPoolSize);", "service", "=", "Executors", ".", "newFixedThreadPool", "(", "threadPoolSize", ",", "new", "ThreadFactory", "(", ")", "{", "private", "int", "count", "=", "0", ";", "@", "Override", "public", "Thread", "newThread", "(", "Runnable", "r", ")", "{", "Thread", "t", "=", "new", "Thread", "(", "r", ",", "\"tile-pool-\"", "+", "count", "++", ")", ";", "t", ".", "setPriority", "(", "Thread", ".", "MIN_PRIORITY", ")", ";", "t", ".", "setDaemon", "(", "true", ")", ";", "return", "t", ";", "}", "}", ")", ";", "}", "return", "service", ";", "}" ]
Subclasses may override this method to provide their own executor services. This method will be called each time a tile needs to be loaded. Implementations should cache the ExecutorService when possible. @return ExecutorService to load tiles with
[ "Subclasses", "may", "override", "this", "method", "to", "provide", "their", "own", "executor", "services", ".", "This", "method", "will", "be", "called", "each", "time", "a", "tile", "needs", "to", "be", "loaded", ".", "Implementations", "should", "cache", "the", "ExecutorService", "when", "possible", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/AbstractTileFactory.java#L196-L216
143,865
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/AbstractTileFactory.java
AbstractTileFactory.setUserAgent
public void setUserAgent(String userAgent) { if (userAgent == null || userAgent.isEmpty()) { throw new IllegalArgumentException("User agent can't be null or empty."); } this.userAgent = userAgent; }
java
public void setUserAgent(String userAgent) { if (userAgent == null || userAgent.isEmpty()) { throw new IllegalArgumentException("User agent can't be null or empty."); } this.userAgent = userAgent; }
[ "public", "void", "setUserAgent", "(", "String", "userAgent", ")", "{", "if", "(", "userAgent", "==", "null", "||", "userAgent", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"User agent can't be null or empty.\"", ")", ";", "}", "this", ".", "userAgent", "=", "userAgent", ";", "}" ]
Set the User agent that will be used when making a tile request. Some tile server usage policies requires application to identify itself, so please make sure that it is set properly. @param userAgent User agent to be used.
[ "Set", "the", "User", "agent", "that", "will", "be", "used", "when", "making", "a", "tile", "request", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/AbstractTileFactory.java#L252-L258
143,866
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/AbstractTileFactory.java
AbstractTileFactory.promote
public synchronized void promote(Tile tile) { if (tileQueue.contains(tile)) { try { tileQueue.remove(tile); tile.setPriority(Tile.Priority.High); tileQueue.put(tile); } catch (Exception ex) { ex.printStackTrace(); } } }
java
public synchronized void promote(Tile tile) { if (tileQueue.contains(tile)) { try { tileQueue.remove(tile); tile.setPriority(Tile.Priority.High); tileQueue.put(tile); } catch (Exception ex) { ex.printStackTrace(); } } }
[ "public", "synchronized", "void", "promote", "(", "Tile", "tile", ")", "{", "if", "(", "tileQueue", ".", "contains", "(", "tile", ")", ")", "{", "try", "{", "tileQueue", ".", "remove", "(", "tile", ")", ";", "tile", ".", "setPriority", "(", "Tile", ".", "Priority", ".", "High", ")", ";", "tileQueue", ".", "put", "(", "tile", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "ex", ".", "printStackTrace", "(", ")", ";", "}", "}", "}" ]
Increase the priority of this tile so it will be loaded sooner. @param tile the tile
[ "Increase", "the", "priority", "of", "this", "tile", "so", "it", "will", "be", "loaded", "sooner", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/AbstractTileFactory.java#L296-L311
143,867
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java
AbstractPainter.getFilters
public final BufferedImageOp[] getFilters() { BufferedImageOp[] results = new BufferedImageOp[filters.length]; System.arraycopy(filters, 0, results, 0, results.length); return results; }
java
public final BufferedImageOp[] getFilters() { BufferedImageOp[] results = new BufferedImageOp[filters.length]; System.arraycopy(filters, 0, results, 0, results.length); return results; }
[ "public", "final", "BufferedImageOp", "[", "]", "getFilters", "(", ")", "{", "BufferedImageOp", "[", "]", "results", "=", "new", "BufferedImageOp", "[", "filters", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "filters", ",", "0", ",", "results", ",", "0", ",", "results", ".", "length", ")", ";", "return", "results", ";", "}" ]
A defensive copy of the Effects to apply to the results of the AbstractPainter's painting operation. The array may be empty but it will never be null. @return the array of filters applied to this painter
[ "A", "defensive", "copy", "of", "the", "Effects", "to", "apply", "to", "the", "results", "of", "the", "AbstractPainter", "s", "painting", "operation", ".", "The", "array", "may", "be", "empty", "but", "it", "will", "never", "be", "null", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java#L127-L131
143,868
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java
AbstractPainter.setAntialiasing
public void setAntialiasing(boolean value) { boolean old = isAntialiasing(); antialiasing = value; if (old != value) setDirty(true); firePropertyChange("antialiasing", old, isAntialiasing()); }
java
public void setAntialiasing(boolean value) { boolean old = isAntialiasing(); antialiasing = value; if (old != value) setDirty(true); firePropertyChange("antialiasing", old, isAntialiasing()); }
[ "public", "void", "setAntialiasing", "(", "boolean", "value", ")", "{", "boolean", "old", "=", "isAntialiasing", "(", ")", ";", "antialiasing", "=", "value", ";", "if", "(", "old", "!=", "value", ")", "setDirty", "(", "true", ")", ";", "firePropertyChange", "(", "\"antialiasing\"", ",", "old", ",", "isAntialiasing", "(", ")", ")", ";", "}" ]
Sets the antialiasing setting. This is a bound property. @param value the new antialiasing setting
[ "Sets", "the", "antialiasing", "setting", ".", "This", "is", "a", "bound", "property", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java#L163-L168
143,869
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java
AbstractPainter.setInterpolation
public void setInterpolation(Interpolation value) { Object old = getInterpolation(); this.interpolation = value == null ? Interpolation.NearestNeighbor : value; if (old != value) setDirty(true); firePropertyChange("interpolation", old, getInterpolation()); }
java
public void setInterpolation(Interpolation value) { Object old = getInterpolation(); this.interpolation = value == null ? Interpolation.NearestNeighbor : value; if (old != value) setDirty(true); firePropertyChange("interpolation", old, getInterpolation()); }
[ "public", "void", "setInterpolation", "(", "Interpolation", "value", ")", "{", "Object", "old", "=", "getInterpolation", "(", ")", ";", "this", ".", "interpolation", "=", "value", "==", "null", "?", "Interpolation", ".", "NearestNeighbor", ":", "value", ";", "if", "(", "old", "!=", "value", ")", "setDirty", "(", "true", ")", ";", "firePropertyChange", "(", "\"interpolation\"", ",", "old", ",", "getInterpolation", "(", ")", ")", ";", "}" ]
Sets a new value for the interpolation setting. This setting determines if interpolation should be used when drawing scaled images. @see java.awt.RenderingHints.KEY_INTERPOLATION. @param value the new interpolation setting
[ "Sets", "a", "new", "value", "for", "the", "interpolation", "setting", ".", "This", "setting", "determines", "if", "interpolation", "should", "be", "used", "when", "drawing", "scaled", "images", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java#L184-L189
143,870
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java
AbstractPainter.setDirty
protected void setDirty(boolean d) { boolean old = isDirty(); this.dirty = d; firePropertyChange("dirty", old, isDirty()); if (isDirty()) { clearCache(); } }
java
protected void setDirty(boolean d) { boolean old = isDirty(); this.dirty = d; firePropertyChange("dirty", old, isDirty()); if (isDirty()) { clearCache(); } }
[ "protected", "void", "setDirty", "(", "boolean", "d", ")", "{", "boolean", "old", "=", "isDirty", "(", ")", ";", "this", ".", "dirty", "=", "d", ";", "firePropertyChange", "(", "\"dirty\"", ",", "old", ",", "isDirty", "(", ")", ")", ";", "if", "(", "isDirty", "(", ")", ")", "{", "clearCache", "(", ")", ";", "}", "}" ]
Sets the dirty bit. If true, then the painter is considered dirty, and the cache will be cleared. This property is bound. @param d whether this <code>Painter</code> is dirty.
[ "Sets", "the", "dirty", "bit", ".", "If", "true", "then", "the", "painter", "is", "considered", "dirty", "and", "the", "cache", "will", "be", "cleared", ".", "This", "property", "is", "bound", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/AbstractPainter.java#L308-L315
143,871
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java
CompoundPainter.addPainter
public void addPainter(Painter<T> painter) { Collection<Painter<T>> old = new ArrayList<Painter<T>>(getPainters()); this.painters.add(painter); if (painter instanceof AbstractPainter) { ((AbstractPainter<?>) painter).addPropertyChangeListener(handler); } setDirty(true); firePropertyChange("painters", old, getPainters()); }
java
public void addPainter(Painter<T> painter) { Collection<Painter<T>> old = new ArrayList<Painter<T>>(getPainters()); this.painters.add(painter); if (painter instanceof AbstractPainter) { ((AbstractPainter<?>) painter).addPropertyChangeListener(handler); } setDirty(true); firePropertyChange("painters", old, getPainters()); }
[ "public", "void", "addPainter", "(", "Painter", "<", "T", ">", "painter", ")", "{", "Collection", "<", "Painter", "<", "T", ">>", "old", "=", "new", "ArrayList", "<", "Painter", "<", "T", ">", ">", "(", "getPainters", "(", ")", ")", ";", "this", ".", "painters", ".", "add", "(", "painter", ")", ";", "if", "(", "painter", "instanceof", "AbstractPainter", ")", "{", "(", "(", "AbstractPainter", "<", "?", ">", ")", "painter", ")", ".", "addPropertyChangeListener", "(", "handler", ")", ";", "}", "setDirty", "(", "true", ")", ";", "firePropertyChange", "(", "\"painters\"", ",", "old", ",", "getPainters", "(", ")", ")", ";", "}" ]
Adds a painter to the queue of painters @param painter the painter that is added
[ "Adds", "a", "painter", "to", "the", "queue", "of", "painters" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java#L211-L224
143,872
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java
CompoundPainter.removePainter
public void removePainter(Painter<T> painter) { Collection<Painter<T>> old = new ArrayList<Painter<T>>(getPainters()); this.painters.remove(painter); if (painter instanceof AbstractPainter) { ((AbstractPainter<?>) painter).removePropertyChangeListener(handler); } setDirty(true); firePropertyChange("painters", old, getPainters()); }
java
public void removePainter(Painter<T> painter) { Collection<Painter<T>> old = new ArrayList<Painter<T>>(getPainters()); this.painters.remove(painter); if (painter instanceof AbstractPainter) { ((AbstractPainter<?>) painter).removePropertyChangeListener(handler); } setDirty(true); firePropertyChange("painters", old, getPainters()); }
[ "public", "void", "removePainter", "(", "Painter", "<", "T", ">", "painter", ")", "{", "Collection", "<", "Painter", "<", "T", ">>", "old", "=", "new", "ArrayList", "<", "Painter", "<", "T", ">", ">", "(", "getPainters", "(", ")", ")", ";", "this", ".", "painters", ".", "remove", "(", "painter", ")", ";", "if", "(", "painter", "instanceof", "AbstractPainter", ")", "{", "(", "(", "AbstractPainter", "<", "?", ">", ")", "painter", ")", ".", "removePropertyChangeListener", "(", "handler", ")", ";", "}", "setDirty", "(", "true", ")", ";", "firePropertyChange", "(", "\"painters\"", ",", "old", ",", "getPainters", "(", ")", ")", ";", "}" ]
Removes a painter from the queue of painters @param painter the painter that is added
[ "Removes", "a", "painter", "from", "the", "queue", "of", "painters" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java#L230-L243
143,873
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java
CompoundPainter.setClipPreserved
public void setClipPreserved(boolean shouldRestoreState) { boolean oldShouldRestoreState = isClipPreserved(); this.clipPreserved = shouldRestoreState; setDirty(true); firePropertyChange("clipPreserved", oldShouldRestoreState, shouldRestoreState); }
java
public void setClipPreserved(boolean shouldRestoreState) { boolean oldShouldRestoreState = isClipPreserved(); this.clipPreserved = shouldRestoreState; setDirty(true); firePropertyChange("clipPreserved", oldShouldRestoreState, shouldRestoreState); }
[ "public", "void", "setClipPreserved", "(", "boolean", "shouldRestoreState", ")", "{", "boolean", "oldShouldRestoreState", "=", "isClipPreserved", "(", ")", ";", "this", ".", "clipPreserved", "=", "shouldRestoreState", ";", "setDirty", "(", "true", ")", ";", "firePropertyChange", "(", "\"clipPreserved\"", ",", "oldShouldRestoreState", ",", "shouldRestoreState", ")", ";", "}" ]
Sets if the clip should be preserved. Normally the clip will be reset between each painter. Setting clipPreserved to true can be used to let one painter mask other painters that come after it. @param shouldRestoreState new value of the clipPreserved property @see #isClipPreserved()
[ "Sets", "if", "the", "clip", "should", "be", "preserved", ".", "Normally", "the", "clip", "will", "be", "reset", "between", "each", "painter", ".", "Setting", "clipPreserved", "to", "true", "can", "be", "used", "to", "let", "one", "painter", "mask", "other", "painters", "that", "come", "after", "it", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java#L276-L282
143,874
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java
CompoundPainter.setTransform
public void setTransform(AffineTransform transform) { AffineTransform old = getTransform(); this.transform = transform; setDirty(true); firePropertyChange("transform", old, transform); }
java
public void setTransform(AffineTransform transform) { AffineTransform old = getTransform(); this.transform = transform; setDirty(true); firePropertyChange("transform", old, transform); }
[ "public", "void", "setTransform", "(", "AffineTransform", "transform", ")", "{", "AffineTransform", "old", "=", "getTransform", "(", ")", ";", "this", ".", "transform", "=", "transform", ";", "setDirty", "(", "true", ")", ";", "firePropertyChange", "(", "\"transform\"", ",", "old", ",", "transform", ")", ";", "}" ]
Set a transform to be applied to all painters contained in this CompoundPainter @param transform a new AffineTransform
[ "Set", "a", "transform", "to", "be", "applied", "to", "all", "painters", "contained", "in", "this", "CompoundPainter" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/painter/CompoundPainter.java#L297-L303
143,875
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/empty/EmptyTileFactory.java
EmptyTileFactory.getTile
@Override public Tile getTile(int x, int y, int zoom) { return new Tile(x, y, zoom) { @Override public synchronized boolean isLoaded() { return true; } @Override public BufferedImage getImage() { return emptyTile; } }; }
java
@Override public Tile getTile(int x, int y, int zoom) { return new Tile(x, y, zoom) { @Override public synchronized boolean isLoaded() { return true; } @Override public BufferedImage getImage() { return emptyTile; } }; }
[ "@", "Override", "public", "Tile", "getTile", "(", "int", "x", ",", "int", "y", ",", "int", "zoom", ")", "{", "return", "new", "Tile", "(", "x", ",", "y", ",", "zoom", ")", "{", "@", "Override", "public", "synchronized", "boolean", "isLoaded", "(", ")", "{", "return", "true", ";", "}", "@", "Override", "public", "BufferedImage", "getImage", "(", ")", "{", "return", "emptyTile", ";", "}", "}", ";", "}" ]
Gets an instance of an empty tile for the given tile position and zoom on the world map. @param x The tile's x position on the world map. @param y The tile's y position on the world map. @param zoom The current zoom level.
[ "Gets", "an", "instance", "of", "an", "empty", "tile", "for", "the", "given", "tile", "position", "and", "zoom", "on", "the", "world", "map", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/empty/EmptyTileFactory.java#L67-L85
143,876
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/LocalResponseCache.java
LocalResponseCache.installResponseCache
@Deprecated public static void installResponseCache(String baseURL, File cacheDir, boolean checkForUpdates) { ResponseCache.setDefault(new LocalResponseCache(baseURL, cacheDir, checkForUpdates)); }
java
@Deprecated public static void installResponseCache(String baseURL, File cacheDir, boolean checkForUpdates) { ResponseCache.setDefault(new LocalResponseCache(baseURL, cacheDir, checkForUpdates)); }
[ "@", "Deprecated", "public", "static", "void", "installResponseCache", "(", "String", "baseURL", ",", "File", "cacheDir", ",", "boolean", "checkForUpdates", ")", "{", "ResponseCache", ".", "setDefault", "(", "new", "LocalResponseCache", "(", "baseURL", ",", "cacheDir", ",", "checkForUpdates", ")", ")", ";", "}" ]
Sets this cache as default response cache @param baseURL the URL, the caching should be restricted to or <code>null</code> for none @param cacheDir the cache directory @param checkForUpdates true if the URL is queried for newer versions of a file first @deprecated Use {@link TileFactory#setLocalCache(LocalCache)} instead
[ "Sets", "this", "cache", "as", "default", "response", "cache" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/LocalResponseCache.java#L55-L59
143,877
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java
JXMapKit.setZoom
public void setZoom(int zoom) { zoomChanging = true; mainMap.setZoom(zoom); miniMap.setZoom(mainMap.getZoom() + 4); if (sliderReversed) { zoomSlider.setValue(zoomSlider.getMaximum() - zoom); } else { zoomSlider.setValue(zoom); } zoomChanging = false; }
java
public void setZoom(int zoom) { zoomChanging = true; mainMap.setZoom(zoom); miniMap.setZoom(mainMap.getZoom() + 4); if (sliderReversed) { zoomSlider.setValue(zoomSlider.getMaximum() - zoom); } else { zoomSlider.setValue(zoom); } zoomChanging = false; }
[ "public", "void", "setZoom", "(", "int", "zoom", ")", "{", "zoomChanging", "=", "true", ";", "mainMap", ".", "setZoom", "(", "zoom", ")", ";", "miniMap", ".", "setZoom", "(", "mainMap", ".", "getZoom", "(", ")", "+", "4", ")", ";", "if", "(", "sliderReversed", ")", "{", "zoomSlider", ".", "setValue", "(", "zoomSlider", ".", "getMaximum", "(", ")", "-", "zoom", ")", ";", "}", "else", "{", "zoomSlider", ".", "setValue", "(", "zoom", ")", ";", "}", "zoomChanging", "=", "false", ";", "}" ]
Set the current zoomlevel for the main map. The minimap will be updated accordingly @param zoom the new zoom level
[ "Set", "the", "current", "zoomlevel", "for", "the", "main", "map", ".", "The", "minimap", "will", "be", "updated", "accordingly" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java#L233-L247
143,878
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java
JXMapKit.getZoomOutAction
public Action getZoomOutAction() { Action act = new AbstractAction() { /** * */ private static final long serialVersionUID = 5525706163434375107L; @Override public void actionPerformed(ActionEvent e) { setZoom(mainMap.getZoom() - 1); } }; act.putValue(Action.NAME, "-"); return act; }
java
public Action getZoomOutAction() { Action act = new AbstractAction() { /** * */ private static final long serialVersionUID = 5525706163434375107L; @Override public void actionPerformed(ActionEvent e) { setZoom(mainMap.getZoom() - 1); } }; act.putValue(Action.NAME, "-"); return act; }
[ "public", "Action", "getZoomOutAction", "(", ")", "{", "Action", "act", "=", "new", "AbstractAction", "(", ")", "{", "/**\r\n *\r\n */", "private", "static", "final", "long", "serialVersionUID", "=", "5525706163434375107L", ";", "@", "Override", "public", "void", "actionPerformed", "(", "ActionEvent", "e", ")", "{", "setZoom", "(", "mainMap", ".", "getZoom", "(", ")", "-", "1", ")", ";", "}", "}", ";", "act", ".", "putValue", "(", "Action", ".", "NAME", ",", "\"-\"", ")", ";", "return", "act", ";", "}" ]
Returns an action which can be attached to buttons or menu items to make the map zoom out @return a preconfigured Zoom Out action
[ "Returns", "an", "action", "which", "can", "be", "attached", "to", "buttons", "or", "menu", "items", "to", "make", "the", "map", "zoom", "out" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java#L253-L270
143,879
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java
JXMapKit.setMiniMapVisible
public void setMiniMapVisible(boolean miniMapVisible) { boolean old = this.isMiniMapVisible(); this.miniMapVisible = miniMapVisible; miniMap.setVisible(miniMapVisible); firePropertyChange("miniMapVisible", old, this.isMiniMapVisible()); }
java
public void setMiniMapVisible(boolean miniMapVisible) { boolean old = this.isMiniMapVisible(); this.miniMapVisible = miniMapVisible; miniMap.setVisible(miniMapVisible); firePropertyChange("miniMapVisible", old, this.isMiniMapVisible()); }
[ "public", "void", "setMiniMapVisible", "(", "boolean", "miniMapVisible", ")", "{", "boolean", "old", "=", "this", ".", "isMiniMapVisible", "(", ")", ";", "this", ".", "miniMapVisible", "=", "miniMapVisible", ";", "miniMap", ".", "setVisible", "(", "miniMapVisible", ")", ";", "firePropertyChange", "(", "\"miniMapVisible\"", ",", "old", ",", "this", ".", "isMiniMapVisible", "(", ")", ")", ";", "}" ]
Sets if the mini-map should be visible @param miniMapVisible a new value for the miniMap property
[ "Sets", "if", "the", "mini", "-", "map", "should", "be", "visible" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java#L447-L453
143,880
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java
JXMapKit.setZoomSliderVisible
public void setZoomSliderVisible(boolean zoomSliderVisible) { boolean old = this.isZoomSliderVisible(); this.zoomSliderVisible = zoomSliderVisible; zoomSlider.setVisible(zoomSliderVisible); firePropertyChange("zoomSliderVisible", old, this.isZoomSliderVisible()); }
java
public void setZoomSliderVisible(boolean zoomSliderVisible) { boolean old = this.isZoomSliderVisible(); this.zoomSliderVisible = zoomSliderVisible; zoomSlider.setVisible(zoomSliderVisible); firePropertyChange("zoomSliderVisible", old, this.isZoomSliderVisible()); }
[ "public", "void", "setZoomSliderVisible", "(", "boolean", "zoomSliderVisible", ")", "{", "boolean", "old", "=", "this", ".", "isZoomSliderVisible", "(", ")", ";", "this", ".", "zoomSliderVisible", "=", "zoomSliderVisible", ";", "zoomSlider", ".", "setVisible", "(", "zoomSliderVisible", ")", ";", "firePropertyChange", "(", "\"zoomSliderVisible\"", ",", "old", ",", "this", ".", "isZoomSliderVisible", "(", ")", ")", ";", "}" ]
Sets if the zoom slider should be visible @param zoomSliderVisible the new value of the zoomSliderVisible property
[ "Sets", "if", "the", "zoom", "slider", "should", "be", "visible" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java#L468-L474
143,881
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java
JXMapKit.setZoomButtonsVisible
public void setZoomButtonsVisible(boolean zoomButtonsVisible) { boolean old = this.isZoomButtonsVisible(); this.zoomButtonsVisible = zoomButtonsVisible; zoomInButton.setVisible(zoomButtonsVisible); zoomOutButton.setVisible(zoomButtonsVisible); firePropertyChange("zoomButtonsVisible", old, this.isZoomButtonsVisible()); }
java
public void setZoomButtonsVisible(boolean zoomButtonsVisible) { boolean old = this.isZoomButtonsVisible(); this.zoomButtonsVisible = zoomButtonsVisible; zoomInButton.setVisible(zoomButtonsVisible); zoomOutButton.setVisible(zoomButtonsVisible); firePropertyChange("zoomButtonsVisible", old, this.isZoomButtonsVisible()); }
[ "public", "void", "setZoomButtonsVisible", "(", "boolean", "zoomButtonsVisible", ")", "{", "boolean", "old", "=", "this", ".", "isZoomButtonsVisible", "(", ")", ";", "this", ".", "zoomButtonsVisible", "=", "zoomButtonsVisible", ";", "zoomInButton", ".", "setVisible", "(", "zoomButtonsVisible", ")", ";", "zoomOutButton", ".", "setVisible", "(", "zoomButtonsVisible", ")", ";", "firePropertyChange", "(", "\"zoomButtonsVisible\"", ",", "old", ",", "this", ".", "isZoomButtonsVisible", "(", ")", ")", ";", "}" ]
Sets if the zoom buttons should be visible. This ia bound property. Changes can be listened for using a PropertyChaneListener @param zoomButtonsVisible new value of the zoomButtonsVisible property
[ "Sets", "if", "the", "zoom", "buttons", "should", "be", "visible", ".", "This", "ia", "bound", "property", ".", "Changes", "can", "be", "listened", "for", "using", "a", "PropertyChaneListener" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java#L491-L498
143,882
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java
JXMapKit.setTileFactory
public void setTileFactory(TileFactory fact) { mainMap.setTileFactory(fact); mainMap.setZoom(fact.getInfo().getDefaultZoomLevel()); mainMap.setCenterPosition(new GeoPosition(0, 0)); miniMap.setTileFactory(fact); miniMap.setZoom(fact.getInfo().getDefaultZoomLevel() + 3); miniMap.setCenterPosition(new GeoPosition(0, 0)); zoomSlider.setMinimum(fact.getInfo().getMinimumZoomLevel()); zoomSlider.setMaximum(fact.getInfo().getMaximumZoomLevel()); }
java
public void setTileFactory(TileFactory fact) { mainMap.setTileFactory(fact); mainMap.setZoom(fact.getInfo().getDefaultZoomLevel()); mainMap.setCenterPosition(new GeoPosition(0, 0)); miniMap.setTileFactory(fact); miniMap.setZoom(fact.getInfo().getDefaultZoomLevel() + 3); miniMap.setCenterPosition(new GeoPosition(0, 0)); zoomSlider.setMinimum(fact.getInfo().getMinimumZoomLevel()); zoomSlider.setMaximum(fact.getInfo().getMaximumZoomLevel()); }
[ "public", "void", "setTileFactory", "(", "TileFactory", "fact", ")", "{", "mainMap", ".", "setTileFactory", "(", "fact", ")", ";", "mainMap", ".", "setZoom", "(", "fact", ".", "getInfo", "(", ")", ".", "getDefaultZoomLevel", "(", ")", ")", ";", "mainMap", ".", "setCenterPosition", "(", "new", "GeoPosition", "(", "0", ",", "0", ")", ")", ";", "miniMap", ".", "setTileFactory", "(", "fact", ")", ";", "miniMap", ".", "setZoom", "(", "fact", ".", "getInfo", "(", ")", ".", "getDefaultZoomLevel", "(", ")", "+", "3", ")", ";", "miniMap", ".", "setCenterPosition", "(", "new", "GeoPosition", "(", "0", ",", "0", ")", ")", ";", "zoomSlider", ".", "setMinimum", "(", "fact", ".", "getInfo", "(", ")", ".", "getMinimumZoomLevel", "(", ")", ")", ";", "zoomSlider", ".", "setMaximum", "(", "fact", ".", "getInfo", "(", ")", ".", "getMaximumZoomLevel", "(", ")", ")", ";", "}" ]
Sets the tile factory for both embedded JXMapViewer components. Calling this method will also reset the center and zoom levels of both maps, as well as the bounds of the zoom slider. @param fact the new TileFactory
[ "Sets", "the", "tile", "factory", "for", "both", "embedded", "JXMapViewer", "components", ".", "Calling", "this", "method", "will", "also", "reset", "the", "center", "and", "zoom", "levels", "of", "both", "maps", "as", "well", "as", "the", "bounds", "of", "the", "zoom", "slider", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/JXMapKit.java#L505-L515
143,883
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/cache/FileBasedLocalCache.java
FileBasedLocalCache.getLocalFile
public File getLocalFile(URL remoteUri) { StringBuilder sb = new StringBuilder(); String host = remoteUri.getHost(); String query = remoteUri.getQuery(); String path = remoteUri.getPath(); if (host != null) { sb.append(host); } if (path != null) { sb.append(path); } if (query != null) { sb.append('?'); sb.append(query); } String name; final int maxLen = 250; if (sb.length() < maxLen) { name = sb.toString(); } else { name = sb.substring(0, maxLen); } name = name.replace('?', '$'); name = name.replace('*', '$'); name = name.replace(':', '$'); name = name.replace('<', '$'); name = name.replace('>', '$'); name = name.replace('"', '$'); File f = new File(cacheDir, name); return f; }
java
public File getLocalFile(URL remoteUri) { StringBuilder sb = new StringBuilder(); String host = remoteUri.getHost(); String query = remoteUri.getQuery(); String path = remoteUri.getPath(); if (host != null) { sb.append(host); } if (path != null) { sb.append(path); } if (query != null) { sb.append('?'); sb.append(query); } String name; final int maxLen = 250; if (sb.length() < maxLen) { name = sb.toString(); } else { name = sb.substring(0, maxLen); } name = name.replace('?', '$'); name = name.replace('*', '$'); name = name.replace(':', '$'); name = name.replace('<', '$'); name = name.replace('>', '$'); name = name.replace('"', '$'); File f = new File(cacheDir, name); return f; }
[ "public", "File", "getLocalFile", "(", "URL", "remoteUri", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "String", "host", "=", "remoteUri", ".", "getHost", "(", ")", ";", "String", "query", "=", "remoteUri", ".", "getQuery", "(", ")", ";", "String", "path", "=", "remoteUri", ".", "getPath", "(", ")", ";", "if", "(", "host", "!=", "null", ")", "{", "sb", ".", "append", "(", "host", ")", ";", "}", "if", "(", "path", "!=", "null", ")", "{", "sb", ".", "append", "(", "path", ")", ";", "}", "if", "(", "query", "!=", "null", ")", "{", "sb", ".", "append", "(", "'", "'", ")", ";", "sb", ".", "append", "(", "query", ")", ";", "}", "String", "name", ";", "final", "int", "maxLen", "=", "250", ";", "if", "(", "sb", ".", "length", "(", ")", "<", "maxLen", ")", "{", "name", "=", "sb", ".", "toString", "(", ")", ";", "}", "else", "{", "name", "=", "sb", ".", "substring", "(", "0", ",", "maxLen", ")", ";", "}", "name", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "name", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "name", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "name", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "name", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "name", "=", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "File", "f", "=", "new", "File", "(", "cacheDir", ",", "name", ")", ";", "return", "f", ";", "}" ]
Returns the local File corresponding to the given remote URI. @param remoteUri the remote URI @return the corresponding local file
[ "Returns", "the", "local", "File", "corresponding", "to", "the", "given", "remote", "URI", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/cache/FileBasedLocalCache.java#L78-L123
143,884
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/DefaultWaypoint.java
DefaultWaypoint.setPosition
public void setPosition(GeoPosition coordinate) { GeoPosition old = getPosition(); this.position = coordinate; firePropertyChange("position", old, getPosition()); }
java
public void setPosition(GeoPosition coordinate) { GeoPosition old = getPosition(); this.position = coordinate; firePropertyChange("position", old, getPosition()); }
[ "public", "void", "setPosition", "(", "GeoPosition", "coordinate", ")", "{", "GeoPosition", "old", "=", "getPosition", "(", ")", ";", "this", ".", "position", "=", "coordinate", ";", "firePropertyChange", "(", "\"position\"", ",", "old", ",", "getPosition", "(", ")", ")", ";", "}" ]
Set a new GeoPosition for this Waypoint @param coordinate a new position
[ "Set", "a", "new", "GeoPosition", "for", "this", "Waypoint" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/DefaultWaypoint.java#L56-L61
143,885
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/wms/WMSService.java
WMSService.toWMSURL
public String toWMSURL(int x, int y, int zoom, int tileSize) { String format = "image/jpeg"; String styles = ""; String srs = "EPSG:4326"; int ts = tileSize; int circumference = widthOfWorldInPixels(zoom, tileSize); double radius = circumference / (2 * Math.PI); double ulx = MercatorUtils.xToLong(x * ts, radius); double uly = MercatorUtils.yToLat(y * ts, radius); double lrx = MercatorUtils.xToLong((x + 1) * ts, radius); double lry = MercatorUtils.yToLat((y + 1) * ts, radius); String bbox = ulx + "," + uly + "," + lrx + "," + lry; String url = getBaseUrl() + "version=1.1.1&request=" + "GetMap&Layers=" + layer + "&format=" + format + "&BBOX=" + bbox + "&width=" + ts + "&height=" + ts + "&SRS=" + srs + "&Styles=" + styles + // "&transparent=TRUE"+ ""; return url; }
java
public String toWMSURL(int x, int y, int zoom, int tileSize) { String format = "image/jpeg"; String styles = ""; String srs = "EPSG:4326"; int ts = tileSize; int circumference = widthOfWorldInPixels(zoom, tileSize); double radius = circumference / (2 * Math.PI); double ulx = MercatorUtils.xToLong(x * ts, radius); double uly = MercatorUtils.yToLat(y * ts, radius); double lrx = MercatorUtils.xToLong((x + 1) * ts, radius); double lry = MercatorUtils.yToLat((y + 1) * ts, radius); String bbox = ulx + "," + uly + "," + lrx + "," + lry; String url = getBaseUrl() + "version=1.1.1&request=" + "GetMap&Layers=" + layer + "&format=" + format + "&BBOX=" + bbox + "&width=" + ts + "&height=" + ts + "&SRS=" + srs + "&Styles=" + styles + // "&transparent=TRUE"+ ""; return url; }
[ "public", "String", "toWMSURL", "(", "int", "x", ",", "int", "y", ",", "int", "zoom", ",", "int", "tileSize", ")", "{", "String", "format", "=", "\"image/jpeg\"", ";", "String", "styles", "=", "\"\"", ";", "String", "srs", "=", "\"EPSG:4326\"", ";", "int", "ts", "=", "tileSize", ";", "int", "circumference", "=", "widthOfWorldInPixels", "(", "zoom", ",", "tileSize", ")", ";", "double", "radius", "=", "circumference", "/", "(", "2", "*", "Math", ".", "PI", ")", ";", "double", "ulx", "=", "MercatorUtils", ".", "xToLong", "(", "x", "*", "ts", ",", "radius", ")", ";", "double", "uly", "=", "MercatorUtils", ".", "yToLat", "(", "y", "*", "ts", ",", "radius", ")", ";", "double", "lrx", "=", "MercatorUtils", ".", "xToLong", "(", "(", "x", "+", "1", ")", "*", "ts", ",", "radius", ")", ";", "double", "lry", "=", "MercatorUtils", ".", "yToLat", "(", "(", "y", "+", "1", ")", "*", "ts", ",", "radius", ")", ";", "String", "bbox", "=", "ulx", "+", "\",\"", "+", "uly", "+", "\",\"", "+", "lrx", "+", "\",\"", "+", "lry", ";", "String", "url", "=", "getBaseUrl", "(", ")", "+", "\"version=1.1.1&request=\"", "+", "\"GetMap&Layers=\"", "+", "layer", "+", "\"&format=\"", "+", "format", "+", "\"&BBOX=\"", "+", "bbox", "+", "\"&width=\"", "+", "ts", "+", "\"&height=\"", "+", "ts", "+", "\"&SRS=\"", "+", "srs", "+", "\"&Styles=\"", "+", "styles", "+", "// \"&transparent=TRUE\"+", "\"\"", ";", "return", "url", ";", "}" ]
Convertes to a WMS URL @param x the x coordinate @param y the y coordinate @param zoom the zomm factor @param tileSize the tile size @return a URL request string
[ "Convertes", "to", "a", "WMS", "URL" ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/wms/WMSService.java#L53-L71
143,886
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/util/GraphicsUtilities.java
GraphicsUtilities.convertToBufferedImage
public static BufferedImage convertToBufferedImage(Image img) { BufferedImage buff = createCompatibleTranslucentImage( img.getWidth(null), img.getHeight(null)); Graphics2D g2 = buff.createGraphics(); try { g2.drawImage(img, 0, 0, null); } finally { g2.dispose(); } return buff; }
java
public static BufferedImage convertToBufferedImage(Image img) { BufferedImage buff = createCompatibleTranslucentImage( img.getWidth(null), img.getHeight(null)); Graphics2D g2 = buff.createGraphics(); try { g2.drawImage(img, 0, 0, null); } finally { g2.dispose(); } return buff; }
[ "public", "static", "BufferedImage", "convertToBufferedImage", "(", "Image", "img", ")", "{", "BufferedImage", "buff", "=", "createCompatibleTranslucentImage", "(", "img", ".", "getWidth", "(", "null", ")", ",", "img", ".", "getHeight", "(", "null", ")", ")", ";", "Graphics2D", "g2", "=", "buff", ".", "createGraphics", "(", ")", ";", "try", "{", "g2", ".", "drawImage", "(", "img", ",", "0", ",", "0", ",", "null", ")", ";", "}", "finally", "{", "g2", ".", "dispose", "(", ")", ";", "}", "return", "buff", ";", "}" ]
Converts the specified image into a compatible buffered image. @param img the image to convert @return a compatible buffered image of the input
[ "Converts", "the", "specified", "image", "into", "a", "compatible", "buffered", "image", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/util/GraphicsUtilities.java#L116-L128
143,887
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/util/GraphicsUtilities.java
GraphicsUtilities.clear
public static void clear(Image img) { Graphics g = img.getGraphics(); try { if (g instanceof Graphics2D) { ((Graphics2D) g).setComposite(AlphaComposite.Clear); } else { g.setColor(new Color(0, 0, 0, 0)); } g.fillRect(0, 0, img.getWidth(null), img.getHeight(null)); } finally { g.dispose(); } }
java
public static void clear(Image img) { Graphics g = img.getGraphics(); try { if (g instanceof Graphics2D) { ((Graphics2D) g).setComposite(AlphaComposite.Clear); } else { g.setColor(new Color(0, 0, 0, 0)); } g.fillRect(0, 0, img.getWidth(null), img.getHeight(null)); } finally { g.dispose(); } }
[ "public", "static", "void", "clear", "(", "Image", "img", ")", "{", "Graphics", "g", "=", "img", ".", "getGraphics", "(", ")", ";", "try", "{", "if", "(", "g", "instanceof", "Graphics2D", ")", "{", "(", "(", "Graphics2D", ")", "g", ")", ".", "setComposite", "(", "AlphaComposite", ".", "Clear", ")", ";", "}", "else", "{", "g", ".", "setColor", "(", "new", "Color", "(", "0", ",", "0", ",", "0", ",", "0", ")", ")", ";", "}", "g", ".", "fillRect", "(", "0", ",", "0", ",", "img", ".", "getWidth", "(", "null", ")", ",", "img", ".", "getHeight", "(", "null", ")", ")", ";", "}", "finally", "{", "g", ".", "dispose", "(", ")", ";", "}", "}" ]
Clears the data from the image. @param img the image to erase
[ "Clears", "the", "data", "from", "the", "image", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/util/GraphicsUtilities.java#L757-L771
143,888
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/util/GraphicsUtilities.java
GraphicsUtilities.tileStretchPaint
public static void tileStretchPaint(Graphics g, JComponent comp, BufferedImage img, Insets ins) { int left = ins.left; int right = ins.right; int top = ins.top; int bottom = ins.bottom; // top g.drawImage(img, 0,0,left,top, 0,0,left,top, null); g.drawImage(img, left, 0, comp.getWidth() - right, top, left, 0, img.getWidth() - right, top, null); g.drawImage(img, comp.getWidth() - right, 0, comp.getWidth(), top, img.getWidth() - right, 0, img.getWidth(), top, null); // middle g.drawImage(img, 0, top, left, comp.getHeight()-bottom, 0, top, left, img.getHeight()-bottom, null); g.drawImage(img, left, top, comp.getWidth()-right, comp.getHeight()-bottom, left, top, img.getWidth()-right, img.getHeight()-bottom, null); g.drawImage(img, comp.getWidth()-right, top, comp.getWidth(), comp.getHeight()-bottom, img.getWidth()-right, top, img.getWidth(), img.getHeight()-bottom, null); // bottom g.drawImage(img, 0,comp.getHeight()-bottom, left, comp.getHeight(), 0,img.getHeight()-bottom, left,img.getHeight(), null); g.drawImage(img, left, comp.getHeight()-bottom, comp.getWidth()-right, comp.getHeight(), left, img.getHeight()-bottom, img.getWidth()-right, img.getHeight(), null); g.drawImage(img, comp.getWidth()-right, comp.getHeight()-bottom, comp.getWidth(), comp.getHeight(), img.getWidth()-right, img.getHeight()-bottom, img.getWidth(), img.getHeight(), null); }
java
public static void tileStretchPaint(Graphics g, JComponent comp, BufferedImage img, Insets ins) { int left = ins.left; int right = ins.right; int top = ins.top; int bottom = ins.bottom; // top g.drawImage(img, 0,0,left,top, 0,0,left,top, null); g.drawImage(img, left, 0, comp.getWidth() - right, top, left, 0, img.getWidth() - right, top, null); g.drawImage(img, comp.getWidth() - right, 0, comp.getWidth(), top, img.getWidth() - right, 0, img.getWidth(), top, null); // middle g.drawImage(img, 0, top, left, comp.getHeight()-bottom, 0, top, left, img.getHeight()-bottom, null); g.drawImage(img, left, top, comp.getWidth()-right, comp.getHeight()-bottom, left, top, img.getWidth()-right, img.getHeight()-bottom, null); g.drawImage(img, comp.getWidth()-right, top, comp.getWidth(), comp.getHeight()-bottom, img.getWidth()-right, top, img.getWidth(), img.getHeight()-bottom, null); // bottom g.drawImage(img, 0,comp.getHeight()-bottom, left, comp.getHeight(), 0,img.getHeight()-bottom, left,img.getHeight(), null); g.drawImage(img, left, comp.getHeight()-bottom, comp.getWidth()-right, comp.getHeight(), left, img.getHeight()-bottom, img.getWidth()-right, img.getHeight(), null); g.drawImage(img, comp.getWidth()-right, comp.getHeight()-bottom, comp.getWidth(), comp.getHeight(), img.getWidth()-right, img.getHeight()-bottom, img.getWidth(), img.getHeight(), null); }
[ "public", "static", "void", "tileStretchPaint", "(", "Graphics", "g", ",", "JComponent", "comp", ",", "BufferedImage", "img", ",", "Insets", "ins", ")", "{", "int", "left", "=", "ins", ".", "left", ";", "int", "right", "=", "ins", ".", "right", ";", "int", "top", "=", "ins", ".", "top", ";", "int", "bottom", "=", "ins", ".", "bottom", ";", "// top", "g", ".", "drawImage", "(", "img", ",", "0", ",", "0", ",", "left", ",", "top", ",", "0", ",", "0", ",", "left", ",", "top", ",", "null", ")", ";", "g", ".", "drawImage", "(", "img", ",", "left", ",", "0", ",", "comp", ".", "getWidth", "(", ")", "-", "right", ",", "top", ",", "left", ",", "0", ",", "img", ".", "getWidth", "(", ")", "-", "right", ",", "top", ",", "null", ")", ";", "g", ".", "drawImage", "(", "img", ",", "comp", ".", "getWidth", "(", ")", "-", "right", ",", "0", ",", "comp", ".", "getWidth", "(", ")", ",", "top", ",", "img", ".", "getWidth", "(", ")", "-", "right", ",", "0", ",", "img", ".", "getWidth", "(", ")", ",", "top", ",", "null", ")", ";", "// middle", "g", ".", "drawImage", "(", "img", ",", "0", ",", "top", ",", "left", ",", "comp", ".", "getHeight", "(", ")", "-", "bottom", ",", "0", ",", "top", ",", "left", ",", "img", ".", "getHeight", "(", ")", "-", "bottom", ",", "null", ")", ";", "g", ".", "drawImage", "(", "img", ",", "left", ",", "top", ",", "comp", ".", "getWidth", "(", ")", "-", "right", ",", "comp", ".", "getHeight", "(", ")", "-", "bottom", ",", "left", ",", "top", ",", "img", ".", "getWidth", "(", ")", "-", "right", ",", "img", ".", "getHeight", "(", ")", "-", "bottom", ",", "null", ")", ";", "g", ".", "drawImage", "(", "img", ",", "comp", ".", "getWidth", "(", ")", "-", "right", ",", "top", ",", "comp", ".", "getWidth", "(", ")", ",", "comp", ".", "getHeight", "(", ")", "-", "bottom", ",", "img", ".", "getWidth", "(", ")", "-", "right", ",", "top", ",", "img", ".", "getWidth", "(", ")", ",", "img", ".", "getHeight", "(", ")", "-", "bottom", ",", "null", ")", ";", "// bottom", "g", ".", "drawImage", "(", "img", ",", "0", ",", "comp", ".", "getHeight", "(", ")", "-", "bottom", ",", "left", ",", "comp", ".", "getHeight", "(", ")", ",", "0", ",", "img", ".", "getHeight", "(", ")", "-", "bottom", ",", "left", ",", "img", ".", "getHeight", "(", ")", ",", "null", ")", ";", "g", ".", "drawImage", "(", "img", ",", "left", ",", "comp", ".", "getHeight", "(", ")", "-", "bottom", ",", "comp", ".", "getWidth", "(", ")", "-", "right", ",", "comp", ".", "getHeight", "(", ")", ",", "left", ",", "img", ".", "getHeight", "(", ")", "-", "bottom", ",", "img", ".", "getWidth", "(", ")", "-", "right", ",", "img", ".", "getHeight", "(", ")", ",", "null", ")", ";", "g", ".", "drawImage", "(", "img", ",", "comp", ".", "getWidth", "(", ")", "-", "right", ",", "comp", ".", "getHeight", "(", ")", "-", "bottom", ",", "comp", ".", "getWidth", "(", ")", ",", "comp", ".", "getHeight", "(", ")", ",", "img", ".", "getWidth", "(", ")", "-", "right", ",", "img", ".", "getHeight", "(", ")", "-", "bottom", ",", "img", ".", "getWidth", "(", ")", ",", "img", ".", "getHeight", "(", ")", ",", "null", ")", ";", "}" ]
Draws an image on top of a component by doing a 3x3 grid stretch of the image using the specified insets. @param g the graphics object @param comp the component @param img the image @param ins the insets
[ "Draws", "an", "image", "on", "top", "of", "a", "component", "by", "doing", "a", "3x3", "grid", "stretch", "of", "the", "image", "using", "the", "specified", "insets", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/util/GraphicsUtilities.java#L801-L870
143,889
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/input/MapClickListener.java
MapClickListener.mouseClicked
@Override public void mouseClicked(MouseEvent evt) { final boolean left = SwingUtilities.isLeftMouseButton(evt); final boolean singleClick = (evt.getClickCount() == 1); if ((left && singleClick)) { Rectangle bounds = viewer.getViewportBounds(); int x = bounds.x + evt.getX(); int y = bounds.y + evt.getY(); Point pixelCoordinates = new Point(x, y); mapClicked(viewer.getTileFactory().pixelToGeo(pixelCoordinates, viewer.getZoom())); } }
java
@Override public void mouseClicked(MouseEvent evt) { final boolean left = SwingUtilities.isLeftMouseButton(evt); final boolean singleClick = (evt.getClickCount() == 1); if ((left && singleClick)) { Rectangle bounds = viewer.getViewportBounds(); int x = bounds.x + evt.getX(); int y = bounds.y + evt.getY(); Point pixelCoordinates = new Point(x, y); mapClicked(viewer.getTileFactory().pixelToGeo(pixelCoordinates, viewer.getZoom())); } }
[ "@", "Override", "public", "void", "mouseClicked", "(", "MouseEvent", "evt", ")", "{", "final", "boolean", "left", "=", "SwingUtilities", ".", "isLeftMouseButton", "(", "evt", ")", ";", "final", "boolean", "singleClick", "=", "(", "evt", ".", "getClickCount", "(", ")", "==", "1", ")", ";", "if", "(", "(", "left", "&&", "singleClick", ")", ")", "{", "Rectangle", "bounds", "=", "viewer", ".", "getViewportBounds", "(", ")", ";", "int", "x", "=", "bounds", ".", "x", "+", "evt", ".", "getX", "(", ")", ";", "int", "y", "=", "bounds", ".", "y", "+", "evt", ".", "getY", "(", ")", ";", "Point", "pixelCoordinates", "=", "new", "Point", "(", "x", ",", "y", ")", ";", "mapClicked", "(", "viewer", ".", "getTileFactory", "(", ")", ".", "pixelToGeo", "(", "pixelCoordinates", ",", "viewer", ".", "getZoom", "(", ")", ")", ")", ";", "}", "}" ]
Gets called on mouseClicked events, calculates the GeoPosition and fires the mapClicked method that the extending class needs to implement. @param evt the mouse event
[ "Gets", "called", "on", "mouseClicked", "events", "calculates", "the", "GeoPosition", "and", "fires", "the", "mapClicked", "method", "that", "the", "extending", "class", "needs", "to", "implement", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/input/MapClickListener.java#L39-L51
143,890
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/GeoBounds.java
GeoBounds.setRect
private void setRect(double minLat, double minLng, double maxLat, double maxLng) { if (!(minLat < maxLat)) { throw new IllegalArgumentException("GeoBounds is not valid - minLat must be less that maxLat."); } if (!(minLng < maxLng)) { if (minLng > 0 && minLng < 180 && maxLng < 0) { rects = new Rectangle2D[] { // split into two rects e.g. 176.8793 to 180 and -180 to // -175.0104 new Rectangle2D.Double(minLng, minLat, 180 - minLng, maxLat - minLat), new Rectangle2D.Double(-180, minLat, maxLng + 180, maxLat - minLat) }; } else { rects = new Rectangle2D[] { new Rectangle2D.Double(minLng, minLat, maxLng - minLng, maxLat - minLat) }; throw new IllegalArgumentException("GeoBounds is not valid - minLng must be less that maxLng or " + "minLng must be greater than 0 and maxLng must be less than 0."); } } else { rects = new Rectangle2D[] { new Rectangle2D.Double(minLng, minLat, maxLng - minLng, maxLat - minLat) }; } }
java
private void setRect(double minLat, double minLng, double maxLat, double maxLng) { if (!(minLat < maxLat)) { throw new IllegalArgumentException("GeoBounds is not valid - minLat must be less that maxLat."); } if (!(minLng < maxLng)) { if (minLng > 0 && minLng < 180 && maxLng < 0) { rects = new Rectangle2D[] { // split into two rects e.g. 176.8793 to 180 and -180 to // -175.0104 new Rectangle2D.Double(minLng, minLat, 180 - minLng, maxLat - minLat), new Rectangle2D.Double(-180, minLat, maxLng + 180, maxLat - minLat) }; } else { rects = new Rectangle2D[] { new Rectangle2D.Double(minLng, minLat, maxLng - minLng, maxLat - minLat) }; throw new IllegalArgumentException("GeoBounds is not valid - minLng must be less that maxLng or " + "minLng must be greater than 0 and maxLng must be less than 0."); } } else { rects = new Rectangle2D[] { new Rectangle2D.Double(minLng, minLat, maxLng - minLng, maxLat - minLat) }; } }
[ "private", "void", "setRect", "(", "double", "minLat", ",", "double", "minLng", ",", "double", "maxLat", ",", "double", "maxLng", ")", "{", "if", "(", "!", "(", "minLat", "<", "maxLat", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"GeoBounds is not valid - minLat must be less that maxLat.\"", ")", ";", "}", "if", "(", "!", "(", "minLng", "<", "maxLng", ")", ")", "{", "if", "(", "minLng", ">", "0", "&&", "minLng", "<", "180", "&&", "maxLng", "<", "0", ")", "{", "rects", "=", "new", "Rectangle2D", "[", "]", "{", "// split into two rects e.g. 176.8793 to 180 and -180 to", "// -175.0104", "new", "Rectangle2D", ".", "Double", "(", "minLng", ",", "minLat", ",", "180", "-", "minLng", ",", "maxLat", "-", "minLat", ")", ",", "new", "Rectangle2D", ".", "Double", "(", "-", "180", ",", "minLat", ",", "maxLng", "+", "180", ",", "maxLat", "-", "minLat", ")", "}", ";", "}", "else", "{", "rects", "=", "new", "Rectangle2D", "[", "]", "{", "new", "Rectangle2D", ".", "Double", "(", "minLng", ",", "minLat", ",", "maxLng", "-", "minLng", ",", "maxLat", "-", "minLat", ")", "}", ";", "throw", "new", "IllegalArgumentException", "(", "\"GeoBounds is not valid - minLng must be less that maxLng or \"", "+", "\"minLng must be greater than 0 and maxLng must be less than 0.\"", ")", ";", "}", "}", "else", "{", "rects", "=", "new", "Rectangle2D", "[", "]", "{", "new", "Rectangle2D", ".", "Double", "(", "minLng", ",", "minLat", ",", "maxLng", "-", "minLng", ",", "maxLat", "-", "minLat", ")", "}", ";", "}", "}" ]
Sets the internal rectangle representation. @param minLat The minimum latitude. @param minLng The minimum longitude. @param maxLat The maximum latitude. @param maxLng The maximum longitude.
[ "Sets", "the", "internal", "rectangle", "representation", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/GeoBounds.java#L62-L90
143,891
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/GeoBounds.java
GeoBounds.intersects
public boolean intersects(GeoBounds other) { boolean rv = false; for (Rectangle2D r1 : rects) { for (Rectangle2D r2 : other.rects) { rv = r1.intersects(r2); if (rv) { break; } } if (rv) { break; } } return rv; }
java
public boolean intersects(GeoBounds other) { boolean rv = false; for (Rectangle2D r1 : rects) { for (Rectangle2D r2 : other.rects) { rv = r1.intersects(r2); if (rv) { break; } } if (rv) { break; } } return rv; }
[ "public", "boolean", "intersects", "(", "GeoBounds", "other", ")", "{", "boolean", "rv", "=", "false", ";", "for", "(", "Rectangle2D", "r1", ":", "rects", ")", "{", "for", "(", "Rectangle2D", "r2", ":", "other", ".", "rects", ")", "{", "rv", "=", "r1", ".", "intersects", "(", "r2", ")", ";", "if", "(", "rv", ")", "{", "break", ";", "}", "}", "if", "(", "rv", ")", "{", "break", ";", "}", "}", "return", "rv", ";", "}" ]
Determines if this bounds intersects the other bounds. @param other The other bounds to test for intersection with. @return Returns true if bounds intersect.
[ "Determines", "if", "this", "bounds", "intersects", "the", "other", "bounds", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/GeoBounds.java#L97-L117
143,892
msteiger/jxmapviewer2
jxmapviewer2/src/main/java/org/jxmapviewer/viewer/GeoBounds.java
GeoBounds.getSouthEast
public GeoPosition getSouthEast() { Rectangle2D r = rects[0]; if (rects.length > 1) { r = rects[1]; } return new GeoPosition(r.getY(), r.getMaxX()); }
java
public GeoPosition getSouthEast() { Rectangle2D r = rects[0]; if (rects.length > 1) { r = rects[1]; } return new GeoPosition(r.getY(), r.getMaxX()); }
[ "public", "GeoPosition", "getSouthEast", "(", ")", "{", "Rectangle2D", "r", "=", "rects", "[", "0", "]", ";", "if", "(", "rects", ".", "length", ">", "1", ")", "{", "r", "=", "rects", "[", "1", "]", ";", "}", "return", "new", "GeoPosition", "(", "r", ".", "getY", "(", ")", ",", "r", ".", "getMaxX", "(", ")", ")", ";", "}" ]
Gets the south east position. @return Returns the south east position.
[ "Gets", "the", "south", "east", "position", "." ]
82639273b0aac983b6026fb90aa925c0cf596410
https://github.com/msteiger/jxmapviewer2/blob/82639273b0aac983b6026fb90aa925c0cf596410/jxmapviewer2/src/main/java/org/jxmapviewer/viewer/GeoBounds.java#L132-L140
143,893
zhangyingwei/cockroach
cockroach-core/src/main/java/com/zhangyingwei/cockroach/executer/ExecuterManager.java
ExecuterManager.bindListener
public ExecuterManager bindListener(Class<? extends IExecutersListener> listener) throws IllegalAccessException, InstantiationException { if (listener != null) { this.executerListeners.add(listener.newInstance()); } return this; }
java
public ExecuterManager bindListener(Class<? extends IExecutersListener> listener) throws IllegalAccessException, InstantiationException { if (listener != null) { this.executerListeners.add(listener.newInstance()); } return this; }
[ "public", "ExecuterManager", "bindListener", "(", "Class", "<", "?", "extends", "IExecutersListener", ">", "listener", ")", "throws", "IllegalAccessException", ",", "InstantiationException", "{", "if", "(", "listener", "!=", "null", ")", "{", "this", ".", "executerListeners", ".", "add", "(", "listener", ".", "newInstance", "(", ")", ")", ";", "}", "return", "this", ";", "}" ]
bind executer listener @param listener @return
[ "bind", "executer", "listener" ]
a8139dea1b4e3e6ec2451520cb9f7700ff0f704e
https://github.com/zhangyingwei/cockroach/blob/a8139dea1b4e3e6ec2451520cb9f7700ff0f704e/cockroach-core/src/main/java/com/zhangyingwei/cockroach/executer/ExecuterManager.java#L105-L110
143,894
zhangyingwei/cockroach
cockroach-core/src/main/java/com/zhangyingwei/cockroach/common/utils/FileUtils.java
FileUtils.save
public static void save(byte[] bytes,String filePath,String fileName) throws IOException { Path path = Paths.get(filePath, fileName); mkirDirs(path.getParent()); String pathStr = path.toString(); File file = new File(pathStr); write(bytes,file); }
java
public static void save(byte[] bytes,String filePath,String fileName) throws IOException { Path path = Paths.get(filePath, fileName); mkirDirs(path.getParent()); String pathStr = path.toString(); File file = new File(pathStr); write(bytes,file); }
[ "public", "static", "void", "save", "(", "byte", "[", "]", "bytes", ",", "String", "filePath", ",", "String", "fileName", ")", "throws", "IOException", "{", "Path", "path", "=", "Paths", ".", "get", "(", "filePath", ",", "fileName", ")", ";", "mkirDirs", "(", "path", ".", "getParent", "(", ")", ")", ";", "String", "pathStr", "=", "path", ".", "toString", "(", ")", ";", "File", "file", "=", "new", "File", "(", "pathStr", ")", ";", "write", "(", "bytes", ",", "file", ")", ";", "}" ]
save bytes into file @param bytes @param filePath @param fileName @throws IOException
[ "save", "bytes", "into", "file" ]
a8139dea1b4e3e6ec2451520cb9f7700ff0f704e
https://github.com/zhangyingwei/cockroach/blob/a8139dea1b4e3e6ec2451520cb9f7700ff0f704e/cockroach-core/src/main/java/com/zhangyingwei/cockroach/common/utils/FileUtils.java#L28-L34
143,895
zhangyingwei/cockroach
cockroach-core/src/main/java/com/zhangyingwei/cockroach/common/utils/FileUtils.java
FileUtils.write
public static void write(byte[] bytes,File file) throws IOException { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); outputStream.write(bytes); outputStream.close(); }
java
public static void write(byte[] bytes,File file) throws IOException { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); outputStream.write(bytes); outputStream.close(); }
[ "public", "static", "void", "write", "(", "byte", "[", "]", "bytes", ",", "File", "file", ")", "throws", "IOException", "{", "BufferedOutputStream", "outputStream", "=", "new", "BufferedOutputStream", "(", "new", "FileOutputStream", "(", "file", ")", ")", ";", "outputStream", ".", "write", "(", "bytes", ")", ";", "outputStream", ".", "close", "(", ")", ";", "}" ]
wtire bytes into file @param bytes @param file @throws IOException
[ "wtire", "bytes", "into", "file" ]
a8139dea1b4e3e6ec2451520cb9f7700ff0f704e
https://github.com/zhangyingwei/cockroach/blob/a8139dea1b4e3e6ec2451520cb9f7700ff0f704e/cockroach-core/src/main/java/com/zhangyingwei/cockroach/common/utils/FileUtils.java#L52-L56
143,896
DDTH/ddth-commons
ddth-commons-core/src/main/java/com/github/ddth/commons/utils/UnsignedUtils.java
UnsignedUtils.forDigit
public static char forDigit(int digit, int radix) { if (digit >= 0 && digit < radix && radix >= Character.MIN_RADIX && radix <= MAX_RADIX) { return digits[digit]; } return '\u0000'; }
java
public static char forDigit(int digit, int radix) { if (digit >= 0 && digit < radix && radix >= Character.MIN_RADIX && radix <= MAX_RADIX) { return digits[digit]; } return '\u0000'; }
[ "public", "static", "char", "forDigit", "(", "int", "digit", ",", "int", "radix", ")", "{", "if", "(", "digit", ">=", "0", "&&", "digit", "<", "radix", "&&", "radix", ">=", "Character", ".", "MIN_RADIX", "&&", "radix", "<=", "MAX_RADIX", ")", "{", "return", "digits", "[", "digit", "]", ";", "}", "return", "'", "'", ";", "}" ]
Determines the character representation for a specific digit in the specified radix. Note: If the value of radix is not a valid radix, or the value of digit is not a valid digit in the specified radix, the null character ('\u0000') is returned. @param digit @param radix @return
[ "Determines", "the", "character", "representation", "for", "a", "specific", "digit", "in", "the", "specified", "radix", "." ]
734f0e77321d41eeca78a557be9884df9874e46e
https://github.com/DDTH/ddth-commons/blob/734f0e77321d41eeca78a557be9884df9874e46e/ddth-commons-core/src/main/java/com/github/ddth/commons/utils/UnsignedUtils.java#L76-L81
143,897
DDTH/ddth-commons
ddth-commons-core/src/main/java/com/github/ddth/commons/jsonrpc/RequestResponse.java
RequestResponse.setRequestData
public RequestResponse setRequestData(Object requestData) { this.requestData = requestData; requestJson = requestData != null ? (requestData instanceof JsonNode ? (JsonNode) requestData : SerializationUtils.toJson(requestData)) : null; return this; }
java
public RequestResponse setRequestData(Object requestData) { this.requestData = requestData; requestJson = requestData != null ? (requestData instanceof JsonNode ? (JsonNode) requestData : SerializationUtils.toJson(requestData)) : null; return this; }
[ "public", "RequestResponse", "setRequestData", "(", "Object", "requestData", ")", "{", "this", ".", "requestData", "=", "requestData", ";", "requestJson", "=", "requestData", "!=", "null", "?", "(", "requestData", "instanceof", "JsonNode", "?", "(", "JsonNode", ")", "requestData", ":", "SerializationUtils", ".", "toJson", "(", "requestData", ")", ")", ":", "null", ";", "return", "this", ";", "}" ]
HTTP request body. @param requestData @return
[ "HTTP", "request", "body", "." ]
734f0e77321d41eeca78a557be9884df9874e46e
https://github.com/DDTH/ddth-commons/blob/734f0e77321d41eeca78a557be9884df9874e46e/ddth-commons-core/src/main/java/com/github/ddth/commons/jsonrpc/RequestResponse.java#L202-L209
143,898
DDTH/ddth-commons
ddth-commons-core/src/main/java/com/github/ddth/commons/jsonrpc/RequestResponse.java
RequestResponse.setResponseData
public RequestResponse setResponseData(byte[] responseData) { this.responseData = responseData; try { responseJson = responseData != null ? SerializationUtils.readJson(responseData) : null; } catch (Exception e) { responseJson = null; LOGGER.error(e.getMessage(), e); } return this; }
java
public RequestResponse setResponseData(byte[] responseData) { this.responseData = responseData; try { responseJson = responseData != null ? SerializationUtils.readJson(responseData) : null; } catch (Exception e) { responseJson = null; LOGGER.error(e.getMessage(), e); } return this; }
[ "public", "RequestResponse", "setResponseData", "(", "byte", "[", "]", "responseData", ")", "{", "this", ".", "responseData", "=", "responseData", ";", "try", "{", "responseJson", "=", "responseData", "!=", "null", "?", "SerializationUtils", ".", "readJson", "(", "responseData", ")", ":", "null", ";", "}", "catch", "(", "Exception", "e", ")", "{", "responseJson", "=", "null", ";", "LOGGER", ".", "error", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "return", "this", ";", "}" ]
Raw HTTP response data. @param responseData @return
[ "Raw", "HTTP", "response", "data", "." ]
734f0e77321d41eeca78a557be9884df9874e46e
https://github.com/DDTH/ddth-commons/blob/734f0e77321d41eeca78a557be9884df9874e46e/ddth-commons-core/src/main/java/com/github/ddth/commons/jsonrpc/RequestResponse.java#L298-L307
143,899
RestExpress/PluginExpress
metrics/src/main/java/com/strategicgains/restexpress/plugin/metrics/LogOutputFactory.java
LogOutputFactory.create
public String create(Request request, Response response, Long duration) { return createStringBuilder(request, response, duration).toString(); }
java
public String create(Request request, Response response, Long duration) { return createStringBuilder(request, response, duration).toString(); }
[ "public", "String", "create", "(", "Request", "request", ",", "Response", "response", ",", "Long", "duration", ")", "{", "return", "createStringBuilder", "(", "request", ",", "response", ",", "duration", ")", ".", "toString", "(", ")", ";", "}" ]
Creates a string suitable for logging output. @param request a RestExpress Request instance. @param response a RestExpress Response instance. @param duration the duration of the request, in milliseconds. @return a String as described above.
[ "Creates", "a", "string", "suitable", "for", "logging", "output", "." ]
aeb13907c23bf31ef2b2b17ae4c0ca4a6f5bee69
https://github.com/RestExpress/PluginExpress/blob/aeb13907c23bf31ef2b2b17ae4c0ca4a6f5bee69/metrics/src/main/java/com/strategicgains/restexpress/plugin/metrics/LogOutputFactory.java#L116-L119