Example usage for java.util SortedSet toArray

List of usage examples for java.util SortedSet toArray

Introduction

In this page you can find the example usage for java.util SortedSet toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:de.ailis.xadrian.data.Sector.java

/**
 * Returns the ice asteroids of this sector.
 * //from  w  w  w. j  ava 2s.co m
 * @return The ice asteroids
 */
public Asteroid[] getIceAsteroids() {
    final SortedSet<Asteroid> asteroids = new TreeSet<Asteroid>();
    for (final Asteroid asteroid : getAsteroids()) {
        if (asteroid.getWare().isIce()) {
            asteroids.add(asteroid);
        }
    }
    return asteroids.toArray(new Asteroid[asteroids.size()]);
}

From source file:de.ailis.xadrian.data.Sector.java

/**
 * Returns the nividium asteroids of this sector.
 * //from w  w w .  jav a 2  s.  co  m
 * @return The nividium asteroids
 */
public Asteroid[] getNividiumAsteroids() {
    final SortedSet<Asteroid> asteroids = new TreeSet<Asteroid>();
    for (final Asteroid asteroid : getAsteroids()) {
        if (asteroid.getWare().isNividium()) {
            asteroids.add(asteroid);
        }
    }
    return asteroids.toArray(new Asteroid[asteroids.size()]);
}

From source file:de.ailis.xadrian.data.Sector.java

/**
 * Returns the silicon asteroids of this sector.
 * //from w  w  w  . j  a  v a 2s .  c  o  m
 * @return The silicon asteroids
 */
public Asteroid[] getSiliconAsteroids() {
    final SortedSet<Asteroid> asteroids = new TreeSet<Asteroid>();
    for (final Asteroid asteroid : getAsteroids()) {
        if (asteroid.getWare().isSiliconWafers()) {
            asteroids.add(asteroid);
        }
    }
    return asteroids.toArray(new Asteroid[asteroids.size()]);
}

From source file:info.rmapproject.core.rmapservice.impl.openrdf.ORMapDiSCOMgr.java

/**
 * Get IRI of next version of a DiSCO./*from  ww  w.j a  va  2 s .c o  m*/
 *
 * @param discoID  IRI of DISCO
 * @param event2disco Map from events to all versions of DiSCOs
 * @param date2event  Map from date events associated with version of DiSCO
 * @param ts the triplestore instance
 * @return IRI of next version of DiSCO, or null if none found
 * @throws RMapException the RMap exception
 * @throws RMapObjectNotFoundException the RMap object not found exception
 * @throws RMapDefectiveArgumentException the RMap defective argument exception
 */
protected IRI getNextIRI(IRI discoID, Map<IRI, IRI> event2disco, Map<Date, IRI> date2event,
        SesameTriplestore ts)
        throws RMapException, RMapObjectNotFoundException, RMapDefectiveArgumentException {
    if (discoID == null) {
        throw new RMapDefectiveArgumentException("null DiSCO id");
    }
    if (event2disco == null) {
        throw new RMapDefectiveArgumentException("Null event2disco map");
    }
    Map<IRI, IRI> disco2event = Utils.invertMap(event2disco);
    if (date2event == null) {
        date2event = eventmgr.getDate2EventMap(event2disco.keySet(), ts);
    }
    Map<IRI, Date> event2date = Utils.invertMap(date2event);
    IRI discoEventId = disco2event.get(discoID);
    Date eventDate = event2date.get(discoEventId);
    SortedSet<Date> sortedDates = new TreeSet<Date>();
    sortedDates.addAll(date2event.keySet());
    SortedSet<Date> laterDates = sortedDates.tailSet(eventDate);
    IRI nextDiscoId = null;
    if (laterDates.size() > 1) {
        Date[] dateArray = laterDates.toArray(new Date[laterDates.size()]);
        IRI nextEventId = date2event.get(dateArray[1]);
        nextDiscoId = event2disco.get(nextEventId);
    }
    return nextDiscoId;
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Returns a sorted array containing all of the elements in the {@link Set}
 * for the given {@link DeviceProtocolInfoSource}.
 * <p>//from   w ww .j  a  v  a2  s .  com
 * The returned array will be "safe" in that no reference to it is
 * maintained. (In other words, this method must allocate a new array). The
 * caller is thus free to modify the returned array.
 *
 * @param type the {@link DeviceProtocolInfoSource} type whose elements to
 *            convert to an {@code array}.
 * @return An array containing all the {@link ProtocolInfo} instances in the
 *         {@link Set} for {@code type}.
 */
public ProtocolInfo[] toArray(DeviceProtocolInfoSource<?> type) {
    setsLock.readLock().lock();
    try {
        SortedSet<ProtocolInfo> set = protocolInfoSets.get(type);
        return set == null ? null : set.toArray(new ProtocolInfo[protocolInfoSets.size()]);
    } finally {
        setsLock.readLock().unlock();
    }
}

From source file:eu.udig.tools.jgrass.navigationview.NavigationView.java

private void updateData() {
    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            IMap activeMap = ApplicationGIS.getActiveMap();
            ViewportModel viewportModel = (ViewportModel) activeMap.getViewportModel();
            activeMap.addMapListener(NavigationView.this);
            activeMap.addMapCompositionListener(NavigationView.this);

            ReferencedEnvelope bounds = viewportModel.getBounds();

            double west = bounds.getMinX();
            double east = bounds.getMaxX();
            double north = bounds.getMaxY();
            double south = bounds.getMinY();

            if (lowerLeftText.isDisposed()) {
                return;
            }/*from   w  w  w.  j a va2  s.c om*/
            lowerLeftText.setText(numFormatter.format(west) + ", " + numFormatter.format(south));
            upperRightText.setText(numFormatter.format(east) + ", " + numFormatter.format(north));

            canvas.redraw();

            SortedSet<Double> preferredScaleDenominators = viewportModel.getPreferredScaleDenominators();
            Double[] scalesArray = (Double[]) preferredScaleDenominators
                    .toArray(new Double[preferredScaleDenominators.size()]);
            String[] scales = new String[scalesArray.length];
            for (int i = 0; i < scales.length; i++) {
                scales[i] = "1:" + String.valueOf(scalesArray[i]);
            }
            int itemCount = scaleCombo.getItemCount();
            int selectionIndex = scaleCombo.getSelectionIndex();
            scaleCombo.setItems(scales);
            if (scales.length == itemCount) {
                scaleCombo.select(selectionIndex);
            }

            List<DateTime> availableTimesteps = viewportModel.getAvailableTimesteps();
            if (availableTimesteps != null) {
                dateTimeCombo.setEnabled(true);
                dtDownButton.setEnabled(true);
                dtUpButton.setEnabled(true);
                String[] dates = new String[availableTimesteps.size()];
                for (int i = 0; i < dates.length; i++) {
                    dates[i] = ISO_DATE_TIME_FORMATTER.print(availableTimesteps.get(i));
                }
                itemCount = dateTimeCombo.getItemCount();
                selectionIndex = dateTimeCombo.getSelectionIndex();
                dateTimeCombo.setItems(dates);
                if (dates.length == itemCount) {
                    dateTimeCombo.select(selectionIndex);
                }
            } else {
                dateTimeCombo.setEnabled(false);
                dtDownButton.setEnabled(false);
                dtUpButton.setEnabled(false);
            }

            List<Double> availableElevation = viewportModel.getAvailableElevation();
            if (availableElevation != null) {
                verticalCombo.setEnabled(true);
                verticalDownButton.setEnabled(true);
                verticalUpButton.setEnabled(true);
                String[] elev = new String[availableElevation.size()];
                for (int i = 0; i < elev.length; i++) {
                    elev[i] = String.valueOf(availableElevation.get(i));
                }
                itemCount = verticalCombo.getItemCount();
                selectionIndex = verticalCombo.getSelectionIndex();
                verticalCombo.setItems(elev);
                if (elev.length == itemCount) {
                    verticalCombo.select(selectionIndex);
                }
            } else {
                verticalCombo.setEnabled(false);
                verticalDownButton.setEnabled(false);
                verticalUpButton.setEnabled(false);
            }
        }
    });
}

From source file:com.microsoft.tfs.client.common.ui.controls.vc.checkin.NotesCheckinControl.java

private void updateControls() {
    if (dirty == false || updating == true) {
        return;/*  w ww.  j a va2s .com*/
    }

    if (options.getCheckinNotesReadOnly() && (checkinNote == null || checkinNote.getValues().length == 0)) {
        dirty = false;
        updateEmptyControl();
        return;
    } else if (options.getCheckinNotesReadOnly()) {
        dirty = false;
        updateReadOnlyControl();
        return;
    } else if (options.getCheckinNotesHistoric()) {
        /* Set updating to true to suppress modify events */
        dirty = false;
        updating = true;
        fieldControls = updateHistoricControl();
        updating = false;
        return;
    } else if (projects == null || projects.length == 0) {
        dirty = false;
        updateEmptyControl();
        return;
    } else if (repository == null || !ConnectionHelper.isConnected(repository.getConnection())) {
        dirty = false;
        updateEmptyControl();
        return;
    }

    updateEmptyControl();

    updating = true;
    fieldControls = new CheckinNoteFieldControl[0];

    updateBusyControl();

    /*
     * Set dirty now so that we can detect if we need to (again) requery.
     * Another thread may set us dirty.
     */
    dirty = false;

    /*
     * Run a background job that queries the check-in notes for the
     * currently selected projects, and build the note fields on the UI
     * thread.
     */
    final Display display = getDisplay();

    final TFSRepository repository = this.repository;
    final String[] projects = this.projects;

    final Job updateJob = new Job(BUSY_MESSAGE) {
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                if (projects.length == 1) {
                    log.info(MessageFormat.format("Querying checkin notes for project {0}", projects[0])); //$NON-NLS-1$
                } else {
                    log.info("Querying checkin notes for team projects"); //$NON-NLS-1$
                }

                final SortedSet definitionSet = repository.getVersionControlClient()
                        .queryCheckinNoteFieldDefinitionsForServerPaths(projects);
                final CheckinNoteFieldDefinition[] definitions = (CheckinNoteFieldDefinition[]) definitionSet
                        .toArray(new CheckinNoteFieldDefinition[definitionSet.size()]);

                display.asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (definitions == null || definitions.length == 0) {
                                updateEmptyControl();
                            } else {
                                fieldControls = updateFieldControl(definitions);
                            }

                            updateCheckinNote();
                        } finally {
                            updating = false;

                            if (dirty == true) {
                                updateControls();
                            }
                        }
                    }
                });
            } catch (final Exception e) {
                return new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, 0,
                        Messages.getString("NotesCheckinControl.CouldNotQueryNotes"), //$NON-NLS-1$
                        e);
            }

            return Status.OK_STATUS;
        }
    };

    updateJob.schedule();
}

From source file:org.apache.blur.store.hdfs.HdfsDirectory.java

@Override
public String[] listAll() throws IOException {
    LOG.debug("listAll [{0}]", getPath());

    if (_useCache) {
        Set<String> names = new HashSet<String>(_fileStatusMap.keySet());
        return names.toArray(new String[names.size()]);
    }//from  ww w . j  a  va 2 s.  c om

    Tracer trace = Trace.trace("filesystem - list", Trace.param("path", getPath()));
    try {
        FileStatus[] files = _fileSystem.listStatus(getPath(), new PathFilter() {
            @Override
            public boolean accept(Path path) {
                try {
                    return _fileSystem.isFile(path);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        SortedSet<String> result = new TreeSet<String>();
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getPath().getName();
            if (name.endsWith(LNK)) {
                result.add(getRealFileName(name));
            } else {
                result.add(name);
            }
        }
        return result.toArray(new String[result.size()]);
    } finally {
        trace.done();
    }
}

From source file:piecework.engine.activiti.ActivitiEngineProxy.java

@Override
public ProcessExecutionResults findExecutions(SearchCriteria criteria) throws ProcessEngineException {
    if (!criteria.getEngines().contains(getKey()))
        return null;

    HistoricProcessInstanceQuery query = instanceQuery(criteria);

    ProcessExecutionResults.Builder resultsBuilder = new ProcessExecutionResults.Builder();

    List<HistoricProcessInstance> instances;

    // Can't use paging since we're going to filter after the fact
    instances = query.list();//w  ww  . ja  v  a 2 s .co m
    int size = instances.size();

    resultsBuilder.firstResult(0);
    resultsBuilder.maxResults(size);
    resultsBuilder.total(size);

    // Only need to worry about filtering if there are more than 1 key, since with 1 key
    // it's part of the search that Activiti performs --- see the instanceQuery() method
    SortedSet<String> engineProcessDefinitionKeys = new TreeSet<String>(
            criteria.getEngineProcessDefinitionKeys());
    Set<String> processDefinitionIds = proxyHelper.getProcessDefinitionIds(
            engineProcessDefinitionKeys.toArray(new String[engineProcessDefinitionKeys.size()]));

    List<ProcessExecution> executions;
    if (instances != null && !instances.isEmpty()) {
        executions = new ArrayList<ProcessExecution>(instances.size());

        for (HistoricProcessInstance instance : instances) {
            if (!processDefinitionIds.contains(instance.getProcessDefinitionId()))
                continue;

            ProcessExecution.Builder executionBuilder = new ProcessExecution.Builder()
                    .executionId(instance.getId()).businessKey(instance.getBusinessKey())
                    .initiatorId(instance.getStartUserId()).deleteReason(instance.getDeleteReason());

            if (criteria.isIncludeVariables()) {
                Map<String, Object> variables = processEngine.getRuntimeService()
                        .getVariables(instance.getId());
                executionBuilder.data(variables);
            }

            executions.add(executionBuilder.build());
        }
    } else {
        executions = Collections.emptyList();
    }

    resultsBuilder.executions(executions);

    return resultsBuilder.build();
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Returns a sorted array containing all of the elements for all of the
 * {@link DeviceProtocolInfoSource} {@link Set}s.
 * <p>//from   w  w  w. j  a  v  a  2  s  .  com
 * The returned array will be "safe" in that no reference to it is
 * maintained. (In other words, this method must allocate a new array). The
 * caller is thus free to modify the returned array.
 *
 * @return An array containing all the {@link ProtocolInfo} instances.
 */
public ProtocolInfo[] toArray() {
    SortedSet<ProtocolInfo> result = new TreeSet<>();
    setsLock.readLock().lock();
    try {
        for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) {
            if (set != null) {
                result.addAll(set);
            }
        }
    } finally {
        setsLock.readLock().unlock();
    }
    return result.toArray(new ProtocolInfo[result.size()]);
}