idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
9,400 | @ NullSafe public static boolean isAnnotationPresent ( Class < ? extends Annotation > annotation , AnnotatedElement ... members ) { return stream ( ArrayUtils . nullSafeArray ( members , AnnotatedElement . class ) ) . anyMatch ( member -> member != null && member . isAnnotationPresent ( annotation ) ) ; } | Determines whether the specified Annotation meta - data is present on the given annotated members such as fields and methods . | 71 | 25 |
9,401 | @ NullSafe public static boolean isClass ( Class type ) { return type != null && ! ( type . isAnnotation ( ) || type . isArray ( ) || type . isEnum ( ) || type . isInterface ( ) || type . isPrimitive ( ) ) ; } | Determines whether the specified Class object represents an actual class and not an Annotation Array Enum Interface or Primitive type . | 60 | 26 |
9,402 | public static < T > Class < T > loadClass ( String fullyQualifiedClassName ) { return loadClass ( fullyQualifiedClassName , DEFAULT_INITIALIZE_LOADED_CLASS , Thread . currentThread ( ) . getContextClassLoader ( ) ) ; } | Loads the Class object for the specified fully qualified class name using the current Thread s context ClassLoader following by initializing the class . | 59 | 27 |
9,403 | @ NullSafe @ SuppressWarnings ( "all" ) public static boolean notInstanceOf ( Object obj , Class ... types ) { boolean result = true ; for ( int index = 0 ; result && index < ArrayUtils . nullSafeLength ( types ) ; index ++ ) { result &= ! instanceOf ( obj , types [ index ] ) ; } return result ; } | Determines whether the Object is an instance of any of the Class types and returns false if it is . | 80 | 22 |
9,404 | public static byte [ ] encrypt ( byte [ ] data , byte [ ] key ) { checkNotNull ( data ) ; checkNotNull ( key ) ; checkArgument ( key . length >= 5 && key . length <= 256 ) ; StreamCipher rc4 = new RC4Engine ( ) ; rc4 . init ( true , new KeyParameter ( key ) ) ; byte [ ] encrypted = new byte [ data . length ] ; rc4 . processBytes ( data , 0 , data . length , encrypted , 0 ) ; return encrypted ; } | Encrypt data bytes using RC4 | 113 | 7 |
9,405 | public static OutputStream encrypt ( OutputStream outputStream , byte [ ] key ) { checkNotNull ( outputStream ) ; checkNotNull ( key ) ; checkArgument ( key . length >= 5 && key . length <= 256 ) ; StreamCipher rc4 = new RC4Engine ( ) ; rc4 . init ( true , new KeyParameter ( key ) ) ; return new CipherOutputStream ( outputStream , rc4 ) ; } | Encrypt output stream using RC4 | 91 | 7 |
9,406 | public static byte [ ] decrypt ( byte [ ] data , byte [ ] key ) { checkNotNull ( data ) ; checkNotNull ( key ) ; checkArgument ( key . length >= 5 && key . length <= 256 ) ; StreamCipher rc4 = new RC4Engine ( ) ; rc4 . init ( false , new KeyParameter ( key ) ) ; byte [ ] decrypted = new byte [ data . length ] ; rc4 . processBytes ( data , 0 , data . length , decrypted , 0 ) ; return decrypted ; } | Decrypt data bytes using RC4 | 116 | 7 |
9,407 | public static InputStream decrypt ( InputStream inputStream , byte [ ] key ) { checkNotNull ( inputStream ) ; checkNotNull ( key ) ; checkArgument ( key . length >= 5 && key . length <= 256 ) ; StreamCipher rc4 = new RC4Engine ( ) ; rc4 . init ( false , new KeyParameter ( key ) ) ; return new CipherInputStream ( inputStream , rc4 ) ; } | Decrypt input stream using RC4 | 91 | 7 |
9,408 | public static StreamCipher createRC4DropCipher ( byte [ ] key , int drop ) { checkArgument ( key . length >= 5 && key . length <= 256 ) ; checkArgument ( drop > 0 ) ; RC4Engine rc4Engine = new RC4Engine ( ) ; rc4Engine . init ( true , new KeyParameter ( key ) ) ; byte [ ] dropBytes = new byte [ drop ] ; Arrays . fill ( dropBytes , ( byte ) 0 ) ; rc4Engine . processBytes ( dropBytes , 0 , dropBytes . length , dropBytes , 0 ) ; return rc4Engine ; } | Creates an RC4 - drop cipher | 132 | 8 |
9,409 | public static xen_health_interface get ( nitro_service client , xen_health_interface resource ) throws Exception { resource . validate ( "get" ) ; return ( ( xen_health_interface [ ] ) resource . get_resources ( client ) ) [ 0 ] ; } | Use this operation to get health and virtual function statistics for the interface . | 59 | 14 |
9,410 | private Map < String , Long > listFiles ( ) throws FtpException { int attempts = 0 ; Map < String , Long > files = new LinkedHashMap < String , Long > ( ) ; while ( true ) { try { FTPListParseEngine engine = null ; if ( type . startsWith ( "UNIX" ) ) { engine = ftpClient . initiateListParsing ( FTPClientConfig . SYST_UNIX , null ) ; } else { engine = ftpClient . initiateListParsing ( ) ; } FTPFile [ ] list = engine . getFiles ( ) ; if ( list != null ) { for ( FTPFile ftpFile : list ) { files . put ( ftpFile . getName ( ) , ftpFile . getSize ( ) ) ; } } return files ; } catch ( Exception e ) { attempts ++ ; if ( attempts > 3 ) { throw new FtpListFilesException ( e ) ; } else { LOGGER . trace ( "First attempt to get list of files FAILED! attempt={}" , attempts ) ; } } } } | List files inside the current folder . | 234 | 7 |
9,411 | public static String normalizeKey ( Algorithms alg ) { if ( alg . equals ( Algorithms . SHA512 ) ) { return FieldName . SHA512 ; } return alg . toString ( ) . toLowerCase ( ) ; } | Handles difference in the keys used for algorithms | 54 | 9 |
9,412 | < O extends Message > JsonResponseFuture < O > newProvisionalResponse ( ClientMethod < O > method ) { long requestId = RANDOM . nextLong ( ) ; JsonResponseFuture < O > outputFuture = new JsonResponseFuture <> ( requestId , method ) ; inFlightRequests . put ( requestId , outputFuture ) ; return outputFuture ; } | Returns a new provisional response suited to receive results of a given protobuf message type . | 81 | 18 |
9,413 | public static String concat ( String [ ] values , String delimiter ) { Assert . notNull ( values , "The array of String values to concatenate cannot be null!" ) ; StringBuilder buffer = new StringBuilder ( ) ; for ( String value : values ) { buffer . append ( buffer . length ( ) > 0 ? delimiter : EMPTY_STRING ) ; buffer . append ( value ) ; } return buffer . toString ( ) ; } | Concatenates the array of Strings into a single String value delimited by the specified delimiter . | 97 | 22 |
9,414 | @ NullSafe public static boolean contains ( String text , String value ) { return text != null && value != null && text . contains ( value ) ; } | Determines whether the String value contains the specified text guarding against null values . | 32 | 16 |
9,415 | @ NullSafe public static boolean containsDigits ( String value ) { for ( char chr : toCharArray ( value ) ) { if ( Character . isDigit ( chr ) ) { return true ; } } return false ; } | Determines whether the String value contains any digits guarding against null values . | 50 | 15 |
9,416 | @ NullSafe public static boolean containsLetters ( String value ) { for ( char chr : toCharArray ( value ) ) { if ( Character . isLetter ( chr ) ) { return true ; } } return false ; } | Determines whether the String value contains any letters guarding against null values . | 49 | 15 |
9,417 | @ NullSafe public static boolean containsWhitespace ( String value ) { for ( char chr : toCharArray ( value ) ) { if ( Character . isWhitespace ( chr ) ) { return true ; } } return false ; } | Determines whether the String value contains any whitespace guarding against null values . | 52 | 16 |
9,418 | @ NullSafe public static String defaultIfBlank ( String value , String ... defaultValues ) { if ( isBlank ( value ) ) { for ( String defaultValue : defaultValues ) { if ( hasText ( defaultValue ) ) { return defaultValue ; } } } return value ; } | Defaults the given String to the first non - blank default value if the given String is blank otherwise returns the given String . | 61 | 25 |
9,419 | @ NullSafe public static boolean equalsIgnoreCase ( String stringOne , String stringTwo ) { return stringOne != null && stringOne . equalsIgnoreCase ( stringTwo ) ; } | Determines whether two String values are equal in value ignoring case and guarding against null values . | 39 | 19 |
9,420 | public static String getDigits ( String value ) { StringBuilder digits = new StringBuilder ( value . length ( ) ) ; for ( char chr : value . toCharArray ( ) ) { if ( Character . isDigit ( chr ) ) { digits . append ( chr ) ; } } return digits . toString ( ) ; } | Extracts numbers from the String value . | 73 | 9 |
9,421 | public static String getLetters ( String value ) { StringBuilder letters = new StringBuilder ( value . length ( ) ) ; for ( char chr : value . toCharArray ( ) ) { if ( Character . isLetter ( chr ) ) { letters . append ( chr ) ; } } return letters . toString ( ) ; } | Extracts letters from the String value . | 72 | 9 |
9,422 | public static String getSpaces ( int number ) { Assert . argument ( number >= 0 , "The number [{0}] of desired spaces must be greater than equal to 0" , number ) ; StringBuilder spaces = new StringBuilder ( Math . max ( number , 0 ) ) ; while ( number > 0 ) { int count = Math . min ( SPACES . length - 1 , number ) ; spaces . append ( SPACES [ count ] ) ; number -= count ; } return spaces . toString ( ) ; } | Constructs a String with only spaces up to the specified length . | 112 | 13 |
9,423 | @ NullSafe public static int indexOf ( String text , String value ) { return text != null && value != null ? text . indexOf ( value ) : - 1 ; } | Determines the index of the first occurrence of token in the String value . This indexOf operation is null - safe and returns a - 1 if the String value is null or the token does not exist in the String value . | 37 | 46 |
9,424 | @ NullSafe public static boolean isDigits ( String value ) { for ( char chr : toCharArray ( value ) ) { if ( ! Character . isDigit ( chr ) ) { return false ; } } return hasText ( value ) ; } | Determines whether the String value represents a number i . e . consists entirely of digits . | 55 | 19 |
9,425 | @ NullSafe public static boolean isLetters ( String value ) { for ( char chr : toCharArray ( value ) ) { if ( ! Character . isLetter ( chr ) ) { return false ; } } return hasText ( value ) ; } | Determines whether the String value consists entirely of letters . | 54 | 12 |
9,426 | @ NullSafe public static int lastIndexOf ( String text , String value ) { return text != null && value != null ? text . lastIndexOf ( value ) : - 1 ; } | Determines the index of the last occurrence of token in the String value . This lastIndexOf operation is null - safe and returns a - 1 if the String value is null or the token does not exist in the String value . | 39 | 47 |
9,427 | @ NullSafe public static String pad ( String value , int length ) { return pad ( value , SINGLE_SPACE_CHAR , length ) ; } | Pads the given String with the specified number of spaces to the right . | 33 | 15 |
9,428 | @ NullSafe @ SuppressWarnings ( "all" ) public static String pad ( String value , char padding , int length ) { assertThat ( length ) . throwing ( new IllegalArgumentException ( String . format ( "[%d] must be greater than equal to 0" , length ) ) ) . isGreaterThanEqualTo ( 0 ) ; if ( length > 0 ) { StringBuilder builder = new StringBuilder ( ObjectUtils . defaultIfNull ( value , EMPTY_STRING ) ) ; while ( length - builder . length ( ) > 0 ) { builder . append ( padding ) ; } return builder . toString ( ) ; } return value ; } | Pads the given String with the specified number of characters to the right . | 144 | 15 |
9,429 | public static String singleSpaceObjects ( Object ... values ) { List < String > valueList = new ArrayList <> ( values . length ) ; for ( Object value : values ) { valueList . add ( String . valueOf ( value ) ) ; } return trim ( concat ( valueList . toArray ( new String [ valueList . size ( ) ] ) , SINGLE_SPACE ) ) ; } | Single spaces the elements in the Object array and converts all values into a String representation using Object . toString to be placed in a single String . | 88 | 29 |
9,430 | public static String singleSpaceString ( String value ) { Assert . hasText ( value , "String value must contain text" ) ; return trim ( concat ( value . split ( "\\s+" ) , SINGLE_SPACE ) ) ; } | Single spaces the tokens in the specified String value . A token is defined as any non - whitespace character . | 55 | 22 |
9,431 | @ NullSafe public static String toLowerCase ( String value ) { return value != null ? value . toLowerCase ( ) : null ; } | Converts the String value to all lower case characters . toLowerCase is a null - safe operation . | 30 | 21 |
9,432 | @ NullSafe @ SuppressWarnings ( "all" ) public static String [ ] toStringArray ( String delimitedValue , String delimiter ) { return ArrayUtils . transform ( ObjectUtils . defaultIfNull ( delimitedValue , EMPTY_STRING ) . split ( defaultIfBlank ( delimiter , COMMA_DELIMITER ) ) , StringUtils :: trim ) ; } | Tokenizes the given delimited String into an array of individually trimmed Strings . If String is blank empty or null then a 0 length String array is returned . If the String is not delimited with the specified delimiter then a String array of size 1 is returned with the given String value as the only element . | 88 | 63 |
9,433 | @ NullSafe public static String toUpperCase ( String value ) { return value != null ? value . toUpperCase ( ) : null ; } | Converts the String value to all UPPER case characters . toUpperCase is a null - safe operation . | 32 | 24 |
9,434 | @ NullSafe public static String trim ( String value ) { return value != null ? value . trim ( ) : null ; } | Trims the specified String value removing any whitespace from the beginning or end of a String . | 26 | 19 |
9,435 | @ NullSafe public static String truncate ( String value , int length ) { assertThat ( length ) . throwing ( new IllegalArgumentException ( String . format ( "[%d] must be greater than equal to 0" , length ) ) ) . isGreaterThanEqualTo ( 0 ) ; return ( value != null ? value . substring ( 0 , Math . min ( value . length ( ) , length ) ) : null ) ; } | Truncates the given String to the desired length . If the String is blank empty or null then value is returned otherwise the String is truncated to the maximum length determined by the value s length and desired length . | 95 | 43 |
9,436 | public static String wrap ( String line , int widthInCharacters , String indent ) { StringBuilder buffer = new StringBuilder ( ) ; int lineCount = 1 ; int spaceIndex ; // if indent is null, then do not indent the wrapped lines indent = ( indent != null ? indent : EMPTY_STRING ) ; while ( line . length ( ) > widthInCharacters ) { spaceIndex = line . substring ( 0 , widthInCharacters ) . lastIndexOf ( SINGLE_SPACE ) ; buffer . append ( lineCount ++ > 1 ? indent : EMPTY_STRING ) ; // throws IndexOutOfBoundsException if spaceIndex is -1, implying no word boundary was found within // the given width; this also avoids the infinite loop buffer . append ( line . substring ( 0 , spaceIndex ) ) ; buffer . append ( LINE_SEPARATOR ) ; // possible infinite loop if spaceIndex is -1, see comment above line = line . substring ( spaceIndex + 1 ) ; } buffer . append ( lineCount > 1 ? indent : EMPTY_STRING ) ; buffer . append ( line ) ; return buffer . toString ( ) ; } | Wraps a line of text to no longer than the specified width measured by the number of characters in each line indenting all subsequent lines with the indent . If the indent is null then an empty String is used . | 247 | 43 |
9,437 | public static boolean init ( Object initableObj ) { if ( initableObj instanceof Initable ) { ( ( Initable ) initableObj ) . init ( ) ; return true ; } return false ; } | Initializes an Object by calling it s init method if the Object is an instance of the Initable interface . | 44 | 22 |
9,438 | public static xen_health_monitor_fan_speed [ ] get_filtered ( nitro_service service , filtervalue [ ] filter ) throws Exception { xen_health_monitor_fan_speed obj = new xen_health_monitor_fan_speed ( ) ; options option = new options ( ) ; option . set_filter ( filter ) ; xen_health_monitor_fan_speed [ ] response = ( xen_health_monitor_fan_speed [ ] ) obj . getfiltered ( service , option ) ; return response ; } | Use this API to fetch filtered set of xen_health_monitor_fan_speed resources . set the filter parameter values in filtervalue object . | 115 | 29 |
9,439 | public static ns_vserver_appflow_config [ ] get_filtered ( nitro_service service , filtervalue [ ] filter ) throws Exception { ns_vserver_appflow_config obj = new ns_vserver_appflow_config ( ) ; options option = new options ( ) ; option . set_filter ( filter ) ; ns_vserver_appflow_config [ ] response = ( ns_vserver_appflow_config [ ] ) obj . getfiltered ( service , option ) ; return response ; } | Use this API to fetch filtered set of ns_vserver_appflow_config resources . set the filter parameter values in filtervalue object . | 115 | 29 |
9,440 | public static techsupport [ ] get_filtered ( nitro_service service , filtervalue [ ] filter ) throws Exception { techsupport obj = new techsupport ( ) ; options option = new options ( ) ; option . set_filter ( filter ) ; techsupport [ ] response = ( techsupport [ ] ) obj . getfiltered ( service , option ) ; return response ; } | Use this API to fetch filtered set of techsupport resources . set the filter parameter values in filtervalue object . | 80 | 22 |
9,441 | public static double cylinderSurfaceArea ( final double radius , final double height ) { return ( ( 2.0d * Math . PI * Math . pow ( radius , 2 ) ) + ( 2.0d * Math . PI * radius * height ) ) ; } | Calculates the surface area of a cylinder . | 56 | 10 |
9,442 | public static BigInteger factorial ( BigInteger value ) { Assert . notNull ( value , "value must not be null" ) ; Assert . isTrue ( value . compareTo ( BigInteger . ZERO ) >= 0 , String . format ( NUMBER_LESS_THAN_ZERO_ERROR_MESSAGE , value ) ) ; if ( value . compareTo ( TWO ) <= 0 ) { return ( value . equals ( TWO ) ? TWO : BigInteger . ONE ) ; } BigInteger result = value ; for ( value = result . add ( NEGATIVE_ONE ) ; value . compareTo ( BigInteger . ONE ) > 0 ; value = value . add ( NEGATIVE_ONE ) ) { result = result . multiply ( value ) ; } return result ; } | Calculates the factorial of the given number using an iterative algorithm and BigInteger value type to avoid a StackOverflowException and numeric overflow respectively . | 168 | 32 |
9,443 | public static int [ ] fibonacciSequence ( final int n ) { Assert . argument ( n > 0 , "The number of elements from the Fibonacci Sequence to calculate must be greater than equal to 0!" ) ; int [ ] fibonacciNumbers = new int [ n ] ; for ( int position = 0 ; position < n ; position ++ ) { if ( position == 0 ) { fibonacciNumbers [ position ] = 0 ; } else if ( position < 2 ) { fibonacciNumbers [ position ] = 1 ; } else { fibonacciNumbers [ position ] = ( fibonacciNumbers [ position - 1 ] + fibonacciNumbers [ position - 2 ] ) ; } } return fibonacciNumbers ; } | Calculates the Fibonacci Sequence to the nth position . | 155 | 14 |
9,444 | @ NullSafe public static double max ( final double ... values ) { double maxValue = Double . NaN ; if ( values != null ) { for ( double value : values ) { maxValue = ( Double . isNaN ( maxValue ) ? value : Math . max ( maxValue , value ) ) ; } } return maxValue ; } | Determines the maximum numerical value in an array of values . | 72 | 13 |
9,445 | @ NullSafe public static double min ( final double ... values ) { double minValue = Double . NaN ; if ( values != null ) { for ( double value : values ) { minValue = ( Double . isNaN ( minValue ) ? value : Math . min ( minValue , value ) ) ; } } return minValue ; } | Determines the minimum numerical value in an array of values . | 72 | 13 |
9,446 | @ NullSafe public static int multiply ( final int ... numbers ) { int result = 0 ; if ( numbers != null ) { result = ( numbers . length > 0 ? 1 : 0 ) ; for ( int number : numbers ) { result *= number ; } } return result ; } | Multiplies the array of numbers . | 59 | 8 |
9,447 | public static double rectangularPrismSurfaceArea ( final double length , final double height , final double width ) { return ( ( 2 * length * height ) + ( 2 * length * width ) + ( 2 * height * width ) ) ; } | Calculates the surface area of a rectangular prism ; | 51 | 11 |
9,448 | @ NullSafe public static int sum ( final int ... numbers ) { int sum = 0 ; if ( numbers != null ) { for ( int number : numbers ) { sum += number ; } } return sum ; } | Calculates the sum of all integer values in the array . | 44 | 13 |
9,449 | public static mps get ( nitro_service client ) throws Exception { mps resource = new mps ( ) ; resource . validate ( "get" ) ; return ( ( mps [ ] ) resource . get_resources ( client ) ) [ 0 ] ; } | Use this operation to get Management Service Information . | 56 | 9 |
9,450 | public static Serializable copy ( Serializable obj ) { try { ByteArrayOutputStream buf = new ByteArrayOutputStream ( 4096 ) ; ObjectOutputStream out = new ObjectOutputStream ( buf ) ; out . writeObject ( obj ) ; out . close ( ) ; ByteArrayInputStream buf2 = new ByteArrayInputStream ( buf . toByteArray ( ) ) ; ObjectInputStream in = new ObjectInputStream ( buf2 ) ; Serializable obj2 = ( Serializable ) in . readObject ( ) ; in . close ( ) ; return obj2 ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( e ) ; } } | Makes a deep - copy clone of an object . | 153 | 11 |
9,451 | public static < T > Constructor < T > getConstructor ( Class < T > cls , Class ... params ) { try { return cls . getConstructor ( params ) ; } catch ( Exception e ) { throw new ClientException ( e ) ; } } | Finds a constructor and hides all checked exceptions . | 56 | 10 |
9,452 | public static < T > T newInstance ( Constructor < T > constructor , Object ... args ) { try { return constructor . newInstance ( args ) ; } catch ( Exception e ) { throw new ClientException ( e ) ; } } | Invokes a constructor and hides all checked exceptions . | 49 | 10 |
9,453 | private static < T > @ NonNull List < T > topologicalSort ( final @ NonNull Graph < T > graph , final @ NonNull SortType < T > type ) { checkArgument ( graph . isDirected ( ) , "the graph must be directed" ) ; checkArgument ( ! graph . allowsSelfLoops ( ) , "the graph cannot allow self loops" ) ; final Map < T , Integer > requiredCounts = new HashMap <> ( ) ; for ( final T node : graph . nodes ( ) ) { for ( final T successor : graph . successors ( node ) ) { requiredCounts . merge ( successor , 1 , ( a , b ) -> a + b ) ; } } final Queue < T > processing = type . createQueue ( ) ; final List < T > results = new ArrayList <> ( ) ; for ( final T node : graph . nodes ( ) ) { if ( ! requiredCounts . containsKey ( node ) ) { processing . add ( node ) ; } } while ( ! processing . isEmpty ( ) ) { final T now = processing . poll ( ) ; for ( final T successor : graph . successors ( now ) ) { final int newCount = requiredCounts . get ( successor ) - 1 ; if ( newCount == 0 ) { processing . add ( successor ) ; requiredCounts . remove ( successor ) ; } else { requiredCounts . put ( successor , newCount ) ; } } results . add ( now ) ; } if ( ! requiredCounts . isEmpty ( ) ) { final StronglyConnectedComponentAnalyzer < T > analyzer = new StronglyConnectedComponentAnalyzer <> ( graph ) ; analyzer . analyze ( ) ; throw new CyclePresentException ( "Graph (" + graph + ") has cycle(s): " + analyzer . renderCycles ( ) , analyzer . components ( ) ) ; } return results ; } | Actual content of the topological sort . This is a breadth - first search based approach . | 409 | 19 |
9,454 | private < I extends Message , O extends Message > void invoke ( ServerMethod < I , O > method , ByteString payload , long requestId , Channel channel ) { FutureCallback < O > callback = new ServerMethodCallback <> ( method , requestId , channel ) ; try { I request = method . inputParser ( ) . parseFrom ( payload ) ; ListenableFuture < O > result = method . invoke ( request ) ; pendingRequests . put ( requestId , result ) ; Futures . addCallback ( result , callback , responseCallbackExecutor ) ; } catch ( InvalidProtocolBufferException ipbe ) { callback . onFailure ( ipbe ) ; } } | Performs a single method invocation . | 140 | 7 |
9,455 | public String getPreferenceValue ( String key , String defaultValue ) { if ( userCFProperties . containsKey ( key ) ) return userCFProperties . getProperty ( key ) ; else if ( userHomeCFProperties . containsKey ( key ) ) return userHomeCFProperties . getProperty ( key ) ; else if ( systemCFProperties . containsKey ( key ) ) return systemCFProperties . getProperty ( key ) ; else if ( defaultProperties . containsKey ( key ) ) return defaultProperties . getProperty ( key ) ; else return defaultValue ; } | check java preferences for the requested key - then checks the various default properties files . | 124 | 16 |
9,456 | public static xen_health_monitor_temp [ ] get_filtered ( nitro_service service , filtervalue [ ] filter ) throws Exception { xen_health_monitor_temp obj = new xen_health_monitor_temp ( ) ; options option = new options ( ) ; option . set_filter ( filter ) ; xen_health_monitor_temp [ ] response = ( xen_health_monitor_temp [ ] ) obj . getfiltered ( service , option ) ; return response ; } | Use this API to fetch filtered set of xen_health_monitor_temp resources . set the filter parameter values in filtervalue object . | 105 | 27 |
9,457 | public static < L , R > @ NonNull Pair < L , R > left ( final @ Nullable L left ) { return of ( left , null ) ; } | Creates a new pair with a left value . | 35 | 10 |
9,458 | public static < L , R > @ NonNull Pair < L , R > right ( final @ Nullable R right ) { return of ( null , right ) ; } | Creates a new pair with a right value . | 35 | 10 |
9,459 | public static < L , R > @ NonNull Pair < L , R > of ( final Map . Entry < L , R > entry ) { return of ( entry . getKey ( ) , entry . getValue ( ) ) ; } | Creates a new pair from a map entry . | 49 | 10 |
9,460 | public static < L , R > @ NonNull Pair < L , R > of ( final @ Nullable L left , final @ Nullable R right ) { return new Pair <> ( left , right ) ; } | Creates a new pair . | 45 | 6 |
9,461 | public < NL , NR > @ NonNull Pair < NL , NR > map ( final @ NonNull Function < ? super L , ? extends NL > left , final @ NonNull Function < ? super R , ? extends NR > right ) { return new Pair <> ( left . apply ( this . left ) , right . apply ( this . right ) ) ; } | Map the left and right value of this pair . | 76 | 10 |
9,462 | public < NL > @ NonNull Pair < NL , R > lmap ( final @ NonNull Function < ? super L , ? extends NL > function ) { return new Pair <> ( function . apply ( this . left ) , this . right ) ; } | Map the left value of this pair . | 54 | 8 |
9,463 | public < NR > @ NonNull Pair < L , NR > rmap ( final @ NonNull Function < ? super R , ? extends NR > function ) { return new Pair <> ( this . left , function . apply ( this . right ) ) ; } | Map the right value of this pair . | 54 | 8 |
9,464 | public static String defaultURL ( String driver ) { assert Driver . exists ( driver ) ; String home = "" ; try { home = VictimsConfig . home ( ) . toString ( ) ; } catch ( VictimsException e ) { // Ignore and use cwd } return Driver . url ( driver , FilenameUtils . concat ( home , "victims" ) ) ; } | Get the default url for a preconfigured driver . | 79 | 11 |
9,465 | public static xen_brvpx_image get ( nitro_service client , xen_brvpx_image resource ) throws Exception { resource . validate ( "get" ) ; return ( ( xen_brvpx_image [ ] ) resource . get_resources ( client ) ) [ 0 ] ; } | Use this operation to get Repeater XVA file . | 65 | 11 |
9,466 | protected base_resource [ ] get_resources ( nitro_service service , options option ) throws Exception { if ( ! service . isLogin ( ) ) service . login ( ) ; String response = _get ( service , option ) ; return get_nitro_response ( service , response ) ; } | Use this method to perform a get operation on MPS resource . | 63 | 13 |
9,467 | public base_resource [ ] perform_operation ( nitro_service service ) throws Exception { if ( ! service . isLogin ( ) && ! get_object_type ( ) . equals ( "login" ) ) service . login ( ) ; return post_request ( service , null ) ; } | Use this method to perform a any post operation ... etc operation on MPS resource . | 62 | 17 |
9,468 | protected base_resource [ ] add_resource ( nitro_service service , options option ) throws Exception { if ( ! service . isLogin ( ) && ! get_object_type ( ) . equals ( "login" ) ) service . login ( ) ; String request = resource_to_string ( service , option ) ; return post_data ( service , request ) ; } | Use this method to perform a add operation on MPS resource . | 79 | 13 |
9,469 | protected base_resource [ ] update_resource ( nitro_service service , options option ) throws Exception { if ( ! service . isLogin ( ) && ! get_object_type ( ) . equals ( "login" ) ) service . login ( ) ; String request = resource_to_string ( service , option ) ; return put_data ( service , request ) ; } | Use this method to perform a modify operation on MPS resource . | 79 | 13 |
9,470 | protected base_resource [ ] delete_resource ( nitro_service service ) throws Exception { if ( ! service . isLogin ( ) ) service . login ( ) ; String str = nitro_util . object_to_string_withoutquotes ( this ) ; String response = _delete ( service , str ) ; return get_nitro_response ( service , response ) ; } | Use this method to perform a delete operation on MPS resource . | 81 | 13 |
9,471 | private String _delete ( nitro_service service , String req_args ) throws Exception { StringBuilder responseStr = new StringBuilder ( ) ; HttpURLConnection httpURLConnection = null ; try { String urlstr ; String ipaddress = service . get_ipaddress ( ) ; String version = service . get_version ( ) ; String sessionid = service . get_sessionid ( ) ; String objtype = get_object_type ( ) ; String protocol = service . get_protocol ( ) ; // build URL urlstr = protocol + "://" + ipaddress + "/nitro/" + version + "/config/" + objtype ; String name = this . get_object_id ( ) ; if ( name != null && name . length ( ) > 0 ) { urlstr = urlstr + "/" + nitro_util . encode ( nitro_util . encode ( name ) ) ; } /*if(req_args != null && req_args.length() > 0) { urlstr = urlstr + "?args=" + req_args; }*/ URL url = new URL ( urlstr ) ; httpURLConnection = ( HttpURLConnection ) url . openConnection ( ) ; httpURLConnection . setRequestMethod ( "DELETE" ) ; if ( sessionid != null ) { httpURLConnection . setRequestProperty ( "Cookie" , "SESSID=" + nitro_util . encode ( sessionid ) ) ; httpURLConnection . setRequestProperty ( "Accept-Encoding" , "gzip, deflate" ) ; } if ( httpURLConnection instanceof HttpsURLConnection ) { SSLContext sslContext = SSLContext . getInstance ( "SSL" ) ; //we are using an empty trust manager, because MPS currently presents //a test certificate not issued by any signing authority, so we need to bypass //the credentials check sslContext . init ( null , new TrustManager [ ] { new EmptyTrustManager ( ) } , null ) ; SocketFactory sslSocketFactory = sslContext . getSocketFactory ( ) ; HttpsURLConnection secured = ( HttpsURLConnection ) httpURLConnection ; secured . setSSLSocketFactory ( ( SSLSocketFactory ) sslSocketFactory ) ; secured . setHostnameVerifier ( new EmptyHostnameVerifier ( ) ) ; } InputStream input = httpURLConnection . getInputStream ( ) ; String contentEncoding = httpURLConnection . getContentEncoding ( ) ; // get correct input stream for compressed data: if ( contentEncoding != null ) { if ( contentEncoding . equalsIgnoreCase ( "gzip" ) ) input = new GZIPInputStream ( input ) ; //reads 2 bytes to determine GZIP stream! else if ( contentEncoding . equalsIgnoreCase ( "deflate" ) ) input = new InflaterInputStream ( input ) ; } int numOfTotalBytesRead ; byte [ ] buffer = new byte [ 1024 ] ; while ( ( numOfTotalBytesRead = input . read ( buffer , 0 , buffer . length ) ) != - 1 ) { responseStr . append ( new String ( buffer , 0 , numOfTotalBytesRead ) ) ; } httpURLConnection . disconnect ( ) ; input . close ( ) ; } catch ( MalformedURLException mue ) { System . err . println ( "Invalid URL" ) ; } catch ( IOException ioe ) { System . err . println ( "I/O Error - " + ioe ) ; } catch ( Exception e ) { System . err . println ( "Error - " + e ) ; } return responseStr . toString ( ) ; } | This method forms the http DELETE request applies on the MPS . Reads the response from the MPS and converts it to base response . | 781 | 30 |
9,472 | protected static base_resource [ ] update_bulk_request ( nitro_service service , base_resource resources [ ] ) throws Exception { if ( ! service . isLogin ( ) ) service . login ( ) ; String objtype = resources [ 0 ] . get_object_type ( ) ; String onerror = service . get_onerror ( ) ; //String id = service.get_sessionid(); String request = service . get_payload_formatter ( ) . resource_to_string ( resources , null , onerror ) ; String result = put_bulk_data ( service , request , objtype ) ; if ( resources . length == 1 ) return resources [ 0 ] . get_nitro_response ( service , result ) ; return resources [ 0 ] . get_nitro_bulk_response ( service , result ) ; } | Use this method to perform a modify operation on multiple MPS resources . | 182 | 14 |
9,473 | public void uninstallBundle ( final String symbolicName , final String version ) { Bundle bundle = bundleDeployerService . getExistingBundleBySymbolicName ( symbolicName , version , null ) ; if ( bundle != null ) { stateChanged = true ; Logger . info ( "Uninstalling bundle: " + bundle ) ; BundleStartLevel bundleStartLevel = bundle . adapt ( BundleStartLevel . class ) ; if ( bundleStartLevel . getStartLevel ( ) < currentFrameworkStartLevelValue ) { setFrameworkStartLevel ( bundleStartLevel . getStartLevel ( ) ) ; } try { bundle . uninstall ( ) ; } catch ( BundleException e ) { Logger . error ( "Error during uninstalling bundle: " + bundle . toString ( ) , e ) ; } } } | Uninstalling an existing bundle | 171 | 6 |
9,474 | public void setResponse ( Envelope response ) { if ( response . hasControl ( ) && response . getControl ( ) . hasError ( ) ) { setException ( new Exception ( response . getControl ( ) . getError ( ) ) ) ; return ; } try { set ( clientMethod . outputParser ( ) . parseFrom ( response . getPayload ( ) ) ) ; clientLogger . logSuccess ( clientMethod ) ; } catch ( InvalidProtocolBufferException ipbe ) { setException ( ipbe ) ; } } | Sets the response envelope of this promise . | 113 | 9 |
9,475 | public static host_interface reset ( nitro_service client , host_interface resource ) throws Exception { return ( ( host_interface [ ] ) resource . perform_operation ( client , "reset" ) ) [ 0 ] ; } | Use this operation to reset interface settings . | 48 | 8 |
9,476 | public static Collection < String > getTagNames ( Channel channel ) { Collection < String > tagNames = new HashSet < String > ( ) ; for ( Tag tag : channel . getTags ( ) ) { tagNames . add ( tag . getName ( ) ) ; } return tagNames ; } | Return a list of tag names associated with this channel | 62 | 10 |
9,477 | public static Collection < String > getAllTagNames ( Collection < Channel > channels ) { Collection < String > tagNames = new HashSet < String > ( ) ; for ( Channel channel : channels ) { tagNames . addAll ( getTagNames ( channel ) ) ; } return tagNames ; } | Return a union of tag names associated with channels | 62 | 9 |
9,478 | public static Collection < String > getPropertyNames ( Channel channel ) { Collection < String > propertyNames = new HashSet < String > ( ) ; for ( Property property : channel . getProperties ( ) ) { if ( property . getValue ( ) != null ) propertyNames . add ( property . getName ( ) ) ; } return propertyNames ; } | Return a list of property names associated with this channel | 74 | 10 |
9,479 | @ Deprecated public static Tag getTag ( Channel channel , String tagName ) { Collection < Tag > tag = Collections2 . filter ( channel . getTags ( ) , new TagNamePredicate ( tagName ) ) ; if ( tag . size ( ) == 1 ) return tag . iterator ( ) . next ( ) ; else return null ; } | Deprecated - use channel . getTag instead | 72 | 9 |
9,480 | @ Deprecated public static Property getProperty ( Channel channel , String propertyName ) { Collection < Property > property = Collections2 . filter ( channel . getProperties ( ) , new PropertyNamePredicate ( propertyName ) ) ; if ( property . size ( ) == 1 ) return property . iterator ( ) . next ( ) ; else return null ; } | deprecated - use the channel . getProperty instead | 73 | 10 |
9,481 | public static Collection < String > getPropertyNames ( Collection < Channel > channels ) { Collection < String > propertyNames = new HashSet < String > ( ) ; for ( Channel channel : channels ) { propertyNames . addAll ( getPropertyNames ( channel ) ) ; } return propertyNames ; } | Return a union of property names associated with channels | 61 | 9 |
9,482 | public static Collection < String > getChannelNames ( Collection < Channel > channels ) { Collection < String > channelNames = new HashSet < String > ( ) ; for ( Channel channel : channels ) { channelNames . add ( channel . getName ( ) ) ; } return channelNames ; } | Returns all the channel Names in the given Collection of channels | 60 | 11 |
9,483 | public static sdx_network_config get ( nitro_service client ) throws Exception { sdx_network_config resource = new sdx_network_config ( ) ; resource . validate ( "get" ) ; return ( ( sdx_network_config [ ] ) resource . get_resources ( client ) ) [ 0 ] ; } | Use this operation to get SDX network configuration . | 72 | 10 |
9,484 | protected HashSet < String > getVulnerabilities ( int recordId ) throws SQLException { HashSet < String > cves = new HashSet < String > ( ) ; Connection connection = getConnection ( ) ; try { PreparedStatement ps = setObjects ( connection , Query . FIND_CVES , recordId ) ; ResultSet matches = ps . executeQuery ( ) ; while ( matches . next ( ) ) { cves . add ( matches . getString ( 1 ) ) ; } matches . close ( ) ; } finally { connection . close ( ) ; } return cves ; } | Returns CVEs that are ascociated with a given record id . | 127 | 13 |
9,485 | protected HashSet < Integer > getEmbeddedRecords ( Set < String > hashes ) throws SQLException { HashSet < Integer > results = new HashSet < Integer > ( ) ; Connection connection = getConnection ( ) ; PreparedStatement ps = setObjects ( connection , Query . FILEHASH_EMBEDDED_MATCH , ( Object ) hashes . toArray ( ) ) ; try { ResultSet resultSet = ps . executeQuery ( ) ; while ( resultSet . next ( ) ) { results . add ( resultSet . getInt ( "record" ) ) ; } resultSet . close ( ) ; } finally { connection . close ( ) ; } return results ; } | Fetch record id s from the local database that is composed entirely of hashes in the set of hashes provided . | 147 | 22 |
9,486 | public synchronized void connect ( ) { if ( state != State . NONE ) { eventHandler . onError ( new WebSocketException ( "connect() already called" ) ) ; close ( ) ; return ; } getIntializer ( ) . setName ( getInnerThread ( ) , THREAD_BASE_NAME + "Reader-" + clientId ) ; state = State . CONNECTING ; getInnerThread ( ) . start ( ) ; } | Start up the socket . This is non - blocking it will fire up the threads used by the library and then trigger the onOpen handler once the connection is established . | 97 | 33 |
9,487 | public synchronized void close ( ) { switch ( state ) { case NONE : state = State . DISCONNECTED ; return ; case CONNECTING : // don't wait for an established connection, just close the tcp socket closeSocket ( ) ; return ; case CONNECTED : // This method also shuts down the writer // the socket will be closed once the ack for the close was received sendCloseHandshake ( true ) ; return ; case DISCONNECTING : return ; // no-op; case DISCONNECTED : return ; // No-op } } | Close down the socket . Will trigger the onClose handler if the socket has not been previously closed . | 118 | 20 |
9,488 | public void blockClose ( ) throws InterruptedException { // If the thread is new, it will never run, since we closed the connection before we actually connected if ( writer . getInnerThread ( ) . getState ( ) != Thread . State . NEW ) { writer . getInnerThread ( ) . join ( ) ; } getInnerThread ( ) . join ( ) ; } | Blocks until both threads exit . The actual close must be triggered separately . This is just a convenience method to make sure everything shuts down if desired . | 81 | 29 |
9,489 | public static ns_image [ ] get_filtered ( nitro_service service , filtervalue [ ] filter ) throws Exception { ns_image obj = new ns_image ( ) ; options option = new options ( ) ; option . set_filter ( filter ) ; ns_image [ ] response = ( ns_image [ ] ) obj . getfiltered ( service , option ) ; return response ; } | Use this API to fetch filtered set of ns_image resources . set the filter parameter values in filtervalue object . | 85 | 23 |
9,490 | public static xen_health_resource [ ] get_filtered ( nitro_service service , filtervalue [ ] filter ) throws Exception { xen_health_resource obj = new xen_health_resource ( ) ; options option = new options ( ) ; option . set_filter ( filter ) ; xen_health_resource [ ] response = ( xen_health_resource [ ] ) obj . getfiltered ( service , option ) ; return response ; } | Use this API to fetch filtered set of xen_health_resource resources . set the filter parameter values in filtervalue object . | 95 | 25 |
9,491 | protected < T > T convert ( final String value , final Class < T > type ) { Assert . notNull ( type , "The Class type to convert the String value to cannot be null!" ) ; if ( getConversionService ( ) . canConvert ( String . class , type ) ) { return getConversionService ( ) . convert ( value , type ) ; } throw new ConversionException ( String . format ( "Cannot convert String value (%1$s) into a value of type (%2$s)!" , value , type . getName ( ) ) ) ; } | Converts the configuration setting property value into a value of the specified type . | 124 | 15 |
9,492 | protected String defaultIfUnset ( final String value , final String defaultValue ) { return ( StringUtils . hasText ( value ) ? value : defaultValue ) ; } | Returns value if not blank otherwise returns default value . | 36 | 10 |
9,493 | public boolean isPresent ( final String propertyName ) { for ( String configurationPropertyName : this ) { if ( configurationPropertyName . equals ( propertyName ) ) { return true ; } } return false ; } | Determines whether the configuration property identified by name is present in the configuration settings which means the configuration property was declared but not necessarily defined . | 43 | 28 |
9,494 | public String getPropertyValue ( final String propertyName , final boolean required ) { String propertyValue = doGetPropertyValue ( propertyName ) ; if ( StringUtils . isBlank ( propertyValue ) && getParent ( ) != null ) { propertyValue = getParent ( ) . getPropertyValue ( propertyName , required ) ; } if ( StringUtils . isBlank ( propertyValue ) && required ) { throw new ConfigurationException ( String . format ( "The property (%1$s) is required!" , propertyName ) ) ; } return defaultIfUnset ( propertyValue , null ) ; } | Gets the value of the configuration property identified by name . The required parameter can be used to indicate the property is not required and that a ConfigurationException should not be thrown if the property is undeclared or undefined . | 127 | 44 |
9,495 | public String getPropertyValue ( final String propertyName , final String defaultPropertyValue ) { return defaultIfUnset ( getPropertyValue ( propertyName , NOT_REQUIRED ) , defaultPropertyValue ) ; } | Gets the value of the configuration property identified by name . The defaultPropertyValue parameter effectively overrides the required attribute indicating that the property is not required to be declared or defined . | 44 | 36 |
9,496 | public < T > T getPropertyValueAs ( final String propertyName , final Class < T > type ) { return convert ( getPropertyValue ( propertyName , DEFAULT_REQUIRED ) , type ) ; } | Gets the value of the configuration property identified by name as a value of the specified Class type . The property is required to be declared and defined otherwise a ConfigurationException is thrown . | 45 | 36 |
9,497 | public < T > T getPropertyValueAs ( final String propertyName , final boolean required , final Class < T > type ) { try { return convert ( getPropertyValue ( propertyName , required ) , type ) ; } catch ( ConversionException e ) { if ( required ) { throw new ConfigurationException ( String . format ( "Failed to get the value of configuration setting property (%1$s) as type (%2$s)!" , propertyName , ClassUtils . getName ( type ) ) , e ) ; } return null ; } } | Gets the value of the configuration property identified by name as a value of the specified Class type . The required parameter can be used to indicate the property is not required and that a ConfigurationException should not be thrown if the property is undeclared or undefined . | 115 | 52 |
9,498 | @ SuppressWarnings ( "unchecked" ) public < T > T getPropertyValueAs ( final String propertyName , final T defaultPropertyValue , final Class < T > type ) { try { return ObjectUtils . defaultIfNull ( convert ( getPropertyValue ( propertyName , NOT_REQUIRED ) , type ) , defaultPropertyValue ) ; } catch ( ConversionException ignore ) { return defaultPropertyValue ; } } | Gets the value of the configuration property identified by name as a value of the specified Class type . The defaultPropertyValue parameter effectively overrides the required attribute indicating that the property is not required to be declared or defined . | 91 | 44 |
9,499 | @ SuppressWarnings ( "unchecked" ) public static < T extends Sorter > T createSorter ( final SortType type ) { switch ( ObjectUtils . defaultIfNull ( type , SortType . UNKONWN ) ) { case BUBBLE_SORT : return ( T ) new BubbleSort ( ) ; case COMB_SORT : return ( T ) new CombSort ( ) ; case HEAP_SORT : return ( T ) new HeapSort ( ) ; case INSERTION_SORT : return ( T ) new InsertionSort ( ) ; case MERGE_SORT : return ( T ) new MergeSort ( ) ; case QUICK_SORT : return ( T ) new QuickSort ( ) ; case SELECTION_SORT : return ( T ) new SelectionSort ( ) ; case SHELL_SORT : return ( T ) new ShellSort ( ) ; default : throw new IllegalArgumentException ( String . format ( "The SortType (%1$s) is not supported by the %2$s!" , type , SorterFactory . class . getSimpleName ( ) ) ) ; } } | Creates an instance of the Sorter interface implementing the sorting algorithm based on the SortType . | 244 | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.