2 * Copyright 2005-2010 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.core;
18 import org.wamblee.test.EventTracker;
25 public class IntegerComponent extends AbstractComponent<Object> {
26 private EventTracker<String> tracker;
28 private double random;
31 * Creates a new IntegerComponent object.
33 public IntegerComponent() {
38 * Creates a new IntegerComponent object.
41 public IntegerComponent(String aName) {
46 * Creates a new IntegerComponent object.
49 public IntegerComponent(String aName, String aPrefix) {
50 super(aName, provided(aPrefix), new RequiredInterface[0]);
51 random = Math.random();
55 * Creates a new IntegerComponent object.
58 public IntegerComponent(EventTracker aTracker) {
63 private static final ProvidedInterface[] provided(String aPrefix) {
64 return new ProvidedInterface[] { new DefaultProvidedInterface(aPrefix +
65 "integer", Integer.class) };
68 public Integer getInteger() {
73 protected Object doStart(Scope aScope) {
74 addInterface(getProvidedInterfaces().get(1), getInteger(), aScope);
75 track("start." + getName());
81 protected void doStop(Object aRuntime) {
82 track("stop." + getName());
84 if (random != (Double) aRuntime) {
85 throw new IllegalArgumentException("Wrong runtime: expected " +
86 random + " but got " + aRuntime);
90 private void track(String aString) {
91 if (tracker == null) {
95 tracker.eventOccurred(aString);