Search in sources :

Example 96 with SortedSet

use of java.util.SortedSet in project eiger by wlloyd.

the class ColumnSerializer method deserialize.

@Override
public Column deserialize(DataInput dis, IColumnSerializer.Flag flag, int expireBefore) throws IOException {
    ByteBuffer name = ByteBufferUtil.readWithShortLength(dis);
    if (name.remaining() <= 0) {
        String format = "invalid column name length %d%s";
        String details = "";
        if (dis instanceof FileDataInput) {
            FileDataInput fdis = (FileDataInput) dis;
            details = String.format(" (%s, %d bytes remaining)", fdis.getPath(), fdis.bytesRemaining());
        }
        throw new CorruptColumnException(String.format(format, name.remaining(), details));
    }
    int b = dis.readUnsignedByte();
    if ((b & COUNTER_MASK) != 0) {
        long timestampOfLastDelete = dis.readLong();
        long ts = dis.readLong();
        ByteBuffer value = ByteBufferUtil.readWithLength(dis);
        Long lastAccessTime = dis.readLong();
        if (lastAccessTime == Long.MIN_VALUE) {
            lastAccessTime = null;
        }
        Long previousVersionLastAccessTime = dis.readLong();
        if (previousVersionLastAccessTime == Long.MIN_VALUE) {
            previousVersionLastAccessTime = null;
        }
        Long earliestValidTime = dis.readLong();
        if (earliestValidTime == Long.MIN_VALUE) {
            earliestValidTime = null;
        }
        Long latestValidTime = dis.readLong();
        if (latestValidTime == Long.MIN_VALUE) {
            latestValidTime = null;
        }
        NavigableSet<IColumn> previousVersions;
        int previousVersionsLength = dis.readInt();
        if (previousVersionsLength == -1) {
            previousVersions = null;
        } else {
            previousVersions = new TreeSet<IColumn>(new EVTComparator());
            for (int i = 0; i < previousVersionsLength; ++i) {
                previousVersions.add(deserialize(dis));
            }
        }
        int transactionCoordinatorKeyLength = dis.readInt();
        ByteBuffer transactionCoordinatorKey = null;
        if (transactionCoordinatorKeyLength > 0) {
            ByteBufferUtil.readWithLength(dis);
        }
        return CounterColumn.create(name, value, ts, timestampOfLastDelete, flag, lastAccessTime, previousVersionLastAccessTime, earliestValidTime, latestValidTime, previousVersions);
    } else if ((b & EXPIRATION_MASK) != 0) {
        int ttl = dis.readInt();
        int expiration = dis.readInt();
        long ts = dis.readLong();
        ByteBuffer value = ByteBufferUtil.readWithLength(dis);
        Long lastAccessTime = dis.readLong();
        if (lastAccessTime == Long.MIN_VALUE) {
            lastAccessTime = null;
        }
        Long previousVersionLastAccessTime = dis.readLong();
        if (previousVersionLastAccessTime == Long.MIN_VALUE) {
            previousVersionLastAccessTime = null;
        }
        Long earliestValidTime = dis.readLong();
        if (earliestValidTime == Long.MIN_VALUE) {
            earliestValidTime = null;
        }
        Long latestValidTime = dis.readLong();
        if (latestValidTime == Long.MIN_VALUE) {
            latestValidTime = null;
        }
        SortedSet<IColumn> previousVersions;
        int previousVersionsLength = dis.readInt();
        if (previousVersionsLength == -1) {
            previousVersions = null;
        } else {
            previousVersions = new TreeSet<IColumn>(new EVTComparator());
            for (int i = 0; i < previousVersionsLength; ++i) {
                previousVersions.add(deserialize(dis));
            }
        }
        int transactionCoordinatorKeyLength = dis.readInt();
        ByteBuffer transactionCoordinatorKey = null;
        if (transactionCoordinatorKeyLength > 0) {
            ByteBufferUtil.readWithLength(dis);
        }
        return ExpiringColumn.create(name, value, ts, ttl, expiration, expireBefore, flag);
    } else {
        long ts = dis.readLong();
        ByteBuffer value = ByteBufferUtil.readWithLength(dis);
        Long lastAccessTime = dis.readLong();
        if (lastAccessTime == Long.MIN_VALUE) {
            lastAccessTime = null;
        }
        Long previousVersionLastAccessTime = dis.readLong();
        if (previousVersionLastAccessTime == Long.MIN_VALUE) {
            previousVersionLastAccessTime = null;
        }
        Long earliestValidTime = dis.readLong();
        if (earliestValidTime == Long.MIN_VALUE) {
            earliestValidTime = null;
        }
        Long latestValidTime = dis.readLong();
        if (latestValidTime == Long.MIN_VALUE) {
            latestValidTime = null;
        }
        NavigableSet<IColumn> previousVersions;
        int previousVersionsLength = dis.readInt();
        if (previousVersionsLength == -1) {
            previousVersions = null;
        } else {
            previousVersions = new TreeSet<IColumn>(new EVTComparator());
            for (int i = 0; i < previousVersionsLength; ++i) {
                previousVersions.add(deserialize(dis));
            }
        }
        int transactionCoordinatorKeyLength = dis.readInt();
        ByteBuffer transactionCoordinatorKey = null;
        if (transactionCoordinatorKeyLength > 0) {
            ByteBufferUtil.readWithLength(dis);
        }
        return (b & COUNTER_UPDATE_MASK) != 0 ? new CounterUpdateColumn(name, value, ts, lastAccessTime, previousVersionLastAccessTime, earliestValidTime, latestValidTime, previousVersions, transactionCoordinatorKey) : ((b & DELETION_MASK) != 0) ? new DeletedColumn(name, value, ts, lastAccessTime, previousVersionLastAccessTime, earliestValidTime, latestValidTime, previousVersions, transactionCoordinatorKey) : ((b & PENDING_TRANSACTION_MASK) != 0) ? new PendingTransactionColumn(name, value, ts, lastAccessTime, previousVersionLastAccessTime, earliestValidTime, latestValidTime, previousVersions, transactionCoordinatorKey) : new Column(name, value, ts, lastAccessTime, previousVersionLastAccessTime, earliestValidTime, latestValidTime, previousVersions, transactionCoordinatorKey);
    }
}
Also used : NavigableSet(java.util.NavigableSet) PendingTransactionColumn(org.apache.cassandra.db.transaction.PendingTransactionColumn) ByteBuffer(java.nio.ByteBuffer) SortedSet(java.util.SortedSet) FileDataInput(org.apache.cassandra.io.util.FileDataInput) PendingTransactionColumn(org.apache.cassandra.db.transaction.PendingTransactionColumn) TreeSet(java.util.TreeSet) EVTComparator(org.apache.cassandra.db.Column.EVTComparator)

Example 97 with SortedSet

use of java.util.SortedSet in project zaproxy by zaproxy.

the class AlertPanel method getTreeAlert.

/**
	 * This method initializes treeAlert	
	 * 	
	 * @return javax.swing.JTree	
	 */
JTree getTreeAlert() {
    if (treeAlert == null) {
        treeAlert = new JTree() {

            private static final long serialVersionUID = 1L;

            @Override
            public Point getPopupLocation(final MouseEvent event) {
                if (event != null) {
                    // Select item on right click
                    TreePath tp = treeAlert.getPathForLocation(event.getX(), event.getY());
                    if (tp != null) {
                        // to be selected
                        if (!treeAlert.getSelectionModel().isPathSelected(tp)) {
                            treeAlert.getSelectionModel().setSelectionPath(tp);
                        }
                    }
                }
                return super.getPopupLocation(event);
            }
        };
        treeAlert.setName(ALERT_TREE_PANEL_NAME);
        treeAlert.setShowsRootHandles(true);
        treeAlert.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        treeAlert.setComponentPopupMenu(new JPopupMenu() {

            private static final long serialVersionUID = 1L;

            @Override
            public void show(Component invoker, int x, int y) {
                final int countSelectedNodes = treeAlert.getSelectionCount();
                final ArrayList<HistoryReference> uniqueHistoryReferences = new ArrayList<>(countSelectedNodes);
                if (countSelectedNodes > 0) {
                    SortedSet<Integer> historyReferenceIdsAdded = new TreeSet<>();
                    for (TreePath path : treeAlert.getSelectionPaths()) {
                        final AlertNode node = (AlertNode) path.getLastPathComponent();
                        final Object userObject = node.getUserObject();
                        if (userObject instanceof Alert) {
                            HistoryReference historyReference = ((Alert) userObject).getHistoryRef();
                            if (historyReference != null && !historyReferenceIdsAdded.contains(Integer.valueOf(historyReference.getHistoryId()))) {
                                historyReferenceIdsAdded.add(Integer.valueOf(historyReference.getHistoryId()));
                                uniqueHistoryReferences.add(historyReference);
                            }
                        }
                    }
                    uniqueHistoryReferences.trimToSize();
                }
                SelectableHistoryReferencesContainer messageContainer = new DefaultSelectableHistoryReferencesContainer(treeAlert.getName(), treeAlert, Collections.<HistoryReference>emptyList(), uniqueHistoryReferences);
                view.getPopupMenu().show(messageContainer, x, y);
            }
        });
        treeAlert.addMouseListener(new java.awt.event.MouseAdapter() {

            @Override
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
                    // Its a double click - edit the alert
                    editSelectedAlert();
                }
            }
        });
        treeAlert.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeAlert.getLastSelectedPathComponent();
                if (node != null && node.getUserObject() != null) {
                    Object obj = node.getUserObject();
                    if (obj instanceof Alert) {
                        Alert alert = (Alert) obj;
                        setMessage(alert.getMessage(), alert.getEvidence());
                        treeAlert.requestFocusInWindow();
                        getAlertViewPanel().displayAlert(alert);
                    } else {
                        getAlertViewPanel().clearAlert();
                    }
                } else {
                    getAlertViewPanel().clearAlert();
                }
            }
        });
        treeAlert.setCellRenderer(new AlertTreeCellRenderer());
        treeAlert.setExpandsSelectedPaths(true);
    }
    return treeAlert;
}
Also used : DefaultSelectableHistoryReferencesContainer(org.zaproxy.zap.view.messagecontainer.http.DefaultSelectableHistoryReferencesContainer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) SortedSet(java.util.SortedSet) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) HistoryReference(org.parosproxy.paros.model.HistoryReference) TreeSelectionListener(javax.swing.event.TreeSelectionListener) Component(java.awt.Component) MouseEvent(java.awt.event.MouseEvent) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MouseEvent(java.awt.event.MouseEvent) JTree(javax.swing.JTree) DefaultSelectableHistoryReferencesContainer(org.zaproxy.zap.view.messagecontainer.http.DefaultSelectableHistoryReferencesContainer) SelectableHistoryReferencesContainer(org.zaproxy.zap.view.messagecontainer.http.SelectableHistoryReferencesContainer) TreePath(javax.swing.tree.TreePath) Alert(org.parosproxy.paros.core.scanner.Alert)

Example 98 with SortedSet

use of java.util.SortedSet in project uPortal by Jasig.

the class ChannelListController method listChannels.

/**
     * Original, pre-4.3 version of this API. Always returns the entire contents of the Portlet
     * Registry, including uncategorized portlets, to which the user has access. Access is based on
     * the SUBSCRIBE permission.
     */
@RequestMapping(value = "/portletList", method = RequestMethod.GET)
public ModelAndView listChannels(WebRequest webRequest, HttpServletRequest request, @RequestParam(value = "type", required = false) String type) {
    if (type != null && TYPE_MANAGE.equals(type)) {
        throw new UnsupportedOperationException("Moved to PortletRESTController under /api/portlets.json");
    }
    final IPerson user = personManager.getPerson(request);
    final Map<String, SortedSet<?>> registry = getRegistryOriginal(webRequest, user);
    // Since type=manage was deprecated channels is always empty but retained for backwards compatibility
    registry.put("channels", new TreeSet<ChannelBean>());
    return new ModelAndView("jsonView", "registry", registry);
}
Also used : IPerson(org.apereo.portal.security.IPerson) ModelAndView(org.springframework.web.servlet.ModelAndView) ChannelBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelBean) SortedSet(java.util.SortedSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 99 with SortedSet

use of java.util.SortedSet in project uPortal by Jasig.

the class BaseStatisticsReportController method buildAggregationReport.

/** Build the aggregation {@link DataTable} */
protected final DataTable buildAggregationReport(F form) throws TypeMismatchException {
    //Pull data out of form for per-group fetching
    final AggregationInterval interval = form.getInterval();
    final DateMidnight start = form.getStart();
    final DateMidnight end = form.getEnd();
    final DateTime startDateTime = start.toDateTime();
    //Use a query end of the end date at 23:59:59
    final DateTime endDateTime = end.plusDays(1).toDateTime().minusSeconds(1);
    //Get the list of DateTimes used on the X axis in the report
    final List<DateTime> reportTimes = this.intervalHelper.getIntervalStartDateTimesBetween(interval, startDateTime, endDateTime, maxIntervals);
    final Map<D, SortedSet<T>> groupedAggregations = createColumnDiscriminatorMap(form);
    //Determine the ValueType of the date/time column. Use the most specific column type possible
    final ValueType dateTimeColumnType;
    if (interval.isHasTimePart()) {
        //If start/end are the same day just display the time
        if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) {
            dateTimeColumnType = ValueType.TIMEOFDAY;
        } else //interval has time data and start/end are on different days, show full date time
        {
            dateTimeColumnType = ValueType.DATETIME;
        }
    } else //interval is date only
    {
        dateTimeColumnType = ValueType.DATE;
    }
    //Setup the date/time column description
    final ColumnDescription dateTimeColumn;
    switch(dateTimeColumnType) {
        case TIMEOFDAY:
            {
                dateTimeColumn = new ColumnDescription("time", dateTimeColumnType, "Time");
                break;
            }
        default:
            {
                dateTimeColumn = new ColumnDescription("date", dateTimeColumnType, "Date");
            }
    }
    final DataTable table = new JsonDataTable();
    table.addColumn(dateTimeColumn);
    //Setup columns in the DataTable
    final Set<D> columnGroups = groupedAggregations.keySet();
    for (final D columnMapping : columnGroups) {
        final Collection<ColumnDescription> columnDescriptions = this.getColumnDescriptions(columnMapping, form);
        table.addColumns(columnDescriptions);
    }
    //Query for all aggregation data in the time range for all groups.  Only the
    //interval and discriminator data is used from the keys.
    final Set<K> keys = createAggregationsQueryKeyset(columnGroups, form);
    final BaseAggregationDao<T, K> baseAggregationDao = this.getBaseAggregationDao();
    final Collection<T> aggregations = baseAggregationDao.getAggregations(startDateTime, endDateTime, keys, extractGroupsArray(columnGroups));
    //Organize the results by group and sort them chronologically by adding them to the sorted set
    for (final T aggregation : aggregations) {
        final D discriminator = aggregation.getAggregationDiscriminator();
        final SortedSet<T> results = groupedAggregations.get(discriminator);
        results.add(aggregation);
    }
    //Build Map from discriminator column mapping to result iterator to allow putting results into
    //the correct column AND the correct time slot in the column
    Comparator<? super D> comparator = getDiscriminatorComparator();
    final Map<D, PeekingIterator<T>> groupedAggregationIterators = new TreeMap<D, PeekingIterator<T>>((comparator));
    for (final Entry<D, SortedSet<T>> groupedAggregationEntry : groupedAggregations.entrySet()) {
        groupedAggregationIterators.put(groupedAggregationEntry.getKey(), Iterators.peekingIterator(groupedAggregationEntry.getValue().iterator()));
    }
    /*
         * populate the data, filling in blank spots. The full list of interval DateTimes is used to create every row in the
         * query range. Then the iterator
         */
    for (final DateTime rowTime : reportTimes) {
        // create the row
        final TableRow row = new TableRow();
        // add the date to the first cell
        final Value dateTimeValue;
        switch(dateTimeColumnType) {
            case DATE:
                {
                    dateTimeValue = new DateValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth());
                    break;
                }
            case TIMEOFDAY:
                {
                    dateTimeValue = new TimeOfDayValue(rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0);
                    break;
                }
            default:
                {
                    dateTimeValue = new DateTimeValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth(), rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0, 0);
                    break;
                }
        }
        row.addCell(new TableCell(dateTimeValue));
        for (final PeekingIterator<T> groupedAggregationIteratorEntry : groupedAggregationIterators.values()) {
            List<Value> values = null;
            if (groupedAggregationIteratorEntry.hasNext()) {
                final T aggr = groupedAggregationIteratorEntry.peek();
                if (rowTime.equals(aggr.getDateTime())) {
                    //Data is for the correct time slot, advance the iterator
                    groupedAggregationIteratorEntry.next();
                    values = createRowValues(aggr, form);
                }
            }
            //Gap in the data, fill it in using a null aggregation
            if (values == null) {
                values = createRowValues(null, form);
            }
            //Add the values to the row
            for (final Value value : values) {
                row.addCell(value);
            }
        }
        table.addRow(row);
    }
    return table;
}
Also used : DataTable(com.google.visualization.datasource.datatable.DataTable) ColumnDescription(com.google.visualization.datasource.datatable.ColumnDescription) SortedSet(java.util.SortedSet) DateTime(org.joda.time.DateTime) TableCell(com.google.visualization.datasource.datatable.TableCell) DateMidnight(org.joda.time.DateMidnight) DateValue(com.google.visualization.datasource.datatable.value.DateValue) DateTimeValue(com.google.visualization.datasource.datatable.value.DateTimeValue) ValueType(com.google.visualization.datasource.datatable.value.ValueType) PeekingIterator(com.google.common.collect.PeekingIterator) TreeMap(java.util.TreeMap) TableRow(com.google.visualization.datasource.datatable.TableRow) Value(com.google.visualization.datasource.datatable.value.Value) DateTimeValue(com.google.visualization.datasource.datatable.value.DateTimeValue) DateValue(com.google.visualization.datasource.datatable.value.DateValue) TimeOfDayValue(com.google.visualization.datasource.datatable.value.TimeOfDayValue) TimeOfDayValue(com.google.visualization.datasource.datatable.value.TimeOfDayValue) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval)

Example 100 with SortedSet

use of java.util.SortedSet in project gerrit by GerritCodeReview.

the class Schema_131 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    SortedSet<Project.NameKey> repoList = repoManager.list();
    SortedSet<Project.NameKey> repoUpgraded = new TreeSet<>();
    ui.message("\tMigrating " + repoList.size() + " repositories ...");
    for (Project.NameKey projectName : repoList) {
        try (Repository git = repoManager.openRepository(projectName);
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, projectName, git)) {
            ProjectConfig config = ProjectConfig.read(md);
            if (config.hasLegacyPermissions()) {
                md.getCommitBuilder().setAuthor(serverUser);
                md.getCommitBuilder().setCommitter(serverUser);
                md.setMessage(COMMIT_MSG);
                config.commit(md);
                repoUpgraded.add(projectName);
            }
        } catch (ConfigInvalidException | IOException ex) {
            throw new OrmException("Cannot migrate project " + projectName, ex);
        }
    }
    ui.message("\tMigration completed:  " + repoUpgraded.size() + " repositories updated:");
    ui.message("\t" + repoUpgraded.stream().map(n -> n.get()).collect(joining(" ")));
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) OrmException(com.google.gwtorm.server.OrmException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SortedSet(java.util.SortedSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) Inject(com.google.inject.Inject) IOException(java.io.IOException) Collectors.joining(java.util.stream.Collectors.joining) TreeSet(java.util.TreeSet) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) TreeSet(java.util.TreeSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

SortedSet (java.util.SortedSet)119 TreeSet (java.util.TreeSet)44 Iterator (java.util.Iterator)42 HashMap (java.util.HashMap)22 NavigableSet (java.util.NavigableSet)22 Map (java.util.Map)20 List (java.util.List)19 ArrayList (java.util.ArrayList)18 TreeMap (java.util.TreeMap)17 Set (java.util.Set)16 Test (org.junit.Test)13 HashSet (java.util.HashSet)12 IOException (java.io.IOException)11 Collection (java.util.Collection)9 Comparator (java.util.Comparator)7 LinkedHashMap (java.util.LinkedHashMap)7 SortedMap (java.util.SortedMap)5 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)4 LinkedList (java.util.LinkedList)4 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)3