Пример #1
0
  private List<Feature> getMatchingEntries(
      String ngram, Model model, int index, boolean useInstanceBasedFeatures) {
    List<Feature> matchingFeatures = new ArrayList<Feature>();
    // List<CCGLexEntry> entries = new ArrayList<CCGLexEntry>();

    if (ngram.equals("")) {
      return matchingFeatures;
    }

    if (ngram.equals("countries")) {
      int z = 1;
    }

    if (useInstanceBasedFeatures) {
      matchingFeatures = model.getEntriesforLexeme(ngram, -1);
      if (matchingFeatures == null) {
        matchingFeatures = model.getEntriesforLexeme(ngram, index);
      } else {
        // add non defined features too
        List<Feature> matchingFeaturesWithIndex = model.getEntriesforLexeme(ngram, index);
        if (matchingFeaturesWithIndex != null) {
          for (Feature f : matchingFeaturesWithIndex) {
            if (!matchingFeatures.contains(f)) {
              matchingFeatures.add(f);
            }
          }
        }
      }

    } else {
      matchingFeatures = model.getEntriesforLexeme(ngram, true);
    }

    return matchingFeatures;
  }
Пример #2
0
  // Based on our latest design, we default to today's date in every case. One record per day per
  // user is expected
  // The Save method doesn't refresh the data. Need to re-query in factory
  public void Save() {
    String sqlStatement = "";

    if (!IsLoaded) {
      sqlStatement =
          "INSERT INTO `java`.`WeekDay` "
              + "( "
              + "`DateCreated`,"
              + "`AppUserId`)"
              + "VALUES"
              + "("
              + " Now()," // "'" + dateCreated + "',"
              + ""
              + appUserId
              + ")";
    } else {
      sqlStatement =
          "UPDATE `java`.`Weekday` SET "
              + "`DateCreated` = Now(), " // '" + dateCreated + "',"
              + "`AppUserId` = "
              + appUserId
              + "WHERE `WeekDayID` = "
              + weekDayId;
    }

    try {
      super.executeInsertUpdateDeleteQuery(sqlStatement);

      super.closeConnection();
    } catch (SQLException ex) {
      Logger.getLogger(MealModel.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Пример #3
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String s1 = request.getParameter("s1");
    // String pass2=request.getParameter("pass2");
    HttpSession session = request.getSession();

    String uname = (String) session.getAttribute("uname");
    Model m = new Model();

    m.setS1(s1);
    //	m.setUname(uname);

    String sql = "delete from register where username=?";
    boolean st = Dao.DeleteUser(m, sql);

    if (st) {
      String msg1 = "Password Changed Successfully.. Login with your new Password";
      request.setAttribute("msg", msg1);
      getServletContext().getRequestDispatcher("/AdminMain.jsp").forward(request, response);

    } else {
      String msg1 = "Password Not Changed";
      request.setAttribute("msg", msg1);
      getServletContext().getRequestDispatcher("/AdminLogin.jsp").forward(request, response);
    }
  }
Пример #4
0
 @Override
 public double evaluate(Model model) {
   int pos = (int) getInputValueOne(model);
   String bgColor = handleSet(model).get(pos);
   model.setBackgroundColor(bgColor);
   model.setBackgroundChanged(true);
   return getInputValueOne(model);
 }
Пример #5
0
 public static void main(String[] args) throws IOException {
   Model model = new Model(); // Initialize model
   controller controller = new controller(model); // Initialize controller
   View view = new View(); // Initialize view
   controller.setVistaRef(view);
   view.fijarControlador(controller);
   view.arranca(); // Show view
   model.addObserver(view);
 }
Пример #6
0
 private void sendWinner() {
   Candidate winner = model.getWinner();
   writeMessage(13, winner.getCandidateNumber()); // Writes out the winner
   boolean isClosest = model.winnerIsClosest(player.getIdealPt(), winner);
   try {
     out.writeBoolean(isClosest);
   } catch (IOException e) {
     removePlayer();
   }
 }
Пример #7
0
 public void updateStatusLamaran(int id, boolean accepted) {
   String status = accepted ? "accept" : "reject";
   String query =
       String.format("UPDATE %s SET status='%s' WHERE id=%s", this.TABLE_NAME, status, id);
   super.openConnection();
   try {
     super.getStatement().executeUpdate(query);
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
 }
Пример #8
0
 public void cregPelamar(int id_lowongan, String username) {
   super.openConnection();
   String query =
       String.format(
           "INSERT INTO %s (id_lowongan, username, jenis) VALUES ('%s','%s','%s')",
           TABLE_NAME, id_lowongan, username, "close");
   try {
     super.getStatement().executeUpdate(query);
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
 }
Пример #9
0
 /**
  * menambahkan user baru
  *
  * @param username
  * @param password
  */
 public void insertUser(String username, String password) {
   super.openConnection();
   String query =
       String.format(
           "INSERT INTO %s(username, password) VALUES ('%s', '%s')",
           TABLE_NAME, username, password);
   openConnection();
   try {
     super.getStatement().executeUpdate(query);
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
 }
Пример #10
0
  public OverviewList(final Model model, final DefaultListModel<? extends Namable> listModel) {
    super((ListModel<Namable>) listModel);

    this.model = model;
    model.addObserver(this);

    this.setOpaque(true);
    this.setFocusable(false);
    this.setCellRenderer(
        new ListCellRenderer<Namable>() {
          @Override
          public Component getListCellRendererComponent(
              JList<? extends Namable> list,
              Namable value,
              int index,
              boolean isSelected,
              boolean cellHasFocus) {
            final JLabel label = new JLabel(value.getName(), JLabel.CENTER);
            label.setOpaque(true);

            if (isSelected) label.setBackground(Color.GREEN);
            else if (index >= 0) {
              final Point p = list.getMousePosition();
              if (p != null && list.locationToIndex(p) == index) label.setBackground(Color.ORANGE);
            }

            return label;
          }
        });
  }
Пример #11
0
  public int getCurrentIdByUserId(Integer userId) throws SQLException {
    int result = 0;

    String sqlStatement =
        "select * from WeekDay where Date(DateCreated) = Date(Now()) And AppUserId = "
            + userId.toString()
            + " Limit 1";
    setData(super.executeSelectQuery(sqlStatement));

    if (getData().isBeforeFirst()) {
      getData().next();
      result = getData().getInt("WeekDayId");
      weekDayId = getData().getInt("WeekDayId");
      dateCreated = getData().getDate("DateCreated");
      appUserId = getData().getInt("AppUserId");

      IsLoaded = true;
    } else {
      IsLoaded = false;
    }

    super.closeConnection();

    return result;
  }
Пример #12
0
  public Window(Model model) {
    super("Chess game\t\t\t" + model.getCurrentPlayer().getName());
    this.model = model;

    // Create window content
    this.menuBar = new MenuBar(this);
    this.content = new Content(this, model);

    // Add window content
    this.setJMenuBar(menuBar);
    this.setContentPane(content);

    // Set window properties
    this.pack();
    this.setResizable(false);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    BufferedImage image = null;
    URL url = null;
    url = getClass().getResource("/view/pieces/iconJC.png");
    try {
      image = ImageIO.read(url);
      setIconImage(image);
    } catch (IOException e) {

    }
    // Display
    this.setVisible(true);
  }
Пример #13
0
 private void startSecondBuy() {
   try {
     ArrayList<Candidate> candidates = model.getSortedCandidates();
     writeMessage(10, candidates.size());
     out.writeByte(1);
     int numPlayers = model.getNumPlayers();
     for (Candidate candidate : candidates) { // This writes the top candidates
       out.writeByte(candidate.getCandidateNumber());
       int numVotes = candidate.getFirstVotes();
       int percentVotes = ((numVotes * 100) / numPlayers);
       out.writeInt(percentVotes);
     }
   } catch (IOException e) {
     removePlayer();
   }
 }
Пример #14
0
 public Pelamar getPelamarByUsername(String username) {
   super.openConnection();
   String query = String.format("SELECT * FROM %s where username='******' ", TABLE_NAME, username);
   try {
     ResultSet res = super.getStatement().executeQuery(query);
     // selama masih ada baris yang bisa dibaca
     res.next();
     Pelamar a =
         new Pelamar(
             res.getInt("id"),
             res.getInt("id_lowongan"),
             res.getString("username"),
             res.getInt("id_cv"),
             res.getString("jenis"),
             res.getString("status"),
             res.getString("created_at"),
             res.getString("updated_at"));
     return a;
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
   return null;
 }
Пример #15
0
 public ArrayList<Pelamar> selectPelamarJenisStatus(int id_lowongan, String jenis, String status) {
   super.openConnection();
   String query =
       String.format(
           "SELECT * FROM %s where id_lowongan ='%s' AND jenis='%s' AND status='%s' ",
           TABLE_NAME, id_lowongan, jenis, status);
   ArrayList<Pelamar> result = new ArrayList<Pelamar>();
   try {
     ResultSet res = super.getStatement().executeQuery(query);
     // selama masih ada baris yang bisa dibaca
     while (res.next()) {
       Pelamar a =
           new Pelamar(
               res.getInt("id"),
               res.getInt("id_lowongan"),
               res.getString("username"),
               res.getInt("id_cv"),
               res.getString("jenis"),
               res.getString("status"),
               res.getString("created_at"),
               res.getString("updated_at"));
       result.add(a);
     }
     return result;
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
   return null;
 }
Пример #16
0
  /**
   * This method takes an event, and sends the appropriate commands to the model based on the
   * command that the event sends:
   *
   * @param event an actionEvent representing an instruction from the View.
   */
  public void actionPerformed(ActionEvent event) {
    gameBoard = Board.getBoard();
    gameInfo = GameInfoPanel.getGameInfo();

    String actionCommand = event.getActionCommand();

    // play button commands
    if (actionCommand.equals("play")) {
      /** this is passed in as an ActionListener */
      if (!hasStarted) {
        makeGameThread();
        waitTime = DEFAULT_RUN;
        hasStarted = true;
        isFinished = model.isFinished();
      } else {
        paused = false;
        waitTime = DEFAULT_RUN;
      }
    }

    // fastforward button commands
    if (actionCommand.equals("fastForward")) {
      paused = false;
      waitTime = FAST_FORWARD;
    }

    // fastforwardX2 button commands
    if (actionCommand.equals("fastForwardX2")) {
      paused = false;
      waitTime = DOUBLE_FAST_FORWARD;
    }

    // pause button commands (pause game until user runs some sort of play
    if (actionCommand.equals("pause")) {
      paused = true;
    }

    // stop game
    if (actionCommand.equals("stop")) {
      gameStopped = true;
    }

    // handle stepback button
    if (actionCommand.equals("home")) {
      JOptionPane.showMessageDialog(
          null,
          "This button does not work at this time, sorry.",
          "ERROR",
          JOptionPane.WARNING_MESSAGE);
    }
    // handle stepback button
    if (actionCommand.equals("stepback")) {
      JOptionPane.showMessageDialog(
          null,
          "This button does not work at this time, sorry.",
          "ERROR",
          JOptionPane.WARNING_MESSAGE);
    }
  }
Пример #17
0
 public void handleIO() {
   waitForGameStart();
   startGame();
   while (true) {
     try {
       char c = (char) in.readByte();
       while (c != '!') {
         c = (char) in.readByte();
       }
       int messageType = in.readByte();
       if (messageType == 5) { // Bought info
         returnInfo();
       } else if (messageType == 7) { // Ended a buy round
         int whichBuyRound = in.readByte();
         waitForNewRound(); // Waits for all players to be done with the round
         setRound(whichBuyRound); // Sets the round in the player's data
         startRound(whichBuyRound); // Sends out a starting round message
       } else if (messageType == 9) {
         voteForCandidate();
         waitForNewRound();
         if (player.getRound() == "straw") {
           startFirstVote();
         } else if (player.getRound() == "first") {
           startSecondBuy();
         } else {
           sendWinner();
           Player clone = new Player(player);
           model.addPlayerToGameObject(clone, gameNum);
           gameNum++;
           if (gameNum < model.getNumGames()) {
             model.getNewGame(gameNum);
             model.resetPlayer(player);
             startGame();
           } else {
             model.writeDataOut();
           }
         }
       } else {
         // Exceptions?
       }
     } catch (IOException e) {
       removePlayer();
       break; // End client
     }
   }
 }
Пример #18
0
  public RequestTable(Model model, Controller controller) {
    super(model, controller);

    initComponents();
    arrangeComponents();

    model.addObserver(this);
  }
Пример #19
0
 private void startFirstVote() {
   try {
     ArrayList<Candidate> candidates = model.getCandidates();
     player.setRound("first");
     writeMessage(10, candidates.size());
     out.writeByte(0);
     int numPlayers = model.getNumPlayers();
     for (Candidate candidate : candidates) {
       out.writeByte(candidate.getCandidateNumber());
       int numVotes = candidate.getStrawVotes();
       int percentVotes = ((numVotes * 100) / numPlayers);
       out.writeInt(percentVotes);
     }
   } catch (IOException e) {
     removePlayer();
   }
 }
Пример #20
0
 private void voteForCandidate() {
   try {
     int candidateToVoteFor = in.readByte();
     if (player.getRound() == "first") {
       model.getCandidate(candidateToVoteFor).voteFirst();
       player.addVote(candidateToVoteFor, 1);
     } else if (player.getRound() == "final") {
       model.getCandidate(candidateToVoteFor).voteSecond();
       player.addVote(candidateToVoteFor, 2);
     } else {
       model.getCandidate(candidateToVoteFor).voteStraw();
       player.addVote(candidateToVoteFor, 0);
     }
   } catch (IOException e) {
     removePlayer();
   }
 }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    Model model = new Model();

    String order = null;
    order = request.getParameter("placeOrder");

    System.out.println(order);

    if (order != null) {
      model.calculateOrder(request);
      request.setAttribute("orderSubTotal", model.getOrderSubTotal());
      request.setAttribute("orderGrandTotal", model.getOrderGrandTotal());
      request.setAttribute("tax", model.getTax());
      request.setAttribute("menu", model.getMenuSelection());
      RequestDispatcher view = request.getRequestDispatcher("Bill.jsp");

      view.forward(request, response);
    } else {
      HashMap<String, String> menu = model.getMenuOptions();

      request.setAttribute("menu", menu);
      RequestDispatcher view = request.getRequestDispatcher("MenuCheckboxes.jsp");

      view.forward(request, response);
    }
  }
 @BeforeClass
 public static void setUpClass() {
   try {
     Model.conectar();
   } catch (SQLException ex) {
     ex.printStackTrace();
     Logger.getLogger(CydeColombiaJUnitTest.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
  /* (non-Javadoc)
   * @see controller.Command#doCommand(java.lang.String, view.View, model.Model)
   */
  @Override
  public void doCommand(String args, View v, Model m) {

    String[] s = args.split(" ");
    char crossBy = s[0].charAt(0);
    int index = Integer.parseInt(s[1]);
    String name = s[2];
    int[][] cs = m.getCrossSection(crossBy, index, name);
    v.displayCrossSection(cs);
  }
Пример #24
0
 /**
  * untuk edit user password
  *
  * @param username
  * @param password
  */
 public void editUser(String username, String password) {
   super.openConnection();
   String query =
       "UPDATE "
           + TABLE_NAME
           + " SET password='******' WHERE username='******'";
   openConnection();
   try {
     super.getStatement().executeUpdate(query);
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
 }
Пример #25
0
 public ResourceStd1Data(String projectRef) {
   this.projectRef = projectRef;
   String projNum = Model.getInstance().getProject(projectRef).getProjectNumber();
   prefs = Main.getProjPrefName().node(projNum).node("resources");
   //            try {
   values = setValues(null);
   //            }catch (Exception e){
   //                throw new Exception("Unable to set value for resourceStd1Data
   // "+e.getMessage());
   //            }
 }
Пример #26
0
 private void startGame() {
   try {
     writeMessage(0, player.getPlayerNumber());
     out.writeChar(player.getParty());
     out.writeInt(player.getIdealPt());
     out.writeInt(model.getBudget());
   } catch (IOException e1) {
     removePlayer();
   }
   writeChartData();
   ArrayList<Candidate> candidates = model.getCandidates();
   writeMessage(2, candidates.size());
   for (int i = 0; i < candidates.size(); i++) {
     try {
       out.writeByte(candidates.get(i).getCandidateNumber());
       out.writeByte(candidates.get(i).getParty());
     } catch (IOException e) {
       removePlayer();
     }
   }
 }
Пример #27
0
 private void writeChartData() {
   int[] chartData = model.getData();
   try {
     out.writeByte((int) '!');
     out.writeByte(1);
     for (int i = 0; i < 4; i++) {
       out.writeInt(chartData[i]);
     }
   } catch (IOException e) {
     removePlayer();
   }
 }
Пример #28
0
 private void waitForGameStart() {
   synchronized (waitObject) {
     if (!model.getStartGame()) {
       try {
         waitObject.wait();
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
     waitObject.notifyAll();
   }
 }
Пример #29
0
 private void waitForNewRound() {
   player.doneWithRound();
   synchronized (waitObject) {
     if (!model.checkEndRound()) {
       try {
         waitObject.wait();
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
     waitObject.notifyAll();
   }
   player.newRound();
 }
Пример #30
0
 public void deletePelamar(int id_lowongan, String username) {
   String query =
       String.format(
           "DELETE FROM %s WHERE id_lowongan='%s' AND username='******'",
           TABLE_NAME, id_lowongan, username);
   openConnection();
   try {
     super.getStatement().executeUpdate(query);
   } catch (SQLException ex) {
     Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     closeConnection();
   }
 }