View Javadoc

1   /*
2      Copyright 2010 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package mirrormap.commands;
17  
18  import java.io.Serializable;
19  import java.util.logging.Level;
20  import java.util.logging.Logger;
21  
22  import mirrormap.MirrorMap;
23  
24  /**
25   * Encapsulates a command to remove a key-value entry into a {@link MirrorMap}.
26   * 
27   * @author Ramon Servadei
28   */
29  public final class RemoveCommand extends AbstractCommand
30  {
31      private final static Logger LOGGER =
32          Logger.getLogger(RemoveCommand.class.getName());
33  
34      private static final long serialVersionUID = 1L;
35  
36      public RemoveCommand()
37      {
38          super();
39      }
40  
41      public RemoveCommand(String mirrorMapName, Serializable key)
42      {
43          super();
44          this.mirrorMapName = mirrorMapName;
45          this.key = key;
46      }
47  
48      public void execute()
49      {
50          final MirrorMap<Serializable, Serializable> mirrorMap =
51              MirrorMap.get(this.mirrorMapName);
52          if (mirrorMap != null)
53          {
54              mirrorMap.remove(this.key);
55          }
56          else
57          {
58              if (LOGGER.isLoggable(Level.FINE))
59              {
60                  LOGGER.fine("No map found for " + this.mirrorMapName);
61              }
62          }
63      }
64  
65  }