idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
7,600 | public List < M > findNear ( double latitude , double longitude , int numImages ) { return getDatastore ( ) . find ( clazz ) . field ( "location.coordinates" ) . near ( latitude , longitude ) . limit ( numImages ) . asList ( ) ; } | Returns a list of media items that are geographically near the specified coordinates |
7,601 | public List < M > search ( String datefield , Date date , int width , int height , int count , int offset , UserAccount account , String query , List < String > sources ) { List < Criteria > l = new ArrayList < > ( ) ; Query < M > q = getDatastore ( ) . createQuery ( clazz ) ; if ( query != null ) { Pattern p = Pattern . compile ( "(.*)" + query + "(.*)" , Pattern . CASE_INSENSITIVE ) ; l . add ( q . or ( q . criteria ( "title" ) . equal ( p ) , q . criteria ( "description" ) . equal ( p ) ) ) ; } if ( account != null ) { l . add ( q . criteria ( "contributor" ) . equal ( account ) ) ; } if ( width > 0 ) l . add ( q . criteria ( "width" ) . greaterThanOrEq ( width ) ) ; if ( height > 0 ) l . add ( q . criteria ( "height" ) . greaterThanOrEq ( height ) ) ; if ( date != null ) l . add ( q . criteria ( datefield ) . greaterThanOrEq ( date ) ) ; if ( sources != null ) l . add ( q . criteria ( "source" ) . in ( sources ) ) ; q . and ( l . toArray ( new Criteria [ l . size ( ) ] ) ) ; return q . order ( "crawlDate" ) . offset ( offset ) . limit ( count ) . asList ( ) ; } | A search function |
7,602 | @ SuppressWarnings ( "deprecation" ) public static void setBackground ( final View view , final Drawable background ) { Condition . INSTANCE . ensureNotNull ( view , "The view may not be null" ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN ) { view . setBackground ( background ) ; } else { view . setBackgroundDrawable ( background ) ; } } | Sets the background of a view . Depending on the device s API level different methods are used for setting the background . |
7,603 | @ SuppressWarnings ( "deprecation" ) public static void removeOnGlobalLayoutListener ( final ViewTreeObserver observer , final OnGlobalLayoutListener listener ) { Condition . INSTANCE . ensureNotNull ( observer , "The view tree observer may not be null" ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN ) { observer . removeOnGlobalLayoutListener ( listener ) ; } else { observer . removeGlobalOnLayoutListener ( listener ) ; } } | Removes a previous registered global layout listener from a view tree observer . Depending on the device s API level different methods are used for removing the listener . |
7,604 | public static void removeFromParent ( final View view ) { Condition . INSTANCE . ensureNotNull ( view , "The view may not be null" ) ; ViewParent parent = view . getParent ( ) ; if ( parent instanceof ViewGroup ) { ( ( ViewGroup ) parent ) . removeView ( view ) ; } } | Removes a specific view from its parent if there is any . |
7,605 | private void obtainScaledEdge ( final TypedArray typedArray ) { int defaultValue = Edge . VERTICAL . getValue ( ) ; Edge scaledEdge = Edge . fromValue ( typedArray . getInt ( R . styleable . SquareImageView_scaledEdge , defaultValue ) ) ; setScaledEdge ( scaledEdge ) ; } | Obtains the scaled edge from a specific typed array . |
7,606 | private static boolean _isValidForCycle ( final Holiday aHoliday , final int nYear ) { final String sEvery = aHoliday . getEvery ( ) ; if ( sEvery != null && ! "EVERY_YEAR" . equals ( sEvery ) ) { if ( "ODD_YEARS" . equals ( sEvery ) ) return nYear % 2 != 0 ; if ( "EVEN_YEARS" . equals ( sEvery ) ) return nYear % 2 == 0 ; if ( aHoliday . getValidFrom ( ) != null ) { int nCycleYears = 0 ; if ( "2_YEARS" . equalsIgnoreCase ( sEvery ) ) nCycleYears = 2 ; else if ( "3_YEARS" . equalsIgnoreCase ( sEvery ) ) nCycleYears = 3 ; else if ( "4_YEARS" . equalsIgnoreCase ( sEvery ) ) nCycleYears = 4 ; else if ( "5_YEARS" . equalsIgnoreCase ( sEvery ) ) nCycleYears = 5 ; else if ( "6_YEARS" . equalsIgnoreCase ( sEvery ) ) nCycleYears = 6 ; else throw new IllegalArgumentException ( "Cannot handle unknown cycle type '" + sEvery + "'." ) ; return ( nYear - aHoliday . getValidFrom ( ) . intValue ( ) ) % nCycleYears == 0 ; } } return true ; } | Checks cyclic holidays and checks if the requested year is hit within the cycles . |
7,607 | private static boolean _isValidInYear ( final Holiday aHoliday , final int nYear ) { return ( aHoliday . getValidFrom ( ) == null || aHoliday . getValidFrom ( ) . intValue ( ) <= nYear ) && ( aHoliday . getValidTo ( ) == null || aHoliday . getValidTo ( ) . intValue ( ) >= nYear ) ; } | Checks whether the holiday is within the valid date range . |
7,608 | protected static final boolean shallBeMoved ( final LocalDate aFixed , final MovingCondition aMoveCond ) { return aFixed . getDayOfWeek ( ) == XMLHolidayHelper . getWeekday ( aMoveCond . getSubstitute ( ) ) ; } | Determines if the provided date shall be substituted . |
7,609 | private static LocalDate _moveDate ( final MovingCondition aMoveCond , final LocalDate aDate ) { final DayOfWeek nWeekday = XMLHolidayHelper . getWeekday ( aMoveCond . getWeekday ( ) ) ; final int nDirection = aMoveCond . getWith ( ) == With . NEXT ? 1 : - 1 ; LocalDate aMovedDate = aDate ; while ( aMovedDate . getDayOfWeek ( ) != nWeekday ) { aMovedDate = aMovedDate . plusDays ( nDirection ) ; } return aMovedDate ; } | Moves the date using the FixedMoving information |
7,610 | protected static final LocalDate moveDate ( final MoveableHoliday aMoveableHoliday , final LocalDate aFixed ) { for ( final MovingCondition aMoveCond : aMoveableHoliday . getMovingCondition ( ) ) if ( shallBeMoved ( aFixed , aMoveCond ) ) return _moveDate ( aMoveCond , aFixed ) ; return aFixed ; } | Moves a date if there are any moving conditions for this holiday and any of them fit . |
7,611 | protected final void setCurrentParentView ( final View currentParentView ) { Condition . INSTANCE . ensureNotNull ( currentParentView , "The parent view may not be null" ) ; this . currentParentView = currentParentView ; } | Sets the parent view whose appearance should currently be customized by the decorator . This method should never be called or overridden by any custom adapter implementation . |
7,612 | @ SuppressWarnings ( "unchecked" ) protected final < ViewType extends View > ViewType findViewById ( final int viewId ) { Condition . INSTANCE . ensureNotNull ( currentParentView , "No parent view set" , IllegalStateException . class ) ; ViewHolder viewHolder = ( ViewHolder ) currentParentView . getTag ( ) ; if ( viewHolder == null ) { viewHolder = new ViewHolder ( currentParentView ) ; currentParentView . setTag ( viewHolder ) ; } return ( ViewType ) viewHolder . findViewById ( viewId ) ; } | References the view which belongs to a specific resource ID by using the view holder pattern . The view is implicitly casted to the type of the field it is assigned to . |
7,613 | private void writeSlot ( T data , Throwable error ) { dataLock . lock ( ) ; try { this . error = error ; this . data = data ; availableCondition . signalAll ( ) ; } finally { dataLock . unlock ( ) ; } } | either data or error should be non - null |
7,614 | private T getAndClearUnderLock ( ) throws Throwable { if ( error != null ) { throw error ; } else { T retValue = data ; data = null ; return retValue ; } } | Get and clear the slot - MUST be called while holding the lock!! |
7,615 | public T take ( ) throws Throwable { dataLock . lock ( ) ; try { while ( data == null && error == null ) { try { availableCondition . await ( ) ; } catch ( InterruptedException e ) { } } 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 . |
7,616 | public Object yyparse ( yyInput yyLex , Object yydebug ) throws java . io . IOException { return yyparse ( yyLex ) ; } | the generated parser with debugging messages . Maintains a dynamic state and value stack . |
7,617 | 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 ) ) ; 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 . |
7,618 | public void addTransition ( DuzztAction action , DuzztState succ ) { transitions . put ( action , new DuzztTransition ( action , succ ) ) ; } | Adds a transition to this state . |
7,619 | public static ObjectNode getObj ( ObjectNode obj , String fieldName ) { return obj != null ? obj ( obj . get ( fieldName ) ) : null ; } | Returns the field from a ObjectNode as ObjectNode |
7,620 | 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 |
7,621 | 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 . |
7,622 | public static ArrayNode getArray ( ObjectNode obj , String fieldName ) { return obj == null ? null : array ( obj . get ( fieldName ) ) ; } | Returns the field from a ObjectNode as ArrayNode |
7,623 | 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 |
7,624 | 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 |
7,625 | 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 |
7,626 | 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 . |
7,627 | public static String getDefaultMediaType ( ResultType expectedType ) { ResponseFormat format = ( expectedType != null ) ? defaultTypeFormats . get ( expectedType ) : null ; return ( format != null ) ? format . mimeText : null ; } | Gets the default content type to use when sending a query request with the given expected result type . |
7,628 | private static final ResultParser findParser ( String mediaType , ResultType expectedType ) { ResponseFormat format = null ; 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 ( 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" ; 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 . |
7,629 | public static Filter equalsFilter ( String column , Object operand ) { return new Filter ( column , FilterOperator . EQUALS , operand ) ; } | Builds an EqualsFilter |
7,630 | public static Filter inFilter ( String column , Object operand ) { return new Filter ( column , FilterOperator . IN , operand ) ; } | Builds an InFilter |
7,631 | protected final View inflatePlaceholderView ( 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 . |
7,632 | protected final int getViewHeight ( 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 . |
7,633 | private OnItemClickListener createItemClickListener ( final OnItemClickListener encapsulatedListener ) { return new OnItemClickListener ( ) { 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 . |
7,634 | private OnItemLongClickListener createItemLongClickListener ( final OnItemLongClickListener encapsulatedListener ) { return new OnItemLongClickListener ( ) { 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 . |
7,635 | 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 . |
7,636 | 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 .. |
7,637 | public final void addHeaderView ( final View view , 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 . |
7,638 | public final void addFooterView ( final View view , 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 . |
7,639 | 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 . |
7,640 | 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 . |
7,641 | @ 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 . |
7,642 | 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 ) { 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 { req = new HttpGet ( u ) ; } if ( command . getTimeout ( ) != Command . NO_TIMEOUT ) { HttpParams reqParams = new BasicHttpParams ( ) ; HttpConnectionParams . setSoTimeout ( reqParams , ( int ) ( command . getTimeout ( ) * 1000 ) ) ; req . setParams ( reqParams ) ; } addHeaders ( req , mimeType ) ; command . setRequest ( req ) ; HttpResponse response = client . execute ( req ) ; StatusLine status = response . getStatusLine ( ) ; int code = status . getStatusCode ( ) ; 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 . |
7,643 | 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 . |
7,644 | public HolidayMap getHolidays ( final int nYear , 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 . |
7,645 | public final void setLogLevel ( 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 . |
7,646 | public final void logVerbose ( final Class < ? > tag , 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 . |
7,647 | public final void logDebug ( final Class < ? > tag , 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 . |
7,648 | public final void logInfo ( final Class < ? > tag , 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 . |
7,649 | public final void logWarn ( final Class < ? > tag , final String message , 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 . |
7,650 | public final void logError ( final Class < ? > tag , 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 . |
7,651 | public static Orientation getOrientation ( 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 . |
7,652 | public static DeviceType getDeviceType ( 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 . |
7,653 | public static int getDisplayWidth ( 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 . |
7,654 | public static int getDisplayHeight ( 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 . |
7,655 | 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 . |
7,656 | 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 |
7,657 | 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 . |
7,658 | 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 |
7,659 | private static int getSampleSize ( 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 . |
7,660 | public static Bitmap clipCircle ( 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 . |
7,661 | public static Bitmap clipCircle ( final Bitmap bitmap , final int size , final int borderWidth , 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 . |
7,662 | public static Bitmap clipSquare ( 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 . |
7,663 | @ SuppressWarnings ( "SuspiciousNameCombination" ) public static Bitmap clipSquare ( 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 . |
7,664 | public static Bitmap clipSquare ( final Bitmap bitmap , final int borderWidth , 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 . |
7,665 | public static Bitmap clipSquare ( final Bitmap bitmap , final int size , final int borderWidth , 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 . |
7,666 | public static Bitmap resize ( 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 . |
7,667 | public static Pair < Bitmap , Bitmap > splitHorizontally ( final Bitmap bitmap ) { return splitHorizontally ( bitmap , bitmap . getHeight ( ) / 2 ) ; } | Splits a specific bitmap horizontally at half . |
7,668 | public static Pair < Bitmap , Bitmap > splitHorizontally ( 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 . |
7,669 | public static Pair < Bitmap , Bitmap > splitVertically ( final Bitmap bitmap ) { return splitVertically ( bitmap , bitmap . getWidth ( ) / 2 ) ; } | Splits a specific bitmap vertically at half . |
7,670 | public static Pair < Bitmap , Bitmap > splitVertically ( 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 . |
7,671 | 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 . |
7,672 | public static Bitmap tint ( final Bitmap bitmap , 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 . |
7,673 | public static Bitmap drawableToBitmap ( 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 . |
7,674 | public static Bitmap colorToBitmap ( final int width , final int height , 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 . |
7,675 | public static Pair < Integer , Integer > getImageDimensions ( 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 . |
7,676 | public static Pair < Integer , Integer > getImageDimensions ( final Context context , 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 . |
7,677 | public static Bitmap loadThumbnail ( 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 . |
7,678 | public static void compressToFile ( final Bitmap bitmap , final File file , 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 . |
7,679 | public static byte [ ] compressToByteArray ( final Bitmap bitmap , 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 . |
7,680 | 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 |
7,681 | private OnItemClickListener createItemClickListener ( ) { return new OnItemClickListener ( ) { 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 . |
7,682 | private OnItemLongClickListener createItemLongClickListener ( ) { return new OnItemLongClickListener ( ) { 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 . |
7,683 | 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 . |
7,684 | 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 . |
7,685 | 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 . |
7,686 | private boolean notifyOnGroupClicked ( 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 . |
7,687 | private boolean notifyOnChildClicked ( 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 . |
7,688 | private void notifyOnItemClicked ( 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 . |
7,689 | private boolean notifyOnItemLongClicked ( 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 . |
7,690 | 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 . |
7,691 | public final void setAdapter ( 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 . |
7,692 | 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 . |
7,693 | 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 . |
7,694 | 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 |
7,695 | 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 |
7,696 | 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 |
7,697 | 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 |
7,698 | 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 |
7,699 | public final Pair < View , Boolean > inflate ( final ItemType item , final ViewGroup parent , final boolean useCache , 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 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.