idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
14,700 | private KeyStore getClientTruststore ( ) throws KeyStoreException , NoSuchAlgorithmException , CertificateException , IOException { KeyStore ks = null ; if ( _config . getTruststoreType ( ) != null && ! _config . getTruststoreType ( ) . isEmpty ( ) ) { try { ks = KeyStore . getInstance ( _config . getTruststoreType ( ) ) ; } catch ( KeyStoreException e ) { LOGGER . warn ( "The specified truststore type [" + _config . getTruststoreType ( ) + "] didn't work." , e ) ; throw e ; } } else { ks = KeyStore . getInstance ( KeyStore . getDefaultType ( ) ) ; } char [ ] password = _config . getTruststorePassword ( ) . toCharArray ( ) ; java . io . FileInputStream fis = null ; try { fis = new java . io . FileInputStream ( _config . geTruststoreFilename ( ) ) ; ks . load ( fis , password ) ; } finally { if ( fis != null ) { fis . close ( ) ; } } return ks ; } | Read the KeyStore information supplied from the responder configuration file . |
14,701 | public void stopResponder ( ) { LOGGER . info ( "Force shutdown of Responder [" + _runtimeId + "]" ) ; _shutdownHook . start ( ) ; Runtime . getRuntime ( ) . removeShutdownHook ( _shutdownHook ) ; } | Close the socket and tell the processing loop to terminate . This is a forced shutdown rather then a natural shutdown . A natural shutdown happens when the shutdown hook fires when the VM exists . This method forces all that to happen . This is done to allow multiple Responders to be created and destroyed during a single VM session . Necessary for various testing and management procedures . |
14,702 | public void shutdown ( ) { LOGGER . info ( "Responder shutting down: [" + _runtimeId + "]" ) ; for ( Transport t : _transports ) { try { t . shutdown ( ) ; } catch ( TransportException e ) { LOGGER . warn ( "Error shutting down transport: [" + t . transportName ( ) + "]" , e ) ; } } } | This will shutdown the listening socket and remove the responder from the multicast group . Part of the natural life cycle . It also will end the run loop of the responder automatically - it will interrupt any read operation going on and exit the run loop . |
14,703 | public void run ( ) { Thread transportThread ; for ( Transport t : _transports ) { transportThread = new Thread ( t ) ; transportThread . setName ( t . transportName ( ) ) ; transportThread . start ( ) ; } } | This is the main run method for the Argo Responder . It starts up all the configured transports in their own thread and starts their receive loops . |
14,704 | public synchronized float probesPerSecond ( ) { Instant now = new Instant ( ) ; Instant event = null ; int events = 0 ; boolean done = false ; long timeWindow = 0 ; long oldestTime = 0 ; do { event = messages . poll ( ) ; if ( event != null ) { events ++ ; if ( events == 1 ) oldestTime = event . getMillis ( ) ; done = event . getMillis ( ) >= now . getMillis ( ) ; } else { done = true ; } } while ( ! done ) ; timeWindow = now . getMillis ( ) - oldestTime ; float mps = ( float ) events / timeWindow ; mps = ( float ) ( mps * 1000.0 ) ; return mps ; } | Calculates the number of probes per second over the last 1000 probes . |
14,705 | public static void main ( String [ ] args ) throws ResponderConfigException { Responder responder = initialize ( args ) ; if ( responder != null ) { responder . run ( ) ; } } | Main entry point for Argo Responder . |
14,706 | public static Responder initialize ( String [ ] args ) throws ResponderConfigException { readVersionProperties ( ) ; LOGGER . info ( "Starting Argo Responder daemon process. Version " + ARGO_VERSION ) ; ResponderConfiguration config = parseCommandLine ( args ) ; if ( config == null ) { LOGGER . error ( "Invalid Responder Configuration. Terminating Responder process." ) ; return null ; } Responder responder = new Responder ( config ) ; try { responder . loadHandlerPlugins ( config . getProbeHandlerConfigs ( ) ) ; } catch ( ProbeHandlerConfigException e ) { throw new ResponderConfigException ( "Error loading handler plugins: " , e ) ; } responder . loadTransportPlugins ( config . getTransportConfigs ( ) ) ; LOGGER . info ( "Responder registering shutdown hook." ) ; ResponderShutdown hook = new ResponderShutdown ( responder ) ; Runtime . getRuntime ( ) . addShutdownHook ( hook ) ; System . out . println ( "Argo " + ARGO_VERSION + " :: " + "Responder started [" + responder . _runtimeId + "] :: Responding as [" + ( config . isHTTPSConfigured ( ) ? "Secure HTTPS" : "Non-secure HTTP" ) + "]" ) ; return responder ; } | Create a new Responder given the command line arguments . |
14,707 | private void loadProperties ( String propFileName ) { if ( propFileName != null ) { loadProperties ( getClass ( ) . getResourceAsStream ( propFileName ) , propFileName ) ; } } | Load properties from a resource stream . |
14,708 | private void loadProperties ( InputStream stream , String path ) { if ( stream == null ) { return ; } try { Properties props = new Properties ( ) ; props . load ( stream ) ; Iterator < Object > keyIt = props . keySet ( ) . iterator ( ) ; while ( keyIt . hasNext ( ) ) { String key = keyIt . next ( ) . toString ( ) ; _properties . put ( key , props . get ( key ) ) ; } } catch ( Exception e ) { Console . warn ( "Unable to load properties file [" + path + "]." ) ; } finally { if ( stream != null ) { try { stream . close ( ) ; } catch ( Exception e ) { Console . warn ( "Unable to close properties file [" + path + "]." ) ; } } } } | Loads properties from the given stream . This will close the stream . |
14,709 | public Object put ( String key , Object o ) { return _properties . put ( key , o ) ; } | Add an object to the context . |
14,710 | public String getString ( String key , String defaultValue ) { Object o = getObject ( key ) ; if ( o == null ) { return defaultValue ; } if ( ! ( o instanceof String ) ) { throw new IllegalArgumentException ( "Object [" + o + "] associated with key [" + key + "] is not of type String." ) ; } return ( String ) o ; } | Get the string value or the defaultValue if not found . |
14,711 | public boolean getBoolean ( String key , boolean defaultValue ) { Object o = getObject ( key ) ; if ( o == null ) { return defaultValue ; } boolean b = defaultValue ; try { b = Boolean . parseBoolean ( o . toString ( ) ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Object [" + o + "] associated with key [" + key + "] is not of type Boolean." ) ; } return b ; } | Get the boolean value or the defaultValue if not found . |
14,712 | public int getInteger ( String key , int defaultValue ) { Object o = getObject ( key ) ; if ( o == null ) { return defaultValue ; } int val = defaultValue ; try { val = Integer . parseInt ( o . toString ( ) ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Object [" + o + "] associated with key [" + key + "] is not of type Integer." ) ; } return val ; } | Get the integer value or the defaultValue if not found . |
14,713 | public static InvocationHandler defaultMethodHandler ( ) { return ( proxy , method , args ) -> { if ( method . isDefault ( ) ) { return MethodHandles . lookup ( ) . in ( method . getDeclaringClass ( ) ) . unreflectSpecial ( method , method . getDeclaringClass ( ) ) . bindTo ( proxy ) . invokeWithArguments ( args ) ; } else { throw new IllegalArgumentException ( method . toString ( ) ) ; } } ; } | Handler for invoking interface default methods . This handler will throw an exception if the method is not a default method . |
14,714 | @ SuppressWarnings ( "unchecked" ) public < E extends T > T [ ] concat ( T [ ] oldArray , E newElement ) { T [ ] arr = ( T [ ] ) Array . newInstance ( type , oldArray . length + 1 ) ; System . arraycopy ( oldArray , 0 , arr , 0 , oldArray . length ) ; arr [ oldArray . length ] = newElement ; return arr ; } | Returns a new instance with the given element at the end . |
14,715 | @ SuppressWarnings ( "unchecked" ) protected T convert ( JsonNode data ) { return ( T ) this . mapper . convertValue ( data , this . resultType ) ; } | Use Jackson to map from JsonNode to the type |
14,716 | @ SuppressWarnings ( "unchecked" ) public Object runKeyword ( String keyword , final Object [ ] params ) { Map attributes = new HashMap ( ) ; attributes . put ( "args" , params ) ; try { ApplicationContextHolder . set ( context ) ; startJSpringBotKeyword ( keyword , attributes ) ; Object [ ] handledParams = argumentHandlers . handlerArguments ( keyword , params ) ; Object returnedValue = ( ( Keyword ) context . getBean ( keywordToBeanMap . get ( keyword ) ) ) . execute ( handledParams ) ; attributes . put ( "status" , "PASS" ) ; return returnedValue ; } catch ( Exception e ) { attributes . put ( "exception" , e ) ; attributes . put ( "status" , "FAIL" ) ; if ( SoftAssertManager . INSTANCE . isEnable ( ) ) { LOGGER . warn ( "[SOFT ASSERT]: (" + keyword + ") -> " + e . getMessage ( ) ) ; SoftAssertManager . INSTANCE . add ( keyword , e ) ; return null ; } else { throw new IllegalStateException ( e . getMessage ( ) , e ) ; } } finally { endJSpringBotKeyword ( keyword , attributes ) ; ApplicationContextHolder . remove ( ) ; } } | Implements the Robot Framework interface method run_keyword required for dynamic libraries . |
14,717 | public static String getAppAccessToken ( String clientId , String clientSecret ) { return getAccessToken ( clientId , clientSecret , null , null ) ; } | Get the app access token from Facebook . |
14,718 | public void execute ( ) { if ( this . batches . isEmpty ( ) ) return ; List < Batch > old = this . batches ; this . batches = new ArrayList < Batch > ( ) ; this . queryBatch = null ; for ( Batch batch : old ) { batch . execute ( ) ; } } | Executes all existing batches and removes them from consideration for further batching . |
14,719 | private Batch getBatchForGraph ( ) { Batch lastValidBatch = this . batches . isEmpty ( ) ? null : this . batches . get ( this . batches . size ( ) - 1 ) ; if ( lastValidBatch != null && lastValidBatch . graphSize ( ) < this . maxBatchSize ) return lastValidBatch ; else { Batch next = new Batch ( this , this . mapper , this . accessToken , this . apiVersion , this . timeout , this . retries ) ; this . batches . add ( next ) ; return next ; } } | Get an appropriate Batch for issuing a new graph call . Will construct a new one if all existing batches are full . |
14,720 | public static SmartBinder from ( Signature inbound ) { return new SmartBinder ( inbound , Binder . from ( inbound . type ( ) ) ) ; } | Create a new SmartBinder from the given Signature . |
14,721 | public static SmartBinder from ( Class < ? > retType , String [ ] names , Class < ? > ... types ) { return from ( Signature . returning ( retType ) . appendArgs ( names , types ) ) ; } | Create a new SmartBinder from the given types and argument names . |
14,722 | public static SmartBinder from ( Class < ? > retType , String name , Class < ? > type ) { return from ( Signature . returning ( retType ) . appendArg ( name , type ) ) ; } | Create a new SmartBinder with from the given types and argument name . |
14,723 | public static SmartBinder from ( Lookup lookup , Signature inbound ) { return new SmartBinder ( inbound , Binder . from ( lookup , inbound . type ( ) ) ) ; } | Create a new SmartBinder from the given Signature using the given Lookup for any handle lookups . |
14,724 | public SmartBinder foldVoid ( SmartHandle function ) { if ( Arrays . equals ( signature ( ) . argNames ( ) , function . signature ( ) . argNames ( ) ) ) { return foldVoid ( function . handle ( ) ) ; } else { return foldVoid ( signature ( ) . asFold ( void . class ) . permuteWith ( function ) . handle ( ) ) ; } } | Pass all arguments to the given function and drop any result . |
14,725 | public SmartBinder foldStatic ( String newName , Lookup lookup , Class < ? > target , String method ) { Binder newBinder = binder . foldStatic ( lookup , target , method ) ; return new SmartBinder ( this , signature ( ) . prependArg ( newName , newBinder . type ( ) . parameterType ( 0 ) ) , binder ) ; } | Acquire a static folding function from the given target class using the given name and Lookup . Pass all arguments to that function and insert the resulting value as newName into the argument list . |
14,726 | public SmartBinder foldVirtual ( String newName , Lookup lookup , String method ) { Binder newBinder = binder . foldVirtual ( lookup , method ) ; return new SmartBinder ( this , signature ( ) . prependArg ( newName , newBinder . type ( ) . parameterType ( 0 ) ) , newBinder ) ; } | Acquire a virtual folding function from the first argument s class using the given name and Lookup . Pass all arguments to that function and insert the resulting value as newName into the argument list . |
14,727 | public SmartBinder permute ( Signature target ) { return new SmartBinder ( this , target , binder . permute ( signature ( ) . to ( target ) ) ) ; } | Using the argument names and order in the target Signature permute the arguments in this SmartBinder . Arguments may be duplicated or omitted in the target Signature but all arguments in the target must be defined in this SmartBinder . |
14,728 | public SmartBinder spread ( String [ ] spreadNames , Class < ? > ... spreadTypes ) { return new SmartBinder ( this , signature ( ) . spread ( spreadNames , spreadTypes ) , binder . spread ( spreadTypes ) ) ; } | Spread a trailing array into the specified argument types . |
14,729 | public SmartBinder spread ( String baseName , int count ) { return new SmartBinder ( this , signature ( ) . spread ( baseName , count ) , binder . spread ( count ) ) ; } | Spread a trailing array into count number of arguments using the natural component type for the array . Build names for the arguments using the given baseName plus the argument s index . |
14,730 | public SmartBinder insert ( int index , String [ ] names , Class < ? > [ ] types , Object ... values ) { return new SmartBinder ( this , signature ( ) . insertArgs ( index , names , types ) , binder . insert ( index , types , values ) ) ; } | Insert arguments into the argument list at the given index with the given names and values . |
14,731 | public SmartBinder append ( String [ ] names , Class < ? > [ ] types , Object ... values ) { return new SmartBinder ( this , signature ( ) . appendArgs ( names , types ) , binder . append ( types , values ) ) ; } | Append the given arguments to the argument list assigning them the given names . |
14,732 | public SmartBinder prepend ( String [ ] names , Class < ? > [ ] types , Object ... values ) { return new SmartBinder ( this , signature ( ) . prependArgs ( names , types ) , binder . prepend ( types , values ) ) ; } | Prepend the given arguments to the argument list assigning them the given name . |
14,733 | public SmartBinder drop ( String name ) { int index = signature ( ) . argOffset ( name ) ; return new SmartBinder ( this , signature ( ) . dropArg ( index ) , binder . drop ( index ) ) ; } | Drop the argument with the given name . |
14,734 | public SmartBinder dropLast ( int count ) { return new SmartBinder ( this , signature ( ) . dropLast ( count ) , binder . dropLast ( count ) ) ; } | Drop the last N arguments . |
14,735 | public SmartBinder dropFirst ( int count ) { return new SmartBinder ( this , signature ( ) . dropFirst ( count ) , binder . dropFirst ( count ) ) ; } | Drop the first N arguments . |
14,736 | public SmartBinder collect ( String outName , String namePattern ) { int index = signature ( ) . argOffsets ( namePattern ) ; assert index >= 0 : "no arguments matching " + namePattern + " found in signature " + signature ( ) ; Signature newSignature = signature ( ) . collect ( outName , namePattern ) ; return new SmartBinder ( this , newSignature , binder . collect ( index , signature ( ) . argCount ( ) - ( newSignature . argCount ( ) - 1 ) , Array . newInstance ( signature ( ) . argType ( index ) , 0 ) . getClass ( ) ) ) ; } | Collect arguments matching namePattern into an trailing array argument named outName . |
14,737 | public SmartBinder cast ( Signature target ) { return new SmartBinder ( target , binder . cast ( target . type ( ) ) ) ; } | Cast the incoming arguments to the types in the given signature . The argument count must match but the names in the target signature are ignored . |
14,738 | public SmartBinder cast ( Class < ? > returnType , Class < ? > ... argTypes ) { return new SmartBinder ( this , new Signature ( returnType , argTypes , signature ( ) . argNames ( ) ) , binder . cast ( returnType , argTypes ) ) ; } | Cast the incoming arguments to the return and argument types given . The argument count must match . |
14,739 | public SmartBinder castVirtual ( Class < ? > returnType , Class < ? > firstArg , Class < ? > ... restArgs ) { return new SmartBinder ( this , new Signature ( returnType , firstArg , restArgs , signature ( ) . argNames ( ) ) , binder . castVirtual ( returnType , firstArg , restArgs ) ) ; } | Cast the incoming arguments to the return first argument type and remaining argument types . Provide for convenience when dealing with virtual method argument lists which frequently omit the target object . |
14,740 | public SmartBinder castArg ( String name , Class < ? > type ) { Signature newSig = signature ( ) . replaceArg ( name , name , type ) ; return new SmartBinder ( this , newSig , binder . cast ( newSig . type ( ) ) ) ; } | Cast the named argument to the given type . |
14,741 | public SmartBinder castReturn ( Class < ? > type ) { return new SmartBinder ( this , signature ( ) . changeReturn ( type ) , binder . cast ( type , binder . type ( ) . parameterArray ( ) ) ) ; } | Cast the return value to the given type . |
14,742 | public SmartHandle invokeVirtual ( Lookup lookup , String name ) throws NoSuchMethodException , IllegalAccessException { return new SmartHandle ( start , binder . invokeVirtual ( lookup , name ) ) ; } | Terminate this binder by looking up the named virtual method on the first argument s type . Perform the actual method lookup using the given Lookup object . |
14,743 | public SmartHandle invokeStatic ( Lookup lookup , Class < ? > target , String name ) throws NoSuchMethodException , IllegalAccessException { return new SmartHandle ( start , binder . invokeStatic ( lookup , target , name ) ) ; } | Terminate this binder by looking up the named static method on the given target type . Perform the actual method lookup using the given Lookup object . |
14,744 | public SmartHandle invoke ( SmartHandle target ) { return new SmartHandle ( start , binder . invoke ( target . handle ( ) ) ) ; } | Terminate this binder by invoking the given target handle . The signature of this binder is not compared to the signature of the given SmartHandle . |
14,745 | public SmartBinder filter ( String pattern , MethodHandle filter ) { String [ ] argNames = signature ( ) . argNames ( ) ; Pattern pat = Pattern . compile ( pattern ) ; Binder newBinder = binder ( ) ; Signature newSig = signature ( ) ; for ( int i = 0 ; i < argNames . length ; i ++ ) { if ( pat . matcher ( argNames [ i ] ) . matches ( ) ) { newBinder = newBinder . filter ( i , filter ) ; newSig = newSig . argType ( i , filter . type ( ) . returnType ( ) ) ; } } return new SmartBinder ( newSig , newBinder ) ; } | Filter the arguments matching the given pattern using the given filter function . |
14,746 | public static Signature from ( Class < ? > retval , Class < ? > [ ] argTypes , String ... argNames ) { assert argTypes . length == argNames . length ; return new Signature ( retval , argTypes , argNames ) ; } | Create a new signature based on the given return value argument types and argument names |
14,747 | public Signature dropArg ( String name ) { String [ ] newArgNames = new String [ argNames . length - 1 ] ; MethodType newType = methodType ; for ( int i = 0 , j = 0 ; i < argNames . length ; i ++ ) { if ( argNames [ i ] . equals ( name ) ) { newType = newType . dropParameterTypes ( j , j + 1 ) ; continue ; } newArgNames [ j ++ ] = argNames [ i ] ; } if ( newType == null ) { return this ; } return new Signature ( newType , newArgNames ) ; } | Drops the first argument with the given name . |
14,748 | public Signature dropArg ( int index ) { assert index < argNames . length ; String [ ] newArgNames = new String [ argNames . length - 1 ] ; if ( index > 0 ) System . arraycopy ( argNames , 0 , newArgNames , 0 , index ) ; if ( index < argNames . length - 1 ) System . arraycopy ( argNames , index + 1 , newArgNames , index , argNames . length - ( index + 1 ) ) ; MethodType newType = methodType . dropParameterTypes ( index , index + 1 ) ; return new Signature ( newType , newArgNames ) ; } | Drops the argument at the given index . |
14,749 | public Signature dropLast ( int n ) { return new Signature ( methodType . dropParameterTypes ( methodType . parameterCount ( ) - n , methodType . parameterCount ( ) ) , Arrays . copyOfRange ( argNames , 0 , argNames . length - n ) ) ; } | Drop the specified number of last arguments from this signature . |
14,750 | public Signature dropFirst ( int n ) { return new Signature ( methodType . dropParameterTypes ( 0 , n ) , Arrays . copyOfRange ( argNames , n , argNames . length ) ) ; } | Drop the specified number of first arguments from this signature . |
14,751 | public Signature replaceArg ( String oldName , String newName , Class < ? > newType ) { int offset = argOffset ( oldName ) ; String [ ] newArgNames = argNames ; if ( ! oldName . equals ( newName ) ) { newArgNames = Arrays . copyOf ( argNames , argNames . length ) ; newArgNames [ offset ] = newName ; } Class < ? > oldType = methodType . parameterType ( offset ) ; MethodType newMethodType = methodType ; if ( ! oldType . equals ( newType ) ) newMethodType = methodType . changeParameterType ( offset , newType ) ; return new Signature ( newMethodType , newArgNames ) ; } | Replace the named argument with a new name and type . |
14,752 | public Signature collect ( String newName , String oldPattern ) { int start = - 1 ; int newCount = 0 ; int gatherCount = 0 ; Class < ? > type = null ; Pattern pattern = Pattern . compile ( oldPattern ) ; MethodType newType = type ( ) ; for ( int i = 0 ; i < argNames . length ; i ++ ) { if ( pattern . matcher ( argName ( i ) ) . matches ( ) ) { gatherCount ++ ; newType = newType . dropParameterTypes ( newCount , newCount + 1 ) ; Class < ? > argType = argType ( i ) ; if ( start == - 1 ) start = i ; if ( type == null ) { type = argType ; } else { if ( argType != type ) { throw new InvalidTransformException ( "arguments matching " + pattern + " are not all of the same type" ) ; } } } else { newCount ++ ; } } if ( start != - 1 ) { String [ ] newNames = new String [ newCount + 1 ] ; System . arraycopy ( argNames , 0 , newNames , 0 , start ) ; newNames [ start ] = newName ; newType = newType . insertParameterTypes ( start , Array . newInstance ( type , 0 ) . getClass ( ) ) ; if ( newCount + 1 > start ) { System . arraycopy ( argNames , start + gatherCount , newNames , start + 1 , newCount - start ) ; } return new Signature ( newType , newNames ) ; } return this ; } | Collect sequential arguments matching pattern into an array . They must have the same type . |
14,753 | public Signature argName ( int index , String name ) { String [ ] argNames = Arrays . copyOf ( argNames ( ) , argNames ( ) . length ) ; argNames [ index ] = name ; return new Signature ( type ( ) , argNames ) ; } | Set the argument name at the given index . |
14,754 | public Signature argType ( int index , Class < ? > type ) { return new Signature ( type ( ) . changeParameterType ( index , type ) , argNames ( ) ) ; } | Set the argument type at the given index . |
14,755 | public MethodHandle permuteWith ( MethodHandle target , String ... permuteArgs ) { return MethodHandles . permuteArguments ( target , methodType , to ( permute ( permuteArgs ) ) ) ; } | Produce a method handle permuting the arguments in this signature using the given permute arguments and targeting the given java . lang . invoke . MethodHandle . |
14,756 | public SmartHandle permuteWith ( SmartHandle target ) { String [ ] argNames = target . signature ( ) . argNames ( ) ; return new SmartHandle ( this , permuteWith ( target . handle ( ) , argNames ) ) ; } | Produce a new SmartHandle by permuting this Signature s arguments to the Signature of a target SmartHandle . The new SmartHandle s signature will match this one permuting those arguments and invoking the target handle . |
14,757 | public static < E > Stream < E > streamUntil ( Supplier < ? extends E > supplier , Predicate < ? super E > stop ) { Iterator < E > iterator = AltIterators . iterateUntil ( supplier , stop ) ; Spliterator < E > spliterator = Spliterators . spliterator ( iterator , Long . MAX_VALUE , Spliterator . ORDERED ) ; return StreamSupport . stream ( spliterator , false ) ; } | Consumes data from the supplier until a condition is met . Use this method where a poison pill can be supplied to stop processing . |
14,758 | public static int find ( int [ ] arr , int start , int end , int valueToFind ) { assert arr != null ; assert end >= 0 ; assert end <= arr . length ; for ( int i = start ; i < end ; i ++ ) { if ( arr [ i ] == valueToFind ) { return i ; } } return NOT_FOUND ; } | Finds a value in an int array . |
14,759 | public static int find ( Object [ ] arr , int start , int end , Object valueToFind ) { assert arr != null ; assert end >= 0 ; assert end <= arr . length ; for ( int i = start ; i < end ; i ++ ) { if ( Objects . equals ( arr [ i ] , valueToFind ) ) { return i ; } } return NOT_FOUND ; } | Finds a value in an Object array . |
14,760 | public static < T > Mutator < T > mutate ( T t ) { Objects . requireNonNull ( t ) ; return new Mutator < > ( t ) ; } | Creates a new mutate instance . |
14,761 | private HttpResponse executeOnce ( RequestSetup setup ) throws IOException { DefaultRequestDefinition req = new DefaultRequestDefinition ( ) ; setup . setup ( req ) ; HttpResponse response = req . execute ( ) ; response . getResponseCode ( ) ; return response ; } | Execute given the specified http method once throwing any exceptions as they come |
14,762 | protected static void buildClassArguments ( StringBuilder builder , Class < ? > [ ] types ) { boolean second = false ; for ( Class cls : types ) { if ( second ) builder . append ( ", " ) ; second = true ; buildClassArgument ( builder , cls ) ; } } | Build a list of argument type classes suitable for inserting into Java code . |
14,763 | protected static void buildClassArgument ( StringBuilder builder , Class cls ) { buildClass ( builder , cls ) ; builder . append ( ".class" ) ; } | Build Java code to represent a single . class reference . |
14,764 | protected static void buildClassCast ( StringBuilder builder , Class cls ) { builder . append ( '(' ) ; buildClass ( builder , cls ) ; builder . append ( ')' ) ; } | Build Java code to represent a cast to the given type . |
14,765 | protected static void buildPrimitiveJava ( StringBuilder builder , Object value ) { builder . append ( value . toString ( ) ) ; if ( value . getClass ( ) == Float . class ) builder . append ( 'F' ) ; if ( value . getClass ( ) == Long . class ) builder . append ( 'L' ) ; } | Build Java code to represent a literal primitive . |
14,766 | private static void buildClass ( StringBuilder builder , Class cls ) { int arrayDims = 0 ; Class tmp = cls ; while ( tmp . isArray ( ) ) { arrayDims ++ ; tmp = tmp . getComponentType ( ) ; } builder . append ( tmp . getName ( ) ) ; if ( arrayDims > 0 ) { for ( ; arrayDims > 0 ; arrayDims -- ) { builder . append ( "[]" ) ; } } } | Build Java code to represent a type reference to the given class . |
14,767 | public static String generateMethodType ( MethodType source ) { StringBuilder builder = new StringBuilder ( "MethodType.methodType(" ) ; buildClassArgument ( builder , source . returnType ( ) ) ; if ( source . parameterCount ( ) > 0 ) { builder . append ( ", " ) ; buildClassArguments ( builder , source . parameterArray ( ) ) ; } builder . append ( ")" ) ; return builder . toString ( ) ; } | Build Java code appropriate for standing up the given MethodType . |
14,768 | protected HttpResponse execute ( final HttpMethod meth , String postURL ) throws IOException { final String url = ( meth == HttpMethod . POST ) ? postURL : this . toString ( ) ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( meth + "ing: " + url ) ; return RequestExecutor . instance ( ) . execute ( this . retries , new RequestSetup ( ) { public void setup ( RequestDefinition req ) throws IOException { req . init ( meth , url ) ; for ( Map . Entry < String , String > header : headers . entrySet ( ) ) req . setHeader ( header . getKey ( ) , header . getValue ( ) ) ; if ( timeout > 0 ) req . setTimeout ( timeout ) ; if ( meth == HttpMethod . POST && ! params . isEmpty ( ) ) { if ( ! hasBinaryAttachments ) { String queryString = createQueryString ( ) ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( "POST data is: " + queryString ) ; req . setHeader ( "Content-Type" , "application/x-www-form-urlencoded; charset=utf-8" ) ; req . setContent ( queryString . getBytes ( "utf-8" ) ) ; } else { log . finer ( "POST contains binary data, sending multipart/form-data" ) ; MultipartWriter writer = new MultipartWriter ( req ) ; writer . write ( params ) ; } } } } ) ; } | Execute given the specified http method retrying up to the allowed number of retries . |
14,769 | protected String createQueryString ( ) { assert ! this . hasBinaryAttachments ; if ( this . params . isEmpty ( ) ) return "" ; StringBuilder bld = null ; for ( Map . Entry < String , Object > param : this . params . entrySet ( ) ) { if ( bld == null ) bld = new StringBuilder ( ) ; else bld . append ( '&' ) ; bld . append ( StringUtils . urlEncode ( param . getKey ( ) ) ) ; bld . append ( '=' ) ; bld . append ( StringUtils . urlEncode ( param . getValue ( ) . toString ( ) ) ) ; } return bld . toString ( ) ; } | Creates a string representing the current query string or an empty string if there are no parameters . Will not work if there are binary attachments! |
14,770 | public static FacebookCookie decode ( String cookie , String appSecret ) { try { String [ ] parts = cookie . split ( "\\." ) ; byte [ ] sig = Base64 . decodeBase64 ( parts [ 0 ] ) ; byte [ ] json = Base64 . decodeBase64 ( parts [ 1 ] ) ; byte [ ] plaintext = parts [ 1 ] . getBytes ( ) ; FacebookCookie decoded = MAPPER . readValue ( json , FacebookCookie . class ) ; String algorithm = decoded . algorithm . replace ( "-" , "" ) ; SecretKey secret = new SecretKeySpec ( appSecret . getBytes ( ) , algorithm ) ; Mac mac = Mac . getInstance ( algorithm ) ; mac . init ( secret ) ; byte [ ] digested = mac . doFinal ( plaintext ) ; if ( ! Arrays . equals ( sig , digested ) ) throw new IllegalStateException ( "Signature failed" ) ; return decoded ; } catch ( Exception ex ) { throw new IllegalStateException ( "Unable to decode cookie" , ex ) ; } } | Decodes and validates the cookie . |
14,771 | public static Map < String , String > getKeywordMap ( ApplicationContext context ) { Map < String , String > keywordToBeanMap = new HashMap < String , String > ( ) ; String [ ] beanNames = context . getBeanNamesForType ( Keyword . class ) ; for ( String beanName : beanNames ) { Object bean = context . getBean ( beanName ) ; KeywordInfo keywordInfo = AnnotationUtils . findAnnotation ( bean . getClass ( ) , KeywordInfo . class ) ; String keywordName = keywordInfo != null ? keywordInfo . name ( ) : beanName ; if ( keywordToBeanMap . put ( keywordName , beanName ) != null ) { throw new RuntimeException ( "Multiple definitions for keyword '" + keywordName + "' exists." ) ; } } return keywordToBeanMap ; } | Builds mapping of robot keywords to actual bean names in spring context . |
14,772 | public static String getDescription ( String keyword , ApplicationContext context , Map < String , String > beanMap ) { KeywordInfo keywordInfo = getKeywordInfo ( keyword , context , beanMap ) ; if ( keywordInfo == null ) { return "" ; } String desc = keywordInfo . description ( ) ; if ( desc . startsWith ( "classpath:" ) ) { try { ResourceEditor editor = new ResourceEditor ( ) ; editor . setAsText ( desc ) ; Resource r = ( Resource ) editor . getValue ( ) ; return IOUtils . toString ( r . getInputStream ( ) ) ; } catch ( Exception ignored ) { } } return desc ; } | Retrieves the given keyword s description . |
14,773 | public static String [ ] getParameters ( String keyword , ApplicationContext context , Map < String , String > beanMap ) { KeywordInfo keywordInfo = getKeywordInfo ( keyword , context , beanMap ) ; return keywordInfo == null ? DEFAULT_PARAMS : keywordInfo . parameters ( ) ; } | Retrieves the given keyword s parameter description . |
14,774 | public static KeywordInfo getKeywordInfo ( String keyword , ApplicationContext context , Map < String , String > beanMap ) { Object bean = context . getBean ( beanMap . get ( keyword ) ) ; return AnnotationUtils . findAnnotation ( bean . getClass ( ) , KeywordInfo . class ) ; } | Retrieves the KeywordInfo of the given keyword . |
14,775 | protected Param [ ] getParams ( ) { Map < String , String > queries = new LinkedHashMap < String , String > ( ) ; for ( QueryRequest < ? > req : this . queryRequests ) queries . put ( req . getName ( ) , req . getFQL ( ) ) ; String json = JSONUtils . toJSON ( queries , this . mapper ) ; return new Param [ ] { new Param ( "queries" , json ) } ; } | Generate the parameters approprate to a multiquery from the registered queries |
14,776 | @ JsonProperty ( "relative_url" ) public String getRelativeURL ( ) { StringBuilder bld = new StringBuilder ( ) ; bld . append ( this . object ) ; Param [ ] params = this . getParams ( ) ; if ( params != null && params . length > 0 ) { bld . append ( '?' ) ; boolean afterFirst = false ; for ( Param param : params ) { if ( afterFirst ) bld . append ( '&' ) ; else afterFirst = true ; if ( param instanceof BinaryParam ) { throw new UnsupportedOperationException ( "Not quite sure what to do with BinaryParam yet" ) ; } else { String paramValue = StringUtils . stringifyValue ( param , this . mapper ) ; bld . append ( StringUtils . urlEncode ( param . name ) ) ; bld . append ( '=' ) ; bld . append ( StringUtils . urlEncode ( paramValue ) ) ; } } } return bld . toString ( ) ; } | What Facebook uses to define the url in a batch |
14,777 | public static SmartHandle findStaticQuiet ( Lookup lookup , Class < ? > target , String name , Signature signature ) { try { return new SmartHandle ( signature , lookup . findStatic ( target , name , signature . type ( ) ) ) ; } catch ( NoSuchMethodException | IllegalAccessException e ) { throw new RuntimeException ( e ) ; } } | Create a new SmartHandle by performing a lookup on the given target class for the given method name with the given signature . |
14,778 | public SmartHandle drop ( String beforeName , String newName , Class < ? > type ) { return new SmartHandle ( signature . insertArg ( beforeName , newName , type ) , MethodHandles . dropArguments ( handle , signature . argOffset ( beforeName ) , type ) ) ; } | Drop an argument name and type from the handle at the given index returning a new SmartHandle . |
14,779 | public SmartHandle drop ( int index , String newName , Class < ? > type ) { return new SmartHandle ( signature . insertArg ( index , newName , type ) , MethodHandles . dropArguments ( handle , index , type ) ) ; } | Drop an argument from the handle at the given index returning a new SmartHandle . |
14,780 | public SmartHandle dropLast ( String newName , Class < ? > type ) { return new SmartHandle ( signature . appendArg ( newName , type ) , MethodHandles . dropArguments ( handle , signature . argOffset ( newName ) , type ) ) ; } | Drop an argument from the handle at the end returning a new SmartHandle . |
14,781 | public SmartHandle bindTo ( Object obj ) { return new SmartHandle ( signature . dropFirst ( ) , handle . bindTo ( obj ) ) ; } | Bind the first argument of this SmartHandle to the given object returning a new adapted handle . |
14,782 | public SmartHandle returnValue ( Class < ? > type , Object value ) { return new SmartHandle ( signature . changeReturn ( type ) , MethodHandles . filterReturnValue ( handle , MethodHandles . constant ( type , value ) ) ) ; } | Replace the return value with the given value performing no other processing of the original value . |
14,783 | public static String toJSON ( Object value , ObjectMapper mapper ) { try { return mapper . writeValueAsString ( value ) ; } catch ( IOException ex ) { throw new FacebookException ( ex ) ; } } | Converts the object to a JSON string using the mapper |
14,784 | public static JsonNode toNode ( String value , ObjectMapper mapper ) { try { return mapper . readTree ( value ) ; } catch ( IOException ex ) { throw new FacebookException ( ex ) ; } } | Parses a string into a JsonNode using the mapper |
14,785 | public static String stringifyValue ( Param param , ObjectMapper mapper ) { assert ! ( param instanceof BinaryParam ) ; if ( param . value instanceof String ) return ( String ) param . value ; if ( param . value instanceof Date ) return Long . toString ( ( ( Date ) param . value ) . getTime ( ) / 1000 ) ; else if ( param . value instanceof Number ) return param . value . toString ( ) ; else return JSONUtils . toJSON ( param . value , mapper ) ; } | Stringify the parameter value in an appropriate way . Note that Facebook fucks up dates by using unix time - since - epoch some places and ISO - 8601 others . However maybe unix times always work as parameters? |
14,786 | public static String read ( InputStream input ) { try { StringBuilder bld = new StringBuilder ( ) ; Reader reader = new InputStreamReader ( input , "utf-8" ) ; int ch ; while ( ( ch = reader . read ( ) ) >= 0 ) bld . append ( ( char ) ch ) ; return bld . toString ( ) ; } catch ( IOException ex ) { throw new RuntimeException ( ex ) ; } } | Reads an input stream into a String encoding with UTF - 8 |
14,787 | public static Binder from ( MethodHandles . Lookup lookup , Binder start ) { return new Binder ( lookup , start ) ; } | Construct a new Binder starting from a given invokebinder . |
14,788 | public Binder to ( Binder other ) { assert type ( ) . equals ( other . start ) ; Binder newBinder = new Binder ( this ) ; for ( ListIterator < Transform > iter = other . transforms . listIterator ( other . transforms . size ( ) ) ; iter . hasPrevious ( ) ; ) { Transform t = iter . previous ( ) ; newBinder . add ( t ) ; } return newBinder ; } | Join this binder to an existing one by applying its transformations after this one . |
14,789 | private void add ( Transform transform , MethodType target ) { types . add ( 0 , target ) ; transforms . add ( 0 , transform ) ; } | Add a Transform with an associated MethodType target to the chain . |
14,790 | public Binder insert ( int index , Class < ? > type , Object value ) { return new Binder ( this , new Insert ( index , new Class [ ] { type } , value ) ) ; } | Insert at the given index the given argument value . |
14,791 | public Binder append ( Class < ? > type , Object value ) { return new Binder ( this , new Insert ( type ( ) . parameterCount ( ) , new Class [ ] { type } , value ) ) ; } | Append to the argument list the given argument value with the specified type . |
14,792 | public Binder append ( Class < ? > [ ] types , Object ... values ) { return new Binder ( this , new Insert ( type ( ) . parameterCount ( ) , types , values ) ) ; } | Append to the argument list the given argument values with the specified types . |
14,793 | public Binder prepend ( Class < ? > type , Object value ) { return new Binder ( this , new Insert ( 0 , new Class [ ] { type } , value ) ) ; } | Prepend to the argument list the given argument value with the specified type |
14,794 | public Binder prepend ( Class < ? > [ ] types , Object ... values ) { return new Binder ( this , new Insert ( 0 , types , values ) ) ; } | Prepend to the argument list the given argument values with the specified types . |
14,795 | public Binder drop ( int index , int count ) { return new Binder ( this , new Drop ( index , Arrays . copyOfRange ( type ( ) . parameterArray ( ) , index , index + count ) ) ) ; } | Drop from the given index a number of arguments . |
14,796 | public Binder dropLast ( int count ) { assert count <= type ( ) . parameterCount ( ) ; return drop ( type ( ) . parameterCount ( ) - count , count ) ; } | Drop from the end of the argument list a number of arguments . |
14,797 | public Binder spread ( Class < ? > ... spreadTypes ) { if ( spreadTypes . length == 0 ) { return dropLast ( ) ; } return new Binder ( this , new Spread ( type ( ) , spreadTypes ) ) ; } | Spread a trailing array argument into the specified argument types . |
14,798 | public Binder spread ( int count ) { if ( count == 0 ) { return dropLast ( ) ; } Class < ? > aryType = type ( ) . parameterType ( type ( ) . parameterCount ( ) - 1 ) ; assert aryType . isArray ( ) ; Class < ? > [ ] spreadTypes = new Class [ count ] ; Arrays . fill ( spreadTypes , aryType . getComponentType ( ) ) ; return spread ( spreadTypes ) ; } | Spread a trailing array argument into the given number of arguments of the type of the array . |
14,799 | public Binder collect ( int index , Class < ? > type ) { return new Binder ( this , new Collect ( type ( ) , index , type ) ) ; } | Box all incoming arguments from the given position onward into the given array type . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.