idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
17,600 | public static void prepareForLogging ( String path , String query ) { MDC . put ( "request_id" , UUID . randomUUID ( ) . toString ( ) ) ; try { URI uri = new URI ( path ) ; MDC . put ( "host" , uri . getHost ( ) ) ; MDC . put ( "scheme" , uri . getScheme ( ) ) ; MDC . put ( "domain" , UrlUtils . resolveDomain ( uri . getPath ( ) ) ) ; MDC . put ( "port" , uri . getPort ( ) + "" ) ; MDC . put ( "path" , uri . getPath ( ) ) ; } catch ( URISyntaxException e ) { MDC . put ( "path" , path ) ; } MDC . put ( "timestamp" , System . currentTimeMillis ( ) + "" ) ; if ( ! StringUtils . isNullOrEmptyTrimmed ( query ) ) { MDC . put ( "query" , query ) ; } } | Common purpose logging |
17,601 | public static BlockingQueue < Runnable > getThreadQueue ( ExecutorService executorService ) { if ( executorService instanceof ThreadPoolExecutor ) return ( ( ThreadPoolExecutor ) executorService ) . getQueue ( ) ; throw JMExceptionManager . handleExceptionAndReturnRuntimeEx ( log , new IllegalArgumentException ( "Unsupported ExecutorService - Use ThrJMThread.newThreadPool Or newSingleThreadPool To Get ExecutorService !!!" ) , "getThreadQueue" , executorService ) ; } | Gets thread queue . |
17,602 | public static void awaitTermination ( ExecutorService executorService , long timeoutMillis ) { if ( executorService . isTerminated ( ) ) return ; log . info ( "Start Terminating !!! - {}, timeoutMillis - {}" , executorService , timeoutMillis ) ; long startTimeMillis = System . currentTimeMillis ( ) ; try { executorService . awaitTermination ( timeoutMillis , TimeUnit . MILLISECONDS ) ; } catch ( InterruptedException e ) { log . warn ( "Timeout Occur !!! - {}, timeoutMillis - {}" , executorService , timeoutMillis ) ; } log . info ( "Terminated !!! - {} took {} ms" , executorService , startTimeMillis - System . currentTimeMillis ( ) ) ; } | Await termination . |
17,603 | public static < R > R suspendWhenNull ( long intervalAsMillis , Supplier < R > objectSupplier ) { R object = objectSupplier . get ( ) ; if ( object == null ) { log . warn ( "Start Suspending !!!" ) ; long startTimeMillis = System . currentTimeMillis ( ) ; while ( ( object = objectSupplier . get ( ) ) == null ) sleep ( intervalAsMillis ) ; log . warn ( "Stop Suspending Over {} ms" , System . currentTimeMillis ( ) - startTimeMillis ) ; } return object ; } | Suspend when null r . |
17,604 | public static < T > Future < T > run ( Callable < T > callableWork , long timeoutInSec ) { final ExecutorService threadPool = Executors . newFixedThreadPool ( 2 ) ; Future < T > future = threadPool . submit ( callableWork ) ; afterTimeout ( timeoutInSec , threadPool , future ) ; return future ; } | Run future . |
17,605 | public static ScheduledExecutorService newSingleScheduledThreadPool ( ) { ScheduledExecutorService scheduledExecutorService = Executors . newScheduledThreadPool ( 1 ) ; OS . addShutdownHook ( scheduledExecutorService :: shutdown ) ; return scheduledExecutorService ; } | New single scheduled thread pool scheduled executor service . |
17,606 | public static < V > Callable < V > buildCallableWithLogging ( String name , Callable < V > callable , Object ... params ) { return ( ) -> supplyAsync ( ( ) -> { try { JMLog . debug ( log , name , System . currentTimeMillis ( ) , params ) ; return callable . call ( ) ; } catch ( Exception e ) { return JMExceptionManager . handleExceptionAndReturnNull ( log , e , name , params ) ; } } ) . get ( ) ; } | Build callable with logging callable . |
17,607 | public static Runnable buildRunnableWithLogging ( String runnableName , Runnable runnable , Object ... params ) { return ( ) -> { JMLog . debug ( log , runnableName , System . currentTimeMillis ( ) , params ) ; runnable . run ( ) ; } ; } | Build runnable with logging runnable . |
17,608 | public static ScheduledFuture < ? > runWithScheduleAtFixedRate ( long initialDelayMillis , long periodMillis , Runnable runnable ) { return runWithScheduleAtFixedRate ( initialDelayMillis , periodMillis , "runWithScheduleAtFixedRate" , runnable ) ; } | Run with schedule at fixed rate scheduled future . |
17,609 | public static ScheduledFuture < ? > runWithScheduleAtFixedRateOnStartTime ( ZonedDateTime startDateTime , long periodMillis , Runnable runnable ) { return runWithScheduleAtFixedRate ( calInitialDelayMillis ( startDateTime ) , periodMillis , "runWithScheduleAtFixedRateOnStartTime" , runnable ) ; } | Run with schedule at fixed rate on start time scheduled future . |
17,610 | public static ScheduledFuture < ? > runWithScheduleWithFixedDelay ( long initialDelayMillis , long delayMillis , Runnable runnable ) { return runWithScheduleWithFixedDelay ( initialDelayMillis , delayMillis , "runWithScheduleWithFixedDelay" , runnable ) ; } | Run with schedule with fixed delay scheduled future . |
17,611 | public static ScheduledFuture < ? > runWithScheduleWithFixedDelayOnStartTime ( ZonedDateTime startDateTime , long delayMillis , Runnable runnable ) { return runWithScheduleWithFixedDelay ( calInitialDelayMillis ( startDateTime ) , delayMillis , "runWithScheduleWithFixedDelayOnStartTime" , runnable ) ; } | Run with schedule with fixed delay on start time scheduled future . |
17,612 | public static ExecutorService startWithSingleExecutorService ( String message , Runnable runnable ) { return startWithExecutorService ( newSingleThreadPool ( ) , message , runnable ) ; } | Start with single executor service executor service . |
17,613 | public static < E > BlockingQueue < E > getLimitedBlockingQueue ( int maxQueue ) { return new LinkedBlockingQueue < E > ( maxQueue ) { public boolean offer ( E e ) { return putInsteadOfOffer ( this , e ) ; } } ; } | Gets limited blocking queue . |
17,614 | public static < E > BlockingQueue < E > getWaitingLimitedBlockingQueue ( long waitingMillis , int maxQueue ) { return new LinkedBlockingQueue < E > ( maxQueue ) { public boolean offer ( E e ) { if ( size ( ) >= maxQueue ) { sleep ( waitingMillis ) ; log . warn ( "Wait For {} ms And Blocking !!! - maxQueue = {}" , waitingMillis , maxQueue ) ; } return putInsteadOfOffer ( this , e ) ; } } ; } | Gets waiting limited blocking queue . |
17,615 | public static ExecutorService newMaxQueueThreadPool ( int numWorkerThreads , long waitingMillis , int maxQueue ) { return new ThreadPoolExecutor ( numWorkerThreads , numWorkerThreads , 0L , TimeUnit . MILLISECONDS , waitingMillis > 0 ? getWaitingLimitedBlockingQueue ( waitingMillis , maxQueue ) : getLimitedBlockingQueue ( maxQueue ) ) ; } | New max queue thread pool executor service . |
17,616 | static Method findMethod ( Class < ? > clazz , String methodName , Object [ ] args , boolean isStatic ) throws NoSuchMethodException { Class < ? > [ ] argTypes = getTypes ( args ) ; Method [ ] methods = null ; if ( classMethodsCache . containsKey ( clazz ) ) { methods = classMethodsCache . get ( clazz ) ; } else { methods = clazz . getMethods ( ) ; classMethodsCache . put ( clazz , methods ) ; } ArrayList < Method > fitMethods = new ArrayList < Method > ( ) ; for ( Method method : methods ) { if ( methodName . equals ( method . getName ( ) ) ) { if ( ! isStatic || Modifier . isStatic ( method . getModifiers ( ) ) ) { if ( match ( argTypes , method . getParameterTypes ( ) ) ) { fitMethods . add ( method ) ; } } } } int fitSize = fitMethods . size ( ) ; if ( fitSize == 0 ) { throw new NoSuchMethodException ( Messages . getString ( "beans.41" , methodName ) ) ; } if ( fitSize == 1 ) { return fitMethods . get ( 0 ) ; } MethodComparator comparator = new MethodComparator ( methodName , argTypes ) ; Method [ ] fitMethodArray = fitMethods . toArray ( new Method [ fitSize ] ) ; Method onlyMethod = fitMethodArray [ 0 ] ; Class < ? > onlyReturnType , fitReturnType ; int difference ; for ( int i = 1 ; i < fitMethodArray . length ; i ++ ) { if ( ( difference = comparator . compare ( onlyMethod , fitMethodArray [ i ] ) ) == 0 ) { onlyReturnType = onlyMethod . getReturnType ( ) ; fitReturnType = fitMethodArray [ i ] . getReturnType ( ) ; if ( onlyReturnType == fitReturnType ) { throw new NoSuchMethodException ( Messages . getString ( "beans.62" , methodName ) ) ; } if ( onlyReturnType . isAssignableFrom ( fitReturnType ) ) { onlyMethod = fitMethodArray [ i ] ; } } if ( difference > 0 ) { onlyMethod = fitMethodArray [ i ] ; } } return onlyMethod ; } | Searches for best matching method for given name and argument types . |
17,617 | public static < K , V > List < V > removeAllIfByKey ( Map < K , V > map , Predicate < ? super K > filter ) { return map . keySet ( ) . stream ( ) . filter ( filter ) . collect ( toList ( ) ) . stream ( ) . map ( map :: remove ) . collect ( toList ( ) ) ; } | Remove all if by key list . |
17,618 | public static < K , V > List < V > removeAllIfByEntry ( Map < K , V > map , Predicate < ? super Entry < K , V > > filter ) { return getEntryStreamWithFilter ( map , filter ) . map ( Entry :: getKey ) . collect ( toList ( ) ) . stream ( ) . map ( map :: remove ) . collect ( toList ( ) ) ; } | Remove all if by entry list . |
17,619 | public static < K , V > Stream < Entry < K , V > > getEntryStreamWithFilter ( Map < K , V > map , Predicate < ? super Entry < K , V > > predicate ) { return buildEntryStream ( map ) . filter ( predicate ) ; } | Gets entry stream with filter . |
17,620 | public static < K , V > V getOrElse ( Map < K , V > map , K key , Supplier < V > valueSupplier ) { return JMOptional . getOptional ( map , key ) . orElseGet ( valueSupplier ) ; } | Gets or else . |
17,621 | public static < V , K > V putGetNew ( Map < K , V > map , K key , V newValue ) { synchronized ( map ) { map . put ( key , newValue ) ; return newValue ; } } | Put get new v . |
17,622 | public static < K , V , NK > Map < NK , V > newChangedKeyMap ( Map < K , V > map , Function < K , NK > changingKeyFunction ) { return buildEntryStream ( map ) . collect ( toMap ( entry -> changingKeyFunction . apply ( entry . getKey ( ) ) , Entry :: getValue ) ) ; } | New changed key map map . |
17,623 | public static < K , V , NK > Map < NK , V > newChangedKeyWithEntryMap ( Map < K , V > map , Function < Entry < K , V > , NK > changingKeyFunction ) { return buildEntryStream ( map ) . collect ( toMap ( changingKeyFunction , Entry :: getValue ) ) ; } | New changed key with entry map map . |
17,624 | public static < K , V , NK > Map < NK , V > newFilteredChangedKeyWithEntryMap ( Map < K , V > map , Predicate < ? super Entry < K , V > > filter , Function < Entry < K , V > , NK > changingKeyFunction ) { return getEntryStreamWithFilter ( map , filter ) . collect ( toMap ( changingKeyFunction , Entry :: getValue ) ) ; } | New filtered changed key with entry map map . |
17,625 | public static < K , V , NV > Map < K , NV > newChangedValueMap ( Map < K , V > map , Function < V , NV > changingValueFunction ) { synchronized ( map ) { return buildEntryStream ( map ) . collect ( toMap ( Entry :: getKey , entry -> changingValueFunction . apply ( entry . getValue ( ) ) ) ) ; } } | New changed value map map . |
17,626 | public static < K , V , NV > Map < K , NV > newChangedValueWithEntryMap ( Map < K , V > map , Function < Entry < K , V > , NV > changingValueFunction ) { return buildEntryStream ( map ) . collect ( toMap ( Entry :: getKey , changingValueFunction ) ) ; } | New changed value with entry map map . |
17,627 | public static < K , V , NV > Map < K , NV > newFilteredChangedValueWithEntryMap ( Map < K , V > map , Predicate < Entry < K , V > > filter , Function < Entry < K , V > , NV > changingValueFunction ) { return getEntryStreamWithFilter ( map , filter ) . collect ( toMap ( Entry :: getKey , changingValueFunction :: apply ) ) ; } | New filtered changed value with entry map map . |
17,628 | public static < K , V , NK , NV > Map < NK , NV > newChangedKeyValueMap ( Map < K , V > map , Function < K , NK > changingKeyFunction , Function < V , NV > changingValueFunction ) { return buildEntryStream ( map ) . collect ( toMap ( entry -> changingKeyFunction . apply ( entry . getKey ( ) ) , entry -> changingValueFunction . apply ( entry . getValue ( ) ) ) ) ; } | New changed key value map map . |
17,629 | public static < K , V , NK , NV > Map < NK , NV > newFilteredChangedKeyValueMap ( Map < K , V > map , Predicate < ? super Entry < K , V > > filter , Function < K , NK > changingKeyFunction , Function < V , NV > changingValueFunction ) { return getEntryStreamWithFilter ( map , filter ) . collect ( toMap ( entry -> changingKeyFunction . apply ( entry . getKey ( ) ) , entry -> changingValueFunction . apply ( entry . getValue ( ) ) ) ) ; } | New filtered changed key value map map . |
17,630 | public static < K , V , NK , NV > Map < NK , NV > newChangedKeyValueWithEntryMap ( Map < K , V > map , Function < Entry < K , V > , NK > changingKeyFunction , Function < Entry < K , V > , NV > changingValueFunction ) { return buildEntryStream ( map ) . collect ( toMap ( changingKeyFunction , changingValueFunction ) ) ; } | New changed key value with entry map map . |
17,631 | public static < K , V , NK , NV > Map < NK , NV > newFilteredChangedKeyValueWithEntryMap ( Map < K , V > map , Predicate < ? super Entry < K , V > > filter , Function < Entry < K , V > , NK > changingKeyFunction , Function < Entry < K , V > , NV > changingValueFunction ) { return getEntryStreamWithFilter ( map , filter ) . collect ( toMap ( changingKeyFunction , changingValueFunction ) ) ; } | New filtered changed key value with entry map map . |
17,632 | public static < K , V > Map < K , V > newFilteredMap ( Map < K , V > map , Predicate < ? super Entry < K , V > > filter ) { return getEntryStreamWithFilter ( map , filter ) . collect ( toMap ( Entry :: getKey , Entry :: getValue ) ) ; } | New filtered map map . |
17,633 | public static < K , V extends Comparable < V > > Map < K , V > sortByValue ( Map < K , V > map ) { return sort ( map , comparing ( map :: get ) ) ; } | Sort by value map . |
17,634 | public static < K , V extends Comparable < V > > Stream < Entry < K , V > > sortedStreamByValue ( Map < K , V > map ) { return buildEntryStream ( map ) . sorted ( comparing ( Entry :: getValue ) ) ; } | Sorted stream by value stream . |
17,635 | public static < K , V > Map < K , V > newCombinedMap ( K [ ] keys , V [ ] values ) { HashMap < K , V > map = new HashMap < > ( ) ; for ( int i = 0 ; i < keys . length ; i ++ ) map . put ( keys [ i ] , getValueOfIndex ( values , i ) ) ; return map ; } | New combined map map . |
17,636 | public static Map < String , Object > newFlatKeyMap ( Map < String , ? > map ) { return newFlatKeyMap ( new HashMap < > ( ) , map ) ; } | New flat key map map . |
17,637 | public static < T > Map < Boolean , List < T > > partitionBy ( Collection < T > collection , Predicate < T > predicate ) { return collection . stream ( ) . collect ( partitioningBy ( predicate ) ) ; } | Partition by map . |
17,638 | public static < T , R > Map < R , T > merge ( Stream < Map < R , T > > stream ) { return stream . collect ( HashMap :: new , Map :: putAll , Map :: putAll ) ; } | Merge map . |
17,639 | public static < T , R1 , R2 > Map < R1 , Map < R2 , T > > groupByTwoKey ( Collection < T > collection , Function < T , R1 > classifier1 , Function < T , R2 > classifier2 ) { return collection . stream ( ) . collect ( groupingBy ( classifier1 , toMap ( classifier2 , t -> t ) ) ) ; } | Group by two key map . |
17,640 | public static < T > void consumeByPredicate ( Collection < T > collection , Predicate < T > predicate , Consumer < T > trueConsumer , Consumer < T > falseConsumer ) { collection . forEach ( target -> JMLambda . consumeByBoolean ( predicate . test ( target ) , target , trueConsumer , falseConsumer ) ) ; } | Consume by predicate . |
17,641 | public static < T > void consumeByBoolean ( boolean bool , T target , Consumer < T > trueConsumer , Consumer < T > falseConsumer ) { if ( bool ) trueConsumer . accept ( target ) ; else falseConsumer . accept ( target ) ; } | Consume by boolean . |
17,642 | public static < T > void consumeIfNotNull ( T target , Consumer < T > consumer ) { Optional . ofNullable ( target ) . ifPresent ( consumer ) ; } | Consume if not null . |
17,643 | public static < T , R > Optional < R > functionIfTrue ( boolean bool , T target , Function < T , R > function ) { return supplierIfTrue ( bool , ( ) -> function . apply ( target ) ) ; } | Function if true optional . |
17,644 | public static < T , U , R > Optional < R > biFunctionIfTrue ( boolean bool , T target1 , U target2 , BiFunction < T , U , R > biFunction ) { return supplierIfTrue ( bool , ( ) -> biFunction . apply ( target1 , target2 ) ) ; } | Bi function if true optional . |
17,645 | public static < R > Optional < R > supplierIfTrue ( boolean bool , Supplier < R > supplier ) { return bool ? Optional . ofNullable ( supplier . get ( ) ) : Optional . empty ( ) ; } | Supplier if true optional . |
17,646 | public static < T , R > R functionByBoolean ( boolean bool , T target , Function < T , R > trueFunction , Function < T , R > falseFunction ) { return bool ? trueFunction . apply ( target ) : falseFunction . apply ( target ) ; } | Function by boolean r . |
17,647 | public static < R > R supplierByBoolean ( boolean bool , Supplier < R > trueSupplier , Supplier < R > falseSupplier ) { return bool ? trueSupplier . get ( ) : falseSupplier . get ( ) ; } | Supplier by boolean r . |
17,648 | public static < T , R > Function < T , R > changeInto ( R input ) { return t -> input ; } | Change into function . |
17,649 | public static < R > R supplierIfNull ( R target , Supplier < R > supplier ) { return Optional . ofNullable ( target ) . orElseGet ( supplier ) ; } | Supplier if null r . |
17,650 | public static void runByBoolean ( boolean bool , Runnable trueBlock , Runnable falseBlock ) { if ( bool ) trueBlock . run ( ) ; else falseBlock . run ( ) ; } | Run by boolean . |
17,651 | public static < T > T consumeAndGetSelf ( T target , Consumer < T > targetConsumer ) { targetConsumer . accept ( target ) ; return target ; } | Consume and get self t . |
17,652 | protected void cleanUpMenuTree ( WebMenuItem root , String menuName ) { List < WebMenuItem > subMenu = root . getSubMenu ( ) ; List < WebMenuItem > rootBreadcrumbs = root . getBreadcrumbs ( ) ; if ( subMenu != null && subMenu . size ( ) > 0 ) { Collections . sort ( subMenu ) ; for ( int i = 0 ; i < subMenu . size ( ) ; i ++ ) { WebMenuItem item = subMenu . get ( i ) ; if ( item instanceof MenuItemExt ) { MenuItemExt itemExt = ( MenuItemExt ) item ; item = itemExt . toWebMenuItem ( ) ; subMenu . set ( i , item ) ; menuItemPaths . get ( menuName ) . put ( itemExt . path , item ) ; } item . breadcrumbs = new ArrayList < WebMenuItem > ( ) ; if ( rootBreadcrumbs != null ) { item . breadcrumbs . addAll ( rootBreadcrumbs ) ; } item . breadcrumbs . add ( item ) ; cleanUpMenuTree ( item , menuName ) ; } } } | Convert MenuItemExt to WebMenuItem and clean up all data |
17,653 | public WebMenuItem getMenuItem ( String menuName , String path ) { try { return menuItemPaths . get ( menuName ) . get ( path ) ; } catch ( Exception e ) { log . error ( "Error when getting menu item for: menuName='" + menuName + "', path='" + path + "'" , e ) ; return null ; } } | Get the menu item by menu and path |
17,654 | public Bits read ( final int bits ) throws IOException { final int additionalBitsNeeded = bits - this . remainder . bitLength ; final int additionalBytesNeeded = ( int ) Math . ceil ( additionalBitsNeeded / 8. ) ; if ( additionalBytesNeeded > 0 ) this . readAhead ( additionalBytesNeeded ) ; final Bits readBits = this . remainder . range ( 0 , bits ) ; this . remainder = this . remainder . range ( bits ) ; return readBits ; } | Read bits . |
17,655 | public Bits peek ( final int bits ) throws IOException { final int additionalBitsNeeded = bits - this . remainder . bitLength ; final int additionalBytesNeeded = ( int ) Math . ceil ( additionalBitsNeeded / 8. ) ; if ( additionalBytesNeeded > 0 ) this . readAhead ( additionalBytesNeeded ) ; return this . remainder . range ( 0 , Math . min ( bits , this . remainder . bitLength ) ) ; } | Peek bits . |
17,656 | public Bits readAhead ( final int bytes ) throws IOException { assert ( 0 < bytes ) ; if ( 0 < bytes ) { final byte [ ] buffer = new byte [ bytes ] ; int bytesRead = this . inner . read ( buffer ) ; if ( bytesRead > 0 ) { this . remainder = this . remainder . concatenate ( new Bits ( Arrays . copyOf ( buffer , bytesRead ) ) ) ; } } return this . remainder ; } | Read ahead bits . |
17,657 | public long readVarLong ( ) throws IOException { final int type = ( int ) this . read ( 2 ) . toLong ( ) ; return this . read ( BitOutputStream . varLongDepths [ type ] ) . toLong ( ) ; } | Read var long long . |
17,658 | public long peekLongCoord ( long max ) throws IOException { if ( 1 >= max ) return 0 ; int bits = 1 + ( int ) Math . ceil ( Math . log ( max ) / Math . log ( 2 ) ) ; Bits peek = this . peek ( bits ) ; double divisor = 1 << peek . bitLength ; long value = ( int ) ( peek . toLong ( ) * ( ( double ) max ) / divisor ) ; assert ( 0 <= value ) ; assert ( max >= value ) ; return value ; } | Peek long coord long . |
17,659 | public short readVarShort ( int optimal ) throws IOException { int [ ] varShortDepths = { optimal , 16 } ; final int type = ( int ) this . read ( 1 ) . toLong ( ) ; return ( short ) this . read ( varShortDepths [ type ] ) . toLong ( ) ; } | Read var short short . |
17,660 | public static Cluster connectCluster ( String host , int port ) { Builder clusterBuilder = Cluster . builder ( ) ; SocketOptions socketOptions = new SocketOptions ( ) ; socketOptions . setConnectTimeoutMillis ( 60000 ) ; socketOptions . setKeepAlive ( true ) ; socketOptions . setReadTimeoutMillis ( 30000 ) ; return clusterBuilder . addContactPoint ( host ) . withSocketOptions ( socketOptions ) . withPort ( port ) . build ( ) ; } | Connects to the specified host and port . |
17,661 | public void addFilter ( Filter filter ) { filter . setInitialContext ( initialContext ) ; int minIndex = Integer . MAX_VALUE ; String [ ] before = filter . before ( ) ; for ( int i = 0 ; i < before . length ; i ++ ) { String s = before [ i ] ; int index = index ( activeFilters , s ) ; if ( index < minIndex ) { minIndex = index ; } } if ( minIndex == Integer . MAX_VALUE ) { minIndex = - 1 ; } if ( contains ( filter . before ( ) , FIRST_IN_PIPE ) ) { activeFilters . add ( 0 , filter ) ; } else if ( minIndex != - 1 ) { activeFilters . add ( minIndex , filter ) ; } else { activeFilters . add ( filter ) ; } } | Add a filter to the active pipe |
17,662 | public String filter ( String input , FilterContext context ) { String output = input ; Iterator filterIterator = activeFilters . iterator ( ) ; RenderContext renderContext = context . getRenderContext ( ) ; while ( filterIterator . hasNext ( ) ) { Filter f = ( Filter ) filterIterator . next ( ) ; if ( ! inactiveFilters . contains ( f ) ) { try { if ( f instanceof CacheFilter ) { renderContext . setCacheable ( true ) ; } else { renderContext . setCacheable ( false ) ; } String tmp = f . filter ( output , context ) ; if ( output . equals ( tmp ) ) { renderContext . setCacheable ( true ) ; } if ( null == tmp ) { log . warn ( "FilterPipe.filter: error while filtering: " + f ) ; } else { output = tmp ; } renderContext . commitCache ( ) ; } catch ( Exception e ) { log . warn ( "Filtering exception: " + f , e ) ; } } } return output ; } | Filter some input and generate ouput . FilterPipe pipes the string input through every filter in the pipe and returns the resulting string . |
17,663 | @ Requires ( { "parent != null" , "annotation != null" , "owner != null" , "p != null" } ) protected void visitAnnotation ( Element parent , AnnotationMirror annotation , boolean primary , ClassName owner , ElementModel p ) { if ( utils . isContractAnnotation ( annotation ) ) { ContractAnnotationModel model = createContractModel ( parent , annotation , primary , owner ) ; if ( model != null ) { p . addEnclosedElement ( model ) ; } } } | Visits an annotation and adds a corresponding node to the specified Element . |
17,664 | protected void initAuthenticationHeader ( ) { if ( isAuthenticated ( ) ) { final String xamzdate = new SimpleDateFormat ( DATE_FORMAT , Locale . US ) . format ( new Date ( ) ) ; final StringJoiner signedHeaders = new StringJoiner ( EOL , "" , EOL ) ; final StringBuilder toSign = new StringBuilder ( ) ; final String key = myKey . charAt ( 0 ) == '?' ? "" : myKey ; headers ( ) . add ( "X-Amz-Date" , xamzdate ) ; signedHeaders . add ( "x-amz-date:" + xamzdate ) ; if ( ! StringUtils . isEmpty ( mySessionToken ) ) { headers ( ) . add ( "X-Amz-Security-Token" , mySessionToken ) ; signedHeaders . add ( "x-amz-security-token:" + mySessionToken ) ; } toSign . append ( myMethod ) . append ( EOL ) . append ( myContentMd5 ) . append ( EOL ) . append ( myContentType ) . append ( EOL ) . append ( EOL ) . append ( signedHeaders ) . append ( PATH_SEP ) . append ( myBucket ) . append ( PATH_SEP ) . append ( key ) ; try { final String signature = b64SignHmacSha1 ( mySecretKey , toSign . toString ( ) ) ; final String authorization = "AWS" + " " + myAccessKey + ":" + signature ; headers ( ) . add ( "Authorization" , authorization ) ; } catch ( InvalidKeyException | NoSuchAlgorithmException details ) { LOGGER . error ( "Failed to sign S3 request due to {}" , details ) ; } } } | Adds the authentication header . |
17,665 | private static String b64SignHmacSha1 ( final String aAwsSecretKey , final String aCanonicalString ) throws NoSuchAlgorithmException , InvalidKeyException { final SecretKeySpec signingKey = new SecretKeySpec ( aAwsSecretKey . getBytes ( ) , HASH_CODE ) ; final Mac mac = Mac . getInstance ( HASH_CODE ) ; mac . init ( signingKey ) ; return new String ( Base64 . getEncoder ( ) . encode ( mac . doFinal ( aCanonicalString . getBytes ( ) ) ) ) ; } | Returns a Base64 HmacSha1 signature . |
17,666 | public void setAsObject ( Object value ) { if ( value instanceof AnyValue ) _value = ( ( AnyValue ) value ) . _value ; else _value = value ; } | Sets a new value for this object |
17,667 | public < T > T getAsNullableType ( Class < T > type ) { return TypeConverter . toNullableType ( type , _value ) ; } | Converts object value into a value defined by specied typecode . If conversion is not possible it returns null . |
17,668 | public < T > T getAsType ( Class < T > type ) { return getAsTypeWithDefault ( type , null ) ; } | Converts object value into a value defined by specied typecode . If conversion is not possible it returns default value for the specified type . |
17,669 | public < T > T getAsTypeWithDefault ( Class < T > type , T defaultValue ) { return TypeConverter . toTypeWithDefault ( type , _value , defaultValue ) ; } | Converts object value into a value defined by specied typecode . If conversion is not possible it returns default value . |
17,670 | public < T > boolean equalsAs ( Class < T > type , Object obj ) { if ( obj == null && _value == null ) return true ; if ( obj == null || _value == null ) return false ; if ( obj instanceof AnyValue ) obj = ( ( AnyValue ) obj ) . _value ; T typedThisValue = TypeConverter . toType ( type , _value ) ; T typedValue = TypeConverter . toType ( type , obj ) ; if ( typedThisValue == null && typedValue == null ) return true ; if ( typedThisValue == null || typedValue == null ) return false ; return typedThisValue . equals ( typedValue ) ; } | Compares this object value to specified specified value . When direct comparison gives negative results it converts values to type specified by type code and compare them again . |
17,671 | public static void setUser ( String userName , String password ) { getImpl ( ) . getDirectoryServiceClient ( ) . setUser ( userName , password ) ; } | Set the Directory User . |
17,672 | public static Gaussian fromBinomial ( final double probability , final long totalPopulation ) { if ( 0. >= totalPopulation ) { throw new IllegalArgumentException ( ) ; } if ( 0. >= probability ) { throw new IllegalArgumentException ( ) ; } if ( 1. <= probability ) { throw new IllegalArgumentException ( ) ; } if ( Double . isNaN ( probability ) ) { throw new IllegalArgumentException ( ) ; } if ( Double . isInfinite ( probability ) ) { throw new IllegalArgumentException ( ) ; } return new Gaussian ( probability * totalPopulation , Math . sqrt ( totalPopulation * probability * ( 1 - probability ) ) ) ; } | From binomial gaussian . |
17,673 | public long decode ( final BitInputStream in , final long max ) throws IOException { if ( 0 == max ) { return 0 ; } int bits = ( int ) ( Math . round ( log2 ( 2 * this . stdDev ) ) - 1 ) ; if ( 0 > bits ) { bits = 0 ; } final long centralWindow = 1l << bits ; if ( centralWindow >= ( max + 1 ) / 2. ) { return in . readBoundedLong ( max + 1 ) ; } long stdDevWindowStart = ( long ) ( this . mean - centralWindow / 2 ) ; long stdDevWindowEnd = stdDevWindowStart + centralWindow ; if ( stdDevWindowStart < 0 ) { stdDevWindowEnd += - stdDevWindowStart ; stdDevWindowStart += - stdDevWindowStart ; } else { final long delta = stdDevWindowEnd - ( max + 1 ) ; if ( delta > 0 ) { stdDevWindowStart -= delta ; stdDevWindowEnd -= delta ; } } if ( in . readBool ( ) ) { return in . readBoundedLong ( centralWindow ) + stdDevWindowStart ; } else { boolean side ; if ( stdDevWindowStart <= 0 ) { side = true ; } else if ( stdDevWindowEnd > max ) { side = false ; } else { side = in . readBool ( ) ; } if ( side ) { return stdDevWindowEnd + in . readBoundedLong ( 1 + max - stdDevWindowEnd ) ; } else { return in . readBoundedLong ( stdDevWindowStart ) ; } } } | Decode long . |
17,674 | public static void notifyOne ( String correlationId , Object component , Parameters args ) throws ApplicationException { if ( component instanceof INotifiable ) ( ( INotifiable ) component ) . notify ( correlationId , args ) ; } | Notifies specific component . |
17,675 | protected void handleOutput ( InputStream stdout ) throws IOException { byte [ ] buffer = new byte [ 4 * 1024 ] ; int b ; while ( ( b = stdout . read ( buffer ) ) > 0 ) { out . write ( buffer , 0 , b ) ; } } | Handles the process standard output stream . |
17,676 | protected void handleError ( InputStream stderr ) throws IOException { byte [ ] buffer = new byte [ 4 * 1024 ] ; int b ; while ( ( b = stderr . read ( buffer ) ) > 0 ) { err . write ( buffer , 0 , b ) ; } } | Handles the process standard error stream . |
17,677 | protected void handleProcessTimeout ( String [ ] cmd ) throws IOException { StringBuilder bld = new StringBuilder ( ) ; boolean first = true ; for ( String c : cmd ) { if ( first ) { first = false ; } else { bld . append ( " " ) ; } String esc = Strings . escape ( c ) ; if ( ! c . equals ( esc ) || c . contains ( " " ) ) { bld . append ( '\"' ) . append ( esc ) . append ( '\"' ) ; } else { bld . append ( c ) ; } } throw new IOException ( "Process took too long: " + bld . toString ( ) ) ; } | Handle timeout on the process finishing . |
17,678 | public static Number getPercentileValue ( int targetPercentile , List < Number > unorderedNumberList ) { return getPercentileValueWithSorted ( targetPercentile , sortedDoubleList ( unorderedNumberList ) ) ; } | Gets percentile value . |
17,679 | public static Map < Integer , Number > getPercentileValueMap ( List < Integer > targetPercentileList , List < Number > numberList ) { List < Double > sortedDoubleList = sortedDoubleList ( numberList ) ; return targetPercentileList . stream ( ) . collect ( toMap ( percentile -> percentile , percentile -> getPercentileValueWithSorted ( percentile , sortedDoubleList ) ) ) ; } | Gets percentile value map . |
17,680 | public static < N extends Number > Number min ( List < N > numberList ) { return cal ( numberList , DoubleStream :: min ) ; } | Min number . |
17,681 | public static < N extends Number > double cal ( List < N > numberList , Function < DoubleStream , OptionalDouble > calFunction ) { return JMCollections . isNullOrEmpty ( numberList ) ? 0 : calFunction . apply ( numberList . stream ( ) . mapToDouble ( Number :: doubleValue ) ) . orElse ( 0 ) ; } | Cal double . |
17,682 | public static < N extends Number > Number max ( List < N > numberList ) { return cal ( numberList , DoubleStream :: max ) ; } | Max number . |
17,683 | public static < N extends Number > Number sum ( List < N > numberList ) { return cal ( numberList , doubleStream -> OptionalDouble . of ( doubleStream . sum ( ) ) ) ; } | Sum number . |
17,684 | public static < N extends Number > Number average ( List < N > numberList ) { return cal ( numberList , DoubleStream :: average ) ; } | Average number . |
17,685 | public static double calPercentPrecisely ( Number target , Number total ) { double targetD = target . doubleValue ( ) ; double totalD = total . doubleValue ( ) ; return targetD == totalD ? 100d : targetD / totalD * 100 ; } | Cal percent precisely double . |
17,686 | public static String calPercent ( Number target , Number total , int digit ) { return JMString . roundedNumberFormat ( calPercentPrecisely ( target , total ) , digit ) ; } | Cal percent string . |
17,687 | public static double roundWithDecimalPlace ( double doubleNumber , int decimalPlace ) { double pow = pow ( 10 , decimalPlace ) ; return Math . round ( doubleNumber * pow ) / pow ; } | Round with decimal place double . |
17,688 | public static double roundWithPlace ( double doubleNumber , int place ) { double pow = pow ( 10 , place ) ; return Math . round ( doubleNumber / pow ) * pow ; } | Round with place double . |
17,689 | public static double pow ( Number baseNumber , int exponent ) { return exponent < 1 ? 1 : exponent > 1 ? baseNumber . doubleValue ( ) * pow ( baseNumber , exponent - 1 ) : baseNumber . doubleValue ( ) ; } | Pow double . |
17,690 | public static double calSumOfSquares ( List < ? extends Number > numberList ) { return calSumOfSquares ( numberList . stream ( ) . mapToDouble ( Number :: doubleValue ) ) ; } | Cal sum of squares double . |
17,691 | public static void validateMetadata ( Map < String , String > metadata ) throws ServiceException { for ( String key : metadata . keySet ( ) ) { if ( ! validateRequiredField ( key , metaKeyRegEx ) ) { throw new ServiceException ( ErrorCode . SERVICE_INSTANCE_METAKEY_FORMAT_ERROR , ErrorCode . SERVICE_INSTANCE_METAKEY_FORMAT_ERROR . getMessageTemplate ( ) , key ) ; } } } | Validate the ServiceInstance Metadata . |
17,692 | private static boolean isValidBrace ( String url ) { if ( null == url || url . trim ( ) . length ( ) == 0 ) { return false ; } boolean isInsideVariable = false ; StringTokenizer tokenizer = new StringTokenizer ( url , "{}" , true ) ; while ( tokenizer . hasMoreTokens ( ) ) { String token = tokenizer . nextToken ( ) ; if ( token . equals ( "{" ) ) { if ( isInsideVariable ) { return false ; } isInsideVariable = true ; } else if ( token . equals ( "}" ) ) { if ( ! isInsideVariable ) { return false ; } isInsideVariable = false ; } } return true ; } | Validate the url of the Instance . |
17,693 | public static IntStream numberRangeClosed ( int startInclusive , int endInclusive , int interval ) { return numberRange ( startInclusive , endInclusive , interval , n -> n <= endInclusive ) ; } | Number range closed int stream . |
17,694 | public static IntStream numberRangeWithCount ( int start , int interval , int count ) { return IntStream . iterate ( start , n -> n + interval ) . limit ( count ) ; } | Number range with count int stream . |
17,695 | public static < N extends Number > IntStream buildIntStream ( Collection < N > numberCollection ) { return numberCollection . stream ( ) . mapToInt ( Number :: intValue ) ; } | Build int stream int stream . |
17,696 | public static < N extends Number > LongStream buildLongStream ( Collection < N > numberCollection ) { return numberCollection . stream ( ) . mapToLong ( Number :: longValue ) ; } | Build long stream long stream . |
17,697 | public static < N extends Number > DoubleStream buildDoubleStream ( Collection < N > numberCollection ) { return numberCollection . stream ( ) . mapToDouble ( Number :: doubleValue ) ; } | Build double stream double stream . |
17,698 | public static < T > Stream < T > buildReversedStream ( Collection < T > collection ) { return JMCollections . getReversed ( collection ) . stream ( ) ; } | Build reversed stream stream . |
17,699 | public static Stream < String > buildTokenStream ( String text , String delimiter ) { return JMStream . buildStream ( delimiter == null ? new StringTokenizer ( text ) : new StringTokenizer ( text , delimiter ) ) . map ( o -> ( String ) o ) ; } | Build token stream stream . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.