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

The following are Jave code examples for showing how to use toArray() of the java.util.SortedSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: SingleModuleProperties.java   View Source Code Vote up 6 votes
/**
 * Returns sorted arrays of CNBs of available friends for this module.
 */
String[] getAvailableFriends() {
    SortedSet<String> set = new TreeSet<String>();
    if (isSuiteComponent()) {
        for (Iterator it = SuiteUtils.getSubProjects(getSuite()).iterator(); it.hasNext();) {
            Project prj = (Project) 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 it = deps.iterator(); it.hasNext();) {
            ModuleDependency dep = (ModuleDependency) 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
Project: incubator-netbeans   File: SingleModuleProperties.java   View Source Code Vote up 6 votes
String[] getAllTokens() {
    if (allTokens == null) {
        try {
            SortedSet<String> provTokens = new TreeSet<String>();
            provTokens.addAll(Arrays.asList(IDE_TOKENS));
            for (ModuleEntry me : getModuleList().getAllEntries()) {
                provTokens.addAll(Arrays.asList(me.getProvidedTokens()));
            }
            String[] result = new String[provTokens.size()];
            return provTokens.toArray(result);
        } catch (IOException e) {
            allTokens = new String[0];
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
        }
    }
    return allTokens;
}
 
Example 3
Project: incubator-netbeans   File: CreatedModifiedFiles.java   View Source Code Vote up 6 votes
@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 4
Project: vexillo   File: EncodingNode.java   View Source Code Vote up 6 votes
public EncodingNode(String[] ids, CodeSequence[] seqs) {
	SortedSet<String> idSet = new TreeSet<String>();
	SortedSet<String> nidSet = new TreeSet<String>();
	for (int i = 0; i < ids.length; i++) {
		String nid = ids[i].toLowerCase().replaceAll("[^a-z0-9]+", "");
		if (ids[i].length() > 0 && nid.length() > 0) {
			if (idSet.contains(ids[i])) throw new IllegalArgumentException("Duplicate id: " + ids[i]);
			if (nidSet.contains(nid)) throw new IllegalArgumentException("Duplicate id:" + nid);
			idSet.add(ids[i]);
			nidSet.add(nid);
		}
	}
	if (idSet.isEmpty() || nidSet.isEmpty()) throw new IllegalArgumentException("No ids");
	this.ids = idSet.toArray(new String[idSet.size()]);
	this.nids = nidSet.toArray(new String[nidSet.size()]);
	SortedSet<CodeSequence> seqSet = new TreeSet<CodeSequence>();
	for (int i = 0; i < seqs.length; i++) {
		if (seqs[i].length() > 0) {
			if (seqSet.contains(seqs[i])) throw new IllegalArgumentException("Duplicate code sequence: " + seqs[i]);
			seqSet.add(seqs[i]);
		}
	}
	if (seqSet.isEmpty()) throw new IllegalArgumentException("No code sequences");
	this.seqs = seqSet.toArray(new CodeSequence[seqSet.size()]);
}
 
Example 5
Project: monarch   File: DistributedSystemBridge.java   View Source Code Vote up 6 votes
/**
 *
 * @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 6
Project: ditb   File: BalancerTestBase.java   View Source Code Vote up 6 votes
protected String printMock(List<ServerAndLoad> balancedCluster) {
  SortedSet<ServerAndLoad> sorted = new TreeSet<ServerAndLoad>(balancedCluster);
  ServerAndLoad[] arr = sorted.toArray(new ServerAndLoad[sorted.size()]);
  StringBuilder sb = new StringBuilder(sorted.size() * 4 + 4);
  sb.append("{ ");
  for (int i = 0; i < arr.length; i++) {
    if (i != 0) {
      sb.append(" , ");
    }
    sb.append(arr[i].getServerName().getHostname());
    sb.append(":");
    sb.append(arr[i].getLoad());
  }
  sb.append(" }");
  return sb.toString();
}
 
Example 7
Project: incubator-netbeans   File: ProjectAssociationAction.java   View Source Code Vote up 5 votes
@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 8
Project: rapidminer   File: AssociationRules.java   View Source Code Vote up 5 votes
public Item[] getAllConclusionItems() {
	SortedSet<Item> conclusions = new TreeSet<Item>();
	for (AssociationRule rule : this) {
		Iterator<Item> i = rule.getConclusionItems();
		while (i.hasNext()) {
			conclusions.add(i.next());
		}
	}
	Item[] itemArray = new Item[conclusions.size()];
	conclusions.toArray(itemArray);
	return itemArray;
}
 
Example 9
Project: vexillo   File: EncodingNode.java   View Source Code Vote up 5 votes
public EncodingNode(String ids, String seqs) {
	SortedSet<String> idSet = new TreeSet<String>();
	SortedSet<String> nidSet = new TreeSet<String>();
	String[] idsArray = ids.split("(\\s|;)+");
	for (String id : idsArray) {
		String nid = id.toLowerCase().replaceAll("[^a-z0-9]+", "");
		if (id.length() > 0 && nid.length() > 0) {
			if (idSet.contains(id)) throw new IllegalArgumentException("Duplicate id: " + id);
			if (nidSet.contains(nid)) throw new IllegalArgumentException("Duplicate id:" + nid);
			idSet.add(id);
			nidSet.add(nid);
		}
	}
	if (idSet.isEmpty() || nidSet.isEmpty()) throw new IllegalArgumentException("No ids");
	this.ids = idSet.toArray(new String[idSet.size()]);
	this.nids = nidSet.toArray(new String[nidSet.size()]);
	SortedSet<CodeSequence> seqSet = new TreeSet<CodeSequence>();
	String[] seqsArray = seqs.split("(\\s|;)+");
	for (String seqString : seqsArray) {
		CodeSequence seq = new CodeSequence(seqString);
		if (seq.length() > 0) {
			if (seqSet.contains(seq)) throw new IllegalArgumentException("Duplicate code sequence: " + seq);
			seqSet.add(seq);
		}
	}
	if (seqSet.isEmpty()) throw new IllegalArgumentException("No code sequences");
	this.seqs = seqSet.toArray(new CodeSequence[seqSet.size()]);
}
 
Example 10
Project: changApp   File: TileContentFragment.java   View Source Code Vote up 5 votes
public ContentAdapter(Context context) {
    mChangasReference = FirebaseDatabase.getInstance().getReference("changas");
    ValueEventListener changaListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            SortedSet<Integer> ids = new TreeSet<>();
            for (DataSnapshot changaSnapshot: dataSnapshot.getChildren()) {
                Changa changa = changaSnapshot.getValue(Changa.class);
                ids.add(changa.category);
            }
            LENGTH = ids.size();
            mIDS = new Integer[LENGTH];
            ids.toArray(mIDS);

            notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
        }
    };
    mChangasReference.addValueEventListener(changaListener);

    Resources resources = context.getResources();

    mChangasTitle = resources.getStringArray(R.array.array_categories);

    TypedArray a = resources.obtainTypedArray(R.array.changas_imgs);
    mChangasPictures = new Drawable[a.length()];
    for (int i = 0; i < a.length(); i++) {
        mChangasPictures[i] = a.getDrawable(i);
    }
    a.recycle();
}
 
Example 11
Project: ChronoBike   File: OnlineEnvironment.java   View Source Code Vote up 5 votes
public Document getXMLDisplay()
	{
		Document doc = createNewDocument() ;
		FieldComparator comp = new FieldComparator() ;
		SortedSet<Element> setFields = new TreeSet<Element>(comp) ;
//		if (m_SendMapOrder != null)
//		{
//			Form form = m_SendMapOrder.m_varFrom ;
//		}
		
		Element eRoot = createNewFormBody(doc, "CESM", "CESM") ;
		Element eBody = createVBox(doc, eRoot);
		int nb = setFields.size() ;
		Element[] arr = new Element[nb] ;
		setFields.toArray(arr);
		int curline = 0 ;
		int curCol = 0 ;
		Element curLineElem = null ;
		for (int i=0; i<nb; i++)
		{
			Element f = arr[i] ;
			int nl = NumberParser.getAsInt(f.getAttribute("PosLine"));
			if (curline != nl)
			{
				curLineElem = createHBox(doc, eBody);
				curline = nl ;
				curCol = 1 ;
			}
			int nc = NumberParser.getAsInt(f.getAttribute("PosCol"));
			int nlen = NumberParser.getAsInt(f.getAttribute("Length"));
			if (nc > curCol +1)
			{
				createBlank(doc, curLineElem, nc - curCol) ;
			}
			curCol = nc + nlen ;
			curLineElem.appendChild(f);
		}
		
		return doc;
	}
 
Example 12
Project: hadoop   File: InMemoryNativeFileSystemStore.java   View Source Code Vote up 5 votes
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
Project: VASSAL-src   File: DataArchive.java   View Source Code Vote up 4 votes
public String[] getImageNames() {
  final SortedSet<String> s = getImageNameSet();
  return s.toArray(new String[s.size()]);
}
 
Example 14
Project: incubator-netbeans   File: PackageView.java   View Source Code Vote up 3 votes
/**
 * 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 15
Project: incubator-netbeans   File: NbPlatform.java   View Source Code Vote up 3 votes
/**
 * 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;
}
 
Example 16
Project: HCFCore   File: TransformedSortedSet.java   View Source Code Vote up 3 votes
/**
 * Factory method to create a transforming sorted set that will transform
 * existing contents of the specified sorted set.
 * <p>
 * If there are any elements already in the set being decorated, they
 * will be transformed by this method.
 * Contrast this with {@link #transformingSortedSet(SortedSet, Transformer)}.
 *
 * @param <E> the element type
 * @param set  the set to decorate, must not be null
 * @param transformer  the transformer to use for conversion, must not be null
 * @return a new transformed {@link SortedSet}
 * @throws NullPointerException if set or transformer is null
 * @since 4.0
 */
public static <E> TransformedSortedSet<E> transformedSortedSet(final SortedSet<E> set,
        final Transformer<? super E, ? extends E> transformer) {

    final TransformedSortedSet<E> decorated = new TransformedSortedSet<E>(set, transformer);
    if (set.size() > 0) {
        @SuppressWarnings("unchecked") // set is type E
        final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
        set.clear();
        for (final E value : values) {
            decorated.decorated().add(transformer.transform(value));
        }
    }
    return decorated;
}
 
Example 17
Project: HCFCore   File: TransformedSortedSet.java   View Source Code Vote up 3 votes
/**
 * Factory method to create a transforming sorted set that will transform
 * existing contents of the specified sorted set.
 * <p>
 * If there are any elements already in the set being decorated, they
 * will be transformed by this method.
 * Contrast this with {@link #transformingSortedSet(SortedSet, Transformer)}.
 *
 * @param <E> the element type
 * @param set  the set to decorate, must not be null
 * @param transformer  the transformer to use for conversion, must not be null
 * @return a new transformed {@link SortedSet}
 * @throws NullPointerException if set or transformer is null
 * @since 4.0
 */
public static <E> TransformedSortedSet<E> transformedSortedSet(final SortedSet<E> set,
        final Transformer<? super E, ? extends E> transformer) {

    final TransformedSortedSet<E> decorated = new TransformedSortedSet<E>(set, transformer);
    if (set.size() > 0) {
        @SuppressWarnings("unchecked") // set is type E
        final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
        set.clear();
        for (final E value : values) {
            decorated.decorated().add(transformer.transform(value));
        }
    }
    return decorated;
}