idx
int64 0
41.2k
| question
stringlengths 74
4.21k
| target
stringlengths 5
888
|
---|---|---|
1,200 |
public List < EventBase > getEventsList ( ) throws Exception { final String eventsPath = StringUtils . join ( new String [ ] { getUri ( ) , "events" } , '/' ) ; final JSONArray array = toJSONArray ( client . get ( eventsPath , null ) ) ; final List < EventBase > list = new ArrayList < EventBase > ( ) ; for ( final Object object : array ) { list . add ( new EventBase ( ( JSONObject ) object ) ) ; } return list ; }
|
Gets the events that occurred during the call .
|
1,201 |
public EventBase getEvent ( final String eventId ) throws Exception { final String eventPath = StringUtils . join ( new String [ ] { getUri ( ) , "events" , eventId } , '/' ) ; final JSONObject jsonObject = toJSONObject ( client . get ( eventPath , null ) ) ; return new EventBase ( jsonObject ) ; }
|
Gets information about one call event .
|
1,202 |
public void hangUp ( ) throws Exception { final Map < String , Object > params = new HashMap < String , Object > ( ) ; params . put ( "state" , "completed" ) ; final String uri = getUri ( ) ; client . post ( uri , params ) ; final JSONObject jsonObject = toJSONObject ( client . get ( uri , null ) ) ; updateProperties ( jsonObject ) ; }
|
Hang up a phone call .
|
1,203 |
public void sendDtmf ( final String dtmf ) throws IOException , AppPlatformException { final Map < String , Object > params = new HashMap < String , Object > ( ) ; params . put ( "dtmfOut" , dtmf ) ; final String uri = StringUtils . join ( new String [ ] { getUri ( ) , "dtmf" } , '/' ) ; client . post ( uri , params ) ; }
|
Sends DTMF .
|
1,204 |
public Gather getGather ( final String gatherId ) throws Exception { final String gatherPath = StringUtils . join ( new String [ ] { getUri ( ) , "gather" , gatherId } , '/' ) ; final JSONObject jsonObject = toJSONObject ( client . get ( gatherPath , null ) ) ; return new Gather ( client , jsonObject ) ; }
|
Gets the gather DTMF parameters and results .
|
1,205 |
public static MediaFile get ( final BandwidthClient client , final String id ) throws Exception { final String mediaUri = client . getUserResourceInstanceUri ( BandwidthConstants . MEDIA_URI_PATH , id ) ; final JSONObject jsonObject = toJSONObject ( client . get ( mediaUri , null ) ) ; return new MediaFile ( client , jsonObject ) ; }
|
Gets information about a previously sent or received MediaFile .
|
1,206 |
public MediaFile upload ( final String mediaName , final File file , final MediaMimeType contentType ) throws IOException , AppPlatformException { final String uri = StringUtils . join ( new String [ ] { getUri ( ) , mediaName } , '/' ) ; client . upload ( uri , file , contentType . toString ( ) ) ; final List < MediaFile > mediaFiles = list ( client , 0 , 25 ) ; for ( final MediaFile mediaFile : mediaFiles ) { if ( StringUtils . equals ( mediaFile . getMediaName ( ) , mediaName ) ) return mediaFile ; } return null ; }
|
Uploads media file .
|
1,207 |
public void download ( final String mediaName , final File file ) throws IOException { final String uri = client . getUserResourceInstanceUri ( BandwidthConstants . MEDIA_URI_PATH , mediaName ) ; client . download ( uri , file ) ; }
|
Downloads existing media file from server .
|
1,208 |
public void initialize ( ) { final JSONObject params = new JSONObject ( ) ; params . put ( "page" , page ) ; params . put ( "size" , size ) ; getPage ( params ) ; }
|
initializes ArrayList with first page from BW API
|
1,209 |
public Iterator < E > iterator ( ) { final Iterator < E > it = new Iterator < E > ( ) { public boolean hasNext ( ) { return ( index < size ( ) ) ; } public E next ( ) { final E elem = get ( index ++ ) ; if ( index >= size ( ) && nextLink != null ) { getNextPage ( ) ; } return elem ; } public void remove ( ) { } } ; return it ; }
|
Customer iterator calls out to BW API when there is more data to retrieve
|
1,210 |
protected void getNextPage ( ) { final JSONObject params = new JSONObject ( ) ; page ++ ; params . put ( "page" , page ) ; params . put ( "size" , size ) ; clear ( ) ; getPage ( params ) ; }
|
This method updates the page value creates the params for the API call and clears the current list
|
1,211 |
protected void getPage ( final JSONObject params ) { if ( this . client == null ) client = BandwidthClient . getInstance ( ) ; try { final RestResponse response = client . get ( resourceUri , params ) ; final JSONArray array = Utils . response2JSONArray ( response ) ; for ( final Object obj : array ) { final E elem = clazz . getConstructor ( BandwidthClient . class , JSONObject . class ) . newInstance ( client , ( JSONObject ) obj ) ; add ( elem ) ; } if ( array . size ( ) > 0 ) this . index = 0 ; this . setNextLink ( response . getNextLink ( ) ) ; this . setFirstLink ( response . getFirstLink ( ) ) ; this . setPreviousLink ( response . getPreviousLink ( ) ) ; } catch ( final Exception e ) { e . printStackTrace ( ) ; } }
|
This method makes the API call to get the list value for the specified resource . It loads the return from the API into the arrayList updates the index if necessary and sets the new link values
|
1,212 |
public AccountInfo getAccountInfo ( ) throws Exception { final JSONObject jsonObject = toJSONObject ( client . get ( getUri ( ) , null ) ) ; return new AccountInfo ( client , jsonObject ) ; }
|
Gets your current account information .
|
1,213 |
public static Endpoint create ( final BandwidthClient client , final String domainId , final Map < String , Object > params ) throws AppPlatformException , ParseException , Exception { assert ( client != null && params != null ) ; final String endpointsUri = String . format ( client . getUserResourceUri ( BandwidthConstants . ENDPOINTS_URI_PATH ) , domainId ) ; final RestResponse response = client . post ( endpointsUri , params ) ; final JSONObject callObj = toJSONObject ( client . get ( response . getLocation ( ) , null ) ) ; return new Endpoint ( client , callObj ) ; }
|
Convenience factory method to create a Endpoint object from a map of parameters
|
1,214 |
public static void delete ( final String domainId , final String endpointId ) throws AppPlatformException , IOException { assert ( endpointId != null ) ; final BandwidthClient client = BandwidthClient . getInstance ( ) ; client . delete ( String . format ( client . getUserResourceUri ( BandwidthConstants . ENDPOINTS_URI_PATH ) , domainId ) + "/" + endpointId ) ; }
|
Permanently deletes the Endpoint .
|
1,215 |
public static Domain create ( final BandwidthClient client , final String name , final String description ) throws AppPlatformException , ParseException , Exception { assert ( name != null ) ; final Map < String , Object > params = new HashMap < String , Object > ( ) ; params . put ( "name" , name ) ; if ( ! StringUtils . isBlank ( description ) ) { params . put ( "description" , description ) ; } return create ( client , params ) ; }
|
Convenience method to create a Domain .
|
1,216 |
public static Domain create ( final BandwidthClient client , final Map < String , Object > params ) throws AppPlatformException , ParseException , Exception { assert ( client != null && params != null ) ; final String domainsUri = client . getUserResourceUri ( BandwidthConstants . DOMAINS_URI_PATH ) ; final RestResponse response = client . post ( domainsUri , params ) ; final JSONObject callObj = toJSONObject ( client . get ( response . getLocation ( ) , null ) ) ; return new Domain ( client , callObj ) ; }
|
Convenience factory method to create a Domain .
|
1,217 |
public static Domain get ( final String id ) throws ParseException , Exception { final BandwidthClient client = BandwidthClient . getInstance ( ) ; return get ( client , id ) ; }
|
Convenience method to get information about a specific Domain
|
1,218 |
public static Domain get ( final BandwidthClient client , final String id ) throws ParseException , Exception { assert ( client != null ) ; final String domainsUri = client . getUserResourceInstanceUri ( BandwidthConstants . DOMAINS_URI_PATH , id ) ; final JSONObject jsonObject = toJSONObject ( client . get ( domainsUri , null ) ) ; return new Domain ( client , jsonObject ) ; }
|
Convenience method to return a Domain
|
1,219 |
public static ResourceList < Domain > list ( final BandwidthClient client , final int page , final int size ) { final String resourceUri = client . getUserResourceUri ( BandwidthConstants . DOMAINS_URI_PATH ) ; final ResourceList < Domain > domains = new ResourceList < Domain > ( resourceUri , Domain . class ) ; domains . setClient ( client ) ; domains . initialize ( ) ; return domains ; }
|
Factory method to list the Domains .
|
1,220 |
public static Domain update ( final BandwidthClient client , final String id , final Map < String , Object > params ) throws AppPlatformException , ParseException , IOException , Exception { assert ( client != null && id != null ) ; final String domainsUri = client . getUserResourceInstanceUri ( BandwidthConstants . DOMAINS_URI_PATH , id ) ; final RestResponse response = client . post ( domainsUri , params ) ; final JSONObject jsonObject = toJSONObject ( client . get ( domainsUri , null ) ) ; return new Domain ( client , jsonObject ) ; }
|
Convenience method to return a Domain .
|
1,221 |
public static void delete ( final String id ) throws AppPlatformException , IOException { assert ( id != null ) ; final BandwidthClient client = BandwidthClient . getInstance ( ) ; client . delete ( client . getUserResourceInstanceUri ( BandwidthConstants . DOMAINS_URI_PATH , id ) ) ; }
|
Permanently deletes the Domain .
|
1,222 |
public static Recording get ( final BandwidthClient client , final String id ) throws Exception { final String recordingsUri = client . getUserResourceUri ( BandwidthConstants . RECORDINGS_URI_PATH ) ; final String uri = StringUtils . join ( new String [ ] { recordingsUri , id } , '/' ) ; final JSONObject jsonObject = toJSONObject ( client . get ( uri , null ) ) ; return new Recording ( client , recordingsUri , jsonObject ) ; }
|
Recording factory method . Returns recording object from id
|
1,223 |
public void fill ( View view ) { validateNotNullableView ( view ) ; try { if ( view instanceof ViewGroup ) { ViewGroup viewGroup = ( ViewGroup ) view ; for ( int i = 0 ; i < viewGroup . getChildCount ( ) ; i ++ ) { View child = viewGroup . getChildAt ( i ) ; fill ( child ) ; } } else { if ( mIds == null ) { fillView ( view ) ; } else if ( mIds . contains ( view . getId ( ) ) ) { fillView ( view ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { mFaker = null ; } }
|
Fill a view with random data
|
1,224 |
public void fillWithText ( TextView view , FakerTextComponent component ) { validateNotNullableView ( view ) ; validateIfIsATextView ( view ) ; validateNotNullableFakerComponent ( component ) ; view . setText ( component . randomText ( ) ) ; }
|
Fill a TextView with a specific FakerTextComponent
|
1,225 |
public void fillWithNumber ( TextView view , FakerNumericComponent component ) { validateNotNullableView ( view ) ; validateIfIsATextView ( view ) ; validateNotNullableFakerComponent ( component ) ; view . setText ( String . valueOf ( component . randomNumber ( ) ) ) ; }
|
Fill a TextView with a specific FakerNumericComponent
|
1,226 |
public void fillWithColor ( View view , FakerColorComponent component ) { validateNotNullableView ( view ) ; validateNotNullableFakerComponent ( component ) ; view . setBackgroundColor ( component . randomColor ( ) ) ; }
|
Fill view with a random color
|
1,227 |
public void fillWithCheckState ( CompoundButton view ) { validateNotNullableView ( view ) ; validateIfIsACompoundButton ( view ) ; view . setChecked ( new Random ( ) . nextBoolean ( ) ) ; }
|
Set a random check or uncheck state
|
1,228 |
public String words ( ) { int numberOfWords = DEFAULT_RANDOM_NUMBERS_POOL [ new Random ( ) . nextInt ( DEFAULT_RANDOM_NUMBERS_POOL . length ) ] ; return words ( numberOfWords ) ; }
|
Provies random words from the words list . The amount of words varies from 3 to 7 .
|
1,229 |
public static int sizeOf ( Class < ? > clz ) throws IllegalArgumentException { switch ( clz . getName ( ) ) { case "int" : return Integer . BYTES ; case "short" : return Short . BYTES ; case "long" : return Long . BYTES ; case "double" : return Double . BYTES ; case "float" : return Float . BYTES ; case "boolean" : return 1 ; case "char" : return Character . BYTES ; case "byte" : return 1 ; default : throw new IllegalArgumentException ( "Not a primitive type." ) ; } }
|
Get the size of a primitive type .
|
1,230 |
@ SuppressWarnings ( "unchecked" ) public static < T > T parse ( Class < T > clz , String objectValue ) { switch ( clz . getName ( ) ) { case "int" : return ( T ) Integer . valueOf ( objectValue ) ; case "short" : return ( T ) Short . valueOf ( objectValue ) ; case "long" : if ( objectValue . endsWith ( "L" ) || objectValue . endsWith ( "l" ) ) { objectValue = objectValue . substring ( 0 , objectValue . length ( ) - 1 ) ; } return ( T ) Long . valueOf ( objectValue ) ; case "double" : return ( T ) Double . valueOf ( objectValue ) ; case "float" : return ( T ) Float . valueOf ( objectValue ) ; case "boolean" : if ( objectValue . equalsIgnoreCase ( Boolean . TRUE . toString ( ) ) ) { return ( T ) Boolean . TRUE ; } else if ( objectValue . equalsIgnoreCase ( Boolean . FALSE . toString ( ) ) ) { return ( T ) Boolean . FALSE ; } else { throw new IllegalArgumentException ( String . format ( "The String %s cannot parse as boolean." , objectValue ) ) ; } case "char" : if ( objectValue . length ( ) == 1 ) { return ( T ) new Character ( objectValue . charAt ( 0 ) ) ; } else { throw new IllegalArgumentException ( String . format ( "The String %s cannot parse as char." , objectValue ) ) ; } case "byte" : return ( T ) Byte . valueOf ( objectValue ) ; default : return null ; } }
|
Parse the string value to a primitive type
|
1,231 |
public static Iterator < Character > notExistChars ( String s ) { return new Iterator < Character > ( ) { IntList collect = IntList . create ( s . chars ( ) . distinct ( ) . sorted ( ) . toArray ( ) ) ; int current = 128 ; Character next = null ; public Character next ( ) { if ( calcNext ( ) ) { Character c = next ; next = null ; return c ; } else { throw new NoSuchElementException ( "No next non-exist character." ) ; } } public boolean hasNext ( ) { return calcNext ( ) ; } private boolean calcNext ( ) { if ( next == null ) { while ( ++ current < Integer . MAX_VALUE ) { if ( collect . remove ( current ) == false ) { next = ( char ) current ; return true ; } } return false ; } return true ; } } ; }
|
Get a list of not exist chars in given string . You can use these chars as placeholder to replace string safety .
|
1,232 |
public static int [ ] balancePair ( String str , String left , String right ) { int count = 0 ; int offset = 0 ; int firstLeft = - 1 ; while ( true ) { int leftIndex = str . indexOf ( left , offset ) ; int rightIndex = str . indexOf ( right , offset ) ; if ( leftIndex == rightIndex ) { return new int [ ] { firstLeft , - 1 } ; } else if ( ( leftIndex < rightIndex && leftIndex != - 1 ) || rightIndex == - 1 ) { if ( firstLeft == - 1 ) { firstLeft = leftIndex ; } count ++ ; offset = leftIndex + 1 ; } else { count -- ; offset = rightIndex + 1 ; if ( count < 0 ) { return new int [ ] { firstLeft , - 1 } ; } if ( count == 0 ) { return new int [ ] { firstLeft , rightIndex } ; } } } }
|
Get the first balance pair substring index .
|
1,233 |
public static < E extends Exception > void period ( Object key , int period , Supplier < E > exceptionFactory ) throws E { int index = cache ( MockException . class , key , ( ) -> 0 ) + 1 ; set ( MockException . class , key , index ) ; if ( index % period == 0 ) { throw exceptionFactory . get ( ) ; } }
|
Mock exception happens by period
|
1,234 |
public static < E extends Exception > void possible ( double possible , Supplier < E > exceptionFactory ) throws E { if ( Math . random ( ) < possible ) { throw exceptionFactory . get ( ) ; } }
|
Mock exception happens by possibility
|
1,235 |
@ SuppressWarnings ( "unchecked" ) public static < T extends Exception > Optional < T > firstFail ( ActionE0 < T > ... tasks ) { for ( ActionE0 < T > task : tasks ) { try { task . call ( ) ; } catch ( Exception t ) { return Optional . of ( ( T ) t ) ; } } return Optional . empty ( ) ; }
|
Run the given tasks until any exception happen
|
1,236 |
public static < T > T of ( Type type , Function < TypeVisitor < T > , T > function ) { return function . apply ( create ( type ) ) ; }
|
Because eclipse s type inference is so bad use this method you can free from angle brackets .
|
1,237 |
public static < K , V > V getOrPutDefault ( Map < K , V > map , K key , Supplier < V > defaultGetter ) { return map . computeIfAbsent ( key , k -> defaultGetter . get ( ) ) ; }
|
Get the value of the key . If absent put the default value .
|
1,238 |
private static Type getActualType ( Map < TypeVariable < ? > , Type > map , Type type ) { return TypeVisitor . of ( type , b -> b . onClass ( c -> c ) . onTypeVariable ( tv -> map . containsKey ( tv ) ? getActualType ( map , map . get ( tv ) ) : tv ) . onParameterizedType ( pt -> TypeVisitor . of ( pt . getRawType ( ) , bb -> bb . onClass ( c -> createParameterizedType ( c , pt . getOwnerType ( ) , Arrays . stream ( pt . getActualTypeArguments ( ) ) . map ( t -> getActualType ( map , t ) ) . toArray ( Type [ ] :: new ) ) ) . result ( ) ) ) . onWildcardType ( wt -> createWildcardType ( Arrays . stream ( wt . getUpperBounds ( ) ) . map ( t -> getActualType ( map , t ) ) . toArray ( Type [ ] :: new ) , Arrays . stream ( wt . getLowerBounds ( ) ) . map ( t -> getActualType ( map , t ) ) . toArray ( Type [ ] :: new ) ) ) . onGenericArrayType ( gat -> createGenericArrayType ( getActualType ( map , gat . getGenericComponentType ( ) ) ) ) . result ( type ) ) ; }
|
Get actual type by the type map .
|
1,239 |
public static Package parse ( File file ) throws IOException { ObjectMapper mapper = new ObjectMapper ( ) ; return mapper . readValue ( file , Package . class ) ; }
|
Parse package . json .
|
1,240 |
public static < T > Method getFunctionInterfaceMethod ( Class < ? > clz ) { if ( ! clz . isInterface ( ) ) { return null ; } Method [ ] ms = Stream . of ( clz . getMethods ( ) ) . filter ( m -> ! ( m . isDefault ( ) || m . isBridge ( ) || m . isSynthetic ( ) || Modifier . isStatic ( m . getModifiers ( ) ) ) ) . toArray ( Method [ ] :: new ) ; if ( ms . length != 1 ) { return null ; } return ms [ 0 ] ; }
|
Get the method from a function interface
|
1,241 |
public static < T > Try < T > to ( FuncE0 < T , Exception > code , ActionE0 < Exception > onFinally ) { try { return new Success < > ( code . call ( ) ) ; } catch ( Exception e ) { return new Failure < > ( e ) ; } finally { if ( onFinally != null ) { try { onFinally . call ( ) ; } catch ( Exception e ) { LogFactory . from ( Try . class ) . trace ( ) . log ( e . getMessage ( ) , e ) ; } } } }
|
Constructs a Try using a code as a supplier .
|
1,242 |
public Try < T > orElse ( Supplier < Try < T > > defaultValue ) { try { return isSuccess ( ) ? this : defaultValue . get ( ) ; } catch ( RuntimeException e ) { return new Failure < > ( e ) ; } }
|
Returns this Try if it s a Success or the given default argument if this is a Failure .
|
1,243 |
@ SuppressWarnings ( "unchecked" ) public static < T extends Annotation > T createAnnotationFromMap ( Class < T > annotationClass , Map < String , Object > valuesMap ) { Map < String , Object > map = getAnnotationDefaultMap ( annotationClass ) ; map . putAll ( valuesMap ) ; return AccessController . doPrivileged ( ( PrivilegedAction < T > ) ( ) -> ( T ) Proxy . newProxyInstance ( annotationClass . getClassLoader ( ) , new Class [ ] { annotationClass } , uncheck ( ( ) -> ( InvocationHandler ) AnnotationInvocationHandler_constructor . newInstance ( annotationClass , map ) ) ) ) ; }
|
Create annotation from the given map .
|
1,244 |
public Tree < T > add ( Tree < T > node ) { node . removeFromParent ( ) ; node . parent = this ; children . add ( node ) ; return node ; }
|
Add the node as child
|
1,245 |
public boolean remove ( Tree < T > node ) { return getChild ( node ) . map ( function ( n -> n . parent = null ) ) . map ( children :: remove ) . orElse ( false ) ; }
|
Remove the node from children
|
1,246 |
public Optional < Tree < T > > removeFromParent ( ) { Tree < T > theParent = this . parent ; if ( parent != null ) { parent . remove ( this ) ; } return Optional . ofNullable ( theParent ) ; }
|
Remove this node from its parent
|
1,247 |
public Optional < Tree < T > > getChild ( T value ) { return children . stream ( ) . filter ( its ( n -> n . value , isEquals ( value ) ) ) . findFirst ( ) ; }
|
Get the first matched child with the given value from children
|
1,248 |
public Optional < Tree < T > > getChild ( Tree < T > node ) { return children . stream ( ) . filter ( is ( node ) ) . findFirst ( ) ; }
|
Return the given node if it s this node s child
|
1,249 |
public Optional < Tree < T > > commonParent ( Tree < T > other ) { List < Tree < T > > myParents = parents ( ) . startWith ( this ) . toList ( ) . blockingGet ( ) ; return other . parents ( ) . startWith ( other ) . filter ( myParents :: contains ) . map ( Optional :: of ) . blockingFirst ( Optional . empty ( ) ) ; }
|
Get the first common parent of this node and the given node
|
1,250 |
public void swap ( Tree < T > node ) { Tree < T > thisParent = this . parent ; List < Tree < T > > thisChildren = new ArrayList < > ( this . children ) ; this . removeFromParent ( ) ; if ( node . parent != null ) { node . parent . add ( this ) ; } node . children . forEach ( this :: add ) ; node . removeFromParent ( ) ; if ( thisParent != null ) { thisParent . add ( node ) ; } thisChildren . forEach ( node :: add ) ; }
|
Swap with the given node . Even they are in different trees .
|
1,251 |
public Flowable < Tree < T > > parents ( ) { return Flowable . generate ( ( ) -> Wrapper . of ( this ) , ( n , e ) -> { Tree < T > parent = n . get ( ) . getParent ( ) ; if ( parent != null ) { e . onNext ( parent ) ; n . set ( parent ) ; } else { e . onComplete ( ) ; } } ) ; }
|
Get all of the node s parent
|
1,252 |
@ SuppressWarnings ( "unchecked" ) public static < T extends Executable > T getRootExecutable ( T m ) { return ( T ) EXECUTABLE_GET_ROOT . apply ( m ) ; }
|
Get root of the executable .
|
1,253 |
@ SuppressWarnings ( "unchecked" ) public static < T , O > O getFieldValue ( Class < T > clz , T t , String fieldName ) throws NoSuchFieldException { Field field = clz . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; try { return ( O ) field . get ( t ) ; } catch ( IllegalAccessException e ) { throw new IllegalStateException ( e ) ; } }
|
Get field value by name
|
1,254 |
public static Method [ ] getAllMethods ( Class < ? > clz ) { Set < Method > set = new HashSet < > ( ) ; List < Class < ? > > classes = new ArrayList < > ( ) ; classes . add ( clz ) ; classes . addAll ( Arrays . asList ( getAllSuperClasses ( clz ) ) ) ; classes . addAll ( Arrays . asList ( getAllInterfaces ( clz ) ) ) ; for ( Class < ? > c : classes ) { set . addAll ( Arrays . asList ( c . getDeclaredMethods ( ) ) ) ; } return set . toArray ( new Method [ set . size ( ) ] ) ; }
|
Get all methods
|
1,255 |
public static Class < ? > [ ] getAllSuperClasses ( Class < ? > clz ) { List < Class < ? > > list = new ArrayList < > ( ) ; while ( ( clz = clz . getSuperclass ( ) ) != null ) { list . add ( clz ) ; } return list . toArray ( new Class < ? > [ list . size ( ) ] ) ; }
|
Get all super classes
|
1,256 |
public static Class < ? > [ ] getAllInterfaces ( Class < ? > clz ) { HashSet < Class < ? > > set = new HashSet < > ( ) ; getAllInterfaces ( clz , set ) ; return set . toArray ( new Class < ? > [ set . size ( ) ] ) ; }
|
Get all interfaces
|
1,257 |
public static StackTraceElement getCaller ( int deep , boolean ignoreSameClass ) { StackTraceElement [ ] stElements = Thread . currentThread ( ) . getStackTrace ( ) ; StackTraceElement currentStack = stElements [ 1 ] ; int found = deep + 1 ; for ( int i = 1 ; i < stElements . length ; i ++ ) { StackTraceElement nextStack = stElements [ i ] ; if ( nextStack . getClassName ( ) . equals ( ReflectUtil . class . getName ( ) ) ) { continue ; } if ( ! ignoreSameClass || ! currentStack . getClassName ( ) . equals ( nextStack . getClassName ( ) ) ) { currentStack = nextStack ; found -- ; } if ( found == 0 ) { return currentStack ; } } throw new IllegalArgumentException ( "Stack don't have such deep." ) ; }
|
Get caller stack info .
|
1,258 |
public static long addressOf ( Object o ) { Object [ ] array = new Object [ ] { o } ; long baseOffset = THE_UNSAFE . arrayBaseOffset ( Object [ ] . class ) ; long objectAddress ; switch ( ADDRESS_SIZE ) { case 4 : objectAddress = THE_UNSAFE . getInt ( array , baseOffset ) ; break ; case 8 : objectAddress = THE_UNSAFE . getLong ( array , baseOffset ) ; break ; default : throw new IllegalStateException ( "unsupported address size: " + ADDRESS_SIZE ) ; } return objectAddress ; }
|
Get the memory address of the given object .
|
1,259 |
public T result ( ) throws NoSuchElementException { if ( result == NULL_RESULT ) { if ( parent != null ) { return parent . result ( ) ; } throw new NoSuchElementException ( "There is no result" ) ; } return result ; }
|
Get the result .
|
1,260 |
public static void addInputMap ( Node node , InputMap < ? > im ) { setInputMapUnsafe ( node , InputMap . sequence ( im , getInputMap ( node ) ) ) ; }
|
Adds the given input map to the start of the node s list of input maps so that an event will be pattern - matched against the given input map before being pattern - matched against any other input maps currently installed in the node .
|
1,261 |
public static void addFallbackInputMap ( Node node , InputMap < ? > im ) { setInputMapUnsafe ( node , InputMap . sequence ( getInputMap ( node ) , im ) ) ; }
|
Adds the given input map to the end of the node s list of input maps so that an event will be pattern - matched against all other input maps currently installed in the node before being pattern - matched against the given input map .
|
1,262 |
public static < S , E extends Event > InputMapTemplate < S , E > sequence ( InputMapTemplate < S , ? extends E > ... templates ) { return new TemplateChain < > ( templates ) ; }
|
Creates a single InputMapTemplate that pattern matches a given event type against all the given InputMapTemplates . This is often the InputMapTemplate installed on a given node since it contains all the other InputMapTemplates .
|
1,263 |
public List < String > split ( String content , String separatorCssSelector ) { return split ( content , separatorCssSelector , JoinSeparator . NO ) ; }
|
Splits the given HTML content into partitions based on the given separator selector . The separators themselves are dropped from the results .
|
1,264 |
private static String outerHtml ( List < Element > elements ) { switch ( elements . size ( ) ) { case 0 : return "" ; case 1 : return elements . get ( 0 ) . outerHtml ( ) ; default : { Element root = new Element ( Tag . valueOf ( "div" ) , "" ) ; for ( Element elem : elements ) { root . appendChild ( elem ) ; } return root . html ( ) ; } } }
|
Outputs the list of partition root elements to HTML .
|
1,265 |
private List < Element > extractElements ( String content , String selector , int amount ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; if ( elements . size ( ) > 0 ) { elements = filterParents ( elements ) ; if ( amount >= 0 ) { elements = elements . subList ( 0 , Math . min ( amount , elements . size ( ) ) ) ; } for ( Element element : elements ) { element . remove ( ) ; } } List < Element > results = new ArrayList < Element > ( ) ; results . add ( body ) ; results . addAll ( elements ) ; return results ; }
|
Extracts elements from the HTML content .
|
1,266 |
private static List < Element > filterParents ( List < Element > elements ) { List < Element > filtered = new ArrayList < Element > ( ) ; for ( Element element : elements ) { List < Element > parentsInter = element . parents ( ) ; parentsInter . retainAll ( elements ) ; if ( parentsInter . isEmpty ( ) ) { filtered . add ( element ) ; } } return filtered ; }
|
Filters the list of elements to only contain parent elements . This is to avoid both parent and child being in the list of elements .
|
1,267 |
public String setAttr ( String content , String selector , String attributeKey , String value ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; if ( elements . size ( ) > 0 ) { for ( Element element : elements ) { element . attr ( attributeKey , value ) ; } return body . html ( ) ; } else { return content ; } }
|
Sets attribute to the given value on elements in HTML .
|
1,268 |
public List < String > getAttr ( String content , String selector , String attributeKey ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; List < String > attrs = new ArrayList < String > ( ) ; for ( Element element : elements ) { String attrValue = element . attr ( attributeKey ) ; attrs . add ( attrValue ) ; } return attrs ; }
|
Retrieves attribute value on elements in HTML . Will return all attribute values for the selector since there can be more than one element .
|
1,269 |
public String addClass ( String content , String selector , String className ) { return addClass ( content , selector , Collections . singletonList ( className ) ) ; }
|
Adds given class to the elements in HTML .
|
1,270 |
public String wrap ( String content , String selector , String wrapHtml , int amount ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; if ( amount >= 0 ) { elements = elements . subList ( 0 , Math . min ( amount , elements . size ( ) ) ) ; } if ( elements . size ( ) > 0 ) { for ( Element element : elements ) { element . wrap ( wrapHtml ) ; } return body . html ( ) ; } else { return content ; } }
|
Wraps elements in HTML with the given HTML .
|
1,271 |
public String remove ( String content , String selector ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; if ( elements . size ( ) > 0 ) { for ( Element element : elements ) { element . remove ( ) ; } return body . html ( ) ; } else { return content ; } }
|
Removes elements from HTML .
|
1,272 |
private static void anchorToId ( Element heading , Element anchor ) { if ( "a" . equals ( anchor . tagName ( ) ) && heading . id ( ) . isEmpty ( ) ) { String aName = anchor . attr ( "name" ) ; if ( ! aName . isEmpty ( ) ) { heading . attr ( "id" , aName ) ; anchor . remove ( ) ; } } }
|
Moves anchor name to heading id if one does not exist . Removes the anchor .
|
1,273 |
public static List < String > concat ( List < String > elements , String text , boolean append ) { List < String > concats = new ArrayList < String > ( ) ; for ( String element : elements ) { concats . add ( append ? element + text : text + element ) ; } return concats ; }
|
Utility method to concatenate a String to a list of Strings . The text can be either appended or prepended .
|
1,274 |
private static String generateUniqueId ( Set < String > ids , String idBase ) { String id = idBase ; int counter = 1 ; while ( ids . contains ( id ) ) { id = idBase + String . valueOf ( counter ++ ) ; } ids . add ( id ) ; return id ; }
|
Generated a unique ID within the given set of IDs . Appends an incrementing number for duplicates .
|
1,275 |
private static String adaptSlug ( String input , String separator ) { String nowhitespace = WHITESPACE . matcher ( input ) . replaceAll ( separator ) ; String normalized = Normalizer . normalize ( nowhitespace , Form . NFD ) ; return NONLATIN . matcher ( normalized ) . replaceAll ( "" ) ; }
|
Creates a slug but does not change capitalization .
|
1,276 |
public static Element parseBodyFragment ( String content ) { Document doc = Jsoup . parseBodyFragment ( content ) ; return doc . body ( ) ; }
|
A generic method to use jsoup parser on an arbitrary HTML body fragment . Allows writing HTML manipulations in the template without adding Java code to the class .
|
1,277 |
private Xpp3Dom getChild ( Xpp3Dom parentNode , String name ) { Xpp3Dom child = parentNode . getChild ( name ) ; if ( child != null ) { return child ; } return parentNode . getChild ( namespace + name ) ; }
|
Retrieves the child node . Tests both default name and with namespace .
|
1,278 |
public void writeTo ( SocketChannel channel ) throws IOException { channel . write ( buffer ) ; if ( buffer . remaining ( ) == 0 ) { buffer . clear ( ) ; state = BufferState . READY_TO_WRITE ; } }
|
This method try to write data from buffer to channel . Buffer changes state to READY_TO_READ only if all data were wrote to channel in other case you should call this method again
|
1,279 |
public void start ( ) { if ( workers != null ) throw new UnsupportedOperationException ( "Please shutdown connector!" ) ; if ( LOGGER . isLoggable ( Level . INFO ) ) LOGGER . info ( "Starting " + name + " with " + config . getWorkerCount ( ) + " workers" ) ; handlers = new ConcurrentLinkedQueue < TcpServerHandler > ( ) ; handlers . add ( new TcpServerAcceptor ( config , handlers ) ) ; workers = new Thread [ config . getWorkerCount ( ) ] ; for ( int i = 0 ; i < workers . length ; i ++ ) { workers [ i ] = new TcpServerWorker ( handlers ) ; } for ( final Thread worker : workers ) worker . start ( ) ; if ( LOGGER . isLoggable ( Level . INFO ) ) LOGGER . info ( name + " started" ) ; }
|
This method starts waiting incoming connections for proxy to remote host . Method return control when all worker will be started it isn t block .
|
1,280 |
public void shutdown ( ) { if ( workers == null ) { if ( LOGGER . isLoggable ( Level . INFO ) ) LOGGER . info ( name + " already been shutdown" ) ; return ; } if ( LOGGER . isLoggable ( Level . INFO ) ) LOGGER . info ( "Starting shutdown " + name ) ; for ( final Thread worker : workers ) { worker . interrupt ( ) ; try { worker . join ( ) ; } catch ( InterruptedException exception ) { Thread . currentThread ( ) . interrupt ( ) ; } } workers = null ; TcpServerHandler handler ; while ( ( handler = handlers . poll ( ) ) != null ) handler . destroy ( ) ; handlers = null ; if ( LOGGER . isLoggable ( Level . INFO ) ) LOGGER . info ( name + " was shutdown" ) ; }
|
Shutdown connector .
|
1,281 |
protected boolean isSamlSoapResponse ( HttpResponse res ) { boolean isSamlSoap = false ; if ( res . getFirstHeader ( HttpHeaders . CONTENT_TYPE ) != null ) { ContentType contentType = ContentType . parse ( res . getFirstHeader ( HttpHeaders . CONTENT_TYPE ) . getValue ( ) ) ; isSamlSoap = MIME_TYPE_PAOS . equals ( contentType . getMimeType ( ) ) ; } return isSamlSoap ; }
|
Checks whether the HttpResponse is a SAML SOAP message
|
1,282 |
protected org . opensaml . saml2 . ecp . RelayState captureRelayState ( org . opensaml . ws . soap . soap11 . Envelope soapEnvelope ) { RelayState relayState = null ; if ( ! soapEnvelope . getHeader ( ) . getUnknownXMLObjects ( RelayState . DEFAULT_ELEMENT_NAME ) . isEmpty ( ) ) { relayState = ( RelayState ) soapEnvelope . getHeader ( ) . getUnknownXMLObjects ( RelayState . DEFAULT_ELEMENT_NAME ) . get ( 0 ) ; relayState . detach ( ) ; log . trace ( "Relay state: captured" ) ; } return relayState ; }
|
Captures the ECP relay state in a SAML SOAP message
|
1,283 |
protected org . opensaml . ws . soap . soap11 . Envelope getSoapMessage ( HttpEntity entity ) throws ClientProtocolException , IllegalStateException , IOException { Envelope soapEnvelope = ( Envelope ) unmarshallMessage ( parserPool , entity . getContent ( ) ) ; EntityUtils . consumeQuietly ( entity ) ; return soapEnvelope ; }
|
Extracts the SOAP message from the HttpResponse
|
1,284 |
public RequestBuilder < Resource > set ( final String name , final File file ) { return set ( name , file != null ? new FileBody ( file ) : null ) ; }
|
Adds a file to the request also making the request to become a multi - part post request or removes any file registered under the given name if the file value is null .
|
1,285 |
public RequestBuilder < Resource > set ( final String name , final ContentBody contentBody ) { if ( contentBody != null ) files . put ( name , contentBody ) ; else files . remove ( name ) ; return this ; }
|
Adds an ContentBody object .
|
1,286 |
public String [ ] get ( final String name ) { if ( has ( name ) ) { List < String > values = parameters . get ( name ) . getValues ( ) ; Collections . sort ( values ) ; return values . toArray ( new String [ values . size ( ) ] ) ; } else return null ; }
|
Returns the current values of the parameters in natural sort order or null if none .
|
1,287 |
public String [ ] getNames ( ) { String [ ] result = new String [ parameters . size ( ) ] ; parameters . keySet ( ) . toArray ( result ) ; return result ; }
|
Returns the parameter names in the order they where added .
|
1,288 |
public String [ ] get ( final String name ) { if ( has ( name ) ) { List < String > values = headers . get ( name ) . getValues ( ) ; return values . toArray ( new String [ values . size ( ) ] ) ; } else return null ; }
|
Returns the current values of the headers in natural sort order or null if none .
|
1,289 |
public String [ ] getNames ( ) { String [ ] result = new String [ headers . size ( ) ] ; headers . keySet ( ) . toArray ( result ) ; return result ; }
|
Returns the header names in the order they where added .
|
1,290 |
public static File newFile ( String fileName ) { File file = new File ( fileName ) ; if ( file . exists ( ) ) file . delete ( ) ; return file ; }
|
Returns a new File object from the given fileName and deleting the file if already exists .
|
1,291 |
private void setupClient ( final AbstractHttpClient client ) { this . client . addResponseInterceptor ( new HttpResponseInterceptor ( ) { public void process ( final HttpResponse response , final HttpContext context ) throws HttpException , IOException { Header header = response . getFirstHeader ( "Location" ) ; if ( header != null ) context . setAttribute ( "Location" , header . getValue ( ) ) ; } } ) ; }
|
This method is used to capture Location headers after HttpClient redirect handling .
|
1,292 |
@ SuppressWarnings ( "unchecked" ) public < T extends Resource > T request ( final HttpRequestBase request ) { try { HttpResponse response = execute ( client , request ) ; Resource resource = toPage ( request , response ) ; return ( T ) resource ; } catch ( Exception e ) { throw MechanizeExceptionFactory . newException ( e ) ; } }
|
Returns the resource received uppon the request . The resource can be casted to any expected subclass of resource but will fail with ClassCastException if the expected type of resource is not the actual returned resource .
|
1,293 |
private void addGeneralSiblingElements ( ) { for ( Node node : nodes ) { Node n = helper . getNextSibling ( node ) ; while ( n != null ) { String tag = selector . getTagName ( ) ; if ( helper . nameMatches ( n , tag ) ) result . add ( n ) ; n = helper . getNextSibling ( n ) ; } } }
|
Add general sibling elements .
|
1,294 |
@ SuppressWarnings ( "unchecked" ) public < T extends Resource > T click ( ) { return ( T ) ( hasAttribute ( "href" ) ? doRequest ( href ( ) ) . get ( ) : null ) ; }
|
Follows the link by using the original agent .
|
1,295 |
public Cookie get ( String name , String domain ) { for ( Cookie cookie : this ) { if ( cookie . getName ( ) . equals ( name ) && cookie . getDomain ( ) . equals ( domain ) ) return cookie ; } return null ; }
|
Returns the cookie with the given name and for the given domain or null .
|
1,296 |
public List < Cookie > getAll ( ) { List < Cookie > cookies = new ArrayList < Cookie > ( ) ; for ( org . apache . http . cookie . Cookie cookie : getStore ( ) . getCookies ( ) ) cookies . add ( getCookie ( cookie ) ) ; return cookies ; }
|
Returns a list of all cookies currently managed by the underlying http client .
|
1,297 |
public void addAllCloned ( List < Cookie > cookies ) { for ( Cookie cookie : cookies ) { Cookie clone = new Cookie ( cookie ) ; getStore ( ) . addCookie ( clone . getHttpCookie ( ) ) ; } }
|
Adds all cookies by actually cloning them .
|
1,298 |
public void remove ( Cookie cookie ) { cookie . getHttpCookie ( ) . setExpiryDate ( new Date ( 0 ) ) ; cookieRepresentationCache . remove ( cookie . getHttpCookie ( ) ) ; getStore ( ) . clearExpired ( new Date ( 1 ) ) ; }
|
Removes the current cookie by changing the expired date and force the store to remove all expired for a given date . The date will be set to a time of 1970 .
|
1,299 |
public String getTitle ( ) { HtmlElement title = htmlElements ( ) . find ( "title" ) ; return title != null ? title . getText ( ) : null ; }
|
Returns the title of the page or null .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.