package org.netmelody.cii.witness.jenkins.jsondomain;

import java.util.List;

public final class JobDetail extends Job {
    public String displayName;
    public String description;
    public boolean buildable;
    public boolean inQueue;
    public boolean keepDependencies;
    public boolean concurrentBuild;
    public List<Build> builds;
    public List<Action> actions;
    public Build firstBuild;
    public Build lastBuild;
    public Build lastFailedBuild;
    public Build lastStableBuild;
    public Build lastSuccessfulBuild;
    public Build lastUnstableBuild;
    public Build lastUnsuccessfulBuild;
    public int nextBuildNumber;
    public List<Project> downstreamProjects;
    public List<Project> upstreamProjects;
    public List<HealthReport> healthReport;
    //scm
    //property
    //queueItem
    
    public String lastBadBuildUrl() {
        if (null == lastUnstableBuild) {
            if (null == lastFailedBuild) {
                return lastFailedBuild.url;
            }
            return url;
        }
        
        if (null == lastFailedBuild) {
            return lastUnstableBuild.url;
        }
        
        return (lastUnstableBuild.number >= lastFailedBuild.number) ? lastUnstableBuild.url : lastFailedBuild.url;
    }
}

@@ -59,22 +59,419 @@
 ort 
-java.util.List
+static com.google.common.base.Predicates.notNull;%0Aimport static com.google.common.collect.Collections2.filter;%0Aimport static com.google.common.collect.Collections2.transform;%0Aimport static com.google.common.collect.Lists.newArrayList;%0A%0Aimport java.util.Collection;%0Aimport java.util.List;%0A%0Aimport com.google.common.base.Function;%0Aimport com.google.common.base.Predicate;%0Aimport com.google.common.collect.Ordering
 ;%0A%0Ap
@@ -1268,64 +1268,96 @@
     
-if (null == lastUnstableBuild) %7B%0A            if (null ==
+final List%3CBuild%3E lastBadBuilds = newArrayList(lastUnstableBuild, lastUnsuccessfulBuild,
  las
@@ -1369,31 +1369,26 @@
 edBuild)
- %7B%0A    
+;%0A
         
     retu
@@ -1383,38 +1383,137 @@
     
-    return lastFailedBuild.url
+final Collection%3CString%3E candidates = filter(filter(transform(filter(lastBadBuilds, notNull()), toUrl()), notNull()), notEmpty())
 ;%0A  
@@ -1514,29 +1514,60 @@
 ));%0A        
+%0A
     
-%7D
+    if (candidates.isEmpty()) %7B
 %0A           
@@ -1610,213 +1610,806 @@
     
-if (null == lastFailedBuild) %7B
+return lexographicallyLastFrom(candidates);
 %0A    
+%7D%0A
     
+%0A
     
-return lastUnstableBuild.url;%0A        %7D%0A        %0A        return (lastUnstableBuild.number %3E= lastFailedBuild.number) ? lastUnstableBuild.url : lastFailedBuild.url
+private String lexographicallyLastFrom(final Collection%3CString%3E candidates) %7B%0A        return new Ordering%3CString%3E() %7B%0A            @Override public int compare(String left, String right) %7B%0A                return left.compareTo(right);%0A            %7D%0A        %7D.max(candidates);%0A    %7D%0A    %0A    private Predicate%3CString%3E notEmpty() %7B%0A        return new Predicate%3CString%3E() %7B%0A            @Override%0A            public boolean apply(String input) %7B%0A                return input.length() %3E 0;%0A            %7D%0A        %7D;%0A    %7D%0A    %0A    private Function%3CBuild, String%3E toUrl() %7B%0A        return new Function%3CBuild, String%3E() %7B%0A            @Override%0A            public String apply(Build input) %7B%0A                return input.url;%0A            %7D%0A        %7D
 ;%0A  

fix analysis of comments on last bad build