package uk.ac.mdx.cs.ie.acontextlib;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * A Class designed to deal with multiple Context Receivers used by the Context Reasoner/Applications.
 *
 * @author Dean Kramer <d.kramer@mdx.ac.uk>
 */
public class ContextReceivers implements IContextReceiver {

    private Map<String, IContextReceiver> mReceiverMap = new HashMap<>();
    private Collection<IContextReceiver> mReceivers;

    public void add(String appkey, IContextReceiver receiver) {

        mReceiverMap.put(appkey, receiver);
        mReceivers = mReceiverMap.values();
    }


    public IContextReceiver remove(String appkey) {

        IContextReceiver result = mReceiverMap.remove(appkey);
        mReceivers = mReceiverMap.values();
        return result;
    }

    public boolean contains(IContextReceiver receiver) {
        return mReceiverMap.containsValue(receiver);
    }

    public boolean contains(String appkey) {
        return mReceiverMap.containsKey(appkey);
    }

    @Override
    public void newContextValue(String name, long value) {

        for (IContextReceiver receiver : mReceivers) {
            receiver.newContextValue(name, value);
        }
    }

    @Override
    public void newContextValue(String name, double value) {

        for (IContextReceiver receiver : mReceivers) {
            receiver.newContextValue(name, value);
        }
    }

    @Override
    public void newContextValue(String name, boolean value) {

        for (IContextReceiver receiver : mReceivers) {
            receiver.newContextValue(name, value);
        }
    }

    @Override
    public void newContextValue(String name, String value) {

        for (IContextReceiver receiver : mReceivers) {
            receiver.newContextValue(name, value);
        }
    }

    @Override
    public void newContextValue(String name, Object value) {

        for (IContextReceiver receiver : mReceivers) {
            receiver.newContextValue(name, value);
        }
    }

    @Override
    public void newContextValues(Map<String, String> values) {

        for (IContextReceiver receiver : mReceivers) {
            receiver.newContextValues(values);
        }
    }
}

@@ -1,8 +1,612 @@
+/*%0A * Copyright 2016 Middlesex University%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 

Add forgotten license