idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
17,400
public static Optional < JMProgressiveManager < Path , Path > > copyFilePathListAsync ( List < Path > filePathList , Path destinationDirPath , CopyOption ... options ) { return operateBulk ( filePathList , destinationDirPath , sourcePath -> Optional . ofNullable ( copy ( sourcePath , destinationDirPath , options ) ) ) ; }
Copy file path list async optional .
17,401
public static Optional < Path > moveDir ( Path sourceDirPath , Path destinationDirPath , CopyOption ... options ) { return operateDir ( sourceDirPath , destinationDirPath , sourceDirPath , path -> move ( path , destinationDirPath , options ) ) ; }
Move dir optional .
17,402
public static Optional < JMProgressiveManager < Path , Path > > movePathListAsync ( List < Path > pathList , Path destinationDirPath , CopyOption ... options ) { return operateBulk ( pathList , destinationDirPath , sourcePath -> JMPath . isDirectory ( sourcePath ) ? moveDir ( sourcePath , destinationDirPath , options ) : Optional . ofNullable ( move ( sourcePath , destinationDirPath , options ) ) ) ; }
Move path list async optional .
17,403
public static boolean deleteAll ( Path targetPath ) { debug ( log , "deleteAll" , targetPath ) ; return JMPath . isDirectory ( targetPath ) ? deleteDir ( targetPath ) : delete ( targetPath ) ; }
Delete all boolean .
17,404
public static boolean deleteDir ( Path targetDirPath ) { debug ( log , "deleteDir" , targetDirPath ) ; return deleteBulkThenFalseList ( JMCollections . getReversed ( JMPath . getSubPathList ( targetDirPath ) ) ) . size ( ) == 0 && delete ( targetDirPath ) ; }
Delete dir boolean .
17,405
public static List < Path > deleteBulkThenFalseList ( List < Path > bulkPathList ) { debug ( log , "deleteBulkThenFalseList" , bulkPathList ) ; return bulkPathList . stream ( ) . filter ( negate ( JMPathOperation :: deleteAll ) ) . collect ( toList ( ) ) ; }
Delete bulk then false list list .
17,406
public static JMProgressiveManager < Path , Boolean > deleteAllAsync ( List < Path > pathList ) { debug ( log , "deleteAllAsync" , pathList ) ; return new JMProgressiveManager < > ( pathList , targetPath -> Optional . of ( deleteAll ( targetPath ) ) ) ; }
Delete all async jm progressive manager .
17,407
public static Path deleteOnExit ( Path path ) { debug ( log , "deleteOnExit" , path ) ; path . toFile ( ) . deleteOnExit ( ) ; return path ; }
Delete on exit path .
17,408
public static Optional < Path > createTempFilePathAsOpt ( Path path ) { debug ( log , "createTempFilePathAsOpt" , path ) ; String [ ] prefixSuffix = JMFiles . getPrefixSuffix ( path . toFile ( ) ) ; try { return Optional . of ( Files . createTempFile ( prefixSuffix [ 0 ] , prefixSuffix [ 1 ] ) ) . filter ( JMPath . ExistFilter ) . map ( JMPathOperation :: deleteOnExit ) ; } catch ( Exception e ) { return JMExceptionManager . handleExceptionAndReturnEmptyOptional ( log , e , "createTempFilePathAsOpt" , path ) ; } }
Create temp file path as opt optional .
17,409
public static Optional < Path > createTempDirPathAsOpt ( Path path ) { debug ( log , "createTempDirPathAsOpt" , path ) ; try { return Optional . of ( Files . createTempDirectory ( path . toString ( ) ) ) . filter ( JMPath . ExistFilter ) . map ( JMPathOperation :: deleteOnExit ) ; } catch ( Exception e ) { return JMExceptionManager . handleExceptionAndReturnEmptyOptional ( log , e , "createTempDirPathAsOpt" , path ) ; } }
Create temp dir path as opt optional .
17,410
public static Optional < Path > createFile ( Path path , FileAttribute < ? > ... attrs ) { debug ( log , "createFile" , path , attrs ) ; try { return Optional . of ( Files . createFile ( path , attrs ) ) ; } catch ( Exception e ) { return JMExceptionManager . handleExceptionAndReturnEmptyOptional ( log , e , "createFile" , path ) ; } }
Create file optional .
17,411
public static Optional < Path > createDirectories ( Path dirPath , FileAttribute < ? > ... attrs ) { debug ( log , "createDirectories" , dirPath , attrs ) ; try { return Optional . of ( Files . createDirectories ( dirPath , attrs ) ) ; } catch ( Exception e ) { return JMExceptionManager . handleExceptionAndReturnEmptyOptional ( log , e , "createDirectories" , dirPath ) ; } }
Create directories optional .
17,412
public static void createFileWithParentDirectories ( Path path , FileAttribute < ? > ... attrs ) { createDirectories ( path . getParent ( ) , attrs ) ; createFile ( path , attrs ) ; }
Create file with parent directories .
17,413
public static String encodeToString ( final byte [ ] source , int off , int len ) { byte [ ] encoded = encode ( source , off , len ) ; return new String ( encoded , US_ASCII ) ; }
Encodes a byte array into Base64 string .
17,414
public static byte [ ] encode ( final byte [ ] source , final int off , final int len ) { if ( source == null ) { throw new NullPointerException ( "Cannot serialize a null array." ) ; } if ( off < 0 ) { throw new IllegalArgumentException ( "Cannot have negative offset: " + off ) ; } if ( len < 0 ) { throw new IllegalArgumentException ( "Cannot have negative length: " + len ) ; } if ( off + len > source . length ) { throw new IllegalArgumentException ( String . format ( "Cannot have offset of %d and length of %d with array of length %d" , off , len , source . length ) ) ; } if ( len == 0 ) { return new byte [ 0 ] ; } int blocks = len / 3 ; int extra = len % 3 ; int bufLen = blocks * 4 + ( extra > 0 ? extra + 1 : 0 ) ; byte [ ] dest = new byte [ bufLen ] ; int srcPos = 0 ; int destPos = 0 ; final int len2 = len - 2 ; for ( ; srcPos < len2 ; srcPos += 3 ) { destPos += encode3to4 ( source , srcPos + off , 3 , dest , destPos ) ; } if ( srcPos < len ) { encode3to4 ( source , srcPos + off , len - srcPos , dest , destPos ) ; } return dest ; }
Encodes a byte array into Base64 data .
17,415
public ApplicationException create ( ErrorDescription description ) { if ( description == null ) throw new NullPointerException ( "Description cannot be null" ) ; ApplicationException error = null ; String category = description . getCategory ( ) ; String code = description . getCode ( ) ; String message = description . getMessage ( ) ; String correlationId = description . getCorrelationId ( ) ; if ( ErrorCategory . Unknown . equals ( category ) ) error = new UnknownException ( correlationId , code , message ) ; else if ( ErrorCategory . Internal . equals ( category ) ) error = new InternalException ( correlationId , code , message ) ; else if ( ErrorCategory . Misconfiguration . equals ( category ) ) error = new ConfigException ( correlationId , code , message ) ; else if ( ErrorCategory . NoResponse . equals ( category ) ) error = new ConnectionException ( correlationId , code , message ) ; else if ( ErrorCategory . FailedInvocation . equals ( category ) ) error = new InvocationException ( correlationId , code , message ) ; else if ( ErrorCategory . FileError . equals ( category ) ) error = new FileException ( correlationId , code , message ) ; else if ( ErrorCategory . BadRequest . equals ( category ) ) error = new BadRequestException ( correlationId , code , message ) ; else if ( ErrorCategory . Unauthorized . equals ( category ) ) error = new UnauthorizedException ( correlationId , code , message ) ; else if ( ErrorCategory . Conflict . equals ( category ) ) error = new ConflictException ( correlationId , code , message ) ; else if ( ErrorCategory . NotFound . equals ( category ) ) error = new NotFoundException ( correlationId , code , message ) ; else if ( ErrorCategory . InvalidState . equals ( category ) ) error = new InvalidStateException ( correlationId , code , message ) ; else if ( ErrorCategory . Unsupported . equals ( category ) ) error = new UnsupportedException ( correlationId , code , message ) ; else { error = new UnknownException ( ) ; error . setCategory ( category ) ; error . setStatus ( description . getStatus ( ) ) ; } error . setDetails ( description . getDetails ( ) ) ; error . setCauseString ( description . getCause ( ) ) ; error . setStackTraceString ( description . getStackTrace ( ) ) ; return error ; }
Recreates ApplicationException object from serialized ErrorDescription .
17,416
public static Window display ( final String title , final int width , final int height , final Picture picture ) { return play ( title , width , height , new Animation ( ) { public Picture getPicture ( ) { return picture ; } public void update ( final double time , final double delta ) { } } ) ; }
Displays a static picture in a single window .
17,417
public static < M > Window animate ( final String title , final int width , final int height , final M model , final Renderer < M > renderer , final UpdateHandler < M > updateHandler ) { return animate ( title , width , height , new Animation ( ) { public void update ( final double time , final double delta ) { updateHandler . update ( model , time , delta ) ; } public Picture getPicture ( ) { return renderer . render ( model ) ; } } ) ; }
Displays an animation in a single window .
17,418
static public String listToJSONString ( List < ? > list ) { if ( list == null || list . size ( ) == 0 ) { return "[]" ; } StringBuilder sb = new StringBuilder ( "[" ) ; for ( Object o : list ) { buildAppendString ( sb , o ) . append ( ',' ) . append ( ' ' ) ; } return sb . delete ( sb . length ( ) - 2 , sb . length ( ) ) . append ( ']' ) . toString ( ) ; }
List to json string string .
17,419
public static String mapToJSONString ( Map < ? , ? > map ) { if ( map == null || map . size ( ) == 0 ) { return "{}" ; } StringBuilder sb = new StringBuilder ( "{" ) ; for ( Object o : map . entrySet ( ) ) { Entry < ? , ? > e = ( Entry < ? , ? > ) o ; buildAppendString ( sb , e . getKey ( ) ) . append ( '=' ) ; buildAppendString ( sb , e . getValue ( ) ) . append ( ',' ) . append ( ' ' ) ; } return sb . delete ( sb . length ( ) - 2 , sb . length ( ) ) . append ( '}' ) . toString ( ) ; }
Map to json string string .
17,420
private void cleanStackTrace ( ) { StackTraceElement [ ] realTrace = getStackTrace ( ) ; StackTraceElement [ ] trace = new StackTraceElement [ realTrace . length - 1 ] ; StackTraceElement top = realTrace [ 0 ] ; trace [ 0 ] = new StackTraceElement ( top . getClassName ( ) , getMethodName ( realTrace [ 2 ] . getMethodName ( ) ) , top . getFileName ( ) , top . getLineNumber ( ) ) ; System . arraycopy ( realTrace , 2 , trace , 1 , realTrace . length - 2 ) ; setStackTrace ( trace ) ; }
Remove wrapper call leaving only the contract helper .
17,421
public boolean match ( Object locator ) { if ( _reference . equals ( locator ) ) return true ; else if ( locator instanceof Class < ? > ) return ( ( Class < ? > ) locator ) . isInstance ( _reference ) ; else if ( _locator != null ) return _locator . equals ( locator ) ; else return false ; }
Matches locator to this reference locator .
17,422
public STTYModeSwitcher setSTTYMode ( STTYMode mode ) { try { return new STTYModeSwitcher ( mode , runtime ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } }
Set the current STTY mode and return the closable switcher to turn back .
17,423
private void addError ( IValidationContext context , ConstraintViolation violation , JsonPointer pointer ) { final Class < ? extends Annotation > annotationType = violation . getConstraintDescriptor ( ) . getAnnotation ( ) . annotationType ( ) ; final IErrorCode validationCode = constraintConverter . getErrorCode ( annotationType ) ; final IErrorLocationType validationType = constraintConverter . getErrorLocationType ( annotationType ) ; context . addError ( pointer . toString ( ) , validationType , validationCode , violation . getMessage ( ) ) ; }
Adds an error message describing a constraint violation .
17,424
private void load ( ) { Iterator iterator = loaders . iterator ( ) ; while ( iterator . hasNext ( ) ) { MacroLoader loader = ( MacroLoader ) iterator . next ( ) ; loader . setRepository ( this ) ; log . debug ( "Loading from: " + loader . getClass ( ) ) ; loader . loadPlugins ( this ) ; } }
Loads macros from all loaders into plugins .
17,425
private static ViewType parseType ( JsonNode node ) throws UnknownViewTypeException { if ( node . hasNonNull ( "type" ) ) { try { return ViewType . valueOf ( node . get ( "type" ) . asText ( ) . toUpperCase ( Locale . ENGLISH ) ) ; } catch ( IllegalArgumentException e ) { throw new UnknownViewTypeException ( node . get ( "type" ) . asText ( ) ) ; } } else { throw new UnknownViewTypeException ( "missing type" ) ; } }
Parses the view type from the given JSON node .
17,426
public Stream < T > stream ( ) { if ( thread == null ) { synchronized ( this ) { if ( thread == null ) { thread = new Thread ( ( ) -> read ( queue ) ) ; thread . setDaemon ( true ) ; thread . start ( ) ; } } } final Iterator < T > iterator = new AsyncListIterator < > ( queue , thread ) ; return StreamSupport . stream ( Spliterators . spliteratorUnknownSize ( iterator , Spliterator . DISTINCT ) , false ) . filter ( x -> x != null ) ; }
Stream stream .
17,427
public BigInteger getAndSet ( BigInteger newValue ) { while ( true ) { BigInteger current = get ( ) ; if ( valueHolder . compareAndSet ( current , newValue ) ) return current ; } }
Atomically sets to the given value and returns the old value .
17,428
public BigInteger getTotalCounts ( ) { BigInteger result = BigInteger . ZERO ; for ( AtomicLong c : counters . getMap ( ) . values ( ) ) { result = result . add ( BigInteger . valueOf ( c . get ( ) ) ) ; } return result ; }
Get the summary value of all the counts
17,429
public static Integer toNullableInteger ( Object value ) { Long result = LongConverter . toNullableLong ( value ) ; return result != null ? ( int ) ( ( long ) result ) : null ; }
Converts value into integer or returns null when conversion is not possible .
17,430
public static int toIntegerWithDefault ( Object value , int defaultValue ) { Integer result = toNullableInteger ( value ) ; return result != null ? ( int ) result : defaultValue ; }
Converts value into integer or returns default value when conversion is not possible .
17,431
private Object findSpringBean ( String beanName ) { ServletContext servletContext = this . pageContext . getServletContext ( ) ; Enumeration < String > attrNames = servletContext . getAttributeNames ( ) ; while ( attrNames . hasMoreElements ( ) ) { String attrName = attrNames . nextElement ( ) ; if ( attrName . startsWith ( "org.springframework" ) ) { try { WebApplicationContext springContext = WebApplicationContextUtils . getWebApplicationContext ( servletContext , attrName ) ; Object bean = springContext . getBean ( beanName ) ; return bean ; } catch ( Exception e ) { } } } return null ; }
Find the Spring bean from WebApplicationContext in servlet context .
17,432
public static byte [ ] integerToBytes ( BigInteger s , int length ) { byte [ ] bytes = s . toByteArray ( ) ; if ( length < bytes . length ) { byte [ ] tmp = new byte [ length ] ; System . arraycopy ( bytes , bytes . length - tmp . length , tmp , 0 , tmp . length ) ; return tmp ; } else if ( length > bytes . length ) { byte [ ] tmp = new byte [ length ] ; System . arraycopy ( bytes , 0 , tmp , tmp . length - bytes . length , bytes . length ) ; return tmp ; } return bytes ; }
Get a big integer as an array of bytes of a specified length
17,433
public static Point multiply ( Point p , BigInteger k ) { BigInteger e = k ; BigInteger h = e . multiply ( BigInteger . valueOf ( 3 ) ) ; Point neg = p . negate ( ) ; Point R = p ; for ( int i = h . bitLength ( ) - 2 ; i > 0 ; -- i ) { R = R . twice ( ) ; boolean hBit = h . testBit ( i ) ; boolean eBit = e . testBit ( i ) ; if ( hBit != eBit ) { R = R . add ( hBit ? p : neg ) ; } } return R ; }
Multiply a point with a big integer
17,434
public String getProviderAddress ( ) { if ( providerAddress != null ) { Matcher matcher = HOST_PORT_PATTERN . matcher ( providerAddress ) ; if ( matcher . matches ( ) && isValidPort ( matcher . group ( 2 ) ) ) { return matcher . group ( 1 ) ; } } else if ( providerId != null ) { Matcher matcher = HOST_PORT_PATTERN . matcher ( providerId ) ; if ( matcher . matches ( ) && isValidPort ( matcher . group ( 2 ) ) ) { return matcher . group ( 1 ) ; } } return providerAddress ; }
Get the providerAddress .
17,435
public static TypeCode toTypeCode ( Class < ? > type ) { if ( type == null ) return TypeCode . Unknown ; else if ( type . isArray ( ) ) return TypeCode . Array ; else if ( type . isEnum ( ) ) return TypeCode . Enum ; else if ( type . isPrimitive ( ) ) { if ( _booleanType . isAssignableFrom ( type ) ) return TypeCode . Boolean ; if ( _doubleType . isAssignableFrom ( type ) ) return TypeCode . Double ; if ( _floatType . isAssignableFrom ( type ) ) return TypeCode . Float ; if ( _longType . isAssignableFrom ( type ) ) return TypeCode . Long ; if ( _integerType . isAssignableFrom ( type ) ) return TypeCode . Integer ; } else { if ( _booleanType . isAssignableFrom ( type ) ) return TypeCode . Boolean ; if ( _doubleType . isAssignableFrom ( type ) ) return TypeCode . Double ; if ( _floatType . isAssignableFrom ( type ) ) return TypeCode . Float ; if ( _longType . isAssignableFrom ( type ) ) return TypeCode . Long ; if ( _integerType . isAssignableFrom ( type ) ) return TypeCode . Integer ; if ( _stringType . isAssignableFrom ( type ) ) return TypeCode . String ; if ( _dateTimeType . isAssignableFrom ( type ) ) return TypeCode . DateTime ; if ( _durationType . isAssignableFrom ( type ) ) return TypeCode . Duration ; if ( _mapType . isAssignableFrom ( type ) ) return TypeCode . Map ; if ( _listType . isAssignableFrom ( type ) ) return TypeCode . Array ; if ( _enumType . isAssignableFrom ( type ) ) return TypeCode . Enum ; } return TypeCode . Object ; }
Gets TypeCode for specific type .
17,436
public static TypeCode toTypeCode ( Object value ) { if ( value == null ) return TypeCode . Unknown ; return toTypeCode ( value . getClass ( ) ) ; }
Gets TypeCode for specific value .
17,437
@ SuppressWarnings ( "unchecked" ) public static < T > T toNullableType ( Class < T > type , Object value ) { TypeCode resultType = toTypeCode ( type ) ; if ( value == null ) return null ; if ( type . isInstance ( value ) ) return ( T ) value ; if ( resultType == TypeCode . String ) return type . cast ( StringConverter . toNullableString ( value ) ) ; else if ( resultType == TypeCode . Integer ) return type . cast ( IntegerConverter . toNullableInteger ( value ) ) ; else if ( resultType == TypeCode . Long ) return type . cast ( LongConverter . toNullableLong ( value ) ) ; else if ( resultType == TypeCode . Float ) return type . cast ( FloatConverter . toNullableFloat ( value ) ) ; else if ( resultType == TypeCode . Double ) return type . cast ( DoubleConverter . toNullableDouble ( value ) ) ; else if ( resultType == TypeCode . Duration ) return type . cast ( DurationConverter . toNullableDuration ( value ) ) ; else if ( resultType == TypeCode . DateTime ) return type . cast ( DateTimeConverter . toNullableDateTime ( value ) ) ; else if ( resultType == TypeCode . Array ) return type . cast ( ArrayConverter . toNullableArray ( value ) ) ; else if ( resultType == TypeCode . Map ) return type . cast ( MapConverter . toNullableMap ( value ) ) ; try { return type . cast ( value ) ; } catch ( Throwable t ) { return null ; } }
Converts value into an object type specified by Type Code or returns null when conversion is not possible .
17,438
public static < T > T toType ( Class < T > type , Object value ) { T result = toNullableType ( type , value ) ; if ( result != null ) return result ; TypeCode resultType = toTypeCode ( type ) ; if ( resultType == TypeCode . String ) return null ; else if ( resultType == TypeCode . Integer ) return type . cast ( ( int ) 0 ) ; else if ( resultType == TypeCode . Long ) return type . cast ( ( long ) 0 ) ; else if ( resultType == TypeCode . Float ) return type . cast ( ( float ) 0 ) ; else if ( resultType == TypeCode . Double ) return type . cast ( ( double ) 0 ) ; else return null ; }
Converts value into an object type specified by Type Code or returns type default when conversion is not possible .
17,439
public static < T > T toTypeWithDefault ( Class < T > type , Object value , T defaultValue ) { T result = toNullableType ( type , value ) ; return result != null ? result : defaultValue ; }
Converts value into an object type specified by Type Code or returns default value when conversion is not possible .
17,440
private String extractFileName ( Part part ) { String disposition = part . getHeader ( "Content-Disposition" ) ; if ( disposition == null ) return null ; Matcher matcher = FILENAME_PATTERN . matcher ( disposition ) ; if ( ! matcher . find ( ) ) return null ; return matcher . group ( 1 ) ; }
Extract filename property from Part s Content - Disposition header .
17,441
public synchronized Double getPercentile ( final double percentile ) { if ( null == values ) return Double . NaN ; return values . parallelStream ( ) . flatMapToDouble ( x -> Arrays . stream ( x ) ) . sorted ( ) . skip ( ( int ) ( percentile * values . size ( ) ) ) . findFirst ( ) . orElse ( Double . NaN ) ; }
Gets percentile .
17,442
@ SuppressWarnings ( "unchecked" ) public Q includeFields ( final Set < String > fields ) { if ( this . fields == null ) { this . fields = new HashSet < > ( ) ; } if ( fields != null ) { this . fields . addAll ( fields ) ; } return ( Q ) this ; }
Specify the set of fields to return in the results . Defined using the Fluent API approach .
17,443
private void validateServiceInstanceMetadataQuery ( ServiceInstanceQuery query ) throws ServiceException { if ( query == null ) { throw new ServiceException ( ErrorCode . SERVICE_DIRECTORY_NULL_ARGUMENT_ERROR , ErrorCode . SERVICE_DIRECTORY_NULL_ARGUMENT_ERROR . getMessageTemplate ( ) , "service instance query" ) ; } for ( QueryCriterion criterion : query . getCriteria ( ) ) { if ( criterion instanceof ContainQueryCriterion || criterion instanceof NotContainQueryCriterion ) { throw new ServiceException ( ErrorCode . QUERY_CRITERION_ILLEGAL_IN_QUERY ) ; } } }
Validate the metadata query for the queryInstanceByMetadataKey queryInstancesByMetadataKey and getAllInstancesByMetadataKey methods . For those methods the ContainQueryCriterion and NotContainQueryCriterion are not supported .
17,444
public static Map < String , Number > buildStatsMap ( Collection < Number > numberCollection ) { return JMMap . newChangedKeyMap ( getOptional ( numberCollection ) . map ( NumberSummaryStatistics :: of ) . map ( NumberSummaryStatistics :: getStatsFieldMap ) . orElseGet ( Collections :: emptyMap ) , StatsField :: name ) ; }
Build stats map map .
17,445
static public String exceptionSummary ( JMSException e ) { Throwable cause = e . getCause ( ) ; Exception linked = e . getLinkedException ( ) ; return "JMSException: " + e . getMessage ( ) + ", error code: " + e . getErrorCode ( ) + ", linked exception: " + ( linked == null ? null : ( linked . getClass ( ) . getName ( ) + " - " + linked . getMessage ( ) ) ) + ", cause: " + ( cause == null ? null : ( cause . getClass ( ) . getName ( ) + " - " + cause . getMessage ( ) ) ) ; }
Generate a single line String consisted of the summary of a JMSException
17,446
public static Float toNullableFloat ( Object value ) { Double result = DoubleConverter . toNullableDouble ( value ) ; return result != null ? ( float ) ( ( double ) result ) : null ; }
Converts value into float or returns null when conversion is not possible .
17,447
public static float toFloatWithDefault ( Object value , float defaultValue ) { Float result = toNullableFloat ( value ) ; return result != null ? ( float ) result : defaultValue ; }
Converts value into float or returns default when conversion is not possible .
17,448
public List < Construction > getNextConstructions ( ) { List < Construction > constructions = new ArrayList < Construction > ( ) ; for ( T item : kernelItems ) { Construction element = item . getNext ( ) ; if ( element != null ) { constructions . add ( element ) ; } } for ( T item : nonKernelItems ) { Construction element = item . getNext ( ) ; if ( element != null ) { constructions . add ( element ) ; } } return constructions ; }
This method returns all constructions which are next to be expected to be found .
17,449
public List < T > getNextItems ( Construction construction ) { List < T > items = new ArrayList < T > ( ) ; for ( T item : allItems ) { if ( construction . equals ( item . getNext ( ) ) ) { items . add ( item ) ; } } return items ; }
This method returns all items which have the given construction as next construction .
17,450
public ModelServiceInstance getModelServiceInstance ( String serviceName , String instanceId ) { ModelService service = getModelService ( serviceName ) ; if ( service != null && service . getServiceInstances ( ) != null ) { for ( ModelServiceInstance instance : service . getServiceInstances ( ) ) { if ( instance . getInstanceId ( ) . equals ( instanceId ) ) { return instance ; } } } return null ; }
Get the ModelServiceInstance by serviceName and instanceId .
17,451
public List < ModelServiceInstance > getModelInstancesByMetadataKey ( String keyName ) { ModelMetadataKey key = getModelMetadataKey ( keyName ) ; if ( key == null || key . getServiceInstances ( ) . isEmpty ( ) ) { return Collections . < ModelServiceInstance > emptyList ( ) ; } else { return new ArrayList < ModelServiceInstance > ( key . getServiceInstances ( ) ) ; } }
Get the ModelServiceInstance list that contains the metadata key .
17,452
protected void onServiceInstanceUnavailable ( ServiceInstance instance ) { if ( instance == null ) { return ; } String serviceName = instance . getServiceName ( ) ; List < NotificationHandler > handlerList = new ArrayList < NotificationHandler > ( ) ; synchronized ( notificationHandlers ) { if ( notificationHandlers . containsKey ( serviceName ) ) { handlerList . addAll ( notificationHandlers . get ( serviceName ) ) ; } } for ( NotificationHandler h : handlerList ) { h . serviceInstanceUnavailable ( instance ) ; } }
Invoke the serviceInstanceUnavailable of the NotificationHandler .
17,453
protected void onServiceInstanceChanged ( ServiceInstance instance ) { String serviceName = instance . getServiceName ( ) ; List < NotificationHandler > handlerList = new ArrayList < NotificationHandler > ( ) ; synchronized ( notificationHandlers ) { if ( notificationHandlers . containsKey ( serviceName ) ) { handlerList . addAll ( notificationHandlers . get ( serviceName ) ) ; } } for ( NotificationHandler h : handlerList ) { h . serviceInstanceChange ( instance ) ; } }
Invoke the serviceInstanceChange of the NotificationHandler .
17,454
protected void onServiceInstanceAvailable ( ServiceInstance instance ) { String serviceName = instance . getServiceName ( ) ; List < NotificationHandler > handlerList = new ArrayList < NotificationHandler > ( ) ; synchronized ( notificationHandlers ) { if ( notificationHandlers . containsKey ( serviceName ) ) { handlerList . addAll ( notificationHandlers . get ( serviceName ) ) ; } } for ( NotificationHandler h : handlerList ) { h . serviceInstanceAvailable ( instance ) ; } }
Invoke the serviceInstanceAvailable of the NotificationHandler .
17,455
public static < E > List < E > asFlatList ( Iterable < E > ... iterables ) { List < E > list = new ArrayList < E > ( ) ; for ( Iterable < E > iterable : iterables ) { for ( E e : iterable ) { list . add ( e ) ; } } return list ; }
Adds elements from one or more iterables to a single flat list
17,456
public static void dump ( Appendable appendable , Iterable < ? > items ) { try { for ( Object item : items ) { appendable . append ( String . valueOf ( item ) ) ; appendable . append ( "\n" ) ; } } catch ( IOException e ) { throw new RuntimeException ( "An error occured while appending" , e ) ; } }
Writes the string value of the specified items to appendable wrapping an eventual IOException into a RuntimeException
17,457
protected void debug ( TextProvider textProvider ) { if ( ! m_debug ) return ; Throwable t = new Throwable ( ) ; StackTraceElement e [ ] = t . getStackTrace ( ) ; StackTraceElement ste = e [ 1 ] ; String indent = "" ; for ( int i = 0 ; i < m_indent ; i ++ ) indent += " " ; log . debug ( "{}SUCCESS {}:{}" , indent , ste . getMethodName ( ) , textProvider . debug ( ) ) ; }
Report the debug information to the logger
17,458
public void clearLeadingSpaces ( TextProvider textProvider ) { while ( true ) { mark ( textProvider ) ; char c ; try { c = getNextChar ( textProvider ) ; } catch ( ExceededBufferSizeException e ) { return ; } catch ( ParserException e ) { return ; } if ( c == 0 ) { if ( m_textProviderStack . size ( ) > 0 ) { textProvider . close ( ) ; textProvider = ( TextProvider ) m_textProviderStack . pop ( ) ; } break ; } if ( " \t\r\n" . indexOf ( c ) == - 1 ) { reset ( textProvider ) ; break ; } unmark ( textProvider ) ; } }
Jump over leading spaces Custom match methods normally call this before trying to match anything
17,459
public boolean exactOrError ( String match , TextProvider textProvider ) { if ( ! exact ( match , textProvider , false ) ) { throw new ParserException ( "Expected " + match , textProvider ) ; } return true ; }
Match against the passed string . Case is ignored if the ignoreCase flag is set .
17,460
public boolean endOfData ( TextProvider textProvider ) { clearLastToken ( textProvider ) ; clearLeadingSpaces ( textProvider ) ; mark ( textProvider ) ; if ( m_debug ) debug ( "testing" , textProvider ) ; try { char c = getNextChar ( textProvider ) ; if ( c == 0 ) { unmark ( textProvider ) ; return true ; } } catch ( Exception e ) { unmark ( textProvider ) ; debug ( textProvider ) ; return true ; } reset ( textProvider ) ; return false ; }
Test to see if we are at the end of the data
17,461
public boolean alphaNum ( TextProvider textProvider ) { clearLastToken ( textProvider ) ; clearLeadingSpaces ( textProvider ) ; mark ( textProvider ) ; if ( m_debug ) debug ( "testing" , textProvider ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { char c = getNextChar ( textProvider ) ; if ( ! Character . isLetterOrDigit ( c ) ) break ; remark ( textProvider ) ; sb . append ( c ) ; } reset ( textProvider ) ; if ( sb . toString ( ) . length ( ) == 0 ) return false ; textProvider . setLastToken ( sb . toString ( ) ) ; debug ( textProvider ) ; return true ; }
See if there is an alphanumeric
17,462
public boolean any ( TextProvider textProvider ) { clearLastToken ( textProvider ) ; clearLeadingSpaces ( textProvider ) ; mark ( textProvider ) ; if ( m_debug ) debug ( "testing" , textProvider ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { char c = getNextChar ( textProvider ) ; if ( c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 0 ) { break ; } sb . append ( c ) ; } unmark ( textProvider ) ; String s = sb . toString ( ) . trim ( ) ; if ( s . length ( ) == 0 ) return false ; textProvider . setLastToken ( s ) ; debug ( textProvider ) ; return true ; }
Match the next space bounded string
17,463
public boolean quotedString ( char quote , TextProvider textProvider ) { clearLastToken ( textProvider ) ; clearLeadingSpaces ( textProvider ) ; mark ( textProvider ) ; if ( m_debug ) debug ( "testing " + quote , textProvider ) ; if ( getNextChar ( textProvider ) != quote ) { reset ( textProvider ) ; return false ; } char lastChar = 0 ; char c = 0 ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { lastChar = c ; c = getNextChar ( textProvider ) ; if ( c == 0 ) { unmark ( textProvider ) ; return false ; } if ( c == quote && lastChar != '\\' ) break ; sb . append ( c ) ; } unmark ( textProvider ) ; String s = sb . toString ( ) . trim ( ) ; if ( s . length ( ) == 0 ) return false ; textProvider . setLastToken ( s ) ; debug ( textProvider ) ; return true ; }
Match a quoted string . The quotes have to be present but they are removed from the result . Quotes inside the string can be quoted using the \ character eg \
17,464
public boolean getBracketedToken ( char start , char end , TextProvider textProvider ) { clearLastToken ( textProvider ) ; clearLeadingSpaces ( textProvider ) ; mark ( textProvider ) ; if ( m_debug ) debug ( "testing " + start + " " + end , textProvider ) ; StringBuilder sb = new StringBuilder ( ) ; char c = getNextChar ( textProvider ) ; if ( c != start ) { reset ( textProvider ) ; return false ; } int brackets = 0 ; while ( true ) { if ( c == start ) brackets ++ ; if ( c == end ) brackets -- ; sb . append ( c ) ; if ( brackets < 1 ) break ; c = getNextChar ( textProvider ) ; if ( c == 0 ) { reset ( textProvider ) ; return false ; } } unmark ( textProvider ) ; String s = sb . toString ( ) . trim ( ) ; if ( s . length ( ) == 0 ) return false ; textProvider . setLastToken ( s ) ; debug ( textProvider ) ; return true ; }
Match a bracketed token given the start bracket and the end bracket The result includes the brackets .
17,465
public int add ( T item ) { Integer count = map . get ( item ) ; if ( count == null ) { map . put ( item , 1 ) ; return 1 ; } else { map . put ( item , count + 1 ) ; return count + 1 ; } }
add item to histogram increasing its frequency by one
17,466
public static boolean isNumber ( String numberString ) { return Optional . ofNullable ( numberPattern ) . orElseGet ( ( ) -> numberPattern = Pattern . compile ( NumberPattern ) ) . matcher ( numberString ) . matches ( ) ; }
Is number boolean .
17,467
public static boolean isWord ( String wordString ) { return Optional . ofNullable ( wordPattern ) . orElseGet ( ( ) -> wordPattern = Pattern . compile ( WordPattern ) ) . matcher ( wordString ) . matches ( ) ; }
Is word boolean .
17,468
public static String joiningWith ( Stream < String > stringStream , CharSequence delimiter ) { return stringStream . collect ( Collectors . joining ( delimiter ) ) ; }
Joining with string .
17,469
public static String getPrefixOfFileName ( String fileName ) { int dotIndex = fileName . lastIndexOf ( DOT ) ; return dotIndex > 0 ? fileName . substring ( 0 , dotIndex ) : fileName ; }
Gets prefix of file name .
17,470
public static String getExtension ( String fileName ) { int dotIndex = fileName . lastIndexOf ( DOT ) ; return dotIndex > 0 ? fileName . substring ( dotIndex ) : EMPTY ; }
Gets extension .
17,471
public static FilterParams fromTuples ( Object ... tuples ) { StringValueMap map = StringValueMap . fromTuplesArray ( tuples ) ; return new FilterParams ( map ) ; }
Creates a new FilterParams from a list of key - value pairs called tuples .
17,472
public static FilterParams fromString ( String line ) { StringValueMap map = StringValueMap . fromString ( line ) ; return new FilterParams ( map ) ; }
Parses semicolon - separated key - value pairs and returns them as a FilterParams .
17,473
public static FilterParams fromValue ( Object value ) { if ( value instanceof FilterParams ) return ( FilterParams ) value ; AnyValueMap map = AnyValueMap . fromValue ( value ) ; return new FilterParams ( map ) ; }
Converts specified value into FilterParams .
17,474
protected void executeSQL ( String sql ) { Connection conn = null ; Statement stmt = null ; if ( useAnt ) { try { AntSqlExec sqlExec = new AntSqlExec ( dataSource , sql , delimiter , delimiterType ) ; sqlExec . execute ( ) ; log . info ( "SQL executed with Ant: " + sql ) ; } catch ( BuildException be ) { throw new RuntimeException ( "Failed to execute SQL with Ant (" + be . getMessage ( ) + "): " + sql , be ) ; } } else { try { conn = dataSource . getConnection ( ) ; stmt = conn . createStatement ( ) ; stmt . execute ( sql ) ; log . info ( "SQL executed: " + sql ) ; } catch ( SQLException sqle ) { throw new RuntimeException ( "Failed to execute SQL (" + sqle . getMessage ( ) + "): " + sql , sqle ) ; } finally { ConnectionUtility . closeConnection ( conn , stmt ) ; } } }
Execute one SQL statement . RuntimeException will be thrown if SQLException was caught .
17,475
protected boolean isInCondition ( String sql ) { Connection conn = null ; Statement stmt = null ; ResultSet rs = null ; try { conn = dataSource . getConnection ( ) ; stmt = conn . createStatement ( ) ; rs = stmt . executeQuery ( sql ) ; rs . next ( ) ; long result = rs . getInt ( 1 ) ; log . debug ( "Result from the condition checking SQL is " + result + " : " + sql ) ; return result > 0 ; } catch ( SQLException sqle ) { throw new RuntimeException ( "Unable to check condition (" + sqle . getMessage ( ) + ") for: " + sql , sqle ) ; } finally { ConnectionUtility . closeConnection ( conn , stmt , rs ) ; } }
Check if the database is in a specific condition by checking the result of a SQL statement
17,476
protected boolean isInConditionResource ( String resource ) { Resource sqlResource = context . getResource ( resource ) ; InputStream in = null ; String sql = null ; try { in = sqlResource . getInputStream ( ) ; sql = IOUtils . toString ( in ) ; } catch ( IOException ioe ) { throw new RuntimeException ( "Failed to get condition SQL (" + ioe . getMessage ( ) + ") from: " + resource , ioe ) ; } finally { IOUtils . closeQuietly ( in ) ; } if ( StringUtils . isNotBlank ( sql ) ) { return isInCondition ( sql ) ; } else { return true ; } }
Check if the database is in a specific condition by checking the result of a SQL statement loaded as a resource .
17,477
public static int getBoundedNumber ( Random random , int inclusiveLowerBound , int exclusiveUpperBound ) { return random . nextInt ( exclusiveUpperBound - inclusiveLowerBound ) + inclusiveLowerBound ; }
Gets bounded number .
17,478
public List < String > getMatchedListByGroup ( String targetString ) { return getMatcherAsOpt ( targetString ) . map ( matcher -> rangeClosed ( 1 , matcher . groupCount ( ) ) . mapToObj ( matcher :: group ) . map ( Object :: toString ) . collect ( toList ( ) ) ) . orElseGet ( Collections :: emptyList ) ; }
Gets matched list by group .
17,479
public Map < String , String > getGroupNameValueMap ( String targetString ) { return getMatcherAsOpt ( targetString ) . map ( matcher -> groupNameList . stream ( ) . collect ( Collectors . toMap ( Function . identity ( ) , matcher :: group ) ) ) . orElseGet ( Collections :: emptyMap ) ; }
Gets group name value map .
17,480
public < T > T executeAbortable ( ExecutorService exec , Callable < T > callable ) throws IOException , InterruptedException , ExecutionException { Future < T > task = exec . submit ( callable ) ; waitAbortable ( task ) ; return task . get ( ) ; }
Execute callable which may not be interruptable by itself but listen to terminal input and abort the task if CTRL - C is pressed .
17,481
public void finish ( ) { try { if ( switcher . getCurrentMode ( ) == STTYMode . RAW && lineCount > 0 ) { out . write ( '\r' ) ; out . write ( '\n' ) ; out . flush ( ) ; } lineCount = 0 ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } }
Finish the current set of lines and continue below .
17,482
public static Configuration getConfiguration ( ) { if ( configurations == null ) { configurations = ConfigurationFactory . getConfiguration ( ) ; LOGGER . info ( "Initialized the Configurations." ) ; } return configurations ; }
Get the Configuration .
17,483
public static String [ ] getStringArray ( String name ) { if ( getConfiguration ( ) . containsKey ( name ) ) { return getConfiguration ( ) . getStringArray ( name ) ; } return null ; }
Get the property object as String Array .
17,484
public static List < Object > getList ( String name ) { if ( getConfiguration ( ) . containsKey ( name ) ) { return getConfiguration ( ) . getList ( name ) ; } return null ; }
Get the property object as List .
17,485
public static void loadCustomerProperties ( Properties props ) { for ( Entry < Object , Object > entry : props . entrySet ( ) ) { setProperty ( ( String ) entry . getKey ( ) , entry . getValue ( ) ) ; } }
Load the customer Properties to Configurations .
17,486
public LR0ItemSet calc ( LR0ItemSet initialItemSet ) { LR0ItemSet result = closures . get ( initialItemSet ) ; if ( result == null ) { return calculate ( initialItemSet ) ; } return result ; }
This is the closure method for a set of items . This method is described in the Dragon Book 4 . 6 . 2 .
17,487
public static InstanceChange < ServiceInstance > toServiceInstanceChange ( InstanceChange < ModelServiceInstance > modelInstanceChange ) { Objects . requireNonNull ( modelInstanceChange ) ; return new InstanceChange < ServiceInstance > ( modelInstanceChange . changedTimeMills , modelInstanceChange . serviceName , modelInstanceChange . changeType , modelInstanceChange . from == null ? null : toServiceInstance ( modelInstanceChange . from ) , modelInstanceChange . to == null ? null : toServiceInstance ( modelInstanceChange . to ) ) ; }
Convert the model service instance change to the service instance change object
17,488
public Warning createWarning ( final Matcher matcher ) { compileScriptIfNotYetDone ( ) ; Binding binding = new Binding ( ) ; binding . setVariable ( "matcher" , matcher ) ; Object result = null ; try { compiled . setBinding ( binding ) ; result = compiled . run ( ) ; if ( result instanceof Warning ) { return ( Warning ) result ; } } catch ( Exception exception ) { LOGGER . log ( Level . SEVERE , "Groovy dynamic warnings parser: exception during parsing: " , exception ) ; } return falsePositive ; }
Creates a new annotation for the specified match .
17,489
public Map < String , List < Cursor > > getCursorsByDocument ( ) { return this . getCursors ( ) . collect ( Collectors . groupingBy ( ( Cursor x ) -> x . getDocument ( ) ) ) ; }
Gets cursors by document .
17,490
public Stream < Cursor > getCursors ( ) { return LongStream . range ( 0 , getData ( ) . cursorCount ) . mapToObj ( i -> { return new Cursor ( ( CharTrieIndex ) this . trie , ( ( CharTrieIndex ) this . trie ) . cursors . get ( ( int ) ( i + getData ( ) . firstCursorIndex ) ) , getDepth ( ) ) ; } ) ; }
Gets cursors .
17,491
public TrieNode split ( ) { if ( getData ( ) . firstChildIndex < 0 ) { TreeMap < Character , SerialArrayList < CursorData > > sortedChildren = new TreeMap < > ( getCursors ( ) . parallel ( ) . collect ( Collectors . groupingBy ( y -> y . next ( ) . getToken ( ) , Collectors . reducing ( new SerialArrayList < > ( CursorType . INSTANCE , 0 ) , cursor -> new SerialArrayList < > ( CursorType . INSTANCE , cursor . data ) , ( left , right ) -> left . add ( right ) ) ) ) ) ; long cursorWriteIndex = getData ( ) . firstCursorIndex ; ArrayList < NodeData > childNodes = new ArrayList < > ( sortedChildren . size ( ) ) ; for ( Map . Entry < Character , SerialArrayList < CursorData > > e : sortedChildren . entrySet ( ) ) { int length = e . getValue ( ) . length ( ) ; ( ( CharTrieIndex ) this . trie ) . cursors . putAll ( e . getValue ( ) , ( int ) cursorWriteIndex ) ; childNodes . add ( new NodeData ( e . getKey ( ) , ( short ) - 1 , - 1 , length , cursorWriteIndex ) ) ; cursorWriteIndex += length ; } int firstChildIndex = this . trie . nodes . addAll ( childNodes ) ; short size = ( short ) childNodes . size ( ) ; trie . ensureParentIndexCapacity ( firstChildIndex , size , index ) ; this . trie . nodes . update ( index , data -> { return data . setFirstChildIndex ( firstChildIndex ) . setNumberOfChildren ( size ) ; } ) ; return new IndexNode ( this . trie , getDepth ( ) , index , getParent ( ) ) ; } else { return this ; } }
Split trie node .
17,492
public IndexNode visitFirstIndex ( Consumer < ? super IndexNode > visitor ) { visitor . accept ( this ) ; IndexNode refresh = refresh ( ) ; refresh . getChildren ( ) . forEach ( n -> n . visitFirstIndex ( visitor ) ) ; return refresh ; }
Visit first index index node .
17,493
public IndexNode visitLastIndex ( Consumer < ? super IndexNode > visitor ) { getChildren ( ) . forEach ( n -> n . visitLastIndex ( visitor ) ) ; visitor . accept ( this ) ; return refresh ( ) ; }
Visit last index index node .
17,494
public void addPublicKey ( PublicKey key , NetworkParameters network ) { Address address = Address . fromStandardPublicKey ( key , network ) ; _addresses . add ( address ) ; _addressSet . add ( address ) ; _publicKeys . put ( address , key ) ; }
Add a public key to the key ring .
17,495
public Pairtree getPrefixedPairtree ( final String aPrefix , final File aDirectory ) throws PairtreeException { return new FsPairtree ( aPrefix , myVertx , getDirPath ( aDirectory ) ) ; }
Gets a file system based Pairtree using the supplied directory as the Pairtree root and the supplied prefix as the Pairtree prefix .
17,496
public Pairtree getPairtree ( final String aBucket , final String aBucketPath ) throws PairtreeException { if ( myAccessKey . isPresent ( ) && mySecretKey . isPresent ( ) ) { final String accessKey = myAccessKey . get ( ) ; final String secretKey = mySecretKey . get ( ) ; if ( myRegion . isPresent ( ) ) { return new S3Pairtree ( myVertx , aBucket , aBucketPath , accessKey , secretKey , myRegion . get ( ) ) ; } else { return new S3Pairtree ( myVertx , aBucket , aBucketPath , accessKey , secretKey ) ; } } else { throw new PairtreeException ( MessageCodes . PT_021 ) ; } }
Gets the S3 based Pairtree using the supplied S3 bucket and bucket path .
17,497
public Pairtree getPairtree ( final String aBucket , final String aAccessKey , final String aSecretKey ) { return new S3Pairtree ( myVertx , aBucket , aAccessKey , aSecretKey ) ; }
Creates a Pairtree using the supplied bucket and AWS credentials .
17,498
public Pairtree getPrefixedPairtree ( final String aPrefix , final String aBucket , final String aBucketPath , final String aAccessKey , final String aSecretKey ) { return new S3Pairtree ( aPrefix , myVertx , aBucket , aBucketPath , aAccessKey , aSecretKey ) ; }
Creates a Pairtree with the supplied prefix using the supplied S3 bucket and internal bucket path .
17,499
public static void validate ( String address ) throws IllegalEmailAddressException { if ( address == null ) { throw new IllegalEmailAddressException ( "<null>" , "Email address is null." ) ; } if ( address . length ( ) > 254 ) { throw new IllegalEmailAddressException ( address , "Email address is longer than 254 characters." ) ; } String [ ] parts = address . split ( "@" ) ; if ( parts . length < 2 ) { int index = address . indexOf ( '@' ) ; if ( index == 0 ) { throw new IllegalEmailAddressException ( address , "Local part must not be empty." ) ; } else if ( index == ( address . length ( ) - 1 ) ) { throw new IllegalEmailAddressException ( address , "Domain part must not be empty." ) ; } throw new IllegalEmailAddressException ( address , "No @ character included." ) ; } if ( parts . length > 2 ) { throw new IllegalEmailAddressException ( address , "Multiple @ characters included." ) ; } try { validateDomainPart ( parts [ 1 ] ) ; validateLocalPart ( parts [ 0 ] ) ; } catch ( IllegalEmailAddressException e ) { throw new IllegalEmailAddressException ( address , e . getReason ( ) ) ; } }
Validates an email address format .