SlideShare a Scribd company logo
Interface RecordComparator

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

Interface RecordComparator
• It is used to comparing two records. Generally it is used to
find the sorting order.
• The return value must indicate the ordering of the two
records.
• The compare method is called by RecordEnumeration to
sort and return records in an application specified order.
For example:
• RecordComparator c = new AddressRecordComparator(); if
(c.compare(recordStore.getRecord(rec1),
recordStore.getRecord(rec2)) ==
RecordComparator.PRECEDES) return rec1;

Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•

import javax.microedition.rms.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class MSortRec 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 Comparator2 com = null;
Interface RecordComparator
•
•
•
•
•
•
•
•
•
•

public MSortRec ()
{
d = Display.getDisplay(this);
exit = new Command("Exit", Command.SCREEN, 1);
start = new Command("Start", Command.SCREEN, 1);
f = new Form("Mixed RecordEnumeration");
f.addCommand(exit);
f.addCommand(start);
f.setCommandListener(this);
}
Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

public void startApp()
{
d.setCurrent(f);
}
public void pauseApp()
{
}
public void destroyApp( boolean unconditional )
{
}
public void commandAction(Command c, Displayable dd)
{
if (c == exit)
{
destroyApp(true);
notifyDestroyed();
}

Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•

else if (c == start)
{
try
{
rec = RecordStore.openRecordStore("myRecordStore", true );
}
catch (Exception er)
{
a = new Alert("Error Creating",
er.toString(), null, AlertType.WARNING);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
}
Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•

try
{
//byte[] outputRecord;
byte[] by;
String s[] = {"Sita", "Rama", "Anand"};
int i[] = {15, 10, 5};
//ByteArrayOutputStream outputStream =
ByteArrayOutputStream baos =
new ByteArrayOutputStream();
//DataOutputStream outputDataStream =
DataOutputStream ods =
new DataOutputStream(baos);

Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

for (int x = 0; x < 3; x++)
{
ods.writeUTF(s[x]);
ods.writeInt(i[x]);
ods.flush();
by = baos.toByteArray();
rec.addRecord(by, 0,by.length);
baos.reset();
}
baos.close();
ods.close();
}
catch ( Exception error)
{
a = new Alert("Error Writing",
error.toString(), null, AlertType.WARNING);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
}

Interface RecordComparator
•
•

try
{

•
•
•
•
•

String[] s = new String[3];
int z = 0;
byte[] by = new byte[300];
ByteArrayInputStream bais =
new ByteArrayInputStream(by);

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

DataInputStream dis =
new DataInputStream(bais);
StringBuffer sb = new StringBuffer();
com = new Comparator2();
r= rec.enumerateRecords(null, com, false);//now RecordEnumeration is build
while (r.hasNextElement())//if there is another record is there in RecordEnumeration, returns true,
//false otherwise
{
rec.getRecord( r.nextRecordId(),by, 0);//it returns the record ID of next record
//present in the RecordEnumeration and copies into by array
sb.append(dis.readUTF());
sb.append(dis.readInt());
sb.append("n");
dis.reset();
}

Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•

a = new Alert("Reading", sb.toString(), null,
AlertType.WARNING);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
dis.close();
bais.close();
}
catch (Exception error)
{
a = new Alert("Error Reading",
error.toString(), null, AlertType.WARNING);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
}
Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•

try
{
rec.closeRecordStore();
}
catch (Exception er)
{
a = new Alert("Error Closing",
er.toString(), null, AlertType.WARNING);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
}
Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

if (RecordStore.listRecordStores() != null)
{
try
{
rec.deleteRecordStore("myRecordStore");
com.compareClose();
r.destroy();
}
catch (Exception er)
{
a = new Alert("Error Removing",
er.toString(), null, AlertType.WARNING);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
}
}
}
}
}

Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

class Comparator2 implements RecordComparator
{
private byte[] comparatorInputData = new byte[300];
private ByteArrayInputStream comparatorInputStream = null;
private DataInputStream comparatorInputDataType = null;
public int compare(byte[] record1, byte[] record2)
{
int record1int, record2int;
try
{
int maxlen = Math.max(record1.length, record2.length);
if (maxlen > comparatorInputData.length)
{
comparatorInputData = new byte[maxlen];
}

Interface RecordComparator
• comparatorInputStream = new
ByteArrayInputStream(record1);
• comparatorInputDataType =
• new DataInputStream(comparatorInputStream);
• comparatorInputDataType.readUTF();
• record1int = comparatorInputDataType.readInt();
• comparatorInputStream = new
ByteArrayInputStream(record2);
• comparatorInputDataType =
• new DataInputStream(comparatorInputStream);
• comparatorInputDataType.readUTF();
• record2int = comparatorInputDataType.readInt();
Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

if (record1int == record2int)
{
return RecordComparator.EQUIVALENT;
}
else if (record1int < record2int)
{
return RecordComparator.PRECEDES;
}
else
{
return RecordComparator.FOLLOWS;
}
}
catch (Exception error)
{
return RecordComparator.EQUIVALENT;
}
}

Interface RecordComparator
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

public void compareClose()
{
try
{
if (comparatorInputStream!= null)
{
comparatorInputStream.close();
}
if (comparatorInputDataType!= null)
{
comparatorInputDataType.close();
}
}
catch (Exception error)
{
}
}
}

Interface RecordComparator
• For java tutorials visit:
http://improvejava.blogspot.in

Interface RecordComparator

More Related Content

KEY
サイ本 文
PDF
Faster Python, FOSDEM
PPTX
JavaScript Event Loop
PDF
Java8 stream
PPTX
Angular2 rxjs
PPTX
Anti patterns
PDF
Active records before_type_cast
PDF
ECMA Script
サイ本 文
Faster Python, FOSDEM
JavaScript Event Loop
Java8 stream
Angular2 rxjs
Anti patterns
Active records before_type_cast
ECMA Script

What's hot (20)

PDF
Parboiled explained
PDF
Data recovery using pg_filedump
PPTX
Using Cerberus and PySpark to validate semi-structured datasets
PDF
RxJS Evolved
PDF
Rcpp11 genentech
PDF
Apache PIG - User Defined Functions
PDF
Extend R with Rcpp!!!
PDF
JavaScript Event Loop
PPTX
Luis Atencio on RxJS
PDF
PyCon KR 2019 sprint - RustPython by example
PDF
Tracing and awk in ns2
PDF
NS2: AWK and GNUplot - PArt III
PDF
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
PDF
R/C++ talk at earl 2014
PDF
pg_filedump
PDF
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
PDF
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
PDF
Transducers in JavaScript
PDF
Real world scala
PDF
Nosql hands on handout 04
Parboiled explained
Data recovery using pg_filedump
Using Cerberus and PySpark to validate semi-structured datasets
RxJS Evolved
Rcpp11 genentech
Apache PIG - User Defined Functions
Extend R with Rcpp!!!
JavaScript Event Loop
Luis Atencio on RxJS
PyCon KR 2019 sprint - RustPython by example
Tracing and awk in ns2
NS2: AWK and GNUplot - PArt III
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
R/C++ talk at earl 2014
pg_filedump
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Transducers in JavaScript
Real world scala
Nosql hands on handout 04
Ad

Viewers also liked (9)

PPTX
Byte arrayoutputstream
PPTX
Interface record enumeration
PPTX
M rec enum
PPTX
Interface Record filter
PPT
J2 me 1
PPT
Session4 J2ME Mobile Information Device Profile(MIDP) Events
PPTX
Wr ex2
PPTX
Record store
PPT
Session6 J2ME High Level User Interface(HLUI) part1
Byte arrayoutputstream
Interface record enumeration
M rec enum
Interface Record filter
J2 me 1
Session4 J2ME Mobile Information Device Profile(MIDP) Events
Wr ex2
Record store
Session6 J2ME High Level User Interface(HLUI) part1
Ad

Similar to Interface record comparator (20)

PPT
Session10 J2ME Record Management System
PPT
Scmad Chapter08
PDF
J2ME RMS
PPTX
Exploring Streams and Lambdas in Java8
PPT
Recordmanagment
PPTX
Comparable/ Comparator
PPT
MIDP: Persistant Storage
PDF
Java 8 - Nuts and Bold - SFEIR Benelux
PPTX
Unit 3 lecture-2
PPTX
Java8lambda
PPTX
Chapter one data structure and algorithm s
PPT
Session9 J2ME Record Management System
PDF
#include iostream #includeData.h #includePerson.h#in.pdf
PPTX
Collections in-csharp
PDF
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
PPTX
Java ME - 06 - Record Stores, Distribution and Localization
PDF
Exercise2 java
PPT
04a-compare in java operator collection.ppt
PPTX
Unit 3 Compiler Design Regulation 2021.pptx
PPTX
Record management system_parvathy
Session10 J2ME Record Management System
Scmad Chapter08
J2ME RMS
Exploring Streams and Lambdas in Java8
Recordmanagment
Comparable/ Comparator
MIDP: Persistant Storage
Java 8 - Nuts and Bold - SFEIR Benelux
Unit 3 lecture-2
Java8lambda
Chapter one data structure and algorithm s
Session9 J2ME Record Management System
#include iostream #includeData.h #includePerson.h#in.pdf
Collections in-csharp
Core Java Programming Language (JSE) : Chapter IX - Collections and Generic F...
Java ME - 06 - Record Stores, Distribution and Localization
Exercise2 java
04a-compare in java operator collection.ppt
Unit 3 Compiler Design Regulation 2021.pptx
Record management system_parvathy

More from myrajendra (20)

PPT
Fundamentals
PPT
Data type
PPTX
Hibernate example1
PPTX
Jdbc workflow
PPTX
2 jdbc drivers
PPTX
3 jdbc api
PPTX
4 jdbc step1
PPTX
Dao example
PPTX
Sessionex1
PPTX
Internal
PPTX
3. elements
PPTX
2. attributes
PPTX
1 introduction to html
PPTX
Headings
PPTX
Forms
PPT
PPTX
Views
PPTX
Views
PPTX
Views
PPT
Starting jdbc
Fundamentals
Data type
Hibernate example1
Jdbc workflow
2 jdbc drivers
3 jdbc api
4 jdbc step1
Dao example
Sessionex1
Internal
3. elements
2. attributes
1 introduction to html
Headings
Forms
Views
Views
Views
Starting jdbc

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Types and Its function , kingdom of life
PDF
Classroom Observation Tools for Teachers
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Pharma ospi slides which help in ospi learning
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Types and Its function , kingdom of life
Classroom Observation Tools for Teachers
Final Presentation General Medicine 03-08-2024.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
TR - Agricultural Crops Production NC III.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program
Pharma ospi slides which help in ospi learning
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
Abdominal Access Techniques with Prof. Dr. R K Mishra
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Renaissance Architecture: A Journey from Faith to Humanism
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Pharmacology of Heart Failure /Pharmacotherapy of CHF
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Interface record comparator

Editor's Notes

  • #18: http://improvejava.blogspot.in