Interface RecordFilter

Interface RecordFilter
• javax.microedition.rms
• public interface RecordFilter

Interface RecordFilter
• This interface is used to searching in the recordstore.
• Searching is also called as ‘Filtering’.
• It specifies which ...
Searching Records:
• Here, if records matches a search criteria are
copied into the RecordEnumeration and
unmatched record...
• Record Searching(Filtering) is performed by
using interface RecordFilter interface.
• RecordFilter interface requires tw...
Match()
• It is a member method of Filter class
• It is used to read columns from the record and
uses logical operators to...
Logic for searching
Step 1
• Create a filter class by implementing RecordFilter
• Filter class should contain the logic fo...
• The enumerateRecords() method calls methods
defined in the Filter class.
Step 3:
• Execute loop record enumeration and c...
filterClose()
• It is used to free the resources

Interface RecordFilter
•
•
•
•
•
•
•
•
•
•
•
•
•

//searching program and exception handling
import javax.microedition.rms.*;
import javax.microe...
•
•
•
•
•
•
•
•
•
•
•
•
•
•

public void startApp()
{
d.setCurrent(f);
}
public void pauseApp()
{
}
public void destroyApp...
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

public void commandAction(Command c, Displayable dd)
{
if (c == exit)
{
t...
•
•
•
•
•
•
•
•
•
•
•
•
•
•

else if (c == start)
{
try
{
rec = RecordStore.openRecordStore(
"myRecordStore", true );
}
ca...
•
•

try
{

•
•
•
•
•
•
•
•
•
•
•
•
•

String s[] = {"Sita", "Rama", "Anand"};
for (int x = 0 ; x < 3; x++)
{
byte[] by = ...
•
•
•
•
•
•

try
{
fil = new Filter("Rama");//searching element
r = rec.enumerateRecords(fil, null, false);//Record Enumer...
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

try
{
rec.closeRecordStore();
}
catch (Exception error)
{
a =...
RecordFilter
•
•
•

//Filter is user defined class
class Filter implements RecordFilter
{

•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•...
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

public void filterClose()
{
try
{
if (bai != null)
{
bai.close();
}
if (dis != null)
...
Upcoming SlideShare
Loading in...5
×

Interface Record filter

576

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
576
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • http://improvejava.blogspot.in
  • Interface Record filter

    1. 1. Interface RecordFilter Interface RecordFilter
    2. 2. • javax.microedition.rms • public interface RecordFilter Interface RecordFilter
    3. 3. • This interface is used to searching in the recordstore. • Searching is also called as ‘Filtering’. • It specifies which records should be included in enumeration • Returns true if the candidate record is selected by the RecordFilter. For example: • RecordFilter f = new DateRecordFilter(); // class implements RecordFilter if (f.matches(recordStore.getRecord(theRecordID)) == true) DoSomethingUseful(theRecordID); Interface RecordFilter
    4. 4. Searching Records: • Here, if records matches a search criteria are copied into the RecordEnumeration and unmatched records are not included in the RecordEnumeration. Interface RecordFilter
    5. 5. • Record Searching(Filtering) is performed by using interface RecordFilter interface. • RecordFilter interface requires two parameters: (1) match() (2) filterclose() Interface RecordFilter
    6. 6. Match() • It is a member method of Filter class • It is used to read columns from the record and uses logical operators to verify whether they are matching the search key or not. • It contains the searching logic Interface RecordFilter
    7. 7. Logic for searching Step 1 • Create a filter class by implementing RecordFilter • Filter class should contain the logic for comparing records and search criteria Step 2: • Create an object of Filter class and create a record enumeration using its object: ie: MyFilter mf=new MyFilter(“searchKey”); Rec_enum=rec.enumerateRecords(filter,null,false); Interface RecordFilter
    8. 8. • The enumerateRecords() method calls methods defined in the Filter class. Step 3: • Execute loop record enumeration and copy each record to a variable. Step 4: • Display the data in dialog box Step 5: • If any errors occurs display them Step 6: • Close and remove RecordEnumeration and record store Interface RecordFilter
    9. 9. filterClose() • It is used to free the resources Interface RecordFilter
    10. 10. • • • • • • • • • • • • • //searching program and exception handling import javax.microedition.rms.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.io.*; public class SearchEx extends MIDlet implements CommandListener { private Display d; private Alert a; private Form f; private Command exit; private Command start; private RecordStore rec = null; • private RecordEnumeration r = null; • • • • • • • • • • • • • • private Filter fil = null; private boolean b; public SearchEx () { d = Display.getDisplay(this); b=false; exit = new Command("Exit", Command.SCREEN, 1); start = new Command("Start", Command.SCREEN, 1); f = new Form("Mixed RecordEnumeration", null); f.addCommand(exit); f.addCommand(start); f.setCommandListener(this); } Interface RecordFilter
    11. 11. • • • • • • • • • • • • • • public void startApp() { d.setCurrent(f); } public void pauseApp() { } public void destroyApp( boolean un ) throws MIDletStateChangeException { if(un==false) { throw new MIDletStateChangeException(); } } Interface RecordFilter
    12. 12. • • • • • • • • • • • • • • • • • • • • • • • • public void commandAction(Command c, Displayable dd) { if (c == exit) { try { if(b==false) { StringItem s=new StringItem(null,"please press exit once again"); f.append(s); destroyApp(false); } else { destroyApp(true); notifyDestroyed(); } }//end of try catch(MIDletStateChangeException e) { b=true; } } Interface RecordFilter
    13. 13. • • • • • • • • • • • • • • else if (c == start) { try { rec = RecordStore.openRecordStore( "myRecordStore", true ); } catch (Exception error) { a = new Alert("Error Creating", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a); } Interface RecordFilter
    14. 14. • • try { • • • • • • • • • • • • • String s[] = {"Sita", "Rama", "Anand"}; for (int x = 0 ; x < 3; x++) { byte[] by = s[x].getBytes(); rec.addRecord(by, 0,by.length); }//x,by are lost }//s is lost catch ( Exception error) { a = new Alert("Error Writing",error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a); } Interface RecordFilter
    15. 15. • • • • • • try { fil = new Filter("Rama");//searching element r = rec.enumerateRecords(fil, null, false);//Record Enumeration is constructed,search element //is stored in recordenumeration r if (r.numRecords() > 0)//It returns no.of records in the RecordEnumeration • • • • • • • • • • • • • • { String s = new String(r.nextRecord()); a = new Alert("Reading", s,null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a); } } catch (Exception error) { a = new Alert("Error Reading", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a); } Interface RecordFilter
    16. 16. • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • try { rec.closeRecordStore(); } catch (Exception error) { a = new Alert("Error Closing", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a); } if (RecordStore.listRecordStores() != null) { try { RecordStore.deleteRecordStore("myRecordStore"); r.destroy(); fil.filterClose(); } catch (Exception error) { a = new Alert("Error Removing", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a); } } } } } Interface RecordFilter
    17. 17. RecordFilter • • • //Filter is user defined class class Filter implements RecordFilter { • • • • • • • • • • • • • • • • • • private String key = null; private ByteArrayInputStream bai = null; private DataInputStream dis = null; //this constructor is called when enumerateRecords() method is called public Filter(String key) { this.key = key.toLowerCase(); } //matches() is called automatically after constructor public boolean matches(byte[] by) { String s = new String(by).toLowerCase();//converted into string form frm byte, converted into lowercase if (s!= null && s.indexOf(key) != -1)//Returns the index within this string of the first //occurrence of the specified substring. return true; else return false; } Interface RecordFilter
    18. 18. • • • • • • • • • • • • • • • • • • public void filterClose() { try { if (bai != null) { bai.close(); } if (dis != null) { dis.close(); } } catch ( Exception error) { } } } Interface RecordFilter
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×