repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.param
public String param(final String name) { try { return request.getParameter(name); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Can't parse request parameter [uri=" + request.getRequestURI() + ", method=" + request.getMethod() + ", parameterName=" + name + "]: " + e.getMessage()); return null; } }
java
public String param(final String name) { try { return request.getParameter(name); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Can't parse request parameter [uri=" + request.getRequestURI() + ", method=" + request.getMethod() + ", parameterName=" + name + "]: " + e.getMessage()); return null; } }
[ "public", "String", "param", "(", "final", "String", "name", ")", "{", "try", "{", "return", "request", ".", "getParameter", "(", "name", ")", ";", "}", "catch", "(", "final", "Exception", "e", ")", "{", "LOGGER", ".", "log", "(", "Level", ".", "ERRO...
Gets a parameter specified by the given name from request body form or query string. @param name the given name @return parameter, returns {@code null} if not found
[ "Gets", "a", "parameter", "specified", "by", "the", "given", "name", "from", "request", "body", "form", "or", "query", "string", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L259-L267
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.sendError
public void sendError(final int sc) { try { response.sendError(sc); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Sends error status code [" + sc + "] failed: " + e.getMessage()); } }
java
public void sendError(final int sc) { try { response.sendError(sc); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Sends error status code [" + sc + "] failed: " + e.getMessage()); } }
[ "public", "void", "sendError", "(", "final", "int", "sc", ")", "{", "try", "{", "response", ".", "sendError", "(", "sc", ")", ";", "}", "catch", "(", "final", "Exception", "e", ")", "{", "LOGGER", ".", "log", "(", "Level", ".", "ERROR", ",", "\"Sen...
Sends the specified error status code. @param sc the specified error status code
[ "Sends", "the", "specified", "error", "status", "code", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L312-L318
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.renderJSONPretty
public RequestContext renderJSONPretty(final JSONObject json) { final JsonRenderer jsonRenderer = new JsonRenderer(); jsonRenderer.setJSONObject(json); jsonRenderer.setPretty(true); this.renderer = jsonRenderer; return this; }
java
public RequestContext renderJSONPretty(final JSONObject json) { final JsonRenderer jsonRenderer = new JsonRenderer(); jsonRenderer.setJSONObject(json); jsonRenderer.setPretty(true); this.renderer = jsonRenderer; return this; }
[ "public", "RequestContext", "renderJSONPretty", "(", "final", "JSONObject", "json", ")", "{", "final", "JsonRenderer", "jsonRenderer", "=", "new", "JsonRenderer", "(", ")", ";", "jsonRenderer", ".", "setJSONObject", "(", "json", ")", ";", "jsonRenderer", ".", "s...
Pretty rends with the specified json object. @param json the specified json object @return this context
[ "Pretty", "rends", "with", "the", "specified", "json", "object", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L352-L360
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.renderJSON
public RequestContext renderJSON(final JSONObject json) { final JsonRenderer jsonRenderer = new JsonRenderer(); jsonRenderer.setJSONObject(json); this.renderer = jsonRenderer; return this; }
java
public RequestContext renderJSON(final JSONObject json) { final JsonRenderer jsonRenderer = new JsonRenderer(); jsonRenderer.setJSONObject(json); this.renderer = jsonRenderer; return this; }
[ "public", "RequestContext", "renderJSON", "(", "final", "JSONObject", "json", ")", "{", "final", "JsonRenderer", "jsonRenderer", "=", "new", "JsonRenderer", "(", ")", ";", "jsonRenderer", ".", "setJSONObject", "(", "json", ")", ";", "this", ".", "renderer", "=...
Renders with the specified json object. @param json the specified json object @return this context
[ "Renders", "with", "the", "specified", "json", "object", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L383-L390
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.renderPretty
public RequestContext renderPretty() { if (renderer instanceof JsonRenderer) { final JsonRenderer r = (JsonRenderer) renderer; r.setPretty(true); } return this; }
java
public RequestContext renderPretty() { if (renderer instanceof JsonRenderer) { final JsonRenderer r = (JsonRenderer) renderer; r.setPretty(true); } return this; }
[ "public", "RequestContext", "renderPretty", "(", ")", "{", "if", "(", "renderer", "instanceof", "JsonRenderer", ")", "{", "final", "JsonRenderer", "r", "=", "(", "JsonRenderer", ")", "renderer", ";", "r", ".", "setPretty", "(", "true", ")", ";", "}", "retu...
Pretty renders. @return this context
[ "Pretty", "renders", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L512-L519
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.handle
public void handle() { try { for (handleIndex++; handleIndex < handlers.size(); handleIndex++) { handlers.get(handleIndex).handle(this); } } catch (final Exception e) { final String requestLog = Requests.getLog(request); LOGGER.log(Level.ERROR, "Handler process failed: " + requestLog, e); setRenderer(new Http500Renderer(e)); } }
java
public void handle() { try { for (handleIndex++; handleIndex < handlers.size(); handleIndex++) { handlers.get(handleIndex).handle(this); } } catch (final Exception e) { final String requestLog = Requests.getLog(request); LOGGER.log(Level.ERROR, "Handler process failed: " + requestLog, e); setRenderer(new Http500Renderer(e)); } }
[ "public", "void", "handle", "(", ")", "{", "try", "{", "for", "(", "handleIndex", "++", ";", "handleIndex", "<", "handlers", ".", "size", "(", ")", ";", "handleIndex", "++", ")", "{", "handlers", ".", "get", "(", "handleIndex", ")", ".", "handle", "(...
Handles this context with handlers.
[ "Handles", "this", "context", "with", "handlers", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L542-L553
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java
RequestContext.parseRequestJSONObject
private static JSONObject parseRequestJSONObject(final HttpServletRequest request, final HttpServletResponse response) { response.setContentType("application/json"); try { BufferedReader reader; try { reader = request.getReader(); } catch (final IllegalStateException illegalStateException) { reader = new BufferedReader(new InputStreamReader(request.getInputStream())); } String tmp = IOUtils.toString(reader); if (StringUtils.isBlank(tmp)) { tmp = "{}"; } else { if (StringUtils.startsWithIgnoreCase(tmp, "%7B%22" /* {" */)) { tmp = URLs.decode(tmp); } } return new JSONObject(tmp); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Parses request JSON object failed [" + e.getMessage() + "], returns an empty json object"); return new JSONObject(); } }
java
private static JSONObject parseRequestJSONObject(final HttpServletRequest request, final HttpServletResponse response) { response.setContentType("application/json"); try { BufferedReader reader; try { reader = request.getReader(); } catch (final IllegalStateException illegalStateException) { reader = new BufferedReader(new InputStreamReader(request.getInputStream())); } String tmp = IOUtils.toString(reader); if (StringUtils.isBlank(tmp)) { tmp = "{}"; } else { if (StringUtils.startsWithIgnoreCase(tmp, "%7B%22" /* {" */)) { tmp = URLs.decode(tmp); } } return new JSONObject(tmp); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Parses request JSON object failed [" + e.getMessage() + "], returns an empty json object"); return new JSONObject(); } }
[ "private", "static", "JSONObject", "parseRequestJSONObject", "(", "final", "HttpServletRequest", "request", ",", "final", "HttpServletResponse", "response", ")", "{", "response", ".", "setContentType", "(", "\"application/json\"", ")", ";", "try", "{", "BufferedReader",...
Gets the request json object with the specified request. @param request the specified request @param response the specified response, sets its content type with "application/json" @return a json object
[ "Gets", "the", "request", "json", "object", "with", "the", "specified", "request", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/RequestContext.java#L578-L604
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Paginator.java
Paginator.getPage
public static int getPage(final HttpServletRequest request) { int ret = 1; final String p = request.getParameter("p"); if (Strings.isNumeric(p)) { try { ret = Integer.parseInt(p); } catch (final Exception e) { // ignored } } if (1 > ret) { ret = 1; } return ret; }
java
public static int getPage(final HttpServletRequest request) { int ret = 1; final String p = request.getParameter("p"); if (Strings.isNumeric(p)) { try { ret = Integer.parseInt(p); } catch (final Exception e) { // ignored } } if (1 > ret) { ret = 1; } return ret; }
[ "public", "static", "int", "getPage", "(", "final", "HttpServletRequest", "request", ")", "{", "int", "ret", "=", "1", ";", "final", "String", "p", "=", "request", ".", "getParameter", "(", "\"p\"", ")", ";", "if", "(", "Strings", ".", "isNumeric", "(", ...
Gets the current page number from the query string "p" of the specified request. @param request the specified request @return page number, returns {@code 1} as default
[ "Gets", "the", "current", "page", "number", "from", "the", "query", "string", "p", "of", "the", "specified", "request", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Paginator.java#L42-L58
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Paginator.java
Paginator.paginate
public static List<Integer> paginate(final int currentPageNum, final int pageSize, final int pageCount, final int windowSize) { List<Integer> ret; if (pageCount < windowSize) { ret = new ArrayList<>(pageCount); for (int i = 0; i < pageCount; i++) { ret.add(i, i + 1); } } else { ret = new ArrayList<>(windowSize); int first = currentPageNum + 1 - windowSize / 2; first = first < 1 ? 1 : first; first = first + windowSize > pageCount ? pageCount - windowSize + 1 : first; for (int i = 0; i < windowSize; i++) { ret.add(i, first + i); } } return ret; }
java
public static List<Integer> paginate(final int currentPageNum, final int pageSize, final int pageCount, final int windowSize) { List<Integer> ret; if (pageCount < windowSize) { ret = new ArrayList<>(pageCount); for (int i = 0; i < pageCount; i++) { ret.add(i, i + 1); } } else { ret = new ArrayList<>(windowSize); int first = currentPageNum + 1 - windowSize / 2; first = first < 1 ? 1 : first; first = first + windowSize > pageCount ? pageCount - windowSize + 1 : first; for (int i = 0; i < windowSize; i++) { ret.add(i, first + i); } } return ret; }
[ "public", "static", "List", "<", "Integer", ">", "paginate", "(", "final", "int", "currentPageNum", ",", "final", "int", "pageSize", ",", "final", "int", "pageCount", ",", "final", "int", "windowSize", ")", "{", "List", "<", "Integer", ">", "ret", ";", "...
Paginates with the specified current page number, page size, page count and window size. @param currentPageNum the specified current page number @param pageSize the specified page size @param pageCount the specified page count @param windowSize the specified window size @return a list integer pagination page numbers
[ "Paginates", "with", "the", "specified", "current", "page", "number", "page", "size", "page", "count", "and", "window", "size", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Paginator.java#L69-L91
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java
PluginManager.getPlugins
public List<AbstractPlugin> getPlugins() { if (pluginCache.isEmpty()) { LOGGER.info("Plugin cache miss, reload"); load(); } final List<AbstractPlugin> ret = new ArrayList<>(); for (final Map.Entry<String, HashSet<AbstractPlugin>> entry : pluginCache.entrySet()) { ret.addAll(entry.getValue()); } return ret; }
java
public List<AbstractPlugin> getPlugins() { if (pluginCache.isEmpty()) { LOGGER.info("Plugin cache miss, reload"); load(); } final List<AbstractPlugin> ret = new ArrayList<>(); for (final Map.Entry<String, HashSet<AbstractPlugin>> entry : pluginCache.entrySet()) { ret.addAll(entry.getValue()); } return ret; }
[ "public", "List", "<", "AbstractPlugin", ">", "getPlugins", "(", ")", "{", "if", "(", "pluginCache", ".", "isEmpty", "(", ")", ")", "{", "LOGGER", ".", "info", "(", "\"Plugin cache miss, reload\"", ")", ";", "load", "(", ")", ";", "}", "final", "List", ...
Gets all plugins. @return all plugins, returns an empty list if not found
[ "Gets", "all", "plugins", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java#L86-L100
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java
PluginManager.getPlugins
public Set<AbstractPlugin> getPlugins(final String viewName) { if (pluginCache.isEmpty()) { LOGGER.info("Plugin cache miss, reload"); load(); } final Set<AbstractPlugin> ret = pluginCache.get(viewName); if (null == ret) { return Collections.emptySet(); } return ret; }
java
public Set<AbstractPlugin> getPlugins(final String viewName) { if (pluginCache.isEmpty()) { LOGGER.info("Plugin cache miss, reload"); load(); } final Set<AbstractPlugin> ret = pluginCache.get(viewName); if (null == ret) { return Collections.emptySet(); } return ret; }
[ "public", "Set", "<", "AbstractPlugin", ">", "getPlugins", "(", "final", "String", "viewName", ")", "{", "if", "(", "pluginCache", ".", "isEmpty", "(", ")", ")", "{", "LOGGER", ".", "info", "(", "\"Plugin cache miss, reload\"", ")", ";", "load", "(", ")", ...
Gets a plugin by the specified view name. @param viewName the specified view name @return a plugin, returns an empty list if not found
[ "Gets", "a", "plugin", "by", "the", "specified", "view", "name", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java#L108-L122
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java
PluginManager.register
private void register(final AbstractPlugin plugin, final Map<String, HashSet<AbstractPlugin>> holder) { final String rendererId = plugin.getRendererId(); /* * the rendererId support multiple,using ';' to split. * and using Map to match the plugin is not flexible, a regular expression match pattern may be needed in futrue. */ final String[] redererIds = rendererId.split(";"); for (final String rid : redererIds) { final HashSet<AbstractPlugin> set = holder.computeIfAbsent(rid, k -> new HashSet<>()); set.add(plugin); } LOGGER.log(Level.DEBUG, "Registered plugin[name={0}, version={1}] for rendererId[name={2}], [{3}] plugins totally", plugin.getName(), plugin.getVersion(), rendererId, holder.size()); }
java
private void register(final AbstractPlugin plugin, final Map<String, HashSet<AbstractPlugin>> holder) { final String rendererId = plugin.getRendererId(); /* * the rendererId support multiple,using ';' to split. * and using Map to match the plugin is not flexible, a regular expression match pattern may be needed in futrue. */ final String[] redererIds = rendererId.split(";"); for (final String rid : redererIds) { final HashSet<AbstractPlugin> set = holder.computeIfAbsent(rid, k -> new HashSet<>()); set.add(plugin); } LOGGER.log(Level.DEBUG, "Registered plugin[name={0}, version={1}] for rendererId[name={2}], [{3}] plugins totally", plugin.getName(), plugin.getVersion(), rendererId, holder.size()); }
[ "private", "void", "register", "(", "final", "AbstractPlugin", "plugin", ",", "final", "Map", "<", "String", ",", "HashSet", "<", "AbstractPlugin", ">", ">", "holder", ")", "{", "final", "String", "rendererId", "=", "plugin", ".", "getRendererId", "(", ")", ...
Registers the specified plugin into the specified holder. @param plugin the specified plugin @param holder the specified holder
[ "Registers", "the", "specified", "plugin", "into", "the", "specified", "holder", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java#L223-L240
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java
PluginManager.setPluginProps
private static void setPluginProps(final String pluginDirName, final AbstractPlugin plugin, final Properties props) throws Exception { final String author = props.getProperty(Plugin.PLUGIN_AUTHOR); final String name = props.getProperty(Plugin.PLUGIN_NAME); final String version = props.getProperty(Plugin.PLUGIN_VERSION); final String types = props.getProperty(Plugin.PLUGIN_TYPES); LOGGER.log(Level.TRACE, "Plugin[name={0}, author={1}, version={2}, types={3}]", name, author, version, types); plugin.setAuthor(author); plugin.setName(name); plugin.setId(name + "_" + version); plugin.setVersion(version); plugin.setDir(pluginDirName); plugin.readLangs(); // try to find the setting config.json final File settingFile = Latkes.getWebFile("/plugins/" + pluginDirName + "/config.json"); if (null != settingFile && settingFile.exists()) { try { final String config = FileUtils.readFileToString(settingFile); final JSONObject jsonObject = new JSONObject(config); plugin.setSetting(jsonObject); } catch (final IOException ie) { LOGGER.log(Level.ERROR, "reading the config of the plugin[" + name + "] failed", ie); } catch (final JSONException e) { LOGGER.log(Level.ERROR, "convert the config of the plugin[" + name + "] to json failed", e); } } Arrays.stream(types.split(",")).map(PluginType::valueOf).forEach(plugin::addType); }
java
private static void setPluginProps(final String pluginDirName, final AbstractPlugin plugin, final Properties props) throws Exception { final String author = props.getProperty(Plugin.PLUGIN_AUTHOR); final String name = props.getProperty(Plugin.PLUGIN_NAME); final String version = props.getProperty(Plugin.PLUGIN_VERSION); final String types = props.getProperty(Plugin.PLUGIN_TYPES); LOGGER.log(Level.TRACE, "Plugin[name={0}, author={1}, version={2}, types={3}]", name, author, version, types); plugin.setAuthor(author); plugin.setName(name); plugin.setId(name + "_" + version); plugin.setVersion(version); plugin.setDir(pluginDirName); plugin.readLangs(); // try to find the setting config.json final File settingFile = Latkes.getWebFile("/plugins/" + pluginDirName + "/config.json"); if (null != settingFile && settingFile.exists()) { try { final String config = FileUtils.readFileToString(settingFile); final JSONObject jsonObject = new JSONObject(config); plugin.setSetting(jsonObject); } catch (final IOException ie) { LOGGER.log(Level.ERROR, "reading the config of the plugin[" + name + "] failed", ie); } catch (final JSONException e) { LOGGER.log(Level.ERROR, "convert the config of the plugin[" + name + "] to json failed", e); } } Arrays.stream(types.split(",")).map(PluginType::valueOf).forEach(plugin::addType); }
[ "private", "static", "void", "setPluginProps", "(", "final", "String", "pluginDirName", ",", "final", "AbstractPlugin", "plugin", ",", "final", "Properties", "props", ")", "throws", "Exception", "{", "final", "String", "author", "=", "props", ".", "getProperty", ...
Sets the specified plugin's properties from the specified properties file under the specified plugin directory. @param pluginDirName the specified plugin directory @param plugin the specified plugin @param props the specified properties file @throws Exception exception
[ "Sets", "the", "specified", "plugin", "s", "properties", "from", "the", "specified", "properties", "file", "under", "the", "specified", "plugin", "directory", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java#L250-L282
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java
PluginManager.registerEventListeners
private void registerEventListeners(final Properties props, final URLClassLoader classLoader, final AbstractPlugin plugin) throws Exception { final String eventListenerClasses = props.getProperty(Plugin.PLUGIN_EVENT_LISTENER_CLASSES); final String[] eventListenerClassArray = eventListenerClasses.split(","); for (final String eventListenerClassName : eventListenerClassArray) { if (StringUtils.isBlank(eventListenerClassName)) { LOGGER.log(Level.INFO, "No event listener to load for plugin[name={0}]", plugin.getName()); return; } LOGGER.log(Level.DEBUG, "Loading event listener[className={0}]", eventListenerClassName); final Class<?> eventListenerClass = classLoader.loadClass(eventListenerClassName); final AbstractEventListener<?> eventListener = (AbstractEventListener) eventListenerClass.newInstance(); plugin.addEventListener(eventListener); LOGGER.log(Level.DEBUG, "Registered event listener[class={0}, eventType={1}] for plugin[name={2}]", eventListener.getClass(), eventListener.getEventType(), plugin.getName()); } }
java
private void registerEventListeners(final Properties props, final URLClassLoader classLoader, final AbstractPlugin plugin) throws Exception { final String eventListenerClasses = props.getProperty(Plugin.PLUGIN_EVENT_LISTENER_CLASSES); final String[] eventListenerClassArray = eventListenerClasses.split(","); for (final String eventListenerClassName : eventListenerClassArray) { if (StringUtils.isBlank(eventListenerClassName)) { LOGGER.log(Level.INFO, "No event listener to load for plugin[name={0}]", plugin.getName()); return; } LOGGER.log(Level.DEBUG, "Loading event listener[className={0}]", eventListenerClassName); final Class<?> eventListenerClass = classLoader.loadClass(eventListenerClassName); final AbstractEventListener<?> eventListener = (AbstractEventListener) eventListenerClass.newInstance(); plugin.addEventListener(eventListener); LOGGER.log(Level.DEBUG, "Registered event listener[class={0}, eventType={1}] for plugin[name={2}]", eventListener.getClass(), eventListener.getEventType(), plugin.getName()); } }
[ "private", "void", "registerEventListeners", "(", "final", "Properties", "props", ",", "final", "URLClassLoader", "classLoader", ",", "final", "AbstractPlugin", "plugin", ")", "throws", "Exception", "{", "final", "String", "eventListenerClasses", "=", "props", ".", ...
Registers event listeners with the specified plugin properties, class loader and plugin. @param props the specified plugin properties @param classLoader the specified class loader @param plugin the specified plugin @throws Exception exception
[ "Registers", "event", "listeners", "with", "the", "specified", "plugin", "properties", "class", "loader", "and", "plugin", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/PluginManager.java#L292-L313
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/service/LangPropsService.java
LangPropsService.getAll
public Map<String, String> getAll(final Locale locale) { Map<String, String> ret = LANGS.get(locale); if (null == ret) { ret = new HashMap<>(); final ResourceBundle defaultLangBundle = ResourceBundle.getBundle(Keys.LANGUAGE, Latkes.getLocale()); final Enumeration<String> defaultLangKeys = defaultLangBundle.getKeys(); while (defaultLangKeys.hasMoreElements()) { final String key = defaultLangKeys.nextElement(); final String value = replaceVars(defaultLangBundle.getString(key)); ret.put(key, value); } final ResourceBundle langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, locale); final Enumeration<String> langKeys = langBundle.getKeys(); while (langKeys.hasMoreElements()) { final String key = langKeys.nextElement(); final String value = replaceVars(langBundle.getString(key)); ret.put(key, value); } LANGS.put(locale, ret); } return ret; }
java
public Map<String, String> getAll(final Locale locale) { Map<String, String> ret = LANGS.get(locale); if (null == ret) { ret = new HashMap<>(); final ResourceBundle defaultLangBundle = ResourceBundle.getBundle(Keys.LANGUAGE, Latkes.getLocale()); final Enumeration<String> defaultLangKeys = defaultLangBundle.getKeys(); while (defaultLangKeys.hasMoreElements()) { final String key = defaultLangKeys.nextElement(); final String value = replaceVars(defaultLangBundle.getString(key)); ret.put(key, value); } final ResourceBundle langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, locale); final Enumeration<String> langKeys = langBundle.getKeys(); while (langKeys.hasMoreElements()) { final String key = langKeys.nextElement(); final String value = replaceVars(langBundle.getString(key)); ret.put(key, value); } LANGS.put(locale, ret); } return ret; }
[ "public", "Map", "<", "String", ",", "String", ">", "getAll", "(", "final", "Locale", "locale", ")", "{", "Map", "<", "String", ",", "String", ">", "ret", "=", "LANGS", ".", "get", "(", "locale", ")", ";", "if", "(", "null", "==", "ret", ")", "{"...
Gets all language properties as a map by the specified locale. @param locale the specified locale @return a map of language configurations
[ "Gets", "all", "language", "properties", "as", "a", "map", "by", "the", "specified", "locale", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/service/LangPropsService.java#L54-L80
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/service/LangPropsService.java
LangPropsService.get
public String get(final String key, final Locale locale) { return get(Keys.LANGUAGE, key, locale); }
java
public String get(final String key, final Locale locale) { return get(Keys.LANGUAGE, key, locale); }
[ "public", "String", "get", "(", "final", "String", "key", ",", "final", "Locale", "locale", ")", "{", "return", "get", "(", "Keys", ".", "LANGUAGE", ",", "key", ",", "locale", ")", ";", "}" ]
Gets a value with the specified key and locale. @param key the specified key @param locale the specified locale @return value
[ "Gets", "a", "value", "with", "the", "specified", "key", "and", "locale", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/service/LangPropsService.java#L100-L102
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/service/LangPropsService.java
LangPropsService.replaceVars
private String replaceVars(final String langValue) { String ret = StringUtils.replace(langValue, "${servePath}", Latkes.getServePath()); ret = StringUtils.replace(ret, "${staticServePath}", Latkes.getStaticServePath()); return ret; }
java
private String replaceVars(final String langValue) { String ret = StringUtils.replace(langValue, "${servePath}", Latkes.getServePath()); ret = StringUtils.replace(ret, "${staticServePath}", Latkes.getStaticServePath()); return ret; }
[ "private", "String", "replaceVars", "(", "final", "String", "langValue", ")", "{", "String", "ret", "=", "StringUtils", ".", "replace", "(", "langValue", ",", "\"${servePath}\"", ",", "Latkes", ".", "getServePath", "(", ")", ")", ";", "ret", "=", "StringUtil...
Replaces all variables of the specified language value. <p> Variables: <ul> <li>${servePath}</li> <li>${staticServePath}</li> </ul> </p> @param langValue the specified language value @return replaced value
[ "Replaces", "all", "variables", "of", "the", "specified", "language", "value", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/service/LangPropsService.java#L148-L153
train
b3log/latke
latke-core/src/main/java/org/json/XML.java
XML.unescape
public static String unescape(String string) { StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { char c = string.charAt(i); if (c == '&') { final int semic = string.indexOf(';', i); if (semic > i) { final String entity = string.substring(i + 1, semic); sb.append(XMLTokener.unescapeEntity(entity)); // skip past the entity we just parsed. i += entity.length() + 1; } else { // this shouldn't happen in most cases since the parser // errors on unclosed entries. sb.append(c); } } else { // not part of an entity sb.append(c); } } return sb.toString(); }
java
public static String unescape(String string) { StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { char c = string.charAt(i); if (c == '&') { final int semic = string.indexOf(';', i); if (semic > i) { final String entity = string.substring(i + 1, semic); sb.append(XMLTokener.unescapeEntity(entity)); // skip past the entity we just parsed. i += entity.length() + 1; } else { // this shouldn't happen in most cases since the parser // errors on unclosed entries. sb.append(c); } } else { // not part of an entity sb.append(c); } } return sb.toString(); }
[ "public", "static", "String", "unescape", "(", "String", "string", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "string", ".", "length", "(", ")", ")", ";", "for", "(", "int", "i", "=", "0", ",", "length", "=", "string", ".", "l...
Removes XML escapes from the string. @param string string to remove escapes from @return string with converted entities
[ "Removes", "XML", "escapes", "from", "the", "string", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/json/XML.java#L187-L209
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/XMLs.java
XMLs.format
public static String format(final String xml) { try { final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document doc = db.parse(new InputSource(new StringReader(xml))); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); final StreamResult result = new StreamResult(new StringWriter()); final DOMSource source = new DOMSource(doc); transformer.transform(source, result); return result.getWriter().toString(); } catch (final Exception e) { LOGGER.log(Level.WARN, "Formats pretty XML failed: " + e.getMessage()); return xml; } }
java
public static String format(final String xml) { try { final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document doc = db.parse(new InputSource(new StringReader(xml))); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); final StreamResult result = new StreamResult(new StringWriter()); final DOMSource source = new DOMSource(doc); transformer.transform(source, result); return result.getWriter().toString(); } catch (final Exception e) { LOGGER.log(Level.WARN, "Formats pretty XML failed: " + e.getMessage()); return xml; } }
[ "public", "static", "String", "format", "(", "final", "String", "xml", ")", "{", "try", "{", "final", "DocumentBuilder", "db", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ".", "newDocumentBuilder", "(", ")", ";", "final", "Document", "doc", ...
Returns pretty print of the specified xml string. @param xml the specified xml string @return the pretty print of the specified xml string
[ "Returns", "pretty", "print", "of", "the", "specified", "xml", "string", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/XMLs.java#L53-L70
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java
AbstractPlugin.initTemplateEngineCfg
private void initTemplateEngineCfg() { configuration = new Configuration(); configuration.setDefaultEncoding("UTF-8"); final ServletContext servletContext = AbstractServletListener.getServletContext(); configuration.setServletContextForTemplateLoading(servletContext, "/plugins/" + dirName); LOGGER.log(Level.DEBUG, "Initialized template configuration"); }
java
private void initTemplateEngineCfg() { configuration = new Configuration(); configuration.setDefaultEncoding("UTF-8"); final ServletContext servletContext = AbstractServletListener.getServletContext(); configuration.setServletContextForTemplateLoading(servletContext, "/plugins/" + dirName); LOGGER.log(Level.DEBUG, "Initialized template configuration"); }
[ "private", "void", "initTemplateEngineCfg", "(", ")", "{", "configuration", "=", "new", "Configuration", "(", ")", ";", "configuration", ".", "setDefaultEncoding", "(", "\"UTF-8\"", ")", ";", "final", "ServletContext", "servletContext", "=", "AbstractServletListener",...
Initializes template engine configuration.
[ "Initializes", "template", "engine", "configuration", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java#L172-L179
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java
AbstractPlugin.getLang
public String getLang(final Locale locale, final String key) { return langs.get(locale.toString()).getProperty(key); }
java
public String getLang(final Locale locale, final String key) { return langs.get(locale.toString()).getProperty(key); }
[ "public", "String", "getLang", "(", "final", "Locale", "locale", ",", "final", "String", "key", ")", "{", "return", "langs", ".", "get", "(", "locale", ".", "toString", "(", ")", ")", ".", "getProperty", "(", "key", ")", ";", "}" ]
Gets language label with the specified locale and key. @param locale the specified locale @param key the specified key @return language label
[ "Gets", "language", "label", "with", "the", "specified", "locale", "and", "key", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java#L217-L219
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java
AbstractPlugin.plug
public void plug(final Map<String, Object> dataModel, final RequestContext context) { String content = (String) dataModel.get(Plugin.PLUGINS); if (null == content) { dataModel.put(Plugin.PLUGINS, ""); } handleLangs(dataModel); fillDefault(dataModel); postPlug(dataModel, context); content = (String) dataModel.get(Plugin.PLUGINS); final StringBuilder contentBuilder = new StringBuilder(content); contentBuilder.append(getViewContent(dataModel)); final String pluginsContent = contentBuilder.toString(); dataModel.put(Plugin.PLUGINS, pluginsContent); LOGGER.log(Level.DEBUG, "Plugin[name={0}] has been plugged", getName()); }
java
public void plug(final Map<String, Object> dataModel, final RequestContext context) { String content = (String) dataModel.get(Plugin.PLUGINS); if (null == content) { dataModel.put(Plugin.PLUGINS, ""); } handleLangs(dataModel); fillDefault(dataModel); postPlug(dataModel, context); content = (String) dataModel.get(Plugin.PLUGINS); final StringBuilder contentBuilder = new StringBuilder(content); contentBuilder.append(getViewContent(dataModel)); final String pluginsContent = contentBuilder.toString(); dataModel.put(Plugin.PLUGINS, pluginsContent); LOGGER.log(Level.DEBUG, "Plugin[name={0}] has been plugged", getName()); }
[ "public", "void", "plug", "(", "final", "Map", "<", "String", ",", "Object", ">", "dataModel", ",", "final", "RequestContext", "context", ")", "{", "String", "content", "=", "(", "String", ")", "dataModel", ".", "get", "(", "Plugin", ".", "PLUGINS", ")",...
Plugs with the specified data model and the args from request. @param dataModel dataModel @param context context
[ "Plugs", "with", "the", "specified", "data", "model", "and", "the", "args", "from", "request", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java#L271-L294
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java
AbstractPlugin.handleLangs
private void handleLangs(final Map<String, Object> dataModel) { final Locale locale = Latkes.getLocale(); final String language = locale.getLanguage(); final String country = locale.getCountry(); final String variant = locale.getVariant(); final StringBuilder keyBuilder = new StringBuilder(language); if (StringUtils.isNotBlank(country)) { keyBuilder.append("_").append(country); } if (StringUtils.isNotBlank(variant)) { keyBuilder.append("_").append(variant); } final String localKey = keyBuilder.toString(); final Properties props = langs.get(localKey); if (null == props) { return; } final Set<Object> keySet = props.keySet(); for (final Object key : keySet) { dataModel.put((String) key, props.getProperty((String) key)); } }
java
private void handleLangs(final Map<String, Object> dataModel) { final Locale locale = Latkes.getLocale(); final String language = locale.getLanguage(); final String country = locale.getCountry(); final String variant = locale.getVariant(); final StringBuilder keyBuilder = new StringBuilder(language); if (StringUtils.isNotBlank(country)) { keyBuilder.append("_").append(country); } if (StringUtils.isNotBlank(variant)) { keyBuilder.append("_").append(variant); } final String localKey = keyBuilder.toString(); final Properties props = langs.get(localKey); if (null == props) { return; } final Set<Object> keySet = props.keySet(); for (final Object key : keySet) { dataModel.put((String) key, props.getProperty((String) key)); } }
[ "private", "void", "handleLangs", "(", "final", "Map", "<", "String", ",", "Object", ">", "dataModel", ")", "{", "final", "Locale", "locale", "=", "Latkes", ".", "getLocale", "(", ")", ";", "final", "String", "language", "=", "locale", ".", "getLanguage", ...
Processes languages. Retrieves language labels with default locale, then sets them into the specified data model. @param dataModel the specified data model
[ "Processes", "languages", ".", "Retrieves", "language", "labels", "with", "default", "locale", "then", "sets", "them", "into", "the", "specified", "data", "model", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java#L301-L328
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java
AbstractPlugin.fillDefault
private void fillDefault(final Map<String, Object> dataModel) { Keys.fillServer(dataModel); Keys.fillRuntime(dataModel); }
java
private void fillDefault(final Map<String, Object> dataModel) { Keys.fillServer(dataModel); Keys.fillRuntime(dataModel); }
[ "private", "void", "fillDefault", "(", "final", "Map", "<", "String", ",", "Object", ">", "dataModel", ")", "{", "Keys", ".", "fillServer", "(", "dataModel", ")", ";", "Keys", ".", "fillRuntime", "(", "dataModel", ")", ";", "}" ]
Fills default values into the specified data model. <p> The default data model variable values includes: <ul> <li>{@code Keys.SERVER.*}</li> <li>{@code Keys.RUNTIME.*}</li> </ul> </p> @param dataModel the specified data model @see Keys#fillServer(java.util.Map)
[ "Fills", "default", "values", "into", "the", "specified", "data", "model", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java#L344-L347
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java
AbstractPlugin.getViewContent
private String getViewContent(final Map<String, Object> dataModel) { if (null == configuration) { initTemplateEngineCfg(); } try { final Template template = configuration.getTemplate("plugin.ftl"); final StringWriter sw = new StringWriter(); template.process(dataModel, sw); return sw.toString(); } catch (final Exception e) { // This plugin has no view return ""; } }
java
private String getViewContent(final Map<String, Object> dataModel) { if (null == configuration) { initTemplateEngineCfg(); } try { final Template template = configuration.getTemplate("plugin.ftl"); final StringWriter sw = new StringWriter(); template.process(dataModel, sw); return sw.toString(); } catch (final Exception e) { // This plugin has no view return ""; } }
[ "private", "String", "getViewContent", "(", "final", "Map", "<", "String", ",", "Object", ">", "dataModel", ")", "{", "if", "(", "null", "==", "configuration", ")", "{", "initTemplateEngineCfg", "(", ")", ";", "}", "try", "{", "final", "Template", "templat...
Gets view content of a plugin. The content is processed with the specified data model by template engine. @param dataModel the specified data model @return plugin view content
[ "Gets", "view", "content", "of", "a", "plugin", ".", "The", "content", "is", "processed", "with", "the", "specified", "data", "model", "by", "template", "engine", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/plugin/AbstractPlugin.java#L356-L373
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/event/AbstractEventQueue.java
AbstractEventQueue.addListener
synchronized void addListener(final AbstractEventListener<?> listener) { if (null == listener) { throw new NullPointerException(); } final String eventType = listener.getEventType(); if (null == eventType) { throw new NullPointerException(); } List<AbstractEventListener<?>> listenerList = listeners.get(eventType); if (null == listenerList) { listenerList = new ArrayList<>(); listeners.put(eventType, listenerList); } listenerList.add(listener); }
java
synchronized void addListener(final AbstractEventListener<?> listener) { if (null == listener) { throw new NullPointerException(); } final String eventType = listener.getEventType(); if (null == eventType) { throw new NullPointerException(); } List<AbstractEventListener<?>> listenerList = listeners.get(eventType); if (null == listenerList) { listenerList = new ArrayList<>(); listeners.put(eventType, listenerList); } listenerList.add(listener); }
[ "synchronized", "void", "addListener", "(", "final", "AbstractEventListener", "<", "?", ">", "listener", ")", "{", "if", "(", "null", "==", "listener", ")", "{", "throw", "new", "NullPointerException", "(", ")", ";", "}", "final", "String", "eventType", "=",...
Adds the specified listener to the set of listeners for this object, provided that it is not the same as some listener already in the set. @param listener the specified listener
[ "Adds", "the", "specified", "listener", "to", "the", "set", "of", "listeners", "for", "this", "object", "provided", "that", "it", "is", "not", "the", "same", "as", "some", "listener", "already", "in", "the", "set", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/event/AbstractEventQueue.java#L48-L65
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/ArrayUtils.java
ArrayUtils.concatenate
public static <T> T[] concatenate(final T[] first, final T[]... rest) { int totalLength = first.length; for (final T[] array : rest) { totalLength += array.length; } final T[] ret = Arrays.copyOf(first, totalLength); int offset = first.length; for (final T[] array : rest) { System.arraycopy(array, 0, ret, offset, array.length); offset += array.length; } return ret; }
java
public static <T> T[] concatenate(final T[] first, final T[]... rest) { int totalLength = first.length; for (final T[] array : rest) { totalLength += array.length; } final T[] ret = Arrays.copyOf(first, totalLength); int offset = first.length; for (final T[] array : rest) { System.arraycopy(array, 0, ret, offset, array.length); offset += array.length; } return ret; }
[ "public", "static", "<", "T", ">", "T", "[", "]", "concatenate", "(", "final", "T", "[", "]", "first", ",", "final", "T", "[", "]", "...", "rest", ")", "{", "int", "totalLength", "=", "first", ".", "length", ";", "for", "(", "final", "T", "[", ...
Concatenates the specified arrays. @param <T> the type of array element @param first the specified first array @param rest the specified rest arrays @return concatenated array
[ "Concatenates", "the", "specified", "arrays", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/ArrayUtils.java#L36-L52
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java
ClassPathResolver.getResourcesFromRoot
private static Set<URL> getResourcesFromRoot(final String rootPath) { final Set<URL> rets = new LinkedHashSet<URL>(); String path = rootPath; if (path.startsWith("/")) { path = path.substring(1); } try { final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(path); URL url = null; while (resources.hasMoreElements()) { url = (URL) resources.nextElement(); rets.add(url); } } catch (final IOException e) { LOGGER.log(Level.ERROR, "get the ROOT Rescources error", e); } return rets; }
java
private static Set<URL> getResourcesFromRoot(final String rootPath) { final Set<URL> rets = new LinkedHashSet<URL>(); String path = rootPath; if (path.startsWith("/")) { path = path.substring(1); } try { final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(path); URL url = null; while (resources.hasMoreElements()) { url = (URL) resources.nextElement(); rets.add(url); } } catch (final IOException e) { LOGGER.log(Level.ERROR, "get the ROOT Rescources error", e); } return rets; }
[ "private", "static", "Set", "<", "URL", ">", "getResourcesFromRoot", "(", "final", "String", "rootPath", ")", "{", "final", "Set", "<", "URL", ">", "rets", "=", "new", "LinkedHashSet", "<", "URL", ">", "(", ")", ";", "String", "path", "=", "rootPath", ...
the URLS under Root path ,each of which we should scan from. @param rootPath rootPath @return the URLS under the Root path
[ "the", "URLS", "under", "Root", "path", "each", "of", "which", "we", "should", "scan", "from", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java#L123-L146
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java
ClassPathResolver.isJarURL
private static boolean isJarURL(final URL rootDirResource) { final String protocol = rootDirResource.getProtocol(); /** * Determine whether the given URL points to a resource in a jar file, that is, has protocol "jar", "zip", * "wsjar" or "code-source". * <p> * "zip" and "wsjar" are used by BEA WebLogic Server and IBM WebSphere, respectively, but can be treated like * jar files. The same applies to "code-source" URLs on Oracle OC4J, provided that the path contains a jar * separator. * * */ return "jar".equals(protocol) || "zip".equals(protocol) || "wsjar".equals(protocol) || ("code-source".equals(protocol) && rootDirResource.getPath().contains(JAR_URL_SEPARATOR)); }
java
private static boolean isJarURL(final URL rootDirResource) { final String protocol = rootDirResource.getProtocol(); /** * Determine whether the given URL points to a resource in a jar file, that is, has protocol "jar", "zip", * "wsjar" or "code-source". * <p> * "zip" and "wsjar" are used by BEA WebLogic Server and IBM WebSphere, respectively, but can be treated like * jar files. The same applies to "code-source" URLs on Oracle OC4J, provided that the path contains a jar * separator. * * */ return "jar".equals(protocol) || "zip".equals(protocol) || "wsjar".equals(protocol) || ("code-source".equals(protocol) && rootDirResource.getPath().contains(JAR_URL_SEPARATOR)); }
[ "private", "static", "boolean", "isJarURL", "(", "final", "URL", "rootDirResource", ")", "{", "final", "String", "protocol", "=", "rootDirResource", ".", "getProtocol", "(", ")", ";", "/**\n * Determine whether the given URL points to a resource in a jar file, that is...
check if the URL of the Rousource is a JAR resource. @param rootDirResource rootDirResource @return isJAR
[ "check", "if", "the", "URL", "of", "the", "Rousource", "is", "a", "JAR", "resource", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java#L154-L170
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java
ClassPathResolver.doFindPathMatchingJarResources
private static Collection<? extends URL> doFindPathMatchingJarResources(final URL rootDirResource, final String subPattern) { final Set<URL> result = new LinkedHashSet<URL>(); JarFile jarFile = null; String jarFileUrl; String rootEntryPath = null; URLConnection con; boolean newJarFile = false; try { con = rootDirResource.openConnection(); if (con instanceof JarURLConnection) { final JarURLConnection jarCon = (JarURLConnection) con; jarCon.setUseCaches(false); jarFile = jarCon.getJarFile(); jarFileUrl = jarCon.getJarFileURL().toExternalForm(); final JarEntry jarEntry = jarCon.getJarEntry(); rootEntryPath = jarEntry != null ? jarEntry.getName() : ""; } else { // No JarURLConnection -> need to resort to URL file parsing. // We'll assume URLs of the format "jar:path!/entry", with the // protocol // being arbitrary as long as following the entry format. // We'll also handle paths with and without leading "file:" // prefix. final String urlFile = rootDirResource.getFile(); final int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR); if (separatorIndex != -1) { jarFileUrl = urlFile.substring(0, separatorIndex); rootEntryPath = urlFile.substring(separatorIndex + JAR_URL_SEPARATOR.length()); jarFile = getJarFile(jarFileUrl); } else { jarFile = new JarFile(urlFile); jarFileUrl = urlFile; rootEntryPath = ""; } newJarFile = true; } } catch (final IOException e) { LOGGER.log(Level.ERROR, "reslove jar File error", e); return result; } try { if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) { // Root entry path must end with slash to allow for proper // matching. // The Sun JRE does not return a slash here, but BEA JRockit // does. rootEntryPath = rootEntryPath + "/"; } for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) { final JarEntry entry = (JarEntry) entries.nextElement(); final String entryPath = entry.getName(); String relativePath = null; if (entryPath.startsWith(rootEntryPath)) { relativePath = entryPath.substring(rootEntryPath.length()); if (AntPathMatcher.match(subPattern, relativePath)) { if (relativePath.startsWith("/")) { relativePath = relativePath.substring(1); } result.add(new URL(rootDirResource, relativePath)); } } } return result; } catch (final IOException e) { LOGGER.log(Level.ERROR, "parse the JarFile error", e); } finally { // Close jar file, but only if freshly obtained - // not from JarURLConnection, which might cache the file reference. if (newJarFile) { try { jarFile.close(); } catch (final IOException e) { LOGGER.log(Level.WARN, " occur error when closing jarFile", e); } } } return result; }
java
private static Collection<? extends URL> doFindPathMatchingJarResources(final URL rootDirResource, final String subPattern) { final Set<URL> result = new LinkedHashSet<URL>(); JarFile jarFile = null; String jarFileUrl; String rootEntryPath = null; URLConnection con; boolean newJarFile = false; try { con = rootDirResource.openConnection(); if (con instanceof JarURLConnection) { final JarURLConnection jarCon = (JarURLConnection) con; jarCon.setUseCaches(false); jarFile = jarCon.getJarFile(); jarFileUrl = jarCon.getJarFileURL().toExternalForm(); final JarEntry jarEntry = jarCon.getJarEntry(); rootEntryPath = jarEntry != null ? jarEntry.getName() : ""; } else { // No JarURLConnection -> need to resort to URL file parsing. // We'll assume URLs of the format "jar:path!/entry", with the // protocol // being arbitrary as long as following the entry format. // We'll also handle paths with and without leading "file:" // prefix. final String urlFile = rootDirResource.getFile(); final int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR); if (separatorIndex != -1) { jarFileUrl = urlFile.substring(0, separatorIndex); rootEntryPath = urlFile.substring(separatorIndex + JAR_URL_SEPARATOR.length()); jarFile = getJarFile(jarFileUrl); } else { jarFile = new JarFile(urlFile); jarFileUrl = urlFile; rootEntryPath = ""; } newJarFile = true; } } catch (final IOException e) { LOGGER.log(Level.ERROR, "reslove jar File error", e); return result; } try { if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) { // Root entry path must end with slash to allow for proper // matching. // The Sun JRE does not return a slash here, but BEA JRockit // does. rootEntryPath = rootEntryPath + "/"; } for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) { final JarEntry entry = (JarEntry) entries.nextElement(); final String entryPath = entry.getName(); String relativePath = null; if (entryPath.startsWith(rootEntryPath)) { relativePath = entryPath.substring(rootEntryPath.length()); if (AntPathMatcher.match(subPattern, relativePath)) { if (relativePath.startsWith("/")) { relativePath = relativePath.substring(1); } result.add(new URL(rootDirResource, relativePath)); } } } return result; } catch (final IOException e) { LOGGER.log(Level.ERROR, "parse the JarFile error", e); } finally { // Close jar file, but only if freshly obtained - // not from JarURLConnection, which might cache the file reference. if (newJarFile) { try { jarFile.close(); } catch (final IOException e) { LOGGER.log(Level.WARN, " occur error when closing jarFile", e); } } } return result; }
[ "private", "static", "Collection", "<", "?", "extends", "URL", ">", "doFindPathMatchingJarResources", "(", "final", "URL", "rootDirResource", ",", "final", "String", "subPattern", ")", "{", "final", "Set", "<", "URL", ">", "result", "=", "new", "LinkedHashSet", ...
scan the jar to get the URLS of the Classes. @param rootDirResource which is "Jar" @param subPattern subPattern @return the URLs of all the matched classes
[ "scan", "the", "jar", "to", "get", "the", "URLS", "of", "the", "Classes", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java#L179-L268
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java
ClassPathResolver.doFindPathMatchingFileResources
private static Collection<? extends URL> doFindPathMatchingFileResources(final URL rootDirResource, final String subPattern) { File rootFile = null; final Set<URL> rets = new LinkedHashSet<URL>(); try { rootFile = new File(rootDirResource.toURI()); } catch (final URISyntaxException e) { LOGGER.log(Level.ERROR, "cat not resolve the rootFile", e); throw new RuntimeException("cat not resolve the rootFile", e); } String fullPattern = StringUtils.replace(rootFile.getAbsolutePath(), File.separator, "/"); if (!subPattern.startsWith("/")) { fullPattern += "/"; } final String filePattern = fullPattern + StringUtils.replace(subPattern, File.separator, "/"); @SuppressWarnings("unchecked") final Collection<File> files = FileUtils.listFiles(rootFile, new IOFileFilter() { @Override public boolean accept(final File dir, final String name) { return true; } @Override public boolean accept(final File file) { if (file.isDirectory()) { return false; } if (AntPathMatcher.match(filePattern, StringUtils.replace(file.getAbsolutePath(), File.separator, "/"))) { return true; } return false; } }, TrueFileFilter.INSTANCE); try { for (File file : files) { rets.add(file.toURI().toURL()); } } catch (final Exception e) { LOGGER.log(Level.ERROR, "convert file to URL error", e); throw new RuntimeException("convert file to URL error", e); } return rets; }
java
private static Collection<? extends URL> doFindPathMatchingFileResources(final URL rootDirResource, final String subPattern) { File rootFile = null; final Set<URL> rets = new LinkedHashSet<URL>(); try { rootFile = new File(rootDirResource.toURI()); } catch (final URISyntaxException e) { LOGGER.log(Level.ERROR, "cat not resolve the rootFile", e); throw new RuntimeException("cat not resolve the rootFile", e); } String fullPattern = StringUtils.replace(rootFile.getAbsolutePath(), File.separator, "/"); if (!subPattern.startsWith("/")) { fullPattern += "/"; } final String filePattern = fullPattern + StringUtils.replace(subPattern, File.separator, "/"); @SuppressWarnings("unchecked") final Collection<File> files = FileUtils.listFiles(rootFile, new IOFileFilter() { @Override public boolean accept(final File dir, final String name) { return true; } @Override public boolean accept(final File file) { if (file.isDirectory()) { return false; } if (AntPathMatcher.match(filePattern, StringUtils.replace(file.getAbsolutePath(), File.separator, "/"))) { return true; } return false; } }, TrueFileFilter.INSTANCE); try { for (File file : files) { rets.add(file.toURI().toURL()); } } catch (final Exception e) { LOGGER.log(Level.ERROR, "convert file to URL error", e); throw new RuntimeException("convert file to URL error", e); } return rets; }
[ "private", "static", "Collection", "<", "?", "extends", "URL", ">", "doFindPathMatchingFileResources", "(", "final", "URL", "rootDirResource", ",", "final", "String", "subPattern", ")", "{", "File", "rootFile", "=", "null", ";", "final", "Set", "<", "URL", ">"...
scan the system file to get the URLS of the Classes. @param rootDirResource rootDirResource which is in File System @param subPattern subPattern @return the URLs of all the matched classes
[ "scan", "the", "system", "file", "to", "get", "the", "URLS", "of", "the", "Classes", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/ioc/ClassPathResolver.java#L298-L345
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.handle
public static RequestContext handle(final HttpServletRequest request, final HttpServletResponse response) { try { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Sets request context character encoding failed", e); } final RequestContext ret = new RequestContext(); ret.setRequest(request); ret.setResponse(response); Latkes.REQUEST_CONTEXT.set(ret); for (final Handler handler : HANDLERS) { ret.addHandler(handler); } ret.handle(); result(ret); Latkes.REQUEST_CONTEXT.set(null); return ret; }
java
public static RequestContext handle(final HttpServletRequest request, final HttpServletResponse response) { try { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Sets request context character encoding failed", e); } final RequestContext ret = new RequestContext(); ret.setRequest(request); ret.setResponse(response); Latkes.REQUEST_CONTEXT.set(ret); for (final Handler handler : HANDLERS) { ret.addHandler(handler); } ret.handle(); result(ret); Latkes.REQUEST_CONTEXT.set(null); return ret; }
[ "public", "static", "RequestContext", "handle", "(", "final", "HttpServletRequest", "request", ",", "final", "HttpServletResponse", "response", ")", "{", "try", "{", "request", ".", "setCharacterEncoding", "(", "\"UTF-8\"", ")", ";", "response", ".", "setCharacterEn...
Handle flow. @param request the specified request @param response the specified response @return context
[ "Handle", "flow", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L79-L101
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.result
public static void result(final RequestContext context) { final HttpServletResponse response = context.getResponse(); if (response.isCommitted()) { // Response sends redirect or error return; } AbstractResponseRenderer renderer = context.getRenderer(); if (null == renderer) { renderer = new Http404Renderer(); } renderer.render(context); }
java
public static void result(final RequestContext context) { final HttpServletResponse response = context.getResponse(); if (response.isCommitted()) { // Response sends redirect or error return; } AbstractResponseRenderer renderer = context.getRenderer(); if (null == renderer) { renderer = new Http404Renderer(); } renderer.render(context); }
[ "public", "static", "void", "result", "(", "final", "RequestContext", "context", ")", "{", "final", "HttpServletResponse", "response", "=", "context", ".", "getResponse", "(", ")", ";", "if", "(", "response", ".", "isCommitted", "(", ")", ")", "{", "// Respo...
Do HTTP response. @param context {@link RequestContext}
[ "Do", "HTTP", "response", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L108-L119
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.delete
public static Router delete(final String uriTemplate, final ContextHandler handler) { return route().delete(uriTemplate, handler); }
java
public static Router delete(final String uriTemplate, final ContextHandler handler) { return route().delete(uriTemplate, handler); }
[ "public", "static", "Router", "delete", "(", "final", "String", "uriTemplate", ",", "final", "ContextHandler", "handler", ")", "{", "return", "route", "(", ")", ".", "delete", "(", "uriTemplate", ",", "handler", ")", ";", "}" ]
HTTP DELETE routing. @param uriTemplate the specified request URI template @param handler the specified handler @return router
[ "HTTP", "DELETE", "routing", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L133-L135
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.put
public static Router put(final String uriTemplate, final ContextHandler handler) { return route().put(uriTemplate, handler); }
java
public static Router put(final String uriTemplate, final ContextHandler handler) { return route().put(uriTemplate, handler); }
[ "public", "static", "Router", "put", "(", "final", "String", "uriTemplate", ",", "final", "ContextHandler", "handler", ")", "{", "return", "route", "(", ")", ".", "put", "(", "uriTemplate", ",", "handler", ")", ";", "}" ]
HTTP PUT routing. @param uriTemplate the specified request URI template @param handler the specified handler @return router
[ "HTTP", "PUT", "routing", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L144-L146
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.get
public static Router get(final String uriTemplate, final ContextHandler handler) { return route().get(uriTemplate, handler); }
java
public static Router get(final String uriTemplate, final ContextHandler handler) { return route().get(uriTemplate, handler); }
[ "public", "static", "Router", "get", "(", "final", "String", "uriTemplate", ",", "final", "ContextHandler", "handler", ")", "{", "return", "route", "(", ")", ".", "get", "(", "uriTemplate", ",", "handler", ")", ";", "}" ]
HTTP GET routing. @param uriTemplate the specified request URI template @param handler the specified handler @return router
[ "HTTP", "GET", "routing", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L155-L157
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.post
public static Router post(final String uriTemplate, final ContextHandler handler) { return route().post(uriTemplate, handler); }
java
public static Router post(final String uriTemplate, final ContextHandler handler) { return route().post(uriTemplate, handler); }
[ "public", "static", "Router", "post", "(", "final", "String", "uriTemplate", ",", "final", "ContextHandler", "handler", ")", "{", "return", "route", "(", ")", ".", "post", "(", "uriTemplate", ",", "handler", ")", ";", "}" ]
HTTP POST routing. @param uriTemplate the specified request URI template @param handler the specified handler @return router
[ "HTTP", "POST", "routing", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L166-L168
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java
DispatcherServlet.mapping
public static void mapping() { for (final Router router : routers) { final ContextHandlerMeta contextHandlerMeta = router.toContextHandlerMeta(); RouteHandler.addContextHandlerMeta(contextHandlerMeta); } }
java
public static void mapping() { for (final Router router : routers) { final ContextHandlerMeta contextHandlerMeta = router.toContextHandlerMeta(); RouteHandler.addContextHandlerMeta(contextHandlerMeta); } }
[ "public", "static", "void", "mapping", "(", ")", "{", "for", "(", "final", "Router", "router", ":", "routers", ")", "{", "final", "ContextHandlerMeta", "contextHandlerMeta", "=", "router", ".", "toContextHandlerMeta", "(", ")", ";", "RouteHandler", ".", "addCo...
Performs mapping for all routers.
[ "Performs", "mapping", "for", "all", "routers", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/DispatcherServlet.java#L185-L190
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/repository/jdbc/JdbcTransaction.java
JdbcTransaction.dispose
public void dispose() { try { connection.close(); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Disposes transaction [" + getId() + "] failed", e); } finally { isActive = false; connection = null; JdbcRepository.TX.set(null); } }
java
public void dispose() { try { connection.close(); } catch (final Exception e) { LOGGER.log(Level.ERROR, "Disposes transaction [" + getId() + "] failed", e); } finally { isActive = false; connection = null; JdbcRepository.TX.set(null); } }
[ "public", "void", "dispose", "(", ")", "{", "try", "{", "connection", ".", "close", "(", ")", ";", "}", "catch", "(", "final", "Exception", "e", ")", "{", "LOGGER", ".", "log", "(", "Level", ".", "ERROR", ",", "\"Disposes transaction [\"", "+", "getId"...
Disposes this transaction.
[ "Disposes", "this", "transaction", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/repository/jdbc/JdbcTransaction.java#L118-L128
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Callstacks.java
Callstacks.isCaller
public static boolean isCaller(final String className, final String methodName) { final Throwable throwable = new Throwable(); final StackTraceElement[] stackElements = throwable.getStackTrace(); if (null == stackElements) { LOGGER.log(Level.WARN, "Empty call stack"); return false; } final boolean matchAllMethod = "*".equals(methodName); for (int i = 1; i < stackElements.length; i++) { if (stackElements[i].getClassName().equals(className)) { return matchAllMethod ? true : stackElements[i].getMethodName().equals(methodName); } } return false; }
java
public static boolean isCaller(final String className, final String methodName) { final Throwable throwable = new Throwable(); final StackTraceElement[] stackElements = throwable.getStackTrace(); if (null == stackElements) { LOGGER.log(Level.WARN, "Empty call stack"); return false; } final boolean matchAllMethod = "*".equals(methodName); for (int i = 1; i < stackElements.length; i++) { if (stackElements[i].getClassName().equals(className)) { return matchAllMethod ? true : stackElements[i].getMethodName().equals(methodName); } } return false; }
[ "public", "static", "boolean", "isCaller", "(", "final", "String", "className", ",", "final", "String", "methodName", ")", "{", "final", "Throwable", "throwable", "=", "new", "Throwable", "(", ")", ";", "final", "StackTraceElement", "[", "]", "stackElements", ...
Checks the current method is whether invoked by a caller specified by the given class name and method name. @param className the given class name @param methodName the given method name, "*" for matching all methods @return {@code true} if it is invoked by the specified caller, returns {@code false} otherwise
[ "Checks", "the", "current", "method", "is", "whether", "invoked", "by", "a", "caller", "specified", "by", "the", "given", "class", "name", "and", "method", "name", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Callstacks.java#L42-L61
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Callstacks.java
Callstacks.printCallstack
public static void printCallstack(final Level logLevel, final String[] carePackages, final String[] exceptablePackages) { if (null == logLevel) { LOGGER.log(Level.WARN, "Requires parameter [logLevel]"); return; } final Throwable throwable = new Throwable(); final StackTraceElement[] stackElements = throwable.getStackTrace(); if (null == stackElements) { LOGGER.log(Level.WARN, "Empty call stack"); return; } final long tId = Thread.currentThread().getId(); final StringBuilder stackBuilder = new StringBuilder("CallStack [tId=").append(tId).append(Strings.LINE_SEPARATOR); for (int i = 1; i < stackElements.length; i++) { final String stackElemClassName = stackElements[i].getClassName(); if (!StringUtils.startsWithAny(stackElemClassName, carePackages) || StringUtils.startsWithAny(stackElemClassName, exceptablePackages)) { continue; } stackBuilder.append(" [className=").append(stackElements[i].getClassName()).append(", fileName=").append(stackElements[i].getFileName()).append(", lineNumber=").append(stackElements[i].getLineNumber()).append(", methodName=").append(stackElements[i].getMethodName()).append(']').append( Strings.LINE_SEPARATOR); } stackBuilder.append("], full depth [").append(stackElements.length).append("]"); LOGGER.log(logLevel, stackBuilder.toString()); }
java
public static void printCallstack(final Level logLevel, final String[] carePackages, final String[] exceptablePackages) { if (null == logLevel) { LOGGER.log(Level.WARN, "Requires parameter [logLevel]"); return; } final Throwable throwable = new Throwable(); final StackTraceElement[] stackElements = throwable.getStackTrace(); if (null == stackElements) { LOGGER.log(Level.WARN, "Empty call stack"); return; } final long tId = Thread.currentThread().getId(); final StringBuilder stackBuilder = new StringBuilder("CallStack [tId=").append(tId).append(Strings.LINE_SEPARATOR); for (int i = 1; i < stackElements.length; i++) { final String stackElemClassName = stackElements[i].getClassName(); if (!StringUtils.startsWithAny(stackElemClassName, carePackages) || StringUtils.startsWithAny(stackElemClassName, exceptablePackages)) { continue; } stackBuilder.append(" [className=").append(stackElements[i].getClassName()).append(", fileName=").append(stackElements[i].getFileName()).append(", lineNumber=").append(stackElements[i].getLineNumber()).append(", methodName=").append(stackElements[i].getMethodName()).append(']').append( Strings.LINE_SEPARATOR); } stackBuilder.append("], full depth [").append(stackElements.length).append("]"); LOGGER.log(logLevel, stackBuilder.toString()); }
[ "public", "static", "void", "printCallstack", "(", "final", "Level", "logLevel", ",", "final", "String", "[", "]", "carePackages", ",", "final", "String", "[", "]", "exceptablePackages", ")", "{", "if", "(", "null", "==", "logLevel", ")", "{", "LOGGER", "....
Prints call stack with the specified logging level. @param logLevel the specified logging level @param carePackages the specified packages to print, for example, ["org.b3log.latke", "org.b3log.solo"], {@code null} to care nothing @param exceptablePackages the specified packages to skip, for example, ["com.sun", "java.io", "org.b3log.solo.filter"], {@code null} to skip nothing
[ "Prints", "call", "stack", "with", "the", "specified", "logging", "level", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Callstacks.java#L72-L105
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java
Stopwatchs.start
public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
java
public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
[ "public", "static", "void", "start", "(", "final", "String", "taskTitle", ")", "{", "Stopwatch", "root", "=", "STOPWATCH", ".", "get", "(", ")", ";", "if", "(", "null", "==", "root", ")", "{", "root", "=", "new", "Stopwatch", "(", "taskTitle", ")", "...
Starts a task timing with the specified task title. @param taskTitle the specified task title
[ "Starts", "a", "task", "timing", "with", "the", "specified", "task", "title", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java#L105-L122
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java
Stopwatchs.getTimingStat
public static String getTimingStat() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return "No stopwatch"; } final StringBuilder stringBuilder = new StringBuilder(); root.appendTimingStat(1, stringBuilder); return stringBuilder.toString(); }
java
public static String getTimingStat() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return "No stopwatch"; } final StringBuilder stringBuilder = new StringBuilder(); root.appendTimingStat(1, stringBuilder); return stringBuilder.toString(); }
[ "public", "static", "String", "getTimingStat", "(", ")", "{", "final", "Stopwatch", "root", "=", "STOPWATCH", ".", "get", "(", ")", ";", "if", "(", "null", "==", "root", ")", "{", "return", "\"No stopwatch\"", ";", "}", "final", "StringBuilder", "stringBui...
Gets the current timing statistics. <p> If a task is not ended, the outputs will be minus for percentage and elapsed, the absolute value of the elapsed filed is the start time. </p> @return the current timing statistics, returns {@code "No stopwatch"} if not stopwatch
[ "Gets", "the", "current", "timing", "statistics", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java#L164-L176
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java
Stopwatchs.getElapsed
public static long getElapsed(final String taskTitle) { final long currentTimeMillis = System.currentTimeMillis(); if (StringUtils.isBlank(taskTitle)) { return -1; } final Stopwatch root = STOPWATCH.get(); if (null == root) { return -1; } final Stopwatch stopwatch = get(root, taskTitle); if (null == stopwatch) { return -1; } if (stopwatch.isEnded()) { return stopwatch.getElapsedTime(); } return currentTimeMillis - stopwatch.getStartTime(); }
java
public static long getElapsed(final String taskTitle) { final long currentTimeMillis = System.currentTimeMillis(); if (StringUtils.isBlank(taskTitle)) { return -1; } final Stopwatch root = STOPWATCH.get(); if (null == root) { return -1; } final Stopwatch stopwatch = get(root, taskTitle); if (null == stopwatch) { return -1; } if (stopwatch.isEnded()) { return stopwatch.getElapsedTime(); } return currentTimeMillis - stopwatch.getStartTime(); }
[ "public", "static", "long", "getElapsed", "(", "final", "String", "taskTitle", ")", "{", "final", "long", "currentTimeMillis", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "if", "(", "StringUtils", ".", "isBlank", "(", "taskTitle", ")", ")", "{", ...
Gets elapsed time from the specified parent stopwatch with the specified task title. @param taskTitle the specified task title @return <ul> <li>{@linkplain org.b3log.latke.util.Stopwatchs.Stopwatch#getElapsedTime() elapsed time} of the found task if it {@linkplain org.b3log.latke.util.Stopwatchs.Stopwatch#isEnded() is ended}</li> <li>{@linkplain System#currentTimeMillis() the current time} subtracts {@linkplain org.b3log.latke.util.Stopwatchs.Stopwatch#startTime the start time} of the found task if it {@linkplain org.b3log.latke.util.Stopwatchs.Stopwatch#isRunning() is running} </li> <li>{@code -1} if not found any stopwatch corresponding to the specified task title</li> </ul>
[ "Gets", "elapsed", "time", "from", "the", "specified", "parent", "stopwatch", "with", "the", "specified", "task", "title", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java#L191-L215
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java
Stopwatchs.get
private static Stopwatch get(final Stopwatch parent, final String taskTitle) { if (taskTitle.equals(parent.getTaskTitle())) { return parent; } for (final Stopwatch leaf : parent.getLeaves()) { final Stopwatch ret = get(leaf, taskTitle); if (null != ret) { return ret; } } return null; }
java
private static Stopwatch get(final Stopwatch parent, final String taskTitle) { if (taskTitle.equals(parent.getTaskTitle())) { return parent; } for (final Stopwatch leaf : parent.getLeaves()) { final Stopwatch ret = get(leaf, taskTitle); if (null != ret) { return ret; } } return null; }
[ "private", "static", "Stopwatch", "get", "(", "final", "Stopwatch", "parent", ",", "final", "String", "taskTitle", ")", "{", "if", "(", "taskTitle", ".", "equals", "(", "parent", ".", "getTaskTitle", "(", ")", ")", ")", "{", "return", "parent", ";", "}",...
Gets stopwatch from the specified parent stopwatch with the specified task title. @param parent the specified parent @param taskTitle the specified task title @return stopwatch, returns {@code null} if not found
[ "Gets", "stopwatch", "from", "the", "specified", "parent", "stopwatch", "with", "the", "specified", "task", "title", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java#L224-L238
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java
Stopwatchs.getRecentRunning
private static Stopwatch getRecentRunning(final Stopwatch parent) { if (null == parent) { return null; } final List<Stopwatch> leaves = parent.getLeaves(); if (leaves.isEmpty()) { if (parent.isRunning()) { return parent; } else { return null; } } for (int i = leaves.size() - 1; i > -1; i--) { final Stopwatch leaf = leaves.get(i); if (leaf.isRunning()) { return getRecentRunning(leaf); } else { continue; } } return parent; }
java
private static Stopwatch getRecentRunning(final Stopwatch parent) { if (null == parent) { return null; } final List<Stopwatch> leaves = parent.getLeaves(); if (leaves.isEmpty()) { if (parent.isRunning()) { return parent; } else { return null; } } for (int i = leaves.size() - 1; i > -1; i--) { final Stopwatch leaf = leaves.get(i); if (leaf.isRunning()) { return getRecentRunning(leaf); } else { continue; } } return parent; }
[ "private", "static", "Stopwatch", "getRecentRunning", "(", "final", "Stopwatch", "parent", ")", "{", "if", "(", "null", "==", "parent", ")", "{", "return", "null", ";", "}", "final", "List", "<", "Stopwatch", ">", "leaves", "=", "parent", ".", "getLeaves",...
Gets the recent running stopwatch with the specified parent stopwatch. @param parent the specified parent stopwatch @return the recent stopwatch, returns {@code null} if not found
[ "Gets", "the", "recent", "running", "stopwatch", "with", "the", "specified", "parent", "stopwatch", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Stopwatchs.java#L246-L272
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.isIPv4
public static boolean isIPv4(final String ip) { if (StringUtils.isBlank(ip)) { return false; } final String regex = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(ip); return matcher.matches(); }
java
public static boolean isIPv4(final String ip) { if (StringUtils.isBlank(ip)) { return false; } final String regex = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(ip); return matcher.matches(); }
[ "public", "static", "boolean", "isIPv4", "(", "final", "String", "ip", ")", "{", "if", "(", "StringUtils", ".", "isBlank", "(", "ip", ")", ")", "{", "return", "false", ";", "}", "final", "String", "regex", "=", "\"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.(2...
Is IPv4. @param ip ip @return {@code true} if it is, returns {@code false} otherwise
[ "Is", "IPv4", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L77-L87
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.toLines
public static List<String> toLines(final String string) throws IOException { if (null == string) { return null; } final List<String> ret = new ArrayList<>(); try (final BufferedReader bufferedReader = new BufferedReader(new StringReader(string))) { String line = bufferedReader.readLine(); while (null != line) { ret.add(line); line = bufferedReader.readLine(); } } return ret; }
java
public static List<String> toLines(final String string) throws IOException { if (null == string) { return null; } final List<String> ret = new ArrayList<>(); try (final BufferedReader bufferedReader = new BufferedReader(new StringReader(string))) { String line = bufferedReader.readLine(); while (null != line) { ret.add(line); line = bufferedReader.readLine(); } } return ret; }
[ "public", "static", "List", "<", "String", ">", "toLines", "(", "final", "String", "string", ")", "throws", "IOException", "{", "if", "(", "null", "==", "string", ")", "{", "return", "null", ";", "}", "final", "List", "<", "String", ">", "ret", "=", ...
Converts the specified string into a string list line by line. @param string the specified string @return a list of string lines, returns {@code null} if the specified string is {@code null} @throws IOException io exception
[ "Converts", "the", "specified", "string", "into", "a", "string", "list", "line", "by", "line", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L97-L113
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.isNumeric
public static boolean isNumeric(final String string) { try { Double.parseDouble(string); } catch (final Exception e) { return false; } return true; }
java
public static boolean isNumeric(final String string) { try { Double.parseDouble(string); } catch (final Exception e) { return false; } return true; }
[ "public", "static", "boolean", "isNumeric", "(", "final", "String", "string", ")", "{", "try", "{", "Double", ".", "parseDouble", "(", "string", ")", ";", "}", "catch", "(", "final", "Exception", "e", ")", "{", "return", "false", ";", "}", "return", "t...
Checks whether the specified string is numeric. @param string the specified string @return {@code true} if the specified string is numeric, returns {@code false} otherwise
[ "Checks", "whether", "the", "specified", "string", "is", "numeric", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L121-L129
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.isEmail
public static boolean isEmail(final String string) { if (StringUtils.isBlank(string)) { return false; } if (MAX_EMAIL_LENGTH < string.length()) { return false; } final String[] parts = string.split("@"); if (2 != parts.length) { return false; } final String local = parts[0]; if (MAX_EMAIL_LENGTH_LOCAL < local.length()) { return false; } final String domain = parts[1]; if (MAX_EMAIL_LENGTH_DOMAIN < domain.length()) { return false; } return EMAIL_PATTERN.matcher(string).matches(); }
java
public static boolean isEmail(final String string) { if (StringUtils.isBlank(string)) { return false; } if (MAX_EMAIL_LENGTH < string.length()) { return false; } final String[] parts = string.split("@"); if (2 != parts.length) { return false; } final String local = parts[0]; if (MAX_EMAIL_LENGTH_LOCAL < local.length()) { return false; } final String domain = parts[1]; if (MAX_EMAIL_LENGTH_DOMAIN < domain.length()) { return false; } return EMAIL_PATTERN.matcher(string).matches(); }
[ "public", "static", "boolean", "isEmail", "(", "final", "String", "string", ")", "{", "if", "(", "StringUtils", ".", "isBlank", "(", "string", ")", ")", "{", "return", "false", ";", "}", "if", "(", "MAX_EMAIL_LENGTH", "<", "string", ".", "length", "(", ...
Checks whether the specified string is a valid email address. @param string the specified string @return {@code true} if the specified string is a valid email address, returns {@code false} otherwise
[ "Checks", "whether", "the", "specified", "string", "is", "a", "valid", "email", "address", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L154-L182
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.trimAll
public static String[] trimAll(final String[] strings) { if (null == strings) { return null; } return Arrays.stream(strings).map(StringUtils::trim).toArray(size -> new String[size]); }
java
public static String[] trimAll(final String[] strings) { if (null == strings) { return null; } return Arrays.stream(strings).map(StringUtils::trim).toArray(size -> new String[size]); }
[ "public", "static", "String", "[", "]", "trimAll", "(", "final", "String", "[", "]", "strings", ")", "{", "if", "(", "null", "==", "strings", ")", "{", "return", "null", ";", "}", "return", "Arrays", ".", "stream", "(", "strings", ")", ".", "map", ...
Trims every string in the specified strings array. @param strings the specified strings array, returns {@code null} if the specified strings is {@code null} @return a trimmed strings array
[ "Trims", "every", "string", "in", "the", "specified", "strings", "array", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L191-L197
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.containsIgnoreCase
public static boolean containsIgnoreCase(final String string, final String[] strings) { if (null == strings) { return false; } return Arrays.stream(strings).anyMatch(str -> StringUtils.equalsIgnoreCase(string, str)); }
java
public static boolean containsIgnoreCase(final String string, final String[] strings) { if (null == strings) { return false; } return Arrays.stream(strings).anyMatch(str -> StringUtils.equalsIgnoreCase(string, str)); }
[ "public", "static", "boolean", "containsIgnoreCase", "(", "final", "String", "string", ",", "final", "String", "[", "]", "strings", ")", "{", "if", "(", "null", "==", "strings", ")", "{", "return", "false", ";", "}", "return", "Arrays", ".", "stream", "(...
Determines whether the specified strings contains the specified string, ignoring case considerations. @param string the specified string @param strings the specified strings @return {@code true} if the specified strings contains the specified string, ignoring case considerations, returns {@code false} otherwise
[ "Determines", "whether", "the", "specified", "strings", "contains", "the", "specified", "string", "ignoring", "case", "considerations", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L207-L213
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Strings.java
Strings.contains
public static boolean contains(final String string, final String[] strings) { if (null == strings) { return false; } return Arrays.stream(strings).anyMatch(str -> StringUtils.equals(string, str)); }
java
public static boolean contains(final String string, final String[] strings) { if (null == strings) { return false; } return Arrays.stream(strings).anyMatch(str -> StringUtils.equals(string, str)); }
[ "public", "static", "boolean", "contains", "(", "final", "String", "string", ",", "final", "String", "[", "]", "strings", ")", "{", "if", "(", "null", "==", "strings", ")", "{", "return", "false", ";", "}", "return", "Arrays", ".", "stream", "(", "stri...
Determines whether the specified strings contains the specified string. @param string the specified string @param strings the specified strings @return {@code true} if the specified strings contains the specified string, returns {@code false} otherwise
[ "Determines", "whether", "the", "specified", "strings", "contains", "the", "specified", "string", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Strings.java#L222-L228
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/ContextHandlerMeta.java
ContextHandlerMeta.initBeforeList
private void initBeforeList() { final List<ProcessAdvice> beforeRequestProcessAdvices = new ArrayList<>(); final Method invokeHolder = getInvokeHolder(); final Class<?> processorClass = invokeHolder.getDeclaringClass(); // 1. process class advice if (null != processorClass && processorClass.isAnnotationPresent(Before.class)) { final Class<? extends ProcessAdvice>[] bcs = processorClass.getAnnotation(Before.class).value(); for (int i = 0; i < bcs.length; i++) { final Class<? extends ProcessAdvice> bc = bcs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(bc); beforeRequestProcessAdvices.add(beforeRequestProcessAdvice); } } // 2. process method advice if (invokeHolder.isAnnotationPresent(Before.class)) { final Class<? extends ProcessAdvice>[] bcs = invokeHolder.getAnnotation(Before.class).value(); for (int i = 0; i < bcs.length; i++) { final Class<? extends ProcessAdvice> bc = bcs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(bc); beforeRequestProcessAdvices.add(beforeRequestProcessAdvice); } } this.beforeRequestProcessAdvices = beforeRequestProcessAdvices; }
java
private void initBeforeList() { final List<ProcessAdvice> beforeRequestProcessAdvices = new ArrayList<>(); final Method invokeHolder = getInvokeHolder(); final Class<?> processorClass = invokeHolder.getDeclaringClass(); // 1. process class advice if (null != processorClass && processorClass.isAnnotationPresent(Before.class)) { final Class<? extends ProcessAdvice>[] bcs = processorClass.getAnnotation(Before.class).value(); for (int i = 0; i < bcs.length; i++) { final Class<? extends ProcessAdvice> bc = bcs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(bc); beforeRequestProcessAdvices.add(beforeRequestProcessAdvice); } } // 2. process method advice if (invokeHolder.isAnnotationPresent(Before.class)) { final Class<? extends ProcessAdvice>[] bcs = invokeHolder.getAnnotation(Before.class).value(); for (int i = 0; i < bcs.length; i++) { final Class<? extends ProcessAdvice> bc = bcs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(bc); beforeRequestProcessAdvices.add(beforeRequestProcessAdvice); } } this.beforeRequestProcessAdvices = beforeRequestProcessAdvices; }
[ "private", "void", "initBeforeList", "(", ")", "{", "final", "List", "<", "ProcessAdvice", ">", "beforeRequestProcessAdvices", "=", "new", "ArrayList", "<>", "(", ")", ";", "final", "Method", "invokeHolder", "=", "getInvokeHolder", "(", ")", ";", "final", "Cla...
Initializes before process advices.
[ "Initializes", "before", "process", "advices", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/ContextHandlerMeta.java#L169-L195
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/ContextHandlerMeta.java
ContextHandlerMeta.initAfterList
private void initAfterList() { final List<ProcessAdvice> afterRequestProcessAdvices = new ArrayList<>(); final Method invokeHolder = getInvokeHolder(); final Class<?> processorClass = invokeHolder.getDeclaringClass(); // 1. process method advice if (invokeHolder.isAnnotationPresent(After.class)) { final Class<? extends ProcessAdvice>[] acs = invokeHolder.getAnnotation(After.class).value(); for (int i = 0; i < acs.length; i++) { final Class<? extends ProcessAdvice> ac = acs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(ac); afterRequestProcessAdvices.add(beforeRequestProcessAdvice); } } // 2. process class advice if (null != processorClass && processorClass.isAnnotationPresent(After.class)) { final Class<? extends ProcessAdvice>[] acs = invokeHolder.getAnnotation(After.class).value(); for (int i = 0; i < acs.length; i++) { final Class<? extends ProcessAdvice> ac = acs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(ac); afterRequestProcessAdvices.add(beforeRequestProcessAdvice); } } this.afterRequestProcessAdvices = afterRequestProcessAdvices; }
java
private void initAfterList() { final List<ProcessAdvice> afterRequestProcessAdvices = new ArrayList<>(); final Method invokeHolder = getInvokeHolder(); final Class<?> processorClass = invokeHolder.getDeclaringClass(); // 1. process method advice if (invokeHolder.isAnnotationPresent(After.class)) { final Class<? extends ProcessAdvice>[] acs = invokeHolder.getAnnotation(After.class).value(); for (int i = 0; i < acs.length; i++) { final Class<? extends ProcessAdvice> ac = acs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(ac); afterRequestProcessAdvices.add(beforeRequestProcessAdvice); } } // 2. process class advice if (null != processorClass && processorClass.isAnnotationPresent(After.class)) { final Class<? extends ProcessAdvice>[] acs = invokeHolder.getAnnotation(After.class).value(); for (int i = 0; i < acs.length; i++) { final Class<? extends ProcessAdvice> ac = acs[i]; final ProcessAdvice beforeRequestProcessAdvice = BeanManager.getInstance().getReference(ac); afterRequestProcessAdvices.add(beforeRequestProcessAdvice); } } this.afterRequestProcessAdvices = afterRequestProcessAdvices; }
[ "private", "void", "initAfterList", "(", ")", "{", "final", "List", "<", "ProcessAdvice", ">", "afterRequestProcessAdvices", "=", "new", "ArrayList", "<>", "(", ")", ";", "final", "Method", "invokeHolder", "=", "getInvokeHolder", "(", ")", ";", "final", "Class...
Initializes after process advices.
[ "Initializes", "after", "process", "advices", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/ContextHandlerMeta.java#L200-L226
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/repository/Query.java
Query.select
public Query select(final String propertyName, final String... propertyNames) { projections.add(new Projection(propertyName)); if (null != propertyNames && 0 < propertyNames.length) { for (int i = 0; i < propertyNames.length; i++) { projections.add(new Projection(propertyNames[i])); } } return this; }
java
public Query select(final String propertyName, final String... propertyNames) { projections.add(new Projection(propertyName)); if (null != propertyNames && 0 < propertyNames.length) { for (int i = 0; i < propertyNames.length; i++) { projections.add(new Projection(propertyNames[i])); } } return this; }
[ "public", "Query", "select", "(", "final", "String", "propertyName", ",", "final", "String", "...", "propertyNames", ")", "{", "projections", ".", "add", "(", "new", "Projection", "(", "propertyName", ")", ")", ";", "if", "(", "null", "!=", "propertyNames", ...
Set SELECT projections. @param propertyName the specified property name @param propertyNames the specified other property names @return the current query object
[ "Set", "SELECT", "projections", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/repository/Query.java#L109-L119
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/repository/Query.java
Query.addSort
public Query addSort(final String propertyName, final SortDirection sortDirection) { sorts.put(propertyName, sortDirection); return this; }
java
public Query addSort(final String propertyName, final SortDirection sortDirection) { sorts.put(propertyName, sortDirection); return this; }
[ "public", "Query", "addSort", "(", "final", "String", "propertyName", ",", "final", "SortDirection", "sortDirection", ")", "{", "sorts", ".", "put", "(", "propertyName", ",", "sortDirection", ")", ";", "return", "this", ";", "}" ]
Adds sort for the specified property with the specified direction. @param propertyName the specified property name to sort @param sortDirection the specified sort @return the current query object
[ "Adds", "sort", "for", "the", "specified", "property", "with", "the", "specified", "direction", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/repository/Query.java#L137-L141
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getTimeAgo
public static String getTimeAgo(final long time, final Locale locale) { final BeanManager beanManager = BeanManager.getInstance(); final LangPropsService langService = beanManager.getReference(LangPropsService.class); final Map<String, String> langs = langService.getAll(locale); final long diff = System.currentTimeMillis() - time; long r; if (diff > YEAR_UNIT) { r = diff / YEAR_UNIT; return r + " " + langs.get("yearsAgoLabel"); } if (diff > MONTH_UNIT) { r = diff / MONTH_UNIT; return r + " " + langs.get("monthsAgoLabel"); } if (diff > WEEK_UNIT) { r = diff / WEEK_UNIT; return r + " " + langs.get("weeksAgoLabel"); } if (diff > DAY_UNIT) { r = diff / DAY_UNIT; return r + " " + langs.get("daysAgoLabel"); } if (diff > HOUR_UNIT) { r = diff / HOUR_UNIT; return r + " " + langs.get("hoursAgoLabel"); } if (diff > MINUTE_UNIT) { r = diff / MINUTE_UNIT; return r + " " + langs.get("minutesAgoLabel"); } return langs.get("justNowLabel"); }
java
public static String getTimeAgo(final long time, final Locale locale) { final BeanManager beanManager = BeanManager.getInstance(); final LangPropsService langService = beanManager.getReference(LangPropsService.class); final Map<String, String> langs = langService.getAll(locale); final long diff = System.currentTimeMillis() - time; long r; if (diff > YEAR_UNIT) { r = diff / YEAR_UNIT; return r + " " + langs.get("yearsAgoLabel"); } if (diff > MONTH_UNIT) { r = diff / MONTH_UNIT; return r + " " + langs.get("monthsAgoLabel"); } if (diff > WEEK_UNIT) { r = diff / WEEK_UNIT; return r + " " + langs.get("weeksAgoLabel"); } if (diff > DAY_UNIT) { r = diff / DAY_UNIT; return r + " " + langs.get("daysAgoLabel"); } if (diff > HOUR_UNIT) { r = diff / HOUR_UNIT; return r + " " + langs.get("hoursAgoLabel"); } if (diff > MINUTE_UNIT) { r = diff / MINUTE_UNIT; return r + " " + langs.get("minutesAgoLabel"); } return langs.get("justNowLabel"); }
[ "public", "static", "String", "getTimeAgo", "(", "final", "long", "time", ",", "final", "Locale", "locale", ")", "{", "final", "BeanManager", "beanManager", "=", "BeanManager", ".", "getInstance", "(", ")", ";", "final", "LangPropsService", "langService", "=", ...
Gets time ago format text. @param time the specified time. @param locale the specified locale @return time ago format text
[ "Gets", "time", "ago", "format", "text", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L72-L117
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.isSameDay
public static boolean isSameDay(final Date date1, final Date date2) { final Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.DATE) == cal2.get(Calendar.DATE); }
java
public static boolean isSameDay(final Date date1, final Date date2) { final Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.DATE) == cal2.get(Calendar.DATE); }
[ "public", "static", "boolean", "isSameDay", "(", "final", "Date", "date1", ",", "final", "Date", "date2", ")", "{", "final", "Calendar", "cal1", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal1", ".", "setTime", "(", "date1", ")", ";", "final", ...
Determines whether the specified date1 is the same day with the specified date2. @param date1 the specified date1 @param date2 the specified date2 @return {@code true} if it is the same day, returns {@code false} otherwise
[ "Determines", "whether", "the", "specified", "date1", "is", "the", "same", "day", "with", "the", "specified", "date2", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L126-L133
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.isSameWeek
public static boolean isSameWeek(final Date date1, final Date date2) { final Calendar cal1 = Calendar.getInstance(); cal1.setFirstDayOfWeek(Calendar.MONDAY); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setFirstDayOfWeek(Calendar.MONDAY); cal2.setTime(date2); return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR); }
java
public static boolean isSameWeek(final Date date1, final Date date2) { final Calendar cal1 = Calendar.getInstance(); cal1.setFirstDayOfWeek(Calendar.MONDAY); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setFirstDayOfWeek(Calendar.MONDAY); cal2.setTime(date2); return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR); }
[ "public", "static", "boolean", "isSameWeek", "(", "final", "Date", "date1", ",", "final", "Date", "date2", ")", "{", "final", "Calendar", "cal1", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal1", ".", "setFirstDayOfWeek", "(", "Calendar", ".", "M...
Determines whether the specified date1 is the same week with the specified date2. @param date1 the specified date1 @param date2 the specified date2 @return {@code true} if it is the same week, returns {@code false} otherwise
[ "Determines", "whether", "the", "specified", "date1", "is", "the", "same", "week", "with", "the", "specified", "date2", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L142-L154
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.isSameMonth
public static boolean isSameMonth(final Date date1, final Date date2) { final Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH); }
java
public static boolean isSameMonth(final Date date1, final Date date2) { final Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH); }
[ "public", "static", "boolean", "isSameMonth", "(", "final", "Date", "date1", ",", "final", "Date", "date2", ")", "{", "final", "Calendar", "cal1", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal1", ".", "setTime", "(", "date1", ")", ";", "final"...
Determines whether the specified date1 is the same month with the specified date2. @param date1 the specified date1 @param date2 the specified date2 @return {@code true} if it is the same month, returns {@code false} otherwise
[ "Determines", "whether", "the", "specified", "date1", "is", "the", "same", "month", "with", "the", "specified", "date2", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L163-L173
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getDayStartTime
public static long getDayStartTime(final long time) { final Calendar start = Calendar.getInstance(); start.setTimeInMillis(time); final int year = start.get(Calendar.YEAR); final int month = start.get(Calendar.MONTH); final int day = start.get(Calendar.DATE); start.set(year, month, day, 0, 0, 0); start.set(Calendar.MILLISECOND, 0); return start.getTimeInMillis(); }
java
public static long getDayStartTime(final long time) { final Calendar start = Calendar.getInstance(); start.setTimeInMillis(time); final int year = start.get(Calendar.YEAR); final int month = start.get(Calendar.MONTH); final int day = start.get(Calendar.DATE); start.set(year, month, day, 0, 0, 0); start.set(Calendar.MILLISECOND, 0); return start.getTimeInMillis(); }
[ "public", "static", "long", "getDayStartTime", "(", "final", "long", "time", ")", "{", "final", "Calendar", "start", "=", "Calendar", ".", "getInstance", "(", ")", ";", "start", ".", "setTimeInMillis", "(", "time", ")", ";", "final", "int", "year", "=", ...
Gets the day start time with the specified time. @param time the specified time @return day start time
[ "Gets", "the", "day", "start", "time", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L181-L191
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getDayEndTime
public static long getDayEndTime(final long time) { final Calendar end = Calendar.getInstance(); end.setTimeInMillis(time); final int year = end.get(Calendar.YEAR); final int month = end.get(Calendar.MONTH); final int day = end.get(Calendar.DATE); end.set(year, month, day, 23, 59, 59); end.set(Calendar.MILLISECOND, 999); return end.getTimeInMillis(); }
java
public static long getDayEndTime(final long time) { final Calendar end = Calendar.getInstance(); end.setTimeInMillis(time); final int year = end.get(Calendar.YEAR); final int month = end.get(Calendar.MONTH); final int day = end.get(Calendar.DATE); end.set(year, month, day, 23, 59, 59); end.set(Calendar.MILLISECOND, 999); return end.getTimeInMillis(); }
[ "public", "static", "long", "getDayEndTime", "(", "final", "long", "time", ")", "{", "final", "Calendar", "end", "=", "Calendar", ".", "getInstance", "(", ")", ";", "end", ".", "setTimeInMillis", "(", "time", ")", ";", "final", "int", "year", "=", "end",...
Gets the day end time with the specified time. @param time the specified time @return day end time
[ "Gets", "the", "day", "end", "time", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L199-L209
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getWeekDay
public static int getWeekDay(final long time) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); int ret = calendar.get(Calendar.DAY_OF_WEEK) - 1; if (ret <= 0) { ret = 7; } return ret; }
java
public static int getWeekDay(final long time) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); int ret = calendar.get(Calendar.DAY_OF_WEEK) - 1; if (ret <= 0) { ret = 7; } return ret; }
[ "public", "static", "int", "getWeekDay", "(", "final", "long", "time", ")", "{", "final", "Calendar", "calendar", "=", "Calendar", ".", "getInstance", "(", ")", ";", "calendar", ".", "setTimeInMillis", "(", "time", ")", ";", "int", "ret", "=", "calendar", ...
Gets the week day with the specified time. @param time the specified time @return week day
[ "Gets", "the", "week", "day", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L217-L226
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getWeekStartTime
public static long getWeekStartTime(final long time) { final Calendar start = Calendar.getInstance(); start.setFirstDayOfWeek(Calendar.MONDAY); start.setTimeInMillis(time); start.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); return start.getTimeInMillis(); }
java
public static long getWeekStartTime(final long time) { final Calendar start = Calendar.getInstance(); start.setFirstDayOfWeek(Calendar.MONDAY); start.setTimeInMillis(time); start.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); return start.getTimeInMillis(); }
[ "public", "static", "long", "getWeekStartTime", "(", "final", "long", "time", ")", "{", "final", "Calendar", "start", "=", "Calendar", ".", "getInstance", "(", ")", ";", "start", ".", "setFirstDayOfWeek", "(", "Calendar", ".", "MONDAY", ")", ";", "start", ...
Gets the week start time with the specified time. @param time the specified time @return week start time
[ "Gets", "the", "week", "start", "time", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L234-L245
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getWeekEndTime
public static long getWeekEndTime(final long time) { final Calendar end = Calendar.getInstance(); end.setFirstDayOfWeek(Calendar.MONDAY); end.setTimeInMillis(time); end.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); return end.getTimeInMillis(); }
java
public static long getWeekEndTime(final long time) { final Calendar end = Calendar.getInstance(); end.setFirstDayOfWeek(Calendar.MONDAY); end.setTimeInMillis(time); end.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); return end.getTimeInMillis(); }
[ "public", "static", "long", "getWeekEndTime", "(", "final", "long", "time", ")", "{", "final", "Calendar", "end", "=", "Calendar", ".", "getInstance", "(", ")", ";", "end", ".", "setFirstDayOfWeek", "(", "Calendar", ".", "MONDAY", ")", ";", "end", ".", "...
Gets the week end time with the specified time. @param time the specified time @return week end time
[ "Gets", "the", "week", "end", "time", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L253-L264
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getMonthStartTime
public static long getMonthStartTime(final long time) { final Calendar start = Calendar.getInstance(); start.setTimeInMillis(time); final int year = start.get(Calendar.YEAR); final int month = start.get(Calendar.MONTH); start.set(year, month, 1, 0, 0, 0); start.set(Calendar.MILLISECOND, 0); return start.getTimeInMillis(); }
java
public static long getMonthStartTime(final long time) { final Calendar start = Calendar.getInstance(); start.setTimeInMillis(time); final int year = start.get(Calendar.YEAR); final int month = start.get(Calendar.MONTH); start.set(year, month, 1, 0, 0, 0); start.set(Calendar.MILLISECOND, 0); return start.getTimeInMillis(); }
[ "public", "static", "long", "getMonthStartTime", "(", "final", "long", "time", ")", "{", "final", "Calendar", "start", "=", "Calendar", ".", "getInstance", "(", ")", ";", "start", ".", "setTimeInMillis", "(", "time", ")", ";", "final", "int", "year", "=", ...
Gets the month start time with the specified time. @param time the specified time @return month start time
[ "Gets", "the", "month", "start", "time", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L272-L281
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/Times.java
Times.getMonthEndTime
public static long getMonthEndTime(final long time) { final Calendar end = Calendar.getInstance(); end.setTimeInMillis(getDayStartTime(time)); end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH)); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); return end.getTimeInMillis(); }
java
public static long getMonthEndTime(final long time) { final Calendar end = Calendar.getInstance(); end.setTimeInMillis(getDayStartTime(time)); end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH)); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); return end.getTimeInMillis(); }
[ "public", "static", "long", "getMonthEndTime", "(", "final", "long", "time", ")", "{", "final", "Calendar", "end", "=", "Calendar", ".", "getInstance", "(", ")", ";", "end", ".", "setTimeInMillis", "(", "getDayStartTime", "(", "time", ")", ")", ";", "end",...
Gets the month end time with the specified time. @param time the specified time @return month end time
[ "Gets", "the", "month", "end", "time", "with", "the", "specified", "time", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/Times.java#L289-L299
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/util/CollectionUtils.java
CollectionUtils.arrayToSet
public static <T> Set<T> arrayToSet(final T[] array) { if (null == array) { return Collections.emptySet(); } final Set<T> ret = new HashSet<T>(); for (int i = 0; i < array.length; i++) { final T object = array[i]; ret.add(object); } return ret; }
java
public static <T> Set<T> arrayToSet(final T[] array) { if (null == array) { return Collections.emptySet(); } final Set<T> ret = new HashSet<T>(); for (int i = 0; i < array.length; i++) { final T object = array[i]; ret.add(object); } return ret; }
[ "public", "static", "<", "T", ">", "Set", "<", "T", ">", "arrayToSet", "(", "final", "T", "[", "]", "array", ")", "{", "if", "(", "null", "==", "array", ")", "{", "return", "Collections", ".", "emptySet", "(", ")", ";", "}", "final", "Set", "<", ...
Converts the specified array to a set. @param <T> the type of elements maintained by the specified array @param array the specified array @return a hash set
[ "Converts", "the", "specified", "array", "to", "a", "set", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/util/CollectionUtils.java#L93-L107
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java
RouteHandler.doMatch
public static MatchResult doMatch(final String requestURI, final String httpMethod) { MatchResult ret; final int segs = StringUtils.countMatches(requestURI, "/"); ContextHandlerMeta contextHandlerMeta; String concreteKey = httpMethod + "." + requestURI; switch (segs) { case 1: contextHandlerMeta = ONE_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, ONE_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, ONE_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, ONE_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, ONE_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, ONE_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } case 2: contextHandlerMeta = TWO_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, TWO_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, TWO_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, TWO_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, TWO_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, TWO_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } case 3: contextHandlerMeta = THREE_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, THREE_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, THREE_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, THREE_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, THREE_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, THREE_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } default: contextHandlerMeta = FOUR_MORE_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, FOUR_MORE_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, FOUR_MORE_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, FOUR_MORE_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, FOUR_MORE_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, FOUR_MORE_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } } }
java
public static MatchResult doMatch(final String requestURI, final String httpMethod) { MatchResult ret; final int segs = StringUtils.countMatches(requestURI, "/"); ContextHandlerMeta contextHandlerMeta; String concreteKey = httpMethod + "." + requestURI; switch (segs) { case 1: contextHandlerMeta = ONE_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, ONE_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, ONE_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, ONE_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, ONE_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, ONE_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } case 2: contextHandlerMeta = TWO_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, TWO_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, TWO_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, TWO_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, TWO_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, TWO_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } case 3: contextHandlerMeta = THREE_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, THREE_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, THREE_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, THREE_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, THREE_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, THREE_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } default: contextHandlerMeta = FOUR_MORE_SEG_CONCRETE_CTX_HANDLER_METAS.get(concreteKey); if (null != contextHandlerMeta) { return new MatchResult(contextHandlerMeta, requestURI, httpMethod, requestURI); } switch (httpMethod) { case "GET": return route(requestURI, httpMethod, FOUR_MORE_SEG_GET_VAR_CTX_HANDLER_METAS); case "POST": return route(requestURI, httpMethod, FOUR_MORE_SEG_POST_VAR_CTX_HANDLER_METAS); case "PUT": return route(requestURI, httpMethod, FOUR_MORE_SEG_PUT_VAR_CTX_HANDLER_METAS); case "DELETE": return route(requestURI, httpMethod, FOUR_MORE_SEG_DELETE_VAR_CTX_HANDLER_METAS); default: return route(requestURI, httpMethod, FOUR_MORE_SEG_OTHER_METHOD_VAR_CTX_HANDLER_METAS); } } }
[ "public", "static", "MatchResult", "doMatch", "(", "final", "String", "requestURI", ",", "final", "String", "httpMethod", ")", "{", "MatchResult", "ret", ";", "final", "int", "segs", "=", "StringUtils", ".", "countMatches", "(", "requestURI", ",", "\"/\"", ")"...
Routes the request specified by the given request URI and HTTP method. @param requestURI the given request URI @param httpMethod the given HTTP method @return MatchResult, returns {@code null} if not found
[ "Routes", "the", "request", "specified", "by", "the", "given", "request", "URI", "and", "HTTP", "method", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java#L215-L294
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java
RouteHandler.route
private static MatchResult route(final String requestURI, final String httpMethod, final Map<String, ContextHandlerMeta> pathVarContextHandlerMetasHolder) { MatchResult ret; for (final Map.Entry<String, ContextHandlerMeta> entry : pathVarContextHandlerMetasHolder.entrySet()) { final String uriTemplate = entry.getKey(); final ContextHandlerMeta contextHandlerMeta = entry.getValue(); final Map<String, String> resolveResult = UriTemplates.resolve(requestURI, uriTemplate); if (null == resolveResult) { continue; } ret = new MatchResult(contextHandlerMeta, requestURI, httpMethod, uriTemplate); ret.setPathVars(resolveResult); return ret; } return null; }
java
private static MatchResult route(final String requestURI, final String httpMethod, final Map<String, ContextHandlerMeta> pathVarContextHandlerMetasHolder) { MatchResult ret; for (final Map.Entry<String, ContextHandlerMeta> entry : pathVarContextHandlerMetasHolder.entrySet()) { final String uriTemplate = entry.getKey(); final ContextHandlerMeta contextHandlerMeta = entry.getValue(); final Map<String, String> resolveResult = UriTemplates.resolve(requestURI, uriTemplate); if (null == resolveResult) { continue; } ret = new MatchResult(contextHandlerMeta, requestURI, httpMethod, uriTemplate); ret.setPathVars(resolveResult); return ret; } return null; }
[ "private", "static", "MatchResult", "route", "(", "final", "String", "requestURI", ",", "final", "String", "httpMethod", ",", "final", "Map", "<", "String", ",", "ContextHandlerMeta", ">", "pathVarContextHandlerMetasHolder", ")", "{", "MatchResult", "ret", ";", "f...
Routes the specified request URI containing path vars with the specified HTTP method and path var context handler metas holder. @param requestURI the specified request URI @param httpMethod the specified HTTP method @param pathVarContextHandlerMetasHolder the specified path var context handler metas holder @return match result, returns {@code null} if not found
[ "Routes", "the", "specified", "request", "URI", "containing", "path", "vars", "with", "the", "specified", "HTTP", "method", "and", "path", "var", "context", "handler", "metas", "holder", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java#L441-L458
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java
RouteHandler.getHttpMethod
private String getHttpMethod(final HttpServletRequest request) { String ret = (String) request.getAttribute(Keys.HttpRequest.REQUEST_METHOD); if (StringUtils.isBlank(ret)) { ret = request.getMethod(); } return ret; }
java
private String getHttpMethod(final HttpServletRequest request) { String ret = (String) request.getAttribute(Keys.HttpRequest.REQUEST_METHOD); if (StringUtils.isBlank(ret)) { ret = request.getMethod(); } return ret; }
[ "private", "String", "getHttpMethod", "(", "final", "HttpServletRequest", "request", ")", "{", "String", "ret", "=", "(", "String", ")", "request", ".", "getAttribute", "(", "Keys", ".", "HttpRequest", ".", "REQUEST_METHOD", ")", ";", "if", "(", "StringUtils",...
Gets the HTTP method. @param request the specified request @return HTTP method
[ "Gets", "the", "HTTP", "method", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java#L466-L473
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java
RouteHandler.getRequestURI
private String getRequestURI(final HttpServletRequest request) { String ret = (String) request.getAttribute(Keys.HttpRequest.REQUEST_URI); if (StringUtils.isBlank(ret)) { ret = request.getRequestURI(); } return ret; }
java
private String getRequestURI(final HttpServletRequest request) { String ret = (String) request.getAttribute(Keys.HttpRequest.REQUEST_URI); if (StringUtils.isBlank(ret)) { ret = request.getRequestURI(); } return ret; }
[ "private", "String", "getRequestURI", "(", "final", "HttpServletRequest", "request", ")", "{", "String", "ret", "=", "(", "String", ")", "request", ".", "getAttribute", "(", "Keys", ".", "HttpRequest", ".", "REQUEST_URI", ")", ";", "if", "(", "StringUtils", ...
Gets the request URI. @param request the specified request @return requestURI
[ "Gets", "the", "request", "URI", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java#L481-L488
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java
RouteHandler.generateContextHandlerMeta
private void generateContextHandlerMeta(final Set<Bean<?>> processBeans) { for (final Bean<?> latkeBean : processBeans) { final Class<?> clz = latkeBean.getBeanClass(); final Method[] declaredMethods = clz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { final Method method = declaredMethods[i]; final RequestProcessing requestProcessingMethodAnn = method.getAnnotation(RequestProcessing.class); if (null == requestProcessingMethodAnn) { continue; } final ContextHandlerMeta contextHandlerMeta = new ContextHandlerMeta(); contextHandlerMeta.setUriTemplates(requestProcessingMethodAnn.value()); contextHandlerMeta.setHttpMethods(requestProcessingMethodAnn.method()); contextHandlerMeta.setInvokeHolder(method); contextHandlerMeta.initProcessAdvices(); addContextHandlerMeta(contextHandlerMeta); } } }
java
private void generateContextHandlerMeta(final Set<Bean<?>> processBeans) { for (final Bean<?> latkeBean : processBeans) { final Class<?> clz = latkeBean.getBeanClass(); final Method[] declaredMethods = clz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { final Method method = declaredMethods[i]; final RequestProcessing requestProcessingMethodAnn = method.getAnnotation(RequestProcessing.class); if (null == requestProcessingMethodAnn) { continue; } final ContextHandlerMeta contextHandlerMeta = new ContextHandlerMeta(); contextHandlerMeta.setUriTemplates(requestProcessingMethodAnn.value()); contextHandlerMeta.setHttpMethods(requestProcessingMethodAnn.method()); contextHandlerMeta.setInvokeHolder(method); contextHandlerMeta.initProcessAdvices(); addContextHandlerMeta(contextHandlerMeta); } } }
[ "private", "void", "generateContextHandlerMeta", "(", "final", "Set", "<", "Bean", "<", "?", ">", ">", "processBeans", ")", "{", "for", "(", "final", "Bean", "<", "?", ">", "latkeBean", ":", "processBeans", ")", "{", "final", "Class", "<", "?", ">", "c...
Scan beans to get the context handler meta. @param processBeans processBeans which contains {@link RequestProcessor}
[ "Scan", "beans", "to", "get", "the", "context", "handler", "meta", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/servlet/handler/RouteHandler.java#L495-L515
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.error
public void error(final String msg) { if (proxy.isErrorEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, null); } else { proxy.error(msg); } } }
java
public void error(final String msg) { if (proxy.isErrorEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, null); } else { proxy.error(msg); } } }
[ "public", "void", "error", "(", "final", "String", "msg", ")", "{", "if", "(", "proxy", ".", "isErrorEnabled", "(", ")", ")", "{", "if", "(", "proxy", "instanceof", "LocationAwareLogger", ")", "{", "(", "(", "LocationAwareLogger", ")", "proxy", ")", ".",...
Logs the specified message at the ERROR level. @param msg the specified message
[ "Logs", "the", "specified", "message", "at", "the", "ERROR", "level", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L78-L86
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.warn
public void warn(final String msg) { if (proxy.isWarnEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, null); } else { proxy.warn(msg); } } }
java
public void warn(final String msg) { if (proxy.isWarnEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, null); } else { proxy.warn(msg); } } }
[ "public", "void", "warn", "(", "final", "String", "msg", ")", "{", "if", "(", "proxy", ".", "isWarnEnabled", "(", ")", ")", "{", "if", "(", "proxy", "instanceof", "LocationAwareLogger", ")", "{", "(", "(", "LocationAwareLogger", ")", "proxy", ")", ".", ...
Logs the specified message at the WARN level. @param msg the specified message
[ "Logs", "the", "specified", "message", "at", "the", "WARN", "level", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L93-L101
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.info
public void info(final String msg) { if (proxy.isInfoEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, null); } else { proxy.info(msg); } } }
java
public void info(final String msg) { if (proxy.isInfoEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, null); } else { proxy.info(msg); } } }
[ "public", "void", "info", "(", "final", "String", "msg", ")", "{", "if", "(", "proxy", ".", "isInfoEnabled", "(", ")", ")", "{", "if", "(", "proxy", "instanceof", "LocationAwareLogger", ")", "{", "(", "(", "LocationAwareLogger", ")", "proxy", ")", ".", ...
Logs the specified message at the INFO level. @param msg the specified message
[ "Logs", "the", "specified", "message", "at", "the", "INFO", "level", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L108-L116
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.debug
public void debug(final String msg) { if (proxy.isDebugEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null); } else { proxy.debug(msg); } } }
java
public void debug(final String msg) { if (proxy.isDebugEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null); } else { proxy.debug(msg); } } }
[ "public", "void", "debug", "(", "final", "String", "msg", ")", "{", "if", "(", "proxy", ".", "isDebugEnabled", "(", ")", ")", "{", "if", "(", "proxy", "instanceof", "LocationAwareLogger", ")", "{", "(", "(", "LocationAwareLogger", ")", "proxy", ")", ".",...
Logs the specified message at the DEBUG level. @param msg the specified message
[ "Logs", "the", "specified", "message", "at", "the", "DEBUG", "level", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L123-L131
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.trace
public void trace(final String msg) { if (proxy.isTraceEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, null); } else { proxy.trace(msg); } } }
java
public void trace(final String msg) { if (proxy.isTraceEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, null); } else { proxy.trace(msg); } } }
[ "public", "void", "trace", "(", "final", "String", "msg", ")", "{", "if", "(", "proxy", ".", "isTraceEnabled", "(", ")", ")", "{", "if", "(", "proxy", "instanceof", "LocationAwareLogger", ")", "{", "(", "(", "LocationAwareLogger", ")", "proxy", ")", ".",...
Logs the specified message at the TRACE level. @param msg the specified message
[ "Logs", "the", "specified", "message", "at", "the", "TRACE", "level", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L138-L146
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.log
public void log(final Level level, final String msg, final Throwable throwable) { switch (level) { case ERROR: if (proxy.isErrorEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, throwable); } else { proxy.error(msg, throwable); } } break; case WARN: if (proxy.isWarnEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, throwable); } else { proxy.warn(msg, throwable); } } break; case INFO: if (proxy.isInfoEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, throwable); } else { proxy.info(msg, throwable); } } break; case DEBUG: if (proxy.isDebugEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, throwable); } else { proxy.debug(msg, throwable); } } break; case TRACE: if (proxy.isTraceEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, throwable); } else { proxy.trace(msg, throwable); } } break; default: throw new IllegalStateException("Logging level [" + level + "] is invalid"); } }
java
public void log(final Level level, final String msg, final Throwable throwable) { switch (level) { case ERROR: if (proxy.isErrorEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, throwable); } else { proxy.error(msg, throwable); } } break; case WARN: if (proxy.isWarnEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, throwable); } else { proxy.warn(msg, throwable); } } break; case INFO: if (proxy.isInfoEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, throwable); } else { proxy.info(msg, throwable); } } break; case DEBUG: if (proxy.isDebugEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, throwable); } else { proxy.debug(msg, throwable); } } break; case TRACE: if (proxy.isTraceEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, throwable); } else { proxy.trace(msg, throwable); } } break; default: throw new IllegalStateException("Logging level [" + level + "] is invalid"); } }
[ "public", "void", "log", "(", "final", "Level", "level", ",", "final", "String", "msg", ",", "final", "Throwable", "throwable", ")", "{", "switch", "(", "level", ")", "{", "case", "ERROR", ":", "if", "(", "proxy", ".", "isErrorEnabled", "(", ")", ")", ...
Logs the specified message with the specified logging level and throwable. @param level the specified logging level @param msg the specified message @param throwable the specified throwable
[ "Logs", "the", "specified", "message", "with", "the", "specified", "logging", "level", "and", "throwable", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L155-L210
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.log
public void log(final Level level, final String msg, final Object... args) { String message = msg; if (null != args && 0 < args.length) { // Is it a java.text style format? // Ideally we could match with Pattern.compile("\\{\\d").matcher(format).find()) // However the cost is 14% higher, so we cheaply check for 1 of the first 4 parameters if (msg.indexOf("{0") >= 0 || msg.indexOf("{1") >= 0 || msg.indexOf("{2") >= 0 || msg.indexOf("{3") >= 0) { message = java.text.MessageFormat.format(msg, args); } } switch (level) { case ERROR: if (proxy.isErrorEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.ERROR_INT, message, null, null); } else { proxy.error(message); } } break; case WARN: if (proxy.isWarnEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.WARN_INT, message, null, null); } else { proxy.warn(message); } } break; case INFO: if (proxy.isInfoEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.INFO_INT, message, null, null); } else { proxy.info(message); } } break; case DEBUG: if (proxy.isDebugEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.DEBUG_INT, message, null, null); } else { proxy.debug(message); } } break; case TRACE: if (proxy.isTraceEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.TRACE_INT, message, null, null); } else { proxy.trace(message); } } break; default: throw new IllegalStateException("Logging level [" + level + "] is invalid"); } }
java
public void log(final Level level, final String msg, final Object... args) { String message = msg; if (null != args && 0 < args.length) { // Is it a java.text style format? // Ideally we could match with Pattern.compile("\\{\\d").matcher(format).find()) // However the cost is 14% higher, so we cheaply check for 1 of the first 4 parameters if (msg.indexOf("{0") >= 0 || msg.indexOf("{1") >= 0 || msg.indexOf("{2") >= 0 || msg.indexOf("{3") >= 0) { message = java.text.MessageFormat.format(msg, args); } } switch (level) { case ERROR: if (proxy.isErrorEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.ERROR_INT, message, null, null); } else { proxy.error(message); } } break; case WARN: if (proxy.isWarnEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.WARN_INT, message, null, null); } else { proxy.warn(message); } } break; case INFO: if (proxy.isInfoEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.INFO_INT, message, null, null); } else { proxy.info(message); } } break; case DEBUG: if (proxy.isDebugEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.DEBUG_INT, message, null, null); } else { proxy.debug(message); } } break; case TRACE: if (proxy.isTraceEnabled()) { if (proxy instanceof LocationAwareLogger) { ((LocationAwareLogger) proxy).log(null, FQCN, LocationAwareLogger.TRACE_INT, message, null, null); } else { proxy.trace(message); } } break; default: throw new IllegalStateException("Logging level [" + level + "] is invalid"); } }
[ "public", "void", "log", "(", "final", "Level", "level", ",", "final", "String", "msg", ",", "final", "Object", "...", "args", ")", "{", "String", "message", "=", "msg", ";", "if", "(", "null", "!=", "args", "&&", "0", "<", "args", ".", "length", "...
Logs the specified message with the specified logging level and arguments. @param level the specified logging level @param msg the specified message @param args the specified arguments
[ "Logs", "the", "specified", "message", "with", "the", "specified", "logging", "level", "and", "arguments", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L219-L285
train
b3log/latke
latke-core/src/main/java/org/b3log/latke/logging/Logger.java
Logger.isLoggable
public boolean isLoggable(final Level level) { switch (level) { case TRACE: return isTraceEnabled(); case DEBUG: return isDebugEnabled(); case INFO: return isInfoEnabled(); case WARN: return isWarnEnabled(); case ERROR: return isErrorEnabled(); default: throw new IllegalStateException("Logging level [" + level + "] is invalid"); } }
java
public boolean isLoggable(final Level level) { switch (level) { case TRACE: return isTraceEnabled(); case DEBUG: return isDebugEnabled(); case INFO: return isInfoEnabled(); case WARN: return isWarnEnabled(); case ERROR: return isErrorEnabled(); default: throw new IllegalStateException("Logging level [" + level + "] is invalid"); } }
[ "public", "boolean", "isLoggable", "(", "final", "Level", "level", ")", "{", "switch", "(", "level", ")", "{", "case", "TRACE", ":", "return", "isTraceEnabled", "(", ")", ";", "case", "DEBUG", ":", "return", "isDebugEnabled", "(", ")", ";", "case", "INFO...
Checks if a message of the given level would actually be logged by this logger. @param level the given level @return {@code true} if it could, returns {@code false} if it couldn't
[ "Checks", "if", "a", "message", "of", "the", "given", "level", "would", "actually", "be", "logged", "by", "this", "logger", "." ]
f7e08a47eeecea5f7c94006382c24f353585de33
https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/b3log/latke/logging/Logger.java#L358-L373
train
aol/cyclops
cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java
Observables.publisher
public static <T> Publisher<T> publisher(Observable<T> observable) { return observable.toFlowable(BackpressureStrategy.BUFFER); }
java
public static <T> Publisher<T> publisher(Observable<T> observable) { return observable.toFlowable(BackpressureStrategy.BUFFER); }
[ "public", "static", "<", "T", ">", "Publisher", "<", "T", ">", "publisher", "(", "Observable", "<", "T", ">", "observable", ")", "{", "return", "observable", ".", "toFlowable", "(", "BackpressureStrategy", ".", "BUFFER", ")", ";", "}" ]
Convert an Observable to a reactive-streams Publisher @param observable To convert @return reactive-streams Publisher
[ "Convert", "an", "Observable", "to", "a", "reactive", "-", "streams", "Publisher" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java#L95-L97
train
aol/cyclops
cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java
Observables.connectToReactiveSeq
public static <T> ReactiveSeq<T> connectToReactiveSeq(Observable<T> observable) { return Spouts.async(s->{ observable.subscribe(s::onNext,e->{ s.onError(e); s.onComplete(); },s::onComplete); }); }
java
public static <T> ReactiveSeq<T> connectToReactiveSeq(Observable<T> observable) { return Spouts.async(s->{ observable.subscribe(s::onNext,e->{ s.onError(e); s.onComplete(); },s::onComplete); }); }
[ "public", "static", "<", "T", ">", "ReactiveSeq", "<", "T", ">", "connectToReactiveSeq", "(", "Observable", "<", "T", ">", "observable", ")", "{", "return", "Spouts", ".", "async", "(", "s", "->", "{", "observable", ".", "subscribe", "(", "s", "::", "o...
Convert an Observable to a cyclops-react ReactiveSeq @param observable To conver @return ReactiveSeq
[ "Convert", "an", "Observable", "to", "a", "cyclops", "-", "react", "ReactiveSeq" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java#L105-L114
train
aol/cyclops
cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java
Observables.observable
public static <T> Observable<T> observable(Publisher<T> publisher) { return Flowable.fromPublisher(publisher).toObservable(); }
java
public static <T> Observable<T> observable(Publisher<T> publisher) { return Flowable.fromPublisher(publisher).toObservable(); }
[ "public", "static", "<", "T", ">", "Observable", "<", "T", ">", "observable", "(", "Publisher", "<", "T", ">", "publisher", ")", "{", "return", "Flowable", ".", "fromPublisher", "(", "publisher", ")", ".", "toObservable", "(", ")", ";", "}" ]
Convert a Publisher to an observable @param publisher To convert @return Observable
[ "Convert", "a", "Publisher", "to", "an", "observable" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java#L123-L125
train
aol/cyclops
cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java
Observables.anyM
public static <T> AnyMSeq<observable,T> anyM(Observable<T> obs) { return AnyM.ofSeq(ObservableReactiveSeq.reactiveSeq(obs), observable.INSTANCE); }
java
public static <T> AnyMSeq<observable,T> anyM(Observable<T> obs) { return AnyM.ofSeq(ObservableReactiveSeq.reactiveSeq(obs), observable.INSTANCE); }
[ "public", "static", "<", "T", ">", "AnyMSeq", "<", "observable", ",", "T", ">", "anyM", "(", "Observable", "<", "T", ">", "obs", ")", "{", "return", "AnyM", ".", "ofSeq", "(", "ObservableReactiveSeq", ".", "reactiveSeq", "(", "obs", ")", ",", "observab...
Construct an AnyM type from an Observable. This allows the Observable to be manipulated according to a standard interface along with a vast array of other Java Monad implementations <pre> {@code AnyMSeq<Integer> obs = Observables.anyM(Observable.just(1,2,3)); AnyMSeq<Integer> transformedObs = myGenericOperation(obs); public AnyMSeq<Integer> myGenericOperation(AnyMSeq<Integer> monad); } </pre> @param obs Observable to wrap inside an AnyM @return AnyMSeq wrapping an Observable
[ "Construct", "an", "AnyM", "type", "from", "an", "Observable", ".", "This", "allows", "the", "Observable", "to", "be", "manipulated", "according", "to", "a", "standard", "interface", "along", "with", "a", "vast", "array", "of", "other", "Java", "Monad", "imp...
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Observables.java#L152-L154
train
aol/cyclops
cyclops/src/main/java/com/oath/cyclops/util/box/MutableChar.java
MutableChar.fromExternal
public static MutableChar fromExternal(final Supplier<Character> s, final Consumer<Character> c) { return new MutableChar() { @Override public char getAsChar() { return s.get(); } @Override public Character get() { return getAsChar(); } @Override public MutableChar set(final char value) { c.accept(value); return this; } }; }
java
public static MutableChar fromExternal(final Supplier<Character> s, final Consumer<Character> c) { return new MutableChar() { @Override public char getAsChar() { return s.get(); } @Override public Character get() { return getAsChar(); } @Override public MutableChar set(final char value) { c.accept(value); return this; } }; }
[ "public", "static", "MutableChar", "fromExternal", "(", "final", "Supplier", "<", "Character", ">", "s", ",", "final", "Consumer", "<", "Character", ">", "c", ")", "{", "return", "new", "MutableChar", "(", ")", "{", "@", "Override", "public", "char", "getA...
Construct a MutableChar that gets and sets an external value using the provided Supplier and Consumer e.g. <pre> {@code MutableChar mutable = MutableChar.fromExternal(()->!this.value,val->!this.value); } </pre> @param s Supplier of an external value @param c Consumer that sets an external value @return MutableChar that gets / sets an external (mutable) value
[ "Construct", "a", "MutableChar", "that", "gets", "and", "sets", "an", "external", "value", "using", "the", "provided", "Supplier", "and", "Consumer" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/com/oath/cyclops/util/box/MutableChar.java#L81-L99
train
aol/cyclops
cyclops/src/main/java/com/oath/cyclops/util/box/MutableDouble.java
MutableDouble.fromExternal
public static MutableDouble fromExternal(final DoubleSupplier s, final DoubleConsumer c) { return new MutableDouble() { @Override public double getAsDouble() { return s.getAsDouble(); } @Override public Double get() { return getAsDouble(); } @Override public MutableDouble set(final double value) { c.accept(value); return this; } }; }
java
public static MutableDouble fromExternal(final DoubleSupplier s, final DoubleConsumer c) { return new MutableDouble() { @Override public double getAsDouble() { return s.getAsDouble(); } @Override public Double get() { return getAsDouble(); } @Override public MutableDouble set(final double value) { c.accept(value); return this; } }; }
[ "public", "static", "MutableDouble", "fromExternal", "(", "final", "DoubleSupplier", "s", ",", "final", "DoubleConsumer", "c", ")", "{", "return", "new", "MutableDouble", "(", ")", "{", "@", "Override", "public", "double", "getAsDouble", "(", ")", "{", "return...
Construct a MutableDouble that gets and sets an external value using the provided Supplier and Consumer e.g. <pre> {@code MutableDouble mutable = MutableDouble.fromExternal(()->!this.value,val->!this.value); } </pre> @param s Supplier of an external value @param c Consumer that sets an external value @return MutableDouble that gets / sets an external (mutable) value
[ "Construct", "a", "MutableDouble", "that", "gets", "and", "sets", "an", "external", "value", "using", "the", "provided", "Supplier", "and", "Consumer" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/com/oath/cyclops/util/box/MutableDouble.java#L81-L99
train
aol/cyclops
cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Maybes.java
Maybes.combine
public static <T1, T2, R> Maybe<R> combine(Maybe<? extends T1> maybe, Maybe<? extends T2> app, BiFunction<? super T1, ? super T2, ? extends R> fn) { return narrow(Single.fromPublisher(Future.fromPublisher(maybe.toFlowable()) .zip(Future.fromPublisher(app.toFlowable()), fn)).toMaybe()); }
java
public static <T1, T2, R> Maybe<R> combine(Maybe<? extends T1> maybe, Maybe<? extends T2> app, BiFunction<? super T1, ? super T2, ? extends R> fn) { return narrow(Single.fromPublisher(Future.fromPublisher(maybe.toFlowable()) .zip(Future.fromPublisher(app.toFlowable()), fn)).toMaybe()); }
[ "public", "static", "<", "T1", ",", "T2", ",", "R", ">", "Maybe", "<", "R", ">", "combine", "(", "Maybe", "<", "?", "extends", "T1", ">", "maybe", ",", "Maybe", "<", "?", "extends", "T2", ">", "app", ",", "BiFunction", "<", "?", "super", "T1", ...
Lazily combine this Maybe with the supplied Maybe via the supplied BiFunction @param maybe Maybe to combine with another value @param app Maybe to combine with supplied maybe @param fn Combiner function @return Combined Maybe
[ "Lazily", "combine", "this", "Maybe", "with", "the", "supplied", "Maybe", "via", "the", "supplied", "BiFunction" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Maybes.java#L357-L361
train
aol/cyclops
cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Maybes.java
Maybes.fromIterable
public static <T> Maybe<T> fromIterable(Iterable<T> t) { return narrow(Single.fromPublisher(Future.fromIterable(t)).toMaybe()); }
java
public static <T> Maybe<T> fromIterable(Iterable<T> t) { return narrow(Single.fromPublisher(Future.fromIterable(t)).toMaybe()); }
[ "public", "static", "<", "T", ">", "Maybe", "<", "T", ">", "fromIterable", "(", "Iterable", "<", "T", ">", "t", ")", "{", "return", "narrow", "(", "Single", ".", "fromPublisher", "(", "Future", ".", "fromIterable", "(", "t", ")", ")", ".", "toMaybe",...
Construct a Maybe from Iterable by taking the first value from Iterable @param t Iterable to populate Maybe from @return Maybe containing first element from Iterable (or empty Maybe)
[ "Construct", "a", "Maybe", "from", "Iterable", "by", "taking", "the", "first", "value", "from", "Iterable" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-rxjava2-integration/src/main/java/cyclops/companion/rx2/Maybes.java#L398-L400
train
aol/cyclops
cyclops-pure/src/main/java/cyclops/control/Writer.java
Writer.forEach3
public <R1, R2, R4> Writer<W,R4> forEach3(Function<? super T, ? extends Writer<W,R1>> value2, BiFunction<? super T, ? super R1, ? extends Writer<W,R2>> value3, Function3<? super T, ? super R1, ? super R2, ? extends R4> yieldingFunction) { return this.flatMap(in -> { Writer<W,R1> a = value2.apply(in); return a.flatMap(ina -> { Writer<W,R2> b = value3.apply(in,ina); return b.map(in2 -> { return yieldingFunction.apply(in, ina, in2); }); }); }); }
java
public <R1, R2, R4> Writer<W,R4> forEach3(Function<? super T, ? extends Writer<W,R1>> value2, BiFunction<? super T, ? super R1, ? extends Writer<W,R2>> value3, Function3<? super T, ? super R1, ? super R2, ? extends R4> yieldingFunction) { return this.flatMap(in -> { Writer<W,R1> a = value2.apply(in); return a.flatMap(ina -> { Writer<W,R2> b = value3.apply(in,ina); return b.map(in2 -> { return yieldingFunction.apply(in, ina, in2); }); }); }); }
[ "public", "<", "R1", ",", "R2", ",", "R4", ">", "Writer", "<", "W", ",", "R4", ">", "forEach3", "(", "Function", "<", "?", "super", "T", ",", "?", "extends", "Writer", "<", "W", ",", "R1", ">", ">", "value2", ",", "BiFunction", "<", "?", "super...
Perform a For Comprehension over a Writer, accepting 2 generating function. This results in a three level nested internal iteration over the provided Writers. <pre> {@code import static com.oath.cyclops.reactor.Writers.forEach3; forEach3(Writer.just(1), a-> Writer.just(a+1), (a,b) -> Writer.<Integer>just(a+b), Tuple::tuple) } </pre> @param value2 Nested Writer @param value3 Nested Writer @param yieldingFunction Generates a result per combination @return Writer with a combined value generated by the yielding function
[ "Perform", "a", "For", "Comprehension", "over", "a", "Writer", "accepting", "2", "generating", "function", ".", "This", "results", "in", "a", "three", "level", "nested", "internal", "iteration", "over", "the", "provided", "Writers", "." ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-pure/src/main/java/cyclops/control/Writer.java#L131-L151
train
aol/cyclops
cyclops-pure/src/main/java/cyclops/control/Writer.java
Writer.forEach2
public <R1, R4> Writer<W,R4> forEach2(Function<? super T, Writer<W,R1>> value2, BiFunction<? super T, ? super R1, ? extends R4> yieldingFunction) { return this.flatMap(in -> { Writer<W,R1> a = value2.apply(in); return a.map(in2 -> { return yieldingFunction.apply(in, in2); }); }); }
java
public <R1, R4> Writer<W,R4> forEach2(Function<? super T, Writer<W,R1>> value2, BiFunction<? super T, ? super R1, ? extends R4> yieldingFunction) { return this.flatMap(in -> { Writer<W,R1> a = value2.apply(in); return a.map(in2 -> { return yieldingFunction.apply(in, in2); }); }); }
[ "public", "<", "R1", ",", "R4", ">", "Writer", "<", "W", ",", "R4", ">", "forEach2", "(", "Function", "<", "?", "super", "T", ",", "Writer", "<", "W", ",", "R1", ">", ">", "value2", ",", "BiFunction", "<", "?", "super", "T", ",", "?", "super", ...
Perform a For Comprehension over a Writer, accepting a generating function. This results in a two level nested internal iteration over the provided Writers. <pre> {@code import static com.oath.cyclops.reactor.Writers.forEach; forEach(Writer.just(1), a-> Writer.just(a+1), Tuple::tuple) } </pre> @param value2 Nested Writer @param yieldingFunction Generates a result per combination @return Writer with a combined value generated by the yielding function
[ "Perform", "a", "For", "Comprehension", "over", "a", "Writer", "accepting", "a", "generating", "function", ".", "This", "results", "in", "a", "two", "level", "nested", "internal", "iteration", "over", "the", "provided", "Writers", "." ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-pure/src/main/java/cyclops/control/Writer.java#L174-L187
train
aol/cyclops
cyclops/src/main/java/cyclops/function/FluentFunctions.java
FluentFunctions.of
public static <R> FluentFunctions.FluentSupplier<R> of(final Supplier<R> supplier) { return new FluentSupplier<>( supplier); }
java
public static <R> FluentFunctions.FluentSupplier<R> of(final Supplier<R> supplier) { return new FluentSupplier<>( supplier); }
[ "public", "static", "<", "R", ">", "FluentFunctions", ".", "FluentSupplier", "<", "R", ">", "of", "(", "final", "Supplier", "<", "R", ">", "supplier", ")", "{", "return", "new", "FluentSupplier", "<>", "(", "supplier", ")", ";", "}" ]
Construct a FluentSupplier from a Supplier <pre> {@code Cache<Object, Integer> cache = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.MINUTES) .build(); called=0; Supplier<Integer> fn = FluentFunctions.of(this::getOne) .name("myFunction") .memoize((key,f)->cache.getValue(key,()->f.applyHKT(key))); fn.getValue(); fn.getValue(); fn.getValue(); called == 1 } </pre> @param supplier to make Fluent @return FluentSupplier
[ "Construct", "a", "FluentSupplier", "from", "a", "Supplier" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/cyclops/function/FluentFunctions.java#L86-L89
train
aol/cyclops
cyclops/src/main/java/cyclops/function/FluentFunctions.java
FluentFunctions.ofChecked
public static <T, R> FluentFunctions.FluentFunction<T, R> ofChecked(final CheckedFunction<T, R> fn) { return FluentFunctions.of(ExceptionSoftener.softenFunction(fn)); }
java
public static <T, R> FluentFunctions.FluentFunction<T, R> ofChecked(final CheckedFunction<T, R> fn) { return FluentFunctions.of(ExceptionSoftener.softenFunction(fn)); }
[ "public", "static", "<", "T", ",", "R", ">", "FluentFunctions", ".", "FluentFunction", "<", "T", ",", "R", ">", "ofChecked", "(", "final", "CheckedFunction", "<", "T", ",", "R", ">", "fn", ")", "{", "return", "FluentFunctions", ".", "of", "(", "Excepti...
Construct a FluentFunction from a CheckedFunction <pre> {@code FluentFunctions.ofChecked(this::exceptionalFirstTime) .recover(IOException.class, in->in+"boo!") .println() .applyHKT("hello ") } </pre> @param fn CheckedFunction @return FluentFunction
[ "Construct", "a", "FluentFunction", "from", "a", "CheckedFunction" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/cyclops/function/FluentFunctions.java#L110-L112
train
aol/cyclops
cyclops/src/main/java/cyclops/function/FluentFunctions.java
FluentFunctions.of
public static <T, R> FluentFunctions.FluentFunction<T, R> of(final Function<T, R> fn) { return new FluentFunction<>( fn); }
java
public static <T, R> FluentFunctions.FluentFunction<T, R> of(final Function<T, R> fn) { return new FluentFunction<>( fn); }
[ "public", "static", "<", "T", ",", "R", ">", "FluentFunctions", ".", "FluentFunction", "<", "T", ",", "R", ">", "of", "(", "final", "Function", "<", "T", ",", "R", ">", "fn", ")", "{", "return", "new", "FluentFunction", "<>", "(", "fn", ")", ";", ...
Construct a FluentFunction from a Function <pre> {@code FluentFunctions.of(this::addOne) .around(advice->advice.proceed(advice.param+1)) .println() .applyHKT(10) } </pre> @param fn Function @return FluentFunction
[ "Construct", "a", "FluentFunction", "from", "a", "Function" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/cyclops/function/FluentFunctions.java#L128-L131
train
aol/cyclops
cyclops/src/main/java/cyclops/function/FluentFunctions.java
FluentFunctions.ofChecked
public static <T1, T2, R> FluentFunctions.FluentBiFunction<T1, T2, R> ofChecked(final CheckedBiFunction<T1, T2, R> fn) { return FluentFunctions.of(ExceptionSoftener.softenBiFunction(fn)); }
java
public static <T1, T2, R> FluentFunctions.FluentBiFunction<T1, T2, R> ofChecked(final CheckedBiFunction<T1, T2, R> fn) { return FluentFunctions.of(ExceptionSoftener.softenBiFunction(fn)); }
[ "public", "static", "<", "T1", ",", "T2", ",", "R", ">", "FluentFunctions", ".", "FluentBiFunction", "<", "T1", ",", "T2", ",", "R", ">", "ofChecked", "(", "final", "CheckedBiFunction", "<", "T1", ",", "T2", ",", "R", ">", "fn", ")", "{", "return", ...
Construct a FluentBiFunction from a CheckedBiFunction <pre> {@code FluentFunctions.ofChecked(this::exceptionalFirstTime) .println() .retry(2,500) .applyHKT("hello","woo!") } </pre> @param fn CheckedBiFunction @return FluentBiFunction
[ "Construct", "a", "FluentBiFunction", "from", "a", "CheckedBiFunction" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/cyclops/function/FluentFunctions.java#L147-L149
train
aol/cyclops
cyclops/src/main/java/cyclops/function/FluentFunctions.java
FluentFunctions.checkedExpression
public static <T1, T2> FluentFunctions.FluentBiFunction<T1, T2, Tuple2<T1, T2>> checkedExpression(final CheckedBiConsumer<T1, T2> action) { final BiConsumer<T1, T2> toUse = ExceptionSoftener.softenBiConsumer(action); return FluentFunctions.of((t1, t2) -> { toUse.accept(t1, t2); return Tuple.tuple(t1, t2); }); }
java
public static <T1, T2> FluentFunctions.FluentBiFunction<T1, T2, Tuple2<T1, T2>> checkedExpression(final CheckedBiConsumer<T1, T2> action) { final BiConsumer<T1, T2> toUse = ExceptionSoftener.softenBiConsumer(action); return FluentFunctions.of((t1, t2) -> { toUse.accept(t1, t2); return Tuple.tuple(t1, t2); }); }
[ "public", "static", "<", "T1", ",", "T2", ">", "FluentFunctions", ".", "FluentBiFunction", "<", "T1", ",", "T2", ",", "Tuple2", "<", "T1", ",", "T2", ">", ">", "checkedExpression", "(", "final", "CheckedBiConsumer", "<", "T1", ",", "T2", ">", "action", ...
Convert a CheckedBiConsumer into a FluentBiConsumer that returns it's input in a tuple <pre> {@code public void printTwo(String input1,String input2) throws IOException{ System.out.println(input1); System.out.println(input2); } FluentFunctions.checkedExpression(this::printTwo) .applyHKT("hello","world"); returns Tuple2["hello","world"] } </pre> @param action @return
[ "Convert", "a", "CheckedBiConsumer", "into", "a", "FluentBiConsumer", "that", "returns", "it", "s", "input", "in", "a", "tuple" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/cyclops/function/FluentFunctions.java#L292-L298
train
aol/cyclops
cyclops/src/main/java/com/oath/cyclops/util/stream/scheduling/cron/CronExpression.java
CronExpression.isSatisfiedBy
public boolean isSatisfiedBy(final Date date) { final Calendar testDateCal = Calendar.getInstance(getTimeZone()); testDateCal.setTime(date); testDateCal.set(Calendar.MILLISECOND, 0); final Date originalDate = testDateCal.getTime(); testDateCal.add(Calendar.SECOND, -1); final Date timeAfter = getTimeAfter(testDateCal.getTime()); return timeAfter != null && timeAfter.equals(originalDate); }
java
public boolean isSatisfiedBy(final Date date) { final Calendar testDateCal = Calendar.getInstance(getTimeZone()); testDateCal.setTime(date); testDateCal.set(Calendar.MILLISECOND, 0); final Date originalDate = testDateCal.getTime(); testDateCal.add(Calendar.SECOND, -1); final Date timeAfter = getTimeAfter(testDateCal.getTime()); return timeAfter != null && timeAfter.equals(originalDate); }
[ "public", "boolean", "isSatisfiedBy", "(", "final", "Date", "date", ")", "{", "final", "Calendar", "testDateCal", "=", "Calendar", ".", "getInstance", "(", "getTimeZone", "(", ")", ")", ";", "testDateCal", ".", "setTime", "(", "date", ")", ";", "testDateCal"...
Indicates whether the given date satisfies the cron expression. Note that milliseconds are ignored, so two Dates falling on different milliseconds of the same second will always have the same result here. @param date the date to evaluate @return a boolean indicating whether the given date satisfies the cron expression
[ "Indicates", "whether", "the", "given", "date", "satisfies", "the", "cron", "expression", ".", "Note", "that", "milliseconds", "are", "ignored", "so", "two", "Dates", "falling", "on", "different", "milliseconds", "of", "the", "same", "second", "will", "always", ...
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/com/oath/cyclops/util/stream/scheduling/cron/CronExpression.java#L320-L331
train
aol/cyclops
cyclops-pure/src/main/java/cyclops/typeclasses/functor/Compose.java
Compose.compose
public static <CRE,C2> Compose<CRE,C2> compose(Functor<CRE> f,Functor<C2> g){ return new Compose<>(f,g); }
java
public static <CRE,C2> Compose<CRE,C2> compose(Functor<CRE> f,Functor<C2> g){ return new Compose<>(f,g); }
[ "public", "static", "<", "CRE", ",", "C2", ">", "Compose", "<", "CRE", ",", "C2", ">", "compose", "(", "Functor", "<", "CRE", ">", "f", ",", "Functor", "<", "C2", ">", "g", ")", "{", "return", "new", "Compose", "<>", "(", "f", ",", "g", ")", ...
Compose two functors @param f First functor to compose @param g Second functor to compose @return Composed functor
[ "Compose", "two", "functors" ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops-pure/src/main/java/cyclops/typeclasses/functor/Compose.java#L50-L52
train
aol/cyclops
cyclops/src/main/java/cyclops/companion/Streams.java
Streams.forEach4
public static <T1, T2, T3, R1, R2, R3, R> Stream<R> forEach4(Stream<? extends T1> value1, Function<? super T1, ? extends Stream<R1>> value2, BiFunction<? super T1, ? super R1, ? extends Stream<R2>> value3, Function3<? super T1, ? super R1, ? super R2, ? extends Stream<R3>> value4, Function4<? super T1, ? super R1, ? super R2, ? super R3, ? extends R> yieldingFunction) { return value1.flatMap(in -> { Stream<R1> a = value2.apply(in); return a.flatMap(ina -> { Stream<R2> b = value3.apply(in,ina); return b.flatMap(inb -> { Stream<R3> c = value4.apply(in,ina,inb); return c.map(in2 -> yieldingFunction.apply(in, ina, inb, in2)); }); }); }); }
java
public static <T1, T2, T3, R1, R2, R3, R> Stream<R> forEach4(Stream<? extends T1> value1, Function<? super T1, ? extends Stream<R1>> value2, BiFunction<? super T1, ? super R1, ? extends Stream<R2>> value3, Function3<? super T1, ? super R1, ? super R2, ? extends Stream<R3>> value4, Function4<? super T1, ? super R1, ? super R2, ? super R3, ? extends R> yieldingFunction) { return value1.flatMap(in -> { Stream<R1> a = value2.apply(in); return a.flatMap(ina -> { Stream<R2> b = value3.apply(in,ina); return b.flatMap(inb -> { Stream<R3> c = value4.apply(in,ina,inb); return c.map(in2 -> yieldingFunction.apply(in, ina, inb, in2)); }); }); }); }
[ "public", "static", "<", "T1", ",", "T2", ",", "T3", ",", "R1", ",", "R2", ",", "R3", ",", "R", ">", "Stream", "<", "R", ">", "forEach4", "(", "Stream", "<", "?", "extends", "T1", ">", "value1", ",", "Function", "<", "?", "super", "T1", ",", ...
Perform a For Comprehension over a Stream, accepting 3 generating arrow. This results in a four level nested internal iteration over the provided Publishers. <pre> {@code import static cyclops.companion.Streams.forEach4; forEach4(IntStream.range(1,10).boxed(), a-> Stream.iterate(a,i->i+1).limit(10), (a,b) -> Stream.<Integer>of(a+b), (a,b,c) -> Stream.<Integer>just(a+b+c), Tuple::tuple) } </pre> @param value1 top level Stream @param value2 Nested Stream @param value3 Nested Stream @param value4 Nested Stream @param yieldingFunction Generates a result per combination @return Stream with an element per combination of nested publishers generated by the yielding function
[ "Perform", "a", "For", "Comprehension", "over", "a", "Stream", "accepting", "3", "generating", "arrow", ".", "This", "results", "in", "a", "four", "level", "nested", "internal", "iteration", "over", "the", "provided", "Publishers", "." ]
59a9fde30190a4d1faeb9f6d9851d209d82b81dd
https://github.com/aol/cyclops/blob/59a9fde30190a4d1faeb9f6d9851d209d82b81dd/cyclops/src/main/java/cyclops/companion/Streams.java#L211-L232
train