idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
125,100 | private static boolean isFloat ( Number n ) { if ( n instanceof Float ) { return true ; } try { float f = Float . parseFloat ( String . valueOf ( n ) ) ; return ! Float . isInfinite ( f ) ; } catch ( NumberFormatException e ) { return false ; } } | Finds out if n represents a Float . |
125,101 | private static boolean isInteger ( Number n ) { if ( n instanceof Integer ) { return true ; } try { Integer . parseInt ( String . valueOf ( n ) ) ; return true ; } catch ( NumberFormatException e ) { return false ; } } | Finds out if n represents an Integer . |
125,102 | private static boolean isLong ( Number n ) { if ( n instanceof Long ) { return true ; } try { Long . parseLong ( String . valueOf ( n ) ) ; return true ; } catch ( NumberFormatException e ) { return false ; } } | Finds out if n represents a Long . |
125,103 | public static JSONFunction parse ( String str ) { if ( ! JSONUtils . isFunction ( str ) ) { throw new JSONException ( "String is not a function. " + str ) ; } else { String params = JSONUtils . getFunctionParams ( str ) ; String text = JSONUtils . getFunctionBody ( str ) ; return new JSONFunction ( ( params != null ) ?... | Constructs a JSONFunction from a text representation |
125,104 | public static int [ ] getDimensions ( JSONArray jsonArray ) { if ( jsonArray == null || jsonArray . isEmpty ( ) ) { return new int [ ] { 0 } ; } List dims = new ArrayList ( ) ; processArrayDimensions ( jsonArray , dims , 0 ) ; int [ ] dimensions = new int [ dims . size ( ) ] ; int j = 0 ; for ( Iterator i = dims . iter... | Returns the number of dimensions suited for a java array . |
125,105 | public static Object toArray ( JSONArray jsonArray , Class objectClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; return toArray ( jsonArray , jsonConfig ) ; } | Creates a java array from a JSONArray . |
125,106 | public static Collection toCollection ( JSONArray jsonArray , Class objectClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; return toCollection ( jsonArray , jsonConfig ) ; } | Creates a Collection from a JSONArray . |
125,107 | public static List toList ( JSONArray jsonArray , Class objectClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; return toList ( jsonArray , jsonConfig ) ; } | Creates a List from a JSONArray . |
125,108 | public JSONArray element ( Collection value , JsonConfig jsonConfig ) { if ( value instanceof JSONArray ) { elements . add ( value ) ; return this ; } else { return element ( _fromCollection ( value , jsonConfig ) ) ; } } | Append a value in the JSONArray where the value will be a JSONArray which is produced from a Collection . |
125,109 | private static JSONArray _fromArray ( Enum e , JsonConfig jsonConfig ) { if ( ! addInstance ( e ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( e ) ; } catch ( JSONException jsone ) { removeInstance ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( ... | Construct a JSONArray from an Enum value . |
125,110 | protected static void fireArrayEndEvent ( JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) listeners . next ( ) ; try { listener... | Fires an end of array event . |
125,111 | protected static void fireArrayStartEvent ( JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) listeners . next ( ) ; try { listen... | Fires a start of array event . |
125,112 | protected static void fireElementAddedEvent ( int index , Object element , JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) list... | Fires an element added event . |
125,113 | protected static void fireErrorEvent ( JSONException jsone , JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) listeners . next (... | Fires an error event . |
125,114 | protected static void fireObjectEndEvent ( JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) listeners . next ( ) ; try { listene... | Fires an end of object event . |
125,115 | protected static void fireObjectStartEvent ( JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) listeners . next ( ) ; try { liste... | Fires a start of object event . |
125,116 | protected static void firePropertySetEvent ( String key , Object value , boolean accumulated , JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( Json... | Fires a property set event . |
125,117 | protected static void fireWarnEvent ( String warning , JsonConfig jsonConfig ) { if ( jsonConfig . isEventTriggeringEnabled ( ) ) { for ( Iterator listeners = jsonConfig . getJsonEventListeners ( ) . iterator ( ) ; listeners . hasNext ( ) ; ) { JsonEventListener listener = ( JsonEventListener ) listeners . next ( ) ; t... | Fires a warning event . |
125,118 | protected static void removeInstance ( Object instance ) { Set set = getCycleSet ( ) ; set . remove ( instance ) ; if ( set . size ( ) == 0 ) { cycleSet . remove ( ) ; } } | Removes a reference for cycle detection check . |
125,119 | public static boolean isValidJsonValue ( Object value ) { if ( JSONNull . getInstance ( ) . equals ( value ) || value instanceof JSON || value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long || value instanceof Double || value instanceof BigInte... | Verifies if value is a valid JSON value . |
125,120 | public void reset ( ) { excludes = EMPTY_EXCLUDES ; ignoreDefaultExcludes = false ; ignoreTransientFields = false ; ignorePublicFields = true ; javascriptCompliant = false ; javaIdentifierTransformer = DEFAULT_JAVA_IDENTIFIER_TRANSFORMER ; cycleDetectionStrategy = DEFAULT_CYCLE_DETECTION_STRATEGY ; skipJavaIdentifierTr... | Resets all values to its default state . |
125,121 | public HttpResponse sendRequest ( PiwikRequest request ) throws IOException { HttpClient client = getHttpClient ( ) ; uriBuilder . replaceQuery ( request . getUrlEncodedQueryString ( ) ) ; HttpGet get = new HttpGet ( uriBuilder . build ( ) ) ; try { return client . execute ( get ) ; } finally { get . releaseConnection ... | Send a request . |
125,122 | public HttpResponse sendBulkRequest ( Iterable < PiwikRequest > requests , String authToken ) throws IOException { if ( authToken != null && authToken . length ( ) != PiwikRequest . AUTH_TOKEN_LENGTH ) { throw new IllegalArgumentException ( authToken + " is not " + PiwikRequest . AUTH_TOKEN_LENGTH + " characters long."... | Send multiple requests in a single HTTP call . More efficient than sending several individual requests . Specify the AuthToken if parameters that require an auth token is used . |
125,123 | protected HttpClient getHttpClient ( ) { HttpClientBuilder builder = HttpClientBuilder . create ( ) ; if ( proxyHost != null && proxyPort != 0 ) { HttpHost proxy = new HttpHost ( proxyHost , proxyPort ) ; DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner ( proxy ) ; builder . setRoutePlanner ( routeP... | Get a HTTP client . With proxy if a proxy is provided in the constructor . |
125,124 | JsonArray toJsonArray ( ) { JsonArrayBuilder ab = Json . createArrayBuilder ( ) ; ab . add ( sku ) ; ab . add ( name ) ; ab . add ( category ) ; ab . add ( price ) ; ab . add ( quantity ) ; return ab . build ( ) ; } | Returns the value of this EcommerceItem as a JsonArray . |
125,125 | public List getCustomTrackingParameter ( String key ) { if ( key == null ) { throw new NullPointerException ( "Key cannot be null." ) ; } List l = customTrackingParameters . get ( key ) ; if ( l == null ) { return new ArrayList ( 0 ) ; } return new ArrayList ( l ) ; } | Gets the list of objects currently stored at the specified custom tracking parameter . An empty list will be returned if there are no objects set at that key . |
125,126 | public void addCustomTrackingParameter ( String key , Object value ) { if ( key == null ) { throw new NullPointerException ( "Key cannot be null." ) ; } if ( value == null ) { throw new NullPointerException ( "Cannot add a null custom tracking parameter." ) ; } else { List l = customTrackingParameters . get ( key ) ; i... | Add a custom tracking parameter to the specified key . This allows users to have multiple parameters with the same name and different values commonly used during situations where list parameters are needed |
125,127 | public void setGoalRevenue ( Double goalRevenue ) { if ( goalRevenue != null && getGoalId ( ) == null ) { throw new IllegalStateException ( "GoalId must be set before GoalRevenue can be set." ) ; } setParameter ( GOAL_REVENUE , goalRevenue ) ; } | Set a monetary value that was generated as revenue by this goal conversion . Only used if idgoal is specified in the request . |
125,128 | public void setPageCustomVariable ( String key , String value ) { if ( value == null ) { removeCustomVariable ( PAGE_CUSTOM_VARIABLE , key ) ; } else { setCustomVariable ( PAGE_CUSTOM_VARIABLE , new CustomVariable ( key , value ) , null ) ; } } | Set a page custom variable with the specified key and value at the first available index . All page custom variables with this key will be overwritten or deleted |
125,129 | public void setSearchCategory ( String searchCategory ) { if ( searchCategory != null && getSearchQuery ( ) == null ) { throw new IllegalStateException ( "SearchQuery must be set before SearchCategory can be set." ) ; } setParameter ( SEARCH_CATEGORY , searchCategory ) ; } | Specify a search category with this parameter . SearchQuery must first be set . |
125,130 | public void setUserCustomVariable ( String key , String value ) { if ( value == null ) { removeCustomVariable ( VISIT_CUSTOM_VARIABLE , key ) ; } else { setCustomVariable ( VISIT_CUSTOM_VARIABLE , new CustomVariable ( key , value ) , null ) ; } } | Set a visit custom variable with the specified key and value at the first available index . All visit custom variables with this key will be overwritten or deleted |
125,131 | public String getQueryString ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( Entry < String , Object > parameter : parameters . entrySet ( ) ) { if ( sb . length ( ) > 0 ) { sb . append ( "&" ) ; } sb . append ( parameter . getKey ( ) ) ; sb . append ( "=" ) ; sb . append ( parameter . getValue ( ) . toString ( ... | Get the query string represented by this object . |
125,132 | public String getUrlEncodedQueryString ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( Entry < String , Object > parameter : parameters . entrySet ( ) ) { if ( sb . length ( ) > 0 ) { sb . append ( "&" ) ; } try { StringBuilder sb2 = new StringBuilder ( ) ; sb2 . append ( parameter . getKey ( ) ) ; sb2 . append ... | Get the url encoded query string represented by this object . |
125,133 | public static String getRandomHexString ( int length ) { byte [ ] bytes = new byte [ length / 2 ] ; new Random ( ) . nextBytes ( bytes ) ; return DatatypeConverter . printHexBinary ( bytes ) ; } | Get a random hexadecimal string of a specified length . |
125,134 | private void setParameter ( String key , Object value ) { if ( value == null ) { parameters . remove ( key ) ; } else { parameters . put ( key , value ) ; } } | Set a stored parameter . |
125,135 | private void setNonEmptyStringParameter ( String key , String value ) { if ( value == null ) { parameters . remove ( key ) ; } else if ( value . length ( ) == 0 ) { throw new IllegalArgumentException ( "Value cannot be empty." ) ; } else { parameters . put ( key , value ) ; } } | Set a stored parameter and verify it is a non - empty string . |
125,136 | private Boolean getBooleanParameter ( String key ) { Integer i = ( Integer ) parameters . get ( key ) ; if ( i == null ) { return null ; } return i . equals ( 1 ) ; } | Get a stored parameter that is a boolean . |
125,137 | private void setBooleanParameter ( String key , Boolean value ) { if ( value == null ) { parameters . remove ( key ) ; } else if ( value ) { parameters . put ( key , 1 ) ; } else { parameters . put ( key , 0 ) ; } } | Set a stored parameter that is a boolean . This value will be stored as 1 for true and 0 for false . |
125,138 | private CustomVariable getCustomVariable ( String parameter , int index ) { CustomVariableList cvl = ( CustomVariableList ) parameters . get ( parameter ) ; if ( cvl == null ) { return null ; } return cvl . get ( index ) ; } | Get a value that is stored in a json object at the specified parameter . |
125,139 | private void setCustomVariable ( String parameter , CustomVariable customVariable , Integer index ) { CustomVariableList cvl = ( CustomVariableList ) parameters . get ( parameter ) ; if ( cvl == null ) { cvl = new CustomVariableList ( ) ; parameters . put ( parameter , cvl ) ; } if ( customVariable == null ) { cvl . re... | Store a value in a json object at the specified parameter . |
125,140 | private JsonValue getFromJsonArray ( String key , int index ) { PiwikJsonArray a = ( PiwikJsonArray ) parameters . get ( key ) ; if ( a == null ) { return null ; } return a . get ( index ) ; } | Get the value at the specified index from the json array at the specified parameter . |
125,141 | private void addToJsonArray ( String key , JsonValue value ) { if ( value == null ) { throw new NullPointerException ( "Value cannot be null." ) ; } PiwikJsonArray a = ( PiwikJsonArray ) parameters . get ( key ) ; if ( a == null ) { a = new PiwikJsonArray ( ) ; parameters . put ( key , a ) ; } a . add ( value ) ; } | Add a value to the json array at the specified parameter |
125,142 | private Memory readChunkOffsets ( DataInput input ) { try { int chunkCount = input . readInt ( ) ; Memory offsets = Memory . allocate ( chunkCount * 8 ) ; for ( int i = 0 ; i < chunkCount ; i ++ ) { try { offsets . setLong ( i * 8 , input . readLong ( ) ) ; } catch ( EOFException e ) { String msg = String . format ( "C... | Read offsets of the individual chunks from the given input . |
125,143 | public static SSTableIndexIndex readIndex ( final FileSystem fileSystem , final Path sstablePath ) throws IOException { final Closer closer = Closer . create ( ) ; final Path indexPath = sstablePath . suffix ( SSTABLE_INDEX_SUFFIX ) ; final FSDataInputStream inputStream = closer . register ( fileSystem . open ( indexPa... | Read an existing index . Reads and returns the index index which is a list of chunks defined by the Cassandra Index . db file along with the configured split size . |
125,144 | public OutputCommitter getOutputCommitter ( TaskAttemptContext taskAttemptContext ) throws IOException , InterruptedException { return new OutputCommitter ( ) { public void setupJob ( JobContext jobContext ) throws IOException { } public void cleanupJob ( JobContext jobContext ) throws IOException { } public void setup... | and writes to that instead . |
125,145 | public static CFMetaData parseCreateStatement ( String cql ) throws RequestValidationException { final CreateColumnFamilyStatement statement = ( CreateColumnFamilyStatement ) QueryProcessor . parseStatement ( cql ) . prepare ( ) . statement ; final CFMetaData cfm = new CFMetaData ( "assess" , "kvs_strict" , ColumnFamil... | Parses a CQL CREATE statement into its CFMetaData object |
125,146 | public long next ( ) { try { ByteBufferUtil . readWithShortLength ( input ) ; final long offset = input . readLong ( ) ; skipPromotedIndex ( input ) ; return offset ; } catch ( IOException e ) { throw new IOError ( e ) ; } } | Get the next offset from the SSTable index . |
125,147 | private void skipPromotedIndex ( final DataInput in ) throws IOException { final int size = in . readInt ( ) ; if ( size <= 0 ) { return ; } FileUtils . skipBytesFully ( in , size ) ; } | Convenience method for skipping promoted index from SSTable index file . |
125,148 | private Collection < FileStatus > handleFile ( final FileStatus file , final JobContext job ) throws IOException { final List < FileStatus > results = Lists . newArrayList ( ) ; if ( file . isDir ( ) ) { final Path p = file . getPath ( ) ; LOG . debug ( "Expanding {}" , p ) ; final FileSystem fs = p . getFileSystem ( j... | If we have a directory recursively gather the files we care about for this job . |
125,149 | public final long hash ( byte [ ] data , int c , int d ) { return SipHasher . hash ( c , d , this . v0 , this . v1 , this . v2 , this . v3 , data ) ; } | Hashes input data using the preconfigured state . |
125,150 | public final SipHasherStream update ( byte b ) { this . len ++ ; this . m |= ( ( ( long ) b & 0xff ) << ( this . m_idx ++ * 8 ) ) ; if ( this . m_idx < 8 ) { return this ; } this . v3 ^= this . m ; for ( int i = 0 ; i < this . c ; i ++ ) { round ( ) ; } this . v0 ^= this . m ; this . m_idx = 0 ; this . m = 0 ; return t... | Updates the hash with a single byte . |
125,151 | public final long digest ( ) { byte msgLenMod256 = this . len ; while ( this . m_idx < 7 ) { update ( ( byte ) 0 ) ; } update ( msgLenMod256 ) ; this . v2 ^= 0xff ; for ( int i = 0 ; i < this . d ; i ++ ) { round ( ) ; } return this . v0 ^ this . v1 ^ this . v2 ^ this . v3 ; } | Finalizes the digest and returns the hash . |
125,152 | private void round ( ) { this . v0 += this . v1 ; this . v2 += this . v3 ; this . v1 = rotateLeft ( this . v1 , 13 ) ; this . v3 = rotateLeft ( this . v3 , 16 ) ; this . v1 ^= this . v0 ; this . v3 ^= this . v2 ; this . v0 = rotateLeft ( this . v0 , 32 ) ; this . v2 += this . v1 ; this . v0 += this . v3 ; this . v1 = r... | SipRound implementation for internal use . |
125,153 | public static long hash ( byte [ ] key , byte [ ] data , int c , int d ) { if ( key . length != 16 ) { throw new IllegalArgumentException ( "Key must be exactly 16 bytes!" ) ; } long k0 = bytesToLong ( key , 0 ) ; long k1 = bytesToLong ( key , 8 ) ; return hash ( c , d , INITIAL_V0 ^ k0 , INITIAL_V1 ^ k1 , INITIAL_V2 ^... | Hashes a data input for a given key using the provided rounds of compression . |
125,154 | public static String toHexString ( long hash ) { String hex = Long . toHexString ( hash ) ; if ( hex . length ( ) == 16 ) { return hex ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 , j = 16 - hex . length ( ) ; i < j ; i ++ ) { sb . append ( '0' ) ; } return sb . append ( hex ) . toString ( ) ; } | Converts a hash to a hexidecimal representation . |
125,155 | static long bytesToLong ( byte [ ] bytes , int offset ) { long m = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { m |= ( ( ( ( long ) bytes [ i + offset ] ) & 0xff ) << ( 8 * i ) ) ; } return m ; } | Converts a chunk of 8 bytes to a number in little endian . |
125,156 | static long hash ( int c , int d , long v0 , long v1 , long v2 , long v3 , byte [ ] data ) { long m ; int last = data . length / 8 * 8 ; int i = 0 ; int r ; while ( i < last ) { m = data [ i ++ ] & 0xffL ; for ( r = 1 ; r < 8 ; r ++ ) { m |= ( data [ i ++ ] & 0xffL ) << ( r * 8 ) ; } v3 ^= m ; for ( r = 0 ; r < c ; r +... | Internal 0A hashing implementation . |
125,157 | public static < T extends Value > List < List < T > > split ( List < T > input , long targetSize ) { Collections . sort ( input , new Comparator < Value > ( ) { public int compare ( Value o1 , Value o2 ) { return new Long ( o1 . getValue ( ) ) . compareTo ( new Long ( o2 . getValue ( ) ) ) ; } } ) ; List < T > smaller ... | things that are too big get their own set |
125,158 | private boolean checkCombineValidity ( Pail p , CopyArgs args ) throws IOException { if ( args . force ) return true ; PailSpec mine = getSpec ( ) ; PailSpec other = p . getSpec ( ) ; PailStructure structure = mine . getStructure ( ) ; boolean typesSame = structure . getType ( ) . equals ( other . getStructure ( ) . ge... | returns if formats are same |
125,159 | public void copyAppend ( Pail p , CopyArgs args ) throws IOException { args = new CopyArgs ( args ) ; if ( args . renameMode == null ) args . renameMode = RenameMode . ALWAYS_RENAME ; boolean formatsSame = checkCombineValidity ( p , args ) ; String sourceQual = getQualifiedRoot ( p ) ; String destQual = getQualifiedRoo... | Copy append will copy all the files from p into this pail . Appending maintains the structure that was present in p . |
125,160 | public static boolean isLong ( String input ) { try { Long . parseLong ( input ) ; return true ; } catch ( Exception e ) { return false ; } } | Return true or false if the input is a long |
125,161 | private void parseAnnotatableText ( String text , Element parent ) { AnnotationNode annotation = null ; Matcher matcher = AnnotationParser . WIDGET_ANNOTATION_REGEX . matcher ( text ) ; int previousEnd = 0 ; while ( matcher . find ( ) ) { int start = matcher . start ( ) ; if ( start > previousEnd ) { String segment = t... | Pulls a text segment apart by annotations within it and creates multiple Text Nodes applying the annotation to each text segment as approriate . |
125,162 | private void addTextNodeToParent ( String text , Element parent , AnnotationNode annotation ) { String [ ] lines = new String [ ] { text } ; if ( annotation != null ) lines = splitInTwo ( text ) ; for ( int i = 0 ; i < lines . length ; i ++ ) { TextNode textNode = TextNode . createFromEncoded ( lines [ i ] , baseUri ) ... | Break the text up by the first line delimiter . We only want annotations applied to the first line of a block of text and not to a whole segment . |
125,163 | private String [ ] splitInTwo ( String text ) { Matcher matcher = LINE_SEPARATOR . matcher ( text ) ; while ( matcher . find ( ) ) { int start = matcher . start ( ) ; if ( start > 0 && start < text . length ( ) ) { String segment = text . substring ( 0 , start ) ; if ( segment . trim ( ) . length ( ) > 0 ) return new S... | Break a text segment apart into two at the first line delimiter which has non - whitespace characters before it . |
125,164 | boolean canContain ( Tag parent , Tag child ) { Validate . notNull ( child ) ; if ( child . isBlock ( ) && ! parent . canContainBlock ( ) ) return false ; if ( ! child . isBlock ( ) && parent . isData ( ) ) return false ; if ( closingOptional . contains ( parent . getName ( ) ) && parent . getName ( ) . equals ( child ... | Test if this tag the prospective parent can accept the proposed child . |
125,165 | static String readAnnotationValue ( Annotation annotation ) { try { Method m = annotation . getClass ( ) . getMethod ( "value" ) ; return ( String ) m . invoke ( annotation ) ; } catch ( NoSuchMethodException e ) { throw new IllegalStateException ( "Encountered a configured annotation that " + "has no value parameter. ... | A simple utility method that reads the String value attribute of any annotation instance . |
125,166 | private ParserContext singleBackingTypeParserContext ( ) throws ExpressionCompileException { ParserContext context = new ParserContext ( ) ; context . setStrongTyping ( true ) ; context . addInput ( "this" , backingType ) ; PropertyDescriptor [ ] propertyDescriptors ; try { propertyDescriptors = Introspector . getBeanI... | generates a parsing context with type information from the backing type s javabean properties |
125,167 | private static List < PathMatcher > toMatchChain ( String path ) { String [ ] pieces = path . split ( PATH_SEPARATOR ) ; List < PathMatcher > matchers = new ArrayList < PathMatcher > ( ) ; for ( String piece : pieces ) { matchers . add ( ( piece . startsWith ( ":" ) ) ? new GreedyPathMatcher ( piece ) : new SimplePathM... | converts a string path to a tree of heterogenous matchers |
125,168 | public synchronized boolean connect ( final DisconnectListener listener ) { reset ( ) ; ChannelFuture future = bootstrap . connect ( new InetSocketAddress ( config . getHost ( ) , config . getPort ( ) ) ) ; Channel channel = future . awaitUninterruptibly ( ) . getChannel ( ) ; if ( ! future . isSuccess ( ) ) { throw ne... | Connects to the IMAP server logs in with the given credentials . |
125,169 | public synchronized void disconnect ( ) { try { if ( ! mailClientHandler . isHalted ( ) ) { if ( mailClientHandler . idleRequested . get ( ) ) { log . warn ( "Disconnect called while IDLE, leaving idle and logging out." ) ; done ( ) ; } channel . write ( ". logout\n" ) ; } currentFolder = null ; } catch ( Exception e )... | Logs out of the current IMAP session and releases all resources including executor services . |
125,170 | public static List < Token > tokenize ( String warpRawText , EvaluatorCompiler compiler ) throws ExpressionCompileException { ArrayList < Token > tokens = new ArrayList < Token > ( ) ; char [ ] characters = warpRawText . toCharArray ( ) ; StringBuilder token = new StringBuilder ( ) ; TokenizerState state = TokenizerSta... | tokenizes text into raw text chunks interspersed with expression chunks |
125,171 | private void collectBindings ( List < SitebricksModule . LinkingBinder > bindings , Set < PageBook . Page > pagesToCompile ) { Map < Class < ? extends Annotation > , String > methodSet = null ; for ( SitebricksModule . LinkingBinder binding : bindings ) { if ( EMBEDDED == binding . bindingKind ) { if ( null == binding ... | processes all explicit bindings including static resources . |
125,172 | private Set < PageBook . Page > scanPagesToCompile ( Set < Class < ? > > set ) { Set < Templates . Descriptor > templates = Sets . newHashSet ( ) ; Set < PageBook . Page > pagesToCompile = Sets . newHashSet ( ) ; for ( Class < ? > pageClass : set ) { EmbedAs embedAs = pageClass . getAnnotation ( EmbedAs . class ) ; if ... | goes through the set of scanned classes and builds pages out of them . |
125,173 | private Class < ? > nextDecoratedClassInHierarchy ( Class < ? > previousTemplateClass , Class < ? > candidate ) { if ( candidate == previousTemplateClass ) { return null ; } else if ( candidate == Object . class ) { throw new IllegalStateException ( "Did not find previous extension" ) ; } else { boolean isDecorated = c... | recursively find the next superclass with an |
125,174 | public void setBody ( String body ) { assert bodyParts . isEmpty ( ) : "Unexpected set body call to a multipart email" ; bodyParts . add ( new BodyPart ( body ) ) ; } | Short hand . |
125,175 | public Set < String > extract ( List < String > messages ) throws ExtractionException { boolean gotFetch = false ; Set < String > result = null ; String fetchStr = null ; for ( int i = 0 , messagesSize = messages . size ( ) ; i < messagesSize ; i ++ ) { String message = messages . get ( i ) ; if ( null == message || me... | Parse the response which includes label settings and command status . We expect only one FETCH response as we only set labels on one msg . |
125,176 | public void enqueue ( CommandCompletion completion ) { completions . add ( completion ) ; commandTrace . add ( new Date ( ) . toString ( ) + " " + completion . toString ( ) ) ; } | DO NOT synchronize! |
125,177 | private synchronized void complete ( String message ) { if ( MESSAGE_COULDNT_BE_FETCHED_REGEX . matcher ( message ) . matches ( ) ) { log . warn ( "Some messages in the batch could not be fetched for {}\n" + "---cmd---\n{}\n---wire---\n{}\n---end---\n" , new Object [ ] { config . getUsername ( ) , getCommandTrace ( ) ,... | This is synchronized to ensure that we process the queue serially . |
125,178 | void observe ( FolderObserver observer ) { synchronized ( idleMutex ) { this . observer = observer ; pushedData = new PushedData ( ) ; idleAcknowledged . set ( false ) ; } } | Registers a FolderObserver to receive events happening with a particular folder . Typically an IMAP IDLE feature . If called multiple times will overwrite the currently set observer . |
125,179 | public static Localization defaultLocalizationFor ( Class < ? > iface ) { Map < String , String > defaultMessages = Maps . newHashMap ( ) ; for ( Method method : iface . getMethods ( ) ) { Message msg = method . getAnnotation ( Message . class ) ; if ( null != msg ) { defaultMessages . put ( method . getName ( ) , msg ... | Returns a localization value object describing the defaults specified in the |
125,180 | public String build ( Protocol protocol , String oauthToken , String oauthTokenSecret ) throws IOException , OAuthException , URISyntaxException { OAuthAccessor accessor = new OAuthAccessor ( consumer ) ; accessor . tokenSecret = oauthTokenSecret ; Map < String , String > parameters = new HashMap < String , String > ( ... | Builds an XOAUTH SASL client response . |
125,181 | public static Class < ? > erase ( Type type ) { if ( type instanceof Class < ? > ) { return ( Class < ? > ) type ; } else if ( type instanceof ParameterizedType ) { return ( Class < ? > ) ( ( ParameterizedType ) type ) . getRawType ( ) ; } else if ( type instanceof TypeVariable < ? > ) { TypeVariable < ? > tv = ( TypeV... | Returns the erasure of the given type . |
125,182 | private static Type mapTypeParameters ( Type toMapType , Type typeAndParams ) { if ( isMissingTypeParameters ( typeAndParams ) ) { return erase ( toMapType ) ; } else { VarMap varMap = new VarMap ( ) ; Type handlingTypeAndParams = typeAndParams ; while ( handlingTypeAndParams instanceof ParameterizedType ) { Parameteri... | Maps type parameters in a type to their values . |
125,183 | private < N extends Node > WidgetChain walk ( PageCompilingContext pc , N node ) { WidgetChain widgetChain = Chains . proceeding ( ) ; for ( Node n : node . childNodes ( ) ) { if ( n instanceof Element ) { final Element child = ( Element ) n ; if ( child . tagName ( ) . equals ( "form" ) ) pc . form = ( Element ) n ; f... | Walks the DOM recursively and converts elements into corresponding sitebricks widgets . |
125,184 | private boolean lexicalClimb ( PageCompilingContext pc , Node node ) { if ( node . attr ( ANNOTATION ) . length ( ) > 1 ) { if ( REPEAT_WIDGET . equalsIgnoreCase ( node . attr ( ANNOTATION_KEY ) ) || CHOOSE_WIDGET . equalsIgnoreCase ( node . attr ( ANNOTATION_KEY ) ) ) { String [ ] keyAndContent = { node . attr ( ANNOT... | Called to push a new lexical scope onto the stack . |
125,185 | private void checkEmbedAgainst ( PageCompilingContext pc , EvaluatorCompiler compiler , Map < String , String > properties , Class < ? > embedClass , Node node ) { for ( String property : properties . keySet ( ) ) { try { if ( ! compiler . isWritable ( property ) ) { pc . errors . add ( CompileError . in ( node . outer... | Ensures that embed bound properties are writable |
125,186 | public List < Node > findSiblings ( Node node ) { Preconditions . checkNotNull ( node ) ; Node parent = node . parent ( ) ; if ( null == parent ) return null ; return parent . childNodes ( ) ; } | TESTING jsoup . nodes . Node |
125,187 | private static String cleanHtml ( final Node node ) { if ( node instanceof Element ) { Element element = ( ( Element ) node ) ; StringBuilder accum = new StringBuilder ( ) ; accum . append ( "<" ) . append ( element . tagName ( ) ) ; for ( Attribute attribute : element . attributes ( ) ) { if ( ! ( attribute . getKey (... | outerHtml from jsoup . Node Element with suppressed _attribs |
125,188 | private Object search ( Collection < ? > collection , String hashKey ) { int hash = Integer . valueOf ( hashKey ) ; for ( Object o : collection ) { if ( o . hashCode ( ) == hash ) return o ; } return null ; } | Linear collection search by hashcode |
125,189 | public AnnotationNode annotation ( String annotation ) { this . attr ( ANNOTATION , annotation ) ; String [ ] kc = AnnotationParser . extractKeyAndContent ( annotation ) ; this . attr ( ANNOTATION_KEY , kc [ 0 ] ) ; this . attr ( ANNOTATION_CONTENT , kc [ 1 ] ) ; return this ; } | Set the annotation of this node . |
125,190 | public Set < Flag > extract ( List < String > messages ) throws ExtractionException { boolean gotFetch = false ; Set < Flag > result = null ; String fetchStr = null ; for ( int i = 0 , messagesSize = messages . size ( ) ; i < messagesSize ; i ++ ) { String message = messages . get ( i ) ; if ( null == message || messag... | Parse the response which includes new flag settings and command status . We expect only one FETCH response as we only set flags on one msg . |
125,191 | protected Element getArticleTitle ( ) { Element articleTitle = mDocument . createElement ( "h1" ) ; articleTitle . html ( mDocument . title ( ) ) ; return articleTitle ; } | Get the article title as an H1 . Currently just uses document . title we might want to be smarter in the future . |
125,192 | protected void prepDocument ( ) { if ( mDocument . body ( ) == null ) { mDocument . appendElement ( "body" ) ; } Elements elementsToRemove = mDocument . getElementsByTag ( "script" ) ; for ( Element script : elementsToRemove ) { script . remove ( ) ; } elementsToRemove = getElementsByTag ( mDocument . head ( ) , "link"... | Prepare the HTML document for readability to scrape it . This includes things like stripping javascript CSS and handling terrible markup . |
125,193 | private void prepArticle ( Element articleContent ) { cleanStyles ( articleContent ) ; killBreaks ( articleContent ) ; clean ( articleContent , "form" ) ; clean ( articleContent , "object" ) ; clean ( articleContent , "h1" ) ; if ( getElementsByTag ( articleContent , "h2" ) . size ( ) == 1 ) { clean ( articleContent , ... | Prepare the article node for display . Clean out any inline styles iframes forms strip extraneous < ; p> ; tags etc . |
125,194 | private static String getInnerText ( Element e , boolean normalizeSpaces ) { String textContent = e . text ( ) . trim ( ) ; if ( normalizeSpaces ) { textContent = textContent . replaceAll ( Patterns . REGEX_NORMALIZE , "" ) ; } return textContent ; } | Get the inner text of a node - cross browser compatibly . This also strips out any excess whitespace to be found . |
125,195 | private static int getCharCount ( Element e , String s ) { if ( s == null || s . length ( ) == 0 ) { s = "," ; } return getInnerText ( e , true ) . split ( s ) . length ; } | Get the number of times a string s appears in the node e . |
125,196 | private static void cleanStyles ( Element e ) { if ( e == null ) { return ; } Element cur = e . children ( ) . first ( ) ; if ( ! "readability-styled" . equals ( e . className ( ) ) ) { e . removeAttr ( "style" ) ; } while ( cur != null ) { if ( ! "readability-styled" . equals ( cur . className ( ) ) ) { cur . removeAt... | Remove the style attribute on every e and under . |
125,197 | private static float getLinkDensity ( Element e ) { Elements links = getElementsByTag ( e , "a" ) ; int textLength = getInnerText ( e , true ) . length ( ) ; float linkLength = 0.0F ; for ( Element link : links ) { linkLength += getInnerText ( link , true ) . length ( ) ; } return linkLength / textLength ; } | Get the density of links as a percentage of the content . This is the amount of text that is inside a link divided by the total text in the node . |
125,198 | private static void killBreaks ( Element e ) { e . html ( e . html ( ) . replaceAll ( Patterns . REGEX_KILL_BREAKS , "<br />" ) ) ; } | Remove extraneous break tags from a node . |
125,199 | private void cleanConditionally ( Element e , String tag ) { Elements tagsList = getElementsByTag ( e , tag ) ; for ( Element node : tagsList ) { int weight = getClassWeight ( node ) ; dbg ( "Cleaning Conditionally (" + node . className ( ) + ":" + node . id ( ) + ")" + getContentScore ( node ) ) ; if ( weight < 0 ) { ... | Clean an element of all tags of type tag if they look fishy . Fishy is an algorithm based on content length classnames link density number of images & embeds etc . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.