Android™
Android™
Subtract One MessageSet from Another
See more IMAP Examples
Demonstrates the Chilkat MessageSet.Subtract method, which removes from this set every identifier whose numeric value is also present in another MessageSet. The only argument is the other set. This example starts with ids 1:10, subtracts 2,4,6, and prints what remains.
Background: A common IMAP pattern is "process everything except what I've already handled."
Subtract makes that a single call: remove the already-processed ids from a working set. The comparison is numeric only and this object's HasUids is preserved, so for meaningful results both sets should hold the same id type from the same mailbox. Passing the same object clears the set; passing an empty set changes nothing.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Demonstrates the MessageSet.Subtract method, which removes from this set every identifier
// that is also present in another MessageSet. The only argument is the other MessageSet.
CkMessageSet msgSet = new CkMessageSet();
// Start with messages 1 through 10.
success = msgSet.FromCompactString("1:10");
if (success == false) {
Log.i(TAG, msgSet.lastErrorText());
return;
}
// The identifiers that have already been processed and should be excluded.
CkMessageSet processed = new CkMessageSet();
success = processed.FromCompactString("2,4,6");
if (success == false) {
Log.i(TAG, processed.lastErrorText());
return;
}
// Remove the already-processed identifiers from msgSet.
msgSet.Subtract(processed);
// Show what remains.
String remaining = msgSet.toCompactString();
Log.i(TAG, remaining);
// Output: 1,3,5,7:10
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}