I'm trying to sort a Hazelcast IList using following code
Class PaymentChannelEntry
public class PaymentChannelEntry implements Serializable {
private static final long serialVersionUID = 5416475057971472127L;
private Long executionTimestamp; // timestamp of the time of the transaction in Zulu time zone (UTC)
private BigDecimal transactionAmount; // The amount of the transaction that contributes to the associated payment channel
public PaymentChannelEntry(Long executionTimestamp, BigDecimal transactionAmount) {
this.executionTimestamp = executionTimestamp;
this.transactionAmount = transactionAmount;
}
public Long getExecutionTimestamp() {
return executionTimestamp;
}
public void setExecutionTimestamp(Long executionTimestamp) {
this.executionTimestamp = executionTimestamp;
}
public BigDecimal getTransactionAmount() {
return transactionAmount;
}
public void setTransactionAmount(BigDecimal transactionAmount) {
this.transactionAmount = transactionAmount;
}
}
Then I select list of PaymentChannelEntry from Hazelcast IList
IList<PaymentChannelEntry> entryIList = channelStore.getChannelEntryList(channelData.getType())
Then when I use sort
method, it throws exception:
java.lang.UnsupportedOperationException
at com.hazelcast.util.UnmodifiableListIterator.set(UnmodifiableListIterator.java:30)
at java.util.List.sort(List.java:482)
Any solution will be appreciated.
Thanks.
答案 0 :(得分:0)
It seems like the list returned by channelStore.getChannelEntryList
is not modifiable hence the exception.
if you cannot modify what's being returned then first make a copy then sort:
// example
IList<PaymentChannelEntry> result = new ArrayList<>(channelStore.getChannelEntryList(channelData.getType()));
// now sort the list
The above is just an example and might not compile but ultimately you'll need to copy whatever is returned from channelStore.getChannelEntryList(channelData.getType())
into a mutable list and then sort it.