Java Code Examples for java.util.SortedSet#toArray()

The following examples show how to use java.util.SortedSet#toArray() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   File: SingleModuleProperties.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns sorted arrays of CNBs of available friends for this module.
 */
String[] getAvailableFriends() {
    SortedSet<String> set = new TreeSet<String>();
    if (isSuiteComponent()) {
        for (Iterator<NbModuleProject> it = SuiteUtils.getSubProjects(getSuite()).iterator(); it.hasNext();) {
            Project prj = it.next();
            String cnb = ProjectUtils.getInformation(prj).getName();
            if (!getCodeNameBase().equals(cnb)) {
                set.add(cnb);
            }
        }
    } else if (isNetBeansOrg()) {
        Set<ModuleDependency> deps = getUniverseDependencies(false);
        for (Iterator<ModuleDependency> it = deps.iterator(); it.hasNext();) {
            ModuleDependency dep = it.next();
            set.add(dep.getModuleEntry().getCodeNameBase());
        }
    } // else standalone module - leave empty (see the UI spec)
    return set.toArray(new String[set.size()]);
}
 
Example 2
Source Project: netbeans   File: CreatedModifiedFiles.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String[] getCreatedPaths() {
    LayerHandle handle = cmf.getLayerHandle();
    FileObject layer = handle.getLayerFile();
    String layerPath = layer != null
            ? FileUtil.getRelativePath(project.getProjectDirectory(), layer)
            : project.getLookup().lookup(NbModuleProvider.class).getResourceDirectoryPath(false) + '/' + handle.newLayerPath();
    int slash = layerPath.lastIndexOf('/');
    String prefix = layerPath.substring(0, slash + 1);
    SortedSet<String> s = new TreeSet<String>();
    if (layer == null) {
        s.add(layerPath);
    }
    for (String file : externalFiles) {
        s.add(prefix + file);
    }
    return s.toArray(new String[s.size()]);
}
 
Example 3
/**
 *
 * @return a list of region names hosted on the system
 */
public String[] listAllRegionPaths() {
  if (distrRegionMap.values().size() == 0) {
    return ManagementConstants.NO_DATA_STRING;
  }
  // Sort region paths
  SortedSet<String> regionPathsSet = new TreeSet<String>();
  for (DistributedRegionBridge bridge : distrRegionMap.values()) {
    regionPathsSet.add(bridge.getFullPath());
  }
  String[] regionPaths = new String[regionPathsSet.size()];
  regionPaths = regionPathsSet.toArray(regionPaths);
  regionPathsSet.clear();

  return regionPaths;
}
 
Example 4
/**
 * Writes out the contents of a series colors block for a chart.  Assumes the caller
 * has already written the <code>&lt;seriesColors&gt;</code> tag.
 *
 * @param seriesColors the colors to write
 */
private void writeSeriesColors(SortedSet<JRSeriesColor> seriesColors) throws IOException
{
	if (seriesColors == null || seriesColors.size() == 0)
	{
		return;
	}
	//FIXME why do we need an array?
	JRSeriesColor[] colors = seriesColors.toArray(new JRSeriesColor[seriesColors.size()]);
	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();
	}
}
 
Example 5
/**
 * Writes out the contents of a series colors block for a chart.  Assumes the caller
 * has already written the <code>&lt;seriesColors&gt;</code> tag.
 *
 * @param seriesColors the colors to write
 */
private void writeSeriesColors( SortedSet<JRSeriesColor> seriesColors, String parentName)
{
	if (seriesColors == null || seriesColors.size() == 0)
	{
		return;
	}
	//FIXME why do we need an array?
	JRSeriesColor[] colors = seriesColors.toArray(new JRSeriesColor[seriesColors.size()]);
	for (int i = 0; i < colors.length; i++)
	{
		String seriesColorName = parentName + "SeriesColor" +i;
		write( "JRBaseSeriesColor " + seriesColorName + " = new JRBaseSeriesColor(" + colors[i].getSeriesOrder() +", {0});\n", colors[i].getColor());
		write( parentName + ".addSeriesColor(" + seriesColorName + ");\n");
		flush();
	}
}
 
Example 6
public static String prettyPrintWeeks(SortedSet<Integer> weeks) {
    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();

}
 
Example 7
/**
 *
 * @return a list of region names hosted on the system
 */
public String[] listAllRegionPaths() {
  if (distrRegionMap.values().size() == 0) {
    return ManagementConstants.NO_DATA_STRING;
  }
  // Sort region paths
  SortedSet<String> regionPathsSet = new TreeSet<String>();
  for (DistributedRegionBridge bridge : distrRegionMap.values()) {
    regionPathsSet.add(bridge.getFullPath());
  }
  String[] regionPaths = new String[regionPathsSet.size()];
  regionPaths = regionPathsSet.toArray(regionPaths);
  regionPathsSet.clear();

  return regionPaths;
}
 
Example 8
Source Project: bigtable-sql   File: WhereClausePanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A JPanel used for a bulk of the GUI elements of the panel.
 *
 * @param	columnList	A list of the column names for the table.
 * @param	tableName	The name of the database table.
 */
WhereClauseSubPanel(SortedSet<String> columnList, 
                    Map<String, Boolean> textColumns,
				    String tableName)
{
	_tableName = tableName;
	_columnCombo = new JComboBox(columnList.toArray());
	_textColumns = textColumns;
	createGUI();
}
 
Example 9
@Override
public void mouseClicked(MouseEvent e) {
    int x = (int) (e.getX() / interval);

    final Map<Integer, DatabaseStatistics.YearData> yearDataMap = stats.getYearDataMap();
    final SortedSet<Integer> sortedYears = new TreeSet<>(yearDataMap.keySet());
    final Integer[] years = sortedYears.toArray(new Integer[sortedYears.size()]);
    final DatabaseStatistics.YearData yearData = yearDataMap.get(years[x]);

    yearData.setSelected(!yearData.isSelected());

    repaint();
}
 
Example 10
void setAttacker(final MagicGame game,final Set<MagicCombatCreature> blockers) {
    final SortedSet<MagicCombatCreature> candidateBlockersSet =
            new TreeSet<>(new BlockerComparator(this));
    for (final MagicCombatCreature blocker : blockers) {
        if (blocker.permanent.canBlock(permanent)) {
            candidateBlockersSet.add(blocker);
        }
    }
    candidateBlockers=new MagicCombatCreature[candidateBlockersSet.size()];
    candidateBlockersSet.toArray(candidateBlockers);

    attackerScore=ArtificialScoringSystem.getAttackerScore(this);
}
 
Example 11
@Messages({
    "ProjectAssociationAction.open_some_projects=Open some projects to choose from.",
    "ProjectAssociationAction.title_select_project=Select Project",
    "ProjectAssociationAction.could_not_associate=Failed to record a Hudson job association.",
    "ProjectAssociationAction.could_not_dissociate=Failed to find the Hudson job association to be removed."
})
@Override public void actionPerformed(ActionEvent e) {
    if (alreadyAssociatedProject == null) {
        SortedSet<Project> projects = new TreeSet<Project>(ProjectRenderer.comparator());
        projects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
        if (projects.isEmpty()) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_open_some_projects(), NotifyDescriptor.INFORMATION_MESSAGE));
            return;
        }
        JComboBox box = new JComboBox(new DefaultComboBoxModel(projects.toArray(new Project[projects.size()])));
        box.setRenderer(new ProjectRenderer());
        if (DialogDisplayer.getDefault().notify(new NotifyDescriptor(box, Bundle.ProjectAssociationAction_title_select_project(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.PLAIN_MESSAGE, null, null)) != NotifyDescriptor.OK_OPTION) {
            return;
        }
        if (!ProjectHudsonProvider.getDefault().recordAssociation((Project) box.getSelectedItem(), assoc)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_could_not_associate(), NotifyDescriptor.WARNING_MESSAGE));
        }
    } else {
        if (!ProjectHudsonProvider.getDefault().recordAssociation(alreadyAssociatedProject, null)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_could_not_dissociate(), NotifyDescriptor.WARNING_MESSAGE));
        }
    }
}
 
Example 12
private PartialListing list(String prefix, String delimiter,
    int maxListingLength, String priorLastKey) throws IOException {

  if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) {
    prefix += PATH_DELIMITER;
  }
  
  List<FileMetadata> metadata = new ArrayList<FileMetadata>();
  SortedSet<String> commonPrefixes = new TreeSet<String>();
  for (String key : dataMap.keySet()) {
    if (key.startsWith(prefix)) {
      if (delimiter == null) {
        metadata.add(retrieveMetadata(key));
      } else {
        int delimIndex = key.indexOf(delimiter, prefix.length());
        if (delimIndex == -1) {
          metadata.add(retrieveMetadata(key));
        } else {
          String commonPrefix = key.substring(0, delimIndex);
          commonPrefixes.add(commonPrefix);
        }
      }
    }
    if (metadata.size() + commonPrefixes.size() == maxListingLength) {
      new PartialListing(key, metadata.toArray(new FileMetadata[0]),
          commonPrefixes.toArray(new String[0]));
    }
  }
  return new PartialListing(null, metadata.toArray(new FileMetadata[0]),
      commonPrefixes.toArray(new String[0]));
}
 
Example 13
private PartialListing list(String prefix, String delimiter,
    int maxListingLength, String priorLastKey) throws IOException {

  if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) {
    prefix += PATH_DELIMITER;
  }
  
  List<FileMetadata> metadata = new ArrayList<FileMetadata>();
  SortedSet<String> commonPrefixes = new TreeSet<String>();
  for (String key : dataMap.keySet()) {
    if (key.startsWith(prefix)) {
      if (delimiter == null) {
        metadata.add(retrieveMetadata(key));
      } else {
        int delimIndex = key.indexOf(delimiter, prefix.length());
        if (delimIndex == -1) {
          metadata.add(retrieveMetadata(key));
        } else {
          String commonPrefix = key.substring(0, delimIndex);
          commonPrefixes.add(commonPrefix);
        }
      }
    }
    if (metadata.size() + commonPrefixes.size() == maxListingLength) {
      new PartialListing(key, metadata.toArray(new FileMetadata[0]),
          commonPrefixes.toArray(new String[0]));
    }
  }
  return new PartialListing(null, metadata.toArray(new FileMetadata[0]),
      commonPrefixes.toArray(new String[0]));
}
 
Example 14
Source Project: gemfirexd-oss   File: ServerGroupUtils.java    License: Apache License 2.0 5 votes vote down vote up
/** get the server groups of this VM as an array */
public static String[] getMyGroupsArray() {
  final SortedSet<String> vmGroups = Misc.getMemStore().getAdvisee()
      .getServerGroups();
  String[] groups = new String[vmGroups.size()];
  return vmGroups.toArray(groups);
}
 
Example 15
Source Project: cosmic   File: IpAddressManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@DB
public String acquireGuestIpAddress(final Network network, final String requestedIp) {
    if (requestedIp != null && requestedIp.equals(network.getGateway())) {
        s_logger.warn("Requested ip address " + requestedIp + " is used as a gateway address in network " + network);
        return null;
    }

    final SortedSet<Long> availableIps = _networkModel.getAvailableIps(network, requestedIp);

    if (availableIps == null || availableIps.isEmpty()) {
        s_logger.debug("There are no free ips in the  network " + network);
        return null;
    }

    final Long[] array = availableIps.toArray(new Long[availableIps.size()]);

    if (requestedIp != null) {
        // check that requested ip has the same cidr
        final String[] cidr = network.getCidr().split("/");
        final boolean isSameCidr = NetUtils.sameSubnetCIDR(requestedIp, NetUtils.long2Ip(array[0]), Integer.parseInt(cidr[1]));
        if (!isSameCidr) {
            s_logger.warn("Requested ip address " + requestedIp + " doesn't belong to the network " + network + " cidr");
            return null;
        } else if (NetUtils.IsIpEqualToNetworkOrBroadCastIp(requestedIp, cidr[0], Integer.parseInt(cidr[1]))) {
            s_logger.warn("Requested ip address " + requestedIp + " is equal to the to the network/broadcast ip of the network" + network);
            return null;
        }
        return requestedIp;
    }

    return NetUtils.long2Ip(array[_rand.nextInt(array.length)]);
}
 
Example 16
protected Bundle[] getAndSortBundles()
{
  final Bundle[] bl = Activator.getBundles();
  final SortedSet<Bundle> set = new TreeSet<Bundle>(Util.bundleIdComparator);
  for (final Bundle element : bl) {
    set.add(element);
  }

  set.toArray(bl);

  return bl;
}
 
Example 17
Source Project: gemfirexd-oss   File: TableMBeanBridge.java    License: Apache License 2.0 4 votes vote down vote up
public String[] getServerGroups() {
  SortedSet<String> serverGroups = ServerGroupUtils.getServerGroupsFromContainer(this.container);
  return serverGroups.toArray(ManagementUtils.EMPTY_STRING_ARRAY);
}
 
Example 18
/**
 * Load all targeted factory configuration instances and update user interface
 * to show them.
 *
 * @param selectedPid
 *          If this PID is available then select it, otherwise select the last
 *          PID. If {@link #nextFactoryPidToSelect} is non-null then select
 *          that configuration instance and set the field to {@code null}.
 */
private void updateSelectionFactoryPID(String selectedPid)
{
  synchronized (pid2Cfg) {
    pid2Cfg.clear();
    if (selectedPid == null) {
      selectedPid = "";
    }

    for (int i = 0; i < MAX_SIZE; i++) {
      try {
        final Configuration[] configs =
          CMDisplayer.getCA().listConfigurations("(service.factoryPid="
                                                     + targetedPids[i] + ")");
        if (configs != null) {
          for (final Configuration cfg : configs) {
            pid2Cfg.put(cfg.getPid(), cfg);
          }
        }
      } catch (final Exception e) {
        Activator.log
            .error("Faile to load factory configuration instances for fpid '"
                   + targetedPids[i] + "': " + e.getMessage(), e);
      }
    }

    final SortedSet<String> instancePIDs =
      new TreeSet<String>(pid2Cfg.keySet());
    instancePIDs.add(FACTORY_PID_DEFAULTS);

    final DefaultComboBoxModel model =
      new DefaultComboBoxModel(instancePIDs.toArray());
    if (nextFactoryPidToSelect != null) {
      if (instancePIDs.contains(nextFactoryPidToSelect)) {
        selectedPid = nextFactoryPidToSelect;
      }
      nextFactoryPidToSelect = null;
    } else if (!instancePIDs.contains(selectedPid)) {
      // New selection needed, use last PID.
      selectedPid = (String) model.getElementAt(model.getSize() - 1);
    }
    model.setSelectedItem(selectedPid);
    fbox.setModel(model);
    final Configuration selectedCfg = pid2Cfg.get(selectedPid);

    // Update the targeted PID selectors to match the target selectors in the
    // factory PID of the selected instance.
    final String fpid =
      selectedCfg != null ? selectedCfg.getFactoryPid() : targetedPids[0];
    String tpid = null;
    for (int i = 0; i < MAX_SIZE && null != (tpid = targetedPids[i]); i++) {
      rbs[i].setToolTipText(TARGET_LEVEL_FACOTRY_PID_TOOLTIPS[i] + tpid
                            + "</code></p></html>");

      if (fpid.equals(targetedPids[i])) {
        rbs[i].setSelected(true);
        selectedTargetLevel = i;
        if (selectedCfg != null) {
          icons[i].setIcon(openDocumentIcon);
          icons[i].setToolTipText("exists");
        } else {
          icons[i].setIcon(newDocumentIcon);
          icons[i].setToolTipText("to be created");
        }
      } else {
        icons[i].setIcon(newDocumentIcon);
        icons[i].setToolTipText("to be created");
      }
    }
  }
}
 
Example 19
Source Project: netbeans   File: PackageView.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Create a list or combo box model suitable for {@link javax.swing.JList} from a source group
 * showing all Java packages in the source group.
 * To display it you will also need {@link #listRenderer}.
 * <p>No particular guarantees are made as to the nature of the model objects themselves,
 * except that {@link Object#toString} will give the fully-qualified package name
 * (or <code>""</code> for the default package), regardless of what the renderer
 * actually displays.</p>
 * @param group a Java-like source group
 * @return a model of its packages
 * @since org.netbeans.modules.java.project/1 1.3 
 */

public static ComboBoxModel createListView(SourceGroup group) {
    Parameters.notNull("group", group); //NOI18N
    SortedSet<PackageItem> data = new TreeSet<PackageItem>();
    findNonExcludedPackages(null, data, group.getRootFolder(), group, false);
    return new DefaultComboBoxModel(data.toArray(new PackageItem[data.size()]));
}
 
Example 20
Source Project: netbeans   File: NbPlatform.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Returns (naturally sorted) array of all module entries pertaining to
 * <code>this</code> NetBeans platform. This is just a convenient delegate
 * to the {@link ModuleList#findOrCreateModuleListFromBinaries}.
 *
 * This may be a time-consuming method, consider using much faster
 * ModuleList#getModules instead, which doesn't sort the modules. Do not call
 * from AWT thread (not checked so that it may be used in tests).
 */
public ModuleEntry[] getSortedModules() {
    SortedSet<ModuleEntry> set = new TreeSet<ModuleEntry>(getModules());
    ModuleEntry[] entries = new ModuleEntry[set.size()];
    set.toArray(entries);
    return entries;
}