Example usage for java.util TreeSet addAll

List of usage examples for java.util TreeSet addAll

Introduction

In this page you can find the example usage for java.util TreeSet addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Adds all of the elements in the specified collection to this set.

Usage

From source file:com.btoddb.fastpersitentqueue.InMemorySegmentMgr.java

private void loadPagedSegments() throws IOException {
    // read files and sort by their UUID name so they are in proper chronological order
    Collection<File> files = FileUtils.listFiles(pagingDirectory, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);/*from   ww  w.ja v  a 2 s .c o  m*/
    TreeSet<File> sortedFiles = new TreeSet<File>(new Comparator<File>() {
        @Override
        public int compare(File o1, File o2) {
            return new UUID(o1.getName()).compareTo(new UUID(o2.getName()));
        }
    });
    sortedFiles.addAll(files);

    // cleanup memory
    files.clear();

    assert 0 == numberOfActiveSegments.get();
    assert segments.isEmpty();

    segments.clear();

    for (File f : sortedFiles) {
        MemorySegment segment;
        // only load the segment's data if room in memory, otherwise just load its header
        if (numberOfActiveSegments.get() < maxNumberOfActiveSegments - 1) {
            segment = segmentSerializer.loadFromDisk(f.getName());
            segment.setStatus(MemorySegment.Status.READY);
            segment.setPushingFinished(true);

            assert segment.getNumberOfOnlineEntries() > 0;
            assert !segment.getQueue().isEmpty();

            numberOfActiveSegments.incrementAndGet();
        } else {
            segment = segmentSerializer.loadHeaderOnly(f.getName());
            segment.setStatus(MemorySegment.Status.OFFLINE);
            segment.setPushingFinished(true);

        }

        assert segment.isPushingFinished();
        assert segment.getNumberOfEntries() > 0;
        assert segment.getEntryListOffsetOnDisk() > 0;

        segments.add(segment);
        numberOfEntries.addAndGet(segment.getNumberOfEntries());
    }

    //        for (MemorySegment seg : segments) {
    //            if (seg.getStatus() == MemorySegment.Status.READY) {
    //                segmentSerializer.removePagingFile(seg);
    //            }
    //        }
}

From source file:com.murati.oszk.audiobook.model.MusicProvider.java

public List<MediaBrowserCompat.MediaItem> getChildren(String mediaId, Resources resources) {
    List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();

    if (mediaId == null)
        return Collections.emptyList();

    if (MEDIA_ID_ROOT.equals(mediaId)) {

        try {//from w w w  .j a va2 s.c o  m
            // Show Last ebook
            if (PlaybackHelper.getLastEBook() != null) {
                mediaItems.add(createHeader(resources.getString(R.string.browse_queue_subtitle)));
                mediaItems.add(new MediaBrowserCompat.MediaItem(PlaybackHelper.getLastEBookDescriptor(),
                        MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
            }
        } catch (Exception ex) {
            Log.d(TAG, "Error restoring last-ebook tile" + ex.getMessage());
        }

        // Catalog header
        mediaItems.add(createHeader(resources.getString(R.string.label_catalog)));

        // Add writers
        mediaItems.add(createGroupItem(MEDIA_ID_BY_WRITER, resources.getString(R.string.browse_writer),
                resources.getString(R.string.browse_writer_subtitle),
                BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_writer)));

        // Add Genres
        mediaItems.add(createGroupItem(MEDIA_ID_BY_GENRE, resources.getString(R.string.browse_genres),
                resources.getString(R.string.browse_genre_subtitle),
                BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_list)));

        // Add EBooks
        mediaItems.add(createGroupItem(MEDIA_ID_BY_EBOOK, resources.getString(R.string.browse_ebook),
                resources.getString(R.string.browse_ebook_subtitle),
                BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_books)));

        // Add Favorites
        mediaItems.add(createGroupItem(MEDIA_ID_BY_FAVORITES, resources.getString(R.string.browse_favorites),
                resources.getString(R.string.browse_favorites_subtitle),
                BitmapHelper.convertDrawabletoUri(R.drawable.ic_star_on)));

        // Add Offline
        mediaItems.add(createGroupItem(MEDIA_ID_BY_DOWNLOADS, resources.getString(R.string.browse_downloads),
                resources.getString(R.string.browse_downloads_subtitle),
                BitmapHelper.convertDrawabletoUri(R.drawable.ic_action_download)));

        return mediaItems;
    }

    // Not root section

    //Refresh button for empty states
    if (mCurrentState != State.INITIALIZED) {
        mediaItems.add(createRefreshItem(mediaId, resources));
        return mediaItems;
    }

    try {
        // Swap mediaId from queue to current eBook
        if (mediaId.equals(MEDIA_ID_BY_QUEUE))
            return getChildren(PlaybackHelper.getLastEBook(), resources);

        //Rethink edgecase of misbrowse
        if (!MediaIDHelper.isBrowseable(mediaId)) {
            return mediaItems;
        }

        // Search ebooks by Query String
        if (mediaId.startsWith(MEDIA_ID_BY_SEARCH)) {
            String search_query = MediaIDHelper.extractMusicIDFromMediaID(mediaId);
            for (String ebook : getEbooksByQueryString(search_query)) {
                mediaItems.add(createEbookItem(ebook, resources));
            }
        }

        // List all Genre Items
        else if (MEDIA_ID_BY_GENRE.equals(mediaId)) {
            mediaItems.addAll(createGroupList(mEbookListByGenre, MEDIA_ID_BY_GENRE,
                    BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_list), resources));
        }
        // List ebooks in a specific Genre
        else if (mediaId.startsWith(MEDIA_ID_BY_GENRE)) {
            String genre = MediaIDHelper.getHierarchy(mediaId)[1];
            for (String ebook : getEbooksByGenre(genre))
                mediaItems.add(createEbookItem(ebook, resources));
        }

        // List Writers
        else if (MEDIA_ID_BY_WRITER.equals(mediaId)) {
            mediaItems.addAll(createGroupList(mEbookListByWriter, MEDIA_ID_BY_WRITER,
                    BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_writer), resources));
        }

        // Open a specific Genre
        else if (mediaId.startsWith(MEDIA_ID_BY_WRITER)) {
            String writer = MediaIDHelper.getHierarchy(mediaId)[1];
            for (String ebook : getEbooksByWriter(writer))
                mediaItems.add(createEbookItem(ebook, resources));
        }

        // List all EBooks Items
        else if (MEDIA_ID_BY_EBOOK.equals(mediaId)) {
            TreeSet<String> sortedEbookTitles = new TreeSet<String>(collator);
            sortedEbookTitles.addAll(mEbookList.keySet());
            for (String ebook : sortedEbookTitles) {
                mediaItems.add(createEbookItem(ebook, resources));
            }
        }

        // List all Favorites
        else if (MEDIA_ID_BY_FAVORITES.equals(mediaId)) {
            for (String ebook : FavoritesHelper.getFavorites()) {
                try {
                    if (ebook.startsWith(MEDIA_ID_BY_EBOOK)) {
                        String title = getCategoryValueFromMediaID(ebook);
                        mediaItems.add(createEbookItem(title, resources));
                    }
                } catch (Exception ex) {
                    Log.i(TAG, "Exception listing favorite:" + ebook);
                }
            }
        }

        // List all Downloads
        else if (MEDIA_ID_BY_DOWNLOADS.equals(mediaId)) {
            //TODO: canonical book list
            List<String> offlineBookList = OfflineBookService.getOfflineBooks();

            //TODO: generalize errorhandling - with customized exception/message
            if (offlineBookList != null) {
                for (String ebook : offlineBookList) {
                    try {
                        mediaItems.add(createEbookItem(ebook, resources));
                    } catch (Exception ex) {
                        Log.i(TAG, "Exception listing favorite:" + ebook);
                    }
                }
            }
        }

        // Open a specific Ebook for direct play
        else if (mediaId.startsWith(MEDIA_ID_BY_EBOOK)) {
            // Add header
            mediaItems.add(createEbookHeader(mediaId, resources));

            //Add tracks
            String ebook = MediaIDHelper.getHierarchy(mediaId)[1];
            for (MediaMetadataCompat metadata : getTracksByEbook(ebook)) {
                mediaItems.add(createTrackItem(metadata));
            }
        }

        // Can't open media
        else {
            LogHelper.w(TAG, "Skipping unmatched mediaId: ", mediaId);
        }

    } catch (Exception ex) {
        //TODO: signal errors properly to UI
        LogHelper.w(TAG, "Something went wrong processing", mediaId);
        Log.d(TAG, ex.getMessage());
    }
    return mediaItems;
}

From source file:org.theospi.portfolio.presentation.support.PresentationService.java

public List<PresentationTemplate> getAvailableTemplates() {
    Agent agent = authnManager.getAgent();
    TreeSet<PresentationTemplate> availableTemplates = new TreeSet<PresentationTemplate>(
            new PresentationTemplateNameComparator());
    availableTemplates.addAll(
            presentationManager.findTemplatesByOwner(agent, toolManager.getCurrentPlacement().getContext()));
    availableTemplates/*  w  w w. j  a v  a 2 s .co m*/
            .addAll(presentationManager.findPublishedTemplates(toolManager.getCurrentPlacement().getContext()));
    availableTemplates.addAll(presentationManager.findGlobalTemplates());
    return new ArrayList<PresentationTemplate>(availableTemplates);
}

From source file:jails.http.MediaType.java

/**
 * Compares this {@link MediaType} to another alphabetically.
 * @param other media type to compare to
 * @see #sortBySpecificity(List)/*from ww w  .  j ava 2 s. co  m*/
 */
public int compareTo(MediaType other) {
    int comp = this.type.compareToIgnoreCase(other.type);
    if (comp != 0) {
        return comp;
    }
    comp = this.subtype.compareToIgnoreCase(other.subtype);
    if (comp != 0) {
        return comp;
    }
    comp = this.parameters.size() - other.parameters.size();
    if (comp != 0) {
        return comp;
    }
    TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    thisAttributes.addAll(this.parameters.keySet());
    TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    otherAttributes.addAll(other.parameters.keySet());
    Iterator<String> thisAttributesIterator = thisAttributes.iterator();
    Iterator<String> otherAttributesIterator = otherAttributes.iterator();
    while (thisAttributesIterator.hasNext()) {
        String thisAttribute = thisAttributesIterator.next();
        String otherAttribute = otherAttributesIterator.next();
        comp = thisAttribute.compareToIgnoreCase(otherAttribute);
        if (comp != 0) {
            return comp;
        }
        String thisValue = this.parameters.get(thisAttribute);
        String otherValue = other.parameters.get(otherAttribute);
        if (otherValue == null) {
            otherValue = "";
        }
        comp = thisValue.compareTo(otherValue);
        if (comp != 0) {
            return comp;
        }
    }
    return 0;
}

From source file:net.spfbl.core.Reverse.java

public TreeSet<String> getAddressSet() {
    if (addressSet == null) {
        return new TreeSet<String>();
    } else {/*from w  ww .j ava2  s. c  o  m*/
        TreeSet<String> resultSet = new TreeSet<String>();
        resultSet.addAll(addressSet);
        return resultSet;
    }
}

From source file:net.spfbl.core.Reverse.java

public TreeSet<String> getAddressSet(boolean refresh) {
    if (addressSet == null) {
        return new TreeSet<String>();
    } else {//  w  w  w  .ja va2s.  c o  m
        if (refresh) {
            refresh();
        }
        TreeSet<String> resultSet = new TreeSet<String>();
        resultSet.addAll(addressSet);
        return resultSet;
    }
}

From source file:com.medigy.persist.model.person.Person.java

@Transient
public MaritalStatusType getCurrentMaritalStatus() {
    final List<MaritalStatus> maritalStatuses = getMaritalStatuses();
    if (maritalStatuses.size() == 0)
        return MaritalStatusType.Cache.UNKNOWN.getEntity();

    TreeSet<MaritalStatus> inverseSorted = new TreeSet<MaritalStatus>(Collections.reverseOrder());
    inverseSorted.addAll(maritalStatuses);
    return inverseSorted.first().getType();
}

From source file:com.linkedin.pinot.controller.api.ControllerRestApplication.java

private void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
    TreeSet<String> pathsOrderedByLength = new TreeSet<String>(
            ComparatorUtils.chainedComparator(new Comparator<String>() {
                private IntComparator _intComparator = IntComparators.NATURAL_COMPARATOR;

                @Override/* w ww. j  av a2 s . co m*/
                public int compare(String o1, String o2) {
                    return _intComparator.compare(o1.length(), o2.length());
                }
            }, ComparatorUtils.NATURAL_COMPARATOR));

    for (Method method : clazz.getDeclaredMethods()) {
        Annotation annotationInstance = method.getAnnotation(Paths.class);
        if (annotationInstance != null) {
            pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
        }
    }

    for (String routePath : pathsOrderedByLength) {
        LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
        router.attach(routePath, clazz);
    }
}

From source file:org.matonto.jaas.engines.RdfEngine.java

@Override
public Set<Role> getUserRoles(String username) {
    TreeSet<Role> allRoles = new TreeSet<>(
            (role1, role2) -> role1.getResource().stringValue().compareTo(role2.getResource().stringValue()));
    Optional<User> userOptional = retrieveUser(username);
    if (!userOptional.isPresent()) {
        throw new MatOntoException("User with that id does not exist");
    }/*from  w w w  . j a v a 2 s.c o  m*/
    allRoles.addAll(userOptional.get().getHasUserRole());
    getGroups().stream()
            .filter(group -> group.getMember().stream().map(Thing::getResource)
                    .anyMatch(resource -> resource.equals(createUserIri(username))))
            .map(Group::getHasGroupRole).flatMap(Collection::stream).forEach(allRoles::add);

    return allRoles;
}

From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java

@SuppressWarnings("unchecked")
public Iterator<RegularTimePeriod> getMergedPeriods(List<TimeSeries> seriesList) {
    TreeSet<RegularTimePeriod> periods = new TreeSet<RegularTimePeriod>();

    for (TimeSeries series : seriesList) {
        if (series.getItemCount() == 0)
            continue;
        periods.addAll(series.getTimePeriods());
    }/*from  ww  w . j  a va2s  .com*/

    return periods.iterator();
}