Ejemplo n.º 1
0
  public void update() {
    infoPanel.update();

    Object[][] history = new Object[account.getHistory().size()][5];
    int i = 0;
    for (Transaction t : account.getHistory()) {
      history[i][0] = t.getType();
      BigDecimal amount;
      BigDecimal balance;
      if (account.getType().isLoan()) {
        amount = (t.getType().isPositive() ? t.getAmount().negate() : t.getAmount());
        balance = t.getBalance().negate();
      } else {
        amount = (t.getType().isPositive() ? t.getAmount() : t.getAmount().negate());
        balance = t.getBalance();
      }
      history[i][1] = FORMATTER.valueToString(amount);
      history[i][2] = FORMATTER.valueToString(balance);
      history[i][3] = t.getTimestamp();
      history[i][4] = t.getFraudStatus();
      i++;
    }
    historyTable.setModel(
        new javax.swing.table.DefaultTableModel(
            history, new String[] {"Type", "Amount", "Balance", "Month", "Flag"}) {
          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
          }
        });
    historyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    historyTable.revalidate();
  }
Ejemplo n.º 2
0
 void transact(LinkedList<Transaction> transactions) {
   for (Transaction t : transactions) {
     Player p = getServer().getPlayer(t.getName());
     if (p != null) {
       getBank().give(p, t.getAmount(), t.getType());
     }
   }
 }
  @Override
  public Void call() throws Exception {
    try {
      LOG.debug("Batched SyncRequestProcessor gets started.");
      MessageTuple lastReq = null;
      // Number of transactions batched so far.
      int batchCount = 0;

      while (true) {
        MessageTuple req;
        if (lastReq == null) {
          req = this.proposalQueue.take();
        } else {
          req = this.proposalQueue.poll();
          if (req == null || batchCount == maxBatchSize || req == MessageTuple.REQUEST_OF_DEATH) {
            // Sync to disk and send ACK to leader.
            this.log.sync();
            Zxid zxid = MessageBuilder.fromProtoZxid(lastReq.getMessage().getProposal().getZxid());
            sendAck(lastReq.getServerId(), zxid);
            batchCount = 0;
          }
        }
        if (req == MessageTuple.REQUEST_OF_DEATH) {
          break;
        }
        if (req == null) {
          lastReq = null;
          continue;
        }
        if (req.getMessage().getType() == MessageType.PROPOSAL) {
          // It's PROPOSAL, sync to disk.
          Message msg = req.getMessage();
          Transaction txn = MessageBuilder.fromProposal(msg.getProposal());
          // TODO : avoid this?
          ByteBuffer body = txn.getBody().asReadOnlyBuffer();
          LOG.debug("Syncing transaction {} to disk.", txn.getZxid());
          this.log.append(txn);
          batchCount++;
          lastReq = req;
          if (txn.getType() == ProposalType.COP_VALUE) {
            // If it's COP, we should also update cluster_config file.
            ClusterConfiguration cnf = ClusterConfiguration.fromByteBuffer(body, this.serverId);
            persistence.setLastSeenConfig(cnf);
            // If it's COP, we shouldn't batch it, send ACK immediatly.
            sendAck(req.getServerId(), txn.getZxid());
            batchCount = 0;
            lastReq = null;
          }
        }
      }
    } catch (Exception e) {
      LOG.error("Caught an exception in SyncProposalProcessor", e);
      throw e;
    }
    LOG.debug("SyncProposalProcessor has been shut down.");
    return null;
  }
Ejemplo n.º 4
0
 @Override
 public JsonElement serialize(
     Transaction transaction, Type type, JsonSerializationContext jsonSerializationContext) {
   final JsonObject jo = new JsonObject();
   jo.addProperty("amount", transaction.getAmount());
   jo.addProperty("type", transaction.getType());
   if (transaction.getParent() != null) {
     jo.addProperty("parent", transaction.getParent().getId());
   }
   return jo;
 }
    @Test
    public void nemesisTransactionsHaveCorrectFees() {
      // Arrange:
      final Block block = this.loadNemesisBlock();

      // Assert:
      for (final Transaction transaction : block.getTransactions()) {
        final Amount expectedFee =
            TransactionTypes.TRANSFER == transaction.getType()
                ? Amount.ZERO
                : NemGlobals.getTransactionFeeCalculator().calculateMinimumFee(transaction);
        Assert.assertThat(transaction.getFee(), IsEqual.equalTo(expectedFee));
      }
    }
Ejemplo n.º 6
0
 public static void createTransaction(Transaction transaction) throws ParseException {
   try {
     String query =
         "insert into transaction_table(business_id, transaction_id, type, category, description, amount, transaction_date, account_balance) values (?,?,?,?,?,?,?,?)";
     PreparedStatement preparedStatement = connection.prepareStatement(query);
     preparedStatement.setInt(1, 1);
     preparedStatement.setInt(2, transaction.getId());
     preparedStatement.setBoolean(3, transaction.getType());
     preparedStatement.setString(4, transaction.getCategory());
     preparedStatement.setString(5, transaction.getDescription());
     preparedStatement.setFloat(6, transaction.getAmount());
     preparedStatement.setString(7, transaction.getTransactionDate());
     preparedStatement.setFloat(8, transaction.getAccountBalance());
     preparedStatement.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 7
0
 public static void updateTransaction(Transaction transaction) throws ParseException {
   try {
     String query =
         "update transaction_table set type=?, category=?, description=?, amount=?, transaction_date=?, account_balance=? where transaction_id=?";
     PreparedStatement preparedStatement = connection.prepareStatement(query);
     preparedStatement.setInt(1, 1);
     preparedStatement.setInt(2, transaction.getId());
     preparedStatement.setBoolean(3, transaction.getType());
     preparedStatement.setString(4, transaction.getCategory());
     preparedStatement.setString(5, transaction.getDescription());
     preparedStatement.setFloat(6, transaction.getAmount());
     preparedStatement.setString(7, transaction.getTransactionDate());
     preparedStatement.setFloat(8, transaction.getAccountBalance());
     preparedStatement.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 8
0
  public static void ExportPortfolios() throws FileNotFoundException, UnsupportedEncodingException {
    String filename = "xp.txt";
    Iterator it = users.entrySet().iterator();
    PrintWriter writer = new PrintWriter(filename, "UTF-8");
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();

      writer.print(pair.getKey() + "|" + encrypt((String) pair.getValue()));
      writer.print("|");
      Portfolio p = portfolios.get(pair.getKey());
      Map<String, Integer> equitiess = p.getEquities();
      Iterator it1 = equitiess.entrySet().iterator();
      while (it1.hasNext()) {
        Map.Entry e = (Map.Entry) it1.next();
        writer.print("e," + e.getKey() + "," + e.getValue() + "|");
      }
      Map<String, Account> accountss = p.getAccounts();
      Iterator it2 = accountss.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry a = (Map.Entry) it2.next();
        Date d = ((Account) a.getValue()).getDateAdded();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
        String da = sdf.format(d);
        writer.print(
            "a,"
                + ((Account) a.getValue()).getType()
                + ","
                + ((Account) a.getValue()).getName()
                + ","
                + (((Account) a.getValue()).getInitialAmount()
                    + ","
                    + (((Account) a.getValue()).getCurrentAmount())
                    + ","
                    + da
                    + "|"));
      }
      for (Transaction tr : p.getTrans()) {
        if (tr.getType().equals("t")) {
          Date d = tr.getDate();
          SimpleDateFormat sdf =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
          String da = sdf.format(d);
          writer.print(
              "t," + tr.getA1() + "," + tr.getA2() + "," + tr.getAmount() + "," + da + "|");
        } else {
          Date d = tr.getDate();
          SimpleDateFormat sdf =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
          String da = sdf.format(d);
          writer.print(
              tr.getType()
                  + ","
                  + tr.getEquity().getTicker()
                  + ","
                  + tr.getNumber()
                  + ","
                  + tr.getA1()
                  + da
                  + "|");
        }
      }
      writer.println();
    }
    writer.close();
  }