/** @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a> */
public class FileAttributes {
  public final Option<String> user;

  public final Option<String> group;

  public final Option<UnixFileMode> mode;

  public final List<String> tags;

  public static final Show<FileAttributes> singleLineShow = Show.anyShow();

  /** A file object with all none fields. Use this when creating template objects. */
  public static final FileAttributes EMPTY =
      new FileAttributes(
          Option.<String>none(),
          Option.<String>none(),
          Option.<UnixFileMode>none(),
          List.<String>nil());

  public FileAttributes(Option<String> user, Option<String> group, Option<UnixFileMode> mode) {
    this(user, group, mode, List.<String>nil());
  }

  public FileAttributes(
      Option<String> user, Option<String> group, Option<UnixFileMode> mode, List<String> tags) {
    validateNotNull(user, group, mode, tags);
    this.user = user;
    this.group = group;
    this.mode = mode;
    this.tags = tags;
  }

  public FileAttributes user(String user) {
    return new FileAttributes(fromNull(user), group, mode, tags);
  }

  public FileAttributes user(Option<String> user) {
    return new FileAttributes(user, group, mode, tags);
  }

  public FileAttributes group(String group) {
    return new FileAttributes(user, fromNull(group), mode, tags);
  }

  public FileAttributes group(Option<String> group) {
    return new FileAttributes(user, group, mode, tags);
  }

  public FileAttributes mode(UnixFileMode mode) {
    return new FileAttributes(user, group, fromNull(mode), tags);
  }

  public FileAttributes mode(Option<UnixFileMode> mode) {
    return new FileAttributes(user, group, mode, tags);
  }

  public FileAttributes addTag(String tag) {
    return new FileAttributes(user, group, mode, tags.append(single(tag)));
  }

  public FileAttributes tags(List<String> tags) {
    return new FileAttributes(user, group, mode, this.tags.append(tags));
  }

  // -----------------------------------------------------------------------
  //
  // -----------------------------------------------------------------------

  public FileAttributes useAsDefaultsFor(FileAttributes other) {
    return new FileAttributes(
        other.user.orElse(user), other.group.orElse(group), other.mode.orElse(mode), other.tags);
  }

  // -----------------------------------------------------------------------
  //
  // -----------------------------------------------------------------------

  public static final F2<FileAttributes, FileAttributes, FileAttributes> useAsDefaultsFor =
      new F2<FileAttributes, FileAttributes, FileAttributes>() {
        public FileAttributes f(FileAttributes defaults, FileAttributes other) {
          return defaults.useAsDefaultsFor(other);
        }
      };

  public static final F<FileAttributes, Option<String>> userF =
      new F<FileAttributes, Option<String>>() {
        public Option<String> f(FileAttributes attributes) {
          return attributes.user;
        }
      };

  public static final F<FileAttributes, Option<String>> groupF =
      new F<FileAttributes, Option<String>>() {
        public Option<String> f(FileAttributes attributes) {
          return attributes.group;
        }
      };

  public static final F<FileAttributes, Option<UnixFileMode>> modeF =
      new F<FileAttributes, Option<UnixFileMode>>() {
        public Option<UnixFileMode> f(FileAttributes attributes) {
          return attributes.mode;
        }
      };

  public static final F<FileAttributes, List<String>> tagsF =
      new F<FileAttributes, List<String>>() {
        public List<String> f(FileAttributes attributes) {
          return attributes.tags;
        }
      };

  // -----------------------------------------------------------------------
  // Object Overrides
  // -----------------------------------------------------------------------

  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }

    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    FileAttributes that = (FileAttributes) o;

    return optionEquals(user, that.user)
        && optionEquals(group, that.group)
        && optionEquals(mode, that.mode);
  }

  public String toString() {
    return "user="******"<not set>")
        + ", "
        + "group="
        + group.orSome("<not set>")
        + ", "
        + "mode="
        + mode.map(showLong).orSome("<not set>");
  }
}
Пример #2
0
 protected SeriesInfo getSeriesInfoObj(Object o) {
   if (o instanceof sage.vfs.MediaNode) o = ((sage.vfs.MediaNode) o).getDataObject();
   if (o instanceof SeriesInfo) return (SeriesInfo) o;
   // See if we can go Show->Series
   Show s = getShowObj(o);
   return (s != null) ? s.getSeriesInfo() : null;
 }
Пример #3
0
  @Override
  public void createPartControl(Composite parent) {
    this.parent = parent;
    Model m = new Model();
    parent.setLayout(new GridLayout(2, false));

    Func func = new Func(m, parent, this);
    func.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 2));

    Show view = new Show(m, parent);
    view.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Info text = new Info(m, parent);
    text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    m.addObserver(view);
    m.addObserver(func);
    m.addObserver(text);
    m.setNotified();
    parent.layout();

    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(parent, ACOPlugin.PLUGIN_ID + ".view"); // $NON-NLS-1$
  }
Пример #4
0
  public static ArrayList<Reservation> getReservations(Show[] shows, Customer[] customers) {
    Logger.log("Database.getReservations");
    ArrayList<Reservation> reservations = new ArrayList<Reservation>();
    try {
      ArrayList<Reservation> tempReservations = new ArrayList<Reservation>();
      Show show = null;
      Customer customer = null;

      ResultSet rs = query("SELECT COUNT(*) FROM reservation");
      rs.next();

      rs = query("SELECT * FROM reservation");
      while (rs.next()) {
        ArrayList<Point> position = new ArrayList<Point>();
        for (Show s : shows) {
          if (s.getID() == rs.getInt("forestilling_id")) {
            show = s;
          }
        }
        position.add(new Point(rs.getInt("pos_x"), rs.getInt("pos_y")));
        for (Customer c : customers) {
          if (c.getID() == rs.getInt("kunde_id")) {
            customer = c;
          }
        }
        tempReservations.add(
            new Reservation(show, position, customer, rs.getInt("reservation_id")));
      }
      // Merge all reservations which have the same show AND customer and save them in reservations
      // list
      while (tempReservations.size() != 0) {
        Customer cus = tempReservations.get(0).getCustomer();
        Show s = tempReservations.get(0).getShow();
        ArrayList<Point> seats = new ArrayList<Point>();
        int ID = tempReservations.get(0).getID();
        for (int x = 0; x < tempReservations.size(); x++) {
          if (tempReservations.get(x).getCustomer() == cus
              && tempReservations.get(x).getShow() == s) {
            seats.add(tempReservations.get(x).getFirstPos());
            tempReservations.remove(tempReservations.get(x));
            // After deleting the object, decrease x with 1 (else one element would never be
            // reached)
            x--;
          }
        }
        reservations.add(new Reservation(s, seats, cus, ID));
      }

    } catch (SQLException exception) {
      Logger.log(exception, "Database:getReservations");
    }
    Logger.log("Database.getReservations");
    return reservations;
  }
Пример #5
0
  public void execute() {

    super.execute();

    try {
      System.out.println(showDescOfAllRelations());
    } catch (EnvironmentNotFoundException e) {
      System.err.println("Database is currently empty!!.");
      return;
    }
  }
Пример #6
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.show_description);
   title = (TextView) findViewById(R.id.showTitle);
   description = (TextView) findViewById(R.id.showDescription);
   horaInicio = (TextView) findViewById(R.id.horaInicio);
   horaFim = (TextView) findViewById(R.id.horaFim);
   Show show = ((GuiaTvApp) getApplication()).getShow();
   setTitle(show.getName());
   title.setText(show.getName());
   description.setText(show.getDescription());
   horaInicio.setText(
       String.format("Inicio:\t %02d:%02d", show.getInicio().hour, show.getInicio().minute));
   horaFim.setText(String.format("Fim:\t %02d:%02d", show.getFim().hour, show.getFim().minute));
 }
Пример #7
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    System.out.println("get shows by date start");
    response.setCharacterEncoding("utf-8");

    // call services
    MovieService ms = new MovieService();
    TicketTypeService tts = new TicketTypeService();
    ShowService ss = new ShowService();

    // 設定要取得的查詢時間
    String start = request.getParameter("start") + " 00:00:00";
    String end = request.getParameter("end") + " 23:59:59";

    System.out.println(start);
    System.out.println(end);
    List<ShowVO> showlist = null;
    List<Show> showList = new ArrayList<>();

    showlist = ss.queryByDate(start, end);

    for (ShowVO showVO : showlist) {
      Show show = new Show();
      show.screenId = showVO.getScreenId();
      show.showId = showVO.getShowId();
      show.movieName = ms.queryByID(showVO.getMovieId()).getName();
      show.movieEname = ms.queryByID(showVO.getMovieId()).geteName();
      show.movieImage = ms.queryByID(showVO.getMovieId()).getImage();
      show.showDate = showVO.getShowDate().toString();
      show.showTime = showVO.getShowTime().toString();
      show.ShowType = tts.queryByID(showVO.getTicketTypeId()).getShowType();
      showList.add(show);
    }

    PrintWriter out = response.getWriter();
    out.println(JsonUtils.obj2Json(showList));
    out.flush();
    out.close();
  }
Пример #8
0
 public static boolean createReservation(Show show, Point[] points, Customer c) {
   Logger.log("Database.createReservation");
   String sql = "";
   for (Point seat : points) {
     sql =
         "INSERT INTO reservation(forestilling_id, pos_x, pos_y, kunde_id) VALUES ("
             + show.getID()
             + ","
             + seat.x
             + ","
             + seat.y
             + ","
             + c.getID()
             + ");";
     if (update(sql)) {
       continue;
     }
     return false;
   }
   Logger.log("Database.createReservation");
   return true;
 }
Пример #9
0
 @Override
 public String toString() {
   return Show.nonEmptyListShow(Show.<A>anyShow()).showS(this);
 }
Пример #10
0
  public String getNewFilename() {
    switch (this.status) {
      case ADDED:
        {
          return ADDED_PLACEHOLDER_FILENAME;
        }
      case DOWNLOADED:
      case RENAMED:
        {
          String showName = "";
          String seasonNum = "";
          String titleString = "";
          Calendar airDate = Calendar.getInstance();
          ;

          try {
            Show show = ShowStore.getShow(this.showName);
            showName = show.getName();

            Season season = show.getSeason(this.seasonNumber);
            if (season == null) {
              seasonNum = String.valueOf(this.seasonNumber);
              logger.log(
                  Level.SEVERE,
                  "Season #" + this.seasonNumber + " not found for show '" + this.showName + "'");
            } else {
              seasonNum = String.valueOf(season.getNumber());

              try {
                titleString = season.getTitle(this.episodeNumber);
                airDate.setTime(season.getAirDate(this.episodeNumber));
              } catch (EpisodeNotFoundException e) {
                logger.log(Level.SEVERE, "Episode not found for '" + this.toString() + "'", e);
              }
            }

          } catch (ShowNotFoundException e) {
            showName = this.showName;
            logger.log(Level.SEVERE, "Show not found for '" + this.toString() + "'", e);
          }

          String newFilename = userPrefs.getRenameReplacementString();

          // Ensure that all special characters in the replacement are quoted
          showName = Matcher.quoteReplacement(showName);
          showName = GlobalOverrides.getInstance().getShowName(showName);
          titleString = Matcher.quoteReplacement(titleString);

          // Make whatever modifications are required
          String episodeNumberString = new DecimalFormat("##0").format(this.episodeNumber);
          String episodeNumberWithLeadingZeros =
              new DecimalFormat("#00").format(this.episodeNumber);
          String episodeTitleNoSpaces = titleString.replaceAll(" ", ".");
          String seasonNumberWithLeadingZero = new DecimalFormat("00").format(this.seasonNumber);

          newFilename = newFilename.replaceAll(ReplacementToken.SHOW_NAME.getToken(), showName);
          newFilename = newFilename.replaceAll(ReplacementToken.SEASON_NUM.getToken(), seasonNum);
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.SEASON_NUM_LEADING_ZERO.getToken(), seasonNumberWithLeadingZero);
          newFilename =
              newFilename.replaceAll(ReplacementToken.EPISODE_NUM.getToken(), episodeNumberString);
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.EPISODE_NUM_LEADING_ZERO.getToken(),
                  episodeNumberWithLeadingZeros);
          newFilename =
              newFilename.replaceAll(ReplacementToken.EPISODE_TITLE.getToken(), titleString);
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.EPISODE_TITLE_NO_SPACES.getToken(), episodeTitleNoSpaces);

          // Date and times
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.DATE_DAY_NUM.getToken(), formatDate(airDate, "d"));
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.DATE_DAY_NUMLZ.getToken(), formatDate(airDate, "dd"));
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.DATE_MONTH_NUM.getToken(), formatDate(airDate, "M"));
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.DATE_MONTH_NUMLZ.getToken(), formatDate(airDate, "MM"));
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.DATE_YEAR_FULL.getToken(), formatDate(airDate, "yyyy"));
          newFilename =
              newFilename.replaceAll(
                  ReplacementToken.DATE_YEAR_MIN.getToken(), formatDate(airDate, "yy"));

          String resultingFilename =
              newFilename.concat(".").concat(StringUtils.getExtension(file.getName()));
          return StringUtils.sanitiseTitle(resultingFilename);
        }
      case BROKEN:
      default:
        return BROKEN_PLACEHOLDER_FILENAME;
    }
  }
Пример #11
0
  /**
   * This is the constructor for objects of the class ChangeReservationDialog
   *
   * @param markedSeats A collection of the seats marked in the room overview
   * @param show The show chosen in the result table
   * @param customerID The phonenumber of the customer
   * @param frame The frame the dialog was called from
   */
  public ChangeReservationDialog(
      ArrayList<Seat> markedSeats, Show show, int customerID, MainFrame frame) {
    super("Reservation");

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    Border standart = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    JPanel north = new JPanel();
    north.setBorder(standart);
    contentPane.add(north, BorderLayout.NORTH);

    JLabel topText =
        new JLabel(
            "Du forsøger at ændre en reservation til en med følgende "
                + markedSeats.size()
                + " sæder til: "
                + show.toString());
    north.add(topText);

    JPanel center = new JPanel();
    center.setLayout(new FlowLayout());
    center.setBorder(standart);
    contentPane.add(center, BorderLayout.CENTER);
    String seatString = "<html>";
    for (Seat s : markedSeats) {
      seatString += s.toString() + "<br>";
    }
    seatString += "</html>";
    JLabel seatText = new JLabel(seatString);
    seatText.setBackground(Color.WHITE);
    center.add(seatText);

    JPanel south = new JPanel();
    south.setLayout(new BorderLayout());
    south.setBorder(standart);
    contentPane.add(south, BorderLayout.SOUTH);

    JPanel phoneSection = new JPanel();
    JLabel costumerText = new JLabel("Kundens telefonnummer: " + customerID);
    phoneSection.add(costumerText);

    JPanel buttons = new JPanel();
    JButton cancel = new JButton("Annuller");
    cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    JButton reserve = new JButton("Ændre");
    reserve.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            String number = "" + customerID;

            if (number.length() == 8) {
              Database.deleteReservations(show, customerID);
              for (Seat s : markedSeats) {
                Database.makeReservation(show, new Customer(Integer.parseInt(number)), s);
              }

              ChangeReservationDialog.this.dispose();
              frame.reset();
            }
          }
        });
    buttons.add(cancel);
    buttons.add(reserve);

    south.add(buttons, BorderLayout.SOUTH);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    pack();
    setVisible(true);
  }
Пример #12
0
 /**
  * Provides a show instance that draws a 2-dimensional representation of a tree.
  *
  * @param s A show instance for the elements of the tree.
  * @return a show instance that draws a 2-dimensional representation of a tree.
  */
 public static <A> Show<Tree<A>> show2D(final Show<A> s) {
   return Show.showS(tree -> tree.draw(s));
 }
Пример #13
0
 @Override
 public String toString() {
   return Show.treeShow(Show.<A>anyShow()).showS(this);
 }
Пример #14
0
 private Stream<String> drawTree(final Show<A> s) {
   return drawSubTrees(s, subForest._1()).cons(s.showS(root));
 }
Пример #15
0
  public void start() {

    List<Show> shows = new ArrayList<Show>(4);

    // SHOW 1
    Show s1 = new Show();
    s1.name = "Family of Four";
    s1.day = Day.SAT;
    s1.runtime = 89;
    s1.isParquet = false;
    s1.is3D = false;
    s1.persons.add(new Person(45, false));
    s1.persons.add(new Person(46, false));
    float c1 = 11f + 2f + 1.5f;
    /* 11 (basic) + 2 (loge) + 1.50 (WE) */
    s1.persons.add(new Person(12, false));
    float c2 = 5.5f + 2f + 1.5f;
    /* 5.50 (basic) + 2 (loge) + 1.50 (WE) */
    s1.persons.add(new Person(21, true));
    float c3 = 8f + 2f + 1.5f;
    /* 8 (basic) + 2 (loge) + 1.50 (WE) */
    s1.totalAdmission = 2 * c1 + c2 + c3;
    shows.add(s1);

    // SHOW 2
    Show s2 = new Show();
    s2.name = "Couple";
    s2.day = Day.THU;
    s2.runtime = 124;
    s2.isParquet = true;
    s2.is3D = false;
    s2.persons.add(new Person(23, false));
    c1 = 11f - 2f + 1.5f;
    /* 11 (basic) - 2 (THU) + 1.5 (over) */
    s2.persons.add(new Person(25, true));
    c2 = 8f - 2f + 1.5f;
    /* 8 (basic) - 2 (THU) + 1.5 (over) */
    s2.totalAdmission = c1 + c2;
    shows.add(s2);

    // SHOW 3
    Show s3 = new Show();
    s3.name = "Senior with Grandson";
    s3.day = Day.FRI;
    s3.runtime = 95;
    s3.isParquet = true;
    s3.is3D = true;
    s3.persons.add(new Person(65, false));
    c1 = 6f + 3f;
    /* 6 (basic) + 3 (3D) */
    s3.persons.add(new Person(6, false));
    c2 = 5.5f + 3f;
    /* 5.5 (basic) + 3 (3D) */
    s3.totalAdmission = c1 + c2;
    shows.add(s3);

    // SHOW 4
    Show s4 = new Show();
    s4.name = "Group of Kids";
    s4.day = Day.SUN;
    s4.runtime = 91;
    s4.isParquet = true;
    s4.is3D = true;
    s4.persons.add(new Person(10, false));
    s4.persons.add(new Person(12, false));
    s4.persons.add(new Person(12, false));
    s4.persons.add(new Person(11, false));
    s4.persons.add(new Person(12, false));
    c1 = 5.5f + 3f + 1.5f;
    /* (for all) = 5.5 (basic) + 3 (3D) + 1.5 (WE) */
    s4.totalAdmission = 5 * c1;
    shows.add(s4);

    // SHOW 5
    Show s5 = new Show();
    s5.name = "Student Course";
    s5.day = Day.THU;
    s5.runtime = 120;
    s5.isParquet = true;
    s5.is3D = false;
    for (int i = 0; i < 22; i++) {
      s5.persons.add(new Person(21 + new Random().nextInt(3), true));
    }
    s5.persons.add(new Person(55, false));
    c1 = 6f; /* 6 (basic) */
    s5.totalAdmission = s5.persons.size() * c1;
    shows.add(s5);

    Collections.shuffle(shows);

    // TESTS
    for (Show s : shows) {

      System.out.println(" ~~ Arriving at your booth: '" + s.name + "' ~~");

      // start ticket purchase
      m_solution.startPurchase(s.runtime, s.day, s.isParquet, s.is3D);

      System.out.println(
          "Today ("
              + s.day
              + ")"
              + " they want to see a "
              + s.runtime
              + " min. long"
              + (s.is3D ? " 3D" : "")
              + " movie"
              + (s.isParquet ? " from the parquet." : " from the loge."));

      // add each ticket
      Collections.shuffle(s.persons);
      for (Person p : s.persons) {
        m_solution.addTicket(p.age, p.isStudent);
        System.out.println(
            " -> "
                + p.age
                + " years old "
                + (!p.isStudent ? "person" : "student")
                + " buys a ticket");
      }

      // finish purchase
      validate(s.totalAdmission, m_solution.finishPurchase(), s.name);
      System.out.print("\n");
    }
  }
Пример #16
0
 public static void main(String[] args) {
   // TODO 自动生成的方法存根
   Show.inFrame(new Table(), 200, 200);
 }
Пример #17
0
 public static void main(String args[]) {
   Show.inFrame(new Menus(), 300, 200);
 }