_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q20200
IO.createTempFile
train
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; }
java
{ "resource": "" }
q20201
Word2VecExamples.demoWord
train
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()); }
java
{ "resource": "" }
q20202
Word2VecExamples.loadModel
train
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()); }
java
{ "resource": "" }
q20203
Word2VecExamples.skipGram
train
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()); }
java
{ "resource": "" }
q20204
CuentasContablesv11.copy
train
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); }
java
{ "resource": "" }
q20205
AllureRunListener.findFeatureByScenarioName
train
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}; }
java
{ "resource": "" }
q20206
AllureRunListener.getStoriesAnnotation
train
Stories getStoriesAnnotation(final String[] value) { return new Stories() { @Override public String[] value() { return value; } @Override public Class<Stories> annotationType() { return Stories.class; } }; }
java
{ "resource": "" }
q20207
AllureRunListener.getFeaturesAnnotation
train
Features getFeaturesAnnotation(final String[] value) { return new Features() { @Override public String[] value() { return value; } @Override public Class<Features> annotationType() { return Features.class; } }; }
java
{ "resource": "" }
q20208
AbstractWrapperBase.getTypeList
train
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)); } }
java
{ "resource": "" }
q20209
TmdbPeople.getPersonExternalIds
train
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); } }
java
{ "resource": "" }
q20210
TmdbPeople.getPersonImages
train
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); } }
java
{ "resource": "" }
q20211
TmdbPeople.getPersonPopular
train
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(); }
java
{ "resource": "" }
q20212
WrapperImages.getAll
train
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; }
java
{ "resource": "" }
q20213
WrapperImages.updateArtworkType
train
private void updateArtworkType(List<Artwork> artworkList, ArtworkType type) { for (Artwork artwork : artworkList) { artwork.setArtworkType(type); } }
java
{ "resource": "" }
q20214
TmdbAuthentication.getAuthorisationToken
train
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); } }
java
{ "resource": "" }
q20215
TmdbAuthentication.getSessionToken
train
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); } }
java
{ "resource": "" }
q20216
TmdbAuthentication.getGuestSessionToken
train
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); } }
java
{ "resource": "" }
q20217
TheMovieDbApi.initialise
train
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); }
java
{ "resource": "" }
q20218
TheMovieDbApi.getFavoriteMovies
train
public ResultList<MovieBasic> getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getFavoriteMovies(sessionId, accountId); }
java
{ "resource": "" }
q20219
TheMovieDbApi.modifyFavoriteStatus
train
public StatusCode modifyFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException { return tmdbAccount.modifyFavoriteStatus(sessionId, accountId, mediaType, mediaId, isFavorite); }
java
{ "resource": "" }
q20220
TheMovieDbApi.getWatchListTV
train
public ResultList<TVBasic> getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { return tmdbAccount.getWatchListTV(sessionId, accountId, page, sortBy, language); }
java
{ "resource": "" }
q20221
TheMovieDbApi.addToWatchList
train
public StatusCode addToWatchList(String sessionId, int accountId, MediaType mediaType, Integer mediaId) throws MovieDbException { return tmdbAccount.modifyWatchList(sessionId, accountId, mediaType, mediaId, true); }
java
{ "resource": "" }
q20222
TheMovieDbApi.removeFromWatchList
train
public StatusCode removeFromWatchList(String sessionId, int accountId, MediaType mediaType, Integer mediaId) throws MovieDbException { return tmdbAccount.modifyWatchList(sessionId, accountId, mediaType, mediaId, false); }
java
{ "resource": "" }
q20223
TheMovieDbApi.getFavoriteTv
train
public ResultList<TVBasic> getFavoriteTv(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getFavoriteTv(sessionId, accountId); }
java
{ "resource": "" }
q20224
TheMovieDbApi.getMovieChangeList
train
public ResultList<ChangeListItem> getMovieChangeList(Integer page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.MOVIE, page, startDate, endDate); }
java
{ "resource": "" }
q20225
TheMovieDbApi.getTvChangeList
train
public ResultList<ChangeListItem> getTvChangeList(Integer page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.TV, page, startDate, endDate); }
java
{ "resource": "" }
q20226
TheMovieDbApi.getPersonChangeList
train
public ResultList<ChangeListItem> getPersonChangeList(Integer page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.PERSON, page, startDate, endDate); }
java
{ "resource": "" }
q20227
TheMovieDbApi.getGenreMovies
train
public ResultList<MovieBasic> getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException { return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies, includeAdult); }
java
{ "resource": "" }
q20228
TheMovieDbApi.checkItemStatus
train
public boolean checkItemStatus(String listId, Integer mediaId) throws MovieDbException { return tmdbList.checkItemStatus(listId, mediaId); }
java
{ "resource": "" }
q20229
TheMovieDbApi.removeItemFromList
train
public StatusCode removeItemFromList(String sessionId, String listId, Integer mediaId) throws MovieDbException { return tmdbList.removeItem(sessionId, listId, mediaId); }
java
{ "resource": "" }
q20230
TheMovieDbApi.getMovieVideos
train
public ResultList<Video> getMovieVideos(int movieId, String language) throws MovieDbException { return tmdbMovies.getMovieVideos(movieId, language); }
java
{ "resource": "" }
q20231
TheMovieDbApi.getMovieReviews
train
public ResultList<Review> getMovieReviews(int movieId, Integer page, String language) throws MovieDbException { return tmdbMovies.getMovieReviews(movieId, page, language); }
java
{ "resource": "" }
q20232
TheMovieDbApi.getMovieLists
train
public ResultList<UserList> getMovieLists(int movieId, Integer page, String language) throws MovieDbException { return tmdbMovies.getMovieLists(movieId, page, language); }
java
{ "resource": "" }
q20233
TheMovieDbApi.getTopRatedMovies
train
public ResultList<MovieInfo> getTopRatedMovies(Integer page, String language) throws MovieDbException { return tmdbMovies.getTopRatedMovies(page, language); }
java
{ "resource": "" }
q20234
TheMovieDbApi.getPersonTVCredits
train
public PersonCreditList<CreditTVBasic> getPersonTVCredits(int personId, String language) throws MovieDbException { return tmdbPeople.getPersonTVCredits(personId, language); }
java
{ "resource": "" }
q20235
TheMovieDbApi.getPersonChanges
train
public ResultList<ChangeKeyItem> getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { return tmdbPeople.getPersonChanges(personId, startDate, endDate); }
java
{ "resource": "" }
q20236
TheMovieDbApi.searchKeyword
train
public ResultList<Keyword> searchKeyword(String query, Integer page) throws MovieDbException { return tmdbSearch.searchKeyword(query, page); }
java
{ "resource": "" }
q20237
TheMovieDbApi.getTVAccountState
train
public MediaState getTVAccountState(int tvID, String sessionID) throws MovieDbException { return tmdbTv.getTVAccountState(tvID, sessionID); }
java
{ "resource": "" }
q20238
TheMovieDbApi.getTVExternalIDs
train
public ExternalID getTVExternalIDs(int tvID, String language) throws MovieDbException { return tmdbTv.getTVExternalIDs(tvID, language); }
java
{ "resource": "" }
q20239
TheMovieDbApi.postTVRating
train
public StatusCode postTVRating(int tvID, int rating, String sessionID, String guestSessionID) throws MovieDbException { return tmdbTv.postTVRating(tvID, rating, sessionID, guestSessionID); }
java
{ "resource": "" }
q20240
TheMovieDbApi.getTVSimilar
train
public ResultList<TVInfo> getTVSimilar(int tvID, Integer page, String language) throws MovieDbException { return tmdbTv.getTVSimilar(tvID, page, language); }
java
{ "resource": "" }
q20241
TheMovieDbApi.getTVOnTheAir
train
public ResultList<TVInfo> getTVOnTheAir(Integer page, String language) throws MovieDbException { return tmdbTv.getTVOnTheAir(page, language); }
java
{ "resource": "" }
q20242
TheMovieDbApi.getTVAiringToday
train
public ResultList<TVInfo> getTVAiringToday(Integer page, String language, String timezone) throws MovieDbException { return tmdbTv.getTVAiringToday(page, language, timezone); }
java
{ "resource": "" }
q20243
TheMovieDbApi.getSeasonExternalID
train
public ExternalID getSeasonExternalID(int tvID, int seasonNumber, String language) throws MovieDbException { return tmdbSeasons.getSeasonExternalID(tvID, seasonNumber, language); }
java
{ "resource": "" }
q20244
TheMovieDbApi.getSeasonImages
train
public ResultList<Artwork> getSeasonImages(int tvID, int seasonNumber, String language, String... includeImageLanguage) throws MovieDbException { return tmdbSeasons.getSeasonImages(tvID, seasonNumber, language, includeImageLanguage); }
java
{ "resource": "" }
q20245
TheMovieDbApi.getEpisodeCredits
train
public MediaCreditList getEpisodeCredits(int tvID, int seasonNumber, int episodeNumber) throws MovieDbException { return tmdbEpisodes.getEpisodeCredits(tvID, seasonNumber, episodeNumber); }
java
{ "resource": "" }
q20246
TheMovieDbApi.getEpisodeExternalID
train
public ExternalID getEpisodeExternalID(int tvID, int seasonNumber, int episodeNumber, String language) throws MovieDbException { return tmdbEpisodes.getEpisodeExternalID(tvID, seasonNumber, episodeNumber, language); }
java
{ "resource": "" }
q20247
TmdbCertifications.getMoviesCertification
train
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); } }
java
{ "resource": "" }
q20248
Compare.compareTitles
train
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); }
java
{ "resource": "" }
q20249
Compare.movies
train
public static boolean movies(final MovieInfo moviedb, final String title, final String year, int maxDistance) { return Compare.movies(moviedb, title, year, maxDistance, true); }
java
{ "resource": "" }
q20250
Compare.compareDistance
train
private static boolean compareDistance(final String title1, final String title2, int distance) { return StringUtils.getLevenshteinDistance(title1, title2) <= distance; }
java
{ "resource": "" }
q20251
TmdbMovies.getMovieCredits
train
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); } }
java
{ "resource": "" }
q20252
TmdbMovies.getMovieKeywords
train
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); } }
java
{ "resource": "" }
q20253
TmdbMovies.getRecommendations
train
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(); }
java
{ "resource": "" }
q20254
TmdbMovies.getReleaseDates
train
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(); }
java
{ "resource": "" }
q20255
TmdbMovies.getMovieTranslations
train
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); } }
java
{ "resource": "" }
q20256
TmdbMovies.getMovieChanges
train
public ResultList<ChangeKeyItem> getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { return getMediaChanges(movieId, startDate, endDate); }
java
{ "resource": "" }
q20257
TmdbSeasons.getSeasonCredits
train
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); } }
java
{ "resource": "" }
q20258
ApiUrl.buildUrl
train
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; } }
java
{ "resource": "" }
q20259
ApiUrl.queryProcessing
train
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; }
java
{ "resource": "" }
q20260
ApiUrl.idProcessing
train
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; }
java
{ "resource": "" }
q20261
ApiUrl.otherProcessing
train
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; }
java
{ "resource": "" }
q20262
TmdbReviews.getReview
train
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); } }
java
{ "resource": "" }
q20263
PostTools.convertToJson
train
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); } }
java
{ "resource": "" }
q20264
TmdbChanges.getChangeList
train
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(); }
java
{ "resource": "" }
q20265
Discover.year
train
public Discover year(int year) { if (checkYear(year)) { params.add(Param.YEAR, year); } return this; }
java
{ "resource": "" }
q20266
Discover.primaryReleaseYear
train
public Discover primaryReleaseYear(int primaryReleaseYear) { if (checkYear(primaryReleaseYear)) { params.add(Param.PRIMARY_RELEASE_YEAR, primaryReleaseYear); } return this; }
java
{ "resource": "" }
q20267
Discover.firstAirDateYear
train
public Discover firstAirDateYear(int year) { if (checkYear(year)) { params.add(Param.FIRST_AIR_DATE_YEAR, year); } return this; }
java
{ "resource": "" }
q20268
Discover.firstAirDateYearGte
train
public Discover firstAirDateYearGte(int year) { if (checkYear(year)) { params.add(Param.FIRST_AIR_DATE_GTE, year); } return this; }
java
{ "resource": "" }
q20269
Discover.firstAirDateYearLte
train
public Discover firstAirDateYearLte(int year) { if (checkYear(year)) { params.add(Param.FIRST_AIR_DATE_LTE, year); } return this; }
java
{ "resource": "" }
q20270
Configuration.isValidPosterSize
train
public boolean isValidPosterSize(String posterSize) { if (StringUtils.isBlank(posterSize) || posterSizes.isEmpty()) { return false; } return posterSizes.contains(posterSize); }
java
{ "resource": "" }
q20271
Configuration.isValidBackdropSize
train
public boolean isValidBackdropSize(String backdropSize) { if (StringUtils.isBlank(backdropSize) || backdropSizes.isEmpty()) { return false; } return backdropSizes.contains(backdropSize); }
java
{ "resource": "" }
q20272
Configuration.isValidProfileSize
train
public boolean isValidProfileSize(String profileSize) { if (StringUtils.isBlank(profileSize) || profileSizes.isEmpty()) { return false; } return profileSizes.contains(profileSize); }
java
{ "resource": "" }
q20273
Configuration.isValidLogoSize
train
public boolean isValidLogoSize(String logoSize) { if (StringUtils.isBlank(logoSize) || logoSizes.isEmpty()) { return false; } return logoSizes.contains(logoSize); }
java
{ "resource": "" }
q20274
Configuration.isValidSize
train
public boolean isValidSize(String sizeToCheck) { return isValidPosterSize(sizeToCheck) || isValidBackdropSize(sizeToCheck) || isValidProfileSize(sizeToCheck) || isValidLogoSize(sizeToCheck); }
java
{ "resource": "" }
q20275
TmdbLists.getList
train
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); } }
java
{ "resource": "" }
q20276
TmdbLists.checkItemStatus
train
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); } }
java
{ "resource": "" }
q20277
TmdbLists.modifyMovieList
train
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); } }
java
{ "resource": "" }
q20278
TmdbLists.removeItem
train
public StatusCode removeItem(String sessionId, String listId, int mediaId) throws MovieDbException { return modifyMovieList(sessionId, listId, mediaId, MethodSub.REMOVE_ITEM); }
java
{ "resource": "" }
q20279
TmdbLists.clear
train
public StatusCode clear(String sessionId, String listId, boolean confirm) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION_ID, sessionId); parameters.add(Param.ID, listId); parameters.add(Param.CONFIRM, confirm); URL url = new ApiUrl(apiKey, MethodBase.LIST).subMethod(MethodSub.CLEAR).buildUrl(parameters); String webpage = httpTools.postRequest(url, ""); try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to clear list", url, ex); } }
java
{ "resource": "" }
q20280
TmdbKeywords.getKeyword
train
public Keyword getKeyword(String keywordId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, keywordId); URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { return MAPPER.readValue(webpage, Keyword.class); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keyword " + keywordId, url, ex); } }
java
{ "resource": "" }
q20281
HttpTools.getRequest
train
public String getRequest(final URL url) throws MovieDbException { try { HttpGet httpGet = new HttpGet(url.toURI()); httpGet.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET); long retryCount = 0L; // If we have a 429 response, wait and try again while (response.getStatusCode() == STATUS_TOO_MANY_REQUESTS && retryCount++ <= RETRY_MAX) { delay(retryCount); // Retry the request response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET); } return validateResponse(response, url); } catch (URISyntaxException | IOException ex) { throw new MovieDbException(ApiExceptionType.CONNECTION_ERROR, null, url, ex); } catch (RuntimeException ex) { throw new MovieDbException(ApiExceptionType.HTTP_503_ERROR, "Service Unavailable", url, ex); } }
java
{ "resource": "" }
q20282
HttpTools.delay
train
private void delay(long multiplier) { try { // Wait for the timeout to finish Thread.sleep(TimeUnit.SECONDS.toMillis(RETRY_DELAY * multiplier)); } catch (InterruptedException ex) { // Doesn't matter if we're interrupted } }
java
{ "resource": "" }
q20283
HttpTools.deleteRequest
train
public String deleteRequest(final URL url) throws MovieDbException { try { HttpDelete httpDel = new HttpDelete(url.toURI()); return validateResponse(DigestedResponseReader.deleteContent(httpClient, httpDel, CHARSET), url); } catch (URISyntaxException | IOException ex) { throw new MovieDbException(ApiExceptionType.CONNECTION_ERROR, null, url, ex); } }
java
{ "resource": "" }
q20284
HttpTools.postRequest
train
public String postRequest(final URL url, final String jsonBody) throws MovieDbException { try { HttpPost httpPost = new HttpPost(url.toURI()); httpPost.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON); httpPost.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); StringEntity params = new StringEntity(jsonBody, ContentType.APPLICATION_JSON); httpPost.setEntity(params); return validateResponse(DigestedResponseReader.postContent(httpClient, httpPost, CHARSET), url); } catch (URISyntaxException | IOException ex) { throw new MovieDbException(ApiExceptionType.CONNECTION_ERROR, null, url, ex); } }
java
{ "resource": "" }
q20285
HttpTools.validateResponse
train
private String validateResponse(final DigestedResponse response, final URL url) throws MovieDbException { if (response.getStatusCode() == 0) { throw new MovieDbException(ApiExceptionType.CONNECTION_ERROR, response.getContent(), response.getStatusCode(), url, null); } else if (response.getStatusCode() >= HttpStatus.SC_INTERNAL_SERVER_ERROR) { throw new MovieDbException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url, null); } else if (response.getStatusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) { throw new MovieDbException(ApiExceptionType.HTTP_404_ERROR, response.getContent(), response.getStatusCode(), url, null); } return response.getContent(); }
java
{ "resource": "" }
q20286
TmdbParameters.add
train
public void add(final Param key, final String[] value) { if (value != null && value.length > 0) { parameters.put(key, toList(value)); } }
java
{ "resource": "" }
q20287
TmdbParameters.add
train
public void add(final Param key, final String value) { if (StringUtils.isNotBlank(value)) { parameters.put(key, value); } }
java
{ "resource": "" }
q20288
TmdbParameters.add
train
public void add(final Param key, final Integer value) { if (value != null && value > 0) { parameters.put(key, String.valueOf(value)); } }
java
{ "resource": "" }
q20289
TmdbParameters.toList
train
public String toList(final String[] appendToResponse) { StringBuilder sb = new StringBuilder(); boolean first = Boolean.TRUE; for (String append : appendToResponse) { if (first) { first = Boolean.FALSE; } else { sb.append(","); } sb.append(append); } return sb.toString(); }
java
{ "resource": "" }
q20290
AbstractMethod.getTypeReference
train
protected static TypeReference getTypeReference(Class aClass) throws MovieDbException { if (TYPE_REFS.containsKey(aClass)) { return TYPE_REFS.get(aClass); } else { throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Class type reference for '" + aClass.getSimpleName() + "' not found!"); } }
java
{ "resource": "" }
q20291
AbstractMethod.processWrapperList
train
protected <T> List<T> processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { WrapperGenericList<T> val = processWrapper(typeRef, url, errorMessageSuffix); return val.getResults(); }
java
{ "resource": "" }
q20292
AbstractMethod.processWrapper
train
protected <T> WrapperGenericList<T> processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { String webpage = httpTools.getRequest(url); try { // Due to type erasure, this doesn't work // TypeReference<WrapperGenericList<T>> typeRef = new TypeReference<WrapperGenericList<T>>() {}; return MAPPER.readValue(webpage, typeRef); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex); } }
java
{ "resource": "" }
q20293
TmdbConfiguration.getJobs
train
public ResultList<JobDepartment> getJobs() throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.JOB).subMethod(MethodSub.LIST).buildUrl(); String webpage = httpTools.getRequest(url); try { WrapperJobList wrapper = MAPPER.readValue(webpage, WrapperJobList.class); ResultList<JobDepartment> results = new ResultList<>(wrapper.getJobs()); wrapper.setResultProperties(results); return results; } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get job list", url, ex); } }
java
{ "resource": "" }
q20294
TmdbConfiguration.getTimezones
train
public ResultsMap<String, List<String>> getTimezones() throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.TIMEZONES).subMethod(MethodSub.LIST).buildUrl(); String webpage = httpTools.getRequest(url); List<Map<String, List<String>>> tzList; try { tzList = MAPPER.readValue(webpage, new TypeReference<List<Map<String, List<String>>>>() { }); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get timezone list", url, ex); } ResultsMap<String, List<String>> timezones = new ResultsMap<>(); for (Map<String, List<String>> tzMap : tzList) { for (Map.Entry<String, List<String>> x : tzMap.entrySet()) { timezones.put(x.getKey(), x.getValue()); } } return timezones; }
java
{ "resource": "" }
q20295
TmdbGenres.getGenreMovieList
train
public ResultList<Genre> getGenreMovieList(String language) throws MovieDbException { return getGenreList(language, MethodSub.MOVIE_LIST); }
java
{ "resource": "" }
q20296
TmdbGenres.getGenreTVList
train
public ResultList<Genre> getGenreTVList(String language) throws MovieDbException { return getGenreList(language, MethodSub.TV_LIST); }
java
{ "resource": "" }
q20297
TmdbGenres.getGenreList
train
private ResultList<Genre> getGenreList(String language, MethodSub sub) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.GENRE).subMethod(sub).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { WrapperGenres wrapper = MAPPER.readValue(webpage, WrapperGenres.class); ResultList<Genre> results = new ResultList<>(wrapper.getGenres()); wrapper.setResultProperties(results); return results; } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre " + sub.toString(), url, ex); } }
java
{ "resource": "" }
q20298
TmdbGenres.getGenreMovies
train
public ResultList<MovieBasic> getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, genreId); parameters.add(Param.LANGUAGE, language); parameters.add(Param.PAGE, page); parameters.add(Param.INCLUDE_ALL_MOVIES, includeAllMovies); parameters.add(Param.INCLUDE_ADULT, includeAdult); URL url = new ApiUrl(apiKey, MethodBase.GENRE).subMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); WrapperGenericList<MovieBasic> wrapper = processWrapper(getTypeReference(MovieBasic.class), url, webpage); return wrapper.getResultsList(); }
java
{ "resource": "" }
q20299
TmdbEpisodes.getEpisodeChanges
train
public ResultList<ChangeKeyItem> getEpisodeChanges(int episodeID, String startDate, String endDate) throws MovieDbException { return getMediaChanges(episodeID, startDate, endDate); }
java
{ "resource": "" }