Example usage for java.util LinkedList pop

List of usage examples for java.util LinkedList pop

Introduction

In this page you can find the example usage for java.util LinkedList pop.

Prototype

public E pop() 

Source Link

Document

Pops an element from the stack represented by this list.

Usage

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testMemoryLeakCycling_ExpectPass() throws ActionNotAuthorizedException {

    LinkedList<byte[]> byteQueue = new LinkedList<byte[]>();

    String tableId = "memoryTest";
    int maxBytes = 32;
    int maxIterations = 1000;
    String testColType = ElementDataType.string.name();

    for (int j = 0; j < maxIterations; ++j) {
        if (j % 10 == 0) {
            System.out.println("iteration " + j + " of " + maxIterations);
        }/*  w ww. j a  va 2 s . com*/

        int maxCols = 10 + (j % 7);
        // construct table
        List<Column> columns = new ArrayList<Column>();
        for (int i = 0; i < maxCols; ++i) {
            String testCol = "testColumn_" + Integer.toString(i);
            columns.add(new Column(testCol, testCol, testColType, "[]"));
        }
        OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
                columns);

        ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db,
                tableId, activeUser, RoleConsts.ADMIN_ROLES_LIST);

        String rowId = LocalizationUtils.genUUID();

        ContentValues cvValues = new ContentValues();
        for (int i = 0; i < maxCols; ++i) {
            String testCol = "testColumn_" + Integer.toString(i);
            String testVal = "testVal_" + Integer.toString(i);
            cvValues.put(testCol, testVal);
        }

        ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues, rowId, activeUser,
                RoleConsts.ADMIN_ROLES_LIST, currentLocale);

        // Select everything out of the table
        String queryCol = "testColumn_" + Integer.toString(j % maxCols);
        String queryVal = "testVal_" + Integer.toString(j % maxCols);
        String sel = "SELECT * FROM " + tableId + " WHERE " + queryCol + " = ?";
        String[] selArgs = { queryVal };
        Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

        String val = null;
        while (cursor.moveToNext()) {
            int ind = cursor.getColumnIndex(queryCol);
            int type = cursor.getType(ind);
            assertEquals(type, Cursor.FIELD_TYPE_STRING);
            val = cursor.getString(ind);

            ind = cursor.getColumnIndex(DataTableColumns.SAVEPOINT_TYPE);
            assertFalse(cursor.isNull(ind));

            // Get the conflict_type and make sure that it is null
            ind = cursor.getColumnIndex(DataTableColumns.CONFLICT_TYPE);
            assertTrue(cursor.isNull(ind));
        }

        assertEquals(val, queryVal);
        cursor.close();

        ODKDatabaseImplUtils.get().deleteRowWithId(db, tableId, rowId, activeUser, RoleConsts.ADMIN_ROLES_LIST);

        // Select everything out of the table
        sel = "SELECT * FROM " + tableId;
        selArgs = new String[0];
        cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

        assertEquals(cursor.getCount(), 0);

        // Drop the table now that the test is done
        ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);

        for (int len = 1; len < maxBytes; len += 4) {
            byte[] bytes = new byte[len];
            for (int k = 0; k < len; ++k) {
                bytes[k] = (byte) k;
            }
            byteQueue.add(bytes);
        }
        for (int len = 1; len < maxBytes; len += 4) {
            byte[] bytes = new byte[len];
            for (int k = 0; k < len; ++k) {
                bytes[k] = (byte) k;
            }
            byteQueue.add(bytes);
        }
        for (int len = 1; len < maxBytes; len += 4) {
            byte[] bytes = byteQueue.pop();
            for (int k = 0; k < len; ++k) {
                assertEquals(bytes[k], (byte) k);
            }
        }
    }
}

From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java

private void internalTestMemoryLeakCycling_ExpectPass(int maxIterations) throws ActionNotAuthorizedException {

    LinkedList<byte[]> byteQueue = new LinkedList<byte[]>();

    String tableId = "memoryTest";
    int maxBytes = 32;
    String testColType = ElementDataType.string.name();

    for (int j = 0; j < maxIterations; ++j) {
        if (j % 10 == 0) {
            System.out.println("iteration " + j + " of " + maxIterations);
        }//from w  w w .j  a v a2  s. c  o  m

        int maxCols = 10 + (j % 7);
        // construct table
        List<Column> columns = new ArrayList<Column>();
        for (int i = 0; i < maxCols; ++i) {
            String testCol = "testColumn_" + Integer.toString(i);
            columns.add(new Column(testCol, testCol, testColType, "[]"));
        }
        OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
                columns);

        ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db,
                tableId, activeUser, RoleConsts.ADMIN_ROLES_LIST);

        String rowId = LocalizationUtils.genUUID();

        ContentValues cvValues = new ContentValues();
        for (int i = 0; i < maxCols; ++i) {
            String testCol = "testColumn_" + Integer.toString(i);
            String testVal = "testVal_" + Integer.toString(i);
            cvValues.put(testCol, testVal);
        }

        ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues, rowId, activeUser,
                RoleConsts.ADMIN_ROLES_LIST, currentLocale);

        // Select everything out of the table
        String queryCol = "testColumn_" + Integer.toString(j % maxCols);
        String queryVal = "testVal_" + Integer.toString(j % maxCols);
        String sel = "SELECT * FROM " + tableId + " WHERE " + queryCol + " = ?";
        String[] selArgs = { queryVal };
        Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

        String val = null;
        while (cursor.moveToNext()) {
            int ind = cursor.getColumnIndex(queryCol);
            int type = cursor.getType(ind);
            assertEquals(type, Cursor.FIELD_TYPE_STRING);
            val = cursor.getString(ind);

            ind = cursor.getColumnIndex(DataTableColumns.SAVEPOINT_TYPE);
            assertFalse(cursor.isNull(ind));

            // Get the conflict_type and make sure that it is null
            ind = cursor.getColumnIndex(DataTableColumns.CONFLICT_TYPE);
            assertTrue(cursor.isNull(ind));
        }

        assertEquals(val, queryVal);
        cursor.close();

        ODKDatabaseImplUtils.get().deleteRowWithId(db, tableId, rowId, activeUser, RoleConsts.ADMIN_ROLES_LIST);

        // Select everything out of the table
        sel = "SELECT * FROM " + tableId;
        selArgs = new String[0];
        cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

        assertEquals(cursor.getCount(), 0);

        // Drop the table now that the test is done
        ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);

        for (int len = 1; len < maxBytes; len += 4) {
            byte[] bytes = new byte[len];
            for (int k = 0; k < len; ++k) {
                bytes[k] = (byte) k;
            }
            byteQueue.add(bytes);
        }
        for (int len = 1; len < maxBytes; len += 4) {
            byte[] bytes = new byte[len];
            for (int k = 0; k < len; ++k) {
                bytes[k] = (byte) k;
            }
            byteQueue.add(bytes);
        }
        for (int len = 1; len < maxBytes; len += 4) {
            byte[] bytes = byteQueue.pop();
            for (int k = 0; k < len; ++k) {
                assertEquals(bytes[k], (byte) k);
            }
        }
    }
}