Search in sources :

Example 66 with BitSet

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);
    }
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor)

Example 67 with BitSet

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);
            }
        }
    }
}
Also used : BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 68 with BitSet

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);
    });
}
Also used : BitSet(java.util.BitSet) FairDiffIterable(com.intellij.diff.comparison.iterables.FairDiffIterable) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with BitSet

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);
}
Also used : GenericPatchApplier(com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier) List(java.util.List) BeforeAfter(com.intellij.util.BeforeAfter) BitSet(java.util.BitSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) LineRange(com.intellij.diff.util.LineRange) NOT_APPLIED(com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.HunkStatus.NOT_APPLIED) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) LineRange(com.intellij.diff.util.LineRange)

Example 70 with BitSet

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));
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) BitSet(java.util.BitSet)

Aggregations

BitSet (java.util.BitSet)2037 Test (org.junit.Test)294 ArrayList (java.util.ArrayList)224 List (java.util.List)83 HashMap (java.util.HashMap)76 Map (java.util.Map)70 IOException (java.io.IOException)60 HashSet (java.util.HashSet)52 Test (org.junit.jupiter.api.Test)47 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)45 Random (java.util.Random)42 Configuration (org.apache.hadoop.conf.Configuration)40 Path (org.apache.hadoop.fs.Path)39 ValidReadTxnList (org.apache.hadoop.hive.common.ValidReadTxnList)33 BlockNode (jadx.core.dex.nodes.BlockNode)29 File (java.io.File)27 LinkedList (java.util.LinkedList)27 RexNode (org.apache.calcite.rex.RexNode)27 ByteBuffer (java.nio.ByteBuffer)25 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)25