View Javadoc

1   /*
2    * Copyright 2002-2009 the original author or authors.
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  
17  package net.sf.json.processors;
18  
19  import java.util.Set;
20  
21  /**
22   * Base class for finding a matching DefaultValueProcessor.<br>
23   * <ul>
24   * <li>DEFAULT - matches the target class with equals().</li>
25   * </ul>
26   *
27   * @author Andres Almiray <aalmiray@users.sourceforge.net>
28   */
29  public abstract class DefaultValueProcessorMatcher {
30     /** Matches the target with equals() */
31     public static final DefaultValueProcessorMatcher DEFAULT = new DefaultDefaultValueProcessorMatcher();
32  
33     /**
34      * Returns the matching class calculated with the target class and the
35      * provided set.
36      *
37      * @param target the target class to match
38      * @param set a set of possible matches
39      */
40     public abstract Object getMatch( Class target, Set set );
41  
42     private static final class DefaultDefaultValueProcessorMatcher extends
43           DefaultValueProcessorMatcher {
44        public Object getMatch( Class target, Set set ) {
45           if( target != null && set != null && set.contains( target ) ){
46              return target;
47           }
48           return null;
49        }
50     }
51  }