2013-03-15 3 views
2

나는 여기에 내 코드를 결과를 정렬 할 수 있습니다.Grails는) 정렬()

오류 :

Error 500: Executing action [recalcCompetitionTable] of controller [at.ligaportal.CompetitionController] caused exception: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.sort() is applicable for argument types: (java.util.ArrayList) values: [[1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16]] Possible solutions: sort(), sort(java.util.Comparator), sort(groovy.lang.Closure), wait(), size(), size() 
    Servlet: grails 
    URI: /ligaportal/grails/competition/recalcCompetitionTable.dispatch 
    Exception Message: No signature of method: java.util.ArrayList.sort() is applicable for argument types: (java.util.ArrayList) values: [[1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16]] Possible solutions: sort(), sort(java.util.Comparator), sort(groovy.lang.Closure), wait(), size(), size() 
    Caused by: No signature of method: java.util.ArrayList.sort() is applicable for argument types: (java.util.ArrayList) values: [[1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16]] Possible solutions: sort(), sort(java.util.Comparator), sort(groovy.lang.Closure), wait(), size(), size() 
    Class: ApiAuthenticationFilter 
    At Line: [77] 

내 문제가 무엇입니까?

withCriteria() 메소드를 통해 게임을 가져 왔습니다. 날짜순으로 정렬합니다.

모든 게임에 라운드가 있으며, 이제 라운드 순으로 정렬하고 싶습니다.

5 게임에는 1 개의 라운드와 게임이 있습니다.

Round 1 = 18.09.2012 - 25.09.2012 (5 Games) 
Round 2 = 26.09.2012 - 31.09.2012 (4 Games) and one Game plays later 
5.11.2012 
Round 3 = 1.10.2012 - 7.10.2013 

And my problem is, i sum up the round with a each and previous round. 

Roudn 1 = 3,3,3,1,1 Points 
Round 2 = 6,4,4,2,1 Points -> 1 Games later 
Round 3 = 9,7,7,4,3 Pounts 
Round 2 = 6,4,4,4,1 (after game) 
Round 4 = here i cant go back to round 4 -> the one game is lost! 

그리고 지금 나는이 내 문제

을 game.round.sorting를 통해 게임을 주문하고 싶다.

감사합니다. 코드에서 솔루션

def bySorting = new Comparator() { 
     int compare(a,b) { a.round.sorting <=> b.round.sorting } 
    } 
    games.sort(bySorting) 
+0

무엇이'games.round.sorting'입니까? –

+0

@ joe69, 당신은 두 번 정렬 : 첫 번째 쿼리에서 : 주문 날짜 ','오름차순 ', 그리고 그 후에. – eugene82

답변

0

games.round.sorting가 무엇 명확하지 않다.
Custom list sorting
Groovy OrderBy

을 또는 다른 예와 설명을 찾을 수 Groovy Comparator에 대한 구글 :

그러나 다음 링크에서 모습 그루비에서 목록을 정렬에 대한 자세한 내용을 배울 수있다.

1

기준이 이미 정렬되어 있기 때문에 gamessort()을 부를 필요가 없습니다.

대신 날짜순으로 정렬 : order 'date', 'asc' 여기에 원하는 속성을 추가 할 수 있습니다.

당신이 정말로 당신이이 Comparator 또는 Closuresort()에 전달해야하는 결과를 정렬해야하는 경우

def sortGames = games.asList().sort{it.round.sorting} 

당신은 좀 더 많은 정보를 제공해야합니다. sortingArrayList입니다 - games은 어떻게 정렬해야합니까?

+0

모든 게임에는 라운드가 있습니다. 2 모델 : – joe69

+0

질문을 편집하십시오. 도메인을 추가하고 원하는 정렬 기준을 설명하십시오. – aiolos

1

당신은 당신의 기준에 createAlias를 사용하여 초기 데이터베이스 쿼리의 일환으로 라운드를 기준으로 정렬 할 수 있어야한다 : 당신은 그루비에서 반환 된 목록의 정렬을 수행 할 필요가 없습니다

def games = Game.withCriteria() { 
       createAlias('round', 'rnd') 

       eq('season', currentSeason) 
       eq('competition', competition) 
       ge('rnd.roundNr', startRound.roundNr) 
       or { 
         le('rnd.roundNr', currentRound.roundNr) 
         gt('state', Game.STATE_NOT_STARTED) 
       } 
       order 'rnd.sorting', 'asc' 
     } 

이 방법을 . 당신이 그들의 round.sorting 값에 의해 게임의 기존 목록을 정렬 할 경우


그러나, 당신은 거의 올바른 구문을했다.당신이 실제로 필요한 것은 :

def sortGames = games.sort { it.round.sorting } 

Groovy는 정렬 방법이 시도가 모든 게임에 대한 모든 정렬 키의 목록을 통과 한 반면, 정렬 키를 반환하는 폐쇄을 기대하고있다.