Search in sources :

Example 56 with BitSet

use of java.util.BitSet in project android_frameworks_base by DirtyUnicorns.

the class ModelTest method testSort_sizes.

// Tests sorting by item size.
public void testSort_sizes() {
    DirectoryResult r = new DirectoryResult();
    r.cursor = cursor;
    r.sortOrder = State.SORT_ORDER_SIZE;
    model.update(r);
    BitSet seen = new BitSet(ITEM_COUNT);
    int previousSize = Integer.MAX_VALUE;
    for (String id : model.getModelIds()) {
        Cursor c = model.getItem(id);
        seen.set(c.getPosition());
        // Check sort order - descending numerical
        int size = DocumentInfo.getCursorInt(c, Document.COLUMN_SIZE);
        assertTrue(previousSize >= size);
        previousSize = size;
    }
    // Check that all items were accounted for.
    assertEquals(ITEM_COUNT, seen.cardinality());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) BitSet(java.util.BitSet) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor)

Example 57 with BitSet

use of java.util.BitSet in project android_frameworks_base by DirtyUnicorns.

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();
        mDemoWifiState.ssid = "DemoMode";
    } 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;
            }
            String activity = args.getString("activity");
            if (activity != null) {
                switch(activity) {
                    case "inout":
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_INOUT);
                        break;
                    case "in":
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_IN);
                        break;
                    case "out":
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_OUT);
                        break;
                    default:
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_NONE);
                        break;
                }
            } else {
                mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_NONE);
            }
            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("hp") ? TelephonyIcons.HP : 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.getState().dataConnected = true;
                switch(activity) {
                    case "inout":
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
                        break;
                    case "in":
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_IN);
                        break;
                    case "out":
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_OUT);
                        break;
                    default:
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE);
                        break;
                }
            } else {
                controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE);
            }
            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 58 with BitSet

use of java.util.BitSet in project android_frameworks_base by DirtyUnicorns.

the class WifiConfiguration method readBitSet.

private static BitSet readBitSet(Parcel src) {
    int cardinality = src.readInt();
    BitSet set = new BitSet();
    for (int i = 0; i < cardinality; i++) {
        set.set(src.readInt());
    }
    return set;
}
Also used : BitSet(java.util.BitSet)

Example 59 with BitSet

use of java.util.BitSet in project jdk8u_jdk by JetBrains.

the class And method main.

public static void main(String[] args) throws Exception {
    BitSet a = new BitSet();
    BitSet b = new BitSet();
    a.set(0);
    a.set(70);
    b.set(40);
    a.and(b);
    if (a.length() != 0)
        throw new RuntimeException("Incorrect length after and().");
}
Also used : BitSet(java.util.BitSet)

Example 60 with BitSet

use of java.util.BitSet in project jdk8u_jdk by JetBrains.

the class BitSetStreamTest method testRandomStream.

@Test
public void testRandomStream() {
    final int size = 1024 * 1024;
    final int[] seeds = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
    final byte[] bytes = new byte[size];
    for (int seed : seeds) {
        final Random random = new Random(seed);
        random.nextBytes(bytes);
        final BitSet bitSet = BitSet.valueOf(bytes);
        final int cardinality = bitSet.cardinality();
        final IntStream stream = bitSet.stream();
        final int[] array = stream.toArray();
        assertEquals(array.length, cardinality);
        int nextSetBit = -1;
        for (int i = 0; i < cardinality; i++) {
            nextSetBit = bitSet.nextSetBit(nextSetBit + 1);
            assertEquals(array[i], nextSetBit);
        }
    }
}
Also used : Random(java.util.Random) BitSet(java.util.BitSet) IntStream(java.util.stream.IntStream) Test(org.testng.annotations.Test)

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