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 package org.apache.james.smtpserver.junkscore; 22 23 import java.util.HashMap; 24 import java.util.Iterator; 25 import java.util.Map; 26 27 /** 28 * 29 * The Object which holds all junkscore 30 */ 31 public class JunkScoreImpl implements JunkScore { 32 33 /** 34 * The map to store the scores 35 */ 36 private Map scoreMap = new HashMap(); 37 38 /** 39 * @see org.apache.james.smtpserver.junkscore.JunkScore#getCompleteStoredScores() 40 */ 41 public double getCompleteStoredScores() { 42 double count = 0; 43 Iterator s = scoreMap.keySet().iterator(); 44 45 while (s.hasNext()) { 46 count = count + getStoredScore(s.next().toString()); 47 } 48 return count; 49 } 50 51 52 /** 53 * @see org.apache.james.smtpserver.junkscore.JunkScore#getStoredScores() 54 */ 55 public Map getStoredScores() { 56 // Get sure we return a copy of the Map so it can not get wrong objects added 57 return new HashMap(scoreMap); 58 } 59 60 61 /** 62 * @see org.apache.james.smtpserver.junkscore.JunkScore#getStoredScore(java.lang.String) 63 */ 64 public double getStoredScore(String key) { 65 Double s = (Double) scoreMap.get(key); 66 67 if (s == null) { 68 return 0; 69 } 70 return s.doubleValue(); 71 } 72 73 /** 74 * @see org.apache.james.smtpserver.junkscore.JunkScore#setStoredScore(java.lang.String, double) 75 */ 76 public double setStoredScore(String key, double score) { 77 Double s = (Double) scoreMap.put(key, new Double(score)); 78 79 if (s== null) { 80 return 0; 81 } 82 return s.doubleValue(); 83 } 84 85 /** 86 * @see org.apache.james.smtpserver.junkscore.JunkScore#resetStoredScores() 87 */ 88 public double resetStoredScores() { 89 double oldSum = getCompleteStoredScores(); 90 scoreMap.clear(); 91 return oldSum; 92 } 93 94 }