List of usage examples for java.util NavigableSet addAll
boolean addAll(Collection<? extends E> c);
From source file:com.eucalyptus.ws.util.HmacUtils.java
public static String makeV2SubjectString(String httpMethod, String host, String path, final Map<String, String> parameters) { parameters.remove(""); StringBuilder sb = new StringBuilder(); sb.append(httpMethod);/*from w w w . j a v a 2 s. c o m*/ sb.append("\n"); sb.append(host); sb.append("\n"); sb.append(path); sb.append("\n"); String prefix = sb.toString(); sb = new StringBuilder(); NavigableSet<String> sortedKeys = new TreeSet<String>(); sortedKeys.addAll(parameters.keySet()); String firstKey = sortedKeys.pollFirst(); if (firstKey != null) { sb.append(urlEncode(firstKey)).append("=") .append(urlEncode(parameters.get(firstKey).replaceAll("\\+", " "))); } while ((firstKey = sortedKeys.pollFirst()) != null) { sb.append("&").append(urlEncode(firstKey)).append("=") .append(urlEncode(parameters.get(firstKey).replaceAll("\\+", " "))); } String subject = prefix + sb.toString(); LOG.trace("VERSION2: " + subject); return subject; }
From source file:com.eucalyptus.auth.login.Hmacv2LoginModule.java
private String makeSubjectString(String httpMethod, String host, String path, final Map<String, String> parameters) throws UnsupportedEncodingException { URLCodec codec = new URLCodec(); parameters.remove(""); StringBuilder sb = new StringBuilder(); sb.append(httpMethod);//from www.j a v a 2 s . c om sb.append("\n"); sb.append(host); sb.append("\n"); sb.append(path); sb.append("\n"); String prefix = sb.toString(); sb = new StringBuilder(); NavigableSet<String> sortedKeys = new TreeSet<String>(); sortedKeys.addAll(parameters.keySet()); String firstKey = sortedKeys.pollFirst(); if (firstKey != null) { sb.append(codec.encode(firstKey, "UTF-8")).append("=").append( codec.encode(Strings.nullToEmpty(parameters.get(firstKey)), "UTF-8").replaceAll("\\+", "%20")); } while ((firstKey = sortedKeys.pollFirst()) != null) { sb.append("&").append(codec.encode(firstKey, "UTF-8")).append("=").append( codec.encode(Strings.nullToEmpty(parameters.get(firstKey)), "UTF-8").replaceAll("\\+", "%20")); } String subject = prefix + sb.toString(); LOG.trace("VERSION2: " + subject); return subject; }
From source file:py.una.pol.karaku.menu.server.MenuServerLogic.java
private void handleRootMenu(Menu menu) { // Este hashSet se usa como un queue, solamente que es deseable que no // tenga valores repetidos NavigableSet<Menu> toSort = new TreeSet<Menu>(); Map<Menu, Menu> parents = new HashMap<Menu, Menu>(); toSort.add(menu);//from w w w . j a v a 2 s. c o m Menu next; while (!toSort.isEmpty()) { next = toSort.pollFirst(); handleMenu(next, parents.get(next)); if (ListHelper.hasElements(next.getItems())) { sortInMemory(next.getItems()); toSort.addAll(next.getItems()); for (Menu m : next.getItems()) { parents.put(m, next); } } } }
From source file:ch.algotrader.service.CalendarServiceImpl.java
@Override public Date getNextOpenTime(final long exchangeId, final Date dateTime) { Validate.notNull(dateTime, "DateTime is null"); Exchange exchange = this.exchangeDao.get(exchangeId); Validate.notNull(exchange, "exchange not found"); Date date = DateUtils.truncate(dateTime, Calendar.DATE); Date openTime;//w ww.j av a 2 s . com NavigableSet<Date> openTimes = new TreeSet<>(); while ((openTime = openTimes.ceiling(dateTime)) == null) { openTimes.addAll(getOpenTimes(exchange, date)); date = DateUtils.addDays(date, 1); } return openTime; }
From source file:ch.algotrader.service.CalendarServiceImpl.java
@Override public Date getNextCloseTime(final long exchangeId, final Date dateTime) { Validate.notNull(dateTime, "DateTime is null"); Exchange exchange = this.exchangeDao.get(exchangeId); Validate.notNull(exchange, "exchange not found"); Date date = DateUtils.addDays(DateUtils.truncate(dateTime, Calendar.DATE), -1); Date closeTime;//from w w w . j a v a 2 s . co m NavigableSet<Date> closeTimes = new TreeSet<>(); while ((closeTime = closeTimes.ceiling(dateTime)) == null) { closeTimes.addAll(getCloseTimes(exchange, date)); date = DateUtils.addDays(date, 1); } return closeTime; }
From source file:ch.algotrader.service.CalendarServiceImpl.java
/** * {@inheritDoc}//from w w w . j av a 2s . c o m */ @Override public Date getCurrentTradingDate(final long exchangeId, final Date dateTime) { Validate.notNull(dateTime, "Data time is null"); Exchange exchange = this.exchangeDao.get(exchangeId); Validate.notNull(exchange, "exchange not found"); Date date = DateUtils.addDays(DateUtils.truncate(dateTime, Calendar.DATE), 2); NavigableSet<Date> openTimes = new TreeSet<>(); while ((openTimes.floor(dateTime)) == null) { date = DateUtils.addDays(date, -1); openTimes.addAll(getOpenTimes(exchange, date)); } return date; }
From source file:com.stratio.cassandra.lucene.IndexService.java
/** * Returns a {@link NavigableSet} of the specified clusterings, sorted by the table metadata. * * @param clusterings the clusterings to be included in the set * @return the navigable sorted set/* w ww. j av a 2s . c o m*/ */ NavigableSet<Clustering> clusterings(Clustering... clusterings) { NavigableSet<Clustering> sortedClusterings = new TreeSet<>(metadata.comparator); if (clusterings.length > 0) { sortedClusterings.addAll(Arrays.asList(clusterings)); } return sortedClusterings; }
From source file:org.apache.hadoop.hbase.master.LoadBalancer.java
/** * Find the block locations for all of the files for the specified region. * * Returns an ordered list of hosts that are hosting the blocks for this * region. The weight of each host is the sum of the block lengths of all * files on that host, so the first host in the list is the server which * holds the most bytes of the given region's HFiles. * * TODO: Make this work. Need to figure out how to match hadoop's hostnames * given for block locations with our HServerAddress. * TODO: Use the right directory for the region * TODO: Use getFileBlockLocations on the files not the directory * * @param fs the filesystem/* w ww.j a va 2 s . c o m*/ * @param region region * @return ordered list of hosts holding blocks of the specified region * @throws IOException if any filesystem errors */ @SuppressWarnings("unused") private List<String> getTopBlockLocations(FileSystem fs, HRegionInfo region) throws IOException { String encodedName = region.getEncodedName(); Path path = new Path("/hbase/table/" + encodedName); FileStatus status = fs.getFileStatus(path); BlockLocation[] blockLocations = fs.getFileBlockLocations(status, 0, status.getLen()); Map<HostAndWeight, HostAndWeight> hostWeights = new TreeMap<HostAndWeight, HostAndWeight>( new HostAndWeight.HostComparator()); for (BlockLocation bl : blockLocations) { String[] hosts = bl.getHosts(); long len = bl.getLength(); for (String host : hosts) { HostAndWeight haw = hostWeights.get(host); if (haw == null) { haw = new HostAndWeight(host, len); hostWeights.put(haw, haw); } else { haw.addWeight(len); } } } NavigableSet<HostAndWeight> orderedHosts = new TreeSet<HostAndWeight>(new HostAndWeight.WeightComparator()); orderedHosts.addAll(hostWeights.values()); List<String> topHosts = new ArrayList<String>(orderedHosts.size()); for (HostAndWeight haw : orderedHosts.descendingSet()) { topHosts.add(haw.getHost()); } return topHosts; }
From source file:org.opennms.web.rest.AlarmRestServiceTest.java
private OnmsAlarm getLastAlarm() { final NavigableSet<OnmsAlarm> alarms = new TreeSet<OnmsAlarm>(new Comparator<OnmsAlarm>() { @Override/* ww w . j ava 2 s. c o m*/ public int compare(final OnmsAlarm a, final OnmsAlarm b) { return a.getId().compareTo(b.getId()); } }); alarms.addAll(getAlarmDao().findAll()); return alarms.last(); }