View Javadoc
1   package org.codehaus.mojo.webstart.dependency;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.LinkedHashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  /**
29   * Created on 1/4/14.
30   *
31   * @author Tony Chemit <chemit@codelutin.com>
32   * @since 1.0-beta-5
33   */
34  public class JnlpDependencyResults
35  {
36  
37      /**
38       * Registred results.
39       */
40      private final Map<JnlpDependencyRequest, JnlpDependencyResult> results;
41  
42      public JnlpDependencyResults()
43      {
44          results = new LinkedHashMap<JnlpDependencyRequest, JnlpDependencyResult>();
45      }
46  
47      public void registerResult( JnlpDependencyRequest request, JnlpDependencyResult result )
48      {
49          results.put( request, result );
50      }
51  
52      public Map<JnlpDependencyRequest, JnlpDependencyResult> getResults()
53      {
54          return Collections.unmodifiableMap( results );
55      }
56  
57      public boolean isError()
58      {
59          boolean result = false;
60  
61          for ( JnlpDependencyResult dependencyResult : results.values() )
62          {
63              if ( dependencyResult.isError() )
64              {
65                  result = true;
66                  break;
67              }
68          }
69          return result;
70      }
71  
72      public JnlpDependencyResult[] getResultsWithError()
73      {
74          List<JnlpDependencyResult> resultWithErrors = new ArrayList<JnlpDependencyResult>();
75          for ( JnlpDependencyResult dependencyResult : results.values() )
76          {
77              if ( dependencyResult.isError() )
78              {
79                  resultWithErrors.add( dependencyResult );
80              }
81          }
82          return resultWithErrors.toArray( new JnlpDependencyResult[resultWithErrors.size()] );
83      }
84  
85      public int getNbRequestsProcessed()
86      {
87          int result = 0;
88          for ( JnlpDependencyRequest request : results.keySet() )
89          {
90              if ( !request.isUptodate() )
91              {
92                  result++;
93              }
94          }
95          return result;
96      }
97  
98      public int getNbRequestsUptodate()
99      {
100         int result = 0;
101         for ( JnlpDependencyRequest request : results.keySet() )
102         {
103             if ( request.isUptodate() )
104             {
105                 result++;
106             }
107         }
108         return result;
109     }
110 }