List of usage examples for com.google.common.collect Multiset add
@Override
boolean add(E element);
From source file:com.wasteofplastic.askyblock.listeners.LavaCheck.java
/** * Magic Cobble Generator/*from w w w. jav a 2 s.com*/ * @param e */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onCobbleGen(BlockFromToEvent e) { /* plugin.getLogger().info("DEBUG: " + e.getEventName()); plugin.getLogger().info("From material is " + e.getBlock().toString()); plugin.getLogger().info("To material is " + e.getToBlock().getType().toString()); plugin.getLogger().info("---------------------------------"); */ // If magic cobble gen isnt used if (!Settings.useMagicCobbleGen) { //plugin.getLogger().info("DEBUG: no magic cobble gen"); return; } // Only do this in ASkyBlock world if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) { //plugin.getLogger().info("DEBUG: wrong world"); return; } // Do nothing if a new island is being created if (plugin.isNewIsland()) { //plugin.getLogger().info("DEBUG: new island in creation"); return; } // If only at spawn, do nothing if we're not at spawn if (Settings.magicCobbleGenOnlyAtSpawn && (!ASkyBlockAPI.getInstance().isAtSpawn(e.getBlock().getLocation()))) { return; } final Block b = e.getBlock(); if (b.getType().equals(Material.WATER) || b.getType().equals(Material.STATIONARY_WATER) || b.getType().equals(Material.LAVA) || b.getType().equals(Material.STATIONARY_LAVA)) { //plugin.getLogger().info("DEBUG: From block is water or lava. To = " + e.getToBlock().getType()); final Block toBlock = e.getToBlock(); if (toBlock.getType().equals(Material.AIR) && generatesCobble(b, toBlock)) { //plugin.getLogger().info("DEBUG: potential cobble gen"); // Get island level or use default int l = Integer.MIN_VALUE; Island island = plugin.getGrid().getIslandAt(b.getLocation()); if (island != null) { if (island.getOwner() != null) { l = plugin.getPlayers().getIslandLevel(island.getOwner()); //plugin.getLogger().info("DEBUG: level " + level); } } final int level = l; // Check if cobble was generated next tick // Store surrounding blocks and their current material types final List<Block> prevBlock = new ArrayList<Block>(); final List<Material> prevMat = new ArrayList<Material>(); for (BlockFace face : FACES) { Block r = toBlock.getRelative(face); prevBlock.add(r); prevMat.add(r.getType()); //r = toBlock.getRelative(face,2); //prevBlock.add(r); //prevMat.add(r.getType()); } // Check if they became cobblestone next tick plugin.getServer().getScheduler().runTask(plugin, new Runnable() { @Override public void run() { Iterator<Block> blockIt = prevBlock.iterator(); Iterator<Material> matIt = prevMat.iterator(); while (blockIt.hasNext() && matIt.hasNext()) { Block block = blockIt.next(); Material material = matIt.next(); if (block.getType().equals(Material.COBBLESTONE) && !block.getType().equals(material)) { //plugin.getLogger().info("DEBUG: " + material + " => " + block.getType()); //plugin.getLogger().info("DEBUG: Cobble generated. Island level = " + level); if (!Settings.magicCobbleGenChances.isEmpty()) { Entry<Integer, TreeMap<Double, Material>> entry = Settings.magicCobbleGenChances .floorEntry(level); double maxValue = entry.getValue().lastKey(); double rnd = Util.randomDouble() * maxValue; Entry<Double, Material> en = entry.getValue().ceilingEntry(rnd); //Bukkit.getLogger().info("DEBUG: " + entry.getValue().toString()); //plugin.getLogger().info("DEBUG: Cobble generated. Island level = " + level); //plugin.getLogger().info("DEBUG: rnd = " + rnd + "/" + maxValue); //plugin.getLogger().info("DEBUG: material = " + en.getValue()); if (en != null) { block.setType(en.getValue()); // Record stats, per level if (stats.containsKey(entry.getKey())) { stats.get(entry.getKey()).add(en.getValue()); } else { Multiset<Material> set = HashMultiset.create(); set.add(en.getValue()); stats.put(entry.getKey(), set); } } } } } } }); } } }
From source file:org.opentripplanner.routing.spt.MultiStateShortestPathTree.java
public void dump() { Multiset<Integer> histogram = HashMultiset.create(); int statesCount = 0; int maxSize = 0; for (Map.Entry<Vertex, List<State>> kv : stateSets.entrySet()) { List<State> states = kv.getValue(); int size = states.size(); histogram.add(size); statesCount += size;//ww w . j av a 2s.co m if (size > maxSize) { maxSize = size; } } LOG.info("SPT: vertices: " + stateSets.size() + " states: total: " + statesCount + " per vertex max: " + maxSize + " avg: " + (statesCount * 1.0 / stateSets.size())); List<Integer> nStates = new ArrayList<Integer>(histogram.elementSet()); Collections.sort(nStates); for (Integer nState : nStates) { LOG.info(nState + " states: " + histogram.count(nState) + " vertices."); } }
From source file:Beans.PlayersBean.java
@PostConstruct public void init() { try {/*from ww w. j a v a2 s .c om*/ Set<CodeAward> codeAwards = CodesImporter.importCodes(); MappingCodeAwards.initializeMapping(); Datastore ds = singleton.getDatastore(); Query q = ds.createQuery(Player.class); players = q.asList(); if (players == null) { players = new ArrayList(); } for (Player player : players) { // Query<Player> qUNiquePlayer = ds.createQuery(Player.class).filter("twitter", player.getTwitter()); // Player foundPlayer = (Player) qUNiquePlayer.get(); StringBuilder sb = new StringBuilder(); Multiset<String> categoryCodeAwards = HashMultiset.create(); for (String code : player.getCodes()) { for (CodeAward codeAward : codeAwards) { if (code.equals(codeAward.getCode())) { categoryCodeAwards.add(codeAward.getCategory()); try { player.setPoints(player.getPoints() + codeAward.getPoints()); } catch (Exception e) { System.out.println("Exception when adding points: "); System.out.println(e); } break; } } } for (String categoryCodeAward : categoryCodeAwards.elementSet()) { if (MappingCodeAwards.getMapCategoryToFontIcon().get(categoryCodeAward) != null) { sb.append("<i style=\"font-size:0.8em\" class=\"fa ") .append(MappingCodeAwards.getMapCategoryToFontIcon().get(categoryCodeAward)) .append("\"></i> x ").append(categoryCodeAwards.count(categoryCodeAward)); sb.append(", "); } } if (sb.lastIndexOf(", ") > 0) { sb.delete(sb.lastIndexOf(","), sb.length() - 1); } player.setHtmlListOfCodeAwards(sb.toString()); } } catch (IOException ex) { Logger.getLogger(PlayersBean.class.getName()).log(Level.SEVERE, null, ex); } Collections.sort(players); Collections.reverse(players); //find rank Player previous = null; int counterPlayers = 0; for (Player player : players) { counterPlayers++; if (previous != null) { if (player.getPoints() == previous.getPoints()) { player.setRank(previous.getRank()); } else { player.setRank(counterPlayers); } } else { player.setRank(counterPlayers); } previous = player; } }
From source file:org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper.java
/** * Get the color histogram of the image// www . j ava2 s.c o m * * @return The color density of the image */ public Multiset<RGB> getHistogram() { Multiset<RGB> colors = HashMultiset.create(); for (int pixel : fPixels) { RGB pixelColor = getRgbFromRGBPixel(pixel); colors.add(pixelColor); } return colors; }
From source file:com.google.inject.internal.WeakKeySet.java
public void add(Key<?> key, State state, Object source) { if (backingMap == null) { backingMap = Maps.newHashMap();// ww w . ja v a 2 s .c o m } // if it's an instanceof Class, it was a JIT binding, which we don't // want to retain. if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) { source = null; } BlacklistKey blacklistKey = new BlacklistKey(key); Multiset<Object> sources = backingMap.get(blacklistKey); if (sources == null) { sources = LinkedHashMultiset.create(); backingMap.put(blacklistKey, sources); } Object convertedSource = Errors.convert(source); sources.add(convertedSource); // Avoid all the extra work if we can. if (state.parent() != State.NONE) { Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state); if (keyAndSources == null) { evictionCache.put(state, keyAndSources = Sets.newHashSet()); } keyAndSources.add(new KeyAndSource(blacklistKey, convertedSource)); } }
From source file:di.uniba.it.tri.occ.BuildOccurrence.java
private Map<String, Multiset<String>> count(File startingDir, int year) throws IOException { Map<String, Multiset<String>> map = new HashMap<>(); File[] listFiles = startingDir.listFiles(); for (File file : listFiles) { if (file.getName().endsWith("_" + String.valueOf(year))) { logger.log(Level.INFO, "Working file: {0}", file.getName()); StringReader reader = extractor.extract(file); List<String> tokens = getTokens(reader); for (int i = 0; i < tokens.size(); i++) { int start = Math.max(0, i - winsize); int end = Math.min(tokens.size() - 1, i + winsize); for (int j = start; j < end; j++) { if (i != j) { Multiset<String> multiset = map.get(tokens.get(i)); if (multiset == null) { multiset = HashMultiset.create(); map.put(tokens.get(i), multiset); }/*from ww w . java 2 s . co m*/ multiset.add(tokens.get(j)); } } } } } return map; }
From source file:de.blizzy.rust.lootconfig.LootConfigDump.java
private void fillItemCategoryDropChances(Category itemCategory, Set<SubSpawn> subSpawns, float parentChance, Multiset<Float> itemCategoryDropChances) { int totalWeight = subSpawns.stream().collect(Collectors.summingInt(subSpawn -> subSpawn.Weight)); for (SubSpawn subSpawn : subSpawns) { float subSpawnChance = parentChance * subSpawn.Weight / totalWeight; if (subSpawn.Category == itemCategory) { itemCategoryDropChances.add(subSpawnChance); } else if (subSpawn.Category.hasSubSpawns()) { fillItemCategoryDropChances(itemCategory, subSpawn.Category.SubSpawn, subSpawnChance, itemCategoryDropChances); }/*from w w w. ja v a2 s . c om*/ } }
From source file:cpw.mods.inventorysorter.SortingHandler.java
private void distributeInventory(Action.ActionContext context, Multiset<ItemStackHolder> itemcounts) { InventoryCrafting ic = (InventoryCrafting) context.slot.inventory; Multiset<ItemStackHolder> slotCounts = TreeMultiset.create(new InventoryHandler.ItemStackComparator()); for (int x = 0; x < ic.getWidth(); x++) { for (int y = 0; y < ic.getHeight(); y++) { ItemStack is = ic.getStackInRowAndColumn(x, y); if (is != null) { slotCounts.add(new ItemStackHolder(is)); }// w w w. j a v a2s.c o m } } final ImmutableMultiset<ItemStackHolder> staticcounts = ImmutableMultiset.copyOf(itemcounts); for (int x = 0; x < ic.getWidth(); x++) { for (int y = 0; y < ic.getHeight(); y++) { ItemStack is = ic.getStackInRowAndColumn(x, y); if (is != null) { ItemStackHolder ish = new ItemStackHolder(is); int count = staticcounts.count(ish); int slotNum = slotCounts.count(ish); final int occurrences = count / slotNum; itemcounts.remove(ish, occurrences); is.stackSize = occurrences; } } } for (int x = 0; x < ic.getWidth(); x++) { for (int y = 0; y < ic.getHeight(); y++) { ItemStack is = ic.getStackInRowAndColumn(x, y); if (is != null) { ItemStackHolder ish = new ItemStackHolder(is); if (itemcounts.count(ish) > 0) { is.stackSize += itemcounts.setCount(ish, 0); } } } } for (int slot = context.slotMapping.begin; slot < context.slotMapping.end + 1; slot++) { context.player.openContainer.getSlot(slot).onSlotChanged(); } }
From source file:org.caleydo.vis.lineup.model.CategoricalRankColumnModel.java
/** * @return/* w w w .j a va 2s . com*/ */ public Multiset<CATEGORY_TYPE> getHist() { Multiset<CATEGORY_TYPE> hist = HashMultiset.create(metaData.size()); for (IRow r : getMyRanker()) { CATEGORY_TYPE v = getCatValue(r); if (v == null) // TODO nan continue; hist.add(v); } return hist; }
From source file:se.gothiaforum.controller.tagcloud.TagCloudController.java
/** * Renders the view for the tag cloud./*from w w w. j a v a 2 s .com*/ * * @param request * the request * @param model * the model * @return a view */ @RenderMapping public String renderView(RenderRequest request, Model model) { try { List<JournalArticle> articles = JournalArticleLocalServiceUtil.getJournalArticles(0, JournalArticleLocalServiceUtil.getJournalArticlesCount()); Set<AssetEntry> entrys = new HashSet<AssetEntry>(); for (JournalArticle ja : articles) { if (ja.getType().equals(ActorsConstants.TYPE_ACTOR)) { entrys.add(AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), ja.getResourcePrimKey())); } } Multiset<AssetTag> tagMultiSet = HashMultiset.create(); for (AssetEntry entry : entrys) { List<AssetTag> tags = AssetTagLocalServiceUtil.getEntryTags(entry.getEntryId()); for (AssetTag tag : tags) { tagMultiSet.add(tag); } } List<TagVO> tagVOList = new ArrayList<TagVO>(); for (Entry<AssetTag> entry : tagMultiSet.entrySet()) { String cssClass; final int number8 = 8; final int number7 = 7; final int number6 = 6; final int number5 = 5; final int number4 = 4; final int number3 = 3; final int number2 = 2; if (entry.getCount() > number8) { cssClass = "tag-weight-10"; } else if (entry.getCount() > number7) { cssClass = "tag-weight-9"; } else if (entry.getCount() > number6) { cssClass = "tag-weight-8"; } else if (entry.getCount() > number5) { cssClass = "tag-weight-7"; } else if (entry.getCount() > number4) { cssClass = "tag-weight-6"; } else if (entry.getCount() > number3) { cssClass = "tag-weight-5"; } else if (entry.getCount() > number2) { cssClass = "tag-weight-4"; } else { cssClass = "tag-weight-2"; } TagVO tagVO = new TagVO(cssClass, entry.getElement().getName(), ActorsConstants.SEARCH_REDIRECT_URL + entry.getElement().getName(), entry.getElement().getTagId()); tagVO.setCount(entry.getCount()); tagVOList.add(tagVO); } final int size = 20; if (tagVOList.size() > size) { for (int i = 1; tagVOList.size() > size; i++) { List<TagVO> removeList = new ArrayList<TagVO>(); for (TagVO tagVO : tagVOList) { if (tagVO.getCount() == i) { removeList.add(tagVO); } } tagVOList.removeAll(removeList); } } Collections.shuffle(tagVOList); model.addAttribute("tagVOList", tagVOList); } catch (SystemException e) { e.printStackTrace(); } catch (PortalException e) { e.printStackTrace(); } return "tagCloudView"; }