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

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

  •  15-07-2023
  •  | 
  •  

문제

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(...) ?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top