Context.java
01 /*
02  * Copyright 2008-2015 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *     http://www.apache.org/licenses/LICENSE-2.0
09  *
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 griffon.core;
17 
18 import javax.annotation.Nonnull;
19 import javax.annotation.Nullable;
20 import java.util.Set;
21 
22 /**
23  @author Andres Almiray
24  @since 2.2.0
25  */
26 public interface Context {
27     /**
28      * Searches for the key in this context and its hierarchy
29      *
30      @param key the key to search
31      @return true if the context (or its parent) contains the given key, false otherwise
32      @since 2.4.0
33      */
34     boolean containsKey(@Nonnull String key);
35 
36     /**
37      * Searches for the key in this context only
38      *
39      @param key the key to search
40      @return true if the context contains the given key, false otherwise
41      */
42     boolean hasKey(@Nonnull String key);
43 
44     @Nullable
45     Object remove(@Nonnull String key);
46 
47     void put(@Nonnull String key, @Nullable Object value);
48 
49     void putAt(@Nonnull String key, @Nullable Object value);
50 
51     @Nullable
52     Object get(@Nonnull String key);
53 
54     @Nullable
55     <T> T get(@Nonnull String key, @Nullable T defaultValue);
56 
57     @Nullable
58     Object getAt(@Nonnull String key);
59 
60     @Nullable
61     <T> T getAt(@Nonnull String key, @Nullable T defaultValue);
62 
63     void destroy();
64 
65     /**
66      * Returns a {@link Set} view of the keys contained in this context.
67      *
68      @return a set view of the keys contained in this map
69      @since 2.4.0
70      */
71     @Nonnull
72     Set<String> keySet();
73 }