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,600
Bedework/bw-util
bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/ConfiguredXSLTFilter.java
ConfiguredXSLTFilter.updateConfigInfo
public void updateConfigInfo(final HttpServletRequest request, final XSLTConfig xcfg) throws ServletException { PresentationState ps = getPresentationState(request); if (ps == null) { // Still can't do a thing return; } if (xcfg.nextCfg == null) { xcfg.nextCfg = new XSLTFilterConfigInfo(); } else { xcfg.cfg.updateFrom(xcfg.nextCfg); } xcfg.cfg.setAppRoot(ps.getAppRoot()); xcfg.nextCfg.setAppRoot(ps.getAppRoot()); /** Transfer the state */ if (ps.getNoXSLTSticky()) { xcfg.cfg.setDontFilter(true); xcfg.nextCfg.setDontFilter(true); } else { xcfg.cfg.setDontFilter(ps.getNoXSLT()); ps.setNoXSLT(false); } /* ============== Don't filter ================= */ if (xcfg.cfg.getDontFilter()) { // I think that's enough return; } /* ============== Locale ================= */ Locale l = request.getLocale(); String lang = l.getLanguage(); if ((lang == null) || (lang.length() == 0)) { lang = xcfg.cfg.getDefaultLang(); } String country = l.getCountry(); if ((country == null) || (country.length() == 0)) { country = xcfg.cfg.getDefaultCountry(); } xcfg.cfg.setLocaleInfo(XSLTFilterConfigInfo.makeLocale(lang, country)); /* locale always sticky */ xcfg.nextCfg.setLocaleInfo(XSLTFilterConfigInfo.makeLocale(lang, country)); /* ============== Browser type ================= */ String temp = ps.getBrowserType(); if (temp != null) { xcfg.cfg.setBrowserType(temp); } if (!ps.getBrowserTypeSticky()) { ps.setBrowserType(null); } else { xcfg.nextCfg.setBrowserType(temp); } /* ============== Skin name ================= */ temp = ps.getSkinName(); if (temp != null) { xcfg.cfg.setSkinName(temp); } if (!ps.getSkinNameSticky()) { ps.setSkinName(null); } else { xcfg.nextCfg.setSkinName(temp); } /* ============== Content type ================= */ xcfg.cfg.setContentType(ps.getContentType()); if (!ps.getContentTypeSticky()) { ps.setContentType(null); } else { xcfg.nextCfg.setContentType(ps.getContentType()); } /* ============== Refresh ================= */ xcfg.cfg.setForceReload(ps.getForceXSLTRefresh()); ps.setForceXSLTRefresh(false); /* I don't think we ever want to allow this info.setReloadAlways(ps.getForceXSLTRefreshAlways()); */ }
java
public void updateConfigInfo(final HttpServletRequest request, final XSLTConfig xcfg) throws ServletException { PresentationState ps = getPresentationState(request); if (ps == null) { // Still can't do a thing return; } if (xcfg.nextCfg == null) { xcfg.nextCfg = new XSLTFilterConfigInfo(); } else { xcfg.cfg.updateFrom(xcfg.nextCfg); } xcfg.cfg.setAppRoot(ps.getAppRoot()); xcfg.nextCfg.setAppRoot(ps.getAppRoot()); /** Transfer the state */ if (ps.getNoXSLTSticky()) { xcfg.cfg.setDontFilter(true); xcfg.nextCfg.setDontFilter(true); } else { xcfg.cfg.setDontFilter(ps.getNoXSLT()); ps.setNoXSLT(false); } /* ============== Don't filter ================= */ if (xcfg.cfg.getDontFilter()) { // I think that's enough return; } /* ============== Locale ================= */ Locale l = request.getLocale(); String lang = l.getLanguage(); if ((lang == null) || (lang.length() == 0)) { lang = xcfg.cfg.getDefaultLang(); } String country = l.getCountry(); if ((country == null) || (country.length() == 0)) { country = xcfg.cfg.getDefaultCountry(); } xcfg.cfg.setLocaleInfo(XSLTFilterConfigInfo.makeLocale(lang, country)); /* locale always sticky */ xcfg.nextCfg.setLocaleInfo(XSLTFilterConfigInfo.makeLocale(lang, country)); /* ============== Browser type ================= */ String temp = ps.getBrowserType(); if (temp != null) { xcfg.cfg.setBrowserType(temp); } if (!ps.getBrowserTypeSticky()) { ps.setBrowserType(null); } else { xcfg.nextCfg.setBrowserType(temp); } /* ============== Skin name ================= */ temp = ps.getSkinName(); if (temp != null) { xcfg.cfg.setSkinName(temp); } if (!ps.getSkinNameSticky()) { ps.setSkinName(null); } else { xcfg.nextCfg.setSkinName(temp); } /* ============== Content type ================= */ xcfg.cfg.setContentType(ps.getContentType()); if (!ps.getContentTypeSticky()) { ps.setContentType(null); } else { xcfg.nextCfg.setContentType(ps.getContentType()); } /* ============== Refresh ================= */ xcfg.cfg.setForceReload(ps.getForceXSLTRefresh()); ps.setForceXSLTRefresh(false); /* I don't think we ever want to allow this info.setReloadAlways(ps.getForceXSLTRefreshAlways()); */ }
[ "public", "void", "updateConfigInfo", "(", "final", "HttpServletRequest", "request", ",", "final", "XSLTConfig", "xcfg", ")", "throws", "ServletException", "{", "PresentationState", "ps", "=", "getPresentationState", "(", "request", ")", ";", "if", "(", "ps", "==", "null", ")", "{", "// Still can't do a thing", "return", ";", "}", "if", "(", "xcfg", ".", "nextCfg", "==", "null", ")", "{", "xcfg", ".", "nextCfg", "=", "new", "XSLTFilterConfigInfo", "(", ")", ";", "}", "else", "{", "xcfg", ".", "cfg", ".", "updateFrom", "(", "xcfg", ".", "nextCfg", ")", ";", "}", "xcfg", ".", "cfg", ".", "setAppRoot", "(", "ps", ".", "getAppRoot", "(", ")", ")", ";", "xcfg", ".", "nextCfg", ".", "setAppRoot", "(", "ps", ".", "getAppRoot", "(", ")", ")", ";", "/** Transfer the state */", "if", "(", "ps", ".", "getNoXSLTSticky", "(", ")", ")", "{", "xcfg", ".", "cfg", ".", "setDontFilter", "(", "true", ")", ";", "xcfg", ".", "nextCfg", ".", "setDontFilter", "(", "true", ")", ";", "}", "else", "{", "xcfg", ".", "cfg", ".", "setDontFilter", "(", "ps", ".", "getNoXSLT", "(", ")", ")", ";", "ps", ".", "setNoXSLT", "(", "false", ")", ";", "}", "/* ============== Don't filter ================= */", "if", "(", "xcfg", ".", "cfg", ".", "getDontFilter", "(", ")", ")", "{", "// I think that's enough", "return", ";", "}", "/* ============== Locale ================= */", "Locale", "l", "=", "request", ".", "getLocale", "(", ")", ";", "String", "lang", "=", "l", ".", "getLanguage", "(", ")", ";", "if", "(", "(", "lang", "==", "null", ")", "||", "(", "lang", ".", "length", "(", ")", "==", "0", ")", ")", "{", "lang", "=", "xcfg", ".", "cfg", ".", "getDefaultLang", "(", ")", ";", "}", "String", "country", "=", "l", ".", "getCountry", "(", ")", ";", "if", "(", "(", "country", "==", "null", ")", "||", "(", "country", ".", "length", "(", ")", "==", "0", ")", ")", "{", "country", "=", "xcfg", ".", "cfg", ".", "getDefaultCountry", "(", ")", ";", "}", "xcfg", ".", "cfg", ".", "setLocaleInfo", "(", "XSLTFilterConfigInfo", ".", "makeLocale", "(", "lang", ",", "country", ")", ")", ";", "/* locale always sticky */", "xcfg", ".", "nextCfg", ".", "setLocaleInfo", "(", "XSLTFilterConfigInfo", ".", "makeLocale", "(", "lang", ",", "country", ")", ")", ";", "/* ============== Browser type ================= */", "String", "temp", "=", "ps", ".", "getBrowserType", "(", ")", ";", "if", "(", "temp", "!=", "null", ")", "{", "xcfg", ".", "cfg", ".", "setBrowserType", "(", "temp", ")", ";", "}", "if", "(", "!", "ps", ".", "getBrowserTypeSticky", "(", ")", ")", "{", "ps", ".", "setBrowserType", "(", "null", ")", ";", "}", "else", "{", "xcfg", ".", "nextCfg", ".", "setBrowserType", "(", "temp", ")", ";", "}", "/* ============== Skin name ================= */", "temp", "=", "ps", ".", "getSkinName", "(", ")", ";", "if", "(", "temp", "!=", "null", ")", "{", "xcfg", ".", "cfg", ".", "setSkinName", "(", "temp", ")", ";", "}", "if", "(", "!", "ps", ".", "getSkinNameSticky", "(", ")", ")", "{", "ps", ".", "setSkinName", "(", "null", ")", ";", "}", "else", "{", "xcfg", ".", "nextCfg", ".", "setSkinName", "(", "temp", ")", ";", "}", "/* ============== Content type ================= */", "xcfg", ".", "cfg", ".", "setContentType", "(", "ps", ".", "getContentType", "(", ")", ")", ";", "if", "(", "!", "ps", ".", "getContentTypeSticky", "(", ")", ")", "{", "ps", ".", "setContentType", "(", "null", ")", ";", "}", "else", "{", "xcfg", ".", "nextCfg", ".", "setContentType", "(", "ps", ".", "getContentType", "(", ")", ")", ";", "}", "/* ============== Refresh ================= */", "xcfg", ".", "cfg", ".", "setForceReload", "(", "ps", ".", "getForceXSLTRefresh", "(", ")", ")", ";", "ps", ".", "setForceXSLTRefresh", "(", "false", ")", ";", "/* I don't think we ever want to allow this\n info.setReloadAlways(ps.getForceXSLTRefreshAlways());\n */", "}" ]
This method can be overridden to allow a subclass to set up ready for a transformation. <p>The default action provided here is to locate the PresentatoinState object in the session and use that to configure the filter. @param request Incoming HttpServletRequest object @param xcfg XSLTConfig Our globals. @throws ServletException
[ "This", "method", "can", "be", "overridden", "to", "allow", "a", "subclass", "to", "set", "up", "ready", "for", "a", "transformation", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/ConfiguredXSLTFilter.java#L165-L258
143,601
Bedework/bw-util
bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/ConfiguredXSLTFilter.java
ConfiguredXSLTFilter.getPresentationState
protected PresentationState getPresentationState(HttpServletRequest request) { String attrName = getPresentationAttrName(); if ((attrName == null) || (attrName.equals("NONE"))) { return null; } /* First try the request */ Object o = request.getAttribute(attrName); if (o == null) { HttpSession sess = request.getSession(false); if (sess == null) { return null; } o = sess.getAttribute(attrName); } if (o == null) { return null; } PresentationState ps = (PresentationState)o; if (debug()) { ps.debugDump("ConfiguredXSLTFilter"); } return ps; }
java
protected PresentationState getPresentationState(HttpServletRequest request) { String attrName = getPresentationAttrName(); if ((attrName == null) || (attrName.equals("NONE"))) { return null; } /* First try the request */ Object o = request.getAttribute(attrName); if (o == null) { HttpSession sess = request.getSession(false); if (sess == null) { return null; } o = sess.getAttribute(attrName); } if (o == null) { return null; } PresentationState ps = (PresentationState)o; if (debug()) { ps.debugDump("ConfiguredXSLTFilter"); } return ps; }
[ "protected", "PresentationState", "getPresentationState", "(", "HttpServletRequest", "request", ")", "{", "String", "attrName", "=", "getPresentationAttrName", "(", ")", ";", "if", "(", "(", "attrName", "==", "null", ")", "||", "(", "attrName", ".", "equals", "(", "\"NONE\"", ")", ")", ")", "{", "return", "null", ";", "}", "/* First try the request */", "Object", "o", "=", "request", ".", "getAttribute", "(", "attrName", ")", ";", "if", "(", "o", "==", "null", ")", "{", "HttpSession", "sess", "=", "request", ".", "getSession", "(", "false", ")", ";", "if", "(", "sess", "==", "null", ")", "{", "return", "null", ";", "}", "o", "=", "sess", ".", "getAttribute", "(", "attrName", ")", ";", "}", "if", "(", "o", "==", "null", ")", "{", "return", "null", ";", "}", "PresentationState", "ps", "=", "(", "PresentationState", ")", "o", ";", "if", "(", "debug", "(", ")", ")", "{", "ps", ".", "debugDump", "(", "\"ConfiguredXSLTFilter\"", ")", ";", "}", "return", "ps", ";", "}" ]
Obtain the presentation state from the session. Override if you want different behaviour. @param request @return PresentationState
[ "Obtain", "the", "presentation", "state", "from", "the", "session", ".", "Override", "if", "you", "want", "different", "behaviour", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/ConfiguredXSLTFilter.java#L277-L310
143,602
Bedework/bw-util
bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/ConfiguredXSLTFilter.java
ConfiguredXSLTFilter.tryPath
private boolean tryPath(StringBuilder prefix, String el, boolean dir) { String path = prefix + "/" + el; if (dir && directoryBrowsingDisallowed) { path += "/" + xsltdirMarkerName; } if (debug()) { debug("trypath: " + path); } try { URL u = new URL(path); URLConnection uc = u.openConnection(); if (!(uc instanceof HttpURLConnection)) { return false; } HttpURLConnection huc = (HttpURLConnection)uc; if (huc.getResponseCode() != 200) { return false; } prefix.append("/"); prefix.append(el); return true; } catch (final Throwable t) { if (debug()) { debug("trypath exception: "); error(t); } } return false; }
java
private boolean tryPath(StringBuilder prefix, String el, boolean dir) { String path = prefix + "/" + el; if (dir && directoryBrowsingDisallowed) { path += "/" + xsltdirMarkerName; } if (debug()) { debug("trypath: " + path); } try { URL u = new URL(path); URLConnection uc = u.openConnection(); if (!(uc instanceof HttpURLConnection)) { return false; } HttpURLConnection huc = (HttpURLConnection)uc; if (huc.getResponseCode() != 200) { return false; } prefix.append("/"); prefix.append(el); return true; } catch (final Throwable t) { if (debug()) { debug("trypath exception: "); error(t); } } return false; }
[ "private", "boolean", "tryPath", "(", "StringBuilder", "prefix", ",", "String", "el", ",", "boolean", "dir", ")", "{", "String", "path", "=", "prefix", "+", "\"/\"", "+", "el", ";", "if", "(", "dir", "&&", "directoryBrowsingDisallowed", ")", "{", "path", "+=", "\"/\"", "+", "xsltdirMarkerName", ";", "}", "if", "(", "debug", "(", ")", ")", "{", "debug", "(", "\"trypath: \"", "+", "path", ")", ";", "}", "try", "{", "URL", "u", "=", "new", "URL", "(", "path", ")", ";", "URLConnection", "uc", "=", "u", ".", "openConnection", "(", ")", ";", "if", "(", "!", "(", "uc", "instanceof", "HttpURLConnection", ")", ")", "{", "return", "false", ";", "}", "HttpURLConnection", "huc", "=", "(", "HttpURLConnection", ")", "uc", ";", "if", "(", "huc", ".", "getResponseCode", "(", ")", "!=", "200", ")", "{", "return", "false", ";", "}", "prefix", ".", "append", "(", "\"/\"", ")", ";", "prefix", ".", "append", "(", "el", ")", ";", "return", "true", ";", "}", "catch", "(", "final", "Throwable", "t", ")", "{", "if", "(", "debug", "(", ")", ")", "{", "debug", "(", "\"trypath exception: \"", ")", ";", "error", "(", "t", ")", ";", "}", "}", "return", "false", ";", "}" ]
Try a path and see if it exists. If so append the element @param prefix StringBuilder current path prefix @param el String path element to append @param dir true if el is a directory @return boolean true if path is OK
[ "Try", "a", "path", "and", "see", "if", "it", "exists", ".", "If", "so", "append", "the", "element" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet-filters/src/main/java/org/bedework/util/servlet/filters/ConfiguredXSLTFilter.java#L539-L577
143,603
sebastiangraf/treetank
thesismodules/integrity/src/main/java/org/treetank/bench/BenchUtils.java
BenchUtils.createDatas
public static final DumbData[][] createDatas(final int[] pDatasPerRevision) { final DumbData[][] returnVal = new DumbData[pDatasPerRevision.length][]; for (int i = 0; i < pDatasPerRevision.length; i++) { returnVal[i] = new DumbData[pDatasPerRevision[i]]; for (int j = 0; j < pDatasPerRevision[i]; j++) { returnVal[i][j] = generateOne(); } } return returnVal; }
java
public static final DumbData[][] createDatas(final int[] pDatasPerRevision) { final DumbData[][] returnVal = new DumbData[pDatasPerRevision.length][]; for (int i = 0; i < pDatasPerRevision.length; i++) { returnVal[i] = new DumbData[pDatasPerRevision[i]]; for (int j = 0; j < pDatasPerRevision[i]; j++) { returnVal[i][j] = generateOne(); } } return returnVal; }
[ "public", "static", "final", "DumbData", "[", "]", "[", "]", "createDatas", "(", "final", "int", "[", "]", "pDatasPerRevision", ")", "{", "final", "DumbData", "[", "]", "[", "]", "returnVal", "=", "new", "DumbData", "[", "pDatasPerRevision", ".", "length", "]", "[", "", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pDatasPerRevision", ".", "length", ";", "i", "++", ")", "{", "returnVal", "[", "i", "]", "=", "new", "DumbData", "[", "pDatasPerRevision", "[", "i", "]", "]", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "pDatasPerRevision", "[", "i", "]", ";", "j", "++", ")", "{", "returnVal", "[", "i", "]", "[", "j", "]", "=", "generateOne", "(", ")", ";", "}", "}", "return", "returnVal", ";", "}" ]
Generating new data-elements passed on a given number of datas within a revision @param pDatasPerRevision denote the number of datas within all versions @return a two-dimensional array containing the datas.
[ "Generating", "new", "data", "-", "elements", "passed", "on", "a", "given", "number", "of", "datas", "within", "a", "revision" ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/thesismodules/integrity/src/main/java/org/treetank/bench/BenchUtils.java#L37-L46
143,604
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/serialize/AbsSerializer.java
AbsSerializer.call
public Void call() throws TTException { emitStartDocument(); long[] versionsToUse; // if there are no versions specified, take the last one, of not version==0 if (mVersions.length == 0) { if (mSession.getMostRecentVersion() > 0) { versionsToUse = new long[] { mSession.getMostRecentVersion() }; }// revision 0 = bootstrapped page else { versionsToUse = new long[0]; } } // if there is any negative number specified, take the entire range of versions, otherwise take the // parameter else { // sort the versions first Arrays.sort(mVersions); if (mVersions[0] < 0) { versionsToUse = new long[(int)mSession.getMostRecentVersion() - 1]; for (int i = 0; i < versionsToUse.length; i++) { versionsToUse[i] = i + 1; } }// otherwise take the versions as requested as params else { int index = Arrays.binarySearch(mVersions, 1); versionsToUse = Arrays.copyOfRange(mVersions, index, mVersions.length); } } for (int i = 0; i < versionsToUse.length; i++) { INodeReadTrx rtx = new NodeReadTrx(mSession.beginBucketRtx(versionsToUse[i])); if (versionsToUse == null || mVersions.length > 1) { emitStartManualElement(i); } rtx.moveTo(mNodeKey); final AbsAxis descAxis = new DescendantAxis(rtx, true); // Setup primitives. boolean closeElements = false; long key = rtx.getNode().getDataKey(); // Iterate over all nodes of the subtree including self. while (descAxis.hasNext()) { key = descAxis.next(); ITreeStructData currentStruc = (ITreeStructData)rtx.getNode(); // Emit all pending end elements. if (closeElements) { while (!mStack.empty() && mStack.peek() != currentStruc.getLeftSiblingKey()) { rtx.moveTo(mStack.pop()); emitEndElement(rtx); rtx.moveTo(key); } if (!mStack.empty()) { rtx.moveTo(mStack.pop()); emitEndElement(rtx); } rtx.moveTo(key); closeElements = false; } // Emit node. emitStartElement(rtx); // Push end element to stack if we are a start element with // children. if (currentStruc.getKind() == IConstants.ELEMENT && currentStruc.hasFirstChild()) { mStack.push(rtx.getNode().getDataKey()); } // Remember to emit all pending end elements from stack if // required. if (!currentStruc.hasFirstChild() && !currentStruc.hasRightSibling()) { closeElements = true; } } // Finally emit all pending end elements. while (!mStack.empty()) { rtx.moveTo(mStack.pop()); emitEndElement(rtx); } if (versionsToUse == null || mVersions.length > 1) { emitEndManualElement(i); } } emitEndDocument(); return null; }
java
public Void call() throws TTException { emitStartDocument(); long[] versionsToUse; // if there are no versions specified, take the last one, of not version==0 if (mVersions.length == 0) { if (mSession.getMostRecentVersion() > 0) { versionsToUse = new long[] { mSession.getMostRecentVersion() }; }// revision 0 = bootstrapped page else { versionsToUse = new long[0]; } } // if there is any negative number specified, take the entire range of versions, otherwise take the // parameter else { // sort the versions first Arrays.sort(mVersions); if (mVersions[0] < 0) { versionsToUse = new long[(int)mSession.getMostRecentVersion() - 1]; for (int i = 0; i < versionsToUse.length; i++) { versionsToUse[i] = i + 1; } }// otherwise take the versions as requested as params else { int index = Arrays.binarySearch(mVersions, 1); versionsToUse = Arrays.copyOfRange(mVersions, index, mVersions.length); } } for (int i = 0; i < versionsToUse.length; i++) { INodeReadTrx rtx = new NodeReadTrx(mSession.beginBucketRtx(versionsToUse[i])); if (versionsToUse == null || mVersions.length > 1) { emitStartManualElement(i); } rtx.moveTo(mNodeKey); final AbsAxis descAxis = new DescendantAxis(rtx, true); // Setup primitives. boolean closeElements = false; long key = rtx.getNode().getDataKey(); // Iterate over all nodes of the subtree including self. while (descAxis.hasNext()) { key = descAxis.next(); ITreeStructData currentStruc = (ITreeStructData)rtx.getNode(); // Emit all pending end elements. if (closeElements) { while (!mStack.empty() && mStack.peek() != currentStruc.getLeftSiblingKey()) { rtx.moveTo(mStack.pop()); emitEndElement(rtx); rtx.moveTo(key); } if (!mStack.empty()) { rtx.moveTo(mStack.pop()); emitEndElement(rtx); } rtx.moveTo(key); closeElements = false; } // Emit node. emitStartElement(rtx); // Push end element to stack if we are a start element with // children. if (currentStruc.getKind() == IConstants.ELEMENT && currentStruc.hasFirstChild()) { mStack.push(rtx.getNode().getDataKey()); } // Remember to emit all pending end elements from stack if // required. if (!currentStruc.hasFirstChild() && !currentStruc.hasRightSibling()) { closeElements = true; } } // Finally emit all pending end elements. while (!mStack.empty()) { rtx.moveTo(mStack.pop()); emitEndElement(rtx); } if (versionsToUse == null || mVersions.length > 1) { emitEndManualElement(i); } } emitEndDocument(); return null; }
[ "public", "Void", "call", "(", ")", "throws", "TTException", "{", "emitStartDocument", "(", ")", ";", "long", "[", "]", "versionsToUse", ";", "// if there are no versions specified, take the last one, of not version==0", "if", "(", "mVersions", ".", "length", "==", "0", ")", "{", "if", "(", "mSession", ".", "getMostRecentVersion", "(", ")", ">", "0", ")", "{", "versionsToUse", "=", "new", "long", "[", "]", "{", "mSession", ".", "getMostRecentVersion", "(", ")", "}", ";", "}", "// revision 0 = bootstrapped page", "else", "{", "versionsToUse", "=", "new", "long", "[", "0", "]", ";", "}", "}", "// if there is any negative number specified, take the entire range of versions, otherwise take the", "// parameter", "else", "{", "// sort the versions first", "Arrays", ".", "sort", "(", "mVersions", ")", ";", "if", "(", "mVersions", "[", "0", "]", "<", "0", ")", "{", "versionsToUse", "=", "new", "long", "[", "(", "int", ")", "mSession", ".", "getMostRecentVersion", "(", ")", "-", "1", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "versionsToUse", ".", "length", ";", "i", "++", ")", "{", "versionsToUse", "[", "i", "]", "=", "i", "+", "1", ";", "}", "}", "// otherwise take the versions as requested as params", "else", "{", "int", "index", "=", "Arrays", ".", "binarySearch", "(", "mVersions", ",", "1", ")", ";", "versionsToUse", "=", "Arrays", ".", "copyOfRange", "(", "mVersions", ",", "index", ",", "mVersions", ".", "length", ")", ";", "}", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "versionsToUse", ".", "length", ";", "i", "++", ")", "{", "INodeReadTrx", "rtx", "=", "new", "NodeReadTrx", "(", "mSession", ".", "beginBucketRtx", "(", "versionsToUse", "[", "i", "]", ")", ")", ";", "if", "(", "versionsToUse", "==", "null", "||", "mVersions", ".", "length", ">", "1", ")", "{", "emitStartManualElement", "(", "i", ")", ";", "}", "rtx", ".", "moveTo", "(", "mNodeKey", ")", ";", "final", "AbsAxis", "descAxis", "=", "new", "DescendantAxis", "(", "rtx", ",", "true", ")", ";", "// Setup primitives.", "boolean", "closeElements", "=", "false", ";", "long", "key", "=", "rtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ";", "// Iterate over all nodes of the subtree including self.", "while", "(", "descAxis", ".", "hasNext", "(", ")", ")", "{", "key", "=", "descAxis", ".", "next", "(", ")", ";", "ITreeStructData", "currentStruc", "=", "(", "ITreeStructData", ")", "rtx", ".", "getNode", "(", ")", ";", "// Emit all pending end elements.", "if", "(", "closeElements", ")", "{", "while", "(", "!", "mStack", ".", "empty", "(", ")", "&&", "mStack", ".", "peek", "(", ")", "!=", "currentStruc", ".", "getLeftSiblingKey", "(", ")", ")", "{", "rtx", ".", "moveTo", "(", "mStack", ".", "pop", "(", ")", ")", ";", "emitEndElement", "(", "rtx", ")", ";", "rtx", ".", "moveTo", "(", "key", ")", ";", "}", "if", "(", "!", "mStack", ".", "empty", "(", ")", ")", "{", "rtx", ".", "moveTo", "(", "mStack", ".", "pop", "(", ")", ")", ";", "emitEndElement", "(", "rtx", ")", ";", "}", "rtx", ".", "moveTo", "(", "key", ")", ";", "closeElements", "=", "false", ";", "}", "// Emit node.", "emitStartElement", "(", "rtx", ")", ";", "// Push end element to stack if we are a start element with", "// children.", "if", "(", "currentStruc", ".", "getKind", "(", ")", "==", "IConstants", ".", "ELEMENT", "&&", "currentStruc", ".", "hasFirstChild", "(", ")", ")", "{", "mStack", ".", "push", "(", "rtx", ".", "getNode", "(", ")", ".", "getDataKey", "(", ")", ")", ";", "}", "// Remember to emit all pending end elements from stack if", "// required.", "if", "(", "!", "currentStruc", ".", "hasFirstChild", "(", ")", "&&", "!", "currentStruc", ".", "hasRightSibling", "(", ")", ")", "{", "closeElements", "=", "true", ";", "}", "}", "// Finally emit all pending end elements.", "while", "(", "!", "mStack", ".", "empty", "(", ")", ")", "{", "rtx", ".", "moveTo", "(", "mStack", ".", "pop", "(", ")", ")", ";", "emitEndElement", "(", "rtx", ")", ";", "}", "if", "(", "versionsToUse", "==", "null", "||", "mVersions", ".", "length", ">", "1", ")", "{", "emitEndManualElement", "(", "i", ")", ";", "}", "}", "emitEndDocument", "(", ")", ";", "return", "null", ";", "}" ]
Serialize the storage. @return null. @throws TTException if can't call serailzer
[ "Serialize", "the", "storage", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/serialize/AbsSerializer.java#L100-L198
143,605
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getOneTaggedNode
public static Node getOneTaggedNode(final Node el, final String name) throws SAXException { if (!el.hasChildNodes()) { return null; } final NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node n = children.item(i); if (name.equals(n.getNodeName())) { return n; } } return null; }
java
public static Node getOneTaggedNode(final Node el, final String name) throws SAXException { if (!el.hasChildNodes()) { return null; } final NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node n = children.item(i); if (name.equals(n.getNodeName())) { return n; } } return null; }
[ "public", "static", "Node", "getOneTaggedNode", "(", "final", "Node", "el", ",", "final", "String", "name", ")", "throws", "SAXException", "{", "if", "(", "!", "el", ".", "hasChildNodes", "(", ")", ")", "{", "return", "null", ";", "}", "final", "NodeList", "children", "=", "el", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "children", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "final", "Node", "n", "=", "children", ".", "item", "(", "i", ")", ";", "if", "(", "name", ".", "equals", "(", "n", ".", "getNodeName", "(", ")", ")", ")", "{", "return", "n", ";", "}", "}", "return", "null", ";", "}" ]
Get the single named element. @param el Node @param name String tag name of required node @return Node node value or null @throws SAXException
[ "Get", "the", "single", "named", "element", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L123-L141
143,606
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getOneNodeVal
public static String getOneNodeVal(final Node el, final String name) throws SAXException { /* We expect one child of type text */ if (!el.hasChildNodes()) { return null; } NodeList children = el.getChildNodes(); if (children.getLength() > 1){ throw new SAXException("Multiple property values: " + name); } Node child = children.item(0); return child.getNodeValue(); }
java
public static String getOneNodeVal(final Node el, final String name) throws SAXException { /* We expect one child of type text */ if (!el.hasChildNodes()) { return null; } NodeList children = el.getChildNodes(); if (children.getLength() > 1){ throw new SAXException("Multiple property values: " + name); } Node child = children.item(0); return child.getNodeValue(); }
[ "public", "static", "String", "getOneNodeVal", "(", "final", "Node", "el", ",", "final", "String", "name", ")", "throws", "SAXException", "{", "/* We expect one child of type text */", "if", "(", "!", "el", ".", "hasChildNodes", "(", ")", ")", "{", "return", "null", ";", "}", "NodeList", "children", "=", "el", ".", "getChildNodes", "(", ")", ";", "if", "(", "children", ".", "getLength", "(", ")", ">", "1", ")", "{", "throw", "new", "SAXException", "(", "\"Multiple property values: \"", "+", "name", ")", ";", "}", "Node", "child", "=", "children", ".", "item", "(", "0", ")", ";", "return", "child", ".", "getNodeValue", "(", ")", ";", "}" ]
Get the value of an element. We expect 0 or 1 child nodes. For no child node we return null, for more than one we raise an exception. @param el Node whose value we want @param name String name to make exception messages more readable @return String node value or null @throws SAXException
[ "Get", "the", "value", "of", "an", "element", ".", "We", "expect", "0", "or", "1", "child", "nodes", ".", "For", "no", "child", "node", "we", "return", "null", "for", "more", "than", "one", "we", "raise", "an", "exception", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L152-L167
143,607
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getReqOneNodeVal
public static String getReqOneNodeVal(final Node el, final String name) throws SAXException { String str = getOneNodeVal(el, name); if ((str == null) || (str.length() == 0)) { throw new SAXException("Missing property value: " + name); } return str; }
java
public static String getReqOneNodeVal(final Node el, final String name) throws SAXException { String str = getOneNodeVal(el, name); if ((str == null) || (str.length() == 0)) { throw new SAXException("Missing property value: " + name); } return str; }
[ "public", "static", "String", "getReqOneNodeVal", "(", "final", "Node", "el", ",", "final", "String", "name", ")", "throws", "SAXException", "{", "String", "str", "=", "getOneNodeVal", "(", "el", ",", "name", ")", ";", "if", "(", "(", "str", "==", "null", ")", "||", "(", "str", ".", "length", "(", ")", "==", "0", ")", ")", "{", "throw", "new", "SAXException", "(", "\"Missing property value: \"", "+", "name", ")", ";", "}", "return", "str", ";", "}" ]
Get the value of an element. We expect 1 child node otherwise we raise an exception. @param el Node whose value we want @param name String name to make exception messages more readable @return String node value @throws SAXException
[ "Get", "the", "value", "of", "an", "element", ".", "We", "expect", "1", "child", "node", "otherwise", "we", "raise", "an", "exception", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L189-L198
143,608
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getAttrVal
public static String getAttrVal(final Element el, final String name) throws SAXException { Attr at = el.getAttributeNode(name); if (at == null) { return null; } return at.getValue(); }
java
public static String getAttrVal(final Element el, final String name) throws SAXException { Attr at = el.getAttributeNode(name); if (at == null) { return null; } return at.getValue(); }
[ "public", "static", "String", "getAttrVal", "(", "final", "Element", "el", ",", "final", "String", "name", ")", "throws", "SAXException", "{", "Attr", "at", "=", "el", ".", "getAttributeNode", "(", "name", ")", ";", "if", "(", "at", "==", "null", ")", "{", "return", "null", ";", "}", "return", "at", ".", "getValue", "(", ")", ";", "}" ]
Return the value of the named attribute of the given element. @param el Element @param name String name of desired attribute @return String attribute value or null @throws SAXException
[ "Return", "the", "value", "of", "the", "named", "attribute", "of", "the", "given", "element", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L218-L226
143,609
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getReqAttrVal
public static String getReqAttrVal(final Element el, final String name) throws SAXException { String str = getAttrVal(el, name); if ((str == null) || (str.length() == 0)) { throw new SAXException("Missing attribute value: " + name); } return str; }
java
public static String getReqAttrVal(final Element el, final String name) throws SAXException { String str = getAttrVal(el, name); if ((str == null) || (str.length() == 0)) { throw new SAXException("Missing attribute value: " + name); } return str; }
[ "public", "static", "String", "getReqAttrVal", "(", "final", "Element", "el", ",", "final", "String", "name", ")", "throws", "SAXException", "{", "String", "str", "=", "getAttrVal", "(", "el", ",", "name", ")", ";", "if", "(", "(", "str", "==", "null", ")", "||", "(", "str", ".", "length", "(", ")", "==", "0", ")", ")", "{", "throw", "new", "SAXException", "(", "\"Missing attribute value: \"", "+", "name", ")", ";", "}", "return", "str", ";", "}" ]
Return the required value of the named attribute of the given element. @param el Element @param name String name of desired attribute @return String attribute value @throws SAXException
[ "Return", "the", "required", "value", "of", "the", "named", "attribute", "of", "the", "given", "element", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L235-L244
143,610
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getAttrVal
public static String getAttrVal(final NamedNodeMap nnm, final String name) { Node nmAttr = nnm.getNamedItem(name); if ((nmAttr == null) || (absent(nmAttr.getNodeValue()))) { return null; } return nmAttr.getNodeValue(); }
java
public static String getAttrVal(final NamedNodeMap nnm, final String name) { Node nmAttr = nnm.getNamedItem(name); if ((nmAttr == null) || (absent(nmAttr.getNodeValue()))) { return null; } return nmAttr.getNodeValue(); }
[ "public", "static", "String", "getAttrVal", "(", "final", "NamedNodeMap", "nnm", ",", "final", "String", "name", ")", "{", "Node", "nmAttr", "=", "nnm", ".", "getNamedItem", "(", "name", ")", ";", "if", "(", "(", "nmAttr", "==", "null", ")", "||", "(", "absent", "(", "nmAttr", ".", "getNodeValue", "(", ")", ")", ")", ")", "{", "return", "null", ";", "}", "return", "nmAttr", ".", "getNodeValue", "(", ")", ";", "}" ]
Return the attribute value of the named attribute from the given map. @param nnm NamedNodeMap @param name String name of desired attribute @return String attribute value or null
[ "Return", "the", "attribute", "value", "of", "the", "named", "attribute", "from", "the", "given", "map", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L252-L260
143,611
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getYesNoAttrVal
public static Boolean getYesNoAttrVal(final NamedNodeMap nnm, final String name) throws SAXException { String val = getAttrVal(nnm, name); if (val == null) { return null; } if ((!"yes".equals(val)) && (!"no".equals(val))) { throw new SAXException("Invalid attribute value: " + val); } return new Boolean("yes".equals(val)); }
java
public static Boolean getYesNoAttrVal(final NamedNodeMap nnm, final String name) throws SAXException { String val = getAttrVal(nnm, name); if (val == null) { return null; } if ((!"yes".equals(val)) && (!"no".equals(val))) { throw new SAXException("Invalid attribute value: " + val); } return new Boolean("yes".equals(val)); }
[ "public", "static", "Boolean", "getYesNoAttrVal", "(", "final", "NamedNodeMap", "nnm", ",", "final", "String", "name", ")", "throws", "SAXException", "{", "String", "val", "=", "getAttrVal", "(", "nnm", ",", "name", ")", ";", "if", "(", "val", "==", "null", ")", "{", "return", "null", ";", "}", "if", "(", "(", "!", "\"yes\"", ".", "equals", "(", "val", ")", ")", "&&", "(", "!", "\"no\"", ".", "equals", "(", "val", ")", ")", ")", "{", "throw", "new", "SAXException", "(", "\"Invalid attribute value: \"", "+", "val", ")", ";", "}", "return", "new", "Boolean", "(", "\"yes\"", ".", "equals", "(", "val", ")", ")", ";", "}" ]
The attribute value of the named attribute in the given map must be absent or "yes" or "no". @param nnm NamedNodeMap @param name String name of desired attribute @return Boolean attribute value or null @throws SAXException
[ "The", "attribute", "value", "of", "the", "named", "attribute", "in", "the", "given", "map", "must", "be", "absent", "or", "yes", "or", "no", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L270-L283
143,612
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getElements
public static List<Element> getElements(final Node nd) throws SAXException { final List<Element> al = new ArrayList<>(); NodeList children = nd.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); if (curnode.getNodeType() == Node.TEXT_NODE) { String val = curnode.getNodeValue(); if (val != null) { for (int vi= 0; vi < val.length(); vi++) { if (!Character.isWhitespace(val.charAt(vi))) { throw new SAXException("Non-whitespace text in element body for " + nd.getLocalName() + "\n text=" + val); } } } } else if (curnode.getNodeType() == Node.COMMENT_NODE) { // Ignore } else if (curnode.getNodeType() == Node.ELEMENT_NODE) { al.add((Element)curnode); } else { throw new SAXException("Unexpected child node " + curnode.getLocalName() + " for " + nd.getLocalName()); } } return al; }
java
public static List<Element> getElements(final Node nd) throws SAXException { final List<Element> al = new ArrayList<>(); NodeList children = nd.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); if (curnode.getNodeType() == Node.TEXT_NODE) { String val = curnode.getNodeValue(); if (val != null) { for (int vi= 0; vi < val.length(); vi++) { if (!Character.isWhitespace(val.charAt(vi))) { throw new SAXException("Non-whitespace text in element body for " + nd.getLocalName() + "\n text=" + val); } } } } else if (curnode.getNodeType() == Node.COMMENT_NODE) { // Ignore } else if (curnode.getNodeType() == Node.ELEMENT_NODE) { al.add((Element)curnode); } else { throw new SAXException("Unexpected child node " + curnode.getLocalName() + " for " + nd.getLocalName()); } } return al; }
[ "public", "static", "List", "<", "Element", ">", "getElements", "(", "final", "Node", "nd", ")", "throws", "SAXException", "{", "final", "List", "<", "Element", ">", "al", "=", "new", "ArrayList", "<>", "(", ")", ";", "NodeList", "children", "=", "nd", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "children", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "curnode", "=", "children", ".", "item", "(", "i", ")", ";", "if", "(", "curnode", ".", "getNodeType", "(", ")", "==", "Node", ".", "TEXT_NODE", ")", "{", "String", "val", "=", "curnode", ".", "getNodeValue", "(", ")", ";", "if", "(", "val", "!=", "null", ")", "{", "for", "(", "int", "vi", "=", "0", ";", "vi", "<", "val", ".", "length", "(", ")", ";", "vi", "++", ")", "{", "if", "(", "!", "Character", ".", "isWhitespace", "(", "val", ".", "charAt", "(", "vi", ")", ")", ")", "{", "throw", "new", "SAXException", "(", "\"Non-whitespace text in element body for \"", "+", "nd", ".", "getLocalName", "(", ")", "+", "\"\\n text=\"", "+", "val", ")", ";", "}", "}", "}", "}", "else", "if", "(", "curnode", ".", "getNodeType", "(", ")", "==", "Node", ".", "COMMENT_NODE", ")", "{", "// Ignore", "}", "else", "if", "(", "curnode", ".", "getNodeType", "(", ")", "==", "Node", ".", "ELEMENT_NODE", ")", "{", "al", ".", "add", "(", "(", "Element", ")", "curnode", ")", ";", "}", "else", "{", "throw", "new", "SAXException", "(", "\"Unexpected child node \"", "+", "curnode", ".", "getLocalName", "(", ")", "+", "\" for \"", "+", "nd", ".", "getLocalName", "(", ")", ")", ";", "}", "}", "return", "al", ";", "}" ]
All the children must be elements or white space text nodes. @param nd @return Collection element nodes. Always non-null @throws SAXException
[ "All", "the", "children", "must", "be", "elements", "or", "white", "space", "text", "nodes", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L305-L336
143,613
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.getElementContent
public static String getElementContent(final Element el, final boolean trim) throws SAXException { StringBuilder sb = new StringBuilder(); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); if (curnode.getNodeType() == Node.TEXT_NODE) { sb.append(curnode.getNodeValue()); } else if (curnode.getNodeType() == Node.CDATA_SECTION_NODE) { sb.append(curnode.getNodeValue()); } else if (curnode.getNodeType() == Node.COMMENT_NODE) { // Ignore } else { throw new SAXException("Unexpected child node " + curnode.getLocalName() + " for " + el.getLocalName()); } } if (!trim) { return sb.toString(); } return sb.toString().trim(); }
java
public static String getElementContent(final Element el, final boolean trim) throws SAXException { StringBuilder sb = new StringBuilder(); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); if (curnode.getNodeType() == Node.TEXT_NODE) { sb.append(curnode.getNodeValue()); } else if (curnode.getNodeType() == Node.CDATA_SECTION_NODE) { sb.append(curnode.getNodeValue()); } else if (curnode.getNodeType() == Node.COMMENT_NODE) { // Ignore } else { throw new SAXException("Unexpected child node " + curnode.getLocalName() + " for " + el.getLocalName()); } } if (!trim) { return sb.toString(); } return sb.toString().trim(); }
[ "public", "static", "String", "getElementContent", "(", "final", "Element", "el", ",", "final", "boolean", "trim", ")", "throws", "SAXException", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "NodeList", "children", "=", "el", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "children", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "curnode", "=", "children", ".", "item", "(", "i", ")", ";", "if", "(", "curnode", ".", "getNodeType", "(", ")", "==", "Node", ".", "TEXT_NODE", ")", "{", "sb", ".", "append", "(", "curnode", ".", "getNodeValue", "(", ")", ")", ";", "}", "else", "if", "(", "curnode", ".", "getNodeType", "(", ")", "==", "Node", ".", "CDATA_SECTION_NODE", ")", "{", "sb", ".", "append", "(", "curnode", ".", "getNodeValue", "(", ")", ")", ";", "}", "else", "if", "(", "curnode", ".", "getNodeType", "(", ")", "==", "Node", ".", "COMMENT_NODE", ")", "{", "// Ignore", "}", "else", "{", "throw", "new", "SAXException", "(", "\"Unexpected child node \"", "+", "curnode", ".", "getLocalName", "(", ")", "+", "\" for \"", "+", "el", ".", "getLocalName", "(", ")", ")", ";", "}", "}", "if", "(", "!", "trim", ")", "{", "return", "sb", ".", "toString", "(", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ".", "trim", "(", ")", ";", "}" ]
Return the content for the current element. All leading and trailing whitespace and embedded comments will be removed. <p>This is only intended for an element with no child elements. @param el @param trim true to trim surrounding white-space @return element content @throws SAXException
[ "Return", "the", "content", "for", "the", "current", "element", ".", "All", "leading", "and", "trailing", "whitespace", "and", "embedded", "comments", "will", "be", "removed", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L348-L374
143,614
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.setElementContent
public static void setElementContent(final Node n, final String s) throws SAXException { NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); n.removeChild(curnode); } Document d = n.getOwnerDocument(); final Node textNode = d.createTextNode(s); n.appendChild(textNode); }
java
public static void setElementContent(final Node n, final String s) throws SAXException { NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); n.removeChild(curnode); } Document d = n.getOwnerDocument(); final Node textNode = d.createTextNode(s); n.appendChild(textNode); }
[ "public", "static", "void", "setElementContent", "(", "final", "Node", "n", ",", "final", "String", "s", ")", "throws", "SAXException", "{", "NodeList", "children", "=", "n", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "children", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "curnode", "=", "children", ".", "item", "(", "i", ")", ";", "n", ".", "removeChild", "(", "curnode", ")", ";", "}", "Document", "d", "=", "n", ".", "getOwnerDocument", "(", ")", ";", "final", "Node", "textNode", "=", "d", ".", "createTextNode", "(", "s", ")", ";", "n", ".", "appendChild", "(", "textNode", ")", ";", "}" ]
Replace the content for the current element. @param n element @param s string content @throws SAXException
[ "Replace", "the", "content", "for", "the", "current", "element", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L382-L397
143,615
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.hasContent
public static boolean hasContent(final Element el) throws SAXException { String s = getElementContent(el); return (s != null) && (s.length() > 0); }
java
public static boolean hasContent(final Element el) throws SAXException { String s = getElementContent(el); return (s != null) && (s.length() > 0); }
[ "public", "static", "boolean", "hasContent", "(", "final", "Element", "el", ")", "throws", "SAXException", "{", "String", "s", "=", "getElementContent", "(", "el", ")", ";", "return", "(", "s", "!=", "null", ")", "&&", "(", "s", ".", "length", "(", ")", ">", "0", ")", ";", "}" ]
Return true if the current element has non zero length content. @param el @return boolean @throws SAXException
[ "Return", "true", "if", "the", "current", "element", "has", "non", "zero", "length", "content", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L418-L422
143,616
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.hasChildren
public static boolean hasChildren(final Element el) throws SAXException { NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); short ntype = curnode.getNodeType(); if ((ntype != Node.TEXT_NODE) && (ntype != Node.CDATA_SECTION_NODE) && (ntype != Node.COMMENT_NODE)) { return true; } } return false; }
java
public static boolean hasChildren(final Element el) throws SAXException { NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curnode = children.item(i); short ntype = curnode.getNodeType(); if ((ntype != Node.TEXT_NODE) && (ntype != Node.CDATA_SECTION_NODE) && (ntype != Node.COMMENT_NODE)) { return true; } } return false; }
[ "public", "static", "boolean", "hasChildren", "(", "final", "Element", "el", ")", "throws", "SAXException", "{", "NodeList", "children", "=", "el", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "children", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "curnode", "=", "children", ".", "item", "(", "i", ")", ";", "short", "ntype", "=", "curnode", ".", "getNodeType", "(", ")", ";", "if", "(", "(", "ntype", "!=", "Node", ".", "TEXT_NODE", ")", "&&", "(", "ntype", "!=", "Node", ".", "CDATA_SECTION_NODE", ")", "&&", "(", "ntype", "!=", "Node", ".", "COMMENT_NODE", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
See if this node has any children @param el @return boolean true for any child elements @throws SAXException
[ "See", "if", "this", "node", "has", "any", "children" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L430-L445
143,617
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.nodeMatches
public static boolean nodeMatches(final Node nd, final QName tag) { if (tag == null) { return false; } String ns = nd.getNamespaceURI(); if (ns == null) { /* It appears a node can have a NULL namespace but a QName has a zero length */ if ((tag.getNamespaceURI() != null) && (!"".equals(tag.getNamespaceURI()))) { return false; } } else if (!ns.equals(tag.getNamespaceURI())) { return false; } String ln = nd.getLocalName(); if (ln == null) { if (tag.getLocalPart() != null) { return false; } } else if (!ln.equals(tag.getLocalPart())) { return false; } return true; }
java
public static boolean nodeMatches(final Node nd, final QName tag) { if (tag == null) { return false; } String ns = nd.getNamespaceURI(); if (ns == null) { /* It appears a node can have a NULL namespace but a QName has a zero length */ if ((tag.getNamespaceURI() != null) && (!"".equals(tag.getNamespaceURI()))) { return false; } } else if (!ns.equals(tag.getNamespaceURI())) { return false; } String ln = nd.getLocalName(); if (ln == null) { if (tag.getLocalPart() != null) { return false; } } else if (!ln.equals(tag.getLocalPart())) { return false; } return true; }
[ "public", "static", "boolean", "nodeMatches", "(", "final", "Node", "nd", ",", "final", "QName", "tag", ")", "{", "if", "(", "tag", "==", "null", ")", "{", "return", "false", ";", "}", "String", "ns", "=", "nd", ".", "getNamespaceURI", "(", ")", ";", "if", "(", "ns", "==", "null", ")", "{", "/* It appears a node can have a NULL namespace but a QName has a zero length\n */", "if", "(", "(", "tag", ".", "getNamespaceURI", "(", ")", "!=", "null", ")", "&&", "(", "!", "\"\"", ".", "equals", "(", "tag", ".", "getNamespaceURI", "(", ")", ")", ")", ")", "{", "return", "false", ";", "}", "}", "else", "if", "(", "!", "ns", ".", "equals", "(", "tag", ".", "getNamespaceURI", "(", ")", ")", ")", "{", "return", "false", ";", "}", "String", "ln", "=", "nd", ".", "getLocalName", "(", ")", ";", "if", "(", "ln", "==", "null", ")", "{", "if", "(", "tag", ".", "getLocalPart", "(", ")", "!=", "null", ")", "{", "return", "false", ";", "}", "}", "else", "if", "(", "!", "ln", ".", "equals", "(", "tag", ".", "getLocalPart", "(", ")", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
See if node matches tag @param nd @param tag @return boolean true for match
[ "See", "if", "node", "matches", "tag" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L474-L502
143,618
Bedework/bw-util
bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java
XmlUtil.fromNode
public static QName fromNode(final Node nd) { String ns = nd.getNamespaceURI(); if (ns == null) { /* It appears a node can have a NULL namespace but a QName has a zero length */ ns = ""; } return new QName(ns, nd.getLocalName()); }
java
public static QName fromNode(final Node nd) { String ns = nd.getNamespaceURI(); if (ns == null) { /* It appears a node can have a NULL namespace but a QName has a zero length */ ns = ""; } return new QName(ns, nd.getLocalName()); }
[ "public", "static", "QName", "fromNode", "(", "final", "Node", "nd", ")", "{", "String", "ns", "=", "nd", ".", "getNamespaceURI", "(", ")", ";", "if", "(", "ns", "==", "null", ")", "{", "/* It appears a node can have a NULL namespace but a QName has a zero length\n */", "ns", "=", "\"\"", ";", "}", "return", "new", "QName", "(", "ns", ",", "nd", ".", "getLocalName", "(", ")", ")", ";", "}" ]
Return a QName for the node @param nd @return boolean true for match
[ "Return", "a", "QName", "for", "the", "node" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-xml/src/main/java/org/bedework/util/xml/XmlUtil.java#L509-L519
143,619
Bedework/bw-util
bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java
BasicHttpClient.getSslSocketFactory
public static SSLSocketFactory getSslSocketFactory() { if (!sslDisabled) { return SSLSocketFactory.getSocketFactory(); } try { final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; final SSLContext ctx = SSLContext.getInstance("TLS"); final X509TrustManager tm = new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return _AcceptedIssuers; } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } @Override public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } }; ctx.init(null, new TrustManager[] { tm }, new SecureRandom()); return new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (final Throwable t) { throw new RuntimeException(t); } }
java
public static SSLSocketFactory getSslSocketFactory() { if (!sslDisabled) { return SSLSocketFactory.getSocketFactory(); } try { final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; final SSLContext ctx = SSLContext.getInstance("TLS"); final X509TrustManager tm = new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return _AcceptedIssuers; } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } @Override public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } }; ctx.init(null, new TrustManager[] { tm }, new SecureRandom()); return new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (final Throwable t) { throw new RuntimeException(t); } }
[ "public", "static", "SSLSocketFactory", "getSslSocketFactory", "(", ")", "{", "if", "(", "!", "sslDisabled", ")", "{", "return", "SSLSocketFactory", ".", "getSocketFactory", "(", ")", ";", "}", "try", "{", "final", "X509Certificate", "[", "]", "_AcceptedIssuers", "=", "new", "X509Certificate", "[", "]", "{", "}", ";", "final", "SSLContext", "ctx", "=", "SSLContext", ".", "getInstance", "(", "\"TLS\"", ")", ";", "final", "X509TrustManager", "tm", "=", "new", "X509TrustManager", "(", ")", "{", "@", "Override", "public", "X509Certificate", "[", "]", "getAcceptedIssuers", "(", ")", "{", "return", "_AcceptedIssuers", ";", "}", "@", "Override", "public", "void", "checkServerTrusted", "(", "final", "X509Certificate", "[", "]", "chain", ",", "final", "String", "authType", ")", "throws", "CertificateException", "{", "}", "@", "Override", "public", "void", "checkClientTrusted", "(", "final", "X509Certificate", "[", "]", "chain", ",", "final", "String", "authType", ")", "throws", "CertificateException", "{", "}", "}", ";", "ctx", ".", "init", "(", "null", ",", "new", "TrustManager", "[", "]", "{", "tm", "}", ",", "new", "SecureRandom", "(", ")", ")", ";", "return", "new", "SSLSocketFactory", "(", "ctx", ",", "SSLSocketFactory", ".", "ALLOW_ALL_HOSTNAME_VERIFIER", ")", ";", "}", "catch", "(", "final", "Throwable", "t", ")", "{", "throw", "new", "RuntimeException", "(", "t", ")", ";", "}", "}" ]
Allow testing of features when we don't have any valid certs. @return socket factory.
[ "Allow", "testing", "of", "features", "when", "we", "don", "t", "have", "any", "valid", "certs", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java#L268-L298
143,620
Bedework/bw-util
bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java
BasicHttpClient.setCredentials
public void setCredentials(final String user, final String pw) { if (user == null) { credentials = null; } else { credentials = new UsernamePasswordCredentials(user, pw); } }
java
public void setCredentials(final String user, final String pw) { if (user == null) { credentials = null; } else { credentials = new UsernamePasswordCredentials(user, pw); } }
[ "public", "void", "setCredentials", "(", "final", "String", "user", ",", "final", "String", "pw", ")", "{", "if", "(", "user", "==", "null", ")", "{", "credentials", "=", "null", ";", "}", "else", "{", "credentials", "=", "new", "UsernamePasswordCredentials", "(", "user", ",", "pw", ")", ";", "}", "}" ]
Set the credentials. user == null for unauthenticated. @param user @param pw
[ "Set", "the", "credentials", ".", "user", "==", "null", "for", "unauthenticated", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java#L420-L426
143,621
Bedework/bw-util
bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java
BasicHttpClient.sendRequest
public int sendRequest(final String methodName, final String url, final List<Header> hdrs, final String contentType, final int contentLen, final byte[] content) throws HttpException { int sz = 0; if (content != null) { sz = content.length; } if (debug()) { debug("About to send request: method=" + methodName + " url=" + url + " contentLen=" + contentLen + " content.length=" + sz + " contentType=" + contentType); } try { URI u = new URI(url); if (!hostSpecified && (u.getHost() == null)) { if ((baseURI == null) && (baseURIValue != null)) { baseURI = new URI(baseURIValue); } if (baseURI == null) { throw new HttpException("No base URI specified for non-absolute URI " + url); } if (baseURI.getHost() == null) { throw new HttpException("Base URI must be absolute: " + baseURI); } u = baseURI.resolve(u); } if (debug()) { debug(" url resolves to " + u); } method = findMethod(methodName, u); if (credentials != null) { getCredentialsProvider().setCredentials(new AuthScope(u.getHost(), u.getPort()), credentials); } if (!Util.isEmpty(hdrs)) { for (final Header hdr: hdrs) { method.addHeader(hdr); } } if (method instanceof HttpEntityEnclosingRequestBase) { if (content != null) { if (contentType == null) { setContent(content, "text/xml"); } else { setContent(content, contentType); } } } response = execute(method); } catch (final HttpException he) { throw he; } catch (final Throwable t) { throw new HttpException(t.getLocalizedMessage(), t); } status = response.getStatusLine().getStatusCode(); return status; }
java
public int sendRequest(final String methodName, final String url, final List<Header> hdrs, final String contentType, final int contentLen, final byte[] content) throws HttpException { int sz = 0; if (content != null) { sz = content.length; } if (debug()) { debug("About to send request: method=" + methodName + " url=" + url + " contentLen=" + contentLen + " content.length=" + sz + " contentType=" + contentType); } try { URI u = new URI(url); if (!hostSpecified && (u.getHost() == null)) { if ((baseURI == null) && (baseURIValue != null)) { baseURI = new URI(baseURIValue); } if (baseURI == null) { throw new HttpException("No base URI specified for non-absolute URI " + url); } if (baseURI.getHost() == null) { throw new HttpException("Base URI must be absolute: " + baseURI); } u = baseURI.resolve(u); } if (debug()) { debug(" url resolves to " + u); } method = findMethod(methodName, u); if (credentials != null) { getCredentialsProvider().setCredentials(new AuthScope(u.getHost(), u.getPort()), credentials); } if (!Util.isEmpty(hdrs)) { for (final Header hdr: hdrs) { method.addHeader(hdr); } } if (method instanceof HttpEntityEnclosingRequestBase) { if (content != null) { if (contentType == null) { setContent(content, "text/xml"); } else { setContent(content, contentType); } } } response = execute(method); } catch (final HttpException he) { throw he; } catch (final Throwable t) { throw new HttpException(t.getLocalizedMessage(), t); } status = response.getStatusLine().getStatusCode(); return status; }
[ "public", "int", "sendRequest", "(", "final", "String", "methodName", ",", "final", "String", "url", ",", "final", "List", "<", "Header", ">", "hdrs", ",", "final", "String", "contentType", ",", "final", "int", "contentLen", ",", "final", "byte", "[", "]", "content", ")", "throws", "HttpException", "{", "int", "sz", "=", "0", ";", "if", "(", "content", "!=", "null", ")", "{", "sz", "=", "content", ".", "length", ";", "}", "if", "(", "debug", "(", ")", ")", "{", "debug", "(", "\"About to send request: method=\"", "+", "methodName", "+", "\" url=\"", "+", "url", "+", "\" contentLen=\"", "+", "contentLen", "+", "\" content.length=\"", "+", "sz", "+", "\" contentType=\"", "+", "contentType", ")", ";", "}", "try", "{", "URI", "u", "=", "new", "URI", "(", "url", ")", ";", "if", "(", "!", "hostSpecified", "&&", "(", "u", ".", "getHost", "(", ")", "==", "null", ")", ")", "{", "if", "(", "(", "baseURI", "==", "null", ")", "&&", "(", "baseURIValue", "!=", "null", ")", ")", "{", "baseURI", "=", "new", "URI", "(", "baseURIValue", ")", ";", "}", "if", "(", "baseURI", "==", "null", ")", "{", "throw", "new", "HttpException", "(", "\"No base URI specified for non-absolute URI \"", "+", "url", ")", ";", "}", "if", "(", "baseURI", ".", "getHost", "(", ")", "==", "null", ")", "{", "throw", "new", "HttpException", "(", "\"Base URI must be absolute: \"", "+", "baseURI", ")", ";", "}", "u", "=", "baseURI", ".", "resolve", "(", "u", ")", ";", "}", "if", "(", "debug", "(", ")", ")", "{", "debug", "(", "\" url resolves to \"", "+", "u", ")", ";", "}", "method", "=", "findMethod", "(", "methodName", ",", "u", ")", ";", "if", "(", "credentials", "!=", "null", ")", "{", "getCredentialsProvider", "(", ")", ".", "setCredentials", "(", "new", "AuthScope", "(", "u", ".", "getHost", "(", ")", ",", "u", ".", "getPort", "(", ")", ")", ",", "credentials", ")", ";", "}", "if", "(", "!", "Util", ".", "isEmpty", "(", "hdrs", ")", ")", "{", "for", "(", "final", "Header", "hdr", ":", "hdrs", ")", "{", "method", ".", "addHeader", "(", "hdr", ")", ";", "}", "}", "if", "(", "method", "instanceof", "HttpEntityEnclosingRequestBase", ")", "{", "if", "(", "content", "!=", "null", ")", "{", "if", "(", "contentType", "==", "null", ")", "{", "setContent", "(", "content", ",", "\"text/xml\"", ")", ";", "}", "else", "{", "setContent", "(", "content", ",", "contentType", ")", ";", "}", "}", "}", "response", "=", "execute", "(", "method", ")", ";", "}", "catch", "(", "final", "HttpException", "he", ")", "{", "throw", "he", ";", "}", "catch", "(", "final", "Throwable", "t", ")", "{", "throw", "new", "HttpException", "(", "t", ".", "getLocalizedMessage", "(", ")", ",", "t", ")", ";", "}", "status", "=", "response", ".", "getStatusLine", "(", ")", ".", "getStatusCode", "(", ")", ";", "return", "status", ";", "}" ]
Send a request to the server @param methodName the method, GET, PUT etc @param url the url @param hdrs may be null @param contentType @param contentLen @param content @return int status code @throws HttpException
[ "Send", "a", "request", "to", "the", "server" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java#L452-L526
143,622
Bedework/bw-util
bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java
BasicHttpClient.findMethod
protected HttpRequestBase findMethod(final String name, final URI uri) throws HttpException { String nm = name.toUpperCase(); if ("PUT".equals(nm)) { return new HttpPut(uri); } if ("GET".equals(nm)) { return new HttpGet(uri); } if ("DELETE".equals(nm)) { return new HttpDelete(uri); } if ("POST".equals(nm)) { return new HttpPost(uri); } if ("PROPFIND".equals(nm)) { return new HttpPropfind(uri); } if ("MKCALENDAR".equals(nm)) { return new HttpMkcalendar(uri); } if ("MKCOL".equals(nm)) { return new HttpMkcol(uri); } if ("OPTIONS".equals(nm)) { return new HttpOptions(uri); } if ("REPORT".equals(nm)) { return new HttpReport(uri); } if ("HEAD".equals(nm)) { return new HttpHead(uri); } throw new HttpException("Illegal method: " + name); }
java
protected HttpRequestBase findMethod(final String name, final URI uri) throws HttpException { String nm = name.toUpperCase(); if ("PUT".equals(nm)) { return new HttpPut(uri); } if ("GET".equals(nm)) { return new HttpGet(uri); } if ("DELETE".equals(nm)) { return new HttpDelete(uri); } if ("POST".equals(nm)) { return new HttpPost(uri); } if ("PROPFIND".equals(nm)) { return new HttpPropfind(uri); } if ("MKCALENDAR".equals(nm)) { return new HttpMkcalendar(uri); } if ("MKCOL".equals(nm)) { return new HttpMkcol(uri); } if ("OPTIONS".equals(nm)) { return new HttpOptions(uri); } if ("REPORT".equals(nm)) { return new HttpReport(uri); } if ("HEAD".equals(nm)) { return new HttpHead(uri); } throw new HttpException("Illegal method: " + name); }
[ "protected", "HttpRequestBase", "findMethod", "(", "final", "String", "name", ",", "final", "URI", "uri", ")", "throws", "HttpException", "{", "String", "nm", "=", "name", ".", "toUpperCase", "(", ")", ";", "if", "(", "\"PUT\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpPut", "(", "uri", ")", ";", "}", "if", "(", "\"GET\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpGet", "(", "uri", ")", ";", "}", "if", "(", "\"DELETE\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpDelete", "(", "uri", ")", ";", "}", "if", "(", "\"POST\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpPost", "(", "uri", ")", ";", "}", "if", "(", "\"PROPFIND\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpPropfind", "(", "uri", ")", ";", "}", "if", "(", "\"MKCALENDAR\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpMkcalendar", "(", "uri", ")", ";", "}", "if", "(", "\"MKCOL\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpMkcol", "(", "uri", ")", ";", "}", "if", "(", "\"OPTIONS\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpOptions", "(", "uri", ")", ";", "}", "if", "(", "\"REPORT\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpReport", "(", "uri", ")", ";", "}", "if", "(", "\"HEAD\"", ".", "equals", "(", "nm", ")", ")", "{", "return", "new", "HttpHead", "(", "uri", ")", ";", "}", "throw", "new", "HttpException", "(", "\"Illegal method: \"", "+", "name", ")", ";", "}" ]
Specify the next method by name. @param name of the method @param uri target @return method object @throws HttpException
[ "Specify", "the", "next", "method", "by", "name", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java#L696-L741
143,623
Bedework/bw-util
bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java
BasicHttpClient.release
public void release() throws HttpException { try { HttpEntity ent = getResponseEntity(); if (ent != null) { InputStream is = ent.getContent(); is.close(); } } catch (Throwable t) { throw new HttpException(t.getLocalizedMessage(), t); } }
java
public void release() throws HttpException { try { HttpEntity ent = getResponseEntity(); if (ent != null) { InputStream is = ent.getContent(); is.close(); } } catch (Throwable t) { throw new HttpException(t.getLocalizedMessage(), t); } }
[ "public", "void", "release", "(", ")", "throws", "HttpException", "{", "try", "{", "HttpEntity", "ent", "=", "getResponseEntity", "(", ")", ";", "if", "(", "ent", "!=", "null", ")", "{", "InputStream", "is", "=", "ent", ".", "getContent", "(", ")", ";", "is", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Throwable", "t", ")", "{", "throw", "new", "HttpException", "(", "t", ".", "getLocalizedMessage", "(", ")", ",", "t", ")", ";", "}", "}" ]
Release the connection @throws HttpException
[ "Release", "the", "connection" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-http/src/main/java/org/bedework/util/http/BasicHttpClient.java#L1014-L1025
143,624
sebastiangraf/treetank
coremodules/node/src/main/java/org/treetank/axis/ItemList.java
ItemList.addItem
public int addItem(final AtomicValue pItem) { final int key = mList.size(); pItem.setNodeKey(key); // TODO: +2 is necessary, because key -1 is the NULLDATA final int itemKey = (key + 2) * (-1); pItem.setNodeKey(itemKey); mList.add(pItem); return itemKey; }
java
public int addItem(final AtomicValue pItem) { final int key = mList.size(); pItem.setNodeKey(key); // TODO: +2 is necessary, because key -1 is the NULLDATA final int itemKey = (key + 2) * (-1); pItem.setNodeKey(itemKey); mList.add(pItem); return itemKey; }
[ "public", "int", "addItem", "(", "final", "AtomicValue", "pItem", ")", "{", "final", "int", "key", "=", "mList", ".", "size", "(", ")", ";", "pItem", ".", "setNodeKey", "(", "key", ")", ";", "// TODO: +2 is necessary, because key -1 is the NULLDATA", "final", "int", "itemKey", "=", "(", "key", "+", "2", ")", "*", "(", "-", "1", ")", ";", "pItem", ".", "setNodeKey", "(", "itemKey", ")", ";", "mList", ".", "add", "(", "pItem", ")", ";", "return", "itemKey", ";", "}" ]
Adding to this list. @param pItem setting and item to this list
[ "Adding", "to", "this", "list", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/node/src/main/java/org/treetank/axis/ItemList.java#L71-L80
143,625
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/io/PooledBuffers.java
PooledBuffers.release
static void release(BufferPool.Buffer buff) throws IOException { if (buff.buf.length == staticConf.getSmallBufferSize()) { smallBufferPool.put(buff); } else if (buff.buf.length == staticConf.getMediumBufferSize()) { mediumBufferPool.put(buff); } else if (buff.buf.length == staticConf.getLargeBufferSize()) { largeBufferPool.put(buff); } }
java
static void release(BufferPool.Buffer buff) throws IOException { if (buff.buf.length == staticConf.getSmallBufferSize()) { smallBufferPool.put(buff); } else if (buff.buf.length == staticConf.getMediumBufferSize()) { mediumBufferPool.put(buff); } else if (buff.buf.length == staticConf.getLargeBufferSize()) { largeBufferPool.put(buff); } }
[ "static", "void", "release", "(", "BufferPool", ".", "Buffer", "buff", ")", "throws", "IOException", "{", "if", "(", "buff", ".", "buf", ".", "length", "==", "staticConf", ".", "getSmallBufferSize", "(", ")", ")", "{", "smallBufferPool", ".", "put", "(", "buff", ")", ";", "}", "else", "if", "(", "buff", ".", "buf", ".", "length", "==", "staticConf", ".", "getMediumBufferSize", "(", ")", ")", "{", "mediumBufferPool", ".", "put", "(", "buff", ")", ";", "}", "else", "if", "(", "buff", ".", "buf", ".", "length", "==", "staticConf", ".", "getLargeBufferSize", "(", ")", ")", "{", "largeBufferPool", ".", "put", "(", "buff", ")", ";", "}", "}" ]
Release a buffer back to the pool. MUST be called to gain the benefit of pooling. @param buff - the buffer @throws java.io.IOException
[ "Release", "a", "buffer", "back", "to", "the", "pool", ".", "MUST", "be", "called", "to", "gain", "the", "benefit", "of", "pooling", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/io/PooledBuffers.java#L93-L101
143,626
Bedework/bw-util
bw-util-jms/src/main/java/org/bedework/util/jms/NotificationsHandlerFactory.java
NotificationsHandlerFactory.getHandler
private static NotificationsHandler getHandler(final String queueName, final Properties pr) throws NotificationException { if (handler != null) { return handler; } synchronized (synchit) { handler = new JmsNotificationsHandlerImpl(queueName, pr); } return handler; }
java
private static NotificationsHandler getHandler(final String queueName, final Properties pr) throws NotificationException { if (handler != null) { return handler; } synchronized (synchit) { handler = new JmsNotificationsHandlerImpl(queueName, pr); } return handler; }
[ "private", "static", "NotificationsHandler", "getHandler", "(", "final", "String", "queueName", ",", "final", "Properties", "pr", ")", "throws", "NotificationException", "{", "if", "(", "handler", "!=", "null", ")", "{", "return", "handler", ";", "}", "synchronized", "(", "synchit", ")", "{", "handler", "=", "new", "JmsNotificationsHandlerImpl", "(", "queueName", ",", "pr", ")", ";", "}", "return", "handler", ";", "}" ]
Return a handler for the system event @param queueName our queue @param pr jms properties @return NotificationsHandler @throws NotificationException
[ "Return", "a", "handler", "for", "the", "system", "event" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-jms/src/main/java/org/bedework/util/jms/NotificationsHandlerFactory.java#L43-L54
143,627
Bedework/bw-util
bw-util-jms/src/main/java/org/bedework/util/jms/NotificationsHandlerFactory.java
NotificationsHandlerFactory.post
public static void post(final SysEvent ev, final String queueName, final Properties pr) throws NotificationException { getHandler(queueName, pr).post(ev); }
java
public static void post(final SysEvent ev, final String queueName, final Properties pr) throws NotificationException { getHandler(queueName, pr).post(ev); }
[ "public", "static", "void", "post", "(", "final", "SysEvent", "ev", ",", "final", "String", "queueName", ",", "final", "Properties", "pr", ")", "throws", "NotificationException", "{", "getHandler", "(", "queueName", ",", "pr", ")", ".", "post", "(", "ev", ")", ";", "}" ]
Called to notify container that an event occurred. In general this should not be called directly as consumers may receive the messages immediately, perhaps before the referenced data has been written. @param ev the system event @param queueName our queue @param pr jms properties @throws NotificationException
[ "Called", "to", "notify", "container", "that", "an", "event", "occurred", ".", "In", "general", "this", "should", "not", "be", "called", "directly", "as", "consumers", "may", "receive", "the", "messages", "immediately", "perhaps", "before", "the", "referenced", "data", "has", "been", "written", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-jms/src/main/java/org/bedework/util/jms/NotificationsHandlerFactory.java#L66-L70
143,628
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.adjustCollection
public static <T> AdjustCollectionResult<T> adjustCollection(final Collection<T> newCol, final Collection<T> toAdjust) { final AdjustCollectionResult<T> acr = new AdjustCollectionResult<>(); acr.removed = new ArrayList<>(); acr.added = new ArrayList<>(); acr.added.addAll(newCol); if (toAdjust != null) { for (final T ent: toAdjust) { if (newCol.contains(ent)) { acr.added.remove(ent); continue; } acr.removed.add(ent); } for (final T ent: acr.added) { toAdjust.add(ent); acr.numAdded++; } for (final T ent: acr.removed) { if (toAdjust.remove(ent)) { acr.numRemoved++; } } } return acr; }
java
public static <T> AdjustCollectionResult<T> adjustCollection(final Collection<T> newCol, final Collection<T> toAdjust) { final AdjustCollectionResult<T> acr = new AdjustCollectionResult<>(); acr.removed = new ArrayList<>(); acr.added = new ArrayList<>(); acr.added.addAll(newCol); if (toAdjust != null) { for (final T ent: toAdjust) { if (newCol.contains(ent)) { acr.added.remove(ent); continue; } acr.removed.add(ent); } for (final T ent: acr.added) { toAdjust.add(ent); acr.numAdded++; } for (final T ent: acr.removed) { if (toAdjust.remove(ent)) { acr.numRemoved++; } } } return acr; }
[ "public", "static", "<", "T", ">", "AdjustCollectionResult", "<", "T", ">", "adjustCollection", "(", "final", "Collection", "<", "T", ">", "newCol", ",", "final", "Collection", "<", "T", ">", "toAdjust", ")", "{", "final", "AdjustCollectionResult", "<", "T", ">", "acr", "=", "new", "AdjustCollectionResult", "<>", "(", ")", ";", "acr", ".", "removed", "=", "new", "ArrayList", "<>", "(", ")", ";", "acr", ".", "added", "=", "new", "ArrayList", "<>", "(", ")", ";", "acr", ".", "added", ".", "addAll", "(", "newCol", ")", ";", "if", "(", "toAdjust", "!=", "null", ")", "{", "for", "(", "final", "T", "ent", ":", "toAdjust", ")", "{", "if", "(", "newCol", ".", "contains", "(", "ent", ")", ")", "{", "acr", ".", "added", ".", "remove", "(", "ent", ")", ";", "continue", ";", "}", "acr", ".", "removed", ".", "add", "(", "ent", ")", ";", "}", "for", "(", "final", "T", "ent", ":", "acr", ".", "added", ")", "{", "toAdjust", ".", "add", "(", "ent", ")", ";", "acr", ".", "numAdded", "++", ";", "}", "for", "(", "final", "T", "ent", ":", "acr", ".", "removed", ")", "{", "if", "(", "toAdjust", ".", "remove", "(", "ent", ")", ")", "{", "acr", ".", "numRemoved", "++", ";", "}", "}", "}", "return", "acr", ";", "}" ]
Used to adjust a collection toAdjust so that it looks like the collection newCol. The collection newCol will be unchanged but the result object will contain a list of added and removed values. @param newCol make it look like this @param toAdjust if non-null will be adjusted @return added and removed values
[ "Used", "to", "adjust", "a", "collection", "toAdjust", "so", "that", "it", "looks", "like", "the", "collection", "newCol", ".", "The", "collection", "newCol", "will", "be", "unchanged", "but", "the", "result", "object", "will", "contain", "a", "list", "of", "added", "and", "removed", "values", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L83-L114
143,629
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.pathElement
public static String pathElement(final int index, final String path) { final String[] paths = path.split("/"); int idx = index; if ((paths[0] == null) || (paths[0].length() == 0)) { // skip empty first part - leading "/" idx++; } if (idx >= paths.length) { return null; } return paths[idx]; }
java
public static String pathElement(final int index, final String path) { final String[] paths = path.split("/"); int idx = index; if ((paths[0] == null) || (paths[0].length() == 0)) { // skip empty first part - leading "/" idx++; } if (idx >= paths.length) { return null; } return paths[idx]; }
[ "public", "static", "String", "pathElement", "(", "final", "int", "index", ",", "final", "String", "path", ")", "{", "final", "String", "[", "]", "paths", "=", "path", ".", "split", "(", "\"/\"", ")", ";", "int", "idx", "=", "index", ";", "if", "(", "(", "paths", "[", "0", "]", "==", "null", ")", "||", "(", "paths", "[", "0", "]", ".", "length", "(", ")", "==", "0", ")", ")", "{", "// skip empty first part - leading \"/\"", "idx", "++", ";", "}", "if", "(", "idx", ">=", "paths", ".", "length", ")", "{", "return", "null", ";", "}", "return", "paths", "[", "idx", "]", ";", "}" ]
get the nth element from the path - first is 0. @param index of element we want @param path from which we extract the element @return element or null
[ "get", "the", "nth", "element", "from", "the", "path", "-", "first", "is", "0", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L186-L202
143,630
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.makeLocale
public static Locale makeLocale(final String val) throws Throwable { String lang = null; String country = ""; // NOT null for Locale String variant = ""; if (val == null) { throw new Exception("Bad Locale: NULL"); } if (val.length() == 2) { lang = val; } else { int pos = val.indexOf('_'); if (pos != 2) { throw new Exception("Bad Locale: " + val); } lang = val.substring(0, 2); pos = val.indexOf("_", 3); if (pos < 0) { if (val.length() != 5) { throw new Exception("Bad Locale: " + val); } country = val.substring(3); } else { country = val.substring(3, 5); if (val.length() > 6) { variant = val.substring(6); } } } return new Locale(lang, country, variant); }
java
public static Locale makeLocale(final String val) throws Throwable { String lang = null; String country = ""; // NOT null for Locale String variant = ""; if (val == null) { throw new Exception("Bad Locale: NULL"); } if (val.length() == 2) { lang = val; } else { int pos = val.indexOf('_'); if (pos != 2) { throw new Exception("Bad Locale: " + val); } lang = val.substring(0, 2); pos = val.indexOf("_", 3); if (pos < 0) { if (val.length() != 5) { throw new Exception("Bad Locale: " + val); } country = val.substring(3); } else { country = val.substring(3, 5); if (val.length() > 6) { variant = val.substring(6); } } } return new Locale(lang, country, variant); }
[ "public", "static", "Locale", "makeLocale", "(", "final", "String", "val", ")", "throws", "Throwable", "{", "String", "lang", "=", "null", ";", "String", "country", "=", "\"\"", ";", "// NOT null for Locale", "String", "variant", "=", "\"\"", ";", "if", "(", "val", "==", "null", ")", "{", "throw", "new", "Exception", "(", "\"Bad Locale: NULL\"", ")", ";", "}", "if", "(", "val", ".", "length", "(", ")", "==", "2", ")", "{", "lang", "=", "val", ";", "}", "else", "{", "int", "pos", "=", "val", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "pos", "!=", "2", ")", "{", "throw", "new", "Exception", "(", "\"Bad Locale: \"", "+", "val", ")", ";", "}", "lang", "=", "val", ".", "substring", "(", "0", ",", "2", ")", ";", "pos", "=", "val", ".", "indexOf", "(", "\"_\"", ",", "3", ")", ";", "if", "(", "pos", "<", "0", ")", "{", "if", "(", "val", ".", "length", "(", ")", "!=", "5", ")", "{", "throw", "new", "Exception", "(", "\"Bad Locale: \"", "+", "val", ")", ";", "}", "country", "=", "val", ".", "substring", "(", "3", ")", ";", "}", "else", "{", "country", "=", "val", ".", "substring", "(", "3", ",", "5", ")", ";", "if", "(", "val", ".", "length", "(", ")", ">", "6", ")", "{", "variant", "=", "val", ".", "substring", "(", "6", ")", ";", "}", "}", "}", "return", "new", "Locale", "(", "lang", ",", "country", ",", "variant", ")", ";", "}" ]
make a locale from the standard underscore separated parts - no idea why this isn't in Locale @param val teh locale String e.g. en_US @return a Locale @throws Throwable
[ "make", "a", "locale", "from", "the", "standard", "underscore", "separated", "parts", "-", "no", "idea", "why", "this", "isn", "t", "in", "Locale" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L211-L246
143,631
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.getPropertiesFromResource
public static Properties getPropertiesFromResource(final String name) throws Throwable { Properties pr = new Properties(); InputStream is = null; try { try { // The jboss?? way - should work for others as well. ClassLoader cl = Thread.currentThread().getContextClassLoader(); is = cl.getResourceAsStream(name); } catch (Throwable clt) {} if (is == null) { // Try another way is = Util.class.getResourceAsStream(name); } if (is == null) { throw new Exception("Unable to load properties file" + name); } pr.load(is); //if (debug) { // pr.list(System.out); // Logger.getLogger(Util.class).debug( // "file.encoding=" + System.getProperty("file.encoding")); //} return pr; } finally { if (is != null) { try { is.close(); } catch (Throwable t1) {} } } }
java
public static Properties getPropertiesFromResource(final String name) throws Throwable { Properties pr = new Properties(); InputStream is = null; try { try { // The jboss?? way - should work for others as well. ClassLoader cl = Thread.currentThread().getContextClassLoader(); is = cl.getResourceAsStream(name); } catch (Throwable clt) {} if (is == null) { // Try another way is = Util.class.getResourceAsStream(name); } if (is == null) { throw new Exception("Unable to load properties file" + name); } pr.load(is); //if (debug) { // pr.list(System.out); // Logger.getLogger(Util.class).debug( // "file.encoding=" + System.getProperty("file.encoding")); //} return pr; } finally { if (is != null) { try { is.close(); } catch (Throwable t1) {} } } }
[ "public", "static", "Properties", "getPropertiesFromResource", "(", "final", "String", "name", ")", "throws", "Throwable", "{", "Properties", "pr", "=", "new", "Properties", "(", ")", ";", "InputStream", "is", "=", "null", ";", "try", "{", "try", "{", "// The jboss?? way - should work for others as well.", "ClassLoader", "cl", "=", "Thread", ".", "currentThread", "(", ")", ".", "getContextClassLoader", "(", ")", ";", "is", "=", "cl", ".", "getResourceAsStream", "(", "name", ")", ";", "}", "catch", "(", "Throwable", "clt", ")", "{", "}", "if", "(", "is", "==", "null", ")", "{", "// Try another way", "is", "=", "Util", ".", "class", ".", "getResourceAsStream", "(", "name", ")", ";", "}", "if", "(", "is", "==", "null", ")", "{", "throw", "new", "Exception", "(", "\"Unable to load properties file\"", "+", "name", ")", ";", "}", "pr", ".", "load", "(", "is", ")", ";", "//if (debug) {", "// pr.list(System.out);", "// Logger.getLogger(Util.class).debug(", "// \"file.encoding=\" + System.getProperty(\"file.encoding\"));", "//}", "return", "pr", ";", "}", "finally", "{", "if", "(", "is", "!=", "null", ")", "{", "try", "{", "is", ".", "close", "(", ")", ";", "}", "catch", "(", "Throwable", "t1", ")", "{", "}", "}", "}", "}" ]
Load a named resource as a Properties object @param name String resource name @return Properties populated from the resource @throws Throwable
[ "Load", "a", "named", "resource", "as", "a", "Properties", "object" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L260-L295
143,632
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.getObject
public static Object getObject(final String className, final Class cl) throws Exception { try { Object o = Class.forName(className).newInstance(); if (o == null) { throw new Exception("Class " + className + " not found"); } if (!cl.isInstance(o)) { throw new Exception("Class " + className + " is not a subclass of " + cl.getName()); } return o; } catch (Exception e) { throw e; } catch (Throwable t) { throw new Exception(t); } }
java
public static Object getObject(final String className, final Class cl) throws Exception { try { Object o = Class.forName(className).newInstance(); if (o == null) { throw new Exception("Class " + className + " not found"); } if (!cl.isInstance(o)) { throw new Exception("Class " + className + " is not a subclass of " + cl.getName()); } return o; } catch (Exception e) { throw e; } catch (Throwable t) { throw new Exception(t); } }
[ "public", "static", "Object", "getObject", "(", "final", "String", "className", ",", "final", "Class", "cl", ")", "throws", "Exception", "{", "try", "{", "Object", "o", "=", "Class", ".", "forName", "(", "className", ")", ".", "newInstance", "(", ")", ";", "if", "(", "o", "==", "null", ")", "{", "throw", "new", "Exception", "(", "\"Class \"", "+", "className", "+", "\" not found\"", ")", ";", "}", "if", "(", "!", "cl", ".", "isInstance", "(", "o", ")", ")", "{", "throw", "new", "Exception", "(", "\"Class \"", "+", "className", "+", "\" is not a subclass of \"", "+", "cl", ".", "getName", "(", ")", ")", ";", "}", "return", "o", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "throw", "new", "Exception", "(", "t", ")", ";", "}", "}" ]
Given a class name return an object of that class. The class parameter is used to check that the named class is an instance of that class. @param className String class name @param cl Class expected @return Object checked to be an instance of that class @throws Exception
[ "Given", "a", "class", "name", "return", "an", "object", "of", "that", "class", ".", "The", "class", "parameter", "is", "used", "to", "check", "that", "the", "named", "class", "is", "an", "instance", "of", "that", "class", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L306-L327
143,633
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.fmtMsg
public static String fmtMsg(final String fmt, final String arg1, final String arg2) { Object[] o = new Object[2]; o[0] = arg1; o[1] = arg2; return MessageFormat.format(fmt, o); }
java
public static String fmtMsg(final String fmt, final String arg1, final String arg2) { Object[] o = new Object[2]; o[0] = arg1; o[1] = arg2; return MessageFormat.format(fmt, o); }
[ "public", "static", "String", "fmtMsg", "(", "final", "String", "fmt", ",", "final", "String", "arg1", ",", "final", "String", "arg2", ")", "{", "Object", "[", "]", "o", "=", "new", "Object", "[", "2", "]", ";", "o", "[", "0", "]", "=", "arg1", ";", "o", "[", "1", "]", "=", "arg2", ";", "return", "MessageFormat", ".", "format", "(", "fmt", ",", "o", ")", ";", "}" ]
Format a message consisting of a format string plus two string parameters @param fmt @param arg1 @param arg2 @return String formatted message
[ "Format", "a", "message", "consisting", "of", "a", "format", "string", "plus", "two", "string", "parameters" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L422-L428
143,634
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.fmtMsg
public static String fmtMsg(final String fmt, final int arg) { Object[] o = new Object[1]; o[0] = new Integer(arg); return MessageFormat.format(fmt, o); }
java
public static String fmtMsg(final String fmt, final int arg) { Object[] o = new Object[1]; o[0] = new Integer(arg); return MessageFormat.format(fmt, o); }
[ "public", "static", "String", "fmtMsg", "(", "final", "String", "fmt", ",", "final", "int", "arg", ")", "{", "Object", "[", "]", "o", "=", "new", "Object", "[", "1", "]", ";", "o", "[", "0", "]", "=", "new", "Integer", "(", "arg", ")", ";", "return", "MessageFormat", ".", "format", "(", "fmt", ",", "o", ")", ";", "}" ]
Format a message consisting of a format string plus one integer parameter @param fmt @param arg @return String formatted message
[ "Format", "a", "message", "consisting", "of", "a", "format", "string", "plus", "one", "integer", "parameter" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L436-L441
143,635
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.makeRandomString
public static String makeRandomString(int length, int maxVal) { if (length < 0) { return null; } length = Math.min(length, 1025); if (maxVal < 0) { return null; } maxVal = Math.min(maxVal, 35); StringBuffer res = new StringBuffer(); Random rand = new Random(); for (int i = 0; i <= length; i++) { res.append(randChars[rand.nextInt(maxVal + 1)]); } return res.toString(); }
java
public static String makeRandomString(int length, int maxVal) { if (length < 0) { return null; } length = Math.min(length, 1025); if (maxVal < 0) { return null; } maxVal = Math.min(maxVal, 35); StringBuffer res = new StringBuffer(); Random rand = new Random(); for (int i = 0; i <= length; i++) { res.append(randChars[rand.nextInt(maxVal + 1)]); } return res.toString(); }
[ "public", "static", "String", "makeRandomString", "(", "int", "length", ",", "int", "maxVal", ")", "{", "if", "(", "length", "<", "0", ")", "{", "return", "null", ";", "}", "length", "=", "Math", ".", "min", "(", "length", ",", "1025", ")", ";", "if", "(", "maxVal", "<", "0", ")", "{", "return", "null", ";", "}", "maxVal", "=", "Math", ".", "min", "(", "maxVal", ",", "35", ")", ";", "StringBuffer", "res", "=", "new", "StringBuffer", "(", ")", ";", "Random", "rand", "=", "new", "Random", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "length", ";", "i", "++", ")", "{", "res", ".", "append", "(", "randChars", "[", "rand", ".", "nextInt", "(", "maxVal", "+", "1", ")", "]", ")", ";", "}", "return", "res", ".", "toString", "(", ")", ";", "}" ]
Creates a string of given length where each character comes from a set of values 0-9 followed by A-Z. @param length returned string will be this long. Less than 1k + 1 @param maxVal maximum ordinal value of characters. If < than 0, return null. If > 35, 35 is used instead. @return String the random string
[ "Creates", "a", "string", "of", "given", "length", "where", "each", "character", "comes", "from", "a", "set", "of", "values", "0", "-", "9", "followed", "by", "A", "-", "Z", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L456-L477
143,636
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.appendTextToArray
public static String[] appendTextToArray(String[] sarray, final String val, final int maxEntries) { if (sarray == null) { if (maxEntries > 0) { sarray = new String[1]; sarray[0] = val; } return sarray; } if (sarray.length > maxEntries) { String[] neb = new String[maxEntries]; System.arraycopy(sarray, sarray.length - maxEntries, neb, 0, maxEntries); sarray = neb; sarray[sarray.length - 1] = val; neb = null; return sarray; } if (sarray.length < maxEntries) { int newLen = sarray.length + 1; String[] neb = new String[newLen]; System.arraycopy(sarray, 0, neb, 0, sarray.length); sarray = neb; sarray[sarray.length - 1] = val; neb = null; return sarray; } if (maxEntries > 1) { System.arraycopy(sarray, 1, sarray, 0, sarray.length - 1); } sarray[sarray.length - 1] = val; return sarray; }
java
public static String[] appendTextToArray(String[] sarray, final String val, final int maxEntries) { if (sarray == null) { if (maxEntries > 0) { sarray = new String[1]; sarray[0] = val; } return sarray; } if (sarray.length > maxEntries) { String[] neb = new String[maxEntries]; System.arraycopy(sarray, sarray.length - maxEntries, neb, 0, maxEntries); sarray = neb; sarray[sarray.length - 1] = val; neb = null; return sarray; } if (sarray.length < maxEntries) { int newLen = sarray.length + 1; String[] neb = new String[newLen]; System.arraycopy(sarray, 0, neb, 0, sarray.length); sarray = neb; sarray[sarray.length - 1] = val; neb = null; return sarray; } if (maxEntries > 1) { System.arraycopy(sarray, 1, sarray, 0, sarray.length - 1); } sarray[sarray.length - 1] = val; return sarray; }
[ "public", "static", "String", "[", "]", "appendTextToArray", "(", "String", "[", "]", "sarray", ",", "final", "String", "val", ",", "final", "int", "maxEntries", ")", "{", "if", "(", "sarray", "==", "null", ")", "{", "if", "(", "maxEntries", ">", "0", ")", "{", "sarray", "=", "new", "String", "[", "1", "]", ";", "sarray", "[", "0", "]", "=", "val", ";", "}", "return", "sarray", ";", "}", "if", "(", "sarray", ".", "length", ">", "maxEntries", ")", "{", "String", "[", "]", "neb", "=", "new", "String", "[", "maxEntries", "]", ";", "System", ".", "arraycopy", "(", "sarray", ",", "sarray", ".", "length", "-", "maxEntries", ",", "neb", ",", "0", ",", "maxEntries", ")", ";", "sarray", "=", "neb", ";", "sarray", "[", "sarray", ".", "length", "-", "1", "]", "=", "val", ";", "neb", "=", "null", ";", "return", "sarray", ";", "}", "if", "(", "sarray", ".", "length", "<", "maxEntries", ")", "{", "int", "newLen", "=", "sarray", ".", "length", "+", "1", ";", "String", "[", "]", "neb", "=", "new", "String", "[", "newLen", "]", ";", "System", ".", "arraycopy", "(", "sarray", ",", "0", ",", "neb", ",", "0", ",", "sarray", ".", "length", ")", ";", "sarray", "=", "neb", ";", "sarray", "[", "sarray", ".", "length", "-", "1", "]", "=", "val", ";", "neb", "=", "null", ";", "return", "sarray", ";", "}", "if", "(", "maxEntries", ">", "1", ")", "{", "System", ".", "arraycopy", "(", "sarray", ",", "1", ",", "sarray", ",", "0", ",", "sarray", ".", "length", "-", "1", ")", ";", "}", "sarray", "[", "sarray", ".", "length", "-", "1", "]", "=", "val", ";", "return", "sarray", ";", "}" ]
Add a string to a string array of a given maximum length. Truncates the string array if required. New entries go at the end. old get dropped off the front. @param sarray String[] to be updated @param val new entry @param maxEntries Number of entries we keep. @return String[] Modified sarray
[ "Add", "a", "string", "to", "a", "string", "array", "of", "a", "given", "maximum", "length", ".", "Truncates", "the", "string", "array", "if", "required", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L489-L528
143,637
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.encodeArray
public static String encodeArray(final String[] val){ if (val == null) { return null; } int len = val.length; if (len == 0) { return ""; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i++) { if (i > 0) { sb.append(" "); } String s = val[i]; try { if (s == null) { sb.append("\t"); } else { sb.append(URLEncoder.encode(s, "UTF-8")); } } catch (Throwable t) { throw new RuntimeException(t); } } return sb.toString(); }
java
public static String encodeArray(final String[] val){ if (val == null) { return null; } int len = val.length; if (len == 0) { return ""; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i++) { if (i > 0) { sb.append(" "); } String s = val[i]; try { if (s == null) { sb.append("\t"); } else { sb.append(URLEncoder.encode(s, "UTF-8")); } } catch (Throwable t) { throw new RuntimeException(t); } } return sb.toString(); }
[ "public", "static", "String", "encodeArray", "(", "final", "String", "[", "]", "val", ")", "{", "if", "(", "val", "==", "null", ")", "{", "return", "null", ";", "}", "int", "len", "=", "val", ".", "length", ";", "if", "(", "len", "==", "0", ")", "{", "return", "\"\"", ";", "}", "StringBuffer", "sb", "=", "new", "StringBuffer", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "if", "(", "i", ">", "0", ")", "{", "sb", ".", "append", "(", "\" \"", ")", ";", "}", "String", "s", "=", "val", "[", "i", "]", ";", "try", "{", "if", "(", "s", "==", "null", ")", "{", "sb", ".", "append", "(", "\"\\t\"", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "URLEncoder", ".", "encode", "(", "s", ",", "\"UTF-8\"", ")", ")", ";", "}", "}", "catch", "(", "Throwable", "t", ")", "{", "throw", "new", "RuntimeException", "(", "t", ")", ";", "}", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Return a String representing the given String array, achieved by URLEncoding the individual String elements then concatenating with intervening blanks. @param val String[] value to encode @return String encoded value
[ "Return", "a", "String", "representing", "the", "given", "String", "array", "achieved", "by", "URLEncoding", "the", "individual", "String", "elements", "then", "concatenating", "with", "intervening", "blanks", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L537-L569
143,638
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.decodeArray
public static String[] decodeArray(final String val){ if (val == null) { return null; } int len = val.length(); if (len == 0) { return new String[0]; } ArrayList<String> al = new ArrayList<String>(); int i = 0; while (i < len) { int end = val.indexOf(" ", i); String s; if (end < 0) { s = val.substring(i); i = len; } else { s = val.substring(i, end); i = end + 1; } try { if (s.equals("\t")) { al.add(null); } else { al.add(URLDecoder.decode(s, "UTF-8")); } } catch (Throwable t) { throw new RuntimeException(t); } } return al.toArray(new String[al.size()]); }
java
public static String[] decodeArray(final String val){ if (val == null) { return null; } int len = val.length(); if (len == 0) { return new String[0]; } ArrayList<String> al = new ArrayList<String>(); int i = 0; while (i < len) { int end = val.indexOf(" ", i); String s; if (end < 0) { s = val.substring(i); i = len; } else { s = val.substring(i, end); i = end + 1; } try { if (s.equals("\t")) { al.add(null); } else { al.add(URLDecoder.decode(s, "UTF-8")); } } catch (Throwable t) { throw new RuntimeException(t); } } return al.toArray(new String[al.size()]); }
[ "public", "static", "String", "[", "]", "decodeArray", "(", "final", "String", "val", ")", "{", "if", "(", "val", "==", "null", ")", "{", "return", "null", ";", "}", "int", "len", "=", "val", ".", "length", "(", ")", ";", "if", "(", "len", "==", "0", ")", "{", "return", "new", "String", "[", "0", "]", ";", "}", "ArrayList", "<", "String", ">", "al", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "int", "i", "=", "0", ";", "while", "(", "i", "<", "len", ")", "{", "int", "end", "=", "val", ".", "indexOf", "(", "\" \"", ",", "i", ")", ";", "String", "s", ";", "if", "(", "end", "<", "0", ")", "{", "s", "=", "val", ".", "substring", "(", "i", ")", ";", "i", "=", "len", ";", "}", "else", "{", "s", "=", "val", ".", "substring", "(", "i", ",", "end", ")", ";", "i", "=", "end", "+", "1", ";", "}", "try", "{", "if", "(", "s", ".", "equals", "(", "\"\\t\"", ")", ")", "{", "al", ".", "add", "(", "null", ")", ";", "}", "else", "{", "al", ".", "add", "(", "URLDecoder", ".", "decode", "(", "s", ",", "\"UTF-8\"", ")", ")", ";", "}", "}", "catch", "(", "Throwable", "t", ")", "{", "throw", "new", "RuntimeException", "(", "t", ")", ";", "}", "}", "return", "al", ".", "toArray", "(", "new", "String", "[", "al", ".", "size", "(", ")", "]", ")", ";", "}" ]
Return a StringArray resulting from decoding the given String which should have been encoded by encodeArray @param val String value encoded by encodeArray @return String[] decoded value
[ "Return", "a", "StringArray", "resulting", "from", "decoding", "the", "given", "String", "which", "should", "have", "been", "encoded", "by", "encodeArray" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L577-L615
143,639
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.equalsString
public static boolean equalsString(final String thisStr, final String thatStr) { if ((thisStr == null) && (thatStr == null)) { return true; } if (thisStr == null) { return false; } return thisStr.equals(thatStr); }
java
public static boolean equalsString(final String thisStr, final String thatStr) { if ((thisStr == null) && (thatStr == null)) { return true; } if (thisStr == null) { return false; } return thisStr.equals(thatStr); }
[ "public", "static", "boolean", "equalsString", "(", "final", "String", "thisStr", ",", "final", "String", "thatStr", ")", "{", "if", "(", "(", "thisStr", "==", "null", ")", "&&", "(", "thatStr", "==", "null", ")", ")", "{", "return", "true", ";", "}", "if", "(", "thisStr", "==", "null", ")", "{", "return", "false", ";", "}", "return", "thisStr", ".", "equals", "(", "thatStr", ")", ";", "}" ]
Return true if Strings are equal including possible null @param thisStr @param thatStr @return boolean true for equal
[ "Return", "true", "if", "Strings", "are", "equal", "including", "possible", "null" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L623-L633
143,640
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.compareStrings
public static int compareStrings(final String s1, final String s2) { if (s1 == null) { if (s2 != null) { return -1; } return 0; } if (s2 == null) { return 1; } return s1.compareTo(s2); }
java
public static int compareStrings(final String s1, final String s2) { if (s1 == null) { if (s2 != null) { return -1; } return 0; } if (s2 == null) { return 1; } return s1.compareTo(s2); }
[ "public", "static", "int", "compareStrings", "(", "final", "String", "s1", ",", "final", "String", "s2", ")", "{", "if", "(", "s1", "==", "null", ")", "{", "if", "(", "s2", "!=", "null", ")", "{", "return", "-", "1", ";", "}", "return", "0", ";", "}", "if", "(", "s2", "==", "null", ")", "{", "return", "1", ";", "}", "return", "s1", ".", "compareTo", "(", "s2", ")", ";", "}" ]
Compare two strings. null is less than any non-null string. @param s1 first string. @param s2 second string. @return int 0 if the s1 is equal to s2; <0 if s1 is lexicographically less than s2; >0 if s1 is lexicographically greater than s2.
[ "Compare", "two", "strings", ".", "null", "is", "less", "than", "any", "non", "-", "null", "string", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L643-L657
143,641
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.getList
public static List<String> getList(final String val, final boolean emptyOk) throws Throwable { List<String> l = new LinkedList<String>(); if ((val == null) || (val.length() == 0)) { return l; } StringTokenizer st = new StringTokenizer(val, ",", false); while (st.hasMoreTokens()) { String token = st.nextToken().trim(); if ((token == null) || (token.length() == 0)) { if (!emptyOk) { // No empty strings throw new Exception("List has an empty element."); } l.add(""); } else { // Got non-empty element l.add(token); } } return l; }
java
public static List<String> getList(final String val, final boolean emptyOk) throws Throwable { List<String> l = new LinkedList<String>(); if ((val == null) || (val.length() == 0)) { return l; } StringTokenizer st = new StringTokenizer(val, ",", false); while (st.hasMoreTokens()) { String token = st.nextToken().trim(); if ((token == null) || (token.length() == 0)) { if (!emptyOk) { // No empty strings throw new Exception("List has an empty element."); } l.add(""); } else { // Got non-empty element l.add(token); } } return l; }
[ "public", "static", "List", "<", "String", ">", "getList", "(", "final", "String", "val", ",", "final", "boolean", "emptyOk", ")", "throws", "Throwable", "{", "List", "<", "String", ">", "l", "=", "new", "LinkedList", "<", "String", ">", "(", ")", ";", "if", "(", "(", "val", "==", "null", ")", "||", "(", "val", ".", "length", "(", ")", "==", "0", ")", ")", "{", "return", "l", ";", "}", "StringTokenizer", "st", "=", "new", "StringTokenizer", "(", "val", ",", "\",\"", ",", "false", ")", ";", "while", "(", "st", ".", "hasMoreTokens", "(", ")", ")", "{", "String", "token", "=", "st", ".", "nextToken", "(", ")", ".", "trim", "(", ")", ";", "if", "(", "(", "token", "==", "null", ")", "||", "(", "token", ".", "length", "(", ")", "==", "0", ")", ")", "{", "if", "(", "!", "emptyOk", ")", "{", "// No empty strings", "throw", "new", "Exception", "(", "\"List has an empty element.\"", ")", ";", "}", "l", ".", "add", "(", "\"\"", ")", ";", "}", "else", "{", "// Got non-empty element", "l", ".", "add", "(", "token", ")", ";", "}", "}", "return", "l", ";", "}" ]
Turn a comma separated list into a List. Throws exception for invalid list. @param val String comma separated list @param emptyOk Empty elements are OK @return List of elements, never null @throws Throwable for invalid list
[ "Turn", "a", "comma", "separated", "list", "into", "a", "List", ".", "Throws", "exception", "for", "invalid", "list", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L696-L721
143,642
Bedework/bw-util
bw-util-misc/src/main/java/org/bedework/util/misc/Util.java
Util.compare
public static int compare(final char[] thisone, final char[] thatone) { if (thisone == thatone) { return 0; } if (thisone == null) { return -1; } if (thatone == null) { return 1; } if (thisone.length < thatone.length) { return -1; } if (thisone.length > thatone.length) { return -1; } for (int i = 0; i < thisone.length; i++) { char thisc = thisone[i]; char thatc = thatone[i]; if (thisc < thatc) { return -1; } if (thisc > thatc) { return 1; } } return 0; }
java
public static int compare(final char[] thisone, final char[] thatone) { if (thisone == thatone) { return 0; } if (thisone == null) { return -1; } if (thatone == null) { return 1; } if (thisone.length < thatone.length) { return -1; } if (thisone.length > thatone.length) { return -1; } for (int i = 0; i < thisone.length; i++) { char thisc = thisone[i]; char thatc = thatone[i]; if (thisc < thatc) { return -1; } if (thisc > thatc) { return 1; } } return 0; }
[ "public", "static", "int", "compare", "(", "final", "char", "[", "]", "thisone", ",", "final", "char", "[", "]", "thatone", ")", "{", "if", "(", "thisone", "==", "thatone", ")", "{", "return", "0", ";", "}", "if", "(", "thisone", "==", "null", ")", "{", "return", "-", "1", ";", "}", "if", "(", "thatone", "==", "null", ")", "{", "return", "1", ";", "}", "if", "(", "thisone", ".", "length", "<", "thatone", ".", "length", ")", "{", "return", "-", "1", ";", "}", "if", "(", "thisone", ".", "length", ">", "thatone", ".", "length", ")", "{", "return", "-", "1", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "thisone", ".", "length", ";", "i", "++", ")", "{", "char", "thisc", "=", "thisone", "[", "i", "]", ";", "char", "thatc", "=", "thatone", "[", "i", "]", ";", "if", "(", "thisc", "<", "thatc", ")", "{", "return", "-", "1", ";", "}", "if", "(", "thisc", ">", "thatc", ")", "{", "return", "1", ";", "}", "}", "return", "0", ";", "}" ]
Compare two char arrays @param thisone @param thatone @return int -1, 0, 1,
[ "Compare", "two", "char", "arrays" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-misc/src/main/java/org/bedework/util/misc/Util.java#L828-L863
143,643
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/diff/out/EditScript.java
EditScript.add
public Diff add(final Diff paramChange) { assert paramChange != null; final ITreeData item = paramChange.getDiff() == EDiff.DELETED ? paramChange.getOldNode() : paramChange.getNewNode(); if (mChangeByNode.containsKey(item)) { return paramChange; } mChanges.add(paramChange); return mChangeByNode.put(item, paramChange); }
java
public Diff add(final Diff paramChange) { assert paramChange != null; final ITreeData item = paramChange.getDiff() == EDiff.DELETED ? paramChange.getOldNode() : paramChange.getNewNode(); if (mChangeByNode.containsKey(item)) { return paramChange; } mChanges.add(paramChange); return mChangeByNode.put(item, paramChange); }
[ "public", "Diff", "add", "(", "final", "Diff", "paramChange", ")", "{", "assert", "paramChange", "!=", "null", ";", "final", "ITreeData", "item", "=", "paramChange", ".", "getDiff", "(", ")", "==", "EDiff", ".", "DELETED", "?", "paramChange", ".", "getOldNode", "(", ")", ":", "paramChange", ".", "getNewNode", "(", ")", ";", "if", "(", "mChangeByNode", ".", "containsKey", "(", "item", ")", ")", "{", "return", "paramChange", ";", "}", "mChanges", ".", "add", "(", "paramChange", ")", ";", "return", "mChangeByNode", ".", "put", "(", "item", ",", "paramChange", ")", ";", "}" ]
Adds a change to the edit script. @param paramChange {@link Diff} reference @return the change
[ "Adds", "a", "change", "to", "the", "edit", "script", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/diff/out/EditScript.java#L124-L134
143,644
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.startListening
public void startListening() throws FileNotFoundException, ClassNotFoundException, IOException, ResourceNotExistingException, TTException { mProcessingThread = new Thread() { public void run() { try { processFileNotifications(); } catch (InterruptedException | TTException | IOException e) { } } }; mProcessingThread.start(); initSessions(); }
java
public void startListening() throws FileNotFoundException, ClassNotFoundException, IOException, ResourceNotExistingException, TTException { mProcessingThread = new Thread() { public void run() { try { processFileNotifications(); } catch (InterruptedException | TTException | IOException e) { } } }; mProcessingThread.start(); initSessions(); }
[ "public", "void", "startListening", "(", ")", "throws", "FileNotFoundException", ",", "ClassNotFoundException", ",", "IOException", ",", "ResourceNotExistingException", ",", "TTException", "{", "mProcessingThread", "=", "new", "Thread", "(", ")", "{", "public", "void", "run", "(", ")", "{", "try", "{", "processFileNotifications", "(", ")", ";", "}", "catch", "(", "InterruptedException", "|", "TTException", "|", "IOException", "e", ")", "{", "}", "}", "}", ";", "mProcessingThread", ".", "start", "(", ")", ";", "initSessions", "(", ")", ";", "}" ]
Start listening to the defined folders. @throws FileNotFoundException @throws ClassNotFoundException @throws IOException @throws ResourceNotExistingException @throws TTException
[ "Start", "listening", "to", "the", "defined", "folders", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L137-L150
143,645
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.initSessions
private void initSessions() throws FileNotFoundException, ClassNotFoundException, IOException, ResourceNotExistingException, TTException { Map<String, String> filelisteners = getFilelisteners(); mSessions = new HashMap<String, ISession>(); mTrx = new HashMap<String, IFilelistenerWriteTrx>(); if (filelisteners.isEmpty()) { return; } for (Entry<String, String> e : filelisteners.entrySet()) { mSessions.put(e.getKey(), StorageManager.getSession(e.getKey())); mTrx.put(e.getKey(), new FilelistenerWriteTrx(mSessions.get(e.getKey()).beginBucketWtx(), mSessions.get(e.getKey()))); mSubDirectories.put(e.getValue(), new ArrayList<String>()); mExecutorMap.put(e.getValue(), Executors.newSingleThreadExecutor()); List<String> subDirs = mSubDirectories.get(e.getValue()); for (String s : mTrx.get(e.getKey()).getFilePaths()) { String fullFilePath = new StringBuilder().append(e.getValue()).append(File.separator).append(s).toString(); subDirs.add(fullFilePath); Path p = Paths.get(fullFilePath); watchParents(p, e.getValue()); } } }
java
private void initSessions() throws FileNotFoundException, ClassNotFoundException, IOException, ResourceNotExistingException, TTException { Map<String, String> filelisteners = getFilelisteners(); mSessions = new HashMap<String, ISession>(); mTrx = new HashMap<String, IFilelistenerWriteTrx>(); if (filelisteners.isEmpty()) { return; } for (Entry<String, String> e : filelisteners.entrySet()) { mSessions.put(e.getKey(), StorageManager.getSession(e.getKey())); mTrx.put(e.getKey(), new FilelistenerWriteTrx(mSessions.get(e.getKey()).beginBucketWtx(), mSessions.get(e.getKey()))); mSubDirectories.put(e.getValue(), new ArrayList<String>()); mExecutorMap.put(e.getValue(), Executors.newSingleThreadExecutor()); List<String> subDirs = mSubDirectories.get(e.getValue()); for (String s : mTrx.get(e.getKey()).getFilePaths()) { String fullFilePath = new StringBuilder().append(e.getValue()).append(File.separator).append(s).toString(); subDirs.add(fullFilePath); Path p = Paths.get(fullFilePath); watchParents(p, e.getValue()); } } }
[ "private", "void", "initSessions", "(", ")", "throws", "FileNotFoundException", ",", "ClassNotFoundException", ",", "IOException", ",", "ResourceNotExistingException", ",", "TTException", "{", "Map", "<", "String", ",", "String", ">", "filelisteners", "=", "getFilelisteners", "(", ")", ";", "mSessions", "=", "new", "HashMap", "<", "String", ",", "ISession", ">", "(", ")", ";", "mTrx", "=", "new", "HashMap", "<", "String", ",", "IFilelistenerWriteTrx", ">", "(", ")", ";", "if", "(", "filelisteners", ".", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "for", "(", "Entry", "<", "String", ",", "String", ">", "e", ":", "filelisteners", ".", "entrySet", "(", ")", ")", "{", "mSessions", ".", "put", "(", "e", ".", "getKey", "(", ")", ",", "StorageManager", ".", "getSession", "(", "e", ".", "getKey", "(", ")", ")", ")", ";", "mTrx", ".", "put", "(", "e", ".", "getKey", "(", ")", ",", "new", "FilelistenerWriteTrx", "(", "mSessions", ".", "get", "(", "e", ".", "getKey", "(", ")", ")", ".", "beginBucketWtx", "(", ")", ",", "mSessions", ".", "get", "(", "e", ".", "getKey", "(", ")", ")", ")", ")", ";", "mSubDirectories", ".", "put", "(", "e", ".", "getValue", "(", ")", ",", "new", "ArrayList", "<", "String", ">", "(", ")", ")", ";", "mExecutorMap", ".", "put", "(", "e", ".", "getValue", "(", ")", ",", "Executors", ".", "newSingleThreadExecutor", "(", ")", ")", ";", "List", "<", "String", ">", "subDirs", "=", "mSubDirectories", ".", "get", "(", "e", ".", "getValue", "(", ")", ")", ";", "for", "(", "String", "s", ":", "mTrx", ".", "get", "(", "e", ".", "getKey", "(", ")", ")", ".", "getFilePaths", "(", ")", ")", "{", "String", "fullFilePath", "=", "new", "StringBuilder", "(", ")", ".", "append", "(", "e", ".", "getValue", "(", ")", ")", ".", "append", "(", "File", ".", "separator", ")", ".", "append", "(", "s", ")", ".", "toString", "(", ")", ";", "subDirs", ".", "add", "(", "fullFilePath", ")", ";", "Path", "p", "=", "Paths", ".", "get", "(", "fullFilePath", ")", ";", "watchParents", "(", "p", ",", "e", ".", "getValue", "(", ")", ")", ";", "}", "}", "}" ]
This method is used to initialize a session with treetank for every storage configuration thats in the database. @throws FileNotFoundException @throws ClassNotFoundException @throws IOException @throws ResourceNotExistingException @throws TTException
[ "This", "method", "is", "used", "to", "initialize", "a", "session", "with", "treetank", "for", "every", "storage", "configuration", "thats", "in", "the", "database", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L162-L191
143,646
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.watchParents
private void watchParents(Path p, String until) throws IOException { if (p.getParent() != null && !until.equals(p.getParent().toString())) { watchDir(p.getParent().toFile()); watchParents(p.getParent(), until); } }
java
private void watchParents(Path p, String until) throws IOException { if (p.getParent() != null && !until.equals(p.getParent().toString())) { watchDir(p.getParent().toFile()); watchParents(p.getParent(), until); } }
[ "private", "void", "watchParents", "(", "Path", "p", ",", "String", "until", ")", "throws", "IOException", "{", "if", "(", "p", ".", "getParent", "(", ")", "!=", "null", "&&", "!", "until", ".", "equals", "(", "p", ".", "getParent", "(", ")", ".", "toString", "(", ")", ")", ")", "{", "watchDir", "(", "p", ".", "getParent", "(", ")", ".", "toFile", "(", ")", ")", ";", "watchParents", "(", "p", ".", "getParent", "(", ")", ",", "until", ")", ";", "}", "}" ]
Watch parent folders of this file until the root listener path has been reached. @param p @param until @throws IOException
[ "Watch", "parent", "folders", "of", "this", "file", "until", "the", "root", "listener", "path", "has", "been", "reached", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L201-L206
143,647
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.releaseSessions
private void releaseSessions() throws TTException { if (mSessions == null) { return; } // Closing all transactions. try { for (IFilelistenerWriteTrx trx : mTrx.values()) { trx.close(); } } catch (IllegalStateException ise) { ise.printStackTrace(); } // Closing all storages aswell. for (ISession s : mSessions.values()) { s.close(); } }
java
private void releaseSessions() throws TTException { if (mSessions == null) { return; } // Closing all transactions. try { for (IFilelistenerWriteTrx trx : mTrx.values()) { trx.close(); } } catch (IllegalStateException ise) { ise.printStackTrace(); } // Closing all storages aswell. for (ISession s : mSessions.values()) { s.close(); } }
[ "private", "void", "releaseSessions", "(", ")", "throws", "TTException", "{", "if", "(", "mSessions", "==", "null", ")", "{", "return", ";", "}", "// Closing all transactions.", "try", "{", "for", "(", "IFilelistenerWriteTrx", "trx", ":", "mTrx", ".", "values", "(", ")", ")", "{", "trx", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "IllegalStateException", "ise", ")", "{", "ise", ".", "printStackTrace", "(", ")", ";", "}", "// Closing all storages aswell.", "for", "(", "ISession", "s", ":", "mSessions", ".", "values", "(", ")", ")", "{", "s", ".", "close", "(", ")", ";", "}", "}" ]
Release transactions and session from treetank. @throws TTException
[ "Release", "transactions", "and", "session", "from", "treetank", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L213-L231
143,648
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.shutDownListener
public void shutDownListener() throws TTException, IOException { for (ExecutorService s : mExecutorMap.values()) { s.shutdown(); while (!s.isTerminated()) { // Do nothing. try { Thread.sleep(1000); } catch (InterruptedException e) { LOGGER.error(e.getStackTrace().toString()); } } } Thread thr = mProcessingThread; if (thr != null) { thr.interrupt(); } mWatcher.close(); releaseSessions(); }
java
public void shutDownListener() throws TTException, IOException { for (ExecutorService s : mExecutorMap.values()) { s.shutdown(); while (!s.isTerminated()) { // Do nothing. try { Thread.sleep(1000); } catch (InterruptedException e) { LOGGER.error(e.getStackTrace().toString()); } } } Thread thr = mProcessingThread; if (thr != null) { thr.interrupt(); } mWatcher.close(); releaseSessions(); }
[ "public", "void", "shutDownListener", "(", ")", "throws", "TTException", ",", "IOException", "{", "for", "(", "ExecutorService", "s", ":", "mExecutorMap", ".", "values", "(", ")", ")", "{", "s", ".", "shutdown", "(", ")", ";", "while", "(", "!", "s", ".", "isTerminated", "(", ")", ")", "{", "// Do nothing.", "try", "{", "Thread", ".", "sleep", "(", "1000", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "LOGGER", ".", "error", "(", "e", ".", "getStackTrace", "(", ")", ".", "toString", "(", ")", ")", ";", "}", "}", "}", "Thread", "thr", "=", "mProcessingThread", ";", "if", "(", "thr", "!=", "null", ")", "{", "thr", ".", "interrupt", "(", ")", ";", "}", "mWatcher", ".", "close", "(", ")", ";", "releaseSessions", "(", ")", ";", "}" ]
Shutdown listening to the defined folders and release all bonds to Treetank. @throws TTException @throws IOException
[ "Shutdown", "listening", "to", "the", "defined", "folders", "and", "release", "all", "bonds", "to", "Treetank", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L240-L262
143,649
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.processFileNotifications
private void processFileNotifications() throws InterruptedException, TTException, IOException { while (true) { WatchKey key = mWatcher.take(); Path dir = mKeyPaths.get(key); for (WatchEvent<?> evt : key.pollEvents()) { WatchEvent.Kind<?> eventType = evt.kind(); if (eventType == OVERFLOW) continue; Object o = evt.context(); if (o instanceof Path) { Path path = dir.resolve((Path)evt.context()); process(dir, path, eventType); } } key.reset(); processFsnOnHold(); } }
java
private void processFileNotifications() throws InterruptedException, TTException, IOException { while (true) { WatchKey key = mWatcher.take(); Path dir = mKeyPaths.get(key); for (WatchEvent<?> evt : key.pollEvents()) { WatchEvent.Kind<?> eventType = evt.kind(); if (eventType == OVERFLOW) continue; Object o = evt.context(); if (o instanceof Path) { Path path = dir.resolve((Path)evt.context()); process(dir, path, eventType); } } key.reset(); processFsnOnHold(); } }
[ "private", "void", "processFileNotifications", "(", ")", "throws", "InterruptedException", ",", "TTException", ",", "IOException", "{", "while", "(", "true", ")", "{", "WatchKey", "key", "=", "mWatcher", ".", "take", "(", ")", ";", "Path", "dir", "=", "mKeyPaths", ".", "get", "(", "key", ")", ";", "for", "(", "WatchEvent", "<", "?", ">", "evt", ":", "key", ".", "pollEvents", "(", ")", ")", "{", "WatchEvent", ".", "Kind", "<", "?", ">", "eventType", "=", "evt", ".", "kind", "(", ")", ";", "if", "(", "eventType", "==", "OVERFLOW", ")", "continue", ";", "Object", "o", "=", "evt", ".", "context", "(", ")", ";", "if", "(", "o", "instanceof", "Path", ")", "{", "Path", "path", "=", "dir", ".", "resolve", "(", "(", "Path", ")", "evt", ".", "context", "(", ")", ")", ";", "process", "(", "dir", ",", "path", ",", "eventType", ")", ";", "}", "}", "key", ".", "reset", "(", ")", ";", "processFsnOnHold", "(", ")", ";", "}", "}" ]
In this method the notifications of the filesystem if anything changed in a folder that the system is listening to are being extracted and processed. @throws InterruptedException @throws IOException @throws TTException
[ "In", "this", "method", "the", "notifications", "of", "the", "filesystem", "if", "anything", "changed", "in", "a", "folder", "that", "the", "system", "is", "listening", "to", "are", "being", "extracted", "and", "processed", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L273-L291
143,650
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.process
private void process(Path dir, Path file, WatchEvent.Kind<?> evtType) throws TTException, IOException, InterruptedException { // LOGGER.info("Processing " + file.getFileName() + " with event " // + evtType); IFilelistenerWriteTrx trx = null; String rootPath = getListenerRootPath(dir); String relativePath = file.toFile().getAbsolutePath(); relativePath = relativePath.substring(getListenerRootPath(dir).length(), relativePath.length()); for (Entry<String, String> e : mFilelistenerToPaths.entrySet()) { if (e.getValue().equals(getListenerRootPath(dir))) { trx = mTrx.get(e.getKey()); } } if (file.toFile().isDirectory()) { if (evtType == ENTRY_CREATE) { addSubDirectory(dir, file); return; } else if (evtType == ENTRY_DELETE) { for (String s : trx.getFilePaths()) { if (s.contains(relativePath)) { trx.removeFile(s); } } } } else { // if (mLockedFiles.get(rootPath + File.separator // + file.toFile().getName()) != null) { // if (mLockedFiles.get( // rootPath + File.separator + file.toFile().getName()) // .isFinished()) { // ExecutorService s = mExecutorMap // .get(getListenerRootPath(dir)); // if (s != null && !s.isShutdown()) { // // FilesystemNotification n = new FilesystemNotification( // file.toFile(), relativePath, rootPath, evtType, // trx); // if (mObserver != null) { // n.addObserver(mObserver); // } // mFsnOnHold.remove(rootPath + File.separator // + file.toFile().getName()); // mLockedFiles.put(rootPath + File.separator // + file.toFile().getName(), n); // s.submit(n); // } // } else { // FilesystemNotification n = new FilesystemNotification( // file.toFile(), relativePath, rootPath, evtType, trx); // if (mObserver != null) { // n.addObserver(mObserver); // } // mFsnOnHold.put(rootPath + File.separator // + file.toFile().getName(), n); // } // } else { ExecutorService s = mExecutorMap.get(getListenerRootPath(dir)); if (s != null && !s.isShutdown()) { FilesystemNotification n = new FilesystemNotification(file.toFile(), relativePath, rootPath, evtType, trx); if (mObserver != null) { n.addObserver(mObserver); } // mLockedFiles.put(rootPath + File.separator // + file.toFile().getName(), n); s.submit(n); // } } } }
java
private void process(Path dir, Path file, WatchEvent.Kind<?> evtType) throws TTException, IOException, InterruptedException { // LOGGER.info("Processing " + file.getFileName() + " with event " // + evtType); IFilelistenerWriteTrx trx = null; String rootPath = getListenerRootPath(dir); String relativePath = file.toFile().getAbsolutePath(); relativePath = relativePath.substring(getListenerRootPath(dir).length(), relativePath.length()); for (Entry<String, String> e : mFilelistenerToPaths.entrySet()) { if (e.getValue().equals(getListenerRootPath(dir))) { trx = mTrx.get(e.getKey()); } } if (file.toFile().isDirectory()) { if (evtType == ENTRY_CREATE) { addSubDirectory(dir, file); return; } else if (evtType == ENTRY_DELETE) { for (String s : trx.getFilePaths()) { if (s.contains(relativePath)) { trx.removeFile(s); } } } } else { // if (mLockedFiles.get(rootPath + File.separator // + file.toFile().getName()) != null) { // if (mLockedFiles.get( // rootPath + File.separator + file.toFile().getName()) // .isFinished()) { // ExecutorService s = mExecutorMap // .get(getListenerRootPath(dir)); // if (s != null && !s.isShutdown()) { // // FilesystemNotification n = new FilesystemNotification( // file.toFile(), relativePath, rootPath, evtType, // trx); // if (mObserver != null) { // n.addObserver(mObserver); // } // mFsnOnHold.remove(rootPath + File.separator // + file.toFile().getName()); // mLockedFiles.put(rootPath + File.separator // + file.toFile().getName(), n); // s.submit(n); // } // } else { // FilesystemNotification n = new FilesystemNotification( // file.toFile(), relativePath, rootPath, evtType, trx); // if (mObserver != null) { // n.addObserver(mObserver); // } // mFsnOnHold.put(rootPath + File.separator // + file.toFile().getName(), n); // } // } else { ExecutorService s = mExecutorMap.get(getListenerRootPath(dir)); if (s != null && !s.isShutdown()) { FilesystemNotification n = new FilesystemNotification(file.toFile(), relativePath, rootPath, evtType, trx); if (mObserver != null) { n.addObserver(mObserver); } // mLockedFiles.put(rootPath + File.separator // + file.toFile().getName(), n); s.submit(n); // } } } }
[ "private", "void", "process", "(", "Path", "dir", ",", "Path", "file", ",", "WatchEvent", ".", "Kind", "<", "?", ">", "evtType", ")", "throws", "TTException", ",", "IOException", ",", "InterruptedException", "{", "// LOGGER.info(\"Processing \" + file.getFileName() + \" with event \"", "// + evtType);", "IFilelistenerWriteTrx", "trx", "=", "null", ";", "String", "rootPath", "=", "getListenerRootPath", "(", "dir", ")", ";", "String", "relativePath", "=", "file", ".", "toFile", "(", ")", ".", "getAbsolutePath", "(", ")", ";", "relativePath", "=", "relativePath", ".", "substring", "(", "getListenerRootPath", "(", "dir", ")", ".", "length", "(", ")", ",", "relativePath", ".", "length", "(", ")", ")", ";", "for", "(", "Entry", "<", "String", ",", "String", ">", "e", ":", "mFilelistenerToPaths", ".", "entrySet", "(", ")", ")", "{", "if", "(", "e", ".", "getValue", "(", ")", ".", "equals", "(", "getListenerRootPath", "(", "dir", ")", ")", ")", "{", "trx", "=", "mTrx", ".", "get", "(", "e", ".", "getKey", "(", ")", ")", ";", "}", "}", "if", "(", "file", ".", "toFile", "(", ")", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "evtType", "==", "ENTRY_CREATE", ")", "{", "addSubDirectory", "(", "dir", ",", "file", ")", ";", "return", ";", "}", "else", "if", "(", "evtType", "==", "ENTRY_DELETE", ")", "{", "for", "(", "String", "s", ":", "trx", ".", "getFilePaths", "(", ")", ")", "{", "if", "(", "s", ".", "contains", "(", "relativePath", ")", ")", "{", "trx", ".", "removeFile", "(", "s", ")", ";", "}", "}", "}", "}", "else", "{", "// if (mLockedFiles.get(rootPath + File.separator", "// + file.toFile().getName()) != null) {", "// if (mLockedFiles.get(", "// rootPath + File.separator + file.toFile().getName())", "// .isFinished()) {", "// ExecutorService s = mExecutorMap", "// .get(getListenerRootPath(dir));", "// if (s != null && !s.isShutdown()) {", "//", "// FilesystemNotification n = new FilesystemNotification(", "// file.toFile(), relativePath, rootPath, evtType,", "// trx);", "// if (mObserver != null) {", "// n.addObserver(mObserver);", "// }", "// mFsnOnHold.remove(rootPath + File.separator", "// + file.toFile().getName());", "// mLockedFiles.put(rootPath + File.separator", "// + file.toFile().getName(), n);", "// s.submit(n);", "// }", "// } else {", "// FilesystemNotification n = new FilesystemNotification(", "// file.toFile(), relativePath, rootPath, evtType, trx);", "// if (mObserver != null) {", "// n.addObserver(mObserver);", "// }", "// mFsnOnHold.put(rootPath + File.separator", "// + file.toFile().getName(), n);", "// }", "// } else {", "ExecutorService", "s", "=", "mExecutorMap", ".", "get", "(", "getListenerRootPath", "(", "dir", ")", ")", ";", "if", "(", "s", "!=", "null", "&&", "!", "s", ".", "isShutdown", "(", ")", ")", "{", "FilesystemNotification", "n", "=", "new", "FilesystemNotification", "(", "file", ".", "toFile", "(", ")", ",", "relativePath", ",", "rootPath", ",", "evtType", ",", "trx", ")", ";", "if", "(", "mObserver", "!=", "null", ")", "{", "n", ".", "addObserver", "(", "mObserver", ")", ";", "}", "// mLockedFiles.put(rootPath + File.separator", "// + file.toFile().getName(), n);", "s", ".", "submit", "(", "n", ")", ";", "// }", "}", "}", "}" ]
This method is used to process the file system modifications. @param dir @param file @param evtType @throws IOException @throws TTException @throws InterruptedException
[ "This", "method", "is", "used", "to", "process", "the", "file", "system", "modifications", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L327-L401
143,651
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.addSubDirectory
private void addSubDirectory(Path root, Path filePath) throws IOException { String listener = getListenerRootPath(root); List<String> listeners = mSubDirectories.get(listener); if (listeners != null) { if (mSubDirectories.get(listener).contains(filePath.toAbsolutePath())) { return; } else { mSubDirectories.get(listener).add(filePath.toString()); } try { watchDir(filePath.toFile()); } catch (IOException e) { throw new IOException("Could not watch the subdirectories.", e); } } }
java
private void addSubDirectory(Path root, Path filePath) throws IOException { String listener = getListenerRootPath(root); List<String> listeners = mSubDirectories.get(listener); if (listeners != null) { if (mSubDirectories.get(listener).contains(filePath.toAbsolutePath())) { return; } else { mSubDirectories.get(listener).add(filePath.toString()); } try { watchDir(filePath.toFile()); } catch (IOException e) { throw new IOException("Could not watch the subdirectories.", e); } } }
[ "private", "void", "addSubDirectory", "(", "Path", "root", ",", "Path", "filePath", ")", "throws", "IOException", "{", "String", "listener", "=", "getListenerRootPath", "(", "root", ")", ";", "List", "<", "String", ">", "listeners", "=", "mSubDirectories", ".", "get", "(", "listener", ")", ";", "if", "(", "listeners", "!=", "null", ")", "{", "if", "(", "mSubDirectories", ".", "get", "(", "listener", ")", ".", "contains", "(", "filePath", ".", "toAbsolutePath", "(", ")", ")", ")", "{", "return", ";", "}", "else", "{", "mSubDirectories", ".", "get", "(", "listener", ")", ".", "add", "(", "filePath", ".", "toString", "(", ")", ")", ";", "}", "try", "{", "watchDir", "(", "filePath", ".", "toFile", "(", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "IOException", "(", "\"Could not watch the subdirectories.\"", ",", "e", ")", ";", "}", "}", "}" ]
In this method a subdirectory is being added to the system and watched. This is necessary since the {@link WatchService} doesn't support watching a folder with higher depths than 1. @param root @param filePath @throws IOException
[ "In", "this", "method", "a", "subdirectory", "is", "being", "added", "to", "the", "system", "and", "watched", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L413-L431
143,652
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.getListenerRootPath
private String getListenerRootPath(Path root) { String listener = ""; for (String s : mFilelistenerToPaths.values()) { if (root.toString().contains(s)) { listener = s; } } return listener; }
java
private String getListenerRootPath(Path root) { String listener = ""; for (String s : mFilelistenerToPaths.values()) { if (root.toString().contains(s)) { listener = s; } } return listener; }
[ "private", "String", "getListenerRootPath", "(", "Path", "root", ")", "{", "String", "listener", "=", "\"\"", ";", "for", "(", "String", "s", ":", "mFilelistenerToPaths", ".", "values", "(", ")", ")", "{", "if", "(", "root", ".", "toString", "(", ")", ".", "contains", "(", "s", ")", ")", "{", "listener", "=", "s", ";", "}", "}", "return", "listener", ";", "}" ]
This utility method allows you to get the root path for a subdirectory. The root path is a directory that has been explicitly listened to and not just recursively. @param root @return returns the root path as a String
[ "This", "utility", "method", "allows", "you", "to", "get", "the", "root", "path", "for", "a", "subdirectory", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L442-L452
143,653
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.getFilelisteners
public static Map<String, String> getFilelisteners() throws FileNotFoundException, IOException, ClassNotFoundException { mFilelistenerToPaths = new HashMap<String, String>(); File listenerFilePaths = new File(StorageManager.ROOT_PATH + File.separator + "mapping.data"); getFileListenersFromSystem(listenerFilePaths); return mFilelistenerToPaths; }
java
public static Map<String, String> getFilelisteners() throws FileNotFoundException, IOException, ClassNotFoundException { mFilelistenerToPaths = new HashMap<String, String>(); File listenerFilePaths = new File(StorageManager.ROOT_PATH + File.separator + "mapping.data"); getFileListenersFromSystem(listenerFilePaths); return mFilelistenerToPaths; }
[ "public", "static", "Map", "<", "String", ",", "String", ">", "getFilelisteners", "(", ")", "throws", "FileNotFoundException", ",", "IOException", ",", "ClassNotFoundException", "{", "mFilelistenerToPaths", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "File", "listenerFilePaths", "=", "new", "File", "(", "StorageManager", ".", "ROOT_PATH", "+", "File", ".", "separator", "+", "\"mapping.data\"", ")", ";", "getFileListenersFromSystem", "(", "listenerFilePaths", ")", ";", "return", "mFilelistenerToPaths", ";", "}" ]
A utility method to get all filelisteners that are already defined and stored. @return returns a map of relative paths to the folders as the keyset and the resourcenames that point to the configurations in the valueset. @throws FileNotFoundException @throws IOException @throws ClassNotFoundException
[ "A", "utility", "method", "to", "get", "all", "filelisteners", "that", "are", "already", "defined", "and", "stored", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L465-L475
143,654
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.addFilelistener
public static boolean addFilelistener(String pResourcename, String pListenerPath) throws FileNotFoundException, IOException, ClassNotFoundException { mFilelistenerToPaths = new HashMap<String, String>(); File listenerFilePaths = new File(StorageManager.ROOT_PATH + File.separator + "mapping.data"); getFileListenersFromSystem(listenerFilePaths); mFilelistenerToPaths.put(pResourcename, pListenerPath); ByteArrayDataOutput output = ByteStreams.newDataOutput(); for (Entry<String, String> e : mFilelistenerToPaths.entrySet()) { output.write((e.getKey() + "\n").getBytes()); output.write((e.getValue() + "\n").getBytes()); } java.nio.file.Files.write(listenerFilePaths.toPath(), output.toByteArray(), StandardOpenOption.TRUNCATE_EXISTING); return true; }
java
public static boolean addFilelistener(String pResourcename, String pListenerPath) throws FileNotFoundException, IOException, ClassNotFoundException { mFilelistenerToPaths = new HashMap<String, String>(); File listenerFilePaths = new File(StorageManager.ROOT_PATH + File.separator + "mapping.data"); getFileListenersFromSystem(listenerFilePaths); mFilelistenerToPaths.put(pResourcename, pListenerPath); ByteArrayDataOutput output = ByteStreams.newDataOutput(); for (Entry<String, String> e : mFilelistenerToPaths.entrySet()) { output.write((e.getKey() + "\n").getBytes()); output.write((e.getValue() + "\n").getBytes()); } java.nio.file.Files.write(listenerFilePaths.toPath(), output.toByteArray(), StandardOpenOption.TRUNCATE_EXISTING); return true; }
[ "public", "static", "boolean", "addFilelistener", "(", "String", "pResourcename", ",", "String", "pListenerPath", ")", "throws", "FileNotFoundException", ",", "IOException", ",", "ClassNotFoundException", "{", "mFilelistenerToPaths", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "File", "listenerFilePaths", "=", "new", "File", "(", "StorageManager", ".", "ROOT_PATH", "+", "File", ".", "separator", "+", "\"mapping.data\"", ")", ";", "getFileListenersFromSystem", "(", "listenerFilePaths", ")", ";", "mFilelistenerToPaths", ".", "put", "(", "pResourcename", ",", "pListenerPath", ")", ";", "ByteArrayDataOutput", "output", "=", "ByteStreams", ".", "newDataOutput", "(", ")", ";", "for", "(", "Entry", "<", "String", ",", "String", ">", "e", ":", "mFilelistenerToPaths", ".", "entrySet", "(", ")", ")", "{", "output", ".", "write", "(", "(", "e", ".", "getKey", "(", ")", "+", "\"\\n\"", ")", ".", "getBytes", "(", ")", ")", ";", "output", ".", "write", "(", "(", "e", ".", "getValue", "(", ")", "+", "\"\\n\"", ")", ".", "getBytes", "(", ")", ")", ";", "}", "java", ".", "nio", ".", "file", ".", "Files", ".", "write", "(", "listenerFilePaths", ".", "toPath", "(", ")", ",", "output", ".", "toByteArray", "(", ")", ",", "StandardOpenOption", ".", "TRUNCATE_EXISTING", ")", ";", "return", "true", ";", "}" ]
Add a new filelistener to the system. @param pResourcename @param pListenerPath @return return true if there has been a success. @throws FileNotFoundException @throws IOException @throws ClassNotFoundException
[ "Add", "a", "new", "filelistener", "to", "the", "system", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L487-L507
143,655
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.removeFilelistener
public boolean removeFilelistener(String pResourcename) throws IOException, TTException, ResourceNotExistingException { mFilelistenerToPaths = new HashMap<String, String>(); File listenerFilePaths = new File(StorageManager.ROOT_PATH + File.separator + "mapping.data"); getFileListenersFromSystem(listenerFilePaths); mFilelistenerToPaths.remove(pResourcename); StorageManager.removeResource(pResourcename); ByteArrayDataOutput output = ByteStreams.newDataOutput(); for (Entry<String, String> e : mFilelistenerToPaths.entrySet()) { output.write((e.getKey() + "\n").getBytes()); output.write((e.getValue() + "\n").getBytes()); } java.nio.file.Files.write(listenerFilePaths.toPath(), output.toByteArray(), StandardOpenOption.TRUNCATE_EXISTING); return true; }
java
public boolean removeFilelistener(String pResourcename) throws IOException, TTException, ResourceNotExistingException { mFilelistenerToPaths = new HashMap<String, String>(); File listenerFilePaths = new File(StorageManager.ROOT_PATH + File.separator + "mapping.data"); getFileListenersFromSystem(listenerFilePaths); mFilelistenerToPaths.remove(pResourcename); StorageManager.removeResource(pResourcename); ByteArrayDataOutput output = ByteStreams.newDataOutput(); for (Entry<String, String> e : mFilelistenerToPaths.entrySet()) { output.write((e.getKey() + "\n").getBytes()); output.write((e.getValue() + "\n").getBytes()); } java.nio.file.Files.write(listenerFilePaths.toPath(), output.toByteArray(), StandardOpenOption.TRUNCATE_EXISTING); return true; }
[ "public", "boolean", "removeFilelistener", "(", "String", "pResourcename", ")", "throws", "IOException", ",", "TTException", ",", "ResourceNotExistingException", "{", "mFilelistenerToPaths", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "File", "listenerFilePaths", "=", "new", "File", "(", "StorageManager", ".", "ROOT_PATH", "+", "File", ".", "separator", "+", "\"mapping.data\"", ")", ";", "getFileListenersFromSystem", "(", "listenerFilePaths", ")", ";", "mFilelistenerToPaths", ".", "remove", "(", "pResourcename", ")", ";", "StorageManager", ".", "removeResource", "(", "pResourcename", ")", ";", "ByteArrayDataOutput", "output", "=", "ByteStreams", ".", "newDataOutput", "(", ")", ";", "for", "(", "Entry", "<", "String", ",", "String", ">", "e", ":", "mFilelistenerToPaths", ".", "entrySet", "(", ")", ")", "{", "output", ".", "write", "(", "(", "e", ".", "getKey", "(", ")", "+", "\"\\n\"", ")", ".", "getBytes", "(", ")", ")", ";", "output", ".", "write", "(", "(", "e", ".", "getValue", "(", ")", "+", "\"\\n\"", ")", ".", "getBytes", "(", ")", ")", ";", "}", "java", ".", "nio", ".", "file", ".", "Files", ".", "write", "(", "listenerFilePaths", ".", "toPath", "(", ")", ",", "output", ".", "toByteArray", "(", ")", ",", "StandardOpenOption", ".", "TRUNCATE_EXISTING", ")", ";", "return", "true", ";", "}" ]
You can remove a filelistener from the system identifying it with it's Storagename. The listeners have to be shutdown to do this task. @param pResourcename @return true if resource could be removed @throws IOException @throws TTException @throws ResourceNotExistingException
[ "You", "can", "remove", "a", "filelistener", "from", "the", "system", "identifying", "it", "with", "it", "s", "Storagename", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L521-L543
143,656
sebastiangraf/treetank
interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java
Filelistener.getFileListenersFromSystem
private static void getFileListenersFromSystem(File pListenerFilePaths) throws IOException { if (!pListenerFilePaths.exists()) { java.nio.file.Files.createFile(pListenerFilePaths.toPath()); } else { byte[] bytes = java.nio.file.Files.readAllBytes(pListenerFilePaths.toPath()); ByteArrayDataInput input = ByteStreams.newDataInput(bytes); String key; while ((key = input.readLine()) != null) { String val = input.readLine(); mFilelistenerToPaths.put(key, val); } } }
java
private static void getFileListenersFromSystem(File pListenerFilePaths) throws IOException { if (!pListenerFilePaths.exists()) { java.nio.file.Files.createFile(pListenerFilePaths.toPath()); } else { byte[] bytes = java.nio.file.Files.readAllBytes(pListenerFilePaths.toPath()); ByteArrayDataInput input = ByteStreams.newDataInput(bytes); String key; while ((key = input.readLine()) != null) { String val = input.readLine(); mFilelistenerToPaths.put(key, val); } } }
[ "private", "static", "void", "getFileListenersFromSystem", "(", "File", "pListenerFilePaths", ")", "throws", "IOException", "{", "if", "(", "!", "pListenerFilePaths", ".", "exists", "(", ")", ")", "{", "java", ".", "nio", ".", "file", ".", "Files", ".", "createFile", "(", "pListenerFilePaths", ".", "toPath", "(", ")", ")", ";", "}", "else", "{", "byte", "[", "]", "bytes", "=", "java", ".", "nio", ".", "file", ".", "Files", ".", "readAllBytes", "(", "pListenerFilePaths", ".", "toPath", "(", ")", ")", ";", "ByteArrayDataInput", "input", "=", "ByteStreams", ".", "newDataInput", "(", "bytes", ")", ";", "String", "key", ";", "while", "(", "(", "key", "=", "input", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "String", "val", "=", "input", ".", "readLine", "(", ")", ";", "mFilelistenerToPaths", ".", "put", "(", "key", ",", "val", ")", ";", "}", "}", "}" ]
This is a helper method that let's you initialize mFilelistenerToPaths with all the filelisteners that have been stored in the filesystem. @param pListenerFilePaths @throws IOException
[ "This", "is", "a", "helper", "method", "that", "let", "s", "you", "initialize", "mFilelistenerToPaths", "with", "all", "the", "filelisteners", "that", "have", "been", "stored", "in", "the", "filesystem", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/filelistener/src/main/java/org/treetank/filelistener/file/Filelistener.java#L552-L567
143,657
centic9/commons-dost
src/main/java/org/dstadler/commons/collections/MapUtils.java
MapUtils.sortByValue
public static <K, V extends Comparable<V>> List<Entry<K, V>> sortByValue(Map<K, V> map) { List<Entry<K, V>> entries = new ArrayList<>(map.entrySet()); entries.sort(new ByValue<>()); return entries; }
java
public static <K, V extends Comparable<V>> List<Entry<K, V>> sortByValue(Map<K, V> map) { List<Entry<K, V>> entries = new ArrayList<>(map.entrySet()); entries.sort(new ByValue<>()); return entries; }
[ "public", "static", "<", "K", ",", "V", "extends", "Comparable", "<", "V", ">", ">", "List", "<", "Entry", "<", "K", ",", "V", ">", ">", "sortByValue", "(", "Map", "<", "K", ",", "V", ">", "map", ")", "{", "List", "<", "Entry", "<", "K", ",", "V", ">", ">", "entries", "=", "new", "ArrayList", "<>", "(", "map", ".", "entrySet", "(", ")", ")", ";", "entries", ".", "sort", "(", "new", "ByValue", "<>", "(", ")", ")", ";", "return", "entries", ";", "}" ]
Sorts the provided Map by the value instead of by key like TreeMap does. The Value-Type needs to implement the Comparable-interface. Note: this will require one Map.Entry for each element in the Map, so for very large Maps this will incur some memory overhead but will not fully duplicate the contents of the map. @param <K> the key-type of the Map that should be sorted @param <V> the value-type of the Map that should be sorted. Needs to derive from {@link Comparable} @param map A map with some elements which should be sorted by Value. @return Returns a new List of Map.Entry values sorted by value.
[ "Sorts", "the", "provided", "Map", "by", "the", "value", "instead", "of", "by", "key", "like", "TreeMap", "does", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/collections/MapUtils.java#L34-L38
143,658
centic9/commons-dost
src/main/java/org/dstadler/commons/collections/MapUtils.java
MapUtils.sortByValueAndKey
public static <K extends Comparable<K>, V extends Comparable<V>> List<Map.Entry<K, V>> sortByValueAndKey(Map<K, V> map) { List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet()); entries.sort(new ByValueAndKey<>()); return entries; }
java
public static <K extends Comparable<K>, V extends Comparable<V>> List<Map.Entry<K, V>> sortByValueAndKey(Map<K, V> map) { List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet()); entries.sort(new ByValueAndKey<>()); return entries; }
[ "public", "static", "<", "K", "extends", "Comparable", "<", "K", ">", ",", "V", "extends", "Comparable", "<", "V", ">", ">", "List", "<", "Map", ".", "Entry", "<", "K", ",", "V", ">", ">", "sortByValueAndKey", "(", "Map", "<", "K", ",", "V", ">", "map", ")", "{", "List", "<", "Map", ".", "Entry", "<", "K", ",", "V", ">", ">", "entries", "=", "new", "ArrayList", "<>", "(", "map", ".", "entrySet", "(", ")", ")", ";", "entries", ".", "sort", "(", "new", "ByValueAndKey", "<>", "(", ")", ")", ";", "return", "entries", ";", "}" ]
Sorts the provided Map by the value and then by key instead of by key like TreeMap does. The Value-Type and Key-Type need to implement the Comparable-interface. Note: this will require one Map.Entry for each element in the Map, so for very large Maps this will incur some memory overhead but will not fully duplicate the contents of the map. @param <K> the key-type of the Map that should be sorted Needs to derive from {@link Comparable} @param <V> the value-type of the Map that should be sorted. Needs to derive from {@link Comparable} @param map A map with some elements which should be sorted by Value first and then by Key. @return Returns a new List of Map.Entry values sorted by value and key.
[ "Sorts", "the", "provided", "Map", "by", "the", "value", "and", "then", "by", "key", "instead", "of", "by", "key", "like", "TreeMap", "does", "." ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/collections/MapUtils.java#L56-L60
143,659
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getReqPar
public String getReqPar(final String name, final String def) { final String s = Util.checkNull(request.getParameter(name)); if (s != null) { return s; } return def; }
java
public String getReqPar(final String name, final String def) { final String s = Util.checkNull(request.getParameter(name)); if (s != null) { return s; } return def; }
[ "public", "String", "getReqPar", "(", "final", "String", "name", ",", "final", "String", "def", ")", "{", "final", "String", "s", "=", "Util", ".", "checkNull", "(", "request", ".", "getParameter", "(", "name", ")", ")", ";", "if", "(", "s", "!=", "null", ")", "{", "return", "s", ";", "}", "return", "def", ";", "}" ]
Get a request parameter stripped of white space. Return default for null or zero length. @param name name of parameter @param def default value @return String value
[ "Get", "a", "request", "parameter", "stripped", "of", "white", "space", ".", "Return", "default", "for", "null", "or", "zero", "length", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L98-L106
143,660
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getIntReqPar
public Integer getIntReqPar(final String name) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return null; } return Integer.valueOf(reqpar); }
java
public Integer getIntReqPar(final String name) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return null; } return Integer.valueOf(reqpar); }
[ "public", "Integer", "getIntReqPar", "(", "final", "String", "name", ")", "throws", "Throwable", "{", "String", "reqpar", "=", "getReqPar", "(", "name", ")", ";", "if", "(", "reqpar", "==", "null", ")", "{", "return", "null", ";", "}", "return", "Integer", ".", "valueOf", "(", "reqpar", ")", ";", "}" ]
Get an Integer request parameter or null. @param name name of parameter @return Integer value or null @throws Throwable
[ "Get", "an", "Integer", "request", "parameter", "or", "null", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L162-L170
143,661
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getIntReqPar
public int getIntReqPar(final String name, final int defaultVal) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return defaultVal; } try { return Integer.parseInt(reqpar); } catch (Throwable t) { return defaultVal; // XXX exception? } }
java
public int getIntReqPar(final String name, final int defaultVal) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return defaultVal; } try { return Integer.parseInt(reqpar); } catch (Throwable t) { return defaultVal; // XXX exception? } }
[ "public", "int", "getIntReqPar", "(", "final", "String", "name", ",", "final", "int", "defaultVal", ")", "throws", "Throwable", "{", "String", "reqpar", "=", "getReqPar", "(", "name", ")", ";", "if", "(", "reqpar", "==", "null", ")", "{", "return", "defaultVal", ";", "}", "try", "{", "return", "Integer", ".", "parseInt", "(", "reqpar", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "return", "defaultVal", ";", "// XXX exception?", "}", "}" ]
Get an integer valued request parameter. @param name name of parameter @param defaultVal @return int value @throws Throwable
[ "Get", "an", "integer", "valued", "request", "parameter", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L179-L192
143,662
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getLongReqPar
public Long getLongReqPar(final String name) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return null; } return Long.valueOf(reqpar); }
java
public Long getLongReqPar(final String name) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return null; } return Long.valueOf(reqpar); }
[ "public", "Long", "getLongReqPar", "(", "final", "String", "name", ")", "throws", "Throwable", "{", "String", "reqpar", "=", "getReqPar", "(", "name", ")", ";", "if", "(", "reqpar", "==", "null", ")", "{", "return", "null", ";", "}", "return", "Long", ".", "valueOf", "(", "reqpar", ")", ";", "}" ]
Get a Long request parameter or null. @param name name of parameter @return Long value or null @throws Throwable
[ "Get", "a", "Long", "request", "parameter", "or", "null", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L200-L208
143,663
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getLongReqPar
public long getLongReqPar(final String name, final long defaultVal) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return defaultVal; } try { return Long.parseLong(reqpar); } catch (Throwable t) { return defaultVal; // XXX exception? } }
java
public long getLongReqPar(final String name, final long defaultVal) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return defaultVal; } try { return Long.parseLong(reqpar); } catch (Throwable t) { return defaultVal; // XXX exception? } }
[ "public", "long", "getLongReqPar", "(", "final", "String", "name", ",", "final", "long", "defaultVal", ")", "throws", "Throwable", "{", "String", "reqpar", "=", "getReqPar", "(", "name", ")", ";", "if", "(", "reqpar", "==", "null", ")", "{", "return", "defaultVal", ";", "}", "try", "{", "return", "Long", ".", "parseLong", "(", "reqpar", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "return", "defaultVal", ";", "// XXX exception?", "}", "}" ]
Get an long valued request parameter. @param name name of parameter @param defaultVal @return long value @throws Throwable
[ "Get", "an", "long", "valued", "request", "parameter", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L217-L230
143,664
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getBooleanReqPar
public Boolean getBooleanReqPar(final String name) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return null; } try { if (reqpar.equalsIgnoreCase("yes")) { reqpar = "true"; } return Boolean.valueOf(reqpar); } catch (Throwable t) { return null; // XXX exception? } }
java
public Boolean getBooleanReqPar(final String name) throws Throwable { String reqpar = getReqPar(name); if (reqpar == null) { return null; } try { if (reqpar.equalsIgnoreCase("yes")) { reqpar = "true"; } return Boolean.valueOf(reqpar); } catch (Throwable t) { return null; // XXX exception? } }
[ "public", "Boolean", "getBooleanReqPar", "(", "final", "String", "name", ")", "throws", "Throwable", "{", "String", "reqpar", "=", "getReqPar", "(", "name", ")", ";", "if", "(", "reqpar", "==", "null", ")", "{", "return", "null", ";", "}", "try", "{", "if", "(", "reqpar", ".", "equalsIgnoreCase", "(", "\"yes\"", ")", ")", "{", "reqpar", "=", "\"true\"", ";", "}", "return", "Boolean", ".", "valueOf", "(", "reqpar", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "return", "null", ";", "// XXX exception?", "}", "}" ]
Get a boolean valued request parameter. @param name name of parameter @return Boolean value or null for absent parameter @throws Throwable
[ "Get", "a", "boolean", "valued", "request", "parameter", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L238-L254
143,665
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getBooleanReqPar
public boolean getBooleanReqPar(final String name, final boolean defVal) throws Throwable { boolean val = defVal; Boolean valB = getBooleanReqPar(name); if (valB != null) { val = valB; } return val; }
java
public boolean getBooleanReqPar(final String name, final boolean defVal) throws Throwable { boolean val = defVal; Boolean valB = getBooleanReqPar(name); if (valB != null) { val = valB; } return val; }
[ "public", "boolean", "getBooleanReqPar", "(", "final", "String", "name", ",", "final", "boolean", "defVal", ")", "throws", "Throwable", "{", "boolean", "val", "=", "defVal", ";", "Boolean", "valB", "=", "getBooleanReqPar", "(", "name", ")", ";", "if", "(", "valB", "!=", "null", ")", "{", "val", "=", "valB", ";", "}", "return", "val", ";", "}" ]
Get a boolean valued request parameter giving a default value. @param name name of parameter @param defVal default value for absent parameter @return boolean value @throws Throwable
[ "Get", "a", "boolean", "valued", "request", "parameter", "giving", "a", "default", "value", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L263-L272
143,666
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.setSessionAttr
public void setSessionAttr(final String attrName, final Object val) { final HttpSession sess = request.getSession(false); if (sess == null) { return; } sess.setAttribute(attrName, val); }
java
public void setSessionAttr(final String attrName, final Object val) { final HttpSession sess = request.getSession(false); if (sess == null) { return; } sess.setAttribute(attrName, val); }
[ "public", "void", "setSessionAttr", "(", "final", "String", "attrName", ",", "final", "Object", "val", ")", "{", "final", "HttpSession", "sess", "=", "request", ".", "getSession", "(", "false", ")", ";", "if", "(", "sess", "==", "null", ")", "{", "return", ";", "}", "sess", ".", "setAttribute", "(", "attrName", ",", "val", ")", ";", "}" ]
Set the value of a named session attribute. @param attrName Name of the attribute @param val Object
[ "Set", "the", "value", "of", "a", "named", "session", "attribute", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L279-L288
143,667
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.removeSessionAttr
public void removeSessionAttr(final String attrName) { final HttpSession sess = request.getSession(false); if (sess == null) { return; } sess.removeAttribute(attrName); }
java
public void removeSessionAttr(final String attrName) { final HttpSession sess = request.getSession(false); if (sess == null) { return; } sess.removeAttribute(attrName); }
[ "public", "void", "removeSessionAttr", "(", "final", "String", "attrName", ")", "{", "final", "HttpSession", "sess", "=", "request", ".", "getSession", "(", "false", ")", ";", "if", "(", "sess", "==", "null", ")", "{", "return", ";", "}", "sess", ".", "removeAttribute", "(", "attrName", ")", ";", "}" ]
Remove a named session attribute. @param attrName Name of the attribute
[ "Remove", "a", "named", "session", "attribute", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L294-L302
143,668
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java
ReqUtil.getSessionAttr
public Object getSessionAttr(final String attrName) { final HttpSession sess = request.getSession(false); if (sess == null) { return null; } return sess.getAttribute(attrName); }
java
public Object getSessionAttr(final String attrName) { final HttpSession sess = request.getSession(false); if (sess == null) { return null; } return sess.getAttribute(attrName); }
[ "public", "Object", "getSessionAttr", "(", "final", "String", "attrName", ")", "{", "final", "HttpSession", "sess", "=", "request", ".", "getSession", "(", "false", ")", ";", "if", "(", "sess", "==", "null", ")", "{", "return", "null", ";", "}", "return", "sess", ".", "getAttribute", "(", "attrName", ")", ";", "}" ]
Return the value of a named session attribute. @param attrName Name of the attribute @return Object Attribute value or null
[ "Return", "the", "value", "of", "a", "named", "session", "attribute", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/ReqUtil.java#L309-L317
143,669
Bedework/bw-util
bw-util-jmx/src/main/java/org/bedework/util/jmx/AnnotatedMBean.java
AnnotatedMBean.registerMBean
@SuppressWarnings("unchecked") public static void registerMBean(final ManagementContext context, final Object object, final ObjectName objectName) throws Exception { String mbeanName = object.getClass().getName() + "MBean"; for (Class c : object.getClass().getInterfaces()) { if (mbeanName.equals(c.getName())) { context.registerMBean(new AnnotatedMBean(object, c), objectName); return; } } context.registerMBean(object, objectName); }
java
@SuppressWarnings("unchecked") public static void registerMBean(final ManagementContext context, final Object object, final ObjectName objectName) throws Exception { String mbeanName = object.getClass().getName() + "MBean"; for (Class c : object.getClass().getInterfaces()) { if (mbeanName.equals(c.getName())) { context.registerMBean(new AnnotatedMBean(object, c), objectName); return; } } context.registerMBean(object, objectName); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "void", "registerMBean", "(", "final", "ManagementContext", "context", ",", "final", "Object", "object", ",", "final", "ObjectName", "objectName", ")", "throws", "Exception", "{", "String", "mbeanName", "=", "object", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\"MBean\"", ";", "for", "(", "Class", "c", ":", "object", ".", "getClass", "(", ")", ".", "getInterfaces", "(", ")", ")", "{", "if", "(", "mbeanName", ".", "equals", "(", "c", ".", "getName", "(", ")", ")", ")", "{", "context", ".", "registerMBean", "(", "new", "AnnotatedMBean", "(", "object", ",", "c", ")", ",", "objectName", ")", ";", "return", ";", "}", "}", "context", ".", "registerMBean", "(", "object", ",", "objectName", ")", ";", "}" ]
Register an mbean with the jmx context @param context @param object @param objectName @throws Exception
[ "Register", "an", "mbean", "with", "the", "jmx", "context" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-jmx/src/main/java/org/bedework/util/jmx/AnnotatedMBean.java#L58-L74
143,670
Bedework/bw-util
bw-util-jmx/src/main/java/org/bedework/util/jmx/AnnotatedMBean.java
AnnotatedMBean.getMethod
private Method getMethod(final MBeanOperationInfo op) { final MBeanParameterInfo[] params = op.getSignature(); final String[] paramTypes = new String[params.length]; for (int i = 0; i < params.length; i++) { paramTypes[i] = params[i].getType(); } return getMethod(getMBeanInterface(), op.getName(), paramTypes); }
java
private Method getMethod(final MBeanOperationInfo op) { final MBeanParameterInfo[] params = op.getSignature(); final String[] paramTypes = new String[params.length]; for (int i = 0; i < params.length; i++) { paramTypes[i] = params[i].getType(); } return getMethod(getMBeanInterface(), op.getName(), paramTypes); }
[ "private", "Method", "getMethod", "(", "final", "MBeanOperationInfo", "op", ")", "{", "final", "MBeanParameterInfo", "[", "]", "params", "=", "op", ".", "getSignature", "(", ")", ";", "final", "String", "[", "]", "paramTypes", "=", "new", "String", "[", "params", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "params", ".", "length", ";", "i", "++", ")", "{", "paramTypes", "[", "i", "]", "=", "params", "[", "i", "]", ".", "getType", "(", ")", ";", "}", "return", "getMethod", "(", "getMBeanInterface", "(", ")", ",", "op", ".", "getName", "(", ")", ",", "paramTypes", ")", ";", "}" ]
Extracts the Method from the MBeanOperationInfo @param op @return
[ "Extracts", "the", "Method", "from", "the", "MBeanOperationInfo" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-jmx/src/main/java/org/bedework/util/jmx/AnnotatedMBean.java#L156-L164
143,671
Bedework/bw-util
bw-util-jmx/src/main/java/org/bedework/util/jmx/AnnotatedMBean.java
AnnotatedMBean.getMethod
private static Method getMethod(final Class<?> mbean, final String method, final String... params) { try { final ClassLoader loader = mbean.getClassLoader(); final Class<?>[] paramClasses = new Class<?>[params.length]; for (int i = 0; i < params.length; i++) { paramClasses[i] = primitives.get(params[i]); if (paramClasses[i] == null) { paramClasses[i] = Class.forName(params[i], false, loader); } } return mbean.getMethod(method, paramClasses); } catch (RuntimeException e) { throw e; } catch (Exception e) { return null; } }
java
private static Method getMethod(final Class<?> mbean, final String method, final String... params) { try { final ClassLoader loader = mbean.getClassLoader(); final Class<?>[] paramClasses = new Class<?>[params.length]; for (int i = 0; i < params.length; i++) { paramClasses[i] = primitives.get(params[i]); if (paramClasses[i] == null) { paramClasses[i] = Class.forName(params[i], false, loader); } } return mbean.getMethod(method, paramClasses); } catch (RuntimeException e) { throw e; } catch (Exception e) { return null; } }
[ "private", "static", "Method", "getMethod", "(", "final", "Class", "<", "?", ">", "mbean", ",", "final", "String", "method", ",", "final", "String", "...", "params", ")", "{", "try", "{", "final", "ClassLoader", "loader", "=", "mbean", ".", "getClassLoader", "(", ")", ";", "final", "Class", "<", "?", ">", "[", "]", "paramClasses", "=", "new", "Class", "<", "?", ">", "[", "params", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "params", ".", "length", ";", "i", "++", ")", "{", "paramClasses", "[", "i", "]", "=", "primitives", ".", "get", "(", "params", "[", "i", "]", ")", ";", "if", "(", "paramClasses", "[", "i", "]", "==", "null", ")", "{", "paramClasses", "[", "i", "]", "=", "Class", ".", "forName", "(", "params", "[", "i", "]", ",", "false", ",", "loader", ")", ";", "}", "}", "return", "mbean", ".", "getMethod", "(", "method", ",", "paramClasses", ")", ";", "}", "catch", "(", "RuntimeException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "null", ";", "}", "}" ]
Returns the Method with the specified name and parameter types for the given class, null if it doesn't exist. @param mbean @param method @param params @return
[ "Returns", "the", "Method", "with", "the", "specified", "name", "and", "parameter", "types", "for", "the", "given", "class", "null", "if", "it", "doesn", "t", "exist", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-jmx/src/main/java/org/bedework/util/jmx/AnnotatedMBean.java#L174-L192
143,672
sebastiangraf/treetank
coremodules/commons/src/main/java/org/treetank/aspects/logging/LoggerAspect.java
LoggerAspect.advice
@Around("@annotation(org.treetank.aspects.logging.Logging)") public Object advice(ProceedingJoinPoint pjp) throws Throwable { final Signature sig = pjp.getSignature(); final Logger logger = FACTORY.getLogger(sig.getDeclaringTypeName()); logger.debug(new StringBuilder("Entering ").append(sig.getDeclaringTypeName()).toString()); final Object returnVal = pjp.proceed(); logger.debug(new StringBuilder("Exiting ").append(sig.getDeclaringTypeName()).toString()); return returnVal; }
java
@Around("@annotation(org.treetank.aspects.logging.Logging)") public Object advice(ProceedingJoinPoint pjp) throws Throwable { final Signature sig = pjp.getSignature(); final Logger logger = FACTORY.getLogger(sig.getDeclaringTypeName()); logger.debug(new StringBuilder("Entering ").append(sig.getDeclaringTypeName()).toString()); final Object returnVal = pjp.proceed(); logger.debug(new StringBuilder("Exiting ").append(sig.getDeclaringTypeName()).toString()); return returnVal; }
[ "@", "Around", "(", "\"@annotation(org.treetank.aspects.logging.Logging)\"", ")", "public", "Object", "advice", "(", "ProceedingJoinPoint", "pjp", ")", "throws", "Throwable", "{", "final", "Signature", "sig", "=", "pjp", ".", "getSignature", "(", ")", ";", "final", "Logger", "logger", "=", "FACTORY", ".", "getLogger", "(", "sig", ".", "getDeclaringTypeName", "(", ")", ")", ";", "logger", ".", "debug", "(", "new", "StringBuilder", "(", "\"Entering \"", ")", ".", "append", "(", "sig", ".", "getDeclaringTypeName", "(", ")", ")", ".", "toString", "(", ")", ")", ";", "final", "Object", "returnVal", "=", "pjp", ".", "proceed", "(", ")", ";", "logger", ".", "debug", "(", "new", "StringBuilder", "(", "\"Exiting \"", ")", ".", "append", "(", "sig", ".", "getDeclaringTypeName", "(", ")", ")", ".", "toString", "(", ")", ")", ";", "return", "returnVal", ";", "}" ]
Injection point for logging aspect @param pjp where the inject takes pace @return the point reaches @throws Throwable if anything happens
[ "Injection", "point", "for", "logging", "aspect" ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/commons/src/main/java/org/treetank/aspects/logging/LoggerAspect.java#L51-L59
143,673
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/treetank/service/jaxrx/util/RestXPathProcessor.java
RestXPathProcessor.doXPathRes
private void doXPathRes(final String resource, final Long revision, final OutputStream output, final boolean nodeid, final String xpath) throws TTException { // Storage connection to treetank ISession session = null; INodeReadTrx rtx = null; try { if (mDatabase.existsResource(resource)) { session = mDatabase.getSession(new SessionConfiguration(resource, StandardSettings.KEY)); // Creating a transaction if (revision == null) { rtx = new NodeReadTrx(session.beginBucketRtx(session.getMostRecentVersion())); } else { rtx = new NodeReadTrx(session.beginBucketRtx(revision)); } final AbsAxis axis = new XPathAxis(rtx, xpath); for (final long key : axis) { WorkerHelper.serializeXML(session, output, false, nodeid, key, revision).call(); } } } catch (final Exception globExcep) { throw new WebApplicationException(globExcep, Response.Status.INTERNAL_SERVER_ERROR); } finally { WorkerHelper.closeRTX(rtx, session); } }
java
private void doXPathRes(final String resource, final Long revision, final OutputStream output, final boolean nodeid, final String xpath) throws TTException { // Storage connection to treetank ISession session = null; INodeReadTrx rtx = null; try { if (mDatabase.existsResource(resource)) { session = mDatabase.getSession(new SessionConfiguration(resource, StandardSettings.KEY)); // Creating a transaction if (revision == null) { rtx = new NodeReadTrx(session.beginBucketRtx(session.getMostRecentVersion())); } else { rtx = new NodeReadTrx(session.beginBucketRtx(revision)); } final AbsAxis axis = new XPathAxis(rtx, xpath); for (final long key : axis) { WorkerHelper.serializeXML(session, output, false, nodeid, key, revision).call(); } } } catch (final Exception globExcep) { throw new WebApplicationException(globExcep, Response.Status.INTERNAL_SERVER_ERROR); } finally { WorkerHelper.closeRTX(rtx, session); } }
[ "private", "void", "doXPathRes", "(", "final", "String", "resource", ",", "final", "Long", "revision", ",", "final", "OutputStream", "output", ",", "final", "boolean", "nodeid", ",", "final", "String", "xpath", ")", "throws", "TTException", "{", "// Storage connection to treetank", "ISession", "session", "=", "null", ";", "INodeReadTrx", "rtx", "=", "null", ";", "try", "{", "if", "(", "mDatabase", ".", "existsResource", "(", "resource", ")", ")", "{", "session", "=", "mDatabase", ".", "getSession", "(", "new", "SessionConfiguration", "(", "resource", ",", "StandardSettings", ".", "KEY", ")", ")", ";", "// Creating a transaction", "if", "(", "revision", "==", "null", ")", "{", "rtx", "=", "new", "NodeReadTrx", "(", "session", ".", "beginBucketRtx", "(", "session", ".", "getMostRecentVersion", "(", ")", ")", ")", ";", "}", "else", "{", "rtx", "=", "new", "NodeReadTrx", "(", "session", ".", "beginBucketRtx", "(", "revision", ")", ")", ";", "}", "final", "AbsAxis", "axis", "=", "new", "XPathAxis", "(", "rtx", ",", "xpath", ")", ";", "for", "(", "final", "long", "key", ":", "axis", ")", "{", "WorkerHelper", ".", "serializeXML", "(", "session", ",", "output", ",", "false", ",", "nodeid", ",", "key", ",", "revision", ")", ".", "call", "(", ")", ";", "}", "}", "}", "catch", "(", "final", "Exception", "globExcep", ")", "{", "throw", "new", "WebApplicationException", "(", "globExcep", ",", "Response", ".", "Status", ".", "INTERNAL_SERVER_ERROR", ")", ";", "}", "finally", "{", "WorkerHelper", ".", "closeRTX", "(", "rtx", ",", "session", ")", ";", "}", "}" ]
This method performs an XPath evaluation and writes it to a given output stream. @param resource The existing resource. @param revision The revision of the requested document. @param output The output stream where the results are written. @param nodeid <code>true</code> if node id's have to be delivered. <code>false</code> otherwise. @param xpath The XPath expression. @throws TTException
[ "This", "method", "performs", "an", "XPath", "evaluation", "and", "writes", "it", "to", "a", "given", "output", "stream", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/treetank/service/jaxrx/util/RestXPathProcessor.java#L216-L242
143,674
Bedework/bw-util
bw-util-config/src/main/java/org/bedework/util/config/ConfigurationFileStore.java
ConfigurationFileStore.getStore
@Override public ConfigurationStore getStore(final String name) throws ConfigException { try { final File dir = new File(dirPath); final String newPath = dirPath + name; final File[] files = dir.listFiles(new DirsOnly()); for (final File f: files) { if (f.getName().equals(name)) { return new ConfigurationFileStore(newPath); } } final File newDir = new File(newPath); if (!newDir.mkdir()) { throw new ConfigException("Unable to create directory " + newPath); } return new ConfigurationFileStore(newPath); } catch (final Throwable t) { throw new ConfigException(t); } }
java
@Override public ConfigurationStore getStore(final String name) throws ConfigException { try { final File dir = new File(dirPath); final String newPath = dirPath + name; final File[] files = dir.listFiles(new DirsOnly()); for (final File f: files) { if (f.getName().equals(name)) { return new ConfigurationFileStore(newPath); } } final File newDir = new File(newPath); if (!newDir.mkdir()) { throw new ConfigException("Unable to create directory " + newPath); } return new ConfigurationFileStore(newPath); } catch (final Throwable t) { throw new ConfigException(t); } }
[ "@", "Override", "public", "ConfigurationStore", "getStore", "(", "final", "String", "name", ")", "throws", "ConfigException", "{", "try", "{", "final", "File", "dir", "=", "new", "File", "(", "dirPath", ")", ";", "final", "String", "newPath", "=", "dirPath", "+", "name", ";", "final", "File", "[", "]", "files", "=", "dir", ".", "listFiles", "(", "new", "DirsOnly", "(", ")", ")", ";", "for", "(", "final", "File", "f", ":", "files", ")", "{", "if", "(", "f", ".", "getName", "(", ")", ".", "equals", "(", "name", ")", ")", "{", "return", "new", "ConfigurationFileStore", "(", "newPath", ")", ";", "}", "}", "final", "File", "newDir", "=", "new", "File", "(", "newPath", ")", ";", "if", "(", "!", "newDir", ".", "mkdir", "(", ")", ")", "{", "throw", "new", "ConfigException", "(", "\"Unable to create directory \"", "+", "newPath", ")", ";", "}", "return", "new", "ConfigurationFileStore", "(", "newPath", ")", ";", "}", "catch", "(", "final", "Throwable", "t", ")", "{", "throw", "new", "ConfigException", "(", "t", ")", ";", "}", "}" ]
Get the named store. Create it if it does not exist @param name of config @return store @throws ConfigException
[ "Get", "the", "named", "store", ".", "Create", "it", "if", "it", "does", "not", "exist" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-config/src/main/java/org/bedework/util/config/ConfigurationFileStore.java#L176-L199
143,675
Bedework/bw-util
bw-util-json/src/main/java/org/bedework/util/json/JsonUtil.java
JsonUtil.jsonNameVal
public static String jsonNameVal(final String indent, final String name, final String val) { StringBuilder sb = new StringBuilder(); sb.append(indent); sb.append("\""); sb.append(name); sb.append("\": "); if (val != null) { sb.append(jsonEncode(val)); } return sb.toString(); }
java
public static String jsonNameVal(final String indent, final String name, final String val) { StringBuilder sb = new StringBuilder(); sb.append(indent); sb.append("\""); sb.append(name); sb.append("\": "); if (val != null) { sb.append(jsonEncode(val)); } return sb.toString(); }
[ "public", "static", "String", "jsonNameVal", "(", "final", "String", "indent", ",", "final", "String", "name", ",", "final", "String", "val", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "indent", ")", ";", "sb", ".", "append", "(", "\"\\\"\"", ")", ";", "sb", ".", "append", "(", "name", ")", ";", "sb", ".", "append", "(", "\"\\\": \"", ")", ";", "if", "(", "val", "!=", "null", ")", "{", "sb", ".", "append", "(", "jsonEncode", "(", "val", ")", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Encode a json name and value for output @param indent initial space @param name of field @param val and value @return encoded String
[ "Encode", "a", "json", "name", "and", "value", "for", "output" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-json/src/main/java/org/bedework/util/json/JsonUtil.java#L120-L135
143,676
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResponseBuilder.java
ResponseBuilder.createResultElement
private static Element createResultElement(final Document document) { return document.createElementNS(JaxRxConstants.URL, JaxRxConstants.JAXRX + ":results"); }
java
private static Element createResultElement(final Document document) { return document.createElementNS(JaxRxConstants.URL, JaxRxConstants.JAXRX + ":results"); }
[ "private", "static", "Element", "createResultElement", "(", "final", "Document", "document", ")", "{", "return", "document", ".", "createElementNS", "(", "JaxRxConstants", ".", "URL", ",", "JaxRxConstants", ".", "JAXRX", "+", "\":results\"", ")", ";", "}" ]
This method creates the response XML element. @param document The {@link Document} instance for the response. @return The created XML {@link Element}.
[ "This", "method", "creates", "the", "response", "XML", "element", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResponseBuilder.java#L103-L105
143,677
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResponseBuilder.java
ResponseBuilder.buildDOMResponse
public static StreamingOutput buildDOMResponse(final List<String> availableResources) { try { final Document document = createSurroundingXMLResp(); final Element resElement = createResultElement(document); final List<Element> resources = createCollectionElement(availableResources, document); for (final Element resource : resources) { resElement.appendChild(resource); } document.appendChild(resElement); return createStream(document); } catch (final ParserConfigurationException exc) { throw new JaxRxException(exc); } }
java
public static StreamingOutput buildDOMResponse(final List<String> availableResources) { try { final Document document = createSurroundingXMLResp(); final Element resElement = createResultElement(document); final List<Element> resources = createCollectionElement(availableResources, document); for (final Element resource : resources) { resElement.appendChild(resource); } document.appendChild(resElement); return createStream(document); } catch (final ParserConfigurationException exc) { throw new JaxRxException(exc); } }
[ "public", "static", "StreamingOutput", "buildDOMResponse", "(", "final", "List", "<", "String", ">", "availableResources", ")", "{", "try", "{", "final", "Document", "document", "=", "createSurroundingXMLResp", "(", ")", ";", "final", "Element", "resElement", "=", "createResultElement", "(", "document", ")", ";", "final", "List", "<", "Element", ">", "resources", "=", "createCollectionElement", "(", "availableResources", ",", "document", ")", ";", "for", "(", "final", "Element", "resource", ":", "resources", ")", "{", "resElement", ".", "appendChild", "(", "resource", ")", ";", "}", "document", ".", "appendChild", "(", "resElement", ")", ";", "return", "createStream", "(", "document", ")", ";", "}", "catch", "(", "final", "ParserConfigurationException", "exc", ")", "{", "throw", "new", "JaxRxException", "(", "exc", ")", ";", "}", "}" ]
Builds a DOM response. @param availableResources list of resources to include in the output @return streaming output
[ "Builds", "a", "DOM", "response", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResponseBuilder.java#L114-L129
143,678
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResponseBuilder.java
ResponseBuilder.createStream
public static StreamingOutput createStream(final Document doc) { return new StreamingOutput() { @Override public void write(final OutputStream output) { synchronized (output) { final DOMSource domSource = new DOMSource(doc); final StreamResult streamResult = new StreamResult(output); Transformer transformer; try { transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final TransformerException exc) { exc.printStackTrace(); throw new JaxRxException(exc); } } } }; }
java
public static StreamingOutput createStream(final Document doc) { return new StreamingOutput() { @Override public void write(final OutputStream output) { synchronized (output) { final DOMSource domSource = new DOMSource(doc); final StreamResult streamResult = new StreamResult(output); Transformer transformer; try { transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final TransformerException exc) { exc.printStackTrace(); throw new JaxRxException(exc); } } } }; }
[ "public", "static", "StreamingOutput", "createStream", "(", "final", "Document", "doc", ")", "{", "return", "new", "StreamingOutput", "(", ")", "{", "@", "Override", "public", "void", "write", "(", "final", "OutputStream", "output", ")", "{", "synchronized", "(", "output", ")", "{", "final", "DOMSource", "domSource", "=", "new", "DOMSource", "(", "doc", ")", ";", "final", "StreamResult", "streamResult", "=", "new", "StreamResult", "(", "output", ")", ";", "Transformer", "transformer", ";", "try", "{", "transformer", "=", "TransformerFactory", ".", "newInstance", "(", ")", ".", "newTransformer", "(", ")", ";", "transformer", ".", "transform", "(", "domSource", ",", "streamResult", ")", ";", "}", "catch", "(", "final", "TransformerException", "exc", ")", "{", "exc", ".", "printStackTrace", "(", ")", ";", "throw", "new", "JaxRxException", "(", "exc", ")", ";", "}", "}", "}", "}", ";", "}" ]
Creates an output stream from the specified document. @param doc document input @return output stream
[ "Creates", "an", "output", "stream", "from", "the", "specified", "document", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResponseBuilder.java#L138-L158
143,679
Bedework/bw-util
bw-util-security/src/main/java/org/bedework/util/security/pki/PKITools.java
PKITools.writeFile
private void writeFile(final String fileName, final byte[] bs, final boolean append) throws IOException { FileOutputStream fstr = null; try { fstr = new FileOutputStream(fileName, append); fstr.write(bs); // Terminate key with newline fstr.write('\n'); fstr.flush(); } finally { if (fstr != null) { fstr.close(); } } }
java
private void writeFile(final String fileName, final byte[] bs, final boolean append) throws IOException { FileOutputStream fstr = null; try { fstr = new FileOutputStream(fileName, append); fstr.write(bs); // Terminate key with newline fstr.write('\n'); fstr.flush(); } finally { if (fstr != null) { fstr.close(); } } }
[ "private", "void", "writeFile", "(", "final", "String", "fileName", ",", "final", "byte", "[", "]", "bs", ",", "final", "boolean", "append", ")", "throws", "IOException", "{", "FileOutputStream", "fstr", "=", "null", ";", "try", "{", "fstr", "=", "new", "FileOutputStream", "(", "fileName", ",", "append", ")", ";", "fstr", ".", "write", "(", "bs", ")", ";", "// Terminate key with newline", "fstr", ".", "write", "(", "'", "'", ")", ";", "fstr", ".", "flush", "(", ")", ";", "}", "finally", "{", "if", "(", "fstr", "!=", "null", ")", "{", "fstr", ".", "close", "(", ")", ";", "}", "}", "}" ]
Write a single string to a file. Used to write keys @param fileName String file to write to @param bs bytes to write @param append true to add the key to the file. @throws IOException
[ "Write", "a", "single", "string", "to", "a", "file", ".", "Used", "to", "write", "keys" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-security/src/main/java/org/bedework/util/security/pki/PKITools.java#L433-L451
143,680
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/dom/DOMJaxRx.java
DOMJaxRx.root
static String root(final ResourcePath path) { if (path.getDepth() == 1) return path.getResourcePath(); throw new JaxRxException(404, "Resource not found: " + path); }
java
static String root(final ResourcePath path) { if (path.getDepth() == 1) return path.getResourcePath(); throw new JaxRxException(404, "Resource not found: " + path); }
[ "static", "String", "root", "(", "final", "ResourcePath", "path", ")", "{", "if", "(", "path", ".", "getDepth", "(", ")", "==", "1", ")", "return", "path", ".", "getResourcePath", "(", ")", ";", "throw", "new", "JaxRxException", "(", "404", ",", "\"Resource not found: \"", "+", "path", ")", ";", "}" ]
Returns the root resource of the specified path. @param path path @return root resource
[ "Returns", "the", "root", "resource", "of", "the", "specified", "path", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/dom/DOMJaxRx.java#L183-L187
143,681
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResourcePath.java
ResourcePath.getResourcePath
public String getResourcePath() { final StringBuilder sb = new StringBuilder(); for (final String r : resource) sb.append(r + '/'); return sb.substring(0, Math.max(0, sb.length() - 1)); }
java
public String getResourcePath() { final StringBuilder sb = new StringBuilder(); for (final String r : resource) sb.append(r + '/'); return sb.substring(0, Math.max(0, sb.length() - 1)); }
[ "public", "String", "getResourcePath", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "final", "String", "r", ":", "resource", ")", "sb", ".", "append", "(", "r", "+", "'", "'", ")", ";", "return", "sb", ".", "substring", "(", "0", ",", "Math", ".", "max", "(", "0", ",", "sb", ".", "length", "(", ")", "-", "1", ")", ")", ";", "}" ]
Returns the complete resource path string. @return resource path string
[ "Returns", "the", "complete", "resource", "path", "string", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResourcePath.java#L111-L116
143,682
sebastiangraf/treetank
interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResourcePath.java
ResourcePath.getResource
public String getResource(final int level) { if (level < resource.length) { return resource[level]; } // offset is out of bounds... throw new IndexOutOfBoundsException("Index: " + level + ", Size: " + resource.length); }
java
public String getResource(final int level) { if (level < resource.length) { return resource[level]; } // offset is out of bounds... throw new IndexOutOfBoundsException("Index: " + level + ", Size: " + resource.length); }
[ "public", "String", "getResource", "(", "final", "int", "level", ")", "{", "if", "(", "level", "<", "resource", ".", "length", ")", "{", "return", "resource", "[", "level", "]", ";", "}", "// offset is out of bounds...\r", "throw", "new", "IndexOutOfBoundsException", "(", "\"Index: \"", "+", "level", "+", "\", Size: \"", "+", "resource", ".", "length", ")", ";", "}" ]
Returns the resource at the specified level. @param level resource level @return resource
[ "Returns", "the", "resource", "at", "the", "specified", "level", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/jax-rx/src/main/java/org/jaxrx/core/ResourcePath.java#L125-L131
143,683
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/HttpServletUtils.java
HttpServletUtils.getHeaders
public static String getHeaders(final HttpServletRequest req) { Enumeration en = req.getHeaderNames(); StringBuffer sb = new StringBuffer(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); sb.append(name); sb.append(": "); sb.append(req.getHeader(name)); sb.append("\n"); } return sb.toString(); }
java
public static String getHeaders(final HttpServletRequest req) { Enumeration en = req.getHeaderNames(); StringBuffer sb = new StringBuffer(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); sb.append(name); sb.append(": "); sb.append(req.getHeader(name)); sb.append("\n"); } return sb.toString(); }
[ "public", "static", "String", "getHeaders", "(", "final", "HttpServletRequest", "req", ")", "{", "Enumeration", "en", "=", "req", ".", "getHeaderNames", "(", ")", ";", "StringBuffer", "sb", "=", "new", "StringBuffer", "(", ")", ";", "while", "(", "en", ".", "hasMoreElements", "(", ")", ")", "{", "String", "name", "=", "(", "String", ")", "en", ".", "nextElement", "(", ")", ";", "sb", ".", "append", "(", "name", ")", ";", "sb", ".", "append", "(", "\": \"", ")", ";", "sb", ".", "append", "(", "req", ".", "getHeader", "(", "name", ")", ")", ";", "sb", ".", "append", "(", "\"\\n\"", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Return a concatenated string of all the headers @param req Incoming HttpServletRequest object @return header values
[ "Return", "a", "concatenated", "string", "of", "all", "the", "headers" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/HttpServletUtils.java#L230-L242
143,684
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/HttpServletUtils.java
HttpServletUtils.dumpHeaders
public static void dumpHeaders(final HttpServletRequest req) { Enumeration en = req.getHeaderNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); logger.debug(name + ": " + req.getHeader(name)); } }
java
public static void dumpHeaders(final HttpServletRequest req) { Enumeration en = req.getHeaderNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); logger.debug(name + ": " + req.getHeader(name)); } }
[ "public", "static", "void", "dumpHeaders", "(", "final", "HttpServletRequest", "req", ")", "{", "Enumeration", "en", "=", "req", ".", "getHeaderNames", "(", ")", ";", "while", "(", "en", ".", "hasMoreElements", "(", ")", ")", "{", "String", "name", "=", "(", "String", ")", "en", ".", "nextElement", "(", ")", ";", "logger", ".", "debug", "(", "name", "+", "\": \"", "+", "req", ".", "getHeader", "(", "name", ")", ")", ";", "}", "}" ]
Print all the headers @param req Incoming HttpServletRequest object
[ "Print", "all", "the", "headers" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/HttpServletUtils.java#L248-L254
143,685
Bedework/bw-util
bw-util-servlet/src/main/java/org/bedework/util/servlet/HttpServletUtils.java
HttpServletUtils.getLocales
public static Collection<Locale> getLocales(final HttpServletRequest req) { if (req.getHeader("Accept-Language") == null) { return null; } @SuppressWarnings("unchecked") Enumeration<Locale> lcs = req.getLocales(); ArrayList<Locale> locales = new ArrayList<Locale>(); while (lcs.hasMoreElements()) { locales.add(lcs.nextElement()); } return locales; }
java
public static Collection<Locale> getLocales(final HttpServletRequest req) { if (req.getHeader("Accept-Language") == null) { return null; } @SuppressWarnings("unchecked") Enumeration<Locale> lcs = req.getLocales(); ArrayList<Locale> locales = new ArrayList<Locale>(); while (lcs.hasMoreElements()) { locales.add(lcs.nextElement()); } return locales; }
[ "public", "static", "Collection", "<", "Locale", ">", "getLocales", "(", "final", "HttpServletRequest", "req", ")", "{", "if", "(", "req", ".", "getHeader", "(", "\"Accept-Language\"", ")", "==", "null", ")", "{", "return", "null", ";", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "Enumeration", "<", "Locale", ">", "lcs", "=", "req", ".", "getLocales", "(", ")", ";", "ArrayList", "<", "Locale", ">", "locales", "=", "new", "ArrayList", "<", "Locale", ">", "(", ")", ";", "while", "(", "lcs", ".", "hasMoreElements", "(", ")", ")", "{", "locales", ".", "add", "(", "lcs", ".", "nextElement", "(", ")", ")", ";", "}", "return", "locales", ";", "}" ]
If there is no Accept-Language header returns null, otherwise returns a collection of Locales ordered with preferred first. @param req @return Collection of locales or null
[ "If", "there", "is", "no", "Accept", "-", "Language", "header", "returns", "null", "otherwise", "returns", "a", "collection", "of", "Locales", "ordered", "with", "preferred", "first", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-servlet/src/main/java/org/bedework/util/servlet/HttpServletUtils.java#L262-L275
143,686
Bedework/bw-util
bw-util-timezones/src/main/java/org/bedework/util/timezones/Timezones.java
Timezones.initTimezones
public static void initTimezones(final String serverUrl) throws TimezonesException { try { if (tzs == null) { tzs = (Timezones)Class.forName("org.bedework.util.timezones.TimezonesImpl").newInstance(); } tzs.init(serverUrl); } catch (final TimezonesException te) { throw te; } catch (final Throwable t) { throw new TimezonesException(t); } }
java
public static void initTimezones(final String serverUrl) throws TimezonesException { try { if (tzs == null) { tzs = (Timezones)Class.forName("org.bedework.util.timezones.TimezonesImpl").newInstance(); } tzs.init(serverUrl); } catch (final TimezonesException te) { throw te; } catch (final Throwable t) { throw new TimezonesException(t); } }
[ "public", "static", "void", "initTimezones", "(", "final", "String", "serverUrl", ")", "throws", "TimezonesException", "{", "try", "{", "if", "(", "tzs", "==", "null", ")", "{", "tzs", "=", "(", "Timezones", ")", "Class", ".", "forName", "(", "\"org.bedework.util.timezones.TimezonesImpl\"", ")", ".", "newInstance", "(", ")", ";", "}", "tzs", ".", "init", "(", "serverUrl", ")", ";", "}", "catch", "(", "final", "TimezonesException", "te", ")", "{", "throw", "te", ";", "}", "catch", "(", "final", "Throwable", "t", ")", "{", "throw", "new", "TimezonesException", "(", "t", ")", ";", "}", "}" ]
Initialize the timezones system. @param serverUrl url of timezone server @throws TimezonesException on error
[ "Initialize", "the", "timezones", "system", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-timezones/src/main/java/org/bedework/util/timezones/Timezones.java#L86-L98
143,687
Bedework/bw-util
bw-util-timezones/src/main/java/org/bedework/util/timezones/Timezones.java
Timezones.getThreadDefaultTzid
public static String getThreadDefaultTzid() throws TimezonesException { final String id = threadTzid.get(); if (id != null) { return id; } return getSystemDefaultTzid(); }
java
public static String getThreadDefaultTzid() throws TimezonesException { final String id = threadTzid.get(); if (id != null) { return id; } return getSystemDefaultTzid(); }
[ "public", "static", "String", "getThreadDefaultTzid", "(", ")", "throws", "TimezonesException", "{", "final", "String", "id", "=", "threadTzid", ".", "get", "(", ")", ";", "if", "(", "id", "!=", "null", ")", "{", "return", "id", ";", "}", "return", "getSystemDefaultTzid", "(", ")", ";", "}" ]
Get the default timezone id for this thread. @return String id @throws TimezonesException on error
[ "Get", "the", "default", "timezone", "id", "for", "this", "thread", "." ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-timezones/src/main/java/org/bedework/util/timezones/Timezones.java#L143-L150
143,688
Bedework/bw-util
bw-util-timezones/src/main/java/org/bedework/util/timezones/Timezones.java
Timezones.getUtc
public static String getUtc(final String time, final String tzid) throws TimezonesException { return getTimezones().calculateUtc(time, tzid); }
java
public static String getUtc(final String time, final String tzid) throws TimezonesException { return getTimezones().calculateUtc(time, tzid); }
[ "public", "static", "String", "getUtc", "(", "final", "String", "time", ",", "final", "String", "tzid", ")", "throws", "TimezonesException", "{", "return", "getTimezones", "(", ")", ".", "calculateUtc", "(", "time", ",", "tzid", ")", ";", "}" ]
Given a String time value and a possibly null tzid, will return a UTC formatted value. The supplied time should be of the form yyyyMMdd or yyyyMMddThhmmss or yyyyMMddThhmmssZ <p>The last form will be returned untouched, it's already UTC. <p>the first will have T000000 appended to the parameter value then the first and second will be converted to the equivalent UTC time. <p>The returned value is used internally as a value for indexes and recurrence ids. <p>tz null mean this is local or floating time @param time String time to convert. @param tzid String tzid. @return String always of form yyyyMMddThhmmssZ @throws TimezonesException for bad parameters or timezone
[ "Given", "a", "String", "time", "value", "and", "a", "possibly", "null", "tzid", "will", "return", "a", "UTC", "formatted", "value", ".", "The", "supplied", "time", "should", "be", "of", "the", "form", "yyyyMMdd", "or", "yyyyMMddThhmmss", "or", "yyyyMMddThhmmssZ" ]
f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad
https://github.com/Bedework/bw-util/blob/f51de4af3d7eb88fe63a0e22be8898a16c6cc3ad/bw-util-timezones/src/main/java/org/bedework/util/timezones/Timezones.java#L191-L194
143,689
centic9/commons-dost
src/main/java/org/dstadler/commons/logging/log4j/Log4jUtils.java
Log4jUtils.rolloverLogfile
public static void rolloverLogfile() { Logger logger = Logger.getRootLogger(); // NOSONAR - local logger used on purpose here @SuppressWarnings("unchecked") Enumeration<Object> appenders = logger.getAllAppenders(); while(appenders.hasMoreElements()) { Object obj = appenders.nextElement(); if(obj instanceof RollingFileAppender) { ((RollingFileAppender)obj).rollOver(); } } }
java
public static void rolloverLogfile() { Logger logger = Logger.getRootLogger(); // NOSONAR - local logger used on purpose here @SuppressWarnings("unchecked") Enumeration<Object> appenders = logger.getAllAppenders(); while(appenders.hasMoreElements()) { Object obj = appenders.nextElement(); if(obj instanceof RollingFileAppender) { ((RollingFileAppender)obj).rollOver(); } } }
[ "public", "static", "void", "rolloverLogfile", "(", ")", "{", "Logger", "logger", "=", "Logger", ".", "getRootLogger", "(", ")", ";", "// NOSONAR - local logger used on purpose here", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "Enumeration", "<", "Object", ">", "appenders", "=", "logger", ".", "getAllAppenders", "(", ")", ";", "while", "(", "appenders", ".", "hasMoreElements", "(", ")", ")", "{", "Object", "obj", "=", "appenders", ".", "nextElement", "(", ")", ";", "if", "(", "obj", "instanceof", "RollingFileAppender", ")", "{", "(", "(", "RollingFileAppender", ")", "obj", ")", ".", "rollOver", "(", ")", ";", "}", "}", "}" ]
Manually roll over logfiles to start with a new logfile
[ "Manually", "roll", "over", "logfiles", "to", "start", "with", "a", "new", "logfile" ]
f6fa4e3e0b943ff103f918824319d8abf33d0e0f
https://github.com/centic9/commons-dost/blob/f6fa4e3e0b943ff103f918824319d8abf33d0e0f/src/main/java/org/dstadler/commons/logging/log4j/Log4jUtils.java#L12-L22
143,690
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/Storage.java
Storage.createStorage
public static synchronized boolean createStorage(final StorageConfiguration pStorageConfig) throws TTIOException { boolean returnVal = true; // if file is existing, skipping if (!pStorageConfig.mFile.exists() && pStorageConfig.mFile.mkdirs()) { returnVal = IOUtils.createFolderStructure(pStorageConfig.mFile, StorageConfiguration.Paths.values()); // serialization of the config StorageConfiguration.serialize(pStorageConfig); // if something was not correct, delete the partly created // substructure if (!returnVal) { pStorageConfig.mFile.delete(); } return returnVal; } else { return false; } }
java
public static synchronized boolean createStorage(final StorageConfiguration pStorageConfig) throws TTIOException { boolean returnVal = true; // if file is existing, skipping if (!pStorageConfig.mFile.exists() && pStorageConfig.mFile.mkdirs()) { returnVal = IOUtils.createFolderStructure(pStorageConfig.mFile, StorageConfiguration.Paths.values()); // serialization of the config StorageConfiguration.serialize(pStorageConfig); // if something was not correct, delete the partly created // substructure if (!returnVal) { pStorageConfig.mFile.delete(); } return returnVal; } else { return false; } }
[ "public", "static", "synchronized", "boolean", "createStorage", "(", "final", "StorageConfiguration", "pStorageConfig", ")", "throws", "TTIOException", "{", "boolean", "returnVal", "=", "true", ";", "// if file is existing, skipping", "if", "(", "!", "pStorageConfig", ".", "mFile", ".", "exists", "(", ")", "&&", "pStorageConfig", ".", "mFile", ".", "mkdirs", "(", ")", ")", "{", "returnVal", "=", "IOUtils", ".", "createFolderStructure", "(", "pStorageConfig", ".", "mFile", ",", "StorageConfiguration", ".", "Paths", ".", "values", "(", ")", ")", ";", "// serialization of the config", "StorageConfiguration", ".", "serialize", "(", "pStorageConfig", ")", ";", "// if something was not correct, delete the partly created", "// substructure", "if", "(", "!", "returnVal", ")", "{", "pStorageConfig", ".", "mFile", ".", "delete", "(", ")", ";", "}", "return", "returnVal", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Creating a storage. This includes loading the storageconfiguration, building up the structure and preparing everything for login. @param pStorageConfig which are used for the storage, including storage location @return true if creation is valid, false otherwise @throws TTIOException if something odd happens within the creation process.
[ "Creating", "a", "storage", ".", "This", "includes", "loading", "the", "storageconfiguration", "building", "up", "the", "structure", "and", "preparing", "everything", "for", "login", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/Storage.java#L103-L121
143,691
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/Storage.java
Storage.truncateStorage
public static synchronized void truncateStorage(final StorageConfiguration pConf) throws TTException { // check that database must be closed beforehand if (!STORAGEMAP.containsKey(pConf.mFile)) { if (existsStorage(pConf.mFile)) { final IStorage storage = new Storage(pConf); final File[] resources = new File(pConf.mFile, StorageConfiguration.Paths.Data.getFile().getName()).listFiles(); for (final File resource : resources) { storage.truncateResource(new SessionConfiguration(resource.getName(), null)); } storage.close(); // instantiate the database for deletion IOUtils.recursiveDelete(pConf.mFile); } } }
java
public static synchronized void truncateStorage(final StorageConfiguration pConf) throws TTException { // check that database must be closed beforehand if (!STORAGEMAP.containsKey(pConf.mFile)) { if (existsStorage(pConf.mFile)) { final IStorage storage = new Storage(pConf); final File[] resources = new File(pConf.mFile, StorageConfiguration.Paths.Data.getFile().getName()).listFiles(); for (final File resource : resources) { storage.truncateResource(new SessionConfiguration(resource.getName(), null)); } storage.close(); // instantiate the database for deletion IOUtils.recursiveDelete(pConf.mFile); } } }
[ "public", "static", "synchronized", "void", "truncateStorage", "(", "final", "StorageConfiguration", "pConf", ")", "throws", "TTException", "{", "// check that database must be closed beforehand", "if", "(", "!", "STORAGEMAP", ".", "containsKey", "(", "pConf", ".", "mFile", ")", ")", "{", "if", "(", "existsStorage", "(", "pConf", ".", "mFile", ")", ")", "{", "final", "IStorage", "storage", "=", "new", "Storage", "(", "pConf", ")", ";", "final", "File", "[", "]", "resources", "=", "new", "File", "(", "pConf", ".", "mFile", ",", "StorageConfiguration", ".", "Paths", ".", "Data", ".", "getFile", "(", ")", ".", "getName", "(", ")", ")", ".", "listFiles", "(", ")", ";", "for", "(", "final", "File", "resource", ":", "resources", ")", "{", "storage", ".", "truncateResource", "(", "new", "SessionConfiguration", "(", "resource", ".", "getName", "(", ")", ",", "null", ")", ")", ";", "}", "storage", ".", "close", "(", ")", ";", "// instantiate the database for deletion", "IOUtils", ".", "recursiveDelete", "(", "pConf", ".", "mFile", ")", ";", "}", "}", "}" ]
Truncate a storage. This deletes all relevant data. All running sessions must be closed beforehand. @param pConf the storage at this path should be deleted. @throws TTException any kind of false Treetank behaviour
[ "Truncate", "a", "storage", ".", "This", "deletes", "all", "relevant", "data", ".", "All", "running", "sessions", "must", "be", "closed", "beforehand", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/Storage.java#L132-L147
143,692
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/Storage.java
Storage.existsStorage
public static synchronized boolean existsStorage(final File pStoragePath) { // if file is existing and folder is a tt-dataplace, delete it if (pStoragePath.exists() && IOUtils.compareStructure(pStoragePath, StorageConfiguration.Paths.values()) == 0) { return true; } else { return false; } }
java
public static synchronized boolean existsStorage(final File pStoragePath) { // if file is existing and folder is a tt-dataplace, delete it if (pStoragePath.exists() && IOUtils.compareStructure(pStoragePath, StorageConfiguration.Paths.values()) == 0) { return true; } else { return false; } }
[ "public", "static", "synchronized", "boolean", "existsStorage", "(", "final", "File", "pStoragePath", ")", "{", "// if file is existing and folder is a tt-dataplace, delete it", "if", "(", "pStoragePath", ".", "exists", "(", ")", "&&", "IOUtils", ".", "compareStructure", "(", "pStoragePath", ",", "StorageConfiguration", ".", "Paths", ".", "values", "(", ")", ")", "==", "0", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Check if Storage exists or not at a given path. @param pStoragePath to be checked. @return true if existing, false otherwise.
[ "Check", "if", "Storage", "exists", "or", "not", "at", "a", "given", "path", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/Storage.java#L156-L165
143,693
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/Storage.java
Storage.openStorage
public static synchronized IStorage openStorage(final File pFile) throws TTException { checkState(existsStorage(pFile), "DB could not be opened (since it was not created?) at location %s", pFile); StorageConfiguration config = StorageConfiguration.deserialize(pFile); final Storage storage = new Storage(config); final IStorage returnVal = STORAGEMAP.putIfAbsent(pFile, storage); if (returnVal == null) { return storage; } else { return returnVal; } }
java
public static synchronized IStorage openStorage(final File pFile) throws TTException { checkState(existsStorage(pFile), "DB could not be opened (since it was not created?) at location %s", pFile); StorageConfiguration config = StorageConfiguration.deserialize(pFile); final Storage storage = new Storage(config); final IStorage returnVal = STORAGEMAP.putIfAbsent(pFile, storage); if (returnVal == null) { return storage; } else { return returnVal; } }
[ "public", "static", "synchronized", "IStorage", "openStorage", "(", "final", "File", "pFile", ")", "throws", "TTException", "{", "checkState", "(", "existsStorage", "(", "pFile", ")", ",", "\"DB could not be opened (since it was not created?) at location %s\"", ",", "pFile", ")", ";", "StorageConfiguration", "config", "=", "StorageConfiguration", ".", "deserialize", "(", "pFile", ")", ";", "final", "Storage", "storage", "=", "new", "Storage", "(", "config", ")", ";", "final", "IStorage", "returnVal", "=", "STORAGEMAP", ".", "putIfAbsent", "(", "pFile", ",", "storage", ")", ";", "if", "(", "returnVal", "==", "null", ")", "{", "return", "storage", ";", "}", "else", "{", "return", "returnVal", ";", "}", "}" ]
Open database. A database can be opened only once. Afterwards the singleton instance bound to the File is given back. @param pFile where the database is located sessionConf a {@link SessionConfiguration} object to set up the session @return {@link IStorage} instance. @throws TTException if something odd happens
[ "Open", "database", ".", "A", "database", "can", "be", "opened", "only", "once", ".", "Afterwards", "the", "singleton", "instance", "bound", "to", "the", "File", "is", "given", "back", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/Storage.java#L239-L250
143,694
sebastiangraf/treetank
coremodules/core/src/main/java/org/treetank/access/Storage.java
Storage.bootstrap
private static void bootstrap(final Storage pStorage, final ResourceConfiguration pResourceConf) throws TTException { final IBackend storage = pResourceConf.mBackend; storage.initialize(); final IBackendWriter writer = storage.getWriter(); final UberBucket uberBucket = new UberBucket(1, 0, 1); long newBucketKey = uberBucket.incrementBucketCounter(); uberBucket.setReferenceKey(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, newBucketKey); uberBucket.setReferenceHash(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, IConstants.BOOTSTRAP_HASHED); writer.write(uberBucket); // --- Create revision tree // ------------------------------------------------ // Initialize revision tree to guarantee that there is a revision root // bucket. IReferenceBucket bucket; for (int i = 0; i < IConstants.INDIRECT_BUCKET_COUNT.length; i++) { bucket = new IndirectBucket(newBucketKey); newBucketKey = uberBucket.incrementBucketCounter(); bucket.setReferenceKey(0, newBucketKey); bucket.setReferenceHash(0, IConstants.BOOTSTRAP_HASHED); writer.write(bucket); } RevisionRootBucket revBucket = new RevisionRootBucket(newBucketKey, 0, 0); newBucketKey = uberBucket.incrementBucketCounter(); // establishing fresh MetaBucket MetaBucket metaBucker = new MetaBucket(newBucketKey); revBucket.setReferenceKey(RevisionRootBucket.META_REFERENCE_OFFSET, newBucketKey); revBucket.setReferenceHash(RevisionRootBucket.META_REFERENCE_OFFSET, IConstants.BOOTSTRAP_HASHED); newBucketKey = uberBucket.incrementBucketCounter(); bucket = new IndirectBucket(newBucketKey); revBucket.setReferenceKey(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, newBucketKey); revBucket.setReferenceHash(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, IConstants.BOOTSTRAP_HASHED); writer.write(revBucket); writer.write(metaBucker); // --- Create data tree // ---------------------------------------------------- // Initialize revision tree to guarantee that there is a revision root // bucket. for (int i = 0; i < IConstants.INDIRECT_BUCKET_COUNT.length; i++) { newBucketKey = uberBucket.incrementBucketCounter(); bucket.setReferenceKey(0, newBucketKey); bucket.setReferenceHash(0, IConstants.BOOTSTRAP_HASHED); writer.write(bucket); bucket = new IndirectBucket(newBucketKey); } final DataBucket ndp = new DataBucket(newBucketKey, IConstants.NULLDATA); writer.write(ndp); writer.writeUberBucket(uberBucket); writer.close(); storage.close(); }
java
private static void bootstrap(final Storage pStorage, final ResourceConfiguration pResourceConf) throws TTException { final IBackend storage = pResourceConf.mBackend; storage.initialize(); final IBackendWriter writer = storage.getWriter(); final UberBucket uberBucket = new UberBucket(1, 0, 1); long newBucketKey = uberBucket.incrementBucketCounter(); uberBucket.setReferenceKey(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, newBucketKey); uberBucket.setReferenceHash(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, IConstants.BOOTSTRAP_HASHED); writer.write(uberBucket); // --- Create revision tree // ------------------------------------------------ // Initialize revision tree to guarantee that there is a revision root // bucket. IReferenceBucket bucket; for (int i = 0; i < IConstants.INDIRECT_BUCKET_COUNT.length; i++) { bucket = new IndirectBucket(newBucketKey); newBucketKey = uberBucket.incrementBucketCounter(); bucket.setReferenceKey(0, newBucketKey); bucket.setReferenceHash(0, IConstants.BOOTSTRAP_HASHED); writer.write(bucket); } RevisionRootBucket revBucket = new RevisionRootBucket(newBucketKey, 0, 0); newBucketKey = uberBucket.incrementBucketCounter(); // establishing fresh MetaBucket MetaBucket metaBucker = new MetaBucket(newBucketKey); revBucket.setReferenceKey(RevisionRootBucket.META_REFERENCE_OFFSET, newBucketKey); revBucket.setReferenceHash(RevisionRootBucket.META_REFERENCE_OFFSET, IConstants.BOOTSTRAP_HASHED); newBucketKey = uberBucket.incrementBucketCounter(); bucket = new IndirectBucket(newBucketKey); revBucket.setReferenceKey(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, newBucketKey); revBucket.setReferenceHash(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, IConstants.BOOTSTRAP_HASHED); writer.write(revBucket); writer.write(metaBucker); // --- Create data tree // ---------------------------------------------------- // Initialize revision tree to guarantee that there is a revision root // bucket. for (int i = 0; i < IConstants.INDIRECT_BUCKET_COUNT.length; i++) { newBucketKey = uberBucket.incrementBucketCounter(); bucket.setReferenceKey(0, newBucketKey); bucket.setReferenceHash(0, IConstants.BOOTSTRAP_HASHED); writer.write(bucket); bucket = new IndirectBucket(newBucketKey); } final DataBucket ndp = new DataBucket(newBucketKey, IConstants.NULLDATA); writer.write(ndp); writer.writeUberBucket(uberBucket); writer.close(); storage.close(); }
[ "private", "static", "void", "bootstrap", "(", "final", "Storage", "pStorage", ",", "final", "ResourceConfiguration", "pResourceConf", ")", "throws", "TTException", "{", "final", "IBackend", "storage", "=", "pResourceConf", ".", "mBackend", ";", "storage", ".", "initialize", "(", ")", ";", "final", "IBackendWriter", "writer", "=", "storage", ".", "getWriter", "(", ")", ";", "final", "UberBucket", "uberBucket", "=", "new", "UberBucket", "(", "1", ",", "0", ",", "1", ")", ";", "long", "newBucketKey", "=", "uberBucket", ".", "incrementBucketCounter", "(", ")", ";", "uberBucket", ".", "setReferenceKey", "(", "IReferenceBucket", ".", "GUARANTEED_INDIRECT_OFFSET", ",", "newBucketKey", ")", ";", "uberBucket", ".", "setReferenceHash", "(", "IReferenceBucket", ".", "GUARANTEED_INDIRECT_OFFSET", ",", "IConstants", ".", "BOOTSTRAP_HASHED", ")", ";", "writer", ".", "write", "(", "uberBucket", ")", ";", "// --- Create revision tree", "// ------------------------------------------------", "// Initialize revision tree to guarantee that there is a revision root", "// bucket.", "IReferenceBucket", "bucket", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "IConstants", ".", "INDIRECT_BUCKET_COUNT", ".", "length", ";", "i", "++", ")", "{", "bucket", "=", "new", "IndirectBucket", "(", "newBucketKey", ")", ";", "newBucketKey", "=", "uberBucket", ".", "incrementBucketCounter", "(", ")", ";", "bucket", ".", "setReferenceKey", "(", "0", ",", "newBucketKey", ")", ";", "bucket", ".", "setReferenceHash", "(", "0", ",", "IConstants", ".", "BOOTSTRAP_HASHED", ")", ";", "writer", ".", "write", "(", "bucket", ")", ";", "}", "RevisionRootBucket", "revBucket", "=", "new", "RevisionRootBucket", "(", "newBucketKey", ",", "0", ",", "0", ")", ";", "newBucketKey", "=", "uberBucket", ".", "incrementBucketCounter", "(", ")", ";", "// establishing fresh MetaBucket", "MetaBucket", "metaBucker", "=", "new", "MetaBucket", "(", "newBucketKey", ")", ";", "revBucket", ".", "setReferenceKey", "(", "RevisionRootBucket", ".", "META_REFERENCE_OFFSET", ",", "newBucketKey", ")", ";", "revBucket", ".", "setReferenceHash", "(", "RevisionRootBucket", ".", "META_REFERENCE_OFFSET", ",", "IConstants", ".", "BOOTSTRAP_HASHED", ")", ";", "newBucketKey", "=", "uberBucket", ".", "incrementBucketCounter", "(", ")", ";", "bucket", "=", "new", "IndirectBucket", "(", "newBucketKey", ")", ";", "revBucket", ".", "setReferenceKey", "(", "IReferenceBucket", ".", "GUARANTEED_INDIRECT_OFFSET", ",", "newBucketKey", ")", ";", "revBucket", ".", "setReferenceHash", "(", "IReferenceBucket", ".", "GUARANTEED_INDIRECT_OFFSET", ",", "IConstants", ".", "BOOTSTRAP_HASHED", ")", ";", "writer", ".", "write", "(", "revBucket", ")", ";", "writer", ".", "write", "(", "metaBucker", ")", ";", "// --- Create data tree", "// ----------------------------------------------------", "// Initialize revision tree to guarantee that there is a revision root", "// bucket.", "for", "(", "int", "i", "=", "0", ";", "i", "<", "IConstants", ".", "INDIRECT_BUCKET_COUNT", ".", "length", ";", "i", "++", ")", "{", "newBucketKey", "=", "uberBucket", ".", "incrementBucketCounter", "(", ")", ";", "bucket", ".", "setReferenceKey", "(", "0", ",", "newBucketKey", ")", ";", "bucket", ".", "setReferenceHash", "(", "0", ",", "IConstants", ".", "BOOTSTRAP_HASHED", ")", ";", "writer", ".", "write", "(", "bucket", ")", ";", "bucket", "=", "new", "IndirectBucket", "(", "newBucketKey", ")", ";", "}", "final", "DataBucket", "ndp", "=", "new", "DataBucket", "(", "newBucketKey", ",", "IConstants", ".", "NULLDATA", ")", ";", "writer", ".", "write", "(", "ndp", ")", ";", "writer", ".", "writeUberBucket", "(", "uberBucket", ")", ";", "writer", ".", "close", "(", ")", ";", "storage", ".", "close", "(", ")", ";", "}" ]
Boostraping a resource within this storage. @param pStorage storage where the new resource should be created in. @param pResourceConf related {@link ResourceConfiguration} for the new resource @throws TTException
[ "Boostraping", "a", "resource", "within", "this", "storage", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/coremodules/core/src/main/java/org/treetank/access/Storage.java#L338-L400
143,695
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java
XPathScanner.nextToken
public IXPathToken nextToken() { // some tokens start in another state than the START state mState = mStartState; // reset startState mStartState = State.START; mOutput = new StringBuilder(); mFinnished = false; mType = TokenType.INVALID; mLastPos = mPos; do { mInput = mQuery.charAt(mPos); switch (mState) { case START: // specify token type according to first char scanStart(); break; case NUMBER: // number scanNumber(); break; case TEXT: // some text, could be a name scanText(); break; case SPECIAL2: // special character that could have 2 digits scanTwoDigitSpecial(); break; case COMMENT: scanComment(); break; case E_NUM: scanENum(); break; default: mPos++; mFinnished = true; } } while (!mFinnished || mPos >= mQuery.length()); if (mCommentCount > 0) { throw new IllegalStateException("Error in Query. Comment does not end."); } return new VariableXPathToken(mOutput.toString(), mType); }
java
public IXPathToken nextToken() { // some tokens start in another state than the START state mState = mStartState; // reset startState mStartState = State.START; mOutput = new StringBuilder(); mFinnished = false; mType = TokenType.INVALID; mLastPos = mPos; do { mInput = mQuery.charAt(mPos); switch (mState) { case START: // specify token type according to first char scanStart(); break; case NUMBER: // number scanNumber(); break; case TEXT: // some text, could be a name scanText(); break; case SPECIAL2: // special character that could have 2 digits scanTwoDigitSpecial(); break; case COMMENT: scanComment(); break; case E_NUM: scanENum(); break; default: mPos++; mFinnished = true; } } while (!mFinnished || mPos >= mQuery.length()); if (mCommentCount > 0) { throw new IllegalStateException("Error in Query. Comment does not end."); } return new VariableXPathToken(mOutput.toString(), mType); }
[ "public", "IXPathToken", "nextToken", "(", ")", "{", "// some tokens start in another state than the START state", "mState", "=", "mStartState", ";", "// reset startState", "mStartState", "=", "State", ".", "START", ";", "mOutput", "=", "new", "StringBuilder", "(", ")", ";", "mFinnished", "=", "false", ";", "mType", "=", "TokenType", ".", "INVALID", ";", "mLastPos", "=", "mPos", ";", "do", "{", "mInput", "=", "mQuery", ".", "charAt", "(", "mPos", ")", ";", "switch", "(", "mState", ")", "{", "case", "START", ":", "// specify token type according to first char", "scanStart", "(", ")", ";", "break", ";", "case", "NUMBER", ":", "// number", "scanNumber", "(", ")", ";", "break", ";", "case", "TEXT", ":", "// some text, could be a name", "scanText", "(", ")", ";", "break", ";", "case", "SPECIAL2", ":", "// special character that could have 2 digits", "scanTwoDigitSpecial", "(", ")", ";", "break", ";", "case", "COMMENT", ":", "scanComment", "(", ")", ";", "break", ";", "case", "E_NUM", ":", "scanENum", "(", ")", ";", "break", ";", "default", ":", "mPos", "++", ";", "mFinnished", "=", "true", ";", "}", "}", "while", "(", "!", "mFinnished", "||", "mPos", ">=", "mQuery", ".", "length", "(", ")", ")", ";", "if", "(", "mCommentCount", ">", "0", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Error in Query. Comment does not end.\"", ")", ";", "}", "return", "new", "VariableXPathToken", "(", "mOutput", ".", "toString", "(", ")", ",", "mType", ")", ";", "}" ]
Reads the string char by char and returns one token by call. The scanning starts in the start state, if not further specified before, and specifies the next scanner state and the type of the future token according to its first char. As soon as the current char does not fit the conditions for the current token type, the token is generated and returned. @return token The new token.
[ "Reads", "the", "string", "char", "by", "char", "and", "returns", "one", "token", "by", "call", ".", "The", "scanning", "starts", "in", "the", "start", "state", "if", "not", "further", "specified", "before", "and", "specifies", "the", "next", "scanner", "state", "and", "the", "type", "of", "the", "future", "token", "according", "to", "its", "first", "char", ".", "As", "soon", "as", "the", "current", "char", "does", "not", "fit", "the", "conditions", "for", "the", "current", "token", "type", "the", "token", "is", "generated", "and", "returned", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java#L128-L172
143,696
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java
XPathScanner.scanStart
private void scanStart() { if (isNumber(mInput)) { mState = State.NUMBER; mOutput.append(mInput); mType = TokenType.VALUE; // number } else if (isFirstLetter(mInput)) { mState = State.TEXT; // word mOutput.append(mInput); mType = TokenType.TEXT; } else if (isSpecial(mInput)) { mState = State.SPECIAL; // special character with only one digit mOutput.append(mInput); mType = retrieveType(mInput); mFinnished = true; } else if (isTwoDigistSpecial(mInput)) { mState = State.SPECIAL2; // 2 digit special character mOutput.append(mInput); mType = retrieveType(mInput); } else if ((mInput == ' ') || (mInput == '\n')) { mState = State.START; mOutput.append(mInput); mFinnished = true; mType = TokenType.SPACE; } else if (mInput == '#') { mType = TokenType.END; // end of query mFinnished = true; mPos--; } else { mState = State.UNKNOWN; // unknown character mOutput.append(mInput); mFinnished = true; } mPos++; }
java
private void scanStart() { if (isNumber(mInput)) { mState = State.NUMBER; mOutput.append(mInput); mType = TokenType.VALUE; // number } else if (isFirstLetter(mInput)) { mState = State.TEXT; // word mOutput.append(mInput); mType = TokenType.TEXT; } else if (isSpecial(mInput)) { mState = State.SPECIAL; // special character with only one digit mOutput.append(mInput); mType = retrieveType(mInput); mFinnished = true; } else if (isTwoDigistSpecial(mInput)) { mState = State.SPECIAL2; // 2 digit special character mOutput.append(mInput); mType = retrieveType(mInput); } else if ((mInput == ' ') || (mInput == '\n')) { mState = State.START; mOutput.append(mInput); mFinnished = true; mType = TokenType.SPACE; } else if (mInput == '#') { mType = TokenType.END; // end of query mFinnished = true; mPos--; } else { mState = State.UNKNOWN; // unknown character mOutput.append(mInput); mFinnished = true; } mPos++; }
[ "private", "void", "scanStart", "(", ")", "{", "if", "(", "isNumber", "(", "mInput", ")", ")", "{", "mState", "=", "State", ".", "NUMBER", ";", "mOutput", ".", "append", "(", "mInput", ")", ";", "mType", "=", "TokenType", ".", "VALUE", ";", "// number", "}", "else", "if", "(", "isFirstLetter", "(", "mInput", ")", ")", "{", "mState", "=", "State", ".", "TEXT", ";", "// word", "mOutput", ".", "append", "(", "mInput", ")", ";", "mType", "=", "TokenType", ".", "TEXT", ";", "}", "else", "if", "(", "isSpecial", "(", "mInput", ")", ")", "{", "mState", "=", "State", ".", "SPECIAL", ";", "// special character with only one digit", "mOutput", ".", "append", "(", "mInput", ")", ";", "mType", "=", "retrieveType", "(", "mInput", ")", ";", "mFinnished", "=", "true", ";", "}", "else", "if", "(", "isTwoDigistSpecial", "(", "mInput", ")", ")", "{", "mState", "=", "State", ".", "SPECIAL2", ";", "// 2 digit special character", "mOutput", ".", "append", "(", "mInput", ")", ";", "mType", "=", "retrieveType", "(", "mInput", ")", ";", "}", "else", "if", "(", "(", "mInput", "==", "'", "'", ")", "||", "(", "mInput", "==", "'", "'", ")", ")", "{", "mState", "=", "State", ".", "START", ";", "mOutput", ".", "append", "(", "mInput", ")", ";", "mFinnished", "=", "true", ";", "mType", "=", "TokenType", ".", "SPACE", ";", "}", "else", "if", "(", "mInput", "==", "'", "'", ")", "{", "mType", "=", "TokenType", ".", "END", ";", "// end of query", "mFinnished", "=", "true", ";", "mPos", "--", ";", "}", "else", "{", "mState", "=", "State", ".", "UNKNOWN", ";", "// unknown character", "mOutput", ".", "append", "(", "mInput", ")", ";", "mFinnished", "=", "true", ";", "}", "mPos", "++", ";", "}" ]
Scans the first character of a token and decides, what type it is.
[ "Scans", "the", "first", "character", "of", "a", "token", "and", "decides", "what", "type", "it", "is", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java#L177-L211
143,697
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java
XPathScanner.retrieveType
private TokenType retrieveType(final char paramInput) { TokenType type; switch (paramInput) { case ',': type = TokenType.COMMA; break; case '(': type = TokenType.OPEN_BR; break; case ')': type = TokenType.CLOSE_BR; break; case '[': type = TokenType.OPEN_SQP; break; case ']': type = TokenType.CLOSE_SQP; break; case '@': type = TokenType.AT; break; case '=': type = TokenType.EQ; break; case '<': case '>': type = TokenType.COMP; break; case '!': type = TokenType.N_EQ; break; case '/': type = TokenType.SLASH; break; case ':': type = TokenType.COLON; break; case '.': type = TokenType.POINT; break; case '+': type = TokenType.PLUS; break; case '-': type = TokenType.MINUS; break; case '\'': type = TokenType.SINGLE_QUOTE; break; case '"': type = TokenType.DBL_QUOTE; break; case '$': type = TokenType.DOLLAR; break; case '?': type = TokenType.INTERROGATION; break; case '*': type = TokenType.STAR; break; case '|': type = TokenType.OR; break; default: type = TokenType.INVALID; } return type; }
java
private TokenType retrieveType(final char paramInput) { TokenType type; switch (paramInput) { case ',': type = TokenType.COMMA; break; case '(': type = TokenType.OPEN_BR; break; case ')': type = TokenType.CLOSE_BR; break; case '[': type = TokenType.OPEN_SQP; break; case ']': type = TokenType.CLOSE_SQP; break; case '@': type = TokenType.AT; break; case '=': type = TokenType.EQ; break; case '<': case '>': type = TokenType.COMP; break; case '!': type = TokenType.N_EQ; break; case '/': type = TokenType.SLASH; break; case ':': type = TokenType.COLON; break; case '.': type = TokenType.POINT; break; case '+': type = TokenType.PLUS; break; case '-': type = TokenType.MINUS; break; case '\'': type = TokenType.SINGLE_QUOTE; break; case '"': type = TokenType.DBL_QUOTE; break; case '$': type = TokenType.DOLLAR; break; case '?': type = TokenType.INTERROGATION; break; case '*': type = TokenType.STAR; break; case '|': type = TokenType.OR; break; default: type = TokenType.INVALID; } return type; }
[ "private", "TokenType", "retrieveType", "(", "final", "char", "paramInput", ")", "{", "TokenType", "type", ";", "switch", "(", "paramInput", ")", "{", "case", "'", "'", ":", "type", "=", "TokenType", ".", "COMMA", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "OPEN_BR", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "CLOSE_BR", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "OPEN_SQP", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "CLOSE_SQP", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "AT", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "EQ", ";", "break", ";", "case", "'", "'", ":", "case", "'", "'", ":", "type", "=", "TokenType", ".", "COMP", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "N_EQ", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "SLASH", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "COLON", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "POINT", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "PLUS", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "MINUS", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "SINGLE_QUOTE", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "DBL_QUOTE", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "DOLLAR", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "INTERROGATION", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "STAR", ";", "break", ";", "case", "'", "'", ":", "type", "=", "TokenType", ".", "OR", ";", "break", ";", "default", ":", "type", "=", "TokenType", ".", "INVALID", ";", "}", "return", "type", ";", "}" ]
Returns the type of the given character. @param paramInput The character the type should be determined @return type of the given character.
[ "Returns", "the", "type", "of", "the", "given", "character", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java#L220-L290
143,698
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java
XPathScanner.isSpecial
private boolean isSpecial(final char paramInput) { return (paramInput == ')') || (paramInput == ';') || (paramInput == ',') || (paramInput == '@') || (paramInput == '[') || (paramInput == ']') || (paramInput == '=') || (paramInput == '"') || (paramInput == '\'') || (paramInput == '$') || (paramInput == ':') || (paramInput == '|') || (paramInput == '+') || (paramInput == '-') || (paramInput == '?') || (paramInput == '*'); }
java
private boolean isSpecial(final char paramInput) { return (paramInput == ')') || (paramInput == ';') || (paramInput == ',') || (paramInput == '@') || (paramInput == '[') || (paramInput == ']') || (paramInput == '=') || (paramInput == '"') || (paramInput == '\'') || (paramInput == '$') || (paramInput == ':') || (paramInput == '|') || (paramInput == '+') || (paramInput == '-') || (paramInput == '?') || (paramInput == '*'); }
[ "private", "boolean", "isSpecial", "(", "final", "char", "paramInput", ")", "{", "return", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", "||", "(", "paramInput", "==", "'", "'", ")", ";", "}" ]
Checks if the given character is a special character. @param paramInput The character to check. @return Returns true, if the character is a special character.
[ "Checks", "if", "the", "given", "character", "is", "a", "special", "character", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java#L339-L345
143,699
sebastiangraf/treetank
interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java
XPathScanner.scanNumber
private void scanNumber() { if (mInput >= '0' && mInput <= '9') { mOutput.append(mInput); mPos++; } else { // could be an e-number if (mInput == 'E' || mInput == 'e') { mStartState = State.E_NUM; } mFinnished = true; } }
java
private void scanNumber() { if (mInput >= '0' && mInput <= '9') { mOutput.append(mInput); mPos++; } else { // could be an e-number if (mInput == 'E' || mInput == 'e') { mStartState = State.E_NUM; } mFinnished = true; } }
[ "private", "void", "scanNumber", "(", ")", "{", "if", "(", "mInput", ">=", "'", "'", "&&", "mInput", "<=", "'", "'", ")", "{", "mOutput", ".", "append", "(", "mInput", ")", ";", "mPos", "++", ";", "}", "else", "{", "// could be an e-number", "if", "(", "mInput", "==", "'", "'", "||", "mInput", "==", "'", "'", ")", "{", "mStartState", "=", "State", ".", "E_NUM", ";", "}", "mFinnished", "=", "true", ";", "}", "}" ]
Scans a number token. A number only consists of digits.
[ "Scans", "a", "number", "token", ".", "A", "number", "only", "consists", "of", "digits", "." ]
9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60
https://github.com/sebastiangraf/treetank/blob/9b96d631b6c2a8502a0cc958dcb02bd6a6fd8b60/interfacemodules/xml/src/main/java/org/treetank/service/xml/xpath/parser/XPathScanner.java#L350-L362