View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  
21  
22  package org.apache.james.smtpserver.junkscore;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * Class to compose the two Junkscore Objects 
29   */
30  public class ComposedJunkScore implements JunkScore {
31  
32      JunkScore score1;
33      
34      JunkScore score2;
35      
36      /**
37       * Construct Class
38       * 
39       * @param score1 The JunkScore for the whole session
40       * @param score2 The JunkScore for the nail
41       * @throws IllegalArgumentException get thrown if one of the given JunkScore Objects is null
42       */
43      public ComposedJunkScore (JunkScore score1, JunkScore score2) throws IllegalArgumentException {
44          if (score1 == null || score2 == null ) throw new IllegalArgumentException("JunkScore can not be null");
45          this.score1 = score1;
46          this.score2 = score2;
47      }
48      
49      /** 
50       * @see org.apache.james.smtpserver.junkscore.JunkScore#getCompleteStoredScores()
51       */
52      public double getCompleteStoredScores() {
53          return (score1.getCompleteStoredScores() + score2.getCompleteStoredScores());
54      }
55  
56      
57      /**
58       * @see org.apache.james.smtpserver.junkscore.JunkScore#getStoredScore(java.lang.String)
59       */
60      public double getStoredScore(String key) {
61          return (score1.getStoredScore(key) + score2.getStoredScore(key));
62      }
63  
64      /**
65       * @see org.apache.james.smtpserver.junkscore.JunkScore#getStoredScores()
66       */
67      public Map getStoredScores() {
68          // copy the Map
69          Map m = new HashMap(score1.getStoredScores());
70          m.putAll(score2.getStoredScores());
71          return m;
72      }
73  
74      /**
75       * @see org.apache.james.smtpserver.junkscore.JunkScore#resetStoredScores()
76       */
77      public double resetStoredScores() {
78          return (score1.resetStoredScores() + score2.resetStoredScores());
79      }
80  
81      /**
82       * Throws an UnsuportedOperationException cause its not supported here
83       * 
84       * @throws UnsupportedOperationException
85       */
86      public double setStoredScore(String key, double score) {
87          throw new UnsupportedOperationException("Unimplemented Method");
88      }
89      
90  }