List of usage examples for org.apache.commons.collections.bag HashBag HashBag
public HashBag()
HashBag
. From source file:com.pureinfo.tgirls.utils.counts.CountsJob.java
public void execute() { logger.debug("to process counts."); CountsProcess cache = CountsProcess.getInstance(); Bag bag = new HashBag(); synchronized (cache) { bag.addAll(cache.getBag());/*from w w w .j a v a2 s . c o m*/ cache.clear(); } ISession session = null; try { session = LocalContextHelper.currentSession(); Set<String> bagKeySet = bag.uniqueSet(); for (Iterator<String> iterator = bagKeySet.iterator(); iterator.hasNext();) { String type = null; try { type = iterator.next(); Counts counts = new Counts(); counts.setType(type); counts.setCounts(bag.getCount(type)); counts.setCreateTime(); session.save(counts); } catch (Exception e) { logger.error("error when save counts:" + type, e); } } } catch (Exception e) { logger.error("error occur.", e); } finally { bag.clear(); if (session != null) try { session.close(); } catch (Exception e) { logger.error("error when close session.", e); } } }
From source file:name.martingeisse.esdk.model.hdl.assembler.verilog.SignalDeclarationRequirementDetector.java
/** * Constructor./*from w w w .j ava 2 s . co m*/ */ public SignalDeclarationRequirementDetector() { this.result = new HashSet<>(); this.bag = new HashBag(); }
From source file:com.pureinfo.tgirls.utils.counts.CountsProcess.java
private CountsProcess() { if (disabled) { return;//w ww .ja v a 2 s.co m } this.bag = new HashBag(); CountsJob job = new CountsJob("CountsJob"); worker = new SimpleSleepWorkThread(job, this.sleepTime); worker.start(); }
From source file:com.pureinfo.tgirls.utils.counts.CountsProcess.java
public synchronized void clear() { this.bag = new HashBag(); }
From source file:com.discursive.jccook.collections.bag.BagExample.java
private void start() { // Read our inventory into a Bag populateInventory();//from ww w.j a va 2s . com System.out.println("Inventory before Transactions"); printAlbums(inventoryBag); printSeparator(); // A Customer wants to purchase 400 copies of ABBA and 2 copies of Radiohead Bag shoppingCart1 = new HashBag(); shoppingCart1.add(album4, 500); shoppingCart1.add(album3, 150); shoppingCart1.add(album1, 2); checkout(shoppingCart1, "Customer 1"); // Another Customer wants to purchase 600 copies of ABBA Bag shoppingCart2 = new HashBag(); shoppingCart2.add(album4, 600); checkout(shoppingCart2, "Customer 2"); // Another Customer wants to purchase 3 copies of Kraftwerk Bag shoppingCart3 = new HashBag(); shoppingCart3.add(album2, 3); checkout(shoppingCart3, "Customer 3"); System.out.println("Inventory after Transactions"); printAlbums(inventoryBag); }
From source file:net.ontopia.topicmaps.query.toma.impl.basic.ResultSet.java
/** * Create a new {@link ResultSet} with the given number of columns. * //www . j a va2 s . c o m * @param cols the number of columns. * @param unique indicates whether this {@link ResultSet} should only contain * unique rows, or allows duplicates. */ public ResultSet(int cols, boolean unique) { columns = new Vector<String>(cols); columns.setSize(cols); rows = new HashBag(); this.unique = unique; }
From source file:net.ontopia.topicmaps.query.toma.impl.basic.ResultSet.java
/** * Create a new {@link ResultSet} that is based on the column definition from * one or more other {@link ResultSet}'s. The new {@link ResultSet} may * contain duplicate rows.//ww w.j a v a 2s. c o m * * @param others the {@link ResultSet}'s */ public ResultSet(ResultSet... others) { int cols = 0; for (ResultSet rs : others) { cols += rs.getColumnCount(); } columns = new Vector<String>(cols); columns.setSize(cols); int i = 0; for (ResultSet rs : others) { for (int j = 0; j < rs.getColumnCount(); j++, i++) { setColumnName(i, rs.getColumnName(j)); } } this.rows = new HashBag(); this.unique = false; }
From source file:com.otiliouine.flera.analyzer.SuccessionBasedDictionaryAnalyzer.java
private void addSuccessionInformations(String word) { char precedent = word.charAt(0); for (int index = 1; index < word.length(); index++) { char currentChar = word.charAt(index); Succession succession = new Succession(precedent, currentChar); Bag<Succession> successionBag = successionBags.get(precedent); if (successionBag == null) { successionBag = new HashBag<Succession>(); successionBags.put(precedent, successionBag); } else {//from w w w . j a v a 2s.c o m successionBag.add(succession); } precedent = currentChar; } }
From source file:annis.sqlgen.TestAbstractFromClauseGenerator.java
private void setupTableAliases(String table, String tableAlias, int count) { HashMap<String, String> tableAliases = new HashMap<String, String>(); tableAliases.put(table, tableAlias); tableAccessStrategy.setTableAliases(tableAliases); Bag tables = new HashBag(); tables.add(tableAlias, count);// w w w. ja v a2 s. co m given(tableAccessStrategy.computeSourceTables()).willReturn(tables); }
From source file:annis.sqlgen.TableAccessStrategy.java
protected Bag computeSourceTables() { Bag tables = new HashBag(); // hack to support table selections for ANNOTATE query if (node == null) { String[] tableNames = { NODE_TABLE, RANK_TABLE, COMPONENT_TABLE, NODE_ANNOTATION_TABLE, EDGE_ANNOTATION_TABLE }; for (String table : tableNames) tables.add(table);/* w w w. j ava 2 s . c om*/ return tables; } tables.add(tableName(NODE_ANNOTATION_TABLE), node.getNodeAnnotations().size()); if (node.getNodeAnnotations().isEmpty() && node.getNodeAnnotations().size() > 0) tables.add(tableName(NODE_ANNOTATION_TABLE)); tables.add(tableName(EDGE_ANNOTATION_TABLE), node.getEdgeAnnotations().size()); if (tables.getCount(tableName(RANK_TABLE)) == 0 && usesRankTable()) tables.add(tableName(RANK_TABLE)); if (tables.getCount(tableName(COMPONENT_TABLE)) == 0 && usesRankTable()) tables.add(tableName(COMPONENT_TABLE)); if (tables.getCount(tableName(NODE_TABLE)) == 0) tables.add(tableName(NODE_TABLE)); return tables; }