如何在J2me中搜索和排序(升序或降序)

发布于 2024-12-16 13:54:38 字数 201 浏览 2 评论 0原文

我想知道如何在 J2ME 中进行搜索。我一直在互联网上搜索,向我展示了很多结果,我在 Java2s.com 中看到我得到了一个使用 RecordFilter 和匹配方法在记录存储中搜索的结果。

但我的问题是,当我需要向其中传递 2 个或更多参数时。结果如何与这些参数匹配?

如何像冒泡排序一样进行降序或升序排序?

I am wondering about how to search in J2ME. I have been searching in the internet, so many result show to me, and I see in Java2s.com I got a result use RecordFilter and matches method for search in record store.

But my problem is, when I need to pass 2 or more parameters into it. How can result matches with these parameter?

And how to sort descending or ascending like bubble sort?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木槿暧夏七纪年 2024-12-23 13:54:38

将搜索连接到单个字符串变量中。例如,用 ; 将它们分开。在 matches 方法的代码中分解字符串以获取每个搜索条件。
要使过滤器生效,请创建 SearchFilter 的实例并使用连接字符串作为其参数调用 matches 方法。
对于sort,实现RecordComparator接口;实现 compare 方法来构建排序标准。在 google 上搜索 j2me+recordcomparator 以查看有关如何进行排序的示例。


编辑:

matches方法的代码中分解从byte[]参数获得的String参数。对待每个分解的字符串来制定标准。
据我了解,您在编写时希望传递两个字符串作为搜索条件:

SearchFilter search = new SearchFilter(txtSearch.getString(), strType);

所以在构造函数中应该有两个参数!

当你想要进行匹配时,调用

if searchFilter.matches((search1+";"+sType).getBytes())

然后将 candidate 参数分解为两个 String您编写 matches 方法。

Concatenate your searches into a single String variable. Separate each of them with ; for example. In the code of the matches method explode the String to get each search criteria.
To make the filter in effect create an instance of SearchFilter and call the matches method with the concantenated String as its param.
For the sort implement the RecordComparator interface ; implement the compare method to build your sort criteria. Make a google search about j2me+recordcomparator to see examples about how to make sorts.


EDIT :

In the code of the matches method explode the String param obtained from the byte[] param. Treat each String exploded to make the criteria.
As I understand you want to pass two string as a search criteria when you wrote :

SearchFilter search = new SearchFilter(txtSearch.getString(), strType);

So in the constructor there should be two params !!!

When you want to make the matching then call

if searchFilter.matches((search1+";"+sType).getBytes())

Then explode the candidate param into two String when you code the matches method.

海螺姑娘 2024-12-23 13:54:38

当我将数据保存在 RMS 中时,我将其保存为 String[],就像我想保存每个员工的姓名、年龄、薪水、EmpID 一样,我将其保存创建一个数组并将其转换为字节并将其保存在 RMS 中。当我检索它时,我会执行相反的过程。现在,如果我想获得姓名以 A 开头且薪水 10000 的员工,我使用以下过滤器

class UtilFilter implements RecordFilter{    
    public UtilFilter(String str_searchText,String str_searchText1)
    {
            this.str_searchText = str_searchText.toLowerCase();
            this.str_searchText1 = str_searchText1.toLowerCase();
    }
    public boolean matches(byte[] bt_byteData)
    {
      String str_str = "";
      String str_str1 = "";
      //here goes code how u get back ur String[] from RMS say u get it in Data
      str_str = Data[0].trim();
      str_str1 = gd_cd.Data[2].trim();

      if(str_searchText != null && str_searchText1 != null && str_str.equals(str_searchText) && str_str1.equals(str_searchText1 ))
        {
              return true;
        }
        else
        {
              return false;
        }
    }
}

这样我可以过滤任何参数。希望有帮助! :)

When I save my Data in RMS I save it as a String[] like I want to save Name, Age,Salary,EmpID for each employee I save it create an array and convert it to bytes and save it in RMS. When i retrieve it i do the reverse process. Now if i want to get employee with names starting with A and with salary 10000 i use the following filter

class UtilFilter implements RecordFilter{    
    public UtilFilter(String str_searchText,String str_searchText1)
    {
            this.str_searchText = str_searchText.toLowerCase();
            this.str_searchText1 = str_searchText1.toLowerCase();
    }
    public boolean matches(byte[] bt_byteData)
    {
      String str_str = "";
      String str_str1 = "";
      //here goes code how u get back ur String[] from RMS say u get it in Data
      str_str = Data[0].trim();
      str_str1 = gd_cd.Data[2].trim();

      if(str_searchText != null && str_searchText1 != null && str_str.equals(str_searchText) && str_str1.equals(str_searchText1 ))
        {
              return true;
        }
        else
        {
              return false;
        }
    }
}

This way i can filter any no of parameters.Hope tht helps! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文