001//@formatter:off
002/*
003 * Worker
004 * Code-Beispiel zum Buch Patterns Kompakt, Verlag Springer Vieweg
005 * Copyright 2014 Karl Eilebrecht
006 * 
007 * Licensed under the Apache License, Version 2.0 (the "License"):
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019//@formatter:on
020package de.calamanari.pk.iterator;
021
022import java.util.HashSet;
023import java.util.Set;
024
025/**
026 * Worker represents the concrete AGGREGATE which can return an ITERATOR.
027 * 
028 * @author <a href="mailto:Karl.Eilebrecht(a/t)calamanari.de">Karl Eilebrecht</a>
029 */
030public class Worker extends AbstractWorker {
031
032    /**
033     * Subordinates of this worker
034     */
035    protected Set<Worker> subordinates = new HashSet<>();
036
037    /**
038     * Creates a worker of the given name
039     * 
040     * @param name person's name
041     */
042    public Worker(String name) {
043        super(name);
044    }
045
046    /**
047     * Adds a subordinate to this worker
048     * 
049     * @param subordinate person who works for this worker
050     */
051    public void addDirectSubordinate(Worker subordinate) {
052        this.subordinates.add(subordinate);
053    }
054
055    /**
056     * Removes the given subordinate
057     * 
058     * @param subordinate to be removed
059     * @return true if the given worker was a subordinate before, otherwise false
060     */
061    public boolean removeDirectSubordinate(AbstractWorker subordinate) {
062        return this.subordinates.remove(subordinate);
063    }
064
065    @Override
066    public WorkerIterator createSubordinatesIterator() {
067        return new WorkerIterator(this.subordinates);
068    }
069
070}