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);
}
}
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;
}
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);
}
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;
}
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(" ")));
}
Aggregations