Exemple #1
1
 void sortTransactionByDate() {
   List<Transaction> tr = new ArrayList<Transaction>(transactions.values());
   tr.sort(Transaction.DateComparator);
   for (Transaction t : tr) {
     t.displayTransaction();
   }
 }
  @Test(groups = "dev")
  public void sinkSingleModelTest() throws EventDeliveryException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.single.name());

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    JSONObject msg = new JSONObject();
    msg.put("name", "test");
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());

    Event e = EventBuilder.withBody(msg.toJSONString().getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_events");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get("name"), msg.get("name"));
    assertEquals(dbObject.get("age"), msg.get("age"));
    assertEquals(dbObject.get("birthday"), msg.get("birthday"));
  }
Exemple #3
0
 public List<User> getUserSearchResults(int topicId) {
   // TODO Auto-generated method stub
   List<User> userArr = new ArrayList<User>();
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     Query query1 = session.createQuery("select userId from UserTopic where topicId = :topicId");
     query1.setString("topicId", String.valueOf(topicId));
     Query query2 = session.createQuery("from User where userId in (:userList)");
     query2.setParameterList("userList", query1.list());
     userArr = query2.list();
     /*for(Topic topic : topicArr){
     	System.out.println("Topic Description----"+topic.getTopicDescription());
     	System.out.println("Topic Id----"+topic.getTopicId());
     }*/
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
   return userArr;
 }
Exemple #4
0
  @Override
  public void saveEventDetails(Event event) {
    // TODO Auto-generated method stub

    // Opening a session to create a database connection
    Session session = this.sessionFactory.openSession();

    // for CRUD operations, we need to create a transaction
    Transaction tx = null;

    // adding a try catch block for maintaining the atomicity of transaction
    try {
      tx = session.beginTransaction();
      System.out.println("DbHelper..saveEventDetails");

      // session save inserts the object into DB
      session.save(event);

      tx.commit();
      System.out.println("Event saved");
    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
        e.printStackTrace();
      }
    } finally {
      session.close();
    }
  }
Exemple #5
0
 @Override
 public void deleteSubscription(int userId, int forumId) {
   // TODO Auto-generated method stub
   Session session = this.sessionFactory.openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     Query query =
         session.createQuery(
             "delete from Subscription where userId = :userId and forumId = :forumId");
     query.setParameter("userId", userId);
     query.setParameter("forumId", forumId);
     int result = query.executeUpdate();
     System.out.println("Execute query..");
     if (result > 0) {
       tx.commit();
       // System.out.println("Subscription Removed..");
     } else {
       // System.out.println("Subscription does not exist");
       tx.rollback();
     }
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
 }
 @Override
 public synchronized boolean deleteTransaction(Sha256Hash transactionId) {
   TransactionEx tex = _backing.getTransaction(transactionId);
   if (tex == null) return false;
   Transaction tx = TransactionEx.toTransaction(tex);
   _backing.beginTransaction();
   try {
     // See if any of the outputs are stored locally and remove them
     for (int i = 0; i < tx.outputs.length; i++) {
       TransactionOutput output = tx.outputs[i];
       OutPoint outPoint = new OutPoint(tx.getHash(), i);
       TransactionOutputEx utxo = _backing.getUnspentOutput(outPoint);
       if (utxo != null) {
         _backing.deleteUnspentOutput(outPoint);
       }
     }
     // remove it from the backing
     _backing.deleteTransaction(transactionId);
     _backing.setTransactionSuccessful();
   } finally {
     _backing.endTransaction();
   }
   updateLocalBalance(); // will still need a new sync besides re-calculating
   return true;
 }
Exemple #7
0
  public void rn() throws IOException {
    List<RoadLink> links = loadToDatabase("/Users/duduba/gj.mif", "/Users/duduba/gj.mid", false);

    GraphDatabaseService graphDb = neo.getDb();
    Index<Node> nodeIndex = neo.getNodeIndex();

    for (RoadLink link : links) {
      Transaction tx = graphDb.beginTx();
      try {

        Node fromNode = nodeIndex.get("id", link.fromNode).getSingle();
        if (fromNode == null) {
          fromNode = graphDb.createNode();
          fromNode.setProperty("id", link.fromNode);
          nodeIndex.add(fromNode, "id", link.fromNode);
        }
        Node toNode = nodeIndex.get("id", link.toNode).getSingle();
        if (toNode == null) {
          toNode = graphDb.createNode();
          toNode.setProperty("id", link.toNode);
          nodeIndex.add(toNode, "id", link.toNode);
        }

        Relationship r = fromNode.createRelationshipTo(toNode, Neo.RelTypes.TO);
        r.setProperty("no", link.no);
        r.setProperty("name", link.name);

        tx.success();
      } finally {
        tx.finish();
      }
    }
    logger.debug("haha, it's ok!");
  }
 private static Block createGenesis(NetworkParameters n) {
   Block genesisBlock = new Block(n);
   Transaction t = new Transaction(n);
   try {
     // A script containing the difficulty bits and the following message:
     //
     //   "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
     byte[] bytes =
         Utils.HEX.decode(
             "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73");
     t.addInput(new TransactionInput(n, t, bytes));
     ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
     Script.writeBytes(
         scriptPubKeyBytes,
         Utils.HEX.decode(
             "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
     scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
     t.addOutput(new TransactionOutput(n, t, FIFTY_COINS, scriptPubKeyBytes.toByteArray()));
   } catch (Exception e) {
     // Cannot happen.
     throw new RuntimeException(e);
   }
   genesisBlock.addTransaction(t);
   return genesisBlock;
 }
Exemple #9
0
  public User getUser(String username) {
    User result = null;
    Session session;
    Object user;
    session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = null;
      user = null;
      try {
        transaction = session.beginTransaction();
        Query query =
            session.createQuery("from User as user where user.userName='******'");
        user = query.uniqueResult();
        transaction.commit();
      } catch (HibernateException e) {
        transaction.rollback();
        e.printStackTrace();
      }

      if (user != null) {
        result = (User) user;
      }
    } finally {
      if (session.isOpen()) {
        if (session.isOpen()) {
          session.disconnect();
          session.close();
        }
      }
    }
    return result;
  }
Exemple #10
0
 public List<Activity> getActivities(Event parent) {
   List<Activity> result = new ArrayList<Activity>();
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     Object event =
         session
             .createQuery("from Event as event where event.idevent= " + parent.getIdevent())
             .uniqueResult();
     transaction.commit();
     if (event != null) {
       Event eventEntity = (Event) event;
       Collection<Activity> activityList = eventEntity.getActivities();
       for (Activity activity : activityList) {
         result.add(activity);
       }
     }
   } finally {
     if (session.isOpen()) {
       session.flush();
       session.disconnect();
       session.close();
     }
   }
   return result;
 }
Exemple #11
0
  public Location getLocation(int id) {
    Location result = null;
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      Object o =
          session
              .createQuery("from Location as location where location.idlocation = " + id)
              .uniqueResult();

      transaction.commit();
      if (o != null) {
        if (o instanceof Location) {
          Location location = (Location) o;
          result = new Location();
          result.setName(location.getName());
          result.setIdlocation(location.getIdlocation());
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
Exemple #12
0
  public ClassificationValue getClassification(String value) {
    ClassificationValue result = null;
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();

      Object o =
          session
              .createQuery(
                  "from ClassificationValue as classificationValue where classificationValue.value like '"
                      + value
                      + "'")
              .uniqueResult();

      transaction.commit();
      if (o != null) {
        if (o instanceof ClassificationValue) {
          result = (ClassificationValue) o;
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
Exemple #13
0
  public Location getLocation(String s) {
    Location result = null;
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      Object o =
          session
              .createQuery("from Location as location where location.name like '" + s + "'")
              .uniqueResult();

      transaction.commit();
      if (o != null) {
        if (o instanceof Location) {
          result = (Location) o;
        }
      }
    } finally {
      if (session.isOpen()) {
        session.flush();
        session.disconnect();
        session.close();
      }
    }
    return result;
  }
Exemple #14
0
  public List<Team> getTeams() {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    List result = null;
    try {
      Transaction transaction = session.beginTransaction();
      result = session.createQuery("from Team").list();
      session.flush();
      transaction.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    } finally {
      if (session.isOpen()) {
        session.close();
      }
    }

    List<Team> teams = new ArrayList<Team>();
    for (Object o : result) {
      if (o instanceof Team) {
        teams.add((Team) o);
      }
    }

    return teams;
  }
  @Test(groups = "dev")
  public void autoWrapTest() throws EventDeliveryException {
    ctx.put(MongoSink.AUTO_WRAP, Boolean.toString(true));
    ctx.put(MongoSink.DB_NAME, "test_wrap");

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    String msg =
        "2012/10/26 11:23:08 [error] 7289#0: *6430831 open() \"/usr/local/nginx/html/50x.html\" failed (2: No such file or directory), client: 10.160.105.161, server: sg15.redatoms.com, request: \"POST /mojo/ajax/embed HTTP/1.0\", upstream: \"fastcgi://unix:/tmp/php-fpm.sock:\", host: \"sg15.redatoms.com\", referrer: \"http://sg15.redatoms.com/mojo/mobile/package\"";

    Event e = EventBuilder.withBody(msg.getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_wrap");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(MongoSink.DEFAULT_WRAP_FIELD, msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get(MongoSink.DEFAULT_WRAP_FIELD), msg);
    mongo.dropDatabase("test_wrap");
  }
Exemple #16
0
  public boolean createUser(User user) {
    boolean result = false;
    if (user.getEmployeeId() != null) {
      User userById = getUserByEmployeeId(user.getEmployeeId());
      if (userById != null) {
        MessageUtils.createMessage("Brugeren eksisterer allerede.");
        return false;
      }
    }
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    try {
      session.saveOrUpdate(user);
      result = true;
      session.flush();
      transaction.commit();
    } catch (StaleObjectStateException sose) {
      System.out.println("StaleObjectException");
      transaction.rollback();
    } catch (HibernateException e) {
      e.printStackTrace();
      transaction.rollback();
      result = false;
    } finally {
      if (session.isOpen()) {
        session.close();
      }
    }

    return result;
  }
  private static List<Double> getWeightVectorForClass(
      Map<String, List<LinkedHashMap<String, Object>>> documents,
      String key,
      List<Integer> featureIndexList,
      GraphDatabaseService db) {
    List<Double> weightVector;

    Transaction tx = db.beginTx();
    // Get class id
    Long classId =
        db.findNodesByLabelAndProperty(DynamicLabel.label("Class"), "name", key)
            .iterator()
            .next()
            .getId();

    // Get weight vector for class
    List<Long> longs =
        documents
            .get(key)
            .stream()
            .map(a -> ((Integer) a.get("feature")).longValue())
            .collect(Collectors.toList());

    weightVector =
        featureIndexList
            .stream()
            .map(i -> longs.contains(i.longValue()) ? tfidf(db, i.longValue(), classId) : 0.0)
            .collect(Collectors.toList());
    tx.success();
    tx.close();
    return weightVector;
  }
Exemple #18
0
  public ActivityPartnerRequest getPartnerRequest(User user, Activity activity) {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List result =
          session
              .createQuery(
                  "from ActivityPartnerRequest as partnerrequest "
                      + "where partnerrequest.idactivity="
                      + activity.getIdactivity()
                      + " and partnerrequest.iduser="
                      + user.getIduser())
              .list();
      transaction.commit();

      if (result != null && result.size() > 0) {
        return (ActivityPartnerRequest) result.get(0);
      }
    } finally {
      if (session.isOpen()) {
        session.disconnect();
        session.close();
      }
    }
    return null;
  }
  /** {@inheritDoc} */
  @Override
  public void txEnd(GridCacheTx tx, boolean commit) throws GridException {
    init();

    Session ses = tx.removeMeta(ATTR_SES);

    if (ses != null) {
      Transaction hTx = ses.getTransaction();

      if (hTx != null) {
        try {
          if (commit) {
            ses.flush();

            hTx.commit();
          } else hTx.rollback();

          if (log.isDebugEnabled())
            log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
        } catch (HibernateException e) {
          throw new GridException(
              "Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e);
        } finally {
          ses.close();
        }
      }
    }
  }
Exemple #20
0
 public void savePartnerRequest(ActivityPartnerRequest activityPartnerRequest) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     List result =
         session
             .createQuery(
                 "from ActivityPartnerRequest as partnerrequest "
                     + "where partnerrequest.idactivity="
                     + activityPartnerRequest.getIdactivity()
                     + " and partnerrequest.iduser="
                     + activityPartnerRequest.getIduser())
             .list();
     transaction.commit();
     if (result != null && result.size() > 0) {
       Session session1 = SessionFactoryUtil.getInstance().getCurrentSession();
       Transaction transaction1 = session1.beginTransaction();
       for (Object o : result) {
         session1.delete(o);
       }
       transaction1.commit();
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   saveObject(activityPartnerRequest);
 }
 public synchronized void queueTransaction(Transaction transaction) {
   // Store transaction in outgoing buffer, so we can broadcast it
   // later
   byte[] rawTransaction = transaction.toBytes();
   _backing.putOutgoingTransaction(transaction.getHash(), rawTransaction);
   markTransactionAsSpent(transaction);
 }
Exemple #22
0
 public void saveEventPassesRequest(EventNumberOfPassesRequest eventNumberOfPassesRequest) {
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     List result =
         session
             .createQuery(
                 "from EventNumberOfPassesRequest as eventNumberOfPassesRequest "
                     + "where eventNumberOfPassesRequest.idevent="
                     + eventNumberOfPassesRequest.getIdevent()
                     + " and eventNumberOfPassesRequest.iduser="
                     + eventNumberOfPassesRequest.getIduser())
             .list();
     transaction.commit();
     if (result != null && result.size() > 0) {
       Session session1 = SessionFactoryUtil.getInstance().getCurrentSession();
       Transaction transaction1 = session1.beginTransaction();
       for (Object o : result) {
         session1.delete(o);
       }
       transaction1.commit();
     }
   } finally {
     if (session.isOpen()) {
       session.disconnect();
       session.close();
     }
   }
   saveObject(eventNumberOfPassesRequest);
 }
Exemple #23
0
 @Override
 public List<Reply> getRepliesToPost(int postId) {
   // TODO Auto-generated method stub
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   List<Reply> replyArr = new ArrayList<Reply>();
   try {
     tx = session.beginTransaction();
     Query query =
         session.createQuery("from Reply where postId = :postId order by createdDate desc");
     query.setParameter("postId", postId);
     replyArr = query.list();
     /*			for(Reply reply : replyArr){
     	System.out.println("Reply - id----"+reply.getReplyId());
     	System.out.println("Reply - Description----"+reply.getDescription());
     	System.out.println("Reply - Post id----"+reply.getPostId());
     }*/
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
   return replyArr;
 }
Exemple #24
0
  public EventNumberOfPassesRequest getEventPassesRequest(User user, Event event) {
    Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    try {
      Transaction transaction = session.beginTransaction();
      List result =
          session
              .createQuery(
                  "from EventNumberOfPassesRequest as eventNumberOfPassesRequest "
                      + "where eventNumberOfPassesRequest.idevent="
                      + event.getIdevent()
                      + " and eventNumberOfPassesRequest.iduser="
                      + user.getIduser())
              .list();
      transaction.commit();

      if (result != null && result.size() > 0) {
        return (EventNumberOfPassesRequest) result.get(0);
      }
    } finally {
      if (session.isOpen()) {
        session.disconnect();
        session.close();
      }
    }
    return null;
  }
Exemple #25
0
  public int getCountOfSubscribers(int forumId, int userId) {
    // TODO Auto-generated method stub
    Session session = this.sessionFactory.openSession();
    Transaction tx = null;
    int countOfSubscribers = 0;
    try {
      tx = session.beginTransaction();
      Query query = null;
      if (userId == 0) {
        query = session.createQuery("select count(*) from Subscription where forumId = :forumId");
        query.setParameter("forumId", forumId);
      } else {
        query =
            session.createQuery(
                "select count(*) from Subscription where forumId = :forumId and userId = :userId");
        query.setParameter("forumId", forumId);
        query.setParameter("userId", userId);
      }

      Long count = (Long) query.uniqueResult();
      countOfSubscribers = count.intValue();
      // System.out.println("No of subscribers.."+countOfSubscribers);
    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
        e.printStackTrace();
      }
    } finally {
      session.close();
    }
    return countOfSubscribers;
  }
  /* abort a transaction, return true if success, false if not */
  public boolean abort(Transaction t) {
    if (!transactionTable.keySet().contains(t)) {
      System.out.println("Oops where does this transaction come from. " + t.toString());
      return false;
    }
    System.out.println("ABORTING: " + t.toString());

    List<RMmeta> rms = middleware.resourceManagers;
    synchronized (rms) {
      for (RMmeta rm : rms) {
        Socket s = rm.getSocket();
        synchronized (s) {
          try {
            BufferedReader inFromServer =
                new BufferedReader(new InputStreamReader(s.getInputStream()));
            DataOutputStream outToServer = new DataOutputStream(s.getOutputStream());
            outToServer.writeBytes("abort," + t.getId() + '\n');
            System.out.println(inFromServer.readLine());
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }

    this.middleware.lockManager.UnlockAll(t.getId());
    t.addCommand("abort", "abort");
    transactionTable.remove(t);
    return true;
  }
Exemple #27
0
  @Override
  public List<Forum> getForumsOfaUser(int userId) {
    // TODO Auto-generated method stub
    List<Forum> forums = new ArrayList<Forum>();
    Session session = sessionFactory.openSession();
    Transaction tx = null;
    try {
      tx = session.beginTransaction();
      Query query = session.createQuery("from Subscription where userId = :userId");
      query.setString("userId", String.valueOf(userId));
      List<Subscription> userSubscribedGroups = query.list();
      for (Subscription subsc : userSubscribedGroups) {
        query = session.createQuery("from Forum where forumId = :forumId");
        query.setParameter("forumId", subsc.getForumId());
        // add this to a list variable query.uniqueResult();
        forums.add((Forum) query.uniqueResult());
      }

    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
        e.printStackTrace();
      }
    } finally {
      session.close();
    }
    return forums;
  }
  /* start a transaction and add to transaction table */
  public Transaction start() {
    Transaction t = new Transaction(random.nextInt(Integer.MAX_VALUE));
    t.addCommand("start", "start");
    ArrayList<RMmeta.RMtype> types = new ArrayList<RMmeta.RMtype>();
    transactionTable.put(t, types);
    types.add(null);

    List<RMmeta> rms = middleware.resourceManagers;
    synchronized (rms) {
      for (RMmeta rm : rms) {
        Socket s = rm.getSocket();
        synchronized (s) {
          try {
            BufferedReader inFromServer =
                new BufferedReader(new InputStreamReader(s.getInputStream()));
            DataOutputStream outToServer = new DataOutputStream(s.getOutputStream());
            outToServer.writeBytes("start," + t.getId() + '\n');
            System.out.println(inFromServer.readLine());
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
    return t;
  }
 private static void sendTransactionsToListener(
     StoredBlock block,
     NewBlockType blockType,
     BlockChainListener listener,
     int relativityOffset,
     List<Transaction> transactions,
     boolean clone,
     Set<Sha256Hash> falsePositives)
     throws VerificationException {
   for (Transaction tx : transactions) {
     try {
       if (listener.isTransactionRelevant(tx)) {
         falsePositives.remove(tx.getHash());
         if (clone) tx = new Transaction(tx.params, tx.bitcoinSerialize());
         listener.receiveFromBlock(tx, block, blockType, relativityOffset++);
       }
     } catch (ScriptException e) {
       // We don't want scripts we don't understand to break the block chain so just note that this
       // tx was
       // not scanned here and continue.
       log.warn("Failed to parse a script: " + e.toString());
     } catch (ProtocolException e) {
       // Failed to duplicate tx, should never happen.
       throw new RuntimeException(e);
     }
   }
 }
  // Determine F(k+1) by support counting on (C(K+1), T) and retaining itemsets from C(k+1) with
  // support at least minsup
  private static List<Itemset> determineFrequentItemsets(
      List<Itemset> candicates, List<Transaction> transactions, double minsup) {
    if (candicates.isEmpty()) {
      return null;
    }

    HashTree hashTree = new HashTree(candicates, candicates.get(0).getNumOfItems());
    HashMap<Itemset, Integer> frequentCount = new HashMap<>();
    for (Itemset itemset : candicates) {
      frequentCount.put(itemset, 0);
    }

    for (Transaction transaction : transactions) {
      Set<Itemset> candidatesInTranscation = hashTree.candidatesInTransaction(transaction);
      if (candidatesInTranscation == null) {
        continue;
      }
      for (Itemset itemset : candidatesInTranscation) {
        if (transaction.containItemset(itemset)) {
          frequentCount.put(itemset, frequentCount.get(itemset) + 1);
        }
      }
    }

    List<Itemset> result = new ArrayList<>();
    for (Itemset itemset : candicates) {
      if ((double) (frequentCount.get(itemset)) / transactions.size() >= minsup) {
        result.add(itemset);
      }
    }
    return result;
  }