Example usage for java.util HashMap values

List of usage examples for java.util HashMap values

Introduction

In this page you can find the example usage for java.util HashMap values.

Prototype

public Collection<V> values() 

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

/**
 * Test method for 'java.util.AbstractMap.values()'.
 *///w w w  .  ja  v  a 2 s  .c  o m
public void testValues() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(hashMap);

    assertNotNull(hashMap.values());

    hashMap.put(KEY_KEY, VALUE_VAL);

    Collection<String> valColl = hashMap.values();
    assertNotNull(valColl);
    assertEquals(valColl.size(), SIZE_ONE);

    Iterator<String> itVal = valColl.iterator();
    String val = itVal.next();
    assertEquals(val, VALUE_VAL);
}

From source file:org.apache.axis2.context.ConfigurationContext.java

/**
 * Registers a OperationContext with a given message ID.
 * If the given message id already has a registered operation context,
 * no change is made unless the override flag is set. 
 *
 * @param messageID/*from  w w w .j  a v  a 2  s.  co m*/
 * @param mepContext
 * @param override
 */
public boolean registerOperationContext(String messageID, OperationContext mepContext, boolean override) {

    if (messageID == null) {
        if (log.isDebugEnabled()) {
            log.debug("messageID is null. Returning false");
        }
        return false;
    }

    boolean alreadyInMap = false;
    mepContext.setKey(messageID);

    if (override) {
        operationContextMap.put(messageID, mepContext);
    } else {
        Object previous = operationContextMap.putIfAbsent(messageID, mepContext);
        alreadyInMap = (previous != null);
    }
    if (log.isDebugEnabled()) {
        log.debug("registerOperationContext (" + override + "): " + mepContext + " with key: " + messageID);
        HashMap msgContextMap = mepContext.getMessageContexts();
        Iterator msgContextIterator = msgContextMap.values().iterator();
        while (msgContextIterator.hasNext()) {
            MessageContext msgContext = (MessageContext) msgContextIterator.next();
            log.debug("msgContext: " + msgContext + " action: " + msgContext.getWSAAction());
        }
    }
    return (!alreadyInMap || override);
}

From source file:eu.stratosphere.pact.runtime.task.CombineTaskExternalITCase.java

@Test
public void testMultiLevelMergeCombineTask() {

    int keyCnt = 32768;
    int valCnt = 8;

    super.initEnvironment(3 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1);
    super.addOutput(this.outList);

    CombineTask<PactRecord> testTask = new CombineTask<PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT);
    super.getTaskConfig().setMemorySize(3 * 1024 * 1024);
    super.getTaskConfig().setNumFilehandles(2);

    final int[] keyPos = new int[] { 0 };
    @SuppressWarnings("unchecked")
    final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class };
    PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(),
            super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses);

    super.registerTask(testTask, MockCombiningReduceStub.class);

    try {/*from www . j ava 2  s.com*/
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expSum = 0;
    for (int i = 1; i < valCnt; i++) {
        expSum += i;
    }

    // wee need to do the final aggregation manually in the test, because the
    // combiner is not guaranteed to do that
    HashMap<PactInteger, PactInteger> aggMap = new HashMap<PactInteger, PactInteger>();
    for (PactRecord record : this.outList) {
        PactInteger key = new PactInteger();
        PactInteger value = new PactInteger();
        record.getField(0, key);
        record.getField(1, value);

        PactInteger prevVal = aggMap.get(key);
        if (prevVal != null) {
            aggMap.put(key, new PactInteger(prevVal.getValue() + value.getValue()));
        } else {
            aggMap.put(key, value);
        }
    }

    Assert.assertTrue("Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
            aggMap.size() == keyCnt);

    for (PactInteger integer : aggMap.values()) {
        Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
    }

    this.outList.clear();

}

From source file:org.apache.hadoop.net.TestClusterTopology.java

/**
 * Test how well we pick random nodes./*w w  w  .j av  a2  s .  c o m*/
 */
@Test
public void testChooseRandom() {
    // create the topology
    NetworkTopology cluster = new NetworkTopology();
    NodeElement node1 = getNewNode("node1", "/d1/r1");
    cluster.add(node1);
    NodeElement node2 = getNewNode("node2", "/d1/r2");
    cluster.add(node2);
    NodeElement node3 = getNewNode("node3", "/d1/r3");
    cluster.add(node3);
    NodeElement node4 = getNewNode("node4", "/d1/r3");
    cluster.add(node4);

    // Number of iterations to do the test
    int numIterations = 100;

    // Pick random nodes
    HashMap<String, Integer> histogram = new HashMap<String, Integer>();
    for (int i = 0; i < numIterations; i++) {
        String randomNode = cluster.chooseRandom(NodeBase.ROOT).getName();
        if (!histogram.containsKey(randomNode)) {
            histogram.put(randomNode, 0);
        }
        histogram.put(randomNode, histogram.get(randomNode) + 1);
    }
    assertEquals("Random is not selecting all nodes", 4, histogram.size());

    // Check with 99% confidence (alpha=0.01 as confidence = (100 * (1 - alpha)
    ChiSquareTest chiSquareTest = new ChiSquareTest();
    double[] expected = new double[histogram.size()];
    long[] observed = new long[histogram.size()];
    int j = 0;
    for (Integer occurrence : histogram.values()) {
        expected[j] = 1.0 * numIterations / histogram.size();
        observed[j] = occurrence;
        j++;
    }
    boolean chiSquareTestRejected = chiSquareTest.chiSquareTest(expected, observed, 0.01);

    // Check that they have the proper distribution
    assertFalse("Not choosing nodes randomly", chiSquareTestRejected);

    // Pick random nodes excluding the 2 nodes in /d1/r3
    histogram = new HashMap<String, Integer>();
    for (int i = 0; i < numIterations; i++) {
        String randomNode = cluster.chooseRandom("~/d1/r3").getName();
        if (!histogram.containsKey(randomNode)) {
            histogram.put(randomNode, 0);
        }
        histogram.put(randomNode, histogram.get(randomNode) + 1);
    }
    assertEquals("Random is not selecting the nodes it should", 2, histogram.size());
}

From source file:net.tourbook.tour.photo.TourPhotoManager.java

private static void setTourCameras(final HashMap<String, String> cameras, final TourPhotoLink historyTour) {

    final Collection<String> allCameras = cameras.values();
    Collections.sort(new ArrayList<String>(allCameras));

    final StringBuilder sb = new StringBuilder();
    boolean isFirst = true;

    for (final String camera : allCameras) {
        if (isFirst) {
            isFirst = false;/*from ww  w .  ja v a  2  s  . co  m*/
            sb.append(camera);
        } else {
            sb.append(UI.COMMA_SPACE);
            sb.append(camera);
        }
    }
    historyTour.tourCameras = sb.toString();
}

From source file:eu.stratosphere.pact.runtime.task.CombineTaskExternalITCase.java

@Test
public void testSingleLevelMergeCombineTask() {

    int keyCnt = 8192;
    int valCnt = 8;

    super.initEnvironment(3 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1);
    super.addOutput(this.outList);

    CombineTask<PactRecord> testTask = new CombineTask<PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT);
    super.getTaskConfig().setMemorySize(3 * 1024 * 1024);
    super.getTaskConfig().setNumFilehandles(2);

    final int[] keyPos = new int[] { 0 };
    @SuppressWarnings("unchecked")
    final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class };
    PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(),
            super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses);

    super.registerTask(testTask, MockCombiningReduceStub.class);

    try {/*  w ww.  j  ava  2  s . c om*/
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expSum = 0;
    for (int i = 1; i < valCnt; i++) {
        expSum += i;
    }

    // wee need to do the final aggregation manually in the test, because the
    // combiner is not guaranteed to do that
    HashMap<PactInteger, PactInteger> aggMap = new HashMap<PactInteger, PactInteger>();
    for (PactRecord record : this.outList) {
        PactInteger key = new PactInteger();
        PactInteger value = new PactInteger();
        key = record.getField(0, key);
        value = record.getField(1, value);
        PactInteger prevVal = aggMap.get(key);
        if (prevVal != null) {
            aggMap.put(key, new PactInteger(prevVal.getValue() + value.getValue()));
        } else {
            aggMap.put(key, value);
        }
    }

    Assert.assertTrue("Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
            aggMap.size() == keyCnt);

    for (PactInteger integer : aggMap.values()) {
        Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
    }

    this.outList.clear();

}

From source file:com.github.vseguip.sweet.contacts.SweetContactSync.java

/**
 * Fetches the list of newer contacts in small batches to avoid out of
 * memory errors or excessively long query times that can timeout. *Must* be
 * orderd by modification date to be consistent so the last returned
 * contacts are always the newer ones. This can lead to a contact being returned two times so we use a hashtable to avoid this.
 * /*  ww  w  . j a va  2  s .c o  m*/
 * @param sugar The Sugar API object
 * @param lastDate Anchor for newer contacts
 * @return The list of contacts
 * @throws IOException
 */
public List<ISweetContact> fetchContacts(SugarAPI sugar, String lastDate)
        throws AuthenticationException, IOException {
    List<ISweetContact> contacts = null;
    HashMap<String, ISweetContact> allContacts = new HashMap<String, ISweetContact>();
    int cursor = 0;
    do {
        Log.i(TAG, "Getting batch from " + cursor + " to " + (cursor + BATCH_SIZE) + " contacts");
        contacts = sugar.getNewerContacts(mAuthToken, lastDate, cursor, BATCH_SIZE);
        for (ISweetContact contact : contacts) {
            allContacts.put(contact.getId(), contact);
        }
        cursor += BATCH_SIZE;
    } while ((contacts != null) && (contacts.size() == BATCH_SIZE));
    if (contacts != null)
        contacts = new ArrayList<ISweetContact>(allContacts.values());
    return contacts;
}

From source file:ch.fixme.status.Main.java

private void populateDataHs() {
    try {/*from www  .  jav  a2  s .c o m*/
        HashMap<String, Object> data = new ParseGeneric(mResultHs).getData();

        // Initialize views
        LayoutInflater inflater = getLayoutInflater();
        LinearLayout vg = (LinearLayout) inflater.inflate(R.layout.base, null);
        ScrollView scroll = (ScrollView) findViewById(R.id.scroll);
        scroll.removeAllViews();
        scroll.addView(vg);

        // Mandatory fields
        ((TextView) findViewById(R.id.space_name)).setText((String) data.get(ParseGeneric.API_NAME));
        ((TextView) findViewById(R.id.space_url)).setText((String) data.get(ParseGeneric.API_URL));
        getImageTask = new GetImage(R.id.space_image);
        getImageTask.execute((String) data.get(ParseGeneric.API_LOGO));

        // Status text
        String status_txt = "";
        if ((Boolean) data.get(ParseGeneric.API_STATUS)) {
            status_txt = OPEN;
            ((TextView) findViewById(R.id.status_txt))
                    .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_online, 0, 0, 0);
        } else {
            status_txt = CLOSED;
            ((TextView) findViewById(R.id.status_txt))
                    .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_busy, 0, 0, 0);
        }
        if (data.containsKey(ParseGeneric.API_STATUS_TXT)) {
            status_txt += ": " + (String) data.get(ParseGeneric.API_STATUS_TXT);
        }
        ((TextView) findViewById(R.id.status_txt)).setText(status_txt);

        // Status last change
        if (data.containsKey(ParseGeneric.API_LASTCHANGE)) {
            TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
            tv.setAutoLinkMask(0);
            tv.setText(
                    getString(R.string.api_lastchange) + " " + (String) data.get(ParseGeneric.API_LASTCHANGE));
            vg.addView(tv);
        }

        // Status duration
        if (data.containsKey(ParseGeneric.API_EXT_DURATION) && (Boolean) data.get(ParseGeneric.API_STATUS)) {
            TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
            tv.setText(getString(R.string.api_duration) + " " + (String) data.get(ParseGeneric.API_EXT_DURATION)
                    + getString(R.string.api_duration_hours));
            vg.addView(tv);
        }

        // Location
        Pattern ptn = Pattern.compile("^.*$", Pattern.DOTALL);
        if (data.containsKey(ParseGeneric.API_ADDRESS) || data.containsKey(ParseGeneric.API_LON)) {
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(getString(R.string.api_location));
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);
            // Address
            if (data.containsKey(ParseGeneric.API_ADDRESS)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setAutoLinkMask(0);
                tv.setText((String) data.get(ParseGeneric.API_ADDRESS));
                Linkify.addLinks(tv, ptn, MAP_SEARCH);
                vg.addView(tv);
            }
            // Lon/Lat
            if (data.containsKey(ParseGeneric.API_LON) && data.containsKey(ParseGeneric.API_LAT)) {
                String addr = (data.containsKey(ParseGeneric.API_ADDRESS))
                        ? (String) data.get(ParseGeneric.API_ADDRESS)
                        : getString(R.string.empty);
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setAutoLinkMask(0);
                tv.setText((String) data.get(ParseGeneric.API_LON) + ", "
                        + (String) data.get(ParseGeneric.API_LAT));
                Linkify.addLinks(tv, ptn, String.format(MAP_COORD, (String) data.get(ParseGeneric.API_LAT),
                        (String) data.get(ParseGeneric.API_LON), addr));
                vg.addView(tv);
            }
        }

        // Contact
        if (data.containsKey(ParseGeneric.API_PHONE) || data.containsKey(ParseGeneric.API_TWITTER)
                || data.containsKey(ParseGeneric.API_IRC) || data.containsKey(ParseGeneric.API_EMAIL)
                || data.containsKey(ParseGeneric.API_ML)) {
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(R.string.api_contact);
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);

            // Phone
            if (data.containsKey(ParseGeneric.API_PHONE)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_PHONE));
                vg.addView(tv);
            }
            // SIP
            if (data.containsKey(ParseGeneric.API_SIP)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_SIP));
                vg.addView(tv);
            }
            // Twitter
            if (data.containsKey(ParseGeneric.API_TWITTER)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText(TWITTER + (String) data.get(ParseGeneric.API_TWITTER));
                vg.addView(tv);
            }
            // Identica
            if (data.containsKey(ParseGeneric.API_IDENTICA)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_IDENTICA));
                vg.addView(tv);
            }
            // Foursquare
            if (data.containsKey(ParseGeneric.API_FOURSQUARE)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText(FOURSQUARE + (String) data.get(ParseGeneric.API_FOURSQUARE));
                vg.addView(tv);
            }
            // IRC
            if (data.containsKey(ParseGeneric.API_IRC)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setAutoLinkMask(0);
                tv.setText((String) data.get(ParseGeneric.API_IRC));
                vg.addView(tv);
            }
            // Email
            if (data.containsKey(ParseGeneric.API_EMAIL)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_EMAIL));
                vg.addView(tv);
            }
            // Jabber
            if (data.containsKey(ParseGeneric.API_JABBER)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_JABBER));
                vg.addView(tv);
            }
            // Mailing-List
            if (data.containsKey(ParseGeneric.API_ML)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_ML));
                vg.addView(tv);
            }
        }

        // Sensors
        if (data.containsKey(ParseGeneric.API_SENSORS)) {
            // Title
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(getString(R.string.api_sensors));
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);

            HashMap<String, ArrayList<HashMap<String, String>>> sensors = (HashMap<String, ArrayList<HashMap<String, String>>>) data
                    .get(ParseGeneric.API_SENSORS);
            Set<String> names = sensors.keySet();
            Iterator<String> it = names.iterator();
            while (it.hasNext()) {
                String name = it.next();
                // Subtitle
                String name_title = name.toLowerCase().replace("_", " ");
                name_title = name_title.substring(0, 1).toUpperCase()
                        + name_title.substring(1, name_title.length());
                TextView subtitle = (TextView) inflater.inflate(R.layout.subtitle, null);
                subtitle.setText(name_title);
                vg.addView(subtitle);
                // Sensors data
                ArrayList<HashMap<String, String>> sensorsData = sensors.get(name);
                for (HashMap<String, String> elem : sensorsData) {
                    RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.entry_sensor, null);
                    if (elem.containsKey(ParseGeneric.API_VALUE)) {
                        ((TextView) rl.findViewById(R.id.entry_value))
                                .setText(elem.get(ParseGeneric.API_VALUE));
                    } else {
                        rl.findViewById(R.id.entry_value).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_UNIT)) {
                        ((TextView) rl.findViewById(R.id.entry_unit)).setText(elem.get(ParseGeneric.API_UNIT));
                    } else {
                        rl.findViewById(R.id.entry_unit).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_NAME2)) {
                        ((TextView) rl.findViewById(R.id.entry_name)).setText(elem.get(ParseGeneric.API_NAME2));
                    } else {
                        rl.findViewById(R.id.entry_name).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_LOCATION2)) {
                        ((TextView) rl.findViewById(R.id.entry_location))
                                .setText(elem.get(ParseGeneric.API_LOCATION2));
                    } else {
                        rl.findViewById(R.id.entry_location).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_DESCRIPTION)) {
                        ((TextView) rl.findViewById(R.id.entry_description))
                                .setText(elem.get(ParseGeneric.API_DESCRIPTION));
                    } else {
                        rl.findViewById(R.id.entry_description).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_PROPERTIES)) {
                        ((TextView) rl.findViewById(R.id.entry_properties))
                                .setText(elem.get(ParseGeneric.API_PROPERTIES));
                    } else {
                        rl.findViewById(R.id.entry_properties).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_MACHINES)) {
                        ((TextView) rl.findViewById(R.id.entry_other))
                                .setText(elem.get(ParseGeneric.API_MACHINES));
                    } else if (elem.containsKey(ParseGeneric.API_NAMES)) {
                        ((TextView) rl.findViewById(R.id.entry_other))
                                .setText(elem.get(ParseGeneric.API_NAMES));
                    } else {
                        rl.findViewById(R.id.entry_other).setVisibility(View.GONE);
                    }
                    vg.addView(rl);
                }
            }
        }

        // Stream and cam
        if (data.containsKey(ParseGeneric.API_STREAM) || data.containsKey(ParseGeneric.API_CAM)) {
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(getString(R.string.api_stream));
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);
            // Stream
            if (data.containsKey(ParseGeneric.API_STREAM)) {
                HashMap<String, String> stream = (HashMap<String, String>) data.get(ParseGeneric.API_STREAM);
                for (Entry<String, String> entry : stream.entrySet()) {
                    final String type = entry.getKey();
                    final String url = entry.getValue();
                    TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                    tv.setText(url);
                    tv.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setDataAndType(Uri.parse(url), type);
                            startActivity(i);
                        }
                    });
                    vg.addView(tv);
                }
            }
            // Cam
            if (data.containsKey(ParseGeneric.API_CAM)) {
                HashMap<String, String> cam = (HashMap<String, String>) data.get(ParseGeneric.API_CAM);
                for (String value : cam.values()) {
                    TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                    tv.setText(value);
                    vg.addView(tv);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        showError(e.getClass().getCanonicalName(), e.getLocalizedMessage() + getString(R.string.error_generic));
    }
}

From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java

/**
 * Loads the remote tasks from the database and merges the two lists. If the
 * remote list contains all items, then this method only adds local db-ids
 * to the items. If it does not contain all of them, this loads whatever
 * extra items are known in the db to the list also.
 *//*from  w  w  w  . j  a  v a2  s.c o  m*/
public static void mergeTasksWithLocalDB(final Context context, final String account,
        final List<GoogleTask> remoteTasks, long listDbId) {
    final HashMap<String, GoogleTask> localVersions = new HashMap<String, GoogleTask>();
    final Cursor c = context.getContentResolver().query(GoogleTask.URI, GoogleTask.Columns.FIELDS,
            GoogleTask.Columns.LISTDBID + " IS ? AND " + GoogleTask.Columns.ACCOUNT + " IS ? AND "
                    + GoogleTask.Columns.SERVICE + " IS ?",
            new String[] { Long.toString(listDbId), account, GoogleTaskList.SERVICENAME }, null);
    try {
        while (c.moveToNext()) {
            GoogleTask task = new GoogleTask(c);
            localVersions.put(task.remoteId, task);
        }
    } finally {
        if (c != null)
            c.close();
    }

    for (final GoogleTask task : remoteTasks) {
        // Set list on remote objects
        task.listdbid = listDbId;
        // Merge with hashmap
        if (localVersions.containsKey(task.remoteId)) {
            task.dbid = localVersions.get(task.remoteId).dbid;
            task.setDeleted(localVersions.get(task.remoteId).isDeleted());
            if (task.isDeleted()) {
                Log.d(TAG, "merge1: deleting " + task.title);
            }
            localVersions.remove(task.remoteId);
        }
    }

    // Remaining ones
    for (final GoogleTask task : localVersions.values()) {
        remoteTasks.add(task);
        if (task.isDeleted()) {
            Log.d(TAG, "merge2: was deleted " + task.title);
        }
    }
}

From source file:com.lines.activitys.OptionsActivity.java

/**
 * Here we get the list of characters in the database
 * /* ww  w.j  av  a 2 s  .  c om*/
 */
private void populateCharacters() {
    mCursor = mDbAdapter.fetchAllLines();

    // First get the data from "character" column and filter out unwanted
    // characters (e.g. STAGE)
    if (mCursor.moveToFirst()) {
        do {
            String character = mCursor.getString(mCursor.getColumnIndex("character"));
            if (!(character.equals("STAGE") || character.contains("and"))) {
                characters.add(character);
            }
        } while (mCursor.moveToNext());
    }

    HashMap<String, Integer> charOccur = new HashMap<String, Integer>();

    // Get the number of lines spoken by each character and store in HashMap
    Set<String> unique = new HashSet<String>(characters);
    for (String key : unique) {
        charOccur.put(key, Collections.frequency(characters, key));
    }

    characters.clear();

    // Sort character list based on the number of lines they have
    while (charOccur.size() > 0) {
        int max = Collections.max(charOccur.values());
        characters.add(getKeyByValue(charOccur, max));
        charOccur.remove(getKeyByValue(charOccur, max));
    }

    // Set contents of Character Spinner
    mAdapterChar = new ArrayAdapter<String>(OptionsActivity.this, android.R.layout.simple_spinner_item,
            characters);
    mAdapterChar.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mChar.setAdapter(mAdapterChar);

    mCursor.close();
}