idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
7,600 | private T getAndClearUnderLock ( ) throws Throwable { if ( error != null ) { throw error ; } else { // Return and clear current T retValue = data ; data = null ; return retValue ; } } | Get and clear the slot - MUST be called while holding the lock!! | 47 | 14 |
7,601 | public T take ( ) throws Throwable { dataLock . lock ( ) ; try { while ( data == null && error == null ) { try { availableCondition . await ( ) ; } catch ( InterruptedException e ) { // ignore and re-loop in case of spurious wake-ups } } // should only get to here if data or error is non-null return getAndClearUnderLock ( ) ; } finally { dataLock . unlock ( ) ; } } | Blocking read and remove . If the thread was interrupted by the producer due to an error the producer s error will be thrown . | 97 | 26 |
7,602 | public Object yyparse ( yyInput yyLex , Object yydebug ) throws java . io . IOException { //t this.yydebug = (jay.yydebug.yyDebug)yydebug; return yyparse ( yyLex ) ; } | the generated parser with debugging messages . Maintains a dynamic state and value stack . | 63 | 17 |
7,603 | private HttpClient createPooledClient ( ) { HttpParams connMgrParams = new BasicHttpParams ( ) ; SchemeRegistry schemeRegistry = new SchemeRegistry ( ) ; schemeRegistry . register ( new Scheme ( HTTP_SCHEME , PlainSocketFactory . getSocketFactory ( ) , HTTP_PORT ) ) ; schemeRegistry . register ( new Scheme ( HTTPS_SCHEME , SSLSocketFactory . getSocketFactory ( ) , HTTPS_PORT ) ) ; // All connections will be to the same endpoint, so no need for per-route configuration. // TODO See how this does in the presence of redirects. ConnManagerParams . setMaxTotalConnections ( connMgrParams , poolSize ) ; ConnManagerParams . setMaxConnectionsPerRoute ( connMgrParams , new ConnPerRouteBean ( poolSize ) ) ; ClientConnectionManager ccm = new ThreadSafeClientConnManager ( connMgrParams , schemeRegistry ) ; HttpParams httpParams = new BasicHttpParams ( ) ; HttpProtocolParams . setUseExpectContinue ( httpParams , false ) ; ConnManagerParams . setTimeout ( httpParams , acquireTimeout * 1000 ) ; return new DefaultHttpClient ( ccm , httpParams ) ; } | Creates a new thread - safe HTTP connection pool for use with a data source . | 285 | 17 |
7,604 | public void addTransition ( DuzztAction action , DuzztState succ ) { transitions . put ( action , new DuzztTransition ( action , succ ) ) ; } | Adds a transition to this state . | 39 | 7 |
7,605 | public static ObjectNode getObj ( ObjectNode obj , String fieldName ) { return obj != null ? obj ( obj . get ( fieldName ) ) : null ; } | Returns the field from a ObjectNode as ObjectNode | 35 | 10 |
7,606 | public static ObjectNode getObjAndRemove ( ObjectNode obj , String fieldName ) { ObjectNode result = null ; if ( obj != null ) { result = obj ( remove ( obj , fieldName ) ) ; } return result ; } | Removes the field from a ObjectNode and returns it as ObjectNode | 49 | 14 |
7,607 | public static ArrayNode createArray ( boolean fallbackToEmptyArray , JsonNode ... nodes ) { ArrayNode array = null ; for ( JsonNode element : nodes ) { if ( element != null ) { if ( array == null ) { array = new ArrayNode ( JsonNodeFactory . instance ) ; } array . add ( element ) ; } } if ( ( array == null ) && fallbackToEmptyArray ) { array = new ArrayNode ( JsonNodeFactory . instance ) ; } return array ; } | Creates an ArrayNode from the given nodes . Returns an empty ArrayNode if no elements are provided and fallbackToEmptyArray is true null if false . | 109 | 32 |
7,608 | public static ArrayNode getArray ( ObjectNode obj , String fieldName ) { return obj == null ? null : array ( obj . get ( fieldName ) ) ; } | Returns the field from a ObjectNode as ArrayNode | 35 | 10 |
7,609 | public static ArrayNode getArrayAndRemove ( ObjectNode obj , String fieldName ) { ArrayNode result = null ; if ( obj != null ) { result = array ( remove ( obj , fieldName ) ) ; } return result ; } | Removes the field from a ObjectNode and returns it as ArrayNode | 49 | 14 |
7,610 | public static JsonNode remove ( ObjectNode obj , String fieldName ) { JsonNode result = null ; if ( obj != null ) { result = obj . remove ( fieldName ) ; } return result ; } | Removes the field with the given name from the given ObjectNode | 45 | 13 |
7,611 | public static void rename ( ObjectNode obj , String oldFieldName , String newFieldName ) { if ( obj != null && isNotBlank ( oldFieldName ) && isNotBlank ( newFieldName ) ) { JsonNode node = remove ( obj , oldFieldName ) ; if ( node != null ) { obj . set ( newFieldName , node ) ; } } } | Renames a field in a ObjectNode from the oldFieldName to the newFieldName | 82 | 18 |
7,612 | private static final String stripParams ( String mediaType ) { int sc = mediaType . indexOf ( ' ' ) ; if ( sc >= 0 ) mediaType = mediaType . substring ( 0 , sc ) ; return mediaType ; } | Strips the parameters from the end of a mediaType description . | 51 | 14 |
7,613 | public static String getDefaultMediaType ( ResultType expectedType ) { ResponseFormat format = ( expectedType != null ) ? defaultTypeFormats . get ( expectedType ) : null ; // If the expected type is unknown, we should let the server decide, otherwise we could // wind up requesting a response type that doesn't match the actual resuts (e.g. xml with CONSTRUCT). // TODO: We could include multiple media types in the Accept: field, but that assumes that the // server has proper support for content negotiation. Many servers only look at the first value. return ( format != null ) ? format . mimeText : null ; } | Gets the default content type to use when sending a query request with the given expected result type . | 136 | 20 |
7,614 | private static final ResultParser findParser ( String mediaType , ResultType expectedType ) { ResponseFormat format = null ; // Prefer MIME type when choosing result format. if ( mediaType != null ) { mediaType = stripParams ( mediaType ) ; format = mimeFormats . get ( mediaType ) ; if ( format == null ) { logger . warn ( "Unrecognized media type ({}) in SPARQL server response" , mediaType ) ; } else { logger . debug ( "Using result format {} for media type {}" , format , mediaType ) ; } } // If MIME type was absent or unrecognized, choose default based on expected result type. if ( format == null ) { logger . debug ( "Unable to determine result format from media type" ) ; if ( expectedType != null ) { format = defaultTypeFormats . get ( expectedType ) ; logger . debug ( "Using default format {} for expected result type {}" , format , expectedType ) ; } else { format = DEFAULT_FORMAT ; logger . debug ( "No expected type provided; using default format {}" , format ) ; } } assert format != null : "Could not determine result format" ; // Validate that the chosen format can produce the expected result type. if ( expectedType != null && ! format . resultTypes . contains ( expectedType ) ) { throw new SparqlException ( "Result format " + format + " does not support expected result type " + expectedType ) ; } return format . parser ; } | Find a parser to handle the protocol response body based on the content type found in the response and the expected result type specified by the user ; if one or both fields is missing then attempts to choose a sensible default . | 323 | 43 |
7,615 | public static Filter equalsFilter ( String column , Object operand ) { return new Filter ( column , FilterOperator . EQUALS , operand ) ; } | Builds an EqualsFilter | 32 | 6 |
7,616 | public static Filter inFilter ( String column , Object operand ) { return new Filter ( column , FilterOperator . IN , operand ) ; } | Builds an InFilter | 31 | 5 |
7,617 | @ NonNull protected final View inflatePlaceholderView ( @ Nullable final View convertView , final int height ) { View view = convertView ; if ( ! ( view instanceof PlaceholderView ) ) { view = new PlaceholderView ( getContext ( ) ) ; } view . setMinimumHeight ( height ) ; return view ; } | Inflates an invisible placeholder view with a specific height . | 71 | 12 |
7,618 | protected final int getViewHeight ( @ NonNull final ListAdapter adapter , final int position ) { View view = adapter . getView ( position , null , this ) ; LayoutParams layoutParams = ( LayoutParams ) view . getLayoutParams ( ) ; if ( layoutParams == null ) { layoutParams = new LayoutParams ( LayoutParams . MATCH_PARENT , LayoutParams . WRAP_CONTENT ) ; view . setLayoutParams ( layoutParams ) ; } int widthMeasureSpec = getChildMeasureSpec ( MeasureSpec . makeMeasureSpec ( getColumnWidthCompatible ( ) , MeasureSpec . EXACTLY ) , 0 , layoutParams . width ) ; int heightMeasureSpec = getChildMeasureSpec ( MeasureSpec . makeMeasureSpec ( 0 , MeasureSpec . UNSPECIFIED ) , 0 , layoutParams . height ) ; view . measure ( widthMeasureSpec , heightMeasureSpec ) ; return view . getMeasuredHeight ( ) ; } | Returns the height of the view which corresponds to a specific position of an adapter . | 210 | 16 |
7,619 | private OnItemClickListener createItemClickListener ( @ NonNull final OnItemClickListener encapsulatedListener ) { return new OnItemClickListener ( ) { @ Override public void onItemClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { encapsulatedListener . onItemClick ( parent , view , getItemPosition ( position ) , id ) ; } } ; } | Creates and returns a listener which encapsulates another listener in order to be able to adapt the position of the item which has been clicked . | 88 | 28 |
7,620 | private OnItemLongClickListener createItemLongClickListener ( @ NonNull final OnItemLongClickListener encapsulatedListener ) { return new OnItemLongClickListener ( ) { @ Override public boolean onItemLongClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { return encapsulatedListener . onItemLongClick ( parent , view , getItemPosition ( position ) , id ) ; } } ; } | Creates and returns a listener which encapsulates another listener in order to be able to adapt the position of the item which has been long - clicked . | 95 | 30 |
7,621 | private int getItemPosition ( final int position ) { int numColumns = getNumColumnsCompatible ( ) ; int headerItemCount = getHeaderViewsCount ( ) * numColumns ; int adapterCount = adapter . getEncapsulatedAdapter ( ) . getCount ( ) ; if ( position < headerItemCount ) { return position / numColumns ; } else if ( position < headerItemCount + adapterCount + getNumberOfPlaceholderViews ( ) ) { return position - headerItemCount + getHeaderViewsCount ( ) ; } else { return getHeaderViewsCount ( ) + adapterCount + ( position - headerItemCount - adapterCount - getNumberOfPlaceholderViews ( ) ) / numColumns ; } } | Returns the index of the item which corresponds to a specific flattened position . | 158 | 14 |
7,622 | private int getNumberOfPlaceholderViews ( ) { int numColumns = getNumColumnsCompatible ( ) ; int adapterCount = adapter . getEncapsulatedAdapter ( ) . getCount ( ) ; int lastLineCount = adapterCount % numColumns ; return lastLineCount > 0 ? numColumns - lastLineCount : 0 ; } | Returns the number of placeholder views which are necessary to complement the items of the encapsulated adapter in order to fill up all columns .. | 75 | 26 |
7,623 | public final void addHeaderView ( @ NonNull final View view , @ Nullable final Object data , final boolean selectable ) { Condition . INSTANCE . ensureNotNull ( view , "The view may not be null" ) ; headers . add ( new FullWidthItem ( view , data , selectable ) ) ; notifyDataSetChanged ( ) ; } | Adds a fixed view to appear at the top of the adapter view . If this method is called more than once the views will appear in the order they were added . | 74 | 33 |
7,624 | public final void addFooterView ( @ NonNull final View view , @ Nullable final Object data , final boolean selectable ) { Condition . INSTANCE . ensureNotNull ( view , "The view may not be null" ) ; footers . add ( new FullWidthItem ( view , data , selectable ) ) ; notifyDataSetChanged ( ) ; } | Adds a fixed view to appear at the bottom of the adapter view . If this method is called more than once the views will appear in the order they were added . | 76 | 33 |
7,625 | private void asyncMoreRequest ( int startRow ) { try { DataRequest moreRequest = new DataRequest ( ) ; moreRequest . queryId = queryId ; moreRequest . startRow = startRow ; moreRequest . maxSize = maxBatchSize ; logger . debug ( "Client requesting {} .. {}" , startRow , ( startRow + maxBatchSize - 1 ) ) ; DataResponse response = server . data ( moreRequest ) ; logger . debug ( "Client got response {} .. {}, more={}" , new Object [ ] { response . startRow , ( response . startRow + response . data . size ( ) - 1 ) , response . more } ) ; nextData . add ( new Window ( response . data , response . more ) ) ; } catch ( AvroRemoteException e ) { this . nextData . addError ( toSparqlException ( e ) ) ; } catch ( Throwable t ) { this . nextData . addError ( t ) ; } } | Send request for more data for this query . | 209 | 9 |
7,626 | private static final String encode ( String s ) { try { return URLEncoder . encode ( s , UTF_8 ) ; } catch ( UnsupportedEncodingException e ) { throw new Error ( "JVM unable to handle UTF-8" ) ; } } | URL - encode a string as UTF - 8 catching any thrown UnsupportedEncodingException . | 56 | 18 |
7,627 | @ SuppressWarnings ( "unused" ) private static final void dump ( HttpClient client , HttpUriRequest req ) { if ( logger . isTraceEnabled ( ) ) { StringBuilder sb = new StringBuilder ( "\n=== Request ===" ) ; sb . append ( "\n" ) . append ( req . getRequestLine ( ) ) ; for ( Header h : req . getAllHeaders ( ) ) { sb . append ( "\n" ) . append ( h . getName ( ) ) . append ( ": " ) . append ( h . getValue ( ) ) ; } logger . trace ( sb . toString ( ) ) ; HttpResponse resp = null ; try { resp = client . execute ( req ) ; } catch ( Exception e ) { logger . trace ( "Error executing request" , e ) ; return ; } sb = new StringBuilder ( "\n=== Response ===" ) ; sb . append ( "\n" ) . append ( resp . getStatusLine ( ) ) ; for ( Header h : resp . getAllHeaders ( ) ) { sb . append ( "\n" ) . append ( h . getName ( ) ) . append ( ": " ) . append ( h . getValue ( ) ) ; } logger . trace ( sb . toString ( ) ) ; HttpEntity entity = resp . getEntity ( ) ; if ( entity != null ) { sb = new StringBuilder ( "\n=== Content ===" ) ; try { int len = ( int ) entity . getContentLength ( ) ; if ( len < 0 ) len = 100 ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( len ) ; entity . writeTo ( baos ) ; sb . append ( "\n" ) . append ( baos . toString ( "UTF-8" ) ) ; logger . trace ( sb . toString ( ) ) ; } catch ( IOException e ) { logger . trace ( "Error reading content" , e ) ; } } } } | Logs a request executes it and dumps the response to the logger . For development use only . | 439 | 19 |
7,628 | static HttpResponse executeRequest ( ProtocolCommand command , String mimeType ) { HttpClient client = ( ( ProtocolConnection ) command . getConnection ( ) ) . getHttpClient ( ) ; URL url = ( ( ProtocolDataSource ) command . getConnection ( ) . getDataSource ( ) ) . getUrl ( ) ; HttpUriRequest req ; try { String params = "query=" + encode ( command . getCommand ( ) ) ; String u = url . toString ( ) + "?" + params ; if ( u . length ( ) > QUERY_LIMIT ) { // POST connection try { req = new HttpPost ( url . toURI ( ) ) ; } catch ( URISyntaxException e ) { throw new SparqlException ( "Endpoint <" + url + "> not in an acceptable format" , e ) ; } ( ( HttpPost ) req ) . setEntity ( ( HttpEntity ) new StringEntity ( params ) ) ; } else { // GET connection req = new HttpGet ( u ) ; } if ( command . getTimeout ( ) != Command . NO_TIMEOUT ) { HttpParams reqParams = new BasicHttpParams ( ) ; HttpConnectionParams . setSoTimeout ( reqParams , ( int ) ( command . getTimeout ( ) * 1000 ) ) ; req . setParams ( reqParams ) ; } // Add Accept and Content-Type (for POST'ed queries) headers to the request. addHeaders ( req , mimeType ) ; // There's a small chance the request could be aborted before it's even executed, we'll have to live with that. command . setRequest ( req ) ; //dump(client, req); HttpResponse response = client . execute ( req ) ; StatusLine status = response . getStatusLine ( ) ; int code = status . getStatusCode ( ) ; // TODO the client doesn't handle redirects for posts; should we do that here? if ( code >= SUCCESS_MIN && code <= SUCCESS_MAX ) { return response ; } else { throw new SparqlException ( "Unexpected status code in server response: " + status . getReasonPhrase ( ) + "(" + code + ")" ) ; } } catch ( UnsupportedEncodingException e ) { throw new SparqlException ( "Unabled to encode data" , e ) ; } catch ( ClientProtocolException cpe ) { throw new SparqlException ( "Error in protocol" , cpe ) ; } catch ( IOException e ) { throw new SparqlException ( e ) ; } } | Executes a SPARQL HTTP protocol request for the given command and returns the response . | 564 | 18 |
7,629 | static void addHeaders ( HttpUriRequest req , String mimeType ) { if ( POST . equalsIgnoreCase ( req . getMethod ( ) ) ) { req . addHeader ( CONTENT_TYPE , FORM_ENCODED ) ; } if ( mimeType != null ) req . setHeader ( ACCEPT , mimeType ) ; } | Add headers to a request . | 78 | 6 |
7,630 | @ Override public HolidayMap getHolidays ( final int nYear , @ Nullable final String ... aArgs ) { final HolidayMap aHolidays = super . getHolidays ( nYear , aArgs ) ; final HolidayMap aAdditionalHolidays = new HolidayMap ( ) ; for ( final Map . Entry < LocalDate , ISingleHoliday > aEntry : aHolidays . getMap ( ) . entrySet ( ) ) { final LocalDate aTwoDaysLater = aEntry . getKey ( ) . plusDays ( 2 ) ; if ( aHolidays . containsHolidayForDate ( aTwoDaysLater ) ) { final LocalDate aBridgingDate = aTwoDaysLater . minusDays ( 1 ) ; aAdditionalHolidays . add ( aBridgingDate , new ResourceBundleHoliday ( EHolidayType . OFFICIAL_HOLIDAY , BRIDGING_HOLIDAY_PROPERTIES_KEY ) ) ; } } aHolidays . addAll ( aAdditionalHolidays ) ; return aHolidays ; } | Implements the rule which requests if two holidays have one non holiday between each other than this day is also a holiday . | 236 | 25 |
7,631 | public final void setLogLevel ( @ NonNull final LogLevel logLevel ) { Condition . INSTANCE . ensureNotNull ( logLevel , "The log level may not be null" ) ; this . logLevel = logLevel ; } | Sets the log level . Only log messages with a rank greater or equal than the rank of the currently applied log level are written to the output . | 49 | 30 |
7,632 | public final void logVerbose ( @ NonNull final Class < ? > tag , @ NonNull final String message ) { Condition . INSTANCE . ensureNotNull ( tag , "The tag may not be null" ) ; Condition . INSTANCE . ensureNotNull ( message , "The message may not be null" ) ; Condition . INSTANCE . ensureNotEmpty ( message , "The message may not be empty" ) ; if ( LogLevel . VERBOSE . getRank ( ) >= getLogLevel ( ) . getRank ( ) ) { Log . v ( ClassUtil . INSTANCE . getTruncatedName ( tag ) , message ) ; } } | Logs a specific message on the log level VERBOSE . | 140 | 13 |
7,633 | public final void logDebug ( @ NonNull final Class < ? > tag , @ NonNull final String message ) { Condition . INSTANCE . ensureNotNull ( tag , "The tag may not be null" ) ; Condition . INSTANCE . ensureNotNull ( message , "The message may not be null" ) ; Condition . INSTANCE . ensureNotEmpty ( message , "The message may not be empty" ) ; if ( LogLevel . DEBUG . getRank ( ) >= getLogLevel ( ) . getRank ( ) ) { Log . d ( ClassUtil . INSTANCE . getTruncatedName ( tag ) , message ) ; } } | Logs a specific message on the log level DEBUG . | 136 | 11 |
7,634 | public final void logInfo ( @ NonNull final Class < ? > tag , @ NonNull final String message ) { Condition . INSTANCE . ensureNotNull ( tag , "The tag may not be null" ) ; Condition . INSTANCE . ensureNotNull ( message , "The message may not be null" ) ; Condition . INSTANCE . ensureNotEmpty ( message , "The message may not be empty" ) ; if ( LogLevel . INFO . getRank ( ) >= getLogLevel ( ) . getRank ( ) ) { Log . i ( ClassUtil . INSTANCE . getTruncatedName ( tag ) , message ) ; } } | Logs a specific message on the log level INFO . | 136 | 11 |
7,635 | public final void logWarn ( @ NonNull final Class < ? > tag , @ NonNull final String message , @ NonNull final Throwable cause ) { Condition . INSTANCE . ensureNotNull ( tag , "The tag may not be null" ) ; Condition . INSTANCE . ensureNotNull ( message , "The message may not be null" ) ; Condition . INSTANCE . ensureNotEmpty ( message , "The message may not be empty" ) ; Condition . INSTANCE . ensureNotNull ( cause , "The cause may not be null" ) ; if ( LogLevel . WARN . getRank ( ) >= getLogLevel ( ) . getRank ( ) ) { Log . w ( ClassUtil . INSTANCE . getTruncatedName ( tag ) , message , cause ) ; } } | Logs a specific message and exception on the log level WARN . | 168 | 13 |
7,636 | public final void logError ( @ NonNull final Class < ? > tag , @ NonNull final String message ) { Condition . INSTANCE . ensureNotNull ( tag , "The tag may not be null" ) ; Condition . INSTANCE . ensureNotNull ( message , "The message may not be null" ) ; Condition . INSTANCE . ensureNotEmpty ( message , "The message may not be empty" ) ; if ( LogLevel . ERROR . getRank ( ) >= getLogLevel ( ) . getRank ( ) ) { Log . e ( ClassUtil . INSTANCE . getTruncatedName ( tag ) , message ) ; } } | Logs a specific message on the log level ERROR . | 136 | 11 |
7,637 | public static Orientation getOrientation ( @ NonNull final Context context ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; int orientation = context . getResources ( ) . getConfiguration ( ) . orientation ; if ( orientation == Configuration . ORIENTATION_UNDEFINED ) { int width = getDisplayWidth ( context ) ; int height = getDisplayHeight ( context ) ; if ( width > height ) { return Orientation . LANDSCAPE ; } else if ( width < height ) { return Orientation . PORTRAIT ; } else { return Orientation . SQUARE ; } } else if ( orientation == Configuration . ORIENTATION_LANDSCAPE ) { return Orientation . LANDSCAPE ; } else if ( orientation == Configuration . ORIENTATION_PORTRAIT ) { return Orientation . PORTRAIT ; } else { return Orientation . SQUARE ; } } | Returns the orientation of the device . | 201 | 7 |
7,638 | public static DeviceType getDeviceType ( @ NonNull final Context context ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; return DeviceType . fromValue ( context . getString ( R . string . device_type ) ) ; } | Returns the type of the device depending on its display size . | 60 | 12 |
7,639 | public static int getDisplayWidth ( @ NonNull final Context context ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; return context . getResources ( ) . getDisplayMetrics ( ) . widthPixels ; } | Returns the width of the device s display . | 56 | 9 |
7,640 | public static int getDisplayHeight ( @ NonNull final Context context ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; return context . getResources ( ) . getDisplayMetrics ( ) . heightPixels ; } | Returns the height of the device s display . | 56 | 9 |
7,641 | public static Driver createDriver ( FeedPartition feedPartition , Plan plan , MetricRegistry metricRegistry ) { populateFeedMetricInfo ( plan , feedPartition , metricRegistry ) ; OperatorDesc desc = plan . getRootOperator ( ) ; Operator oper = buildOperator ( desc , metricRegistry , plan . getName ( ) , feedPartition ) ; OffsetStorage offsetStorage = null ; OffsetStorageDesc offsetDesc = plan . getOffsetStorageDesc ( ) ; if ( offsetDesc != null && feedPartition . supportsOffsetManagement ( ) ) { offsetStorage = buildOffsetStorage ( feedPartition , plan , offsetDesc ) ; Offset offset = offsetStorage . findLatestPersistedOffset ( ) ; if ( offset != null ) { feedPartition . setOffset ( new String ( offset . serialize ( ) , Charsets . UTF_8 ) ) ; } } CollectorProcessor cp = new CollectorProcessor ( ) ; cp . setTupleRetry ( plan . getTupleRetry ( ) ) ; int offsetCommitInterval = plan . getOffsetCommitInterval ( ) ; Driver driver = new Driver ( feedPartition , oper , offsetStorage , cp , offsetCommitInterval , metricRegistry , plan . getName ( ) ) ; recurseOperatorAndDriverNode ( desc , driver . getDriverNode ( ) , metricRegistry , feedPartition ) ; return driver ; } | Given a FeedParition and Plan create a Driver that will consume from the feed partition and execute the plan . | 305 | 22 |
7,642 | private static NitDesc nitDescFromDynamic ( DynamicInstantiatable d ) { NitDesc nd = new NitDesc ( ) ; nd . setScript ( d . getScript ( ) ) ; nd . setTheClass ( d . getTheClass ( ) ) ; if ( d . getSpec ( ) == null || "java" . equals ( d . getSpec ( ) ) ) { nd . setSpec ( NitDesc . NitSpec . JAVA_LOCAL_CLASSPATH ) ; } else if ( "groovy" . equals ( d . getSpec ( ) ) ) { nd . setSpec ( NitDesc . NitSpec . GROOVY_CLASS_LOADER ) ; } else if ( "groovyclosure" . equals ( d . getSpec ( ) ) ) { nd . setSpec ( NitDesc . NitSpec . GROOVY_CLOSURE ) ; } else if ( "url" . equals ( d . getSpec ( ) ) ) { nd . setSpec ( NitDesc . NitSpec . JAVA_URL_CLASSLOADER ) ; } else { nd . setSpec ( NitDesc . NitSpec . valueOf ( d . getSpec ( ) ) ) ; } return nd ; } | DynamicInstantiatable has some pre - nit strings it uses as for spec that do not match nit - compiler . Here we correct these and return a new object | 271 | 32 |
7,643 | public static Operator buildOperator ( OperatorDesc operatorDesc , MetricRegistry metricRegistry , String planPath , FeedPartition feedPartition ) { Operator operator = null ; NitFactory nitFactory = new NitFactory ( ) ; NitDesc nitDesc = nitDescFromDynamic ( operatorDesc ) ; try { if ( nitDesc . getSpec ( ) == NitDesc . NitSpec . GROOVY_CLOSURE ) { operator = new GroovyOperator ( ( Closure ) nitFactory . construct ( nitDesc ) ) ; } else { operator = nitFactory . construct ( nitDesc ) ; } } catch ( NitException e ) { throw new RuntimeException ( e ) ; } operator . setProperties ( operatorDesc . getParameters ( ) ) ; operator . setMetricRegistry ( metricRegistry ) ; operator . setPartitionId ( feedPartition . getPartitionId ( ) ) ; String myName = operatorDesc . getName ( ) ; if ( myName == null ) { myName = operatorDesc . getTheClass ( ) ; if ( myName . indexOf ( "." ) > - 1 ) { String [ ] parts = myName . split ( "\\." ) ; myName = parts [ parts . length - 1 ] ; } } operator . setPath ( planPath + "." + myName ) ; return operator ; } | OperatorDesc can describe local reasources URL loaded resources and dynamic resources like groovy code . This method instantiates an Operator based on the OperatorDesc . | 287 | 32 |
7,644 | public static Feed buildFeed ( FeedDesc feedDesc ) { Feed feed = null ; NitFactory nitFactory = new NitFactory ( ) ; NitDesc nitDesc = nitDescFromDynamic ( feedDesc ) ; nitDesc . setConstructorParameters ( new Class [ ] { Map . class } ) ; nitDesc . setConstructorArguments ( new Object [ ] { feedDesc . getProperties ( ) } ) ; try { feed = nitFactory . construct ( nitDesc ) ; } catch ( NitException e ) { throw new RuntimeException ( e ) ; } return feed ; } | Build a feed using reflection | 120 | 5 |
7,645 | private static int getSampleSize ( @ NonNull final Pair < Integer , Integer > imageDimensions , final int maxWidth , final int maxHeight ) { Condition . INSTANCE . ensureNotNull ( imageDimensions , "The image dimensions may not be null" ) ; Condition . INSTANCE . ensureAtLeast ( maxWidth , 1 , "The maximum width must be at least 1" ) ; Condition . INSTANCE . ensureAtLeast ( maxHeight , 1 , "The maximum height must be at least 1" ) ; int width = imageDimensions . first ; int height = imageDimensions . second ; int sampleSize = 1 ; if ( width > maxWidth || height > maxHeight ) { int halfWidth = width / 2 ; int halfHeight = height / 2 ; while ( ( halfWidth / sampleSize ) > maxWidth && ( halfHeight / sampleSize ) > maxHeight ) { sampleSize *= 2 ; } } return sampleSize ; } | Calculates the sample size which should be used to downsample an image to a maximum width and height . | 201 | 22 |
7,646 | public static Bitmap clipCircle ( @ NonNull final Bitmap bitmap , final int size ) { Bitmap squareBitmap = clipSquare ( bitmap , size ) ; int squareSize = squareBitmap . getWidth ( ) ; float radius = ( float ) squareSize / 2.0f ; Bitmap clippedBitmap = Bitmap . createBitmap ( squareSize , squareSize , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( clippedBitmap ) ; Paint paint = new Paint ( ) ; paint . setAntiAlias ( true ) ; paint . setColor ( Color . BLACK ) ; canvas . drawCircle ( radius , radius , radius , paint ) ; paint . setXfermode ( new PorterDuffXfermode ( PorterDuff . Mode . SRC_IN ) ) ; canvas . drawBitmap ( squareBitmap , new Rect ( 0 , 0 , squareSize , squareSize ) , new Rect ( 0 , 0 , squareSize , squareSize ) , paint ) ; return clippedBitmap ; } | Clips the corners of a bitmap in order to transform it into a round shape . Additionally the bitmap is resized to a specific size . Bitmaps whose width and height are not equal will be clipped to a square beforehand . | 225 | 47 |
7,647 | public static Bitmap clipCircle ( @ NonNull final Bitmap bitmap , final int size , final int borderWidth , @ ColorInt final int borderColor ) { Condition . INSTANCE . ensureAtLeast ( borderWidth , 0 , "The border width must be at least 0" ) ; Bitmap clippedBitmap = clipCircle ( bitmap , size ) ; Bitmap result = Bitmap . createBitmap ( clippedBitmap . getWidth ( ) , clippedBitmap . getHeight ( ) , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( result ) ; float offset = borderWidth / 2.0f ; Rect src = new Rect ( 0 , 0 , clippedBitmap . getWidth ( ) , clippedBitmap . getHeight ( ) ) ; RectF dst = new RectF ( offset , offset , result . getWidth ( ) - offset , result . getHeight ( ) - offset ) ; canvas . drawBitmap ( clippedBitmap , src , dst , null ) ; if ( borderWidth > 0 && Color . alpha ( borderColor ) != 0 ) { Paint paint = new Paint ( ) ; paint . setFilterBitmap ( false ) ; paint . setAntiAlias ( true ) ; paint . setStrokeCap ( Paint . Cap . ROUND ) ; paint . setStyle ( Paint . Style . STROKE ) ; paint . setStrokeWidth ( borderWidth ) ; paint . setColor ( borderColor ) ; offset = borderWidth / 2.0f ; RectF bounds = new RectF ( offset , offset , result . getWidth ( ) - offset , result . getWidth ( ) - offset ) ; canvas . drawArc ( bounds , 0 , COMPLETE_ARC_ANGLE , false , paint ) ; } return result ; } | Clips the corners of a bitmap in order to transform it into a round shape . Additionally the bitmap is resized to a specific size and a border will be added . Bitmaps whose width and height are not equal will be clipped to a square beforehand . | 382 | 53 |
7,648 | public static Bitmap clipSquare ( @ NonNull final Bitmap bitmap ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; return clipSquare ( bitmap , bitmap . getWidth ( ) >= bitmap . getHeight ( ) ? bitmap . getHeight ( ) : bitmap . getWidth ( ) ) ; } | Clips the long edge of a bitmap if its width and height are not equal in order to form it into a square . | 81 | 26 |
7,649 | @ SuppressWarnings ( "SuspiciousNameCombination" ) public static Bitmap clipSquare ( @ NonNull final Bitmap bitmap , final int size ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureAtLeast ( size , 1 , "The size must be at least 1" ) ; Bitmap clippedBitmap = bitmap ; int width = bitmap . getWidth ( ) ; int height = bitmap . getHeight ( ) ; if ( width > height ) { clippedBitmap = Bitmap . createBitmap ( bitmap , width / 2 - height / 2 , 0 , height , height ) ; } else if ( bitmap . getWidth ( ) < bitmap . getHeight ( ) ) { clippedBitmap = Bitmap . createBitmap ( bitmap , 0 , bitmap . getHeight ( ) / 2 - width / 2 , width , width ) ; } if ( clippedBitmap . getWidth ( ) != size ) { clippedBitmap = resize ( clippedBitmap , size , size ) ; } return clippedBitmap ; } | Clips the long edge of a bitmap if its width and height are not equal in order to form it into a square . Additionally the bitmap is resized to a specific size . | 245 | 38 |
7,650 | public static Bitmap clipSquare ( @ NonNull final Bitmap bitmap , final int borderWidth , @ ColorInt final int borderColor ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; return clipSquare ( bitmap , bitmap . getWidth ( ) >= bitmap . getHeight ( ) ? bitmap . getHeight ( ) : bitmap . getWidth ( ) , borderWidth , borderColor ) ; } | Clips the long edge of a bitmap if its width and height are not equal in order to transform it into a square . Additionally a border will be added . | 100 | 33 |
7,651 | public static Bitmap clipSquare ( @ NonNull final Bitmap bitmap , final int size , final int borderWidth , @ ColorInt final int borderColor ) { Condition . INSTANCE . ensureAtLeast ( borderWidth , 0 , "The border width must be at least 0" ) ; Bitmap clippedBitmap = clipSquare ( bitmap , size ) ; Bitmap result = Bitmap . createBitmap ( clippedBitmap . getWidth ( ) , clippedBitmap . getHeight ( ) , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( result ) ; float offset = borderWidth / 2.0f ; Rect src = new Rect ( 0 , 0 , clippedBitmap . getWidth ( ) , clippedBitmap . getHeight ( ) ) ; RectF dst = new RectF ( offset , offset , result . getWidth ( ) - offset , result . getHeight ( ) - offset ) ; canvas . drawBitmap ( clippedBitmap , src , dst , null ) ; if ( borderWidth > 0 && Color . alpha ( borderColor ) != 0 ) { Paint paint = new Paint ( ) ; paint . setFilterBitmap ( false ) ; paint . setStyle ( Paint . Style . STROKE ) ; paint . setStrokeWidth ( borderWidth ) ; paint . setColor ( borderColor ) ; offset = borderWidth / 2.0f ; RectF bounds = new RectF ( offset , offset , result . getWidth ( ) - offset , result . getWidth ( ) - offset ) ; canvas . drawRect ( bounds , paint ) ; } return result ; } | Clips the long edge of a bitmap if its width and height are not equal in order to transform it into a square . Additionally the bitmap is resized to a specific size and a border will be added . | 343 | 44 |
7,652 | public static Bitmap resize ( @ NonNull final Bitmap bitmap , final int width , final int height ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureAtLeast ( width , 1 , "The width must be at least 1" ) ; Condition . INSTANCE . ensureAtLeast ( height , 1 , "The height must be at least 1" ) ; return Bitmap . createScaledBitmap ( bitmap , width , height , false ) ; } | Resizes a bitmap to a specific width and height . If the ratio between width and height differs from the bitmap s original ratio the bitmap is stretched . | 118 | 33 |
7,653 | public static Pair < Bitmap , Bitmap > splitHorizontally ( @ NonNull final Bitmap bitmap ) { return splitHorizontally ( bitmap , bitmap . getHeight ( ) / 2 ) ; } | Splits a specific bitmap horizontally at half . | 46 | 10 |
7,654 | public static Pair < Bitmap , Bitmap > splitHorizontally ( @ NonNull final Bitmap bitmap , final int splitPoint ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureGreater ( splitPoint , 0 , "The split point must be greater than 0" ) ; Condition . INSTANCE . ensureSmaller ( splitPoint , bitmap . getHeight ( ) , "The split point must be smaller than " + bitmap . getHeight ( ) ) ; Bitmap topBitmap = Bitmap . createBitmap ( bitmap , 0 , 0 , bitmap . getWidth ( ) , splitPoint ) ; Bitmap bottomBitmap = Bitmap . createBitmap ( bitmap , 0 , splitPoint , bitmap . getWidth ( ) , bitmap . getHeight ( ) - splitPoint ) ; return new Pair <> ( topBitmap , bottomBitmap ) ; } | Splits a specific bitmap horizontally at a specific split point . | 207 | 13 |
7,655 | public static Pair < Bitmap , Bitmap > splitVertically ( @ NonNull final Bitmap bitmap ) { return splitVertically ( bitmap , bitmap . getWidth ( ) / 2 ) ; } | Splits a specific bitmap vertically at half . | 44 | 10 |
7,656 | public static Pair < Bitmap , Bitmap > splitVertically ( @ NonNull final Bitmap bitmap , final int splitPoint ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureGreater ( splitPoint , 0 , "The split point must be greater than 0" ) ; Condition . INSTANCE . ensureSmaller ( splitPoint , bitmap . getWidth ( ) , "The split point must be smaller than " + bitmap . getWidth ( ) ) ; Bitmap leftBitmap = Bitmap . createBitmap ( bitmap , 0 , 0 , splitPoint , bitmap . getHeight ( ) ) ; Bitmap rightBitmap = Bitmap . createBitmap ( bitmap , splitPoint , 0 , bitmap . getWidth ( ) - splitPoint , bitmap . getHeight ( ) ) ; return new Pair <> ( leftBitmap , rightBitmap ) ; } | Splits a specific bitmap vertically at a specific split point . | 206 | 13 |
7,657 | public static Bitmap tile ( final Bitmap bitmap , final int width , final int height ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureAtLeast ( width , 1 , "The width must be at least 1" ) ; Condition . INSTANCE . ensureAtLeast ( height , 1 , "The height must be at least 1" ) ; Bitmap result = Bitmap . createBitmap ( width , height , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( result ) ; int originalWidth = bitmap . getWidth ( ) ; int originalHeight = bitmap . getHeight ( ) ; for ( int x = 0 ; x < width ; x += originalWidth ) { for ( int y = 0 ; y < width ; y += originalHeight ) { int copyWidth = ( width - x >= originalWidth ) ? originalWidth : width - x ; int copyHeight = ( height - y >= originalHeight ) ? originalHeight : height - y ; Rect src = new Rect ( 0 , 0 , copyWidth , copyHeight ) ; Rect dest = new Rect ( x , y , x + copyWidth , y + copyHeight ) ; canvas . drawBitmap ( bitmap , src , dest , null ) ; } } return result ; } | Creates and returns a bitmap with a specific width and height by tiling another bitmap . | 290 | 20 |
7,658 | public static Bitmap tint ( @ NonNull final Bitmap bitmap , @ ColorInt final int color ) { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Canvas canvas = new Canvas ( bitmap ) ; Paint paint = new Paint ( ) ; paint . setColor ( color ) ; canvas . drawRect ( new Rect ( 0 , 0 , bitmap . getWidth ( ) , bitmap . getHeight ( ) ) , paint ) ; return bitmap ; } | Creates and returns a bitmap by overlaying it with a specific color . | 111 | 16 |
7,659 | public static Bitmap drawableToBitmap ( @ NonNull final Drawable drawable ) { Condition . INSTANCE . ensureNotNull ( drawable , "The drawable may not be null" ) ; if ( drawable instanceof BitmapDrawable ) { BitmapDrawable bitmapDrawable = ( BitmapDrawable ) drawable ; if ( bitmapDrawable . getBitmap ( ) != null ) { return bitmapDrawable . getBitmap ( ) ; } } Bitmap bitmap ; if ( drawable . getIntrinsicWidth ( ) <= 0 || drawable . getIntrinsicHeight ( ) <= 0 ) { bitmap = Bitmap . createBitmap ( 1 , 1 , Bitmap . Config . ARGB_8888 ) ; } else { bitmap = Bitmap . createBitmap ( drawable . getIntrinsicWidth ( ) , drawable . getIntrinsicHeight ( ) , Bitmap . Config . ARGB_8888 ) ; } Canvas canvas = new Canvas ( bitmap ) ; drawable . setBounds ( 0 , 0 , canvas . getWidth ( ) , canvas . getHeight ( ) ) ; drawable . draw ( canvas ) ; return bitmap ; } | Creates and returns a bitmap from a specific drawable . | 266 | 13 |
7,660 | public static Bitmap colorToBitmap ( final int width , final int height , @ ColorInt final int color ) { Condition . INSTANCE . ensureAtLeast ( width , 1 , "The width must be at least 1" ) ; Condition . INSTANCE . ensureAtLeast ( height , 1 , "The height must be at least 1" ) ; Bitmap bitmap = Bitmap . createBitmap ( width , height , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( bitmap ) ; Paint paint = new Paint ( ) ; paint . setColor ( color ) ; canvas . drawRect ( 0 , 0 , width , height , paint ) ; return bitmap ; } | Creates and returns a bitmap from a specific color . | 152 | 12 |
7,661 | public static Pair < Integer , Integer > getImageDimensions ( @ NonNull final File file ) throws IOException { Condition . INSTANCE . ensureNotNull ( file , "The file may not be null" ) ; Condition . INSTANCE . ensureFileIsNoDirectory ( file , "The file must exist and must not be a directory" ) ; String path = file . getPath ( ) ; BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeFile ( path , options ) ; int width = options . outWidth ; int height = options . outHeight ; if ( width == - 1 || height == - 1 ) { throw new IOException ( "Failed to decode image \"" + path + "\"" ) ; } return Pair . create ( width , height ) ; } | Returns the width and height of a specific image file . | 183 | 11 |
7,662 | public static Pair < Integer , Integer > getImageDimensions ( @ NonNull final Context context , @ DrawableRes final int resourceId ) throws IOException { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeResource ( context . getResources ( ) , resourceId , options ) ; int width = options . outWidth ; int height = options . outHeight ; if ( width == - 1 || height == - 1 ) { throw new IOException ( "Failed to decode image resource with id " + resourceId ) ; } return Pair . create ( width , height ) ; } | Returns the width and height of a specific image resource . | 162 | 11 |
7,663 | public static Bitmap loadThumbnail ( @ NonNull final File file , final int maxWidth , final int maxHeight ) throws IOException { Pair < Integer , Integer > imageDimensions = getImageDimensions ( file ) ; int sampleSize = getSampleSize ( imageDimensions , maxWidth , maxHeight ) ; BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = false ; options . inSampleSize = sampleSize ; String path = file . getAbsolutePath ( ) ; Bitmap thumbnail = BitmapFactory . decodeFile ( path , options ) ; if ( thumbnail == null ) { throw new IOException ( "Failed to decode image \"" + path + "\"" ) ; } return thumbnail ; } | Loads a downsampled thumbnail of a specific image file while maintaining its aspect ratio . | 162 | 18 |
7,664 | public static void compressToFile ( @ NonNull final Bitmap bitmap , @ NonNull final File file , @ NonNull final CompressFormat format , final int quality ) throws IOException { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureNotNull ( file , "The file may not be null" ) ; Condition . INSTANCE . ensureNotNull ( format , "The format may not be null" ) ; Condition . INSTANCE . ensureAtLeast ( quality , 0 , "The quality must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( quality , 100 , "The quality must be at maximum 100" ) ; OutputStream outputStream = null ; try { outputStream = new FileOutputStream ( file ) ; boolean result = bitmap . compress ( format , quality , outputStream ) ; if ( ! result ) { throw new IOException ( "Failed to compress bitmap to file \"" + file + "\" using format " + format + " and quality " + quality ) ; } } finally { StreamUtil . INSTANCE . close ( outputStream ) ; } } | Compresses a specific bitmap and stores it within a file . | 250 | 13 |
7,665 | public static byte [ ] compressToByteArray ( @ NonNull final Bitmap bitmap , @ NonNull final CompressFormat format , final int quality ) throws IOException { Condition . INSTANCE . ensureNotNull ( bitmap , "The bitmap may not be null" ) ; Condition . INSTANCE . ensureNotNull ( format , "The format may not be null" ) ; Condition . INSTANCE . ensureAtLeast ( quality , 0 , "The quality must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( quality , 100 , "The quality must be at maximum 100" ) ; ByteArrayOutputStream outputStream = null ; try { outputStream = new ByteArrayOutputStream ( ) ; boolean result = bitmap . compress ( format , quality , outputStream ) ; if ( result ) { return outputStream . toByteArray ( ) ; } throw new IOException ( "Failed to compress bitmap to byte array using format " + format + " and quality " + quality ) ; } finally { StreamUtil . INSTANCE . close ( outputStream ) ; } } | Compresses a specific bitmap and returns it as a byte array . | 230 | 14 |
7,666 | public boolean isPlanSane ( Plan plan ) { if ( plan == null ) { logger . warn ( "did not find plan" ) ; return false ; } if ( plan . isDisabled ( ) ) { logger . debug ( "disabled " + plan . getName ( ) ) ; return false ; } if ( plan . getFeedDesc ( ) == null ) { logger . warn ( "feed was null " + plan . getName ( ) ) ; return false ; } return true ; } | Determines if the plan can be run . IE not disabled and not malformed | 104 | 17 |
7,667 | private OnItemClickListener createItemClickListener ( ) { return new OnItemClickListener ( ) { @ Override public void onItemClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { Pair < Integer , Integer > itemPosition = getItemPosition ( position - getHeaderViewsCount ( ) ) ; int groupIndex = itemPosition . first ; int childIndex = itemPosition . second ; long packedId ; if ( childIndex != - 1 ) { packedId = getPackedPositionForChild ( groupIndex , childIndex ) ; notifyOnChildClicked ( view , groupIndex , childIndex , packedId ) ; } else if ( groupIndex != - 1 ) { packedId = getPackedPositionForGroup ( groupIndex ) ; notifyOnGroupClicked ( view , groupIndex , packedId ) ; } else { packedId = getPackedPositionForChild ( Integer . MAX_VALUE , position ) ; } notifyOnItemClicked ( view , getPackedPosition ( position ) , packedId ) ; } } ; } | Creates and returns a listener which allows to delegate when any item of the grid view has been clicked to the appropriate listeners . | 228 | 25 |
7,668 | private OnItemLongClickListener createItemLongClickListener ( ) { return new OnItemLongClickListener ( ) { @ Override public boolean onItemLongClick ( AdapterView < ? > parent , View view , int position , long id ) { Pair < Integer , Integer > itemPosition = getItemPosition ( position - getHeaderViewsCount ( ) ) ; int groupIndex = itemPosition . first ; int childIndex = itemPosition . second ; long packedId ; if ( childIndex != - 1 ) { packedId = getPackedPositionForChild ( groupIndex , childIndex ) ; } else if ( groupIndex != - 1 ) { packedId = getPackedPositionForGroup ( groupIndex ) ; } else { packedId = getPackedPositionForChild ( Integer . MAX_VALUE , position ) ; } return notifyOnItemLongClicked ( view , getPackedPosition ( position ) , packedId ) ; } } ; } | Creates and returns a listener which allows to delegate when any item of the grid view has been long - clicked to the appropriate listeners . | 197 | 27 |
7,669 | private int getPackedPosition ( final int position ) { if ( position < getHeaderViewsCount ( ) ) { return position ; } else { Pair < Integer , Integer > pair = getItemPosition ( position - getHeaderViewsCount ( ) ) ; int groupIndex = pair . first ; int childIndex = pair . second ; if ( childIndex == - 1 && groupIndex == - 1 ) { int childCount = 0 ; for ( int i = 0 ; i < getExpandableListAdapter ( ) . getGroupCount ( ) ; i ++ ) { childCount += getExpandableListAdapter ( ) . getChildrenCount ( i ) ; } return getHeaderViewsCount ( ) + getExpandableListAdapter ( ) . getGroupCount ( ) + childCount + position - ( getHeaderViewsCount ( ) + adapter . getCount ( ) ) ; } else if ( childIndex != - 1 ) { return getPackedChildPosition ( groupIndex , childIndex ) ; } else { return getPackedGroupPosition ( groupIndex ) ; } } } | Returns the packed position of an item which corresponds to a specific position . | 227 | 14 |
7,670 | private int getPackedGroupPosition ( final int groupIndex ) { int packedPosition = getHeaderViewsCount ( ) ; if ( groupIndex > 0 ) { for ( int i = groupIndex - 1 ; i >= 0 ; i -- ) { packedPosition += getExpandableListAdapter ( ) . getChildrenCount ( i ) + 1 ; } } return packedPosition ; } | Returns the packed position of a group which corresponds to a specific index . | 80 | 14 |
7,671 | private Pair < Integer , Integer > getItemPosition ( final int packedPosition ) { int currentPosition = packedPosition ; int groupIndex = - 1 ; int childIndex = - 1 ; int numColumns = getNumColumnsCompatible ( ) ; for ( int i = 0 ; i < getExpandableListAdapter ( ) . getGroupCount ( ) ; i ++ ) { if ( currentPosition == 0 ) { groupIndex = i ; break ; } else if ( currentPosition < numColumns ) { break ; } else { currentPosition -= numColumns ; if ( isGroupExpanded ( i ) ) { int childCount = getExpandableListAdapter ( ) . getChildrenCount ( i ) ; if ( currentPosition < childCount ) { groupIndex = i ; childIndex = currentPosition ; break ; } else { int lastLineCount = childCount % numColumns ; currentPosition -= childCount + ( lastLineCount > 0 ? numColumns - lastLineCount : 0 ) ; } } } } return new Pair <> ( groupIndex , childIndex ) ; } | Returns a pair which contains the group and child index of the item which corresponds to a specific packed position . | 229 | 21 |
7,672 | private boolean notifyOnGroupClicked ( @ NonNull final View view , final int groupIndex , final long id ) { return groupClickListener != null && groupClickListener . onGroupClick ( this , view , groupIndex , id ) ; } | Notifies the listener which has been registered to be notified when a group has been clicked about a group being clicked . | 51 | 23 |
7,673 | private boolean notifyOnChildClicked ( @ NonNull final View view , final int groupIndex , final int childIndex , final long id ) { return childClickListener != null && childClickListener . onChildClick ( this , view , groupIndex , childIndex , id ) ; } | Notifies the listener which has been registered to be notified when a child has been clicked about a child being clicked . | 59 | 23 |
7,674 | private void notifyOnItemClicked ( @ NonNull final View view , final int position , final long id ) { if ( itemClickListener != null ) { itemClickListener . onItemClick ( this , view , position , id ) ; } } | Notifies the listener which has been registered to be notified when any item has been clicked about an item being clicked . | 52 | 23 |
7,675 | private boolean notifyOnItemLongClicked ( @ NonNull final View view , final int position , final long id ) { return itemLongClickListener != null && itemLongClickListener . onItemLongClick ( this , view , position , id ) ; } | Notifies the listener which has been registered to be notified when any item has been long - clicked about an item being long - clicked . | 53 | 27 |
7,676 | public static int getPackedPositionType ( final long packedPosition ) { if ( packedPosition == PACKED_POSITION_VALUE_NULL ) { return PACKED_POSITION_TYPE_NULL ; } return ( packedPosition & PACKED_POSITION_MASK_TYPE ) == PACKED_POSITION_MASK_TYPE ? PACKED_POSITION_TYPE_CHILD : PACKED_POSITION_TYPE_GROUP ; } | Returns the type of the item which corresponds to a specific packed position . | 93 | 14 |
7,677 | public final void setAdapter ( @ Nullable final ExpandableListAdapter adapter ) { expandedGroups . clear ( ) ; if ( adapter != null ) { this . adapter = new AdapterWrapper ( adapter ) ; super . setAdapter ( this . adapter ) ; } else { this . adapter = null ; super . setAdapter ( null ) ; } } | Sets the adapter that provides data to this view . | 73 | 11 |
7,678 | public final boolean expandGroup ( final int groupIndex ) { ExpandableListAdapter adapter = getExpandableListAdapter ( ) ; if ( adapter != null && ! isGroupExpanded ( groupIndex ) ) { expandedGroups . add ( groupIndex ) ; notifyDataSetChanged ( ) ; return true ; } return false ; } | Expands the group which corresponds to a specific index . | 69 | 11 |
7,679 | public final boolean collapseGroup ( final int groupIndex ) { ExpandableListAdapter adapter = getExpandableListAdapter ( ) ; if ( adapter != null && isGroupExpanded ( groupIndex ) ) { expandedGroups . remove ( groupIndex ) ; notifyDataSetChanged ( ) ; return true ; } return false ; } | Collapses the group which corresponds to a specific index . | 68 | 11 |
7,680 | private void validateString ( Class < ? > clazz ) throws SerializerException { if ( null != clazz && ! clazz . isAssignableFrom ( String . class ) ) { throw new SerializerException ( "String serializer is able to work only with data types assignable from java.lang.String" ) ; } } | Validates that provided class is assignable from java . lang . String | 71 | 14 |
7,681 | private void validateString ( Type type ) throws SerializerException { if ( null == type || ! String . class . equals ( TypeToken . of ( type ) . getRawType ( ) ) ) { throw new SerializerException ( "String serializer is able to work only with data types assignable from java.lang.String" ) ; } } | Validates that provided type is assignable from java . lang . String | 73 | 14 |
7,682 | @ Override public final void process ( final HttpRequest request , final HttpContext context ) throws HttpException , IOException { AuthState authState = ( AuthState ) context . getAttribute ( HttpClientContext . TARGET_AUTH_STATE ) ; if ( authState . getAuthScheme ( ) == null ) { HttpHost targetHost = ( HttpHost ) context . getAttribute ( HttpCoreContext . HTTP_TARGET_HOST ) ; AuthCache authCache = new BasicAuthCache ( ) ; authCache . put ( targetHost , new BasicScheme ( ) ) ; context . setAttribute ( HttpClientContext . AUTH_CACHE , authCache ) ; } } | Adds provided auth scheme to the client if there are no another provided auth schemes | 151 | 15 |
7,683 | @ Override public final < RQ , RS > Maybe < Response < RS > > executeRequest ( RestCommand < RQ , RS > command ) throws RestEndpointIOException { URI uri = spliceUrl ( command . getUri ( ) ) ; HttpUriRequest rq ; Serializer serializer ; switch ( command . getHttpMethod ( ) ) { case GET : rq = new HttpGet ( uri ) ; break ; case POST : if ( command . isMultipart ( ) ) { MultiPartRequest rqData = ( MultiPartRequest ) command . getRequest ( ) ; rq = buildMultipartRequest ( uri , rqData ) ; } else { serializer = getSupportedSerializer ( command . getRequest ( ) ) ; rq = new HttpPost ( uri ) ; ( ( HttpPost ) rq ) . setEntity ( new ByteArrayEntity ( serializer . serialize ( command . getRequest ( ) ) , ContentType . create ( serializer . getMimeType ( ) ) ) ) ; } break ; case PUT : serializer = getSupportedSerializer ( command . getRequest ( ) ) ; rq = new HttpPut ( uri ) ; ( ( HttpPut ) rq ) . setEntity ( new ByteArrayEntity ( serializer . serialize ( command . getRequest ( ) ) , ContentType . create ( serializer . getMimeType ( ) ) ) ) ; break ; case DELETE : rq = new HttpDelete ( uri ) ; break ; case PATCH : serializer = getSupportedSerializer ( command . getRequest ( ) ) ; rq = new HttpPatch ( uri ) ; ( ( HttpPatch ) rq ) . setEntity ( new ByteArrayEntity ( serializer . serialize ( command . getRequest ( ) ) , ContentType . create ( serializer . getMimeType ( ) ) ) ) ; break ; default : throw new IllegalArgumentException ( "Method '" + command . getHttpMethod ( ) + "' is unsupported" ) ; } return executeInternal ( rq , new TypeConverterCallback < RS > ( serializers , command . getResponseType ( ) ) ) ; } | Executes request command | 478 | 4 |
7,684 | private Serializer getSupportedSerializer ( Object o ) throws SerializerException { for ( Serializer s : serializers ) { if ( s . canWrite ( o ) ) { return s ; } } throw new SerializerException ( "Unable to find serializer for object with type '" + o . getClass ( ) + "'" ) ; } | Finds supported serializer for this type of object | 74 | 10 |
7,685 | @ SafeVarargs @ NonNull public final Pair < View , Boolean > inflate ( @ NonNull final ItemType item , @ Nullable final ViewGroup parent , final boolean useCache , @ NonNull final ParamType ... params ) { Condition . INSTANCE . ensureNotNull ( params , "The array may not be null" ) ; Condition . INSTANCE . ensureNotNull ( getAdapter ( ) , "No adapter has been set" , IllegalStateException . class ) ; View view = getView ( item ) ; boolean inflated = false ; if ( view == null ) { int viewType = getAdapter ( ) . getViewType ( item ) ; if ( useCache ) { view = pollUnusedView ( viewType ) ; } if ( view == null ) { view = getAdapter ( ) . onInflateView ( getLayoutInflater ( ) , parent , item , viewType , params ) ; inflated = true ; getLogger ( ) . logInfo ( getClass ( ) , "Inflated view to visualize item " + item + " using view type " + viewType ) ; } else { getLogger ( ) . logInfo ( getClass ( ) , "Reusing view to visualize item " + item + " using view type " + viewType ) ; } getActiveViews ( ) . put ( item , view ) ; } getAdapter ( ) . onShowView ( getContext ( ) , view , item , inflated , params ) ; getLogger ( ) . logDebug ( getClass ( ) , "Updated view of item " + item ) ; return Pair . create ( view , inflated ) ; } | Inflates the view which is used to visualize a specific item . | 344 | 14 |
7,686 | private static void mkdir ( @ NonNull final File directory , final boolean createParents ) throws IOException { Condition . INSTANCE . ensureNotNull ( directory , "The directory may not be null" ) ; boolean result = createParents ? directory . mkdirs ( ) : directory . mkdir ( ) ; if ( ! result && ! directory . exists ( ) ) { throw new IOException ( "Failed to create directory \"" + directory + "\"" ) ; } } | Creates a specific directory if it does not already exist . | 100 | 12 |
7,687 | public static void deleteRecursively ( @ NonNull final File file ) throws IOException { Condition . INSTANCE . ensureNotNull ( file , "The file or directory may not be null" ) ; if ( file . isDirectory ( ) ) { for ( File child : file . listFiles ( ) ) { deleteRecursively ( child ) ; } } delete ( file ) ; } | Deletes a specific file or directory . If the file is a directory all contained files and subdirectories are deleted recursively . | 81 | 27 |
7,688 | public static void createNewFile ( @ NonNull final File file , final boolean overwrite ) throws IOException { Condition . INSTANCE . ensureNotNull ( file , "The file may not be null" ) ; boolean result = file . createNewFile ( ) ; if ( ! result ) { if ( overwrite ) { try { delete ( file ) ; createNewFile ( file , false ) ; } catch ( IOException e ) { throw new IOException ( "Failed to overwrite file \"" + file + "\"" ) ; } } else if ( file . exists ( ) ) { throw new IOException ( "File \"" + file + "\" does already exist" ) ; } else { throw new IllegalArgumentException ( "The file must not be a directory" ) ; } } } | Creates a new empty file . | 166 | 7 |
7,689 | public void maybeDoOffset ( ) { long seen = tuplesSeen ; if ( offsetCommitInterval > 0 && seen % offsetCommitInterval == 0 && offsetStorage != null && fp . supportsOffsetManagement ( ) ) { doOffsetInternal ( ) ; } } | To do offset storage we let the topology drain itself out . Then we commit . | 59 | 17 |
7,690 | private static TypedArray obtainStyledAttributes ( @ NonNull final Context context , @ StyleRes final int themeResourceId , @ AttrRes final int resourceId ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; Theme theme = context . getTheme ( ) ; int [ ] attrs = new int [ ] { resourceId } ; if ( themeResourceId != - 1 ) { return theme . obtainStyledAttributes ( themeResourceId , attrs ) ; } else { return theme . obtainStyledAttributes ( attrs ) ; } } | Obtains the attribute which corresponds to a specific resource id from a theme . | 125 | 15 |
7,691 | public static boolean getBoolean ( @ NonNull final Context context , @ StyleRes final int themeResourceId , @ AttrRes final int resourceId ) { TypedArray typedArray = null ; try { typedArray = obtainStyledAttributes ( context , themeResourceId , resourceId ) ; return typedArray . getBoolean ( 0 , false ) ; } finally { if ( typedArray != null ) { typedArray . recycle ( ) ; } } } | Obtains the boolean value which corresponds to a specific resource id from a specific theme . | 95 | 17 |
7,692 | public static boolean getBoolean ( @ NonNull final Context context , @ AttrRes final int resourceId , final boolean defaultValue ) { return getBoolean ( context , - 1 , resourceId , defaultValue ) ; } | Obtains the boolean value which corresponds to a specific resource id from a context s theme . | 47 | 18 |
7,693 | public static int getInt ( @ NonNull final Context context , @ AttrRes final int resourceId , final int defaultValue ) { return getInt ( context , - 1 , resourceId , defaultValue ) ; } | Obtains the integer value which corresponds to a specific resource id from a context s theme . | 45 | 18 |
7,694 | public static float getFloat ( @ NonNull final Context context , @ AttrRes final int resourceId , final float defaultValue ) { return getFloat ( context , - 1 , resourceId , defaultValue ) ; } | Obtains the float value which corresponds to a specific resource id from a context s theme . | 45 | 18 |
7,695 | public static int getResId ( @ NonNull final Context context , @ AttrRes final int resourceId , final int defaultValue ) { return getResId ( context , - 1 , resourceId , defaultValue ) ; } | Obtains the resource id which corresponds to a specific resource id from a context s theme . | 47 | 18 |
7,696 | void setRequest ( HttpUriRequest request ) { requestLock . lock ( ) ; try { if ( this . request != null ) { throw new SparqlException ( "Command is already executing a request." ) ; } this . request = request ; } finally { requestLock . unlock ( ) ; } } | Sets the currently executing request . | 66 | 7 |
7,697 | private Result execute ( ResultType cmdType ) throws SparqlException { String mimeType = contentType ; // Validate the user-supplied MIME type. if ( mimeType != null && ! ResultFactory . supports ( mimeType , cmdType ) ) { logger . warn ( "Requested MIME content type '{}' does not support expected response type: {}" , mimeType , cmdType ) ; mimeType = null ; } // Get the default MIME type to request if ( mimeType == null ) { mimeType = ResultFactory . getDefaultMediaType ( cmdType ) ; } if ( logger . isDebugEnabled ( ) ) { logRequest ( cmdType , mimeType ) ; } try { HttpResponse response = SparqlCall . executeRequest ( this , mimeType ) ; return ResultFactory . getResult ( this , response , cmdType ) ; } catch ( Throwable t ) { release ( ) ; throw SparqlException . convert ( "Error creating SPARQL result from server response" , t ) ; } } | Executes the request and parses the response . | 230 | 10 |
7,698 | private void logRequest ( ResultType cmdType , String mimeType ) { StringBuilder sb = new StringBuilder ( "Executing SPARQL protocol request " ) ; sb . append ( "to endpoint <" ) . append ( ( ( ProtocolDataSource ) getConnection ( ) . getDataSource ( ) ) . getUrl ( ) ) . append ( "> " ) ; if ( mimeType != null ) { sb . append ( "for content type '" ) . append ( mimeType ) . append ( "' " ) ; } else { sb . append ( "for unknown content type " ) ; } if ( cmdType != null ) { sb . append ( "with expected results of type " ) . append ( cmdType ) . append ( "." ) ; } else { sb . append ( "with unknown expected result type." ) ; } logger . debug ( sb . toString ( ) ) ; } | Log the enpoint URL and request parameters . | 199 | 9 |
7,699 | public void initialize ( ) { thread = new Thread ( collectorProcessor ) ; thread . start ( ) ; for ( DriverNode dn : this . children ) { dn . initialize ( ) ; } } | initialize driver node and all children of the node | 43 | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.