1 /*******************************************************************************
2 * Copyright (c) 2012-2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.export;
14 import java.util.ArrayDeque;
15 import java.util.Collection;
16 import java.util.HashSet;
17 import java.util.Queue;
19 import org.eclipse.winery.common.ids.definitions.TOSCAComponentId;
22 * Holds the state of ids regarding the export <br />
24 * Required as we do not know at the entry point (usually a service template),
25 * which other components are linked <br />
27 * Users can call flagAsExportRequired more than once for the same id. If an id
28 * is already exported, it is not flagged as exported again
30 public class ExportedState {
32 private final Collection<TOSCAComponentId> exported = new HashSet<>();
33 private final Queue<TOSCAComponentId> exportRequired = new ArrayDeque<>();
37 * @return the first tosca component id to be exported, null if no more
38 * elements are in the queue
40 public TOSCAComponentId pop() {
41 return this.exportRequired.poll();
44 public void flagAsExported(TOSCAComponentId id) {
45 this.exportRequired.remove(id);
46 this.exported.add(id);
50 * Flags the given id as required for export, if not already exported
52 * @param id the id to flag
54 public void flagAsExportRequired(TOSCAComponentId id) {
55 if (!this.exported.contains(id)) {
56 this.exportRequired.add(id);
60 public void flagAsExportRequired(Collection<TOSCAComponentId> ids) {
61 for (TOSCAComponentId id : ids) {
62 if ((!this.exported.contains(id)) && (!this.exportRequired.contains(id))) {
63 this.exportRequired.add(id);