public int converter(String str) { TreeMap<Integer, String> hm = new TreeMap<>(); { hm.put(new Integer(1000), "M"); hm.put(new Integer(900), "CM"); hm.put(new Integer(500), "D"); hm.put(new Integer(400), "CD"); hm.put(new Integer(100), "C"); hm.put(new Integer(90), "XC"); hm.put(new Integer(50), "L"); hm.put(new Integer(40), "XL"); hm.put(new Integer(10), "X"); hm.put(new Integer(9), "IX"); hm.put(new Integer(5), "V"); hm.put(new Integer(4), "IV"); hm.put(new Integer(1), "I"); } NavigableMap<Integer, String> nmap = hm.descendingMap(); int tmpResult = 0; int index = 0; for (Entry<Integer, String> entry : nmap.entrySet()) { while ((str.length() >= index + entry.getValue().length()) && str.substring(index, index + entry.getValue().length()).equals(entry.getValue())) { tmpResult += entry.getKey(); index += entry.getValue().length(); } } result = tmpResult; return result; }
// similar private void similar() { double similarity = 0; double count1 = 0; // x and y double count2 = 0; // !x and y int a = 0; int b = 0; String previous_user = ratings.get(1)[0]; for (int j = 1; j < movies.size(); j++) { if (!movies.get(j)[0].equals(best_movie)) { for (int i = 1; i < ratings.size(); i++) { if (!previous_user.equals(ratings.get(i)[0])) { if ((a == 1) && (b == 1)) { count1++; } if ((a == 0) && (b == 1)) { count2++; } a = 0; b = 0; } previous_user = ratings.get(i)[0]; if (ratings.get(i)[1].equals(best_movie)) { a = 1; } if (ratings.get(i)[1].equals(movies.get(j)[0])) { b = 1; } } similarity = (count1 * (1 + hm.get(best_movie).size())) / (1 + (count2 / (1 + (1 - hm.get(best_movie).size())))); similar.put(similarity, movies.get(j)[0]); count1 = 0; count2 = 0; a = 0; b = 0; } } text += "for best top 10 \n"; int N = 10; int i = 0; for (Entry<Double, String> entry : similar.descendingMap().entrySet()) { if (i++ < N) { text += entry.getKey() + " " + hm2.get(entry.getValue()) + "\n"; if (best_movie.equals("")) { best_movie = entry.getValue(); } } else { break; } } }
void compute() { NavigableMap<GregorianCalendar, run> briefName = scores.descendingMap(); double differentials[] = new double[20]; for (i = 0, iterator = scores.firstEntry(); i < 20; i++) { tmp = courses.get(iterator.getValue().course); differentials[i] = (iterator.getValue().score - tmp.rating) * 113.0 / tmp.slope; iterator = scores.higherEntry(iterator.getKey()); } Arrays.sort(differentials); score = 0.0; for (i = 0; i < 10; i++) { score += differentials[i]; } score /= 10; }
public String doFooBarQix(Integer candidate) { StringBuilder builder = new StringBuilder(); if (candidate == null) { return ""; } if (isDivisibleByX(candidate, 3)) { builder.append("Foo"); } if (isDivisibleByX(candidate, 5)) { builder.append("Bar"); } if (isDivisibleByX(candidate, 7)) { builder.append("Qix"); } TreeMap<Integer, String> m = new TreeMap<>(); Result r; int index; if ((r = containsX(candidate, 3)).result()) { r.populate(m, "Foo"); // m.put(index, "Foo"); } // if (( index = containsX(candidate, 5)) != 0) { if ((r = containsX(candidate, 5)).result()) { r.populate(m, "Bar"); // m.put(index, "Bar"); } if ((r = containsX(candidate, 7)).result()) { r.populate(m, "Qix"); // m.put(index, "Qix"); } m.descendingMap() .forEach( (i, s) -> { builder.append(s); }); if (builder.length() == 0) { builder.append(candidate); } return builder.toString(); }
/** @return Sorted list of warps with most recent players listed first */ public Collection<UUID> listSortedWarps() { // Bigger value of time means a more recent login TreeMap<Long, UUID> map = new TreeMap<Long, UUID>(); for (UUID uuid : warpList.keySet()) { // If never played, will be zero long lastPlayed = plugin.getServer().getOfflinePlayer(uuid).getLastPlayed(); // This aims to avoid the chance that players logged off at exactly the same time if (!map.isEmpty() && map.containsKey(lastPlayed)) { lastPlayed = map.firstKey() - 1; } map.put(lastPlayed, uuid); } Collection<UUID> result = map.descendingMap().values(); // Fire event WarpListEvent event = new WarpListEvent(plugin, result); plugin.getServer().getPluginManager().callEvent(event); // Get the result of any changes by listeners result = event.getWarps(); return result; }
// damped mean for k=5 private void dampedMeanTop10() { double d_m = 0; // damped mean for k=5 for (Entry<String, ArrayList<Double>> entry : hm.entrySet()) { for (double d : entry.getValue()) { d_m += d; } d_m = (d_m + 5 * 2.5) / (entry.getValue().size() + 5); damped_mean.put(d_m, entry.getKey()); d_m = 0; } text += "damped_mean top 10 \n"; int N = 10; int i = 0; for (Entry<Double, String> entry : damped_mean.descendingMap().entrySet()) { if (i++ < N) { text += +entry.getKey() + " " + hm2.get(entry.getValue()) + " " + entry.getValue() + "\n"; if (best_movie.equals("")) { best_movie = entry.getValue(); } } else { break; } } }
// ------------------------------------------------------------------------- protected ManageablePortfolio generatePortfolio(final String portfolioName) { final ReferenceDataProvider referenceDataProvider = getToolContext().getBloombergReferenceDataProvider(); final ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName); // Is this a hack? final ManageablePortfolioNode rootNode = portfolio.getRootNode(); portfolio.setRootNode(rootNode); // String indexTickerSuffix = " Index"; final Set<String> memberEquities = new HashSet<String>(); for (final Entry<String, String> entry : INDEXES_TO_EXCHANGE.entrySet()) { final String indexTickerSuffix = " Index"; final String underlying = entry.getKey(); final String ticker = underlying + indexTickerSuffix; // don't add index (delete at some point) // addNodes(rootNode, ticker, false, INDEX_OPTION_PERIODS); final Set<String> indexMembers = BloombergDataUtils.getIndexMembers(referenceDataProvider, ticker); for (final String member : indexMembers) { final String symbol = getBloombergEquitySymbol(entry.getValue(), member); // time series errors for Walmart // Todo: investegate & fix if ("WMT US Equity".equals(symbol)) { continue; } memberEquities.add(symbol); } } // Sort the symbols for the current index by market cap (highest to lowest), skipping any in the // list of EXCLUDED_SECTORS final TreeMap<Double, String> equityByMarketCap = new TreeMap<Double, String>(); final Map<String, FudgeMsg> refDataMap = referenceDataProvider.getReferenceData( memberEquities, Sets.newHashSet( BloombergFields.CURRENT_MARKET_CAP_FIELD, BloombergConstants.FIELD_GICS_SUB_INDUSTRY)); for (final String equity : memberEquities) { final FudgeMsg fieldData = refDataMap.get(equity); if (fieldData == null) { throw new OpenGammaRuntimeException("Information not found for equity: " + equity); } final String gicsCodeString = fieldData.getString(BloombergConstants.FIELD_GICS_SUB_INDUSTRY); if (gicsCodeString == null) { continue; } final GICSCode gicsCode = GICSCode.of(gicsCodeString); if (EXCLUDED_SECTORS.contains(gicsCode.getSectorDescription())) { continue; } final Double marketCap = fieldData.getDouble(BloombergFields.CURRENT_MARKET_CAP_FIELD); if (marketCap != null) { equityByMarketCap.put(marketCap, equity); } } // Add a given number of symbols (MEMBERS_DEPTH) to the portfolio and store in a List // When adding to the portfolio, add a collar of options with PVs distributed equally +/- around // 0 int count = 0; final List<String> chosenEquities = new ArrayList<String>(); for (final Entry<Double, String> entry : equityByMarketCap.descendingMap().entrySet()) { try { addNodes(rootNode, entry.getValue(), true, MEMBER_OPTION_PERIODS); chosenEquities.add(entry.getValue()); if (++count >= _numMembers) { break; } } catch (final RuntimeException e) { s_logger.warn("Caught exception", e); } } s_logger.info("Generated collar portfolio for {}", chosenEquities); return portfolio; }
// ------------------------------------------------------------------------- protected ManageablePortfolio generatePortfolio(String portfolioName) { ReferenceDataProvider referenceDataProvider = ((BloombergToolContext) getToolContext()).getBloombergReferenceDataProvider(); ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName); // Is this a hack? ManageablePortfolioNode rootNode = portfolio.getRootNode(); portfolio.setRootNode(rootNode); // String indexTickerSuffix = " Index"; Set<String> memberEquities = new HashSet<String>(); for (Entry<String, String> entry : INDEXES_TO_EXCHANGE.entrySet()) { String indexTickerSuffix = " Index"; String underlying = entry.getKey(); String ticker = underlying + indexTickerSuffix; // don't add index (delete at some point) // addNodes(rootNode, ticker, false, INDEX_OPTION_PERIODS); Set<String> indexMembers = BloombergDataUtils.getIndexMembers(referenceDataProvider, ticker); for (String member : indexMembers) { String symbol = getBloombergEquitySymbol(entry.getValue(), member); // time series errors for Walmart // Todo: investegate & fix if ("WMT US Equity".equals(symbol)) { continue; } memberEquities.add(symbol); } } // Sort the symbols for the current index by market cap (highest to lowest), skipping any in the // list of EXCLUDED_SECTORS TreeMap<Double, String> equityByMarketCap = new TreeMap<Double, String>(); ReferenceDataResult fields = referenceDataProvider.getFields( memberEquities, Sets.newHashSet( BloombergFields.CURRENT_MARKET_CAP_FIELD, BloombergConstants.FIELD_GICS_SUB_INDUSTRY)); for (String equity : memberEquities) { PerSecurityReferenceDataResult result = fields.getResult(equity); String gicsCodeString = result.getFieldData().getString(BloombergConstants.FIELD_GICS_SUB_INDUSTRY); GICSCode gicsCode = GICSCode.of(gicsCodeString); if (EXCLUDED_SECTORS.contains(gicsCode.getSectorDescription())) { continue; } Double marketCap = result.getFieldData().getDouble(BloombergFields.CURRENT_MARKET_CAP_FIELD); equityByMarketCap.put(marketCap, equity); } // Add a given number of symbols (MEMBERS_DEPTH) to the portfolio and store in a List // When adding to the portfolio, add a collar of options with PVs distributed equally +/- around // 0 int count = 0; List<String> chosenEquities = new ArrayList<String>(); for (Entry<Double, String> entry : equityByMarketCap.descendingMap().entrySet()) { if (count++ >= _numMembers) { break; } addNodes(rootNode, entry.getValue(), true, MEMBER_OPTION_PERIODS); chosenEquities.add(entry.getValue()); } s_logger.info("Generated collar portfolio for {}", chosenEquities); return portfolio; }
public void mainMenu() { shouldClear = true; shouldAddScrollPane = false; charityScrollPane = false; characterScrollPane = false; scrollPaneContainer = null; menu = Assets.menuSplashBlankRegion; menuComponents = new ArrayList<MenuComponent>(); menuTextFields = new HashMap<String, TextField>(); menuComponents.add( 0, new MenuComponent(200, 350, 175, 75, Assets.menuButtonSmallRegion)); // play button menuComponents.add( 1, new MenuComponent(200, 250, 175, 75, Assets.menuButtonSmallRegion)); // options button menuComponents.add( 2, new MenuComponent(200, 150, 175, 75, Assets.menuButtonSmallRegion)); // profile button // right now I am using the metric of setting the width to be 175 and height 50 (for textfields) // and making them 88 units below the buttons and 73 units below. thats maybe like 1 or 2 units // higher than it needs to be, but it looks aight TextField playTextField = new TextField(("PLAY!"), Assets.tfsTransWhite40); playTextField.setPosition(112, 277); playTextField.setWidth(175); // to be centered well make the width about 325 playTextField.setHeight(50); playTextField.setAlignment(Align.center); playTextField.setFocusTraversal(false); playTextField.setDisabled(true); TextField optionsTextField = new TextField(("OPTIONS"), Assets.tfsTransWhite40); optionsTextField.setPosition(112, 177); optionsTextField.setWidth(175); optionsTextField.setHeight(50); optionsTextField.setAlignment(Align.center); optionsTextField.setFocusTraversal(false); optionsTextField.setDisabled(true); TextField profileTextField = new TextField(("PROFILE"), Assets.tfsTransWhite40); profileTextField.setPosition(112, 77); profileTextField.setWidth(175); profileTextField.setHeight(50); profileTextField.setAlignment(Align.center); profileTextField.setFocusTraversal(false); profileTextField.setDisabled(true); TextField charityChampsTextField = new TextField(("CHARITY CHAMPS"), Assets.tfsTrans100); charityChampsTextField.setPosition(50, 390); charityChampsTextField.setWidth(700); charityChampsTextField.setHeight(50); charityChampsTextField.setAlignment(Align.center); charityChampsTextField.setFocusTraversal(false); charityChampsTextField.setDisabled(true); Leaderboard leaderboard = new Leaderboard(game.getPlayerID(), 5, 0); int yOffset = 0; TreeMap<Integer, Integer> sortedMap = new TreeMap<Integer, Integer>(); for (Integer id : leaderboard.board.keySet()) // for each (INT, <String, String>) { System.out.println( "sorting " + Integer.parseInt(leaderboard.board.get(id).get("WINS")) + " " + id); sortedMap.put(Integer.parseInt(leaderboard.board.get(id).get("WINS")), id); } System.out.println(sortedMap.descendingMap()); for (Integer id : sortedMap .descendingMap() .values()) { // the values, is the id. should do it in the order of wins highest TextField playerTextField = new TextField(leaderboard.board.get(id).get("USERNAME"), Assets.tfsTrans40); playerTextField.setPosition(400, 260 - (yOffset * 70)); playerTextField.setWidth(300); playerTextField.setHeight(50); playerTextField.setAlignment(Align.left); playerTextField.setFocusTraversal(false); playerTextField.setDisabled(true); TextField winsTextField = new TextField(leaderboard.board.get(id).get("WINS"), Assets.tfsTrans40); winsTextField.setPosition(700, 260 - (yOffset * 70)); winsTextField.setWidth(100); winsTextField.setHeight(50); winsTextField.setAlignment(Align.left); winsTextField.setFocusTraversal(false); winsTextField.setDisabled(true); yOffset++; menuTextFields.put(leaderboard.board.get(id).get("USERNAME"), playerTextField); menuTextFields.put(leaderboard.board.get(id).get("WINS"), winsTextField); } menuTextFields.put("playTF", playTextField); menuTextFields.put("optionsTF", optionsTextField); menuTextFields.put("profileTF", profileTextField); menuTextFields.put("charityChampsTF", charityChampsTextField); menuNumber = this.MENU_MAINMENU; }
void forEachDescending(BiIntConsumer consumer) { List<Entry<Integer, Integer>> items = new ArrayList<>(map.descendingMap().entrySet()); items.forEach(e -> consumer.accept(e.getKey(), e.getValue())); }
List<Entry<Integer, Integer>> descendingEntries() { return new ArrayList<>(map.descendingMap().entrySet()); }
public Map<Integer, Album> getAlbums() { NavigableMap albumsTrie = albums.descendingMap(); return albumsTrie; }
/* (non-Javadoc) * @see me.tabinol.factoid.commands.executor.CommandInterface#commandExecute() */ @Override public void commandExecute() throws FactoidCommandException { String curArg = entity.argList.getNext(); ApproveList approveList = Factoid.getThisPlugin().iLands().getApproveList(); boolean isApprover = entity.sender.hasPermission("factoid.collisionapprove"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); if (curArg.equalsIgnoreCase("clear")) { if (!isApprover) { throw new FactoidCommandException("Approve", entity.sender, "GENERAL.MISSINGPERMISSION"); } approveList.removeAll(); entity.sender.sendMessage( ChatColor.YELLOW + "[Factoid] " + Factoid.getThisPlugin().iLanguage().getMessage("COLLISION.GENERAL.CLEAR")); } else if (curArg.equalsIgnoreCase("list")) { // List of Approve StringBuilder stList = new StringBuilder(); int t = 0; TreeMap<Date, Approve> approveTree = new TreeMap<Date, Approve>(); // create list (short by date/time) for (Approve app : approveList.getApproveList().values()) { approveTree.put(app.getDateTime().getTime(), app); } // show Approve List for (Map.Entry<Date, Approve> approveEntry : approveTree.descendingMap().entrySet()) { Approve app = approveEntry.getValue(); if (app != null && (isApprover || app.getOwner().hasAccess(entity.player))) { stList.append( ChatColor.WHITE + Factoid.getThisPlugin() .iLanguage() .getMessage( "COLLISION.SHOW.LIST", ChatColor.BLUE + df.format(app.getDateTime().getTime()) + ChatColor.WHITE, ChatColor.BLUE + app.getLandName() + ChatColor.WHITE, app.getOwner().getPrint() + ChatColor.WHITE, ChatColor.BLUE + app.getAction().toString() + ChatColor.WHITE)); stList.append(Config.NEWLINE); t++; } } if (t == 0) { // List empty entity.sender.sendMessage( ChatColor.YELLOW + "[Factoid] " + Factoid.getThisPlugin().iLanguage().getMessage("COLLISION.SHOW.LISTROWNULL")); } else { // List not empty new ChatPage("COLLISION.SHOW.LISTSTART", stList.toString(), entity.sender, null).getPage(1); } } else if (curArg.equalsIgnoreCase("info") || curArg.equalsIgnoreCase("confirm") || curArg.equalsIgnoreCase("cancel")) { String param = entity.argList.getNext(); if (param == null) { throw new FactoidCommandException("Approve", entity.sender, "COLLISION.SHOW.PARAMNULL"); } Approve approve = approveList.getApprove(param); if (approve == null) { throw new FactoidCommandException("Approve", entity.sender, "COLLISION.SHOW.PARAMNULL"); } // Check permission if ((curArg.equalsIgnoreCase("confirm") && !isApprover) || ((curArg.equalsIgnoreCase("cancel") || curArg.equalsIgnoreCase("info")) && !(isApprover || approve.getOwner().hasAccess(entity.player)))) { throw new FactoidCommandException("Approve", entity.sender, "GENERAL.MISSINGPERMISSION"); } ILand land = Factoid.getThisPlugin().iLands().getLand(param); Collisions.LandAction action = approve.getAction(); int removeId = approve.getRemovedAreaId(); ICuboidArea newArea = approve.getNewArea(); ILand parent = approve.getParent(); Double price = approve.getPrice(); IPlayerContainer owner = approve.getOwner(); if (curArg.equalsIgnoreCase("info") || curArg.equalsIgnoreCase("confirm")) { // Print area if (newArea != null) { entity.sender.sendMessage(newArea.getPrint()); } // Info on the specified land (Collision) checkCollision(param, land, null, action, removeId, newArea, parent, owner, price, false); if (curArg.equalsIgnoreCase("confirm")) { // Create the action (if it is possible) approveList.removeApprove(approve); approve.createAction(); entity.sender.sendMessage( ChatColor.YELLOW + "[Factoid] " + Factoid.getThisPlugin().iLanguage().getMessage("COLLISION.GENERAL.DONE")); } } else if (curArg.equalsIgnoreCase("cancel")) { // Remove in approve list approveList.removeApprove(approve); entity.sender.sendMessage( ChatColor.YELLOW + "[Factoid] " + Factoid.getThisPlugin().iLanguage().getMessage("COLLISION.GENERAL.REMOVE")); } else { throw new FactoidCommandException("Approve", entity.sender, "GENERAL.MISSINGPERMISSION"); } } else { throw new FactoidCommandException( "Missing information command", entity.sender, "GENERAL.MISSINGINFO"); } }