View Javadoc

1   /*
2   *
3   * ====================================================================
4   *
5   * Copyright 2004 The Apache Software Foundation 
6   *
7   * Licensed under the Apache License, Version 2.0 (the "License");
8   * you may not use this file except in compliance with the License.
9   * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20  package org.apache.commons.contract.context;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.commons.contract.Context;
26  import org.apache.commons.contract.Information;
27  import org.apache.commons.contract.Store;
28  import org.apache.commons.contract.store.Environment;
29  
30  public class VMContext implements Context {
31      private Environment environment = new Environment();
32      private List informations = new ArrayList();
33      private int informationNumber = 0;
34      
35      public Store getStore(String id) {
36          if ( id.equals(Environment.ID) ) {
37              return environment;
38          }
39          return null;
40      }
41  
42      public void addInformation(Information info) {
43          if ( !informations.contains(info) ) {
44              informationNumber++;
45              info.setNumber(informationNumber);
46              informations.add(info);
47          }
48      }
49  
50      public List getInformations() {
51          return informations;
52      }
53  }