idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
11,700 | private static byte [ ] generateKey ( int size ) throws SymmetricKeyException { if ( size <= 0 ) throw new IllegalArgumentException ( "Size cannot be zero or less than zero." ) ; try { SecureRandom secureRandom = new SecureRandom ( ) ; KeyGenerator keyGenerator = KeyGenerator . getInstance ( "AES" ) ; keyGenerator . init ( size * 8 , secureRandom ) ; return keyGenerator . generateKey ( ) . getEncoded ( ) ; } catch ( NoSuchAlgorithmException e ) { throw new SymmetricKeyException ( e ) ; } } | Generate an AES key of the specifies size in bytes . | 130 | 12 |
11,701 | private static byte [ ] secureRandom ( int size ) { if ( size <= 0 ) throw new IllegalArgumentException ( "Size cannot be zero or less than zero." ) ; SecureRandom secureRandom = new SecureRandom ( ) ; byte [ ] bytes = new byte [ size ] ; secureRandom . nextBytes ( bytes ) ; return bytes ; } | Secure random bytes of size in bytes | 72 | 7 |
11,702 | private Cipher getCipher ( int mode , byte [ ] iv ) throws SymmetricKeyException { Cipher cipher = null ; try { cipher = getCipherInstance ( "AES/CBC/PKCS7Padding" ) ; if ( cipher == null ) { throw new SymmetricKeyException ( "Cannot get a cipher instance for AES/CBC/PKCS7Padding algorithm" ) ; } SecretKey secret = new SecretKeySpec ( getKey ( ) , "AES" ) ; cipher . init ( mode , secret , new IvParameterSpec ( iv ) ) ; } catch ( InvalidKeyException e ) { throw new SymmetricKeyException ( "Couchbase Lite uses the AES 256-bit key to provide data encryption. " + "Please make sure you have installed 'Java Cryptography Extension (JCE) " + "Unlimited Strength Jurisdiction' Policy provided by Oracle." , e ) ; } catch ( SymmetricKeyException e ) { throw e ; } catch ( Exception e ) { throw new SymmetricKeyException ( e ) ; } return cipher ; } | Get a cipher instance for either encrypt or decrypt mode with an IV header . | 231 | 15 |
11,703 | private Cipher getCipherInstance ( String algorithm ) { Cipher cipher = null ; if ( ! useBCProvider ) { try { cipher = Cipher . getInstance ( algorithm ) ; } catch ( NoSuchAlgorithmException e ) { Log . v ( Log . TAG_SYMMETRIC_KEY , "Cannot find a cipher (no algorithm); will try with Bouncy Castle provider." ) ; } catch ( NoSuchPaddingException e ) { Log . v ( Log . TAG_SYMMETRIC_KEY , "Cannot find a cipher (no padding); will try with Bouncy Castle provider." ) ; } } if ( cipher == null ) { // Register and use BouncyCastle provider if applicable: try { if ( Security . getProvider ( "BC" ) == null ) { try { Class bc = Class . forName ( "org.bouncycastle.jce.provider.BouncyCastleProvider" ) ; Security . addProvider ( ( Provider ) bc . newInstance ( ) ) ; } catch ( Exception e ) { Log . e ( Log . TAG_SYMMETRIC_KEY , "Cannot instantiate Bouncy Castle provider" , e ) ; return null ; } } cipher = Cipher . getInstance ( algorithm , "BC" ) ; useBCProvider = true ; } catch ( Exception e ) { Log . e ( Log . TAG_SYMMETRIC_KEY , "Cannot find a cipher with Bouncy Castle provider" , e ) ; } } return cipher ; } | Get a cipher instance for the algorithm . It will try to use the Cipher from the default security provider by the platform . If it couldn t find the cipher it will try to the cipher from the Bouncy Castle if the BouncyCastle library is available . | 325 | 54 |
11,704 | public synchronized long addValue ( String value ) { sequences . add ( ++ lastSequence ) ; values . add ( value ) ; return lastSequence ; } | Adds a value to the map assigning it a sequence number and returning it . Sequence numbers start at 1 and increment from there . | 33 | 25 |
11,705 | public synchronized long getCheckpointedSequence ( ) { long sequence = lastSequence ; if ( ! sequences . isEmpty ( ) ) { sequence = sequences . first ( ) - 1 ; } if ( sequence > firstValueSequence ) { // Garbage-collect inaccessible values: int numToRemove = ( int ) ( sequence - firstValueSequence ) ; for ( int i = 0 ; i < numToRemove ; i ++ ) { values . remove ( 0 ) ; } firstValueSequence += numToRemove ; } return sequence ; } | Returns the maximum consecutively - removed sequence number . This is one less than the minimum remaining sequence number . | 115 | 21 |
11,706 | public synchronized String getCheckpointedValue ( ) { int index = ( int ) ( getCheckpointedSequence ( ) - firstValueSequence ) ; return ( index >= 0 ) ? values . get ( index ) : null ; } | Returns the value associated with the checkpointedSequence . | 50 | 11 |
11,707 | public static void serialize ( Serializable obj , ByteArrayOutputStream bout ) { try { ObjectOutputStream out = new ObjectOutputStream ( bout ) ; out . writeObject ( obj ) ; out . close ( ) ; } catch ( IOException e ) { throw new IllegalStateException ( "Could not serialize " + obj , e ) ; } } | Serialize the given object into the given stream | 74 | 9 |
11,708 | public static List < String > readToList ( File f ) throws IOException { try ( final Reader reader = asReaderUTF8Lenient ( new FileInputStream ( f ) ) ) { return readToList ( reader ) ; } catch ( IOException ioe ) { throw new IllegalStateException ( String . format ( "Failed to read %s: %s" , f . getAbsolutePath ( ) , ioe ) , ioe ) ; } } | Read the file line for line and return the result in a list | 98 | 13 |
11,709 | public static List < String > readToList ( Reader r ) throws IOException { try ( BufferedReader in = new BufferedReader ( r ) ) { List < String > l = new ArrayList <> ( ) ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) l . add ( line ) ; return Collections . unmodifiableList ( l ) ; } } | Read the Reader line for line and return the result in a list | 87 | 13 |
11,710 | public static String readFileToString ( File f ) throws IOException { StringWriter sw = new StringWriter ( ) ; IO . copyAndCloseBoth ( Common . asReaderUTF8Lenient ( new FileInputStream ( f ) ) , sw ) ; return sw . toString ( ) ; } | Read the contents of the given file into a string | 62 | 10 |
11,711 | public void appendToLog ( String logAppendMessage ) { ProfilingTimerNode currentNode = current . get ( ) ; if ( currentNode != null ) { currentNode . appendToLog ( logAppendMessage ) ; } } | Append the given string to the log message of the current subtask | 49 | 14 |
11,712 | public void mergeTree ( ProfilingTimerNode otherRoot ) { ProfilingTimerNode currentNode = current . get ( ) ; Preconditions . checkNotNull ( currentNode ) ; mergeOrAddNode ( currentNode , otherRoot ) ; } | Merges the specified tree as a child under the current node . | 51 | 13 |
11,713 | private static void writeToLog ( int level , long totalNanos , long count , ProfilingTimerNode parent , String taskName , Log log , String logAppendMessage ) { if ( log == null ) { return ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < level ; i ++ ) { sb . append ( ' ' ) ; } String durationText = String . format ( "%s%s" , formatElapsed ( totalNanos ) , count == 1 ? "" : String . format ( " across %d invocations, average: %s" , count , formatElapsed ( totalNanos / count ) ) ) ; String text = parent == null ? String . format ( "total time %s" , durationText ) : String . format ( "[%s] took %s" , taskName , durationText ) ; sb . append ( text ) ; sb . append ( logAppendMessage ) ; log . info ( sb . toString ( ) ) ; } | Writes one profiling line of information to the log | 220 | 10 |
11,714 | public static < T extends TBase > String serializeJson ( T obj ) throws TException { // Tried having a static final serializer, but it doesn't seem to be thread safe return new TSerializer ( new TJSONProtocol . Factory ( ) ) . toString ( obj , THRIFT_CHARSET ) ; } | Serialize a JSON - encoded thrift object | 71 | 9 |
11,715 | public static < T extends TBase > T deserializeJson ( T dest , String thriftJson ) throws TException { // Tried having a static final deserializer, but it doesn't seem to be thread safe new TDeserializer ( new TJSONProtocol . Factory ( ) ) . deserialize ( dest , thriftJson , THRIFT_CHARSET ) ; return dest ; } | Deserialize a JSON - encoded thrift object | 88 | 10 |
11,716 | public static String sepList ( String sep , Iterable < ? > os , int max ) { return sepList ( sep , null , os , max ) ; } | Same as sepList with no wrapping | 34 | 7 |
11,717 | Word2VecModel train ( Log log , TrainingProgressListener listener , Iterable < List < String > > sentences ) throws InterruptedException { try ( ProfilingTimer timer = ProfilingTimer . createLoggingSubtasks ( log , "Training word2vec" ) ) { final Multiset < String > counts ; try ( AC ac = timer . start ( "Acquiring word frequencies" ) ) { listener . update ( Stage . ACQUIRE_VOCAB , 0.0 ) ; counts = ( vocab . isPresent ( ) ) ? vocab . get ( ) : count ( Iterables . concat ( sentences ) ) ; } final ImmutableMultiset < String > vocab ; try ( AC ac = timer . start ( "Filtering and sorting vocabulary" ) ) { listener . update ( Stage . FILTER_SORT_VOCAB , 0.0 ) ; vocab = filterAndSort ( counts ) ; } final Map < String , HuffmanNode > huffmanNodes ; try ( AC task = timer . start ( "Create Huffman encoding" ) ) { huffmanNodes = new HuffmanCoding ( vocab , listener ) . encode ( ) ; } final NeuralNetworkModel model ; try ( AC task = timer . start ( "Training model %s" , neuralNetworkConfig ) ) { model = neuralNetworkConfig . createTrainer ( vocab , huffmanNodes , listener ) . train ( sentences ) ; } return new Word2VecModel ( vocab . elementSet ( ) , model . layerSize ( ) , Doubles . concat ( model . vectors ( ) ) ) ; } } | Train a model using the given data | 351 | 7 |
11,718 | private void normalize ( ) { for ( int i = 0 ; i < vocab . size ( ) ; ++ i ) { double len = 0 ; for ( int j = i * layerSize ; j < ( i + 1 ) * layerSize ; ++ j ) len += vectors . get ( j ) * vectors . get ( j ) ; len = Math . sqrt ( len ) ; for ( int j = i * layerSize ; j < ( i + 1 ) * layerSize ; ++ j ) vectors . put ( j , vectors . get ( j ) / len ) ; } } | Normalizes the vectors in this model | 124 | 7 |
11,719 | protected void init ( ) throws IOException { if ( internalIn2 != null ) return ; String encoding ; byte bom [ ] = new byte [ BOM_SIZE ] ; int n , unread ; n = internalIn . read ( bom , 0 , bom . length ) ; if ( ( bom [ 0 ] == ( byte ) 0x00 ) && ( bom [ 1 ] == ( byte ) 0x00 ) && ( bom [ 2 ] == ( byte ) 0xFE ) && ( bom [ 3 ] == ( byte ) 0xFF ) ) { encoding = "UTF-32BE" ; unread = n - 4 ; } else if ( ( bom [ 0 ] == ( byte ) 0xFF ) && ( bom [ 1 ] == ( byte ) 0xFE ) && ( bom [ 2 ] == ( byte ) 0x00 ) && ( bom [ 3 ] == ( byte ) 0x00 ) ) { encoding = "UTF-32LE" ; unread = n - 4 ; } else if ( ( bom [ 0 ] == ( byte ) 0xEF ) && ( bom [ 1 ] == ( byte ) 0xBB ) && ( bom [ 2 ] == ( byte ) 0xBF ) ) { encoding = "UTF-8" ; unread = n - 3 ; } else if ( ( bom [ 0 ] == ( byte ) 0xFE ) && ( bom [ 1 ] == ( byte ) 0xFF ) ) { encoding = "UTF-16BE" ; unread = n - 2 ; } else if ( ( bom [ 0 ] == ( byte ) 0xFF ) && ( bom [ 1 ] == ( byte ) 0xFE ) ) { encoding = "UTF-16LE" ; unread = n - 2 ; } else { // Unicode BOM not found, unread all bytes encoding = defaultEnc ; unread = n ; } if ( unread > 0 ) internalIn . unread ( bom , ( n - unread ) , unread ) ; // Use given encoding if ( encoding == null ) { internalIn2 = new InputStreamReader ( internalIn ) ; } else if ( strict ) { internalIn2 = new InputStreamReader ( internalIn , Charset . forName ( encoding ) . newDecoder ( ) ) ; } else { internalIn2 = new InputStreamReader ( internalIn , encoding ) ; } } | Read - ahead four bytes and check for BOM . Extra bytes are unread back to the stream only BOM bytes are skipped . | 501 | 27 |
11,720 | public static File getDir ( File parent , String item ) { File dir = new File ( parent , item ) ; return ( dir . exists ( ) && dir . isDirectory ( ) ) ? dir : null ; } | Returns a subdirectory of a given directory ; the subdirectory is expected to already exist . | 45 | 18 |
11,721 | public static boolean deleteRecursive ( final File file ) { boolean result = true ; if ( file . isDirectory ( ) ) { for ( final File inner : file . listFiles ( ) ) { result &= deleteRecursive ( inner ) ; } } return result & file . delete ( ) ; } | Deletes a file or directory . If the file is a directory it recursively deletes it . | 63 | 21 |
11,722 | public static File createTempFile ( byte [ ] fileContents , String namePrefix , String extension ) throws IOException { Preconditions . checkNotNull ( fileContents , "file contents missing" ) ; File tempFile = File . createTempFile ( namePrefix , extension ) ; try ( FileOutputStream fos = new FileOutputStream ( tempFile ) ) { fos . write ( fileContents ) ; } return tempFile ; } | Stores the given contents into a temporary file | 93 | 9 |
11,723 | public static void demoWord ( ) throws IOException , TException , InterruptedException , UnknownWordException { File f = new File ( "text8" ) ; if ( ! f . exists ( ) ) throw new IllegalStateException ( "Please download and unzip the text8 example from http://mattmahoney.net/dc/text8.zip" ) ; List < String > read = Common . readToList ( f ) ; List < List < String > > partitioned = Lists . transform ( read , new Function < String , List < String > > ( ) { @ Override public List < String > apply ( String input ) { return Arrays . asList ( input . split ( " " ) ) ; } } ) ; Word2VecModel model = Word2VecModel . trainer ( ) . setMinVocabFrequency ( 5 ) . useNumThreads ( 20 ) . setWindowSize ( 8 ) . type ( NeuralNetworkType . CBOW ) . setLayerSize ( 200 ) . useNegativeSamples ( 25 ) . setDownSamplingRate ( 1e-4 ) . setNumIterations ( 5 ) . setListener ( new TrainingProgressListener ( ) { @ Override public void update ( Stage stage , double progress ) { System . out . println ( String . format ( "%s is %.2f%% complete" , Format . formatEnum ( stage ) , progress * 100 ) ) ; } } ) . train ( partitioned ) ; // Writes model to a thrift file try ( ProfilingTimer timer = ProfilingTimer . create ( LOG , "Writing output to file" ) ) { FileUtils . writeStringToFile ( new File ( "text8.model" ) , ThriftUtils . serializeJson ( model . toThrift ( ) ) ) ; } // Alternatively, you can write the model to a bin file that's compatible with the C // implementation. try ( final OutputStream os = Files . newOutputStream ( Paths . get ( "text8.bin" ) ) ) { model . toBinFile ( os ) ; } interact ( model . forSearch ( ) ) ; } | Trains a model and allows user to find similar words demo - word . sh example from the open source C implementation | 461 | 23 |
11,724 | public static void loadModel ( ) throws IOException , TException , UnknownWordException { final Word2VecModel model ; try ( ProfilingTimer timer = ProfilingTimer . create ( LOG , "Loading model" ) ) { String json = Common . readFileToString ( new File ( "text8.model" ) ) ; model = Word2VecModel . fromThrift ( ThriftUtils . deserializeJson ( new Word2VecModelThrift ( ) , json ) ) ; } interact ( model . forSearch ( ) ) ; } | Loads a model and allows user to find similar words | 120 | 11 |
11,725 | public static void skipGram ( ) throws IOException , TException , InterruptedException , UnknownWordException { List < String > read = Common . readToList ( new File ( "sents.cleaned.word2vec.txt" ) ) ; List < List < String > > partitioned = Lists . transform ( read , new Function < String , List < String > > ( ) { @ Override public List < String > apply ( String input ) { return Arrays . asList ( input . split ( " " ) ) ; } } ) ; Word2VecModel model = Word2VecModel . trainer ( ) . setMinVocabFrequency ( 100 ) . useNumThreads ( 20 ) . setWindowSize ( 7 ) . type ( NeuralNetworkType . SKIP_GRAM ) . useHierarchicalSoftmax ( ) . setLayerSize ( 300 ) . useNegativeSamples ( 0 ) . setDownSamplingRate ( 1e-3 ) . setNumIterations ( 5 ) . setListener ( new TrainingProgressListener ( ) { @ Override public void update ( Stage stage , double progress ) { System . out . println ( String . format ( "%s is %.2f%% complete" , Format . formatEnum ( stage ) , progress * 100 ) ) ; } } ) . train ( partitioned ) ; try ( ProfilingTimer timer = ProfilingTimer . create ( LOG , "Writing output to file" ) ) { FileUtils . writeStringToFile ( new File ( "300layer.20threads.5iter.model" ) , ThriftUtils . serializeJson ( model . toThrift ( ) ) ) ; } interact ( model . forSearch ( ) ) ; } | Example using Skip - Gram model | 372 | 6 |
11,726 | private Catalogo copy ( Catalogo catalogo ) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory . newInstance ( ) ; dbf . setNamespaceAware ( true ) ; DocumentBuilder db = dbf . newDocumentBuilder ( ) ; Document doc = db . newDocument ( ) ; Marshaller m = context . createMarshaller ( ) ; m . marshal ( catalogo , doc ) ; Unmarshaller u = context . createUnmarshaller ( ) ; return ( Catalogo ) u . unmarshal ( doc ) ; } | Defensive deep - copy | 120 | 5 |
11,727 | private String [ ] findFeatureByScenarioName ( String scenarioName ) throws IllegalAccessException { List < Description > testClasses = findTestClassesLevel ( parentDescription . getChildren ( ) ) ; for ( Description testClass : testClasses ) { List < Description > features = findFeaturesLevel ( testClass . getChildren ( ) ) ; //Feature cycle for ( Description feature : features ) { //Story cycle for ( Description story : feature . getChildren ( ) ) { Object scenarioType = getTestEntityType ( story ) ; //Scenario if ( scenarioType instanceof Scenario && story . getDisplayName ( ) . equals ( scenarioName ) ) { return new String [ ] { feature . getDisplayName ( ) , scenarioName } ; //Scenario Outline } else if ( scenarioType instanceof ScenarioOutline ) { List < Description > examples = story . getChildren ( ) . get ( 0 ) . getChildren ( ) ; // we need to go deeper :) for ( Description example : examples ) { if ( example . getDisplayName ( ) . equals ( scenarioName ) ) { return new String [ ] { feature . getDisplayName ( ) , story . getDisplayName ( ) } ; } } } } } } return new String [ ] { "Feature: Undefined Feature" , scenarioName } ; } | Find feature and story for given scenario | 279 | 7 |
11,728 | Stories getStoriesAnnotation ( final String [ ] value ) { return new Stories ( ) { @ Override public String [ ] value ( ) { return value ; } @ Override public Class < Stories > annotationType ( ) { return Stories . class ; } } ; } | Creates Story annotation object | 58 | 5 |
11,729 | Features getFeaturesAnnotation ( final String [ ] value ) { return new Features ( ) { @ Override public String [ ] value ( ) { return value ; } @ Override public Class < Features > annotationType ( ) { return Features . class ; } } ; } | Creates Feature annotation object | 56 | 5 |
11,730 | public < E extends Enum < E > > List < E > getTypeList ( Class < E > clz , E [ ] typeList ) { if ( typeList . length > 0 ) { return new ArrayList <> ( Arrays . asList ( typeList ) ) ; } else { return new ArrayList <> ( EnumSet . allOf ( clz ) ) ; } } | Get a list of the enums passed | 84 | 8 |
11,731 | public ExternalID getPersonExternalIds ( int personId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , personId ) ; URL url = new ApiUrl ( apiKey , MethodBase . PERSON ) . subMethod ( MethodSub . EXTERNAL_IDS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , ExternalID . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get person external IDs" , url , ex ) ; } } | Get the external ids for a specific person id . | 153 | 11 |
11,732 | public ResultList < Artwork > getPersonImages ( int personId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , personId ) ; URL url = new ApiUrl ( apiKey , MethodBase . PERSON ) . subMethod ( MethodSub . IMAGES ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { WrapperImages wrapper = MAPPER . readValue ( webpage , WrapperImages . class ) ; ResultList < Artwork > results = new ResultList <> ( wrapper . getAll ( ArtworkType . PROFILE ) ) ; wrapper . setResultProperties ( results ) ; return results ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get person images" , url , ex ) ; } } | Get the images for a specific person id . | 196 | 9 |
11,733 | public ResultList < PersonFind > getPersonPopular ( Integer page ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . PAGE , page ) ; URL url = new ApiUrl ( apiKey , MethodBase . PERSON ) . subMethod ( MethodSub . POPULAR ) . buildUrl ( parameters ) ; WrapperGenericList < PersonFind > wrapper = processWrapper ( getTypeReference ( PersonFind . class ) , url , "person popular" ) ; return wrapper . getResultsList ( ) ; } | Get the list of popular people on The Movie Database . | 120 | 11 |
11,734 | public List < Artwork > getAll ( ArtworkType ... artworkList ) { List < Artwork > artwork = new ArrayList <> ( ) ; List < ArtworkType > types ; if ( artworkList . length > 0 ) { types = new ArrayList <> ( Arrays . asList ( artworkList ) ) ; } else { types = new ArrayList <> ( Arrays . asList ( ArtworkType . values ( ) ) ) ; } // Add all the posters to the list if ( types . contains ( ArtworkType . POSTER ) ) { updateArtworkType ( posters , ArtworkType . POSTER ) ; artwork . addAll ( posters ) ; } // Add all the backdrops to the list if ( types . contains ( ArtworkType . BACKDROP ) ) { updateArtworkType ( backdrops , ArtworkType . BACKDROP ) ; artwork . addAll ( backdrops ) ; } // Add all the profiles to the list if ( types . contains ( ArtworkType . PROFILE ) ) { updateArtworkType ( profiles , ArtworkType . PROFILE ) ; artwork . addAll ( profiles ) ; } // Add all the stills to the list if ( types . contains ( ArtworkType . STILL ) ) { updateArtworkType ( stills , ArtworkType . STILL ) ; artwork . addAll ( stills ) ; } return artwork ; } | Return a list of all the artwork with their types . | 297 | 11 |
11,735 | private void updateArtworkType ( List < Artwork > artworkList , ArtworkType type ) { for ( Artwork artwork : artworkList ) { artwork . setArtworkType ( type ) ; } } | Update the artwork type for the artwork list | 43 | 8 |
11,736 | public TokenAuthorisation getAuthorisationToken ( ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; URL url = new ApiUrl ( apiKey , MethodBase . AUTH ) . subMethod ( MethodSub . TOKEN_NEW ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , TokenAuthorisation . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . AUTH_FAILURE , "Failed to get Authorisation Token" , url , ex ) ; } } | This method is used to generate a valid request token for user based authentication . | 136 | 15 |
11,737 | public TokenSession getSessionToken ( TokenAuthorisation token ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; if ( ! token . getSuccess ( ) ) { throw new MovieDbException ( ApiExceptionType . AUTH_FAILURE , "Authorisation token was not successful!" ) ; } parameters . add ( Param . TOKEN , token . getRequestToken ( ) ) ; URL url = new ApiUrl ( apiKey , MethodBase . AUTH ) . subMethod ( MethodSub . SESSION_NEW ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , TokenSession . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get Session Token" , url , ex ) ; } } | This method is used to generate a session id for user based authentication . | 195 | 14 |
11,738 | public TokenSession getGuestSessionToken ( ) throws MovieDbException { URL url = new ApiUrl ( apiKey , MethodBase . AUTH ) . subMethod ( MethodSub . GUEST_SESSION ) . buildUrl ( ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , TokenSession . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get Guest Session Token" , url , ex ) ; } } | This method is used to generate a guest session id . | 122 | 11 |
11,739 | private void initialise ( String apiKey , HttpTools httpTools ) { tmdbAccount = new TmdbAccount ( apiKey , httpTools ) ; tmdbAuth = new TmdbAuthentication ( apiKey , httpTools ) ; tmdbCertifications = new TmdbCertifications ( apiKey , httpTools ) ; tmdbChanges = new TmdbChanges ( apiKey , httpTools ) ; tmdbCollections = new TmdbCollections ( apiKey , httpTools ) ; tmdbCompany = new TmdbCompanies ( apiKey , httpTools ) ; tmdbConfiguration = new TmdbConfiguration ( apiKey , httpTools ) ; tmdbCredits = new TmdbCredits ( apiKey , httpTools ) ; tmdbDiscover = new TmdbDiscover ( apiKey , httpTools ) ; tmdbFind = new TmdbFind ( apiKey , httpTools ) ; tmdbGenre = new TmdbGenres ( apiKey , httpTools ) ; tmdbKeywords = new TmdbKeywords ( apiKey , httpTools ) ; tmdbList = new TmdbLists ( apiKey , httpTools ) ; tmdbMovies = new TmdbMovies ( apiKey , httpTools ) ; tmdbNetworks = new TmdbNetworks ( apiKey , httpTools ) ; tmdbPeople = new TmdbPeople ( apiKey , httpTools ) ; tmdbReviews = new TmdbReviews ( apiKey , httpTools ) ; tmdbSearch = new TmdbSearch ( apiKey , httpTools ) ; tmdbTv = new TmdbTV ( apiKey , httpTools ) ; tmdbSeasons = new TmdbSeasons ( apiKey , httpTools ) ; tmdbEpisodes = new TmdbEpisodes ( apiKey , httpTools ) ; } | Initialise the sub - classes once the API key and http client are known | 416 | 15 |
11,740 | public ResultList < MovieBasic > getFavoriteMovies ( String sessionId , int accountId ) throws MovieDbException { return tmdbAccount . getFavoriteMovies ( sessionId , accountId ) ; } | Get the account favourite movies | 44 | 5 |
11,741 | public StatusCode modifyFavoriteStatus ( String sessionId , int accountId , Integer mediaId , MediaType mediaType , boolean isFavorite ) throws MovieDbException { return tmdbAccount . modifyFavoriteStatus ( sessionId , accountId , mediaType , mediaId , isFavorite ) ; } | Add or remove a movie to an accounts favourite list . | 60 | 11 |
11,742 | public ResultList < TVBasic > getWatchListTV ( String sessionId , int accountId , Integer page , String sortBy , String language ) throws MovieDbException { return tmdbAccount . getWatchListTV ( sessionId , accountId , page , sortBy , language ) ; } | Get the list of movies on an accounts watchlist . | 61 | 11 |
11,743 | public StatusCode addToWatchList ( String sessionId , int accountId , MediaType mediaType , Integer mediaId ) throws MovieDbException { return tmdbAccount . modifyWatchList ( sessionId , accountId , mediaType , mediaId , true ) ; } | Add a movie to an accounts watch list . | 56 | 9 |
11,744 | public StatusCode removeFromWatchList ( String sessionId , int accountId , MediaType mediaType , Integer mediaId ) throws MovieDbException { return tmdbAccount . modifyWatchList ( sessionId , accountId , mediaType , mediaId , false ) ; } | Remove a movie from an accounts watch list . | 56 | 9 |
11,745 | public ResultList < TVBasic > getFavoriteTv ( String sessionId , int accountId ) throws MovieDbException { return tmdbAccount . getFavoriteTv ( sessionId , accountId ) ; } | Get the list of favorite TV series for an account . | 44 | 11 |
11,746 | public ResultList < ChangeListItem > getMovieChangeList ( Integer page , String startDate , String endDate ) throws MovieDbException { return tmdbChanges . getChangeList ( MethodBase . MOVIE , page , startDate , endDate ) ; } | Get a list of Movie IDs that have been edited . | 55 | 11 |
11,747 | public ResultList < ChangeListItem > getTvChangeList ( Integer page , String startDate , String endDate ) throws MovieDbException { return tmdbChanges . getChangeList ( MethodBase . TV , page , startDate , endDate ) ; } | Get a list of TV IDs that have been edited . | 55 | 11 |
11,748 | public ResultList < ChangeListItem > getPersonChangeList ( Integer page , String startDate , String endDate ) throws MovieDbException { return tmdbChanges . getChangeList ( MethodBase . PERSON , page , startDate , endDate ) ; } | Get a list of PersonInfo IDs that have been edited . | 54 | 12 |
11,749 | public ResultList < MovieBasic > getGenreMovies ( int genreId , String language , Integer page , Boolean includeAllMovies , Boolean includeAdult ) throws MovieDbException { return tmdbGenre . getGenreMovies ( genreId , language , page , includeAllMovies , includeAdult ) ; } | Get a list of movies per genre . | 68 | 8 |
11,750 | public boolean checkItemStatus ( String listId , Integer mediaId ) throws MovieDbException { return tmdbList . checkItemStatus ( listId , mediaId ) ; } | Check to see if an item is already on a list . | 37 | 12 |
11,751 | public StatusCode removeItemFromList ( String sessionId , String listId , Integer mediaId ) throws MovieDbException { return tmdbList . removeItem ( sessionId , listId , mediaId ) ; } | This method lets users remove items from a list that they created . | 45 | 13 |
11,752 | public ResultList < Video > getMovieVideos ( int movieId , String language ) throws MovieDbException { return tmdbMovies . getMovieVideos ( movieId , language ) ; } | This method is used to retrieve all of the trailers for a particular movie . | 42 | 15 |
11,753 | public ResultList < Review > getMovieReviews ( int movieId , Integer page , String language ) throws MovieDbException { return tmdbMovies . getMovieReviews ( movieId , page , language ) ; } | Get the reviews for a particular movie id . | 47 | 9 |
11,754 | public ResultList < UserList > getMovieLists ( int movieId , Integer page , String language ) throws MovieDbException { return tmdbMovies . getMovieLists ( movieId , page , language ) ; } | Get the lists that the movie belongs to | 48 | 8 |
11,755 | public ResultList < MovieInfo > getTopRatedMovies ( Integer page , String language ) throws MovieDbException { return tmdbMovies . getTopRatedMovies ( page , language ) ; } | This method is used to retrieve the top rated movies that have over 10 votes on TMDb . | 43 | 20 |
11,756 | public PersonCreditList < CreditTVBasic > getPersonTVCredits ( int personId , String language ) throws MovieDbException { return tmdbPeople . getPersonTVCredits ( personId , language ) ; } | Get the TV credits for a specific person id . | 44 | 10 |
11,757 | public ResultList < ChangeKeyItem > getPersonChanges ( int personId , String startDate , String endDate ) throws MovieDbException { return tmdbPeople . getPersonChanges ( personId , startDate , endDate ) ; } | Get the changes for a specific person id . | 50 | 9 |
11,758 | public ResultList < Keyword > searchKeyword ( String query , Integer page ) throws MovieDbException { return tmdbSearch . searchKeyword ( query , page ) ; } | Search for keywords by name | 38 | 5 |
11,759 | public MediaState getTVAccountState ( int tvID , String sessionID ) throws MovieDbException { return tmdbTv . getTVAccountState ( tvID , sessionID ) ; } | This method lets users get the status of whether or not the TV show has been rated or added to their favourite or watch lists . | 41 | 26 |
11,760 | public ExternalID getTVExternalIDs ( int tvID , String language ) throws MovieDbException { return tmdbTv . getTVExternalIDs ( tvID , language ) ; } | Get the external ids that we have stored for a TV series . | 39 | 14 |
11,761 | public StatusCode postTVRating ( int tvID , int rating , String sessionID , String guestSessionID ) throws MovieDbException { return tmdbTv . postTVRating ( tvID , rating , sessionID , guestSessionID ) ; } | This method lets users rate a TV show . | 53 | 9 |
11,762 | public ResultList < TVInfo > getTVSimilar ( int tvID , Integer page , String language ) throws MovieDbException { return tmdbTv . getTVSimilar ( tvID , page , language ) ; } | Get the similar TV shows for a specific tv id . | 46 | 11 |
11,763 | public ResultList < TVInfo > getTVOnTheAir ( Integer page , String language ) throws MovieDbException { return tmdbTv . getTVOnTheAir ( page , language ) ; } | Get the list of TV shows that are currently on the air . | 43 | 13 |
11,764 | public ResultList < TVInfo > getTVAiringToday ( Integer page , String language , String timezone ) throws MovieDbException { return tmdbTv . getTVAiringToday ( page , language , timezone ) ; } | Get the list of TV shows that air today . | 50 | 10 |
11,765 | public ExternalID getSeasonExternalID ( int tvID , int seasonNumber , String language ) throws MovieDbException { return tmdbSeasons . getSeasonExternalID ( tvID , seasonNumber , language ) ; } | Get the external ids that we have stored for a TV season by season number . | 46 | 17 |
11,766 | public ResultList < Artwork > getSeasonImages ( int tvID , int seasonNumber , String language , String ... includeImageLanguage ) throws MovieDbException { return tmdbSeasons . getSeasonImages ( tvID , seasonNumber , language , includeImageLanguage ) ; } | Get the images that we have stored for a TV season by season number . | 58 | 15 |
11,767 | public MediaCreditList getEpisodeCredits ( int tvID , int seasonNumber , int episodeNumber ) throws MovieDbException { return tmdbEpisodes . getEpisodeCredits ( tvID , seasonNumber , episodeNumber ) ; } | Get the TV episode credits by combination of season and episode number . | 47 | 13 |
11,768 | public ExternalID getEpisodeExternalID ( int tvID , int seasonNumber , int episodeNumber , String language ) throws MovieDbException { return tmdbEpisodes . getEpisodeExternalID ( tvID , seasonNumber , episodeNumber , language ) ; } | Get the external ids for a TV episode by comabination of a season and episode number . | 53 | 20 |
11,769 | public ResultsMap < String , List < Certification > > getMoviesCertification ( ) throws MovieDbException { URL url = new ApiUrl ( apiKey , MethodBase . CERTIFICATION ) . subMethod ( MethodSub . MOVIE_LIST ) . buildUrl ( ) ; String webpage = httpTools . getRequest ( url ) ; try { JsonNode node = MAPPER . readTree ( webpage ) ; Map < String , List < Certification > > results = MAPPER . readValue ( node . elements ( ) . next ( ) . traverse ( ) , new TypeReference < Map < String , List < Certification > > > ( ) { } ) ; return new ResultsMap <> ( results ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get movie certifications" , url , ex ) ; } } | Get a list of movies certification . | 193 | 7 |
11,770 | private static boolean compareTitles ( String primaryTitle , String firstCompareTitle , String secondCompareTitle , int maxDistance ) { // Compare with the first title if ( compareDistance ( primaryTitle , firstCompareTitle , maxDistance ) ) { return true ; } // Compare with the other title return compareDistance ( primaryTitle , secondCompareTitle , maxDistance ) ; } | Compare a title with two other titles . | 75 | 8 |
11,771 | public static boolean movies ( final MovieInfo moviedb , final String title , final String year , int maxDistance ) { return Compare . movies ( moviedb , title , year , maxDistance , true ) ; } | Compare the MovieDB object with a title and year case sensitive | 45 | 12 |
11,772 | private static boolean compareDistance ( final String title1 , final String title2 , int distance ) { return StringUtils . getLevenshteinDistance ( title1 , title2 ) <= distance ; } | Compare the Levenshtein Distance between the two strings | 42 | 11 |
11,773 | public MediaCreditList getMovieCredits ( int movieId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , movieId ) ; URL url = new ApiUrl ( apiKey , MethodBase . MOVIE ) . subMethod ( MethodSub . CREDITS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , MediaCreditList . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get credits" , url , ex ) ; } } | Get the cast and crew information for a specific movie id . | 150 | 12 |
11,774 | public ResultList < Keyword > getMovieKeywords ( int movieId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , movieId ) ; URL url = new ApiUrl ( apiKey , MethodBase . MOVIE ) . subMethod ( MethodSub . KEYWORDS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { WrapperMovieKeywords wrapper = MAPPER . readValue ( webpage , WrapperMovieKeywords . class ) ; ResultList < Keyword > results = new ResultList <> ( wrapper . getKeywords ( ) ) ; wrapper . setResultProperties ( results ) ; return results ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get keywords" , url , ex ) ; } } | This method is used to retrieve all of the keywords that have been added to a particular movie . | 198 | 19 |
11,775 | public ResultList < MovieInfo > getRecommendations ( int movieId , String language ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , movieId ) ; parameters . add ( Param . LANGUAGE , language ) ; URL url = new ApiUrl ( apiKey , MethodBase . MOVIE ) . subMethod ( MethodSub . RECOMMENDATIONS ) . buildUrl ( parameters ) ; WrapperGenericList < MovieInfo > wrapper = processWrapper ( getTypeReference ( MovieInfo . class ) , url , "recommendations" ) ; return wrapper . getResultsList ( ) ; } | The recommendations method will let you retrieve the movie recommendations for a particular movie . | 143 | 15 |
11,776 | public ResultList < ReleaseDates > getReleaseDates ( int movieId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , movieId ) ; URL url = new ApiUrl ( apiKey , MethodBase . MOVIE ) . subMethod ( MethodSub . RELEASE_DATES ) . buildUrl ( parameters ) ; WrapperGenericList < ReleaseDates > wrapper = processWrapper ( getTypeReference ( ReleaseDates . class ) , url , "release dates" ) ; return wrapper . getResultsList ( ) ; } | Get the release dates certifications and related information by country for a specific movie id . | 128 | 17 |
11,777 | public ResultList < Translation > getMovieTranslations ( int movieId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , movieId ) ; URL url = new ApiUrl ( apiKey , MethodBase . MOVIE ) . subMethod ( MethodSub . TRANSLATIONS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { WrapperTranslations wrapper = MAPPER . readValue ( webpage , WrapperTranslations . class ) ; ResultList < Translation > results = new ResultList <> ( wrapper . getTranslations ( ) ) ; wrapper . setResultProperties ( results ) ; return results ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get translations" , url , ex ) ; } } | This method is used to retrieve a list of the available translations for a specific movie . | 194 | 17 |
11,778 | public ResultList < ChangeKeyItem > getMovieChanges ( int movieId , String startDate , String endDate ) throws MovieDbException { return getMediaChanges ( movieId , startDate , endDate ) ; } | Get the changes for a specific movie ID . | 45 | 9 |
11,779 | public MediaCreditList getSeasonCredits ( int tvID , int seasonNumber ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , tvID ) ; parameters . add ( Param . SEASON_NUMBER , seasonNumber ) ; URL url = new ApiUrl ( apiKey , MethodBase . SEASON ) . subMethod ( MethodSub . CREDITS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , MediaCreditList . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get credits" , url , ex ) ; } } | Get the cast & crew credits for a TV season by season number . | 170 | 14 |
11,780 | public URL buildUrl ( final TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( TMDB_API_BASE ) ; LOG . trace ( "Method: '{}', Sub-method: '{}', Params: {}" , method . getValue ( ) , submethod . getValue ( ) , ToStringBuilder . reflectionToString ( params , ToStringStyle . SHORT_PREFIX_STYLE ) ) ; // Get the start of the URL, substituting TV for the season or episode methods if ( method == MethodBase . SEASON || method == MethodBase . EPISODE ) { urlString . append ( MethodBase . TV . getValue ( ) ) ; } else { urlString . append ( method . getValue ( ) ) ; } // We have either a queury, or a ID request if ( params . has ( Param . QUERY ) ) { urlString . append ( queryProcessing ( params ) ) ; } else { urlString . append ( idProcessing ( params ) ) ; } urlString . append ( otherProcessing ( params ) ) ; try { LOG . trace ( "URL: {}" , urlString . toString ( ) ) ; return new URL ( urlString . toString ( ) ) ; } catch ( MalformedURLException ex ) { LOG . warn ( "Failed to create URL {} - {}" , urlString . toString ( ) , ex . getMessage ( ) ) ; return null ; } } | Build the URL from the pre - created parameters . | 318 | 10 |
11,781 | private StringBuilder queryProcessing ( TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( ) ; // Append the suffix of the API URL if ( submethod != MethodSub . NONE ) { urlString . append ( "/" ) . append ( submethod . getValue ( ) ) ; } // Append the key information urlString . append ( DELIMITER_FIRST ) . append ( Param . API_KEY . getValue ( ) ) . append ( apiKey ) . append ( DELIMITER_SUBSEQUENT ) // Append the search term . append ( Param . QUERY . getValue ( ) ) ; String query = ( String ) params . get ( Param . QUERY ) ; try { urlString . append ( URLEncoder . encode ( query , "UTF-8" ) ) ; } catch ( UnsupportedEncodingException ex ) { LOG . trace ( "Unable to encode query: '{}' trying raw." , query , ex ) ; // If we can't encode it, try it raw urlString . append ( query ) ; } return urlString ; } | Create the query based URL portion | 240 | 6 |
11,782 | private StringBuilder idProcessing ( final TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( ) ; // Append the ID if ( params . has ( Param . ID ) ) { urlString . append ( "/" ) . append ( params . get ( Param . ID ) ) ; } if ( params . has ( Param . SEASON_NUMBER ) ) { urlString . append ( "/season/" ) . append ( params . get ( Param . SEASON_NUMBER ) ) ; } if ( params . has ( Param . EPISODE_NUMBER ) ) { urlString . append ( "/episode/" ) . append ( params . get ( Param . EPISODE_NUMBER ) ) ; } if ( submethod != MethodSub . NONE ) { urlString . append ( "/" ) . append ( submethod . getValue ( ) ) ; } // Append the key information urlString . append ( DELIMITER_FIRST ) . append ( Param . API_KEY . getValue ( ) ) . append ( apiKey ) ; return urlString ; } | Create the ID based URL portion | 231 | 6 |
11,783 | private StringBuilder otherProcessing ( final TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( ) ; for ( Map . Entry < Param , String > argEntry : params . getEntries ( ) ) { // Skip the ID an QUERY params if ( IGNORE_PARAMS . contains ( argEntry . getKey ( ) ) ) { continue ; } urlString . append ( DELIMITER_SUBSEQUENT ) . append ( argEntry . getKey ( ) . getValue ( ) ) . append ( argEntry . getValue ( ) ) ; } return urlString ; } | Create a string of the remaining parameters | 129 | 7 |
11,784 | public Review getReview ( String reviewId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , reviewId ) ; URL url = new ApiUrl ( apiKey , MethodBase . REVIEW ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , Review . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get review" , url , ex ) ; } } | Get the full details of a review by ID . | 134 | 10 |
11,785 | private String convertToJson ( Map < String , ? > map ) throws MovieDbException { try { return MAPPER . writeValueAsString ( map ) ; } catch ( JsonProcessingException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "JSON conversion failed" , "" , ex ) ; } } | Use Jackson to convert Map to JSON string . | 77 | 9 |
11,786 | public ResultList < ChangeListItem > getChangeList ( MethodBase method , Integer page , String startDate , String endDate ) throws MovieDbException { TmdbParameters params = new TmdbParameters ( ) ; params . add ( Param . PAGE , page ) ; params . add ( Param . START_DATE , startDate ) ; params . add ( Param . END_DATE , endDate ) ; URL url = new ApiUrl ( apiKey , method ) . subMethod ( MethodSub . CHANGES ) . buildUrl ( params ) ; WrapperGenericList < ChangeListItem > wrapper = processWrapper ( getTypeReference ( ChangeListItem . class ) , url , "changes" ) ; return wrapper . getResultsList ( ) ; } | Get a list of Media IDs that have been edited . | 161 | 11 |
11,787 | public Discover year ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . YEAR , year ) ; } return this ; } | Filter the results release dates to matches that include this value . | 33 | 12 |
11,788 | public Discover primaryReleaseYear ( int primaryReleaseYear ) { if ( checkYear ( primaryReleaseYear ) ) { params . add ( Param . PRIMARY_RELEASE_YEAR , primaryReleaseYear ) ; } return this ; } | Filter the results so that only the primary release date year has this value | 49 | 14 |
11,789 | public Discover firstAirDateYear ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . FIRST_AIR_DATE_YEAR , year ) ; } return this ; } | Filter the air dates that match this year | 44 | 8 |
11,790 | public Discover firstAirDateYearGte ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . FIRST_AIR_DATE_GTE , year ) ; } return this ; } | Filter the air dates to years that are greater than or equal to this year | 46 | 15 |
11,791 | public Discover firstAirDateYearLte ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . FIRST_AIR_DATE_LTE , year ) ; } return this ; } | Filter the air dates to years that are less than or equal to this year | 46 | 15 |
11,792 | public boolean isValidPosterSize ( String posterSize ) { if ( StringUtils . isBlank ( posterSize ) || posterSizes . isEmpty ( ) ) { return false ; } return posterSizes . contains ( posterSize ) ; } | Check that the poster size is valid | 53 | 7 |
11,793 | public boolean isValidBackdropSize ( String backdropSize ) { if ( StringUtils . isBlank ( backdropSize ) || backdropSizes . isEmpty ( ) ) { return false ; } return backdropSizes . contains ( backdropSize ) ; } | Check that the backdrop size is valid | 53 | 7 |
11,794 | public boolean isValidProfileSize ( String profileSize ) { if ( StringUtils . isBlank ( profileSize ) || profileSizes . isEmpty ( ) ) { return false ; } return profileSizes . contains ( profileSize ) ; } | Check that the profile size is valid | 52 | 7 |
11,795 | public boolean isValidLogoSize ( String logoSize ) { if ( StringUtils . isBlank ( logoSize ) || logoSizes . isEmpty ( ) ) { return false ; } return logoSizes . contains ( logoSize ) ; } | Check that the logo size is valid | 53 | 7 |
11,796 | public boolean isValidSize ( String sizeToCheck ) { return isValidPosterSize ( sizeToCheck ) || isValidBackdropSize ( sizeToCheck ) || isValidProfileSize ( sizeToCheck ) || isValidLogoSize ( sizeToCheck ) ; } | Check to see if the size is valid for any of the images types | 57 | 14 |
11,797 | public ListItem < MovieInfo > getList ( String listId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , listId ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , new TypeReference < ListItem < MovieInfo > > ( ) { } ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get list" , url , ex ) ; } } | Get a list by its ID | 150 | 6 |
11,798 | public boolean checkItemStatus ( String listId , int mediaId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , listId ) ; parameters . add ( Param . MOVIE_ID , mediaId ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . subMethod ( MethodSub . ITEM_STATUS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , ListItemStatus . class ) . isItemPresent ( ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get item status" , url , ex ) ; } } | Check to see if an ID is already on a list . | 175 | 12 |
11,799 | private StatusCode modifyMovieList ( String sessionId , String listId , int movieId , MethodSub operation ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . SESSION_ID , sessionId ) ; parameters . add ( Param . ID , listId ) ; String jsonBody = new PostTools ( ) . add ( PostBody . MEDIA_ID , movieId ) . build ( ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . subMethod ( operation ) . buildUrl ( parameters ) ; String webpage = httpTools . postRequest ( url , jsonBody ) ; try { return MAPPER . readValue ( webpage , StatusCode . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to remove item from list" , url , ex ) ; } } | Modify a list | 202 | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.