private static NumericMatrix getMatrix(Collection<PlainPerson> persons, LegPredicate pred) { NumericMatrix m = new NumericMatrix(); for (Person person : persons) { for (Episode episode : person.getEpisodes()) { for (int i = 0; i < episode.getLegs().size(); i++) { Segment leg = episode.getLegs().get(i); if (pred.test(leg)) { Segment prev = episode.getActivities().get(i); Segment next = episode.getActivities().get(i + 1); String origin = prev.getAttribute(SetZones.ZONE_KEY); String dest = next.getAttribute(SetZones.ZONE_KEY); if (origin != null && dest != null) { m.add(origin, dest, 1); String touched = leg.getAttribute(DBG_TOUCHED); int cnt = 0; if (touched != null) cnt = Integer.parseInt(touched); leg.setAttribute(DBG_TOUCHED, String.valueOf(cnt + 1)); } } } } } return m; }
public void UpdateAllType() { if (IsSaved()) { // update serie ContentValues values = new ContentValues(); values.put(SeriesContract.SeriesEntry.COLUMN_TYPE, type); MyApplication.getContext() .getContentResolver() .update( SeriesContract.SeriesEntry.CONTENT_URI, values, SeriesContract.SeriesEntry.COLUMN_ID + "=?", new String[] {id}); // update episodes values = new ContentValues(); int viewed = 0; if (type == VIEWED) viewed = 1; values.put(SeriesContract.EpisodesEntry.COLUMN_VIEWED, viewed); MyApplication.getContext() .getContentResolver() .update( SeriesContract.EpisodesEntry.CONTENT_URI, values, SeriesContract.EpisodesEntry.COLUMN_SERIE_ID + "=?", new String[] {id}); for (Episode episode : episodes) { episode.setViewed(viewed); } } }
@Test public void saveGetAndUpdateSeriesWithEpisodes() { Series serie = new Series("EpisodeSeriesTest", "estID"); List<Episode> eList = new ArrayList<>(); eList.add(new Episode("title", "path1", 1, 1)); eList.add(new Episode("title", "path2", 1, 2)); serie.setEpisodes(eList); repository.save(serie); Series serieRe = repository.findByImdbId("estID"); List<Episode> reEp = serieRe.getEpisodes(); assertThat(reEp, hasSize(2)); serieRe.getEpisodes().add(new Episode("title", "path3", 1, 3)); repository.save(serieRe); serieRe = repository.findByImdbId("estID"); reEp = serieRe.getEpisodes(); assertThat(reEp, hasSize(3)); Episode e = eRepository.findByFilePath("path1"); assertEquals("title", e.getTitle()); e = eRepository.findByFilePath("path2"); assertEquals("title", e.getTitle()); }
public boolean hasNoEpisodeViewed() { if (episodes.size() == 0) return true; List<Episode> list = episodes; for (Episode episode : list) { if (episode.getViewed() == 1) return false; } return true; }
public void reset() { currentRoom = episode.getStartingPosition().room; player = new Player( currentRoom, episode.getStartingPosition().x, episode.getStartingPosition().y, episode.getStartingPosition().z); }
public int GetFistEpisodeNotViewed() { if (episodes.size() == 0) return 0; if (episodes.size() == 1) return 1; List<Episode> list = episodes; for (Episode episode : list) { if (episode.getViewed() == 0) return episode.getEpisode_number(); } return 1; }
public ArrayList<Episode> getSeason(int season) { if (season == 0 || season > getSeasonsCount()) return new ArrayList<>(); if (episodes.size() == 0) return new ArrayList<>(); ArrayList<Episode> seasonEpisodes = new ArrayList<>(); List<Episode> list = episodes; for (Episode episode : list) { if (episode.getSeason_number() == season) seasonEpisodes.add(episode); } return seasonEpisodes; }
public static void DownloadQueue(Context c) { while (!EpisodeQueue.isEmpty()) { final Episode episode = EpisodeQueue.remove(); makeToast("Downloading " + episode.filename); episode.podcast.priority++; episode.download(true, c); refreshUI(); } // Log.i("RSS Reader", "Finished Queue"); }
public void Update(boolean isRefresing) { // when we refresh the data from the internet, we load again episodes and we neew to get back // to the objects that already exists if the were viewed that is smth we have stored. if (IsSaved()) { ContentValues values = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. values.put(SeriesContract.SeriesEntry.COLUMN_NAME, name); values.put(SeriesContract.SeriesEntry.COLUMN_NETWORK, network); values.put(SeriesContract.SeriesEntry.COLUMN_POSTER_URL, poster_url); values.put(SeriesContract.SeriesEntry.COLUMN_BANNER_URL, image_url); values.put(SeriesContract.SeriesEntry.COLUMN_OVERVIEW, overView); values.put(SeriesContract.SeriesEntry.COLUMN_RATING, rating); values.put(SeriesContract.SeriesEntry.COLUMN_VOTES, votes); values.put(SeriesContract.SeriesEntry.COLUMN_REALSED_DATE, dateReleased); values.put(SeriesContract.SeriesEntry.COLUMN_GENRE, genre); values.put(SeriesContract.SeriesEntry.COLUMN_MODIFYDATE, modify_date.getTime()); values.put(SeriesContract.SeriesEntry.COLUMN_STATUS, status); // Finally, insert serie data into the database. MyApplication.getContext() .getContentResolver() .update( SeriesContract.SeriesEntry.CONTENT_URI, values, SeriesContract.SeriesEntry.COLUMN_ID + "=?", new String[] {id}); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. if (episodes != null && episodes.size() > 0) { List<Episode> list = episodes; for (Episode episode : list) { if (episode.IsSaved()) { episode.Update(); if (isRefresing) { // we need to get back the field viewed from database to inflate it properly episode.LoadViewed(); } } else episode.Save(); } } if (actors != null && actors.size() > 0) { List<Actor> list = actors; for (Actor actor : list) { if (actor.IsSaved()) actor.Update(); else actor.Save(); } } } else { Save(); } }
@Override public void startTag(String name, Attributes atts, Stack<String> context) { if (name.equalsIgnoreCase(Constants.PERSONS_TAG)) { persons = new HashSet<>(); } else if (name.equalsIgnoreCase(Constants.PERSON_TAG)) { person = factory.newPerson(getAttribute(Constants.ID_KEY, atts)); for (int i = 0; i < atts.getLength(); i++) { String type = atts.getLocalName(i); if (!type.equalsIgnoreCase(Constants.ID_KEY)) { if (!blacklist.contains(type)) { person.setAttribute(type, getAttribute(type, atts)); } } } } else if (name.equalsIgnoreCase(Constants.PLAN_TAG)) { plan = factory.newEpisode(); for (int i = 0; i < atts.getLength(); i++) { String type = atts.getLocalName(i); if (!blacklist.contains(type)) { plan.setAttribute(type, getAttribute(type, atts)); } } } else if (name.equalsIgnoreCase(Constants.ACTIVITY_TAG)) { Segment act = factory.newSegment(); for (int i = 0; i < atts.getLength(); i++) { String type = atts.getLocalName(i); if (!blacklist.contains(type)) { act.setAttribute(type, getAttribute(type, atts)); } } plan.addActivity(act); } else if (name.equalsIgnoreCase(Constants.LEG_TAG)) { Segment leg = factory.newSegment(); for (int i = 0; i < atts.getLength(); i++) { String type = atts.getLocalName(i); if (!blacklist.contains(type)) { leg.setAttribute(type, getAttribute(type, atts)); } } plan.addLeg(leg); } }
public static int getLastSeason(Iterable<Episode> episodes) { int lastSeason = 0; // filter given season from all seasons for (Episode episode : episodes) { try { lastSeason = Math.max(lastSeason, Integer.parseInt(episode.getSeason())); } catch (NumberFormatException e) { // ignore illegal episodes } } return lastSeason; }
@Test public void itReturnsAudioUrl() { Episode episode = new Episode() { @Override protected Audio getAudio() { return new Audio() { @Override public String getUrl() { return "audio.mp3"; } }; } }; assertThat(episode.getAudioUrl(), is(episode.getAudio().getUrl())); }
public static List<Episode> filterBySeason(Iterable<Episode> episodes, int season) { List<Episode> results = new ArrayList<Episode>(25); // filter given season from all seasons for (Episode episode : episodes) { try { if (season == Integer.parseInt(episode.getSeason())) { results.add(episode); } } catch (NumberFormatException e) { // ignore illegal episodes } } return results; }
@Test public void itReturnsEpisodeRepresentation() { Episode episode = new Episode() { @Override public String getTitle() { return "Newest episode"; } @Override public Feed getFeed() { return new Feed() { @Override public String getId() { return "123"; } @Override public String getTitle() { return "Awesome podcast"; } }; } @Override public Audio getAudio() { return new Audio() { @Override public String getUrl() { return "audio.mp3"; } }; } }; String episodeRepresentation = format( "{ \"title\": %s, \"audioFilePath\": %s, \"feed\": { \"id\": %s, \"title\": %s } }", episode.getTitle(), episode.getAudioFilePath(), episode.getFeed().getId(), episode.getFeed().getTitle()); assertThat(episode.toString(), is(episodeRepresentation)); }
public void buttonClickHandler(View v) { final int id = v.getId(); for (TableRow tr : mButtons) { if (id == tr.getId()) activateButton(tr); else resetButton(tr); } if (id == R.id.row1) { mDescription.setText(mEpisode.getDescription()); } else if (id == R.id.row2) { String t = mEpisode.getTransscript(); // System.out.print(t); mDescription.setText(t.toString()); } else if (id == R.id.row3) { mDescription.setText(mShowNotes); } }
// Store Line of dialog private void storeLine(String line) { // Split line so character name and dialog are seperated. String[] splitLine = line.split("\t", 2); if (splitLine.length < 2) { return; } String character = splitLine[0].toLowerCase(); // Store character name character = updateName( character); // Check to see if name needs to be changed (eg. "inez" is also = "mrs. // wong") // Add character to episode (unless is a background character) if (!isBackgroundCharacter(character)) { int i = findCharacter(character); if (i < 0) { // If chracter does not exist Character chr = new Character(character, GLOBAL.COLORS.getNextColor()); // make a new Character object chr.addAppearence( ALL_CHARACTERS .get(lastCharacter) .getName()); // Add the previous Character to its HashMap ALL_CHARACTERS.add(chr); // Add Character object to ArrayList ep.addCharacter(chr); // Add Character object to Episode lastCharacter = ALL_CHARACTERS.size() - 1; // Store index of this Character } else { // Add Character object to Episode ALL_CHARACTERS.get(i).addAppearence(ALL_CHARACTERS.get(lastCharacter).getName()); ep.addCharacter(ALL_CHARACTERS.get(i)); lastCharacter = i; // Store index of this Character } // Determine if current line is a catchphrase of character findCatchphrase(character, splitLine[1]); } }
public void Save() { if (!IsSaved()) { ContentValues values = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. values.put(SeriesContract.SeriesEntry.COLUMN_ID, id); values.put(SeriesContract.SeriesEntry.COLUMN_NAME, name); values.put(SeriesContract.SeriesEntry.COLUMN_NETWORK, network); values.put(SeriesContract.SeriesEntry.COLUMN_POSTER_URL, poster_url); values.put(SeriesContract.SeriesEntry.COLUMN_BANNER_URL, image_url); values.put(SeriesContract.SeriesEntry.COLUMN_OVERVIEW, overView); values.put(SeriesContract.SeriesEntry.COLUMN_RATING, rating); values.put(SeriesContract.SeriesEntry.COLUMN_VOTES, votes); values.put(SeriesContract.SeriesEntry.COLUMN_REALSED_DATE, dateReleased); values.put(SeriesContract.SeriesEntry.COLUMN_GENRE, genre); values.put(SeriesContract.SeriesEntry.COLUMN_MODIFYDATE, modify_date.getTime()); values.put(SeriesContract.SeriesEntry.COLUMN_STATUS, status); values.put(SeriesContract.SeriesEntry.COLUMN_TYPE, type); // Finally, insert serie data into the database. Uri insertedUri = MyApplication.getContext() .getContentResolver() .insert(SeriesContract.SeriesEntry.CONTENT_URI, values); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. _id = ContentUris.parseId(insertedUri); if (episodes != null && episodes.size() > 0) { List<Episode> list = episodes; for (Episode episode : list) { episode.Save(); } } if (actors != null && actors.size() > 0) { List<Actor> list = actors; for (Actor actor : list) { actor.Save(); } } } }
@Test public void itReturnsAudioFilePath() { Episode episode = new Episode() { @Override public String getTitle() { return "Newest episode"; } @Override public Feed getFeed() { return new Feed() { @Override public String getId() { return "123"; } @Override public String getTitle() { return "Awesome podcast"; } }; } @Override public Audio getAudio() { return new Audio() { @Override public String getUrl() { return "audio.mp3"; } }; } }; assertThat( episode.getAudioFilePath(), is(episode.getFeed().getId() + "/" + episode.getTitle() + ".mp3")); }
// Add current episode to Character objects' episode lists private void updateCharacterEpisodes() { // Retrieve all chracters added to the current episode ArrayList<Character> chars = ep.getChars(); // Parse characters from current episode for (int x = 0; x < chars.size(); ++x) { for (int y = 0; y < ALL_CHARACTERS.size(); ++y) { if (chars.get(x).getName().equals(ALL_CHARACTERS.get(y).getName())) { ALL_CHARACTERS.get(y).addEpisode(season, episode); // System.out.println(chars.get(x) + "\tep# " + episode); } } } }
public static Episode deepCopy(Episode episode, Factory factory) { Episode clone = factory.newEpisode(); for (String key : episode.keys()) { clone.setAttribute(key, episode.getAttribute(key)); } for (Segment act : episode.getActivities()) { Segment actClone = shallowCopy(act, factory); clone.addActivity(actClone); } for (Segment leg : episode.getLegs()) { Segment legClone = shallowCopy(leg, factory); clone.addLeg(legClone); } return clone; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.episode); // this.getExternalFilesDir(null) this.database = new EpisodeDatabase(this); mFetcher = new EpisodeFetcher(this.database); mProgressBar = (SeekBar) findViewById(R.id.SeekBar); mProgressBar.setOnSeekBarChangeListener(weightSeekBarListener); mTitle = (TextView) findViewById(R.id.title); mDescription = (TextView) findViewById(R.id.textarea); mScrollView = (ScrollView) findViewById(R.id.scrollview); // mStreamTxt = (TextView) findViewById(R.id.streamtxt); TableRow mButton1 = (TableRow) findViewById(R.id.row1); TableRow mButton2 = (TableRow) findViewById(R.id.row2); TableRow mButton3 = (TableRow) findViewById(R.id.row3); mButtons.add(mButton1); mButtons.add(mButton2); mButtons.add(mButton3); // Bundle bun = getIntent().getExtras(); mTitle.setText(bun.getString("title")); // is this needed? Spanned desc = Html.fromHtml(bun.getString("description")); mDescription.setText(desc); mPlayButton = (Button) findViewById(R.id.play); mPlayButton.setOnClickListener(playButtonListener); int episodeNumber = bun.getInt("episode"); Episode episode = database.getEpisode(episodeNumber); if (episode != null) { mEpisode = episode; mDescription.setText(mEpisode.getDescription()); } episodeLoader = new LoadEpisode(); episodeLoader.execute(episodeNumber); }
@Test public void findByFilePath() { Episode e = repository.findByFilePath("testEpisode1.avi"); assertThat(e.getTitle(), is("testEpisode1")); }
public void LoadEpisodes() { if (id.equals("")) return; Cursor data = MyApplication.getContext() .getContentResolver() .query( SeriesContract.EpisodesEntry.CONTENT_URI, EPISODES_COLUMNS, SeriesContract.EpisodesEntry.COLUMN_SERIE_ID + " = ?", new String[] {id}, null); episodes = new ArrayList<>(); while (data.moveToNext()) { Episode myEpisode = new Episode(); myEpisode.set_id(COL__ID); myEpisode.setSerie_id(data.getString(COLUMN_SERIE_ID)); myEpisode.setSeason_id(data.getString(COLUMN_SEASON_ID)); myEpisode.setEpisode_id(data.getString(COLUMN_EPISODE_ID)); myEpisode.setSeason_number(data.getInt(COLUMN_SEASON_NUMBER)); myEpisode.setEpisode_number(data.getInt(COLUMN_EPISODE_NUMBER)); myEpisode.setName(data.getString(COLUMN_NAME)); myEpisode.setDate(data.getString(COLUMN_DATE)); myEpisode.setOverview(data.getString(COLUMN_OVERVIEW)); myEpisode.setRating(data.getString(COLUMN_RATING)); myEpisode.setVotes(data.getString(COLUMN_VOTES)); myEpisode.setImage_url(data.getString(COLUMN_IMAGE_URL)); myEpisode.setViewed(data.getInt(COLUMN_VIEWED)); episodes.add(myEpisode); } data.close(); }
public static void main(String[] args) throws IOException { String in = args[0]; String rootDir = args[1]; logger.info("Loading persons..."); XMLHandler reader = new XMLHandler(new PlainFactory()); reader.setValidating(false); reader.readFile(in); Collection<PlainPerson> persons = (Set<PlainPerson>) reader.getPersons(); logger.info(String.format("Loaded %s persons.", persons.size())); logger.info("Restoring original activity types..."); TaskRunner.run(new RestoreActTypes(), persons, true); logger.info("Replacing misc types..."); new ReplaceMiscType().apply(persons); logger.info("Imputing month attributes..."); new ImputeMonth().apply(persons); logger.info("Assigning leg purposes..."); TaskRunner.run(new SetLegPurposes(), persons); logger.info("Inferring wecommuter purpose..."); TaskRunner.run(new InfereWeCommuter(100000), persons); Map<String, LegPredicate> modePreds = new LinkedHashMap<>(); modePreds.put("car", new LegKeyValuePredicate(CommonKeys.LEG_MODE, "car")); Map<String, LegPredicate> purposePreds = new LinkedHashMap<>(); purposePreds.put( ActivityTypes.BUSINESS, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.BUSINESS)); purposePreds.put( ActivityTypes.EDUCATION, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.EDUCATION)); PredicateORComposite leisurePred = new PredicateORComposite(); leisurePred.addComponent( new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.LEISURE)); leisurePred.addComponent(new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, "visit")); leisurePred.addComponent(new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, "gastro")); leisurePred.addComponent(new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, "culture")); leisurePred.addComponent(new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, "private")); leisurePred.addComponent(new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, "pickdrop")); leisurePred.addComponent(new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, "sport")); purposePreds.put(ActivityTypes.LEISURE, leisurePred); purposePreds.put( ActivityTypes.SHOP, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.SHOP)); purposePreds.put( ActivityTypes.WORK, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.WORK)); purposePreds.put( ActivityTypes.VACATIONS_SHORT, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.VACATIONS_SHORT)); purposePreds.put( ActivityTypes.VACATIONS_LONG, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, ActivityTypes.VACATIONS_LONG)); purposePreds.put( InfereWeCommuter.WECOMMUTER, new LegKeyValuePredicate(CommonKeys.LEG_PURPOSE, InfereWeCommuter.WECOMMUTER)); Map<String, LegPredicate> dayPreds = new LinkedHashMap<>(); dayPreds.put( CommonValues.MONDAY, new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.MONDAY)); dayPreds.put( CommonValues.FRIDAY, new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.FRIDAY)); dayPreds.put( CommonValues.SATURDAY, new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.SATURDAY)); dayPreds.put( CommonValues.SUNDAY, new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.SUNDAY)); PredicateORComposite dimidoPred = new PredicateORComposite(); dimidoPred.addComponent(new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.TUESDAY)); dimidoPred.addComponent(new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.WEDNESDAY)); dimidoPred.addComponent(new PersonKeyValuePredicate(CommonKeys.DAY, CommonValues.THURSDAY)); dayPreds.put(DIMIDO, dimidoPred); Map<String, LegPredicate> seasonPreds = new LinkedHashMap<>(); PredicateORComposite summerPred = new PredicateORComposite(); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.APRIL)); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.MAY)); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.JUNE)); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.JULY)); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.AUGUST)); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.SEPTEMBER)); summerPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.OCTOBER)); seasonPreds.put(SUMMER, summerPred); PredicateORComposite winterPred = new PredicateORComposite(); winterPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.NOVEMBER)); winterPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.DECEMBER)); winterPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.JANUARY)); winterPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.FEBRUARY)); winterPred.addComponent(new PersonKeyValuePredicate(MiDKeys.PERSON_MONTH, MiDValues.MARCH)); seasonPreds.put(WINTER, winterPred); Map<String, LegPredicate> directionPreds = new LinkedHashMap<>(); directionPreds.put( DirectionPredicate.OUTWARD, new DirectionPredicate(DirectionPredicate.OUTWARD)); directionPreds.put( DirectionPredicate.RETURN, new DirectionPredicate(DirectionPredicate.RETURN)); directionPreds.put( DirectionPredicate.INTERMEDIATE, new DirectionPredicate(DirectionPredicate.INTERMEDIATE)); logger.info("Extracting full matrix..."); NumericMatrixTxtIO.write( getMatrix(persons, modePreds.get("car")), String.format("%s/car.txt.gz", rootDir)); for (Map.Entry<String, LegPredicate> mode : modePreds.entrySet()) { for (Map.Entry<String, LegPredicate> purpose : purposePreds.entrySet()) { for (Map.Entry<String, LegPredicate> day : dayPreds.entrySet()) { for (Map.Entry<String, LegPredicate> season : seasonPreds.entrySet()) { for (Map.Entry<String, LegPredicate> direction : directionPreds.entrySet()) { PredicateANDComposite comp = new PredicateANDComposite(); comp.addComponent(mode.getValue()); comp.addComponent(purpose.getValue()); comp.addComponent(day.getValue()); comp.addComponent(season.getValue()); comp.addComponent(direction.getValue()); StringBuilder builder = new StringBuilder(); builder.append(mode.getKey()); builder.append(DIM_SEPARATOR); builder.append(purpose.getKey()); builder.append(DIM_SEPARATOR); builder.append(day.getKey()); builder.append(DIM_SEPARATOR); builder.append(season.getKey()); builder.append(DIM_SEPARATOR); builder.append(direction.getKey()); logger.info(String.format("Extracting matrix %s...", builder.toString())); NumericMatrix m = getMatrix(persons, comp); String out = String.format("%s/%s.txt.gz", rootDir, builder.toString()); NumericMatrixTxtIO.write(m, out); } } } } } int cnt = 0; for (Person person : persons) { for (Episode episode : person.getEpisodes()) { for (Segment leg : episode.getLegs()) { String touched = leg.getAttribute(DBG_TOUCHED); if (touched == null) { leg.setAttribute(DBG_TOUCHED, "0"); cnt++; } } } } logger.info(String.format("%s trips are untouched.", cnt)); XMLWriter writer = new XMLWriter(); writer.write(rootDir + "/plans.xml.gz", persons); logger.info("Done."); }
public List<Episode> getNewEpisodeList(boolean doMakeToast, Context c) { try { List<Episode> newEpisodes = new ArrayList<Episode>(); List<File> oldFiles = this.getLocalEpisodeFiles(); Boolean newEpisodeFound = false; RssFeed feed = RssReader.read(new URL(this.Url)); List<RssItem> entries = feed.getRssItems(); Log.i("RSS Reader", feed.getTitle()); Log.i("RSS Reader", feed.getLink()); Log.i("RSS Reader", feed.getDescription()); if (entries.size() < Math.abs(Limit)) Limit = entries.size(); if (Limit > 0) { entries = entries.subList(0, Limit); } else if (Limit < 0) { entries = entries.subList(entries.size() + Limit, entries.size()); } else if (Limit == 0) { entries = new ArrayList<RssItem>(); } List<String> newFiles = new ArrayList<String>(); String filename = ""; for (RssItem item : entries) { // RssItem item = entries.get(i); Log.i("RSS Reader", item.getTitle()); Log.i("RSS Reader", "XXXXX\tContent: " + item.getContent()); Log.i("RSS Reader", "XXXXX\tDate:" + item.getPubDate().toString()); Log.i("RSS Reader", "XXXXX\tLink: " + item.getLink()); Log.i("RSS Reader", "XXXXX\tEnclosures: "); for (RssEnclosure enc : item.getEnclosures()) { Log.i("RSS Reader", " \t" + enc.toString()); String encType = enc.getType(); String encUrl = enc.getValue(); filename = getFileName(encUrl); String extension = getFileExtension(encUrl); String NamingType = Setting_Naming.getSavedValue(context); try { String titleName = item.getTitle() + extension; SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm"); String datename = sdf.format(item.getPubDate()) + extension; if (NamingType.equals("Default")) { // Do nothing, the filename is currently correct } else if (NamingType.equals("Title")) { filename = titleName; } else if (NamingType.equals("Publish Date")) { filename = datename; } } catch (Exception e) { Log.d("Podcast|Naming", "Failed to change episode name", e); } newFiles.add(filename); String qname = enc.getQName(); if (qname.equals("url")) { Episode e = new Episode(item.getTitle(), filename, encUrl, this, item.getPubDate()); if (!e.exists(c) && !containsUrl(e.url)) { newEpisodeFound = true; newEpisodes.add(e); } } } } Boolean deletedFile = false; for (File f : oldFiles) { if (!newFiles.contains(f.getName()) && !PodcastApplication.isStarred(f.getName())) { f.delete(); if (doMakeToast) makeToast("Deleted old file " + f.getName()); deletedFile = true; } } if (deletedFile && doMakeToast) refreshUI(); return newEpisodes; } catch (Exception exp) { Log.e("Podcast", exp.getMessage(), exp); if (doMakeToast) makeToast("Error " + exp.getMessage() + " occurred. Please try again."); return new ArrayList<Episode>(); } }
@Test public void itReturnsEmptyUrlWhenAudioIsNull() { Episode episode = new Episode(); assertThat(episode.getAudioUrl(), is("")); }
private Alias generateAliasFor(Episode content) { return PaHelper.getEpisodeAlias(content.getId().toString()); }
@Test public void itReturnsEmptyDescriptionWhenItIsNull() { Episode episode = new Episode(); assertThat(episode.getDescription(), is("")); }