use of java.util.BitSet in project android_frameworks_base by AOSPA.
the class ModelTest method testSort_names.
// Tests sorting by item name.
public void testSort_names() {
BitSet seen = new BitSet(ITEM_COUNT);
List<String> names = new ArrayList<>();
DirectoryResult r = new DirectoryResult();
r.cursor = cursor;
r.sortOrder = State.SORT_ORDER_DISPLAY_NAME;
model.update(r);
for (String id : model.getModelIds()) {
Cursor c = model.getItem(id);
seen.set(c.getPosition());
names.add(DocumentInfo.getCursorString(c, Document.COLUMN_DISPLAY_NAME));
}
assertEquals(ITEM_COUNT, seen.cardinality());
for (int i = 0; i < names.size() - 1; ++i) {
assertTrue(Shared.compareToIgnoreCaseNullable(names.get(i), names.get(i + 1)) <= 0);
}
}
use of java.util.BitSet in project android_frameworks_base by AOSPA.
the class NetworkControllerImpl method dispatchDemoCommand.
@Override
public void dispatchDemoCommand(String command, Bundle args) {
if (!mDemoMode && command.equals(COMMAND_ENTER)) {
if (DEBUG)
Log.d(TAG, "Entering demo mode");
unregisterListeners();
mDemoMode = true;
mDemoInetCondition = mInetCondition;
mDemoWifiState = mWifiSignalController.getState();
} else if (mDemoMode && command.equals(COMMAND_EXIT)) {
if (DEBUG)
Log.d(TAG, "Exiting demo mode");
mDemoMode = false;
// Update what MobileSignalControllers, because they may change
// to set the number of sim slots.
updateMobileControllers();
for (MobileSignalController controller : mMobileSignalControllers.values()) {
controller.resetLastState();
}
mWifiSignalController.resetLastState();
mReceiverHandler.post(mRegisterListeners);
notifyAllListeners();
} else if (mDemoMode && command.equals(COMMAND_NETWORK)) {
String airplane = args.getString("airplane");
if (airplane != null) {
boolean show = airplane.equals("show");
mCallbackHandler.setIsAirplaneMode(new IconState(show, TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext));
}
String fully = args.getString("fully");
if (fully != null) {
mDemoInetCondition = Boolean.parseBoolean(fully);
BitSet connected = new BitSet();
if (mDemoInetCondition) {
connected.set(mWifiSignalController.mTransportType);
}
mWifiSignalController.updateConnectivity(connected, connected);
for (MobileSignalController controller : mMobileSignalControllers.values()) {
if (mDemoInetCondition) {
connected.set(controller.mTransportType);
}
controller.updateConnectivity(connected, connected);
}
}
String wifi = args.getString("wifi");
if (wifi != null) {
boolean show = wifi.equals("show");
String level = args.getString("level");
if (level != null) {
mDemoWifiState.level = level.equals("null") ? -1 : Math.min(Integer.parseInt(level), WifiIcons.WIFI_LEVEL_COUNT - 1);
mDemoWifiState.connected = mDemoWifiState.level >= 0;
}
mDemoWifiState.enabled = show;
mWifiSignalController.notifyListeners();
}
String sims = args.getString("sims");
if (sims != null) {
int num = MathUtils.constrain(Integer.parseInt(sims), 1, 8);
List<SubscriptionInfo> subs = new ArrayList<>();
if (num != mMobileSignalControllers.size()) {
mMobileSignalControllers.clear();
int start = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
for (int i = start; /* get out of normal index range */
i < start + num; i++) {
subs.add(addSignalController(i, i));
}
mCallbackHandler.setSubs(subs);
}
}
String nosim = args.getString("nosim");
if (nosim != null) {
mHasNoSims = nosim.equals("show");
mCallbackHandler.setNoSims(mHasNoSims);
}
String mobile = args.getString("mobile");
if (mobile != null) {
boolean show = mobile.equals("show");
String datatype = args.getString("datatype");
String slotString = args.getString("slot");
int slot = TextUtils.isEmpty(slotString) ? 0 : Integer.parseInt(slotString);
slot = MathUtils.constrain(slot, 0, 8);
// Ensure we have enough sim slots
List<SubscriptionInfo> subs = new ArrayList<>();
while (mMobileSignalControllers.size() <= slot) {
int nextSlot = mMobileSignalControllers.size();
subs.add(addSignalController(nextSlot, nextSlot));
}
if (!subs.isEmpty()) {
mCallbackHandler.setSubs(subs);
}
// Hack to index linearly for easy use.
MobileSignalController controller = mMobileSignalControllers.values().toArray(new MobileSignalController[0])[slot];
controller.getState().dataSim = datatype != null;
if (datatype != null) {
controller.getState().iconGroup = datatype.equals("1x") ? TelephonyIcons.ONE_X : datatype.equals("3g") ? TelephonyIcons.THREE_G : datatype.equals("4g") ? TelephonyIcons.FOUR_G : datatype.equals("4g+") ? TelephonyIcons.FOUR_G_PLUS : datatype.equals("e") ? TelephonyIcons.E : datatype.equals("g") ? TelephonyIcons.G : datatype.equals("h") ? TelephonyIcons.H : datatype.equals("lte") ? TelephonyIcons.LTE : datatype.equals("lte+") ? TelephonyIcons.LTE_PLUS : TelephonyIcons.UNKNOWN;
}
if (args.containsKey("roam")) {
controller.getState().roaming = "show".equals(args.getString("roam"));
}
int[][] icons = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH;
String level = args.getString("level");
if (level != null) {
controller.getState().level = level.equals("null") ? -1 : Math.min(Integer.parseInt(level), icons[0].length - 1);
controller.getState().connected = controller.getState().level >= 0;
}
String activity = args.getString("activity");
if (activity != null) {
controller.setActivity(Integer.parseInt(activity));
}
controller.getState().enabled = show;
controller.notifyListeners();
}
String carrierNetworkChange = args.getString("carriernetworkchange");
if (carrierNetworkChange != null) {
boolean show = carrierNetworkChange.equals("show");
for (MobileSignalController controller : mMobileSignalControllers.values()) {
controller.setCarrierNetworkChangeMode(show);
}
}
}
}
use of java.util.BitSet in project intellij-community by JetBrains.
the class ComparisonManagerImpl method compareLinesWithIgnoredRanges.
/**
* Compare two texts by-line and then compare changed fragments by-word
*/
@NotNull
public List<LineFragment> compareLinesWithIgnoredRanges(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull List<TextRange> ignoredRanges1, @NotNull List<TextRange> ignoredRanges2, boolean innerFragments, @NotNull ProgressIndicator indicator) throws DiffTooBigException {
BitSet ignored1 = collectIgnoredRanges(ignoredRanges1);
BitSet ignored2 = collectIgnoredRanges(ignoredRanges2);
List<Line> lines1 = getLines(text1);
List<Line> lines2 = getLines(text2);
List<CharSequence> lineTexts1 = ContainerUtil.map(lines1, line -> line.getNotIgnoredContent(ignored1));
List<CharSequence> lineTexts2 = ContainerUtil.map(lines2, line -> line.getNotIgnoredContent(ignored2));
FairDiffIterable iterable = ByLine.compare(lineTexts1, lineTexts2, ComparisonPolicy.DEFAULT, indicator);
FairDiffIterable correctedIterable = correctIgnoredRangesSecondStep(iterable, lines1, lines2, ignored1, ignored2);
List<LineFragment> lineFragments = convertIntoLineFragments(lines1, lines2, correctedIterable);
if (innerFragments) {
lineFragments = createInnerFragments(lineFragments, text1, text2, ComparisonPolicy.DEFAULT, indicator);
}
return ContainerUtil.mapNotNull(lineFragments, fragment -> {
return trimIgnoredChanges(fragment, lines1, lines2, ignored1, ignored2);
});
}
use of java.util.BitSet in project intellij-community by JetBrains.
the class AppliedTextPatch method create.
public static AppliedTextPatch create(@NotNull List<AppliedSplitPatchHunk> splitPatchHunkList) {
List<AppliedSplitPatchHunk> hunks = new ArrayList<>(splitPatchHunkList);
// ensure, that `appliedTo` ranges do not overlap
BitSet appliedLines = new BitSet();
for (int i = 0; i < hunks.size(); i++) {
AppliedSplitPatchHunk hunk = hunks.get(i);
LineRange appliedTo = hunk.getAppliedTo();
if (appliedTo == null)
continue;
int nextAppliedLine = appliedLines.nextSetBit(appliedTo.start);
if (nextAppliedLine != -1 && nextAppliedLine < appliedTo.end) {
hunks.set(i, new AppliedSplitPatchHunk(hunk, -1, -1, NOT_APPLIED));
} else {
appliedLines.set(appliedTo.start, appliedTo.end, true);
}
}
ContainerUtil.sort(hunks, Comparator.comparingInt(o -> o.getLineRangeBefore().start));
return new AppliedTextPatch(hunks);
}
use of java.util.BitSet in project gerrit by GerritCodeReview.
the class TagSet method readObject.
void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
int refCnt = in.readInt();
for (int i = 0; i < refCnt; i++) {
String name = in.readUTF();
int flag = in.readInt();
ObjectId id = readNotNull(in);
refs.put(name, new CachedRef(flag, id));
}
int tagCnt = in.readInt();
for (int i = 0; i < tagCnt; i++) {
ObjectId id = readNotNull(in);
BitSet flags = (BitSet) in.readObject();
tags.add(new Tag(id, flags));
}
}
Aggregations