gpt4 book ai didi

java - 对 Arraylist 进行多次排序

转载 作者:行者123 更新时间:2023-12-01 17:00:43 24 4
gpt4 key购买 nike

我有一个类“SendBundleQuery”,其中包含一些对象,如类别、类型、名称。类别可以有两种类型 base 和 Addons 。类型可以是数据、语音、短信三种类型。我有一个此类对象的数组列表,现在我需要进行排序,就像所有基本优惠都将首先出现,然后是所有附加组件。对于所有基本优惠,订单将为数据、语音、短信。

目前我已根据类别对其进行排序

public int compareTo(SendBundleQuery other) {
int result= category.compareTo(other.category);
if(result==0){
result =other.bundleType.compareTo(bundleType);
}
return result;
}

但现在我需要达到上述条件。有什么好的方法可以做到这一点。

下面是我想要实现的示例。

我需要为客户撰写短信,如下所示:

尊敬的客户,

You have <0 MB> left within your <Eenmalig 100 MB Maandbundel>. ---Base offer

In addition, you have <22 Minuten> left within your <100 Minuten Bundel>. --- Base offer

In addition, you have <0 MB> left within your <Web 200 MB Maandbundel>. --Addon

In addition, you have <35 MB> left within your <Alles-in-1 op Reis Data Dagbundel>. --Addon

In addition, you have <374 MB> left within your <Blox 400 MB Maandbundel>. --Addon

In addition, you have <20 Minuten> left within your <Alles-in-1 Op Reis 20 Minuten gesprekken ontvangen>. --Addon

In addition, you have <20 Minuten> left within your <Alles-in-1 Op Reis 20 Minuten Bellen>. --Addon

In addition, you have <20 SMS> left within your <Alles-in-1 Op Reis 20 SMS Dagbundel>. --Addon

这些制作人员信息将更新至<12-12-2014>的<14.53>。

在“我的沃达丰”中维护您的 BloX 和其他设备。

下面是当前结果,但顺序是数据、短信,然后是语音,但我需要数据、语音,然后短信:

        Dear Customer,

You have 0.0 MB Data left within your Web 500 MB Maandbundel.

In addition, you have 106 minutes left within your 150 Minuten Bundel.

In addition, you have 35.0 MB Data left within your Alles-in-1 op Reis Data Dagbundel.

In addition, you have 20 messages left within your Alles-in-1 Op Reis 20 SMS Dagbundel.

In addition, you have 20 minutes left within your Alles-in-1 Op Reis 20 Minuten gesprekken ontvangen.

In addition, you have 20 minutes left within your Alles-in-1 Op Reis 20 Minuten Bellen.

These credits are updated until 15-12-2014 at 03:57.

Maintain your BloX and extras in My Vodafone.

最佳答案

为了按多个条件排序,请按以下方式编写compareTo:

public int compareTo(SendBundleQuery other) {
int result = category1.compareTo(other.category1);
if( result == 0 ) {
result = category2.compareTo(other.category2);
}
return result;
}

关于java - 对 Arraylist 进行多次排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27800640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com