idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
12,100 | private T getCurrent ( T item ) { for ( String key : order ) { ConcurrentCache < Object , T > cache = caches . get ( key ) ; Object val = getValue ( key , item ) ; T tmp ; if ( val instanceof BigDecimal ) { val = ( ( BigDecimal ) val ) . longValue ( ) ; } tmp = cache . get ( val ) ; if ( tmp != null ) { if ( tmp instanceof CachedItem ) { if ( ( ( CachedItem ) tmp ) . isValidForCache ( ) ) { return tmp ; } } else { return tmp ; } } } return item ; } | Provides the current version of the specified item stored in the cache . If no item matches the passed in item then the passed in item is returned but not cached . This better be called from a synchronized block! |
12,101 | public HashMap < String , Object > getKeys ( T item ) { HashMap < String , Object > keys = new HashMap < String , Object > ( ) ; for ( String key : caches . keySet ( ) ) { keys . put ( key , getValue ( key , item ) ) ; } return keys ; } | Provides the values for all of the unique identifiers managed by the cache . |
12,102 | private Object getValue ( String key , T item ) { Class cls = item . getClass ( ) ; while ( true ) { try { Field f = cls . getDeclaredField ( key ) ; int m = f . getModifiers ( ) ; if ( Modifier . isTransient ( m ) || Modifier . isStatic ( m ) ) { return null ; } f . setAccessible ( true ) ; return f . get ( item ) ; } catch ( Exception e ) { Class [ ] params = new Class [ 0 ] ; String mname ; mname = "get" + key . substring ( 0 , 1 ) . toUpperCase ( ) + key . substring ( 1 ) ; try { Method method = cls . getDeclaredMethod ( mname , params ) ; Object [ ] args = new Object [ 0 ] ; return method . invoke ( item , args ) ; } catch ( IllegalAccessException e2 ) { } catch ( SecurityException e2 ) { } catch ( NoSuchMethodException e2 ) { } catch ( IllegalArgumentException e2 ) { } catch ( InvocationTargetException e2 ) { } cls = cls . getSuperclass ( ) ; if ( cls == null || cls . getName ( ) . getClass ( ) . equals ( Object . class . getName ( ) ) ) { throw new CacheManagementException ( "No such property: " + key ) ; } } } } | Provides the actual value for the specified unique ID key for the specified object . |
12,103 | private void put ( T item ) { HashMap < String , Object > keys ; if ( item == null ) { throw new NullPointerException ( "Multi caches may not have null values." ) ; } keys = getKeys ( item ) ; synchronized ( this ) { for ( String key : caches . keySet ( ) ) { ConcurrentCache < Object , T > cache = caches . get ( key ) ; Object ob = keys . get ( key ) ; if ( ob instanceof BigDecimal ) { ob = ( ( BigDecimal ) ob ) . longValue ( ) ; } cache . put ( ob , item ) ; } } } | Places the specified item into the cache regardless of current cache state . |
12,104 | public void cache ( Object key , T val ) { cache . put ( key , new SoftReference < T > ( val ) ) ; } | Caches the specified object identified by the specified key . |
12,105 | public boolean containsAll ( Collection < ? > coll ) { for ( Object item : coll ) { if ( ! contains ( item ) ) { return false ; } } return true ; } | Checks the passed in collection and determines if all elements of that collection are contained within this cache . Care should be taken in reading too much into a failure . If one of the elements was once in this cache but has expired due to inactivity this method will return false . |
12,106 | public boolean containsKey ( Object key ) { if ( ! cache . containsKey ( key ) ) { return false ; } else { SoftReference < T > ref = cache . get ( key ) ; T ob = ref . get ( ) ; if ( ob == null ) { release ( key ) ; return false ; } if ( ob instanceof CachedItem ) { if ( ! ( ( CachedItem ) ob ) . isValidForCache ( ) ) { release ( key ) ; return false ; } } return true ; } } | Checks if an object with the specified key is in the cache . |
12,107 | public < K extends Serializable & Comparable > Process < K > newProcess ( ) { final String queueOwner = partition == null ? null : partition . getQueueOwnerKey ( ) ; Callback < ProcessWrapper < K > > callback = new Callback < ProcessWrapper < K > > ( ) { protected void doAction ( ) { ProcessWrapper < K > process = ProcessWrapper . getNewInstance ( queueOwner , is_persistent , implementation_options ) ; ProcessPersistence < ProcessEntity < K > , K > processHome = process . setDetails ( process_name , queue , process_description , user , occurrence , visibility , access , resilience , output , pre_processes , post_processes , keep_completed , process_listeners , locale , implementation_options ) ; if ( report_type != null ) process . setReportType ( report_type ) ; if ( source_name != null ) process . setSourceName ( source_name ) ; setupProcess ( new Process ( process ) ) ; preSubmitBatchJobProcessing ( ) ; if ( is_persistent ) processHome . persist ( ) ; process . getContainingServer ( ) . submitProcess ( process ) ; _return ( process ) ; } } ; QueujTransaction < K > transaction = ( QueujTransaction < K > ) QueujFactory . getTransaction ( ) ; return new Process < K > ( transaction . doTransaction ( queueOwner , is_persistent , callback , true ) ) ; } | Creates the Process using the parameters that have been set . |
12,108 | char [ ] print ( T bean ) { char [ ] output = new char [ type . length ( ) ] ; Arrays . fill ( output , type . fill ( ) ) ; for ( Slot slot : slots . values ( ) ) { if ( ! slot . reference . isReadable ( ) ) { continue ; } Object value = slot . reference . readValue ( bean ) ; CharSequence content = slot . converter . toCharacters ( value ) ; if ( content . length ( ) > slot . field . length ( ) ) { content = slot . field . trim ( ) . trim ( content , slot . field . length ( ) , slot . field . align ( ) ) ; } slot . field . align ( ) . fill ( content , output , slot . field . start ( ) , slot . field . length ( ) , slot . fill ) ; } return output ; } | Print bean into given char array FIXME It s not completely working yet |
12,109 | public String formatMessage ( String key , Object [ ] args ) { try { String raw = this . getMessage ( key ) ; return MessageFormat . format ( raw , args ) ; } catch ( MissingResourceException ex ) { return "???!" + key + "!???" ; } } | Retorna uma mensagem formatada utilizando o MessageFormat . |
12,110 | public void addFilePart ( String fieldName , File uploadFile ) throws FileNotFoundException { stream . put ( fieldName , new NamedInputStream ( uploadFile . getName ( ) , new FileInputStream ( uploadFile ) , "binary" , URLConnection . guessContentTypeFromName ( uploadFile . getName ( ) ) ) ) ; } | Adds a file to the request |
12,111 | public void addInputStreamPart ( String name , String inputStreamName , InputStream inputStream , String contentTransferEncoding , String contentType ) { stream . put ( name , new NamedInputStream ( inputStreamName , inputStream , contentTransferEncoding , contentType ) ) ; } | Adds an inputstream to te request |
12,112 | public static < T , K > HashMap < K , T > toHashMap ( Collection < T > entities , Function < T , K > keyMapper ) { return toMap ( entities , keyMapper , HashMap < K , T > :: new ) ; } | Convert a collection to HashMap The key is decided by keyMapper value is the object in collection |
12,113 | public static < T , K > Hashtable < K , T > toHashtable ( Collection < T > entities , Function < T , K > keyMapper ) { return toMap ( entities , keyMapper , Hashtable < K , T > :: new ) ; } | Convert a collection to Hashtable . The key is decided by keyMapper value is the object in collection |
12,114 | public static < T , K , V , P , C extends Collection < V > > HashMap < K , HashMap < P , C > > groupTwice ( Collection < T > entities , Function < T , K > keyMapper1 , Function < T , P > keyMapper2 , Function < T , V > valueMapper , Supplier < C > collectionFactory ) { if ( entities == null ) return null ; return entities . stream ( ) . collect ( Collectors . groupingBy ( keyMapper1 , HashMap :: new , Collectors . groupingBy ( keyMapper2 , HashMap :: new , Collectors . mapping ( valueMapper , Collectors . toCollection ( collectionFactory ) ) ) ) ) ; } | Grouping into 2 levels |
12,115 | public static < T , K , V , P > HashMap < K , HashMap < P , V > > matrix ( Collection < T > entities , Function < T , K > keyMapper1 , Function < T , P > keyMapper2 , Function < T , V > valueMapper ) { if ( entities == null ) return null ; return entities . stream ( ) . collect ( Collectors . groupingBy ( keyMapper1 , HashMap :: new , Collectors . toMap ( keyMapper2 , valueMapper , ( a , b ) -> a , HashMap :: new ) ) ) ; } | Similar to grouping into 2 levels except each unit is not a Collection but a single object |
12,116 | public static < T , K > K [ ] toArray ( Collection < T > entities , Function < T , K > keyMapper , K [ ] arr ) { if ( entities == null ) return null ; return entities . stream ( ) . map ( keyMapper ) . toArray ( size -> arr ) ; } | Extract attribute from objects in collection and store them in array and return . |
12,117 | public static < T , K > boolean moveUp ( List < T > list , K key , Function < T , K > keyMapper , int n ) { if ( list == null ) return false ; ArrayList < T > newList = new ArrayList < T > ( ) ; boolean changed = false ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { T item = list . get ( i ) ; if ( i > 0 && key . equals ( keyMapper . apply ( item ) ) ) { int posi = i - n ; if ( posi < 0 ) posi = 0 ; newList . add ( posi , item ) ; changed = true ; } else newList . add ( item ) ; } if ( changed ) { list . clear ( ) ; list . addAll ( newList ) ; return true ; } return false ; } | Move an object in List up |
12,118 | private ClickableMarkerShape translateMarker ( ClickableMarkerShape shape , int amountOfMarkers ) { if ( amountOfMarkers % imagePerRow != 0 ) { int size = choiceListImageSize + 6 ; shape . setTranslation ( size * ( amountOfMarkers % imagePerRow ) , size * ( amountOfMarkers / imagePerRow ) ) ; } return shape ; } | used for displaying marker SVG elements in a drawing area . |
12,119 | public static void writeLong ( long value , byte [ ] dest , int offset ) throws IllegalArgumentException { if ( dest . length < offset + 8 ) { throw new IllegalArgumentException ( "Destination byte array does not have enough space to write long from offset " + offset ) ; } long t = value ; for ( int i = offset ; i < offset + 8 ; i ++ ) { dest [ i ] = ( byte ) ( t & 0xff ) ; t = t >> 8 ; } } | Write long value to given byte array |
12,120 | public static long readLong ( byte [ ] src , int offset ) throws IllegalArgumentException { if ( src . length < offset ) { throw new IllegalArgumentException ( "There's nothing to read in src from offset " + offset ) ; } long r = 0 ; for ( int i = offset , j = 0 ; i < src . length && j < 64 ; i ++ , j += 8 ) { r += ( ( long ) src [ i ] & 0xff ) << j ; } return r ; } | Read long value from given source byte array |
12,121 | public static String getGMTTimeString ( long milliSeconds ) { SimpleDateFormat sdf = new SimpleDateFormat ( "E, d MMM yyyy HH:mm:ss 'GMT'" , Locale . ENGLISH ) ; return sdf . format ( new Date ( milliSeconds ) ) ; } | Retorna uma data em GMT . |
12,122 | public static String toTitleCase ( String text ) { StringBuilder str = new StringBuilder ( ) ; String [ ] words = text . trim ( ) . split ( "\\s" ) ; for ( int i = 0 ; i < words . length ; i ++ ) { if ( words [ i ] . length ( ) > 0 ) { if ( i > 0 ) { str . append ( " " ) ; } String lower = words [ i ] . toLowerCase ( Locale . getDefault ( ) ) ; if ( words [ i ] . length ( ) == 1 ) { str . append ( lower ) ; } else if ( words [ i ] . length ( ) == 2 ) { if ( lower . equals ( "da" ) || lower . equals ( "de" ) || lower . equals ( "do" ) || lower . equals ( "di" ) ) str . append ( lower ) ; else str . append ( StringUtils . capitalize ( lower ) ) ; } else { str . append ( StringUtils . capitalize ( lower ) ) ; } } } return str . toString ( ) ; } | Converte string para title case . |
12,123 | public static < T > T firstValue ( List < T > list ) { if ( list != null && ! list . isEmpty ( ) ) { return list . get ( 0 ) ; } return null ; } | Returns the first value of a list or null if the list is empty . |
12,124 | public static Map < String , Object > getBeanProperties ( Object bean ) { Map < String , Object > props = new HashMap < > ( ) ; if ( bean == null ) { return props ; } Class < ? > clazz = bean . getClass ( ) ; try { Field [ ] fields = clazz . getFields ( ) ; for ( Field field : fields ) { String name = field . getName ( ) ; if ( ! name . equals ( "class" ) ) { props . put ( field . getName ( ) , field . get ( bean ) ) ; } } BeanInfo info = Introspector . getBeanInfo ( clazz ) ; for ( PropertyDescriptor desc : info . getPropertyDescriptors ( ) ) { Method readMethod = desc . getReadMethod ( ) ; String name = desc . getName ( ) ; if ( readMethod != null && ! name . equals ( "class" ) ) { props . put ( desc . getName ( ) , readMethod . invoke ( bean ) ) ; } } return props ; } catch ( IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { throw new UniformException ( "Error while getting bean object properties of class" + clazz . getName ( ) , ex ) ; } } | Returns an index of all the accessible properties of a Java bean object . |
12,125 | public < T > Dao < T , ? > getDao ( Class < T > clz ) throws SQLException { return DaoManager . createDao ( getConnectionSource ( ) , clz ) ; } | Gets the data access object for an entity class that has an integer primary key data type . Dao caching is performed by the ORM library so you don t need to take pains to hold on to this reference . |
12,126 | public < T , K > Dao < T , K > getDao ( Class < T > clazz , Class < K > keyType ) throws SQLException { return DaoManager . createDao ( getConnectionSource ( ) , clazz ) ; } | Gets the data access object for an entity class with a given key type . Dao caching is performed by the ORM library so you don t need to take pains to hold on to this reference . |
12,127 | public static ExecutorService createFixedTimeoutExecutorService ( int poolSize , long keepAliveTime , TimeUnit timeUnit ) { ThreadPoolExecutor e = new ThreadPoolExecutor ( poolSize , poolSize , keepAliveTime , timeUnit , new LinkedBlockingQueue < Runnable > ( ) ) ; e . allowCoreThreadTimeOut ( true ) ; return e ; } | Creates an executor service with a fixed pool size that will time out after a certain period of inactivity . |
12,128 | public < O extends Comparable > Set < O > transform ( Set < O > set ) { return checkNotNull ( set ) ; } | A set transformer that returns the supplied set . |
12,129 | public static Connection newInstance ( Connection conn ) { return ( Connection ) java . lang . reflect . Proxy . newProxyInstance ( Connection . class . getClassLoader ( ) , new Class [ ] { Connection . class } , new ConnectionProxy ( conn ) ) ; } | Creates new SQL Connection Proxy instance |
12,130 | public void removeOverride ( String operation ) { if ( this . overrideOnce . containsKey ( operation ) == true ) { this . overrideOnce . remove ( operation ) ; } if ( this . override . containsKey ( operation ) == true ) { this . override . remove ( operation ) ; } } | Removes override . |
12,131 | public boolean hasOverride ( String operation ) { boolean result = false ; if ( this . overrideOnce . containsKey ( operation ) == true || this . override . containsKey ( operation ) == true ) { result = true ; } return result ; } | Checks if override is present but it won t be actually read |
12,132 | public Object getOverride ( String operation ) { Object result = null ; if ( this . overrideOnce . containsKey ( operation ) == true ) { result = this . overrideOnce . get ( operation ) ; this . overrideOnce . remove ( operation ) ; } else if ( this . override . containsKey ( operation ) == true ) { result = this . override . get ( operation ) ; } return result ; } | Return override value |
12,133 | public void lastPage ( ) { int idx = pages . size ( ) - 1 ; if ( idx < 0 ) { idx = 0 ; } if ( pageIndex != idx ) { pageIndex = idx ; currentPage = null ; } } | Navigates to the last page in the iterator . |
12,134 | private boolean loadPage ( ) { Collection < T > list ; if ( pages . size ( ) <= pageIndex ) { return false ; } list = pages . get ( pageIndex ) ; currentPage = list . iterator ( ) ; return true ; } | Loads the next page |
12,135 | public boolean setPage ( int p ) { p -- ; if ( p < 0 ) { return false ; } if ( p >= pages . size ( ) ) { return false ; } pageIndex = p ; currentPage = null ; return true ; } | Navigates to the specified page number with 0 being the first page . |
12,136 | public void setPageSize ( int ps ) { ArrayList < T > tmp = new ArrayList < T > ( ) ; for ( Collection < T > page : pages ) { for ( T item : page ) { tmp . add ( item ) ; } } setup ( tmp , ps , sorter ) ; } | Changes the page size of the list and reforms the list . May cause unexpected behavior in terms of what is considered the current page after resizing . |
12,137 | private void setup ( Collection < T > items , int ps , Comparator < T > sort ) { Collection < T > list ; Iterator < T > it ; if ( sort == null ) { list = items ; } else { list = new TreeSet < T > ( sort ) ; list . addAll ( items ) ; } sorter = sort ; pageSize = ps ; pages = new ArrayList < Collection < T > > ( ) ; it = list . iterator ( ) ; while ( it . hasNext ( ) ) { ArrayList < T > page = new ArrayList < T > ( ) ; pages . add ( page ) ; for ( int i = 0 ; i < ps ; i ++ ) { T ob ; if ( ! it . hasNext ( ) ) { break ; } ob = it . next ( ) ; page . add ( ob ) ; } } } | Sets the collection up using the specified parameters . |
12,138 | public void sort ( Comparator < T > sort ) { ArrayList < T > tmp = new ArrayList < T > ( ) ; for ( Collection < T > page : pages ) { tmp . addAll ( page ) ; } setup ( tmp , pageSize , sort ) ; } | Re - sorts the list according to the specified sorter . |
12,139 | private static void setSLF4jAvailable ( boolean slf4jAvailable ) { if ( ( SLF4jAvailable != null && SLF4jAvailable == true ) && slf4jAvailable == false ) { Logger . getAnonymousLogger ( ) . warning ( "Switching off SLF4j availability. Usually means that SLF4j was found but exception was thrown during it's usage" ) ; } SLF4jAvailable = slf4jAvailable ; } | Standard Setter function . Informs if SLF4j availability was set from true into false |
12,140 | protected Map < String , List < Element > > elementsIndexByName ( ) { HashMap < String , List < Element > > index = new HashMap < > ( ) ; for ( Object part : renderingParts ) { if ( part instanceof Element ) { Element element = ( Element ) part ; String name = element . getProperty ( "name" ) ; if ( name != null && ! name . trim ( ) . isEmpty ( ) ) { boolean multiValued = element . isMultiValue ( ) ; if ( multiValued && index . containsKey ( name ) ) { throw new IllegalStateException ( "Name '" + name + "' cannot be repeated in the form if any of the elements is multi-valued" ) ; } if ( name . contains ( "[" ) && name . contains ( "]" ) ) { throw new IllegalStateException ( "Name '" + name + "' cannot be in array form" ) ; } if ( ! index . containsKey ( name ) ) { index . put ( name , new ArrayList < Element > ( ) ) ; } else { Class < ? > expectedType = index . get ( name ) . get ( 0 ) . getValueType ( ) ; if ( ! element . getValueType ( ) . equals ( expectedType ) ) { throw new IllegalStateException ( "Multiple elements with same name '" + name + "' should all have the same value type" ) ; } } index . get ( name ) . add ( element ) ; } } } return index ; } | Creates an index of the form element by their name . Makes sure that the names are not repeated and are valid . |
12,141 | protected Integer invokeSection ( ) { try { S runner = getRunner ( getRunObject ( ) ) ; if ( run_method_str == null ) return null ; createRunMethod ( param_types , runner ) ; Object [ ] local_params = ( Object [ ] ) params . clone ( ) ; Integer result_code = ( Integer ) run_method . invoke ( runner , local_params ) ; return result_code ; } catch ( ForceProcessComplete fpc ) { throw fpc ; } catch ( ForceRescheduleException fre ) { throw fre ; } catch ( InvocationTargetException ite ) { Throwable cause = ite . getCause ( ) ; if ( cause instanceof ForceProcessComplete || cause instanceof ForceRescheduleException ) throw ( RuntimeException ) cause ; new QueujException ( ite ) ; return BatchProcessServer . FAILURE ; } catch ( Exception e ) { new QueujException ( e ) ; return BatchProcessServer . FAILURE ; } } | reflectively runs the relevant method |
12,142 | @ SuppressWarnings ( "unchecked" ) protected K createKey ( QueryParameters params ) throws MjdbcException { K result = null ; if ( columnName == null ) { result = ( K ) params . getValue ( params . getNameByPosition ( columnIndex ) ) ; } else { result = ( K ) params . getValue ( columnName ) ; } return result ; } | Generates key for query output row |
12,143 | private void prepareNextIterator ( ) { if ( currentIterator == null || ! currentIterator . hasNext ( ) ) { currentIterator = null ; while ( iteratorIterator . hasNext ( ) ) { currentIterator = iteratorIterator . next ( ) ; if ( currentIterator . hasNext ( ) ) { break ; } currentIterator = null ; } } } | Prepare the next iterator to use |
12,144 | public static String getClassName ( Map < String , Object > map ) { String className = null ; if ( map . containsKey ( MAP_CLASS_NAME ) == true ) { className = ( String ) map . get ( MAP_CLASS_NAME ) ; } return className ; } | InputHandler converts every object into Map . This function returns Class name of object from which this Map was created . |
12,145 | public static void setClassName ( Map < String , Object > map , String className ) { String processedClassName = className ; if ( processedClassName != null ) { processedClassName = processedClassName . replaceAll ( "\\." , "_" ) ; } map . put ( MAP_CLASS_NAME , processedClassName ) ; } | InputHandler converts every object into Map . Sets Class name of object from which this Map was created . |
12,146 | public static boolean isClassNameKey ( String key ) { boolean equals = false ; if ( MAP_CLASS_NAME . equals ( key ) == true ) { equals = true ; } return equals ; } | Checks if this Map key is Map Class Name |
12,147 | public static String addClassName ( String className , String key ) { return className . toLowerCase ( ) + "." + key . toLowerCase ( ) ; } | Used by InputHandlers . Allows combining of few Maps into one Map . In order to avoid collisions - Map Class name is user as prefix |
12,148 | public FTSeries getTvArtwork ( String id ) throws FanartTvException { URL url = ftapi . getImageUrl ( BaseType . TV , id ) ; String page = requestWebPage ( url ) ; FTSeries series = null ; try { series = mapper . readValue ( page , FTSeries . class ) ; } catch ( IOException ex ) { throw new FanartTvException ( ApiExceptionType . MAPPING_FAILED , "Failed to get data for ID " + id , url , ex ) ; } if ( series . isError ( ) ) { throw new FanartTvException ( ApiExceptionType . ID_NOT_FOUND , series . getErrorMessage ( ) ) ; } return series ; } | Get images for TV |
12,149 | public FTMovie getMovieArtwork ( String id ) throws FanartTvException { URL url = ftapi . getImageUrl ( BaseType . MOVIE , id ) ; String page = requestWebPage ( url ) ; FTMovie movie = null ; try { movie = mapper . readValue ( page , FTMovie . class ) ; } catch ( IOException ex ) { throw new FanartTvException ( ApiExceptionType . MAPPING_FAILED , "Failed to get Movie artwork with ID " + id , url , ex ) ; } if ( movie . isError ( ) ) { throw new FanartTvException ( ApiExceptionType . ID_NOT_FOUND , movie . getErrorMessage ( ) ) ; } return movie ; } | Get images for Movie |
12,150 | public FTMusicArtist getMusicArtist ( String id ) throws FanartTvException { URL url = ftapi . getImageUrl ( BaseType . ARTIST , id ) ; String page = requestWebPage ( url ) ; FTMusicArtist artist = null ; try { artist = mapper . readValue ( page , FTMusicArtist . class ) ; } catch ( IOException ex ) { throw new FanartTvException ( ApiExceptionType . MAPPING_FAILED , "Fauled to get Music Artist with ID " + id , url , ex ) ; } return artist ; } | Get images for artist |
12,151 | private String requestWebPage ( URL url ) throws FanartTvException { try { HttpGet httpGet = new HttpGet ( url . toURI ( ) ) ; httpGet . addHeader ( "accept" , "application/json" ) ; final DigestedResponse response = DigestedResponseReader . requestContent ( httpClient , httpGet , charset ) ; if ( response . getStatusCode ( ) >= 500 ) { throw new FanartTvException ( ApiExceptionType . HTTP_503_ERROR , response . getContent ( ) , response . getStatusCode ( ) , url ) ; } else if ( response . getStatusCode ( ) >= 300 ) { throw new FanartTvException ( ApiExceptionType . HTTP_404_ERROR , response . getContent ( ) , response . getStatusCode ( ) , url ) ; } return response . getContent ( ) ; } catch ( URISyntaxException ex ) { throw new FanartTvException ( ApiExceptionType . CONNECTION_ERROR , "Invalid URL" , url , ex ) ; } catch ( IOException ex ) { throw new FanartTvException ( ApiExceptionType . CONNECTION_ERROR , "Error retrieving URL" , url , ex ) ; } } | Download the URL into a String |
12,152 | ParamExpressionBuilder < T , EB , VEB > param ( ) { return new ParamExpressionBuilder < T , EB , VEB > ( new ExpressionHandler < MethodCallBuilder < T , EB , VEB > > ( ) { public MethodCallBuilder < T , EB , VEB > handleExpression ( Expression e ) { return new MethodCallBuilder < T , EB , VEB > ( factory , callee , methodName , expressionHandler , parameters . append ( e ) ) ; } } ) ; } | pass a parameter to the method |
12,153 | public FoxHttpRequestBuilder addRequestQueryEntry ( String name , String value ) { foxHttpRequest . getRequestQuery ( ) . addQueryEntry ( name , value ) ; return this ; } | Add a new query entry |
12,154 | public FoxHttpRequest build ( ) throws MalformedURLException , FoxHttpRequestException { if ( this . url != null ) { foxHttpRequest . setUrl ( this . url ) ; } return foxHttpRequest ; } | Get the FoxHttpRequest of this builder |
12,155 | public String generateJs ( final Settings settings , final String methodName ) { final Map < String , Object > variables = initializeVariables ( settings . asSet ( ) ) ; final String stringTemplateContent = generateJavascriptTemplateContent ( variables , methodName ) ; final StringTextTemplate stringTextTemplate = new StringTextTemplate ( stringTemplateContent ) ; stringTextTemplate . interpolate ( variables ) ; try { return stringTextTemplate . asString ( ) ; } finally { try { stringTextTemplate . close ( ) ; } catch ( final IOException e ) { LOGGER . error ( e . getMessage ( ) , e ) ; } } } | Generate the javascript code . |
12,156 | protected void generateJsOptionsForTemplateContent ( final Map < String , Object > variables , final StringBuilder sb ) { sb . append ( "{\n" ) ; int count = 1 ; Object localComponentId = null ; if ( withComponentId ) { localComponentId = variables . get ( COMPONENT_ID ) ; variables . remove ( COMPONENT_ID ) ; } for ( final Map . Entry < String , Object > entry : variables . entrySet ( ) ) { final String key = entry . getKey ( ) ; sb . append ( key ) . append ( ": ${" ) . append ( key ) . append ( "}" ) ; if ( count < variables . size ( ) ) { sb . append ( ",\n" ) ; } else { sb . append ( "\n" ) ; } count ++ ; } if ( withComponentId ) { variables . put ( COMPONENT_ID , localComponentId ) ; } sb . append ( "}" ) ; } | Generate the javascript options for template content . |
12,157 | protected Map < String , Object > initializeVariables ( final Set < StringTextValue < ? > > allSettings ) { final Map < String , Object > variables = new HashMap < > ( ) ; if ( withComponentId ) { variables . put ( JavascriptGenerator . COMPONENT_ID , componentId ) ; } for ( final StringTextValue < ? > textValue : allSettings ) { if ( ! textValue . isInitialValue ( ) ) { switch ( textValue . getType ( ) ) { case STRING : if ( textValue . getQuotationMarkType ( ) . equals ( QuotationMarkType . NONE ) ) { variables . put ( textValue . getName ( ) , textValue . getValue ( ) ) ; break ; } TextTemplateExtensions . setVariableWithSingleQuotationMarks ( textValue . getName ( ) , textValue . getValue ( ) , variables ) ; break ; case ENUM : TextTemplateExtensions . setVariableWithSingleQuotationMarks ( textValue . getName ( ) , ( ( ValueEnum ) textValue . getValue ( ) ) . getValue ( ) , variables ) ; break ; case STRING_INTEGER : TextTemplateExtensions . setVariableWithSingleQuotationMarks ( textValue . getName ( ) , textValue . getValue ( ) , variables ) ; break ; default : variables . put ( textValue . getName ( ) , textValue . getValue ( ) ) ; break ; } } } return variables ; } | Sets the values to the map . If the default value is set than it will not be added to the map for later not to generate js for it . |
12,158 | private ConversionService getConversionService ( ) { if ( conversionService != null ) return conversionService ; try { conversionService = ( ConversionService ) ctx . getBean ( "daoConversionService" ) ; if ( conversionService != null ) return conversionService ; } catch ( Exception e ) { } ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean ( ) ; factory . afterPropertiesSet ( ) ; conversionService = factory . getObject ( ) ; return conversionService ; } | get ConversionService . If a service is defined in context with name daoConversionService then use it otherwise create a default one |
12,159 | private static boolean isPublicInstanceMethod ( Method method ) { return Modifier . isPublic ( method . getModifiers ( ) ) && ! Modifier . isStatic ( method . getModifiers ( ) ) ; } | Returns whether the modifiers of the given method show that it is a public instance method . |
12,160 | public static String create ( Map < String , String > properties ) throws RottenTomatoesException { if ( StringUtils . isBlank ( apiKey ) ) { throw new RottenTomatoesException ( ApiExceptionType . INVALID_URL , "Missing API Key" ) ; } StringBuilder urlBuilder = new StringBuilder ( API_SITE ) ; urlBuilder . append ( API_VERSION ) ; urlBuilder . append ( getUrlFromProps ( properties ) ) ; urlBuilder . append ( API_PREFIX ) . append ( apiKey ) ; for ( Map . Entry < String , String > property : properties . entrySet ( ) ) { if ( StringUtils . isNotBlank ( property . getKey ( ) ) && StringUtils . isNotBlank ( property . getValue ( ) ) ) { urlBuilder . append ( "&" ) . append ( property . getKey ( ) ) . append ( "=" ) . append ( property . getValue ( ) ) ; } } LOG . trace ( "URL: {}" , urlBuilder . toString ( ) ) ; return urlBuilder . toString ( ) ; } | Create the URL |
12,161 | private static String getUrlFromProps ( Map < String , String > properties ) throws RottenTomatoesException { if ( properties . containsKey ( PROPERTY_URL ) && StringUtils . isNotBlank ( properties . get ( PROPERTY_URL ) ) ) { String url = properties . get ( PROPERTY_URL ) ; if ( properties . containsKey ( PROPERTY_ID ) && StringUtils . isNotBlank ( properties . get ( PROPERTY_ID ) ) ) { url = url . replace ( MOVIE_ID , String . valueOf ( properties . get ( PROPERTY_ID ) ) ) ; properties . remove ( PROPERTY_ID ) ; } properties . remove ( PROPERTY_URL ) ; return url ; } else { throw new RottenTomatoesException ( ApiExceptionType . INVALID_URL , "No URL specified" ) ; } } | Get and process the URL from the properties map |
12,162 | public static boolean validateProperty ( String key , String value ) { return ! StringUtils . isBlank ( key ) && ! StringUtils . isBlank ( value ) ; } | Validate the key and value of a property |
12,163 | public static String validateLimit ( int limit ) { if ( limit < 1 ) { return "" ; } if ( limit > LIMIT_MAX ) { return String . valueOf ( LIMIT_MAX ) ; } return String . valueOf ( limit ) ; } | Validate and convert the limit property |
12,164 | public static String validateCountry ( String country ) { if ( country . length ( ) > DEFAULT_COUNTRY_LEN ) { return country . substring ( 0 , DEFAULT_COUNTRY_LEN ) ; } return country ; } | Validate the country property |
12,165 | public void addArtwork ( FTArtworkType artworkType , List < FTArtwork > artworkList ) { artwork . put ( artworkType , artworkList ) ; } | Add artwork to the list |
12,166 | public List < FTArtwork > getArtwork ( FTArtworkType artworkType ) { if ( artwork . containsKey ( artworkType ) ) { return artwork . get ( artworkType ) ; } return Collections . emptyList ( ) ; } | Get a specific type of artwork |
12,167 | public boolean hasArtwork ( ) { for ( FTArtworkType at : FTArtworkType . values ( ) ) { if ( hasArtwork ( at ) && ! artwork . isEmpty ( ) ) { return true ; } } return false ; } | Determines if there is any artwork associated with the series |
12,168 | public boolean hasArtwork ( FTArtworkType artworkType ) { return artwork . containsKey ( artworkType ) && ! artwork . get ( artworkType ) . isEmpty ( ) ; } | Determines if the series has a specific type of artwork |
12,169 | public ServiceFault getFault ( boolean checkHash ) throws FoxHttpResponseException { try { String body = getStringBody ( ) ; ServiceResult < ServiceFault > result = parser . fromJson ( body , new TypeToken < ServiceResult < ServiceFault > > ( ) { } . getType ( ) ) ; foxHttpClient . getFoxHttpLogger ( ) . log ( "processFault(" + result + ")" ) ; checkHash ( checkHash , body , result ) ; return result . getContent ( ) ; } catch ( IOException e ) { throw new FoxHttpResponseException ( e ) ; } } | Get the fault of the service result |
12,170 | public TableRef create ( Key key , Throughput throughput , OnTableCreation onTableCreation , OnError onError ) { PostBodyBuilder pbb = new PostBodyBuilder ( context ) ; pbb . addObject ( "table" , this . name ) ; pbb . addObject ( "provisionType" , StorageProvisionType . CUSTOM . getValue ( ) ) ; pbb . addObject ( "key" , key . map ( ) ) ; pbb . addObject ( "throughput" , throughput . map ( ) ) ; Rest r = new Rest ( context , RestType . CREATETABLE , pbb , null ) ; r . onError = onError ; r . onTableCreation = onTableCreation ; context . processRest ( r ) ; return this ; } | Creates a table with a custom throughput . The provision type is Custom and the provision load is ignored . |
12,171 | public TableRef create ( Key key , StorageProvisionType provisionType , StorageProvisionLoad provisionLoad , OnTableCreation onTableCreation , OnError onError ) { PostBodyBuilder pbb = new PostBodyBuilder ( context ) ; pbb . addObject ( "table" , this . name ) ; pbb . addObject ( "provisionLoad" , provisionLoad . getValue ( ) ) ; pbb . addObject ( "provisionType" , provisionType . getValue ( ) ) ; pbb . addObject ( "key" , key . map ( ) ) ; Rest r = new Rest ( context , RestType . CREATETABLE , pbb , null ) ; r . onError = onError ; r . onTableCreation = onTableCreation ; context . processRest ( r ) ; return this ; } | Creates a table with a |
12,172 | public void del ( OnBooleanResponse onBooleanResponse , OnError onError ) { PostBodyBuilder pbb = new PostBodyBuilder ( context ) ; pbb . addObject ( "table" , this . name ) ; Rest r = new Rest ( context , RestType . DELETETABLE , pbb , null ) ; r . onError = onError ; r . onBooleanResponse = onBooleanResponse ; context . processRest ( r ) ; } | Delete this table . |
12,173 | public TableRef meta ( OnTableMetadata onTableMetadata , OnError onError ) { PostBodyBuilder pbb = new PostBodyBuilder ( context ) ; pbb . addObject ( "table" , this . name ) ; Rest r = new Rest ( context , RestType . DESCRIBETABLE , pbb , null ) ; r . onError = onError ; r . onTableMetadata = onTableMetadata ; context . processRest ( r ) ; return this ; } | Gets the metadata of the table reference . |
12,174 | public TableRef push ( LinkedHashMap < String , ItemAttribute > item , OnItemSnapshot onItemSnapshot , OnError onError ) { PostBodyBuilder pbb = new PostBodyBuilder ( context ) ; pbb . addObject ( "table" , this . name ) ; pbb . addObject ( "item" , item ) ; Rest r = new Rest ( context , RestType . PUTITEM , pbb , this ) ; r . onError = onError ; r . onItemSnapshot = onItemSnapshot ; context . processRest ( r ) ; return this ; } | Adds a new item to the table . |
12,175 | public TableRef update ( final StorageProvisionLoad provisionLoad , final StorageProvisionType provisionType , final OnTableUpdate onTableUpdate , final OnError onError ) { TableMetadata tm = context . getTableMeta ( this . name ) ; if ( tm == null ) { this . meta ( new OnTableMetadata ( ) { public void run ( TableMetadata tableMetadata ) { _update ( provisionLoad , provisionType , onTableUpdate , onError ) ; } } , onError ) ; } else { this . _update ( provisionLoad , provisionType , onTableUpdate , onError ) ; } return this ; } | Updates the provision type and provision load of the referenced table . |
12,176 | public TableRef notEqual ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . NOTEQUAL , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items that does not match the filter property value . |
12,177 | public TableRef greaterEqual ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . GREATEREQUAL , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items greater or equal to filter property value . |
12,178 | public TableRef greaterThan ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . GREATERTHAN , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items greater than the filter property value . |
12,179 | public TableRef lessEqual ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . LESSEREQUAL , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items lesser or equals to the filter property value . |
12,180 | public TableRef lessThan ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . LESSERTHAN , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items lesser than the filter property value . |
12,181 | public TableRef notNull ( String attributeName ) { filters . add ( new Filter ( StorageFilter . NOTNULL , attributeName , null , null ) ) ; return this ; } | Applies a filter to the table reference . When fetched it will return the non null values . |
12,182 | public TableRef isNull ( String attributeName ) { filters . add ( new Filter ( StorageFilter . NULL , attributeName , null , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the null values . |
12,183 | public TableRef contains ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . CONTAINS , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items that contains the filter property value . |
12,184 | public TableRef notContains ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . NOTCONTAINS , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items that does not contains the filter property value . |
12,185 | public TableRef beginsWith ( String attributeName , ItemAttribute value ) { filters . add ( new Filter ( StorageFilter . BEGINSWITH , attributeName , value , null ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items that begins with the filter property value . |
12,186 | public TableRef between ( String attributeName , ItemAttribute startValue , ItemAttribute endValue ) { filters . add ( new Filter ( StorageFilter . BETWEEN , attributeName , startValue , endValue ) ) ; return this ; } | Applies a filter to the table . When fetched it will return the items in range of the filter property value . |
12,187 | private RestType _tryConstructKey ( TableMetadata tm ) { for ( Filter f : filters ) if ( f . operator == StorageFilter . NOTEQUAL || f . operator == StorageFilter . NOTNULL || f . operator == StorageFilter . NULL || f . operator == StorageFilter . CONTAINS || f . operator == StorageFilter . NOTCONTAINS ) return RestType . LISTITEMS ; if ( tm . getSecondaryKeyName ( ) != null ) { if ( filters . size ( ) == 1 ) { Iterator < Filter > itr = filters . iterator ( ) ; Filter f = itr . next ( ) ; if ( f . itemName . equals ( tm . getPrimaryKeyName ( ) ) && f . operator == StorageFilter . EQUALS ) { this . key = new LinkedHashMap < String , Object > ( ) ; this . key . put ( "primary" , f . value ) ; filters . clear ( ) ; return RestType . QUERYITEMS ; } } else if ( filters . size ( ) == 2 ) { Object tValue = null ; Filter tFilter = null ; for ( Filter f : filters ) { if ( f . itemName . equals ( tm . getPrimaryKeyName ( ) ) && f . operator == StorageFilter . EQUALS ) { tValue = f . value ; } if ( f . itemName . equals ( tm . getSecondaryKeyName ( ) ) ) { tFilter = f ; } } if ( tValue != null && tFilter != null ) { filters . clear ( ) ; filters . add ( tFilter ) ; this . key = new LinkedHashMap < String , Object > ( ) ; this . key . put ( "primary" , tValue ) ; return RestType . QUERYITEMS ; } else { return RestType . LISTITEMS ; } } } else { if ( filters . size ( ) == 1 ) { Iterator < Filter > itr = filters . iterator ( ) ; Filter f = itr . next ( ) ; if ( f . itemName . equals ( tm . getPrimaryKeyName ( ) ) && f . operator == StorageFilter . EQUALS ) { return RestType . GETITEM ; } } } return RestType . LISTITEMS ; } | if returns null the rest type is listItems otherwise queryItems |
12,188 | public TableRef getItems ( final OnItemSnapshot onItemSnapshot , final OnError onError ) { TableMetadata tm = context . getTableMeta ( this . name ) ; if ( tm == null ) { this . meta ( new OnTableMetadata ( ) { public void run ( TableMetadata tableMetadata ) { _getItems ( onItemSnapshot , onError ) ; } } , onError ) ; } else { this . _getItems ( onItemSnapshot , onError ) ; } return this ; } | Get the items of this tableRef . |
12,189 | public ItemRef item ( ItemAttribute primaryKeyValue , ItemAttribute secondaryKeyValue ) { return new ItemRef ( context , this , primaryKeyValue , secondaryKeyValue ) ; } | Creates a new item reference . |
12,190 | public TableRef on ( StorageEvent eventType , final OnItemSnapshot onItemSnapshot ) { return on ( eventType , onItemSnapshot , null ) ; } | Attach a listener to run every time the eventType occurs . |
12,191 | public TableRef once ( StorageEvent eventType , final OnItemSnapshot onItemSnapshot , final OnError onError ) { if ( eventType == StorageEvent . PUT ) { getItems ( onItemSnapshot , onError ) ; } Event ev = new Event ( eventType , this . name , null , null , true , true , pushNotificationsEnabled , onItemSnapshot ) ; context . addEvent ( ev ) ; return this ; } | Attach a listener to run only once the event type occurs . |
12,192 | public TableRef off ( StorageEvent eventType , OnItemSnapshot onItemSnapshot ) { Event ev = new Event ( eventType , this . name , null , null , false , true , false , onItemSnapshot ) ; context . removeEvent ( ev ) ; return this ; } | Remove an event handler . |
12,193 | public static UUID fromBytes ( byte [ ] bytes ) { long mostBits = ByteUtils . readLong ( bytes , 0 ) ; long leastBits = 0 ; if ( bytes . length > 8 ) { leastBits = ByteUtils . readLong ( bytes , 8 ) ; } return new UUID ( mostBits , leastBits ) ; } | Convert byte array into UUID . Byte array is a compact form of bits in UUID |
12,194 | public static byte [ ] toBytes ( UUID id ) { byte [ ] bytes = new byte [ 16 ] ; ByteUtils . writeLong ( id . getMostSignificantBits ( ) , bytes , 0 ) ; ByteUtils . writeLong ( id . getLeastSignificantBits ( ) , bytes , 8 ) ; return bytes ; } | Convert UUID in compact form of byte array |
12,195 | public static < T > Format < T > newFixLengthFormat ( Class < T > beanType ) { return new FixLengthFormat < T > ( beanType ) ; } | Create new text format for fix - length syntax |
12,196 | public static < T > Format < T > newCSVFormat ( Class < T > beanType ) { return new CSVFormat < T > ( beanType ) ; } | Create new text format for CSV syntax |
12,197 | public static boolean implementsInterface ( Class < ? > c , Class < ? > i ) { if ( c == i ) return true ; for ( Class < ? > x : c . getInterfaces ( ) ) if ( implementsInterface ( x , i ) ) return true ; return false ; } | Check whether c implements interface i |
12,198 | public StringTextValue < T > setValue ( final T value , final boolean initialValue ) { this . initialValue = initialValue ; this . value = value ; return this ; } | Sets the given value and set the initalValue flag if the flag should keep his state . |
12,199 | private boolean equalsNull ( String value1 , String value2 ) { return ( value1 == value2 || value1 == null || ( value1 != null && value1 . equalsIgnoreCase ( value2 ) ) ) ; } | Compares two values . Treats null as equal and is case insensitive |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.