1 /* 2 * Copyright 2012 the original author or authors. 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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 org.openehealth.ipf.commons.ihe.core.chain; 17 18 import java.util.Collections; 19 import java.util.HashSet; 20 import java.util.Set; 21 22 import static java.util.Objects.requireNonNull; 23 24 /** 25 * Base for an element of a chain. 26 * @author Dmytro Rud 27 */ 28 public abstract class ChainableImpl implements Chainable { 29 private String id = getClass().getName(); 30 private Set<String> before = new HashSet<>(); 31 private Set<String> after = new HashSet<>(); 32 33 34 /** 35 * Sets the ID of this chain element. 36 * @param id 37 * ID of this chain element. 38 */ 39 public void setId(String id) { 40 this.id = requireNonNull(id); 41 } 42 43 /** 44 * @return ID of this chain element. 45 */ 46 @Override 47 public String getId() { 48 return id; 49 } 50 51 /** 52 * Configures this chain element to be deployed before the given ones. 53 * @param ids 54 * IDs of chain elements this chain element should be deployed before. 55 */ 56 public void addBefore(String... ids) { 57 Collections.addAll(before, ids); 58 } 59 60 /** 61 * Configures this chain element to be deployed after the given ones. 62 * @param ids 63 * IDs of chain elements this chain element should be deployed after. 64 */ 65 public void addAfter(String... ids) { 66 Collections.addAll(after, ids); 67 } 68 69 /** 70 * @return IDs of chain elements this chain element will be/has been deployed before. 71 */ 72 @Override 73 public Set<String> getBefore() { 74 return before; 75 } 76 77 /** 78 * @return IDs of chain elements this chain element will be/has been deployed after. 79 */ 80 @Override 81 public Set<String> getAfter() { 82 return after; 83 } 84 85 }