Can I sort the items in repeated field collection of Google Protocol Buffer Builder?

StackOverflow https://stackoverflow.com/questions/23475458

  •  15-07-2023
  •  | 
  •  

Domanda

I mean,

Collections.sort(myBuilder.getMyRepeatedItem(), myComparator);

Can I assume items will then be in the sorted order after calling build() later, or it is better to sort in a separate array and use clearMyRepeatedItem() and then addAllMyRepeatedItem(...) ?

È stato utile?

Soluzione

Seems that not even possible:

java.lang.UnsupportedOperationException
    at java.util.Collections$UnmodifiableList.sort(Collections.java:1331)
    at java.util.Collections.sort(Collections.java:175)

Sorry, I initially assumed may work but may not be recommended as something undocumented. However while you can add elements to the Builder, the list that the Builder returns is not a modifyable list.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top