List of usage examples for java.util SortedSet toArray
<T> T[] toArray(T[] a);
From source file:org.apache.wiki.auth.user.XMLUserDatabase.java
/** * Returns all WikiNames that are stored in the UserDatabase * as an array of WikiPrincipal objects. If the database does not * contain any profiles, this method will return a zero-length * array.//from w w w .j a va 2s. c o m * @return the WikiNames * @throws WikiSecurityException In case things fail. */ public Principal[] getWikiNames() throws WikiSecurityException { if (c_dom == null) { throw new IllegalStateException("FATAL: database does not exist"); } SortedSet<Principal> principals = new TreeSet<Principal>(); NodeList users = c_dom.getElementsByTagName(USER_TAG); for (int i = 0; i < users.getLength(); i++) { Element user = (Element) users.item(i); String wikiName = user.getAttribute(WIKI_NAME); if (wikiName == null) { log.warn("Detected null wiki name in XMLUserDataBase. Check your user database."); } else { Principal principal = new WikiPrincipal(wikiName, WikiPrincipal.WIKI_NAME); principals.add(principal); } } return principals.toArray(new Principal[principals.size()]); }
From source file:de.knowwe.defi.usermanager.XMLUserDatabase.java
/** * Returns all WikiNames that are stored in the UserDatabase * as an array of WikiPrincipal objects. If the database does not * contain any profiles, this method will return a zero-length * array.//from www. j a va 2s. c om * @return the WikiNames * @throws org.apache.wiki.auth.WikiSecurityException In case things fail. */ @Override public Principal[] getWikiNames() throws WikiSecurityException { if (c_dom == null) { throw new IllegalStateException("FATAL: database does not exist"); } SortedSet<Principal> principals = new TreeSet<>(); NodeList users = c_dom.getElementsByTagName(USER_TAG); for (int i = 0; i < users.getLength(); i++) { Element user = (Element) users.item(i); String wikiName = user.getAttribute(WIKI_NAME); if (wikiName == null) { Log.warning("Detected null wiki name in XMLUserDataBase. Check your user database."); } else { Principal principal = new WikiPrincipal(wikiName, WikiPrincipal.WIKI_NAME); principals.add(principal); } } return principals.toArray(new Principal[principals.size()]); }
From source file:org.apache.roller.weblogger.webservices.atomprotocol.MediaCollection.java
public Feed getCollection(AtomRequest areq) throws AtomException { log.debug("Entering"); String[] rawPathInfo = StringUtils.split(areq.getPathInfo(), "/"); try {/*from www . j av a2s .co m*/ int start = 0; int max = maxEntries; String[] pathInfo = rawPathInfo; if (rawPathInfo.length > 2) { try { start = Integer.parseInt(rawPathInfo[rawPathInfo.length - 1]); pathInfo = new String[rawPathInfo.length - 1]; for (int i = 0; i < rawPathInfo.length - 1; i++) { pathInfo[i] = rawPathInfo[i]; } } catch (Exception ingored) { } } String path = filePathFromPathInfo(pathInfo); if (!path.equals("")) path = path + File.separator; String handle = pathInfo[0]; String absUrl = WebloggerRuntimeConfig.getAbsoluteContextURL(); Weblog website = roller.getWeblogManager().getWeblogByHandle(handle); if (website == null) { throw new AtomNotFoundException("Cannot find weblog: " + handle); } if (!RollerAtomHandler.canView(user, website)) { throw new AtomNotAuthorizedException("Not authorized to access website"); } Feed feed = new Feed(); feed.setId(atomURL + "/" + website.getHandle() + "/resources/" + path + start); feed.setTitle(website.getName()); Link link = new Link(); link.setHref(absUrl + "/" + website.getHandle()); link.setRel("alternate"); link.setType("text/html"); feed.setAlternateLinks(Collections.singletonList(link)); MediaFileManager fmgr = roller.getMediaFileManager(); MediaFileDirectory dir = null; if (StringUtils.isNotEmpty(path)) { log.debug("Fetching resource collection from weblog " + handle + " at path: " + path); dir = fmgr.getMediaFileDirectoryByPath(website, path); } else { log.debug("Fetching root resource collection from weblog " + handle); dir = fmgr.getMediaFileRootDirectory(website); } Set<MediaFile> files = dir.getMediaFiles(); SortedSet sortedSet = new TreeSet(new Comparator() { public int compare(Object o1, Object o2) { MediaFile f1 = (MediaFile) o1; MediaFile f2 = (MediaFile) o2; if (f1.getLastModified() < f2.getLastModified()) return 1; else if (f1.getLastModified() == f2.getLastModified()) return 0; else return -1; } }); if (files != null && start < files.size()) { for (MediaFile mf : files) { sortedSet.add(mf); } int count = 0; MediaFile[] sortedResources = (MediaFile[]) sortedSet.toArray(new MediaFile[sortedSet.size()]); List atomEntries = new ArrayList(); for (int i = start; i < (start + max) && i < (sortedResources.length); i++) { Entry entry = createAtomResourceEntry(website, sortedResources[i]); atomEntries.add(entry); if (count == 0) { // first entry is most recent feed.setUpdated(entry.getUpdated()); } count++; } List otherLinks = new ArrayList(); if (start + count < files.size()) { // add next link int nextOffset = start + max; String url = atomURL + "/" + website.getHandle() + "/resources/" + path + nextOffset; Link nextLink = new Link(); nextLink.setRel("next"); nextLink.setHref(url); otherLinks.add(nextLink); } if (start > 0) { // add previous link int prevOffset = start > max ? start - max : 0; String url = atomURL + "/" + website.getHandle() + "/resources/" + path + prevOffset; Link prevLink = new Link(); prevLink.setRel("previous"); prevLink.setHref(url); otherLinks.add(prevLink); } feed.setOtherLinks(otherLinks); feed.setEntries(atomEntries); log.debug("Collection contains: " + count); } else { log.debug("Returning empty collection"); } log.debug("Exiting"); return feed; } catch (WebloggerException re) { throw new AtomException("Getting resource collection", re); } }
From source file:com.microsoft.tfs.client.common.ui.teamexplorer.internal.pendingchanges.PendingChangesViewModel.java
private void updateCheckinNoteFieldDefinitions(final String[] teamProjectPaths) { final CheckinNoteFieldDefinition[] definitions; if ((workspace != null && workspace.getLocation() == WorkspaceLocation.LOCAL && workspace.getClient().getConnection().getConnectivityFailureOnLastWebServiceCall()) || teamProjectPaths == null || teamProjectPaths.length == 0) { definitions = new CheckinNoteFieldDefinition[0]; } else {/*from www. j a va2 s. c o m*/ final VersionControlClient client = repository.getVersionControlClient(); final SortedSet<CheckinNoteFieldDefinition> set = client .queryCheckinNoteFieldDefinitionsForServerPaths(teamProjectPaths); definitions = set.toArray(new CheckinNoteFieldDefinition[set.size()]); } if (checkinNotesDiffer(checkinNoteFieldDefinitions, definitions)) { checkinNoteFieldDefinitions = definitions; fireCheckinNoteFieldDefinitionsChangedEvent(); } }
From source file:de.ailis.xadrian.data.Complex.java
/** * Adds the factories needed to fulfill the need of the specified complex * ware./*from w w w . ja va 2 s. c om*/ * * @param complexWare * The complex ware for which factories must be added * @param race * The race from which factories should be bought. If null then * the cheapest factory is used. * @return True if a new factories were added, false if this was not * possible */ private boolean addBaseComplexForWare(final ComplexWare complexWare, final Race race) { final Ware ware = complexWare.getWare(); final FactoryFactory factoryFactory = this.game.getFactoryFactory(); // Remove all automatically added factories which produces the // specified ware and calculate the real need which must be // fulfilled. double need = complexWare.getMissing(); final double oldNeed = need; for (final ComplexFactory complexFactory : new ArrayList<ComplexFactory>(this.autoFactories)) { if (complexFactory.getFactory().getProduct().getWare().equals(ware)) { need += complexFactory.getProductPerHour(getSuns()).getQuantity(); this.autoFactories.remove(complexFactory); } } // Determine the available factory sizes final SortedSet<FactorySize> sizesSet = factoryFactory.getFactorySizes(ware, race); final FactorySize[] sizes = sizesSet.toArray(new FactorySize[sizesSet.size()]); // Abort if no factories were found if (sizes.length == 0) return false; // Get the cheapest factories for the sizes final Map<FactorySize, Factory> factories = new HashMap<FactorySize, Factory>(); for (final FactorySize size : sizes) { if (race == null) factories.put(size, factoryFactory.getCheapestFactory(ware, size)); else factories.put(size, factoryFactory.getFactory(ware, size, race)); } // Get the smallest possible production quantity final double minProduction = factories.get(sizes[0]).getProductPerHour(getSuns(), 0).getQuantity(); // Iterate the available sizes (from largest to smallest) and add // the factories producing an adequate number of products for (int i = sizes.length - 1; i >= 0; i--) { final FactorySize size = sizes[i]; final Factory factory = factories.get(size); final double product = factory.getProductPerHour(getSuns(), 0).getQuantity(); // Calculate the number of factories of the current size needed log.debug("Need " + need + " units of " + ware + ". Considering " + factory + " which produces " + product + " units"); final int quantity = (int) Math.floor((need + minProduction - 0.1) / product); // Add the number of factories and decrease the need if (quantity > 0) { log.debug("Adding " + quantity + "x " + factory); this.autoFactories.add(new ComplexFactory(this.game, factory, quantity, 0)); need -= quantity * product; } else log.debug("Not adding any " + factory); } if (Math.abs(need - oldNeed) < .0000001) { log.debug("Unable to calculate best matching factory. Aborting"); return false; } return true; }
From source file:org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder.java
/** * Performs a match uses reverse mappings to looks up a mapping from the * controller, action and params. This is refactored to use a list of mappings * identified by only controller and action and then matches the mapping to select * the mapping that best matches the params (most possible matches). * * * @param controller The controller name * @param action The action name/*from ww w . j a v a 2 s . c om*/ * @param httpMethod The HTTP method * @param version * @param params The params @return A UrlMapping instance or null */ @SuppressWarnings("unchecked") protected UrlMapping lookupMapping(String controller, String action, String namespace, String pluginName, String httpMethod, String version, Map params) { final UrlMappingsListKey lookupKey = new UrlMappingsListKey(controller, action, namespace, pluginName, httpMethod, version); SortedSet mappingKeysSet = mappingsListLookup.get(lookupKey); final String actionName = lookupKey.action; boolean secondAttempt = false; final boolean isIndexAction = GrailsControllerClass.INDEX_ACTION.equals(actionName); if (null == mappingKeysSet) { lookupKey.httpMethod = UrlMapping.ANY_HTTP_METHOD; mappingKeysSet = mappingsListLookup.get(lookupKey); } if (null == mappingKeysSet && actionName != null) { lookupKey.action = null; mappingKeysSet = mappingsListLookup.get(lookupKey); secondAttempt = true; } if (null == mappingKeysSet) return null; Set<String> lookupParams = new HashSet<String>(params.keySet()); if (secondAttempt) { lookupParams.removeAll(DEFAULT_ACTION_PARAMS); lookupParams.addAll(DEFAULT_ACTION_PARAMS); } UrlMappingKey[] mappingKeys = (UrlMappingKey[]) mappingKeysSet .toArray(new UrlMappingKey[mappingKeysSet.size()]); for (int i = mappingKeys.length; i > 0; i--) { UrlMappingKey mappingKey = mappingKeys[i - 1]; if (lookupParams.containsAll(mappingKey.paramNames)) { final UrlMapping mapping = mappingsLookup.get(mappingKey); if (canInferAction(actionName, secondAttempt, isIndexAction, mapping)) { return mapping; } if (!secondAttempt) { return mapping; } } } return null; }
From source file:org.apache.geode.management.internal.beans.DistributedSystemBridge.java
/** * @return a list of region names hosted on the system *///from w ww . j a v a 2s .c o m public String[] listAllRegionPaths() { if (distrRegionMap.values().size() == 0) { return ManagementConstants.NO_DATA_STRING; } // Sort region paths SortedSet<String> regionPathsSet = new TreeSet<>(); for (DistributedRegionBridge bridge : distrRegionMap.values()) { regionPathsSet.add(bridge.getFullPath()); } String[] regionPaths = new String[regionPathsSet.size()]; regionPaths = regionPathsSet.toArray(regionPaths); regionPathsSet.clear(); return regionPaths; }
From source file:org.cloudata.core.tabletserver.Tablet.java
public Row.Key[] getSplitedRowKeyRanges(int splitPerTablet) throws IOException { if (splitPerTablet < 0) { return null; }/*from ww w . j a va2s . c om*/ SortedSet<Row.Key> memoryRowKeys = memorySSTable.getAllRowKeys(); SortedSet<MapFileIndexRecord> indexRecords = diskSSTable.get().getMapFileIndex(); SortedSet<Row.Key> rowKeys = null; int memoryRowKeySize = memoryRowKeys.size(); int indexSize = indexRecords.size(); if (indexSize > 0 && memoryRowKeySize > indexSize * 2) { rowKeys = new TreeSet<Row.Key>(); int gap = memoryRowKeySize / indexSize; Row.Key[] rowKeyArr = new Row.Key[memoryRowKeySize]; memoryRowKeys.toArray(rowKeyArr); for (int i = 0; i < indexSize; i++) { rowKeys.add(rowKeyArr[(i + 1) * gap - 1]); } } else { rowKeys = memoryRowKeys; } for (MapFileIndexRecord eachIndex : indexRecords) { rowKeys.add(eachIndex.getRowKey()); } int rowKeySize = rowKeys.size(); if (splitPerTablet >= rowKeySize) { return rowKeys.toArray(new Row.Key[] {}); } else { Row.Key[] result = new Row.Key[splitPerTablet]; Row.Key[] rowKeyArr = new Row.Key[rowKeySize]; rowKeys.toArray(rowKeyArr); int gap = rowKeySize / splitPerTablet; for (int i = 0; i < splitPerTablet - 1; i++) { result[i] = rowKeyArr[(i + 1) * gap]; } result[splitPerTablet - 1] = tabletInfo.getEndRowKey(); return result; } }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
public String getOccurrenceWeeksAsString() { final SortedSet<Integer> weeks = new TreeSet<Integer>(); final ExecutionCourse executionCourse = getExecutionCourse(); final YearMonthDay firstPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getLeft(); final YearMonthDay lastPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getRight(); for (final Interval interval : getAllLessonIntervals()) { final Integer week = Weeks.weeksBetween(firstPossibleLessonDay, interval.getStart().toLocalDate()) .getWeeks() + 1;/*from w w w . j a v a 2 s .c om*/ weeks.add(week); } final StringBuilder builder = new StringBuilder(); final Integer[] weeksA = weeks.toArray(new Integer[0]); for (int i = 0; i < weeksA.length; i++) { if (i == 0) { builder.append(weeksA[i]); } else if (i == weeksA.length - 1 || (weeksA[i]) + 1 != (weeksA[i + 1])) { final String seperator = (weeksA[i - 1]) + 1 == (weeksA[i]) ? " - " : ", "; builder.append(seperator); builder.append(weeksA[i]); } else if ((weeksA[i - 1]) + 1 != weeksA[i]) { builder.append(", "); builder.append(weeksA[i]); } } return builder.toString(); }
From source file:net.sf.jasperreports.engine.xml.JRXmlWriter.java
/** * Writes out the contents of a series colors block for a chart. Assumes the caller * has already written the <code><seriesColors></code> tag. * * @param seriesColors the colors to write *//*from w ww . ja v a2 s. c om*/ private void writeSeriesColors(SortedSet seriesColors) throws IOException { if (seriesColors == null || seriesColors.size() == 0) return; JRSeriesColor[] colors = (JRSeriesColor[]) seriesColors.toArray(new JRSeriesColor[0]); for (int i = 0; i < colors.length; i++) { writer.startElement(JRXmlConstants.ELEMENT_seriesColor); writer.addAttribute(JRXmlConstants.ATTRIBUTE_seriesOrder, colors[i].getSeriesOrder()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_color, colors[i].getColor()); writer.closeElement(); } }