use of java.util.Comparator in project midpoint by Evolveum.
the class LensUtil method findRelatedContexts.
/**
* Returns a list of context that have equivalent discriminator with the reference context. Ordered by "order" in the
* discriminator.
*/
public static <F extends ObjectType> List<LensProjectionContext> findRelatedContexts(LensContext<F> context, LensProjectionContext refProjCtx) {
List<LensProjectionContext> projCtxs = new ArrayList<LensProjectionContext>();
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
if (refDiscr == null) {
return projCtxs;
}
for (LensProjectionContext aProjCtx : context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (refDiscr.equivalent(aDiscr)) {
projCtxs.add(aProjCtx);
}
}
Comparator<? super LensProjectionContext> orderComparator = new Comparator<LensProjectionContext>() {
@Override
public int compare(LensProjectionContext ctx1, LensProjectionContext ctx2) {
int order1 = ctx1.getResourceShadowDiscriminator().getOrder();
int order2 = ctx2.getResourceShadowDiscriminator().getOrder();
return Integer.compare(order1, order2);
}
};
Collections.sort(projCtxs, orderComparator);
return projCtxs;
}
use of java.util.Comparator in project android_frameworks_base by DirtyUnicorns.
the class ActivityManagerService method dumpProcessOomList.
private static final boolean dumpProcessOomList(PrintWriter pw, ActivityManagerService service, List<ProcessRecord> origList, String prefix, String normalLabel, String persistentLabel, boolean inclDetails, String dumpPackage) {
ArrayList<Pair<ProcessRecord, Integer>> list = new ArrayList<Pair<ProcessRecord, Integer>>(origList.size());
for (int i = 0; i < origList.size(); i++) {
ProcessRecord r = origList.get(i);
if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
continue;
}
list.add(new Pair<ProcessRecord, Integer>(origList.get(i), i));
}
if (list.size() <= 0) {
return false;
}
Comparator<Pair<ProcessRecord, Integer>> comparator = new Comparator<Pair<ProcessRecord, Integer>>() {
@Override
public int compare(Pair<ProcessRecord, Integer> object1, Pair<ProcessRecord, Integer> object2) {
if (object1.first.setAdj != object2.first.setAdj) {
return object1.first.setAdj > object2.first.setAdj ? -1 : 1;
}
if (object1.first.setProcState != object2.first.setProcState) {
return object1.first.setProcState > object2.first.setProcState ? -1 : 1;
}
if (object1.second.intValue() != object2.second.intValue()) {
return object1.second.intValue() > object2.second.intValue() ? -1 : 1;
}
return 0;
}
};
Collections.sort(list, comparator);
final long curRealtime = SystemClock.elapsedRealtime();
final long realtimeSince = curRealtime - service.mLastPowerCheckRealtime;
final long curUptime = SystemClock.uptimeMillis();
final long uptimeSince = curUptime - service.mLastPowerCheckUptime;
for (int i = list.size() - 1; i >= 0; i--) {
ProcessRecord r = list.get(i).first;
String oomAdj = ProcessList.makeOomAdjString(r.setAdj);
char schedGroup;
switch(r.setSchedGroup) {
case ProcessList.SCHED_GROUP_BACKGROUND:
schedGroup = 'B';
break;
case ProcessList.SCHED_GROUP_DEFAULT:
schedGroup = 'F';
break;
case ProcessList.SCHED_GROUP_TOP_APP:
schedGroup = 'T';
break;
default:
schedGroup = '?';
break;
}
char foreground;
if (r.foregroundActivities) {
foreground = 'A';
} else if (r.foregroundServices) {
foreground = 'S';
} else {
foreground = ' ';
}
String procState = ProcessList.makeProcStateString(r.curProcState);
pw.print(prefix);
pw.print(r.persistent ? persistentLabel : normalLabel);
pw.print(" #");
int num = (origList.size() - 1) - list.get(i).second;
if (num < 10)
pw.print(' ');
pw.print(num);
pw.print(": ");
pw.print(oomAdj);
pw.print(' ');
pw.print(schedGroup);
pw.print('/');
pw.print(foreground);
pw.print('/');
pw.print(procState);
pw.print(" trm:");
if (r.trimMemoryLevel < 10)
pw.print(' ');
pw.print(r.trimMemoryLevel);
pw.print(' ');
pw.print(r.toShortString());
pw.print(" (");
pw.print(r.adjType);
pw.println(')');
if (r.adjSource != null || r.adjTarget != null) {
pw.print(prefix);
pw.print(" ");
if (r.adjTarget instanceof ComponentName) {
pw.print(((ComponentName) r.adjTarget).flattenToShortString());
} else if (r.adjTarget != null) {
pw.print(r.adjTarget.toString());
} else {
pw.print("{null}");
}
pw.print("<=");
if (r.adjSource instanceof ProcessRecord) {
pw.print("Proc{");
pw.print(((ProcessRecord) r.adjSource).toShortString());
pw.println("}");
} else if (r.adjSource != null) {
pw.println(r.adjSource.toString());
} else {
pw.println("{null}");
}
}
if (inclDetails) {
pw.print(prefix);
pw.print(" ");
pw.print("oom: max=");
pw.print(r.maxAdj);
pw.print(" curRaw=");
pw.print(r.curRawAdj);
pw.print(" setRaw=");
pw.print(r.setRawAdj);
pw.print(" cur=");
pw.print(r.curAdj);
pw.print(" set=");
pw.println(r.setAdj);
pw.print(prefix);
pw.print(" ");
pw.print("state: cur=");
pw.print(ProcessList.makeProcStateString(r.curProcState));
pw.print(" set=");
pw.print(ProcessList.makeProcStateString(r.setProcState));
pw.print(" lastPss=");
DebugUtils.printSizeValue(pw, r.lastPss * 1024);
pw.print(" lastSwapPss=");
DebugUtils.printSizeValue(pw, r.lastSwapPss * 1024);
pw.print(" lastCachedPss=");
DebugUtils.printSizeValue(pw, r.lastCachedPss * 1024);
pw.println();
pw.print(prefix);
pw.print(" ");
pw.print("cached=");
pw.print(r.cached);
pw.print(" empty=");
pw.print(r.empty);
pw.print(" hasAboveClient=");
pw.println(r.hasAboveClient);
if (r.setProcState >= ActivityManager.PROCESS_STATE_SERVICE) {
if (r.lastWakeTime != 0) {
long wtime;
BatteryStatsImpl stats = service.mBatteryStatsService.getActiveStatistics();
synchronized (stats) {
wtime = stats.getProcessWakeTime(r.info.uid, r.pid, curRealtime);
}
long timeUsed = wtime - r.lastWakeTime;
pw.print(prefix);
pw.print(" ");
pw.print("keep awake over ");
TimeUtils.formatDuration(realtimeSince, pw);
pw.print(" used ");
TimeUtils.formatDuration(timeUsed, pw);
pw.print(" (");
pw.print((timeUsed * 100) / realtimeSince);
pw.println("%)");
}
if (r.lastCpuTime != 0) {
long timeUsed = r.curCpuTime - r.lastCpuTime;
pw.print(prefix);
pw.print(" ");
pw.print("run cpu over ");
TimeUtils.formatDuration(uptimeSince, pw);
pw.print(" used ");
TimeUtils.formatDuration(timeUsed, pw);
pw.print(" (");
pw.print((timeUsed * 100) / uptimeSince);
pw.println("%)");
}
}
}
}
return true;
}
use of java.util.Comparator in project android_frameworks_base by AOSPA.
the class Am method getRecentConfigurations.
private List<Configuration> getRecentConfigurations(int days) {
IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
final long now = System.currentTimeMillis();
final long nDaysAgo = now - (days * 24 * 60 * 60 * 1000);
try {
@SuppressWarnings("unchecked") ParceledListSlice<ConfigurationStats> configStatsSlice = usm.queryConfigurationStats(UsageStatsManager.INTERVAL_BEST, nDaysAgo, now, "com.android.shell");
if (configStatsSlice == null) {
return Collections.emptyList();
}
final ArrayMap<Configuration, Integer> recentConfigs = new ArrayMap<>();
final List<ConfigurationStats> configStatsList = configStatsSlice.getList();
final int configStatsListSize = configStatsList.size();
for (int i = 0; i < configStatsListSize; i++) {
final ConfigurationStats stats = configStatsList.get(i);
final int indexOfKey = recentConfigs.indexOfKey(stats.getConfiguration());
if (indexOfKey < 0) {
recentConfigs.put(stats.getConfiguration(), stats.getActivationCount());
} else {
recentConfigs.setValueAt(indexOfKey, recentConfigs.valueAt(indexOfKey) + stats.getActivationCount());
}
}
final Comparator<Configuration> comparator = new Comparator<Configuration>() {
@Override
public int compare(Configuration a, Configuration b) {
return recentConfigs.get(b).compareTo(recentConfigs.get(a));
}
};
ArrayList<Configuration> configs = new ArrayList<>(recentConfigs.size());
configs.addAll(recentConfigs.keySet());
Collections.sort(configs, comparator);
return configs;
} catch (RemoteException e) {
return Collections.emptyList();
}
}
use of java.util.Comparator in project android_frameworks_base by AOSPA.
the class AlarmManagerService method dumpImpl.
void dumpImpl(PrintWriter pw) {
synchronized (mLock) {
pw.println("Current Alarm Manager state:");
mConstants.dump(pw);
pw.println();
final long nowRTC = System.currentTimeMillis();
final long nowELAPSED = SystemClock.elapsedRealtime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
pw.print(" nowRTC=");
pw.print(nowRTC);
pw.print("=");
pw.print(sdf.format(new Date(nowRTC)));
pw.print(" nowELAPSED=");
pw.print(nowELAPSED);
pw.println();
pw.print(" mLastTimeChangeClockTime=");
pw.print(mLastTimeChangeClockTime);
pw.print("=");
pw.println(sdf.format(new Date(mLastTimeChangeClockTime)));
pw.print(" mLastTimeChangeRealtime=");
TimeUtils.formatDuration(mLastTimeChangeRealtime, pw);
pw.println();
if (!mInteractive) {
pw.print(" Time since non-interactive: ");
TimeUtils.formatDuration(nowELAPSED - mNonInteractiveStartTime, pw);
pw.println();
pw.print(" Max wakeup delay: ");
TimeUtils.formatDuration(currentNonWakeupFuzzLocked(nowELAPSED), pw);
pw.println();
pw.print(" Time since last dispatch: ");
TimeUtils.formatDuration(nowELAPSED - mLastAlarmDeliveryTime, pw);
pw.println();
pw.print(" Next non-wakeup delivery time: ");
TimeUtils.formatDuration(nowELAPSED - mNextNonWakeupDeliveryTime, pw);
pw.println();
}
long nextWakeupRTC = mNextWakeup + (nowRTC - nowELAPSED);
long nextNonWakeupRTC = mNextNonWakeup + (nowRTC - nowELAPSED);
pw.print(" Next non-wakeup alarm: ");
TimeUtils.formatDuration(mNextNonWakeup, nowELAPSED, pw);
pw.print(" = ");
pw.println(sdf.format(new Date(nextNonWakeupRTC)));
pw.print(" Next wakeup: ");
TimeUtils.formatDuration(mNextWakeup, nowELAPSED, pw);
pw.print(" = ");
pw.println(sdf.format(new Date(nextWakeupRTC)));
pw.print(" Last wakeup: ");
TimeUtils.formatDuration(mLastWakeup, nowELAPSED, pw);
pw.print(" set at ");
TimeUtils.formatDuration(mLastWakeupSet, nowELAPSED, pw);
pw.println();
pw.print(" Num time change events: ");
pw.println(mNumTimeChanged);
pw.println(" mDeviceIdleUserWhitelist=" + Arrays.toString(mDeviceIdleUserWhitelist));
pw.println();
pw.println(" Next alarm clock information: ");
final TreeSet<Integer> users = new TreeSet<>();
for (int i = 0; i < mNextAlarmClockForUser.size(); i++) {
users.add(mNextAlarmClockForUser.keyAt(i));
}
for (int i = 0; i < mPendingSendNextAlarmClockChangedForUser.size(); i++) {
users.add(mPendingSendNextAlarmClockChangedForUser.keyAt(i));
}
for (int user : users) {
final AlarmManager.AlarmClockInfo next = mNextAlarmClockForUser.get(user);
final long time = next != null ? next.getTriggerTime() : 0;
final boolean pendingSend = mPendingSendNextAlarmClockChangedForUser.get(user);
pw.print(" user:");
pw.print(user);
pw.print(" pendingSend:");
pw.print(pendingSend);
pw.print(" time:");
pw.print(time);
if (time > 0) {
pw.print(" = ");
pw.print(sdf.format(new Date(time)));
pw.print(" = ");
TimeUtils.formatDuration(time, nowRTC, pw);
}
pw.println();
}
if (mAlarmBatches.size() > 0) {
pw.println();
pw.print(" Pending alarm batches: ");
pw.println(mAlarmBatches.size());
for (Batch b : mAlarmBatches) {
pw.print(b);
pw.println(':');
dumpAlarmList(pw, b.alarms, " ", nowELAPSED, nowRTC, sdf);
}
}
if (mPendingIdleUntil != null || mPendingWhileIdleAlarms.size() > 0) {
pw.println();
pw.println(" Idle mode state:");
pw.print(" Idling until: ");
if (mPendingIdleUntil != null) {
pw.println(mPendingIdleUntil);
mPendingIdleUntil.dump(pw, " ", nowRTC, nowELAPSED, sdf);
} else {
pw.println("null");
}
pw.println(" Pending alarms:");
dumpAlarmList(pw, mPendingWhileIdleAlarms, " ", nowELAPSED, nowRTC, sdf);
}
if (mNextWakeFromIdle != null) {
pw.println();
pw.print(" Next wake from idle: ");
pw.println(mNextWakeFromIdle);
mNextWakeFromIdle.dump(pw, " ", nowRTC, nowELAPSED, sdf);
}
pw.println();
pw.print(" Past-due non-wakeup alarms: ");
if (mPendingNonWakeupAlarms.size() > 0) {
pw.println(mPendingNonWakeupAlarms.size());
dumpAlarmList(pw, mPendingNonWakeupAlarms, " ", nowELAPSED, nowRTC, sdf);
} else {
pw.println("(none)");
}
pw.print(" Number of delayed alarms: ");
pw.print(mNumDelayedAlarms);
pw.print(", total delay time: ");
TimeUtils.formatDuration(mTotalDelayTime, pw);
pw.println();
pw.print(" Max delay time: ");
TimeUtils.formatDuration(mMaxDelayTime, pw);
pw.print(", max non-interactive time: ");
TimeUtils.formatDuration(mNonInteractiveTime, pw);
pw.println();
pw.println();
pw.print(" Broadcast ref count: ");
pw.println(mBroadcastRefCount);
pw.println();
if (mInFlight.size() > 0) {
pw.println("Outstanding deliveries:");
for (int i = 0; i < mInFlight.size(); i++) {
pw.print(" #");
pw.print(i);
pw.print(": ");
pw.println(mInFlight.get(i));
}
pw.println();
}
pw.print(" mAllowWhileIdleMinTime=");
TimeUtils.formatDuration(mAllowWhileIdleMinTime, pw);
pw.println();
if (mLastAllowWhileIdleDispatch.size() > 0) {
pw.println(" Last allow while idle dispatch times:");
for (int i = 0; i < mLastAllowWhileIdleDispatch.size(); i++) {
pw.print(" UID ");
UserHandle.formatUid(pw, mLastAllowWhileIdleDispatch.keyAt(i));
pw.print(": ");
TimeUtils.formatDuration(mLastAllowWhileIdleDispatch.valueAt(i), nowELAPSED, pw);
pw.println();
}
}
pw.println();
if (mLog.dump(pw, " Recent problems", " ")) {
pw.println();
}
final FilterStats[] topFilters = new FilterStats[10];
final Comparator<FilterStats> comparator = new Comparator<FilterStats>() {
@Override
public int compare(FilterStats lhs, FilterStats rhs) {
if (lhs.aggregateTime < rhs.aggregateTime) {
return 1;
} else if (lhs.aggregateTime > rhs.aggregateTime) {
return -1;
}
return 0;
}
};
int len = 0;
for (int iu = 0; iu < mBroadcastStats.size(); iu++) {
ArrayMap<String, BroadcastStats> uidStats = mBroadcastStats.valueAt(iu);
for (int ip = 0; ip < uidStats.size(); ip++) {
BroadcastStats bs = uidStats.valueAt(ip);
for (int is = 0; is < bs.filterStats.size(); is++) {
FilterStats fs = bs.filterStats.valueAt(is);
int pos = len > 0 ? Arrays.binarySearch(topFilters, 0, len, fs, comparator) : 0;
if (pos < 0) {
pos = -pos - 1;
}
if (pos < topFilters.length) {
int copylen = topFilters.length - pos - 1;
if (copylen > 0) {
System.arraycopy(topFilters, pos, topFilters, pos + 1, copylen);
}
topFilters[pos] = fs;
if (len < topFilters.length) {
len++;
}
}
}
}
}
if (len > 0) {
pw.println(" Top Alarms:");
for (int i = 0; i < len; i++) {
FilterStats fs = topFilters[i];
pw.print(" ");
if (fs.nesting > 0)
pw.print("*ACTIVE* ");
TimeUtils.formatDuration(fs.aggregateTime, pw);
pw.print(" running, ");
pw.print(fs.numWakeup);
pw.print(" wakeups, ");
pw.print(fs.count);
pw.print(" alarms: ");
UserHandle.formatUid(pw, fs.mBroadcastStats.mUid);
pw.print(":");
pw.print(fs.mBroadcastStats.mPackageName);
pw.println();
pw.print(" ");
pw.print(fs.mTag);
pw.println();
}
}
pw.println(" ");
pw.println(" Alarm Stats:");
final ArrayList<FilterStats> tmpFilters = new ArrayList<FilterStats>();
for (int iu = 0; iu < mBroadcastStats.size(); iu++) {
ArrayMap<String, BroadcastStats> uidStats = mBroadcastStats.valueAt(iu);
for (int ip = 0; ip < uidStats.size(); ip++) {
BroadcastStats bs = uidStats.valueAt(ip);
pw.print(" ");
if (bs.nesting > 0)
pw.print("*ACTIVE* ");
UserHandle.formatUid(pw, bs.mUid);
pw.print(":");
pw.print(bs.mPackageName);
pw.print(" ");
TimeUtils.formatDuration(bs.aggregateTime, pw);
pw.print(" running, ");
pw.print(bs.numWakeup);
pw.println(" wakeups:");
tmpFilters.clear();
for (int is = 0; is < bs.filterStats.size(); is++) {
tmpFilters.add(bs.filterStats.valueAt(is));
}
Collections.sort(tmpFilters, comparator);
for (int i = 0; i < tmpFilters.size(); i++) {
FilterStats fs = tmpFilters.get(i);
pw.print(" ");
if (fs.nesting > 0)
pw.print("*ACTIVE* ");
TimeUtils.formatDuration(fs.aggregateTime, pw);
pw.print(" ");
pw.print(fs.numWakeup);
pw.print(" wakes ");
pw.print(fs.count);
pw.print(" alarms, last ");
TimeUtils.formatDuration(fs.lastTime, nowELAPSED, pw);
pw.println(":");
pw.print(" ");
pw.print(fs.mTag);
pw.println();
}
}
}
if (RECORD_DEVICE_IDLE_ALARMS) {
pw.println();
pw.println(" Allow while idle dispatches:");
for (int i = 0; i < mAllowWhileIdleDispatches.size(); i++) {
IdleDispatchEntry ent = mAllowWhileIdleDispatches.get(i);
pw.print(" ");
TimeUtils.formatDuration(ent.elapsedRealtime, nowELAPSED, pw);
pw.print(": ");
UserHandle.formatUid(pw, ent.uid);
pw.print(":");
pw.println(ent.pkg);
if (ent.op != null) {
pw.print(" ");
pw.print(ent.op);
pw.print(" / ");
pw.print(ent.tag);
if (ent.argRealtime != 0) {
pw.print(" (");
TimeUtils.formatDuration(ent.argRealtime, nowELAPSED, pw);
pw.print(")");
}
pw.println();
}
}
}
if (WAKEUP_STATS) {
pw.println();
pw.println(" Recent Wakeup History:");
long last = -1;
for (WakeupEvent event : mRecentWakeups) {
pw.print(" ");
pw.print(sdf.format(new Date(event.when)));
pw.print('|');
if (last < 0) {
pw.print('0');
} else {
pw.print(event.when - last);
}
last = event.when;
pw.print('|');
pw.print(event.uid);
pw.print('|');
pw.print(event.action);
pw.println();
}
pw.println();
}
}
}
use of java.util.Comparator in project azure-tools-for-java by Microsoft.
the class MachineSettingsStep method prepare.
@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
rootPanel.revalidate();
boolean isLinux;
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
azure = azureManager.getAzure(((VMWizardModel) model).getSubscription().getSubscriptionId());
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
}
if (model.isKnownMachineImage()) {
isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
} else {
isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem().equals(OperatingSystemTypes.LINUX);
}
if (isLinux) {
certificateCheckBox.setEnabled(true);
passwordCheckBox.setEnabled(true);
certificateCheckBox.setSelected(false);
passwordCheckBox.setSelected(true);
} else {
certificateCheckBox.setSelected(false);
passwordCheckBox.setSelected(true);
certificateCheckBox.setEnabled(false);
passwordCheckBox.setEnabled(false);
}
validateEmptyFields();
if (vmSizeComboBox.getItemCount() == 0) {
vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading VM sizes...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().name());
Collections.sort(sizes, new Comparator<VirtualMachineSize>() {
@Override
public int compare(VirtualMachineSize t0, VirtualMachineSize t1) {
if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
return t0.name().compareTo(t1.name());
} else if (t0.name().contains("Basic")) {
return -1;
} else if (t1.name().contains("Basic")) {
return 1;
}
int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
if (coreCompare == 0) {
return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
} else {
return coreCompare;
}
}
});
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
selectDefaultSize();
}
}, ModalityState.any());
}
});
} else {
selectDefaultSize();
}
return rootPanel;
}
Aggregations