idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
9,400 | public String resource_to_string ( base_resource resrc , options option ) { String result = "{ " ; if ( option != null && option . get_action ( ) != null ) result = result + "\"params\": {\"action\":\"" + option . get_action ( ) + "\"}," ; result = result + "\"" + resrc . get_object_type ( ) + "\":" + this . resource_to_string ( resrc ) + "}" ; return result ; } | Converts NetScaler SDX resource to Json string . |
9,401 | public String resource_to_string ( base_resource resources [ ] , options option ) { String objecttype = resources [ 0 ] . get_object_type ( ) ; String request = "{" ; if ( option != null && option . get_action ( ) != null ) request = request + "\"params\": {\"action\": \"" + option . get_action ( ) + "\"}," ; request = request + "\"" + objecttype + "\":[" ; for ( int i = 0 ; i < resources . length ; i ++ ) { String str = this . resource_to_string ( resources [ i ] ) ; request = request + str + "," ; } request = request + "]}" ; return request ; } | Converts NetScaler SDX resources to Json string . |
9,402 | public String resource_to_string ( base_resource resources [ ] , options option , String onerror ) { String objecttype = resources [ 0 ] . get_object_type ( ) ; String request = "{" ; if ( ( option != null && option . get_action ( ) != null ) || ( ! onerror . equals ( "" ) ) ) { request = request + "\"params\":{" ; if ( option != null ) { if ( option . get_action ( ) != null ) { request = request + "\"action\":\"" + option . get_action ( ) + "\"," ; } } if ( ( ! onerror . equals ( "" ) ) ) { request = request + "\"onerror\":\"" + onerror + "\"" ; } request = request + "}," ; } request = request + "\"" + objecttype + "\":[" ; for ( int i = 0 ; i < resources . length ; i ++ ) { String str = this . resource_to_string ( resources [ i ] ) ; request = request + str + "," ; } request = request + "]}" ; return request ; } | Converts MPS resources to Json string . |
9,403 | public static Class < ? > getClass ( Object obj ) { return obj != null ? obj . getClass ( ) : null ; } | Get the Class type of the specified Object . Returns null if the Object reference is null . |
9,404 | public static String getClassSimpleName ( Object obj ) { return obj != null ? obj . getClass ( ) . getSimpleName ( ) : null ; } | Gets the unqualified simple name of the Class type for the specified Object . Returns null if the Object reference is null . |
9,405 | @ SuppressWarnings ( { "unchecked" , "all" } ) public static < T > Constructor < T > findConstructor ( Class < T > type , Object ... arguments ) { for ( Constructor < ? > constructor : type . getDeclaredConstructors ( ) ) { Class < ? > [ ] parameterTypes = constructor . getParameterTypes ( ) ; if ( ArrayUtils . nullSafeLength ( arguments ) == parameterTypes . length ) { boolean match = true ; for ( int index = 0 ; match && index < parameterTypes . length ; index ++ ) { match &= instanceOf ( arguments [ index ] , parameterTypes [ index ] ) ; } if ( match ) { return ( Constructor < T > ) constructor ; } } } return null ; } | Attempts to find a compatible constructor on the given class type with a signature having parameter types satisfying the specified arguments . |
9,406 | public static < T > Constructor < T > getConstructor ( Class < T > type , Class < ? > ... parameterTypes ) { try { return type . getDeclaredConstructor ( parameterTypes ) ; } catch ( NoSuchMethodException cause ) { throw new ConstructorNotFoundException ( cause ) ; } } | Gets the constructor with the specified signature from the given class type . |
9,407 | public static < T > Constructor < T > resolveConstructor ( Class < T > type , Class < ? > [ ] parameterTypes , Object ... arguments ) { try { return getConstructor ( type , parameterTypes ) ; } catch ( ConstructorNotFoundException cause ) { Constructor < T > constructor = findConstructor ( type , arguments ) ; Assert . notNull ( constructor , new ConstructorNotFoundException ( String . format ( "Failed to resolve constructor with signature [%1$s] on class type [%2$s]" , getMethodSignature ( getSimpleName ( type ) , parameterTypes , Void . class ) , getName ( type ) ) , cause . getCause ( ) ) ) ; return constructor ; } } | Attempts to resolve the constructor from the given class type based on the constructor s exact signature otherwise finds a constructor who s signature parameter types satisfy the array of Object arguments . |
9,408 | public static Field getField ( Class < ? > type , String fieldName ) { try { return type . getDeclaredField ( fieldName ) ; } catch ( NoSuchFieldException cause ) { if ( type . getSuperclass ( ) != null ) { return getField ( type . getSuperclass ( ) , fieldName ) ; } throw new FieldNotFoundException ( cause ) ; } } | Gets a Field object representing the named field on the specified class . This method will recursively search up the class hierarchy of the specified class until the Object class is reached . If the named field is found then a Field object representing the class field is returned otherwise a NoSuchFieldException is thrown . |
9,409 | @ SuppressWarnings ( "all" ) public static Method findMethod ( Class < ? > type , String methodName , Object ... arguments ) { for ( Method method : type . getDeclaredMethods ( ) ) { if ( method . getName ( ) . equals ( methodName ) ) { Class < ? > [ ] parameterTypes = method . getParameterTypes ( ) ; if ( ArrayUtils . nullSafeLength ( arguments ) == parameterTypes . length ) { boolean match = true ; for ( int index = 0 ; match && index < parameterTypes . length ; index ++ ) { match &= instanceOf ( arguments [ index ] , parameterTypes [ index ] ) ; } if ( match ) { return method ; } } } } return ( type . getSuperclass ( ) != null ? findMethod ( type . getSuperclass ( ) , methodName , arguments ) : null ) ; } | Attempts to find a method with the specified name on the given class type having a signature with parameter types that are compatible with the given arguments . This method searches recursively up the inherited class hierarchy for the given class type until the desired method is found or the class type hierarchy is exhausted in which case null is returned . |
9,410 | public static Method getMethod ( Class < ? > type , String methodName , Class < ? > ... parameterTypes ) { try { return type . getDeclaredMethod ( methodName , parameterTypes ) ; } catch ( NoSuchMethodException cause ) { if ( type . getSuperclass ( ) != null ) { return getMethod ( type . getSuperclass ( ) , methodName , parameterTypes ) ; } throw new MethodNotFoundException ( cause ) ; } } | Gets a Method object representing the named method on the specified class . This method will recursively search up the class hierarchy of the specified class until the Object class is reached . If the named method is found then a Method object representing the class method is returned otherwise a NoSuchMethodException is thrown . |
9,411 | public static Method resolveMethod ( Class < ? > type , String methodName , Class < ? > [ ] parameterTypes , Object [ ] arguments , Class < ? > returnType ) { try { return getMethod ( type , methodName , parameterTypes ) ; } catch ( MethodNotFoundException cause ) { Method method = findMethod ( type , methodName , arguments ) ; Assert . notNull ( method , new MethodNotFoundException ( String . format ( "Failed to resolve method with signature [%1$s] on class type [%2$s]" , getMethodSignature ( methodName , parameterTypes , returnType ) , getName ( type ) ) , cause . getCause ( ) ) ) ; return method ; } } | Attempts to resolve the method with the specified name and signature on the given class type . The named method s resolution is first attempted by using the specified method s name along with the array of parameter types . If unsuccessful the method proceeds to lookup the named method by searching all declared methods of the class type having a signature compatible with the given argument types . This method operates recursively until the method is resolved or the class type hierarchy is exhausted in which case a MethodNotFoundException is thrown . |
9,412 | protected static String getMethodSignature ( Method method ) { return getMethodSignature ( method . getName ( ) , method . getParameterTypes ( ) , method . getReturnType ( ) ) ; } | Builds the signature of a method based on a java . lang . reflect . Method object . |
9,413 | protected static String getMethodSignature ( String methodName , Class < ? > [ ] parameterTypes , Class < ? > returnType ) { StringBuilder buffer = new StringBuilder ( methodName ) ; buffer . append ( "(" ) ; if ( parameterTypes != null ) { int index = 0 ; for ( Class < ? > parameterType : parameterTypes ) { buffer . append ( index ++ > 0 ? ", :" : ":" ) ; buffer . append ( getSimpleName ( parameterType ) ) ; } } buffer . append ( "):" ) ; buffer . append ( returnType == null || Void . class . equals ( returnType ) ? "void" : getSimpleName ( returnType ) ) ; return buffer . toString ( ) ; } | Builds the signature of a method based on the method s name parameter types and return type . |
9,414 | public static String getName ( Class type ) { return type != null ? type . getName ( ) : null ; } | Gets the fully - qualified name of the Class . |
9,415 | public static String getSimpleName ( Class type ) { return type != null ? type . getSimpleName ( ) : null ; } | Gets the simple name of the Class . |
9,416 | public static boolean instanceOf ( Object obj , Class < ? > type ) { return type != null && type . isInstance ( obj ) ; } | Determines whether the given Object is an instance of the specified Class . Note an Object cannot be an instance of null so this method returns false if the Class type is null or the Object is null . |
9,417 | 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 . |
9,418 | 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 . |
9,419 | 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 . |
9,420 | @ 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 . |
9,421 | 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 |
9,422 | 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 |
9,423 | 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 |
9,424 | 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 |
9,425 | 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 |
9,426 | 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 . |
9,427 | 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 . |
9,428 | 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 |
9,429 | < 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 . |
9,430 | 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 . |
9,431 | 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 . |
9,432 | 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 . |
9,433 | 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 . |
9,434 | 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 . |
9,435 | 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 . |
9,436 | 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 . |
9,437 | 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 . |
9,438 | 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 . |
9,439 | 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 . |
9,440 | 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 . |
9,441 | 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 . |
9,442 | 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 . |
9,443 | 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 . |
9,444 | 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 . |
9,445 | @ 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 . |
9,446 | 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 . |
9,447 | 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 . |
9,448 | 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 . |
9,449 | @ 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 . |
9,450 | 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 . |
9,451 | 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 . |
9,452 | 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 . |
9,453 | public static String wrap ( String line , int widthInCharacters , String indent ) { StringBuilder buffer = new StringBuilder ( ) ; int lineCount = 1 ; int spaceIndex ; 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 ) ; buffer . append ( line . substring ( 0 , spaceIndex ) ) ; buffer . append ( LINE_SEPARATOR ) ; 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 . |
9,454 | 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 . |
9,455 | 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 . |
9,456 | 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 . |
9,457 | 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 . |
9,458 | 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 . |
9,459 | 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 . |
9,460 | 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 . |
9,461 | 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 . |
9,462 | 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 . |
9,463 | 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 . |
9,464 | 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 ; |
9,465 | 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 . |
9,466 | 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 . |
9,467 | 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 . |
9,468 | 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 . |
9,469 | 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 . |
9,470 | private static < T > List < T > topologicalSort ( final Graph < T > graph , final 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 . |
9,471 | 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 . |
9,472 | 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 . |
9,473 | 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 . |
9,474 | public static < L , R > Pair < L , R > left ( final L left ) { return of ( left , null ) ; } | Creates a new pair with a left value . |
9,475 | public static < L , R > Pair < L , R > right ( final R right ) { return of ( null , right ) ; } | Creates a new pair with a right value . |
9,476 | public static < L , R > Pair < L , R > of ( final Map . Entry < L , R > entry ) { return of ( entry . getKey ( ) , entry . getValue ( ) ) ; } | Creates a new pair from a map entry . |
9,477 | public static < L , R > Pair < L , R > of ( final L left , final R right ) { return new Pair < > ( left , right ) ; } | Creates a new pair . |
9,478 | public < NL , NR > Pair < NL , NR > map ( final Function < ? super L , ? extends NL > left , final 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 . |
9,479 | public < NL > Pair < NL , R > lmap ( final Function < ? super L , ? extends NL > function ) { return new Pair < > ( function . apply ( this . left ) , this . right ) ; } | Map the left value of this pair . |
9,480 | public < NR > Pair < L , NR > rmap ( final Function < ? super R , ? extends NR > function ) { return new Pair < > ( this . left , function . apply ( this . right ) ) ; } | Map the right value of this pair . |
9,481 | public static String defaultURL ( String driver ) { assert Driver . exists ( driver ) ; String home = "" ; try { home = VictimsConfig . home ( ) . toString ( ) ; } catch ( VictimsException e ) { } return Driver . url ( driver , FilenameUtils . concat ( home , "victims" ) ) ; } | Get the default url for a preconfigured driver . |
9,482 | 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 . |
9,483 | 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 . |
9,484 | 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 . |
9,485 | 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 . |
9,486 | 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 . |
9,487 | 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 . |
9,488 | 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 ( ) ; 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 ) ) ; } 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" ) ; 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 ( ) ; if ( contentEncoding != null ) { if ( contentEncoding . equalsIgnoreCase ( "gzip" ) ) input = new GZIPInputStream ( input ) ; 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 . |
9,489 | 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 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 . |
9,490 | 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 |
9,491 | 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 . |
9,492 | 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 . |
9,493 | 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 |
9,494 | 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 |
9,495 | 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 |
9,496 | 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 |
9,497 | 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 |
9,498 | 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 |
9,499 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.