idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
24,900 | 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 ; } } | Gets a parameter specified by the given name from request body form or query string . |
24,901 | 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 ( ) ) ; } } | Sends the specified error status code . |
24,902 | public RequestContext renderJSONPretty ( final JSONObject json ) { final JsonRenderer jsonRenderer = new JsonRenderer ( ) ; jsonRenderer . setJSONObject ( json ) ; jsonRenderer . setPretty ( true ) ; this . renderer = jsonRenderer ; return this ; } | Pretty rends with the specified json object . |
24,903 | public RequestContext renderJSON ( final JSONObject json ) { final JsonRenderer jsonRenderer = new JsonRenderer ( ) ; jsonRenderer . setJSONObject ( json ) ; this . renderer = jsonRenderer ; return this ; } | Renders with the specified json object . |
24,904 | public RequestContext renderPretty ( ) { if ( renderer instanceof JsonRenderer ) { final JsonRenderer r = ( JsonRenderer ) renderer ; r . setPretty ( true ) ; } return this ; } | Pretty renders . |
24,905 | 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 ) ) ; } } | Handles this context with handlers . |
24,906 | 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 ( ) ; } } | Gets the request json object with the specified request . |
24,907 | 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 ) { } } if ( 1 > ret ) { ret = 1 ; } return ret ; } | Gets the current page number from the query string p of the specified request . |
24,908 | 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 ; } | Paginates with the specified current page number page size page count and window size . |
24,909 | 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 ; } | Gets all plugins . |
24,910 | 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 ; } | Gets a plugin by the specified view name . |
24,911 | private void register ( final AbstractPlugin plugin , final Map < String , HashSet < AbstractPlugin > > holder ) { final String rendererId = plugin . getRendererId ( ) ; 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 ( ) ) ; } | Registers the specified plugin into the specified holder . |
24,912 | 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 ( ) ; 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 ) ; } | Sets the specified plugin s properties from the specified properties file under the specified plugin directory . |
24,913 | 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 ( ) ) ; } } | Registers event listeners with the specified plugin properties class loader and plugin . |
24,914 | 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 ; } | Gets all language properties as a map by the specified locale . |
24,915 | public String get ( final String key , final Locale locale ) { return get ( Keys . LANGUAGE , key , locale ) ; } | Gets a value with the specified key and locale . |
24,916 | private String replaceVars ( final String langValue ) { String ret = StringUtils . replace ( langValue , "${servePath}" , Latkes . getServePath ( ) ) ; ret = StringUtils . replace ( ret , "${staticServePath}" , Latkes . getStaticServePath ( ) ) ; return ret ; } | Replaces all variables of the specified language value . |
24,917 | 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 ) ) ; i += entity . length ( ) + 1 ; } else { sb . append ( c ) ; } } else { sb . append ( c ) ; } } return sb . toString ( ) ; } | Removes XML escapes from the string . |
24,918 | 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 ; } } | Returns pretty print of the specified xml string . |
24,919 | 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" ) ; } | Initializes template engine configuration . |
24,920 | 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 . |
24,921 | 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 ( ) ) ; } | Plugs with the specified data model and the args from request . |
24,922 | 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 ) ) ; } } | Processes languages . Retrieves language labels with default locale then sets them into the specified data model . |
24,923 | private void fillDefault ( final Map < String , Object > dataModel ) { Keys . fillServer ( dataModel ) ; Keys . fillRuntime ( dataModel ) ; } | Fills default values into the specified data model . |
24,924 | 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 ) { return "" ; } } | Gets view content of a plugin . The content is processed with the specified data model by template engine . |
24,925 | 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 ) ; } | 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 . |
24,926 | 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 ; } | Concatenates the specified arrays . |
24,927 | 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 ; } | the URLS under Root path each of which we should scan from . |
24,928 | private static boolean isJarURL ( final URL rootDirResource ) { final String protocol = rootDirResource . getProtocol ( ) ; return "jar" . equals ( protocol ) || "zip" . equals ( protocol ) || "wsjar" . equals ( protocol ) || ( "code-source" . equals ( protocol ) && rootDirResource . getPath ( ) . contains ( JAR_URL_SEPARATOR ) ) ; } | check if the URL of the Rousource is a JAR resource . |
24,929 | 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 { 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 ( "/" ) ) { 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 { if ( newJarFile ) { try { jarFile . close ( ) ; } catch ( final IOException e ) { LOGGER . log ( Level . WARN , " occur error when closing jarFile" , e ) ; } } } return result ; } | scan the jar to get the URLS of the Classes . |
24,930 | 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 ( ) { public boolean accept ( final File dir , final String name ) { return true ; } 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 ; } | scan the system file to get the URLS of the Classes . |
24,931 | 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 ; } | Handle flow . |
24,932 | public static void result ( final RequestContext context ) { final HttpServletResponse response = context . getResponse ( ) ; if ( response . isCommitted ( ) ) { return ; } AbstractResponseRenderer renderer = context . getRenderer ( ) ; if ( null == renderer ) { renderer = new Http404Renderer ( ) ; } renderer . render ( context ) ; } | Do HTTP response . |
24,933 | public static Router delete ( final String uriTemplate , final ContextHandler handler ) { return route ( ) . delete ( uriTemplate , handler ) ; } | HTTP DELETE routing . |
24,934 | public static Router put ( final String uriTemplate , final ContextHandler handler ) { return route ( ) . put ( uriTemplate , handler ) ; } | HTTP PUT routing . |
24,935 | public static Router get ( final String uriTemplate , final ContextHandler handler ) { return route ( ) . get ( uriTemplate , handler ) ; } | HTTP GET routing . |
24,936 | public static Router post ( final String uriTemplate , final ContextHandler handler ) { return route ( ) . post ( uriTemplate , handler ) ; } | HTTP POST routing . |
24,937 | public static void mapping ( ) { for ( final Router router : routers ) { final ContextHandlerMeta contextHandlerMeta = router . toContextHandlerMeta ( ) ; RouteHandler . addContextHandlerMeta ( contextHandlerMeta ) ; } } | Performs mapping for all routers . |
24,938 | 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 ) ; } } | Disposes this transaction . |
24,939 | 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 ; } | Checks the current method is whether invoked by a caller specified by the given class name and method name . |
24,940 | 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 ( ) ) ; } | Prints call stack with the specified logging level . |
24,941 | public static void start ( final String taskTitle ) { Stopwatch root = STOPWATCH . get ( ) ; if ( null == root ) { root = new Stopwatch ( taskTitle ) ; STOPWATCH . set ( root ) ; return ; } final Stopwatch recent = getRecentRunning ( STOPWATCH . get ( ) ) ; if ( null == recent ) { return ; } recent . addLeaf ( new Stopwatch ( taskTitle ) ) ; } | Starts a task timing with the specified task title . |
24,942 | 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 ( ) ; } | Gets the current timing statistics . |
24,943 | 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 ( ) ; } | Gets elapsed time from the specified parent stopwatch with the specified task title . |
24,944 | 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 ; } | Gets stopwatch from the specified parent stopwatch with the specified task title . |
24,945 | 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 ; } | Gets the recent running stopwatch with the specified parent stopwatch . |
24,946 | 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 ( ) ; } | Is IPv4 . |
24,947 | 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 ; } | Converts the specified string into a string list line by line . |
24,948 | public static boolean isNumeric ( final String string ) { try { Double . parseDouble ( string ) ; } catch ( final Exception e ) { return false ; } return true ; } | Checks whether the specified string is numeric . |
24,949 | 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 ( ) ; } | Checks whether the specified string is a valid email address . |
24,950 | public static String [ ] trimAll ( final String [ ] strings ) { if ( null == strings ) { return null ; } return Arrays . stream ( strings ) . map ( StringUtils :: trim ) . toArray ( size -> new String [ size ] ) ; } | Trims every string in the specified strings array . |
24,951 | 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 ) ) ; } | Determines whether the specified strings contains the specified string ignoring case considerations . |
24,952 | 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 ) ) ; } | Determines whether the specified strings contains the specified string . |
24,953 | private void initBeforeList ( ) { final List < ProcessAdvice > beforeRequestProcessAdvices = new ArrayList < > ( ) ; final Method invokeHolder = getInvokeHolder ( ) ; final Class < ? > processorClass = invokeHolder . getDeclaringClass ( ) ; 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 ) ; } } 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 ; } | Initializes before process advices . |
24,954 | private void initAfterList ( ) { final List < ProcessAdvice > afterRequestProcessAdvices = new ArrayList < > ( ) ; final Method invokeHolder = getInvokeHolder ( ) ; final Class < ? > processorClass = invokeHolder . getDeclaringClass ( ) ; 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 ) ; } } 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 ; } | Initializes after process advices . |
24,955 | 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 ; } | Set SELECT projections . |
24,956 | 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 . |
24,957 | 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" ) ; } | Gets time ago format text . |
24,958 | 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 ) ; } | Determines whether the specified date1 is the same day with the specified date2 . |
24,959 | 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 ) ; } | Determines whether the specified date1 is the same week with the specified date2 . |
24,960 | 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 ) ; } | Determines whether the specified date1 is the same month with the specified date2 . |
24,961 | 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 ( ) ; } | Gets the day start time with the specified time . |
24,962 | 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 ( ) ; } | Gets the day end time with the specified time . |
24,963 | 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 ; } | Gets the week day with the specified time . |
24,964 | 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 ( ) ; } | Gets the week start time with the specified time . |
24,965 | 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 ( ) ; } | Gets the week end time with the specified time . |
24,966 | 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 ( ) ; } | Gets the month start time with the specified time . |
24,967 | 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 ( ) ; } | Gets the month end time with the specified time . |
24,968 | 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 ; } | Converts the specified array to a set . |
24,969 | 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 ) ; } } } | Routes the request specified by the given request URI and HTTP method . |
24,970 | 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 ; } | Routes the specified request URI containing path vars with the specified HTTP method and path var context handler metas holder . |
24,971 | private String getHttpMethod ( final HttpServletRequest request ) { String ret = ( String ) request . getAttribute ( Keys . HttpRequest . REQUEST_METHOD ) ; if ( StringUtils . isBlank ( ret ) ) { ret = request . getMethod ( ) ; } return ret ; } | Gets the HTTP method . |
24,972 | private String getRequestURI ( final HttpServletRequest request ) { String ret = ( String ) request . getAttribute ( Keys . HttpRequest . REQUEST_URI ) ; if ( StringUtils . isBlank ( ret ) ) { ret = request . getRequestURI ( ) ; } return ret ; } | Gets the request URI . |
24,973 | 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 ) ; } } } | Scan beans to get the context handler meta . |
24,974 | 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 ) ; } } } | Logs the specified message at the ERROR level . |
24,975 | 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 ) ; } } } | Logs the specified message at the WARN level . |
24,976 | 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 ) ; } } } | Logs the specified message at the INFO level . |
24,977 | 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 ) ; } } } | Logs the specified message at the DEBUG level . |
24,978 | 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 ) ; } } } | Logs the specified message at the TRACE level . |
24,979 | 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" ) ; } } | Logs the specified message with the specified logging level and throwable . |
24,980 | public void log ( final Level level , final String msg , final Object ... args ) { String message = msg ; if ( null != args && 0 < args . length ) { 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" ) ; } } | Logs the specified message with the specified logging level and arguments . |
24,981 | 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" ) ; } } | Checks if a message of the given level would actually be logged by this logger . |
24,982 | public static < T > Publisher < T > publisher ( Observable < T > observable ) { return observable . toFlowable ( BackpressureStrategy . BUFFER ) ; } | Convert an Observable to a reactive - streams Publisher |
24,983 | 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 ) ; } ) ; } | Convert an Observable to a cyclops - react ReactiveSeq |
24,984 | public static < T > Observable < T > observable ( Publisher < T > publisher ) { return Flowable . fromPublisher ( publisher ) . toObservable ( ) ; } | Convert a Publisher to an observable |
24,985 | public static < T > AnyMSeq < observable , T > anyM ( Observable < T > obs ) { return AnyM . ofSeq ( ObservableReactiveSeq . reactiveSeq ( obs ) , observable . INSTANCE ) ; } | 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 |
24,986 | public static MutableChar fromExternal ( final Supplier < Character > s , final Consumer < Character > c ) { return new MutableChar ( ) { public char getAsChar ( ) { return s . get ( ) ; } public Character get ( ) { return getAsChar ( ) ; } public MutableChar set ( final char value ) { c . accept ( value ) ; return this ; } } ; } | Construct a MutableChar that gets and sets an external value using the provided Supplier and Consumer |
24,987 | public static MutableDouble fromExternal ( final DoubleSupplier s , final DoubleConsumer c ) { return new MutableDouble ( ) { public double getAsDouble ( ) { return s . getAsDouble ( ) ; } public Double get ( ) { return getAsDouble ( ) ; } public MutableDouble set ( final double value ) { c . accept ( value ) ; return this ; } } ; } | Construct a MutableDouble that gets and sets an external value using the provided Supplier and Consumer |
24,988 | 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 ( ) ) ; } | Lazily combine this Maybe with the supplied Maybe via the supplied BiFunction |
24,989 | 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 |
24,990 | 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 ) ; } ) ; } ) ; } ) ; } | Perform a For Comprehension over a Writer accepting 2 generating function . This results in a three level nested internal iteration over the provided Writers . |
24,991 | 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 ) ; } ) ; } ) ; } | Perform a For Comprehension over a Writer accepting a generating function . This results in a two level nested internal iteration over the provided Writers . |
24,992 | public static < R > FluentFunctions . FluentSupplier < R > of ( final Supplier < R > supplier ) { return new FluentSupplier < > ( supplier ) ; } | Construct a FluentSupplier from a Supplier |
24,993 | public static < T , R > FluentFunctions . FluentFunction < T , R > ofChecked ( final CheckedFunction < T , R > fn ) { return FluentFunctions . of ( ExceptionSoftener . softenFunction ( fn ) ) ; } | Construct a FluentFunction from a CheckedFunction |
24,994 | public static < T , R > FluentFunctions . FluentFunction < T , R > of ( final Function < T , R > fn ) { return new FluentFunction < > ( fn ) ; } | Construct a FluentFunction from a Function |
24,995 | public static < T1 , T2 , R > FluentFunctions . FluentBiFunction < T1 , T2 , R > ofChecked ( final CheckedBiFunction < T1 , T2 , R > fn ) { return FluentFunctions . of ( ExceptionSoftener . softenBiFunction ( fn ) ) ; } | Construct a FluentBiFunction from a CheckedBiFunction |
24,996 | 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 ) ; } ) ; } | Convert a CheckedBiConsumer into a FluentBiConsumer that returns it s input in a tuple |
24,997 | 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 ) ; } | 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 . |
24,998 | public static < CRE , C2 > Compose < CRE , C2 > compose ( Functor < CRE > f , Functor < C2 > g ) { return new Compose < > ( f , g ) ; } | Compose two functors |
24,999 | 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 ) ) ; } ) ; } ) ; } ) ; } | Perform a For Comprehension over a Stream accepting 3 generating arrow . This results in a four level nested internal iteration over the provided Publishers . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.