Ejemplo n.º 1
0
  /** Tries reading one particular file as a post. */
  public Optional<Post> parsePost(FileNode node) {
    String fileName = node.getPath();

    // check for match
    Matcher matcher = POST_TITLE_PATTERN.matcher(fileName);
    if (!matcher.matches()) return Optional.absent();

    try {
      // get date
      int year = Integer.valueOf(matcher.group(1));
      int month = Integer.valueOf(matcher.group(2)) - 1; // java Calendar is 0 based
      int day = Integer.valueOf(matcher.group(3));
      Calendar calendar = Calendar.getInstance();
      calendar.set(year, month, day);

      // get title
      String title = formatTitle(matcher.group(4));

      return Optional.of(new Post(title, calendar.getTime(), node));

    } catch (NumberFormatException nfe) {
      Timber.w(nfe, "failed to parse post tile \"" + fileName + "\"");
      return Optional.absent();
    }
  }
Ejemplo n.º 2
0
  /** Tries reading one particular file as a draft. */
  public Optional<Draft> parseDraft(FileNode node) {
    // check for match
    Matcher matcher = DRAFT_TITLE_PATTERN.matcher(node.getPath());
    if (!matcher.matches()) return Optional.absent();

    // get title
    String title = formatTitle(matcher.group(1));

    return Optional.of(new Draft(title, node));
  }
Ejemplo n.º 3
0
 public Observable<Optional<Station>> getStationByGaugeId(final String gaugeId) {
   if (!stationCache.getStations().isPresent()) {
     return getStations()
         .flatMap(
             new Func1<Collection<Station>, Observable<Optional<Station>>>() {
               @Override
               public Observable<Optional<Station>> call(Collection<Station> stations) {
                 return Observable.just(
                     Optional.of(stationCache.getStations().get().get(gaugeId)));
               }
             });
   } else {
     return Observable.just(Optional.of(stationCache.getStations().get().get(gaugeId)));
   }
 }