001package org.hl7.fhir.r5.utils.structuremap; 002 003import org.hl7.fhir.r5.model.Base; 004import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; 005 006import java.util.ArrayList; 007import java.util.List; 008 009public class Variables { 010 private List<Variable> list = new ArrayList<Variable>(); 011 012 public void add(VariableMode mode, String name, Base object) { 013 Variable vv = null; 014 for (Variable v : list) 015 if ((v.getMode() == mode) && v.getName().equals(name)) 016 vv = v; 017 if (vv != null) 018 list.remove(vv); 019 list.add(new Variable(mode, name, object)); 020 } 021 022 public Variables copy() { 023 Variables result = new Variables(); 024 result.list.addAll(list); 025 return result; 026 } 027 028 public Base get(VariableMode mode, String name) { 029 for (Variable v : list) 030 if ((v.getMode() == mode) && v.getName().equals(name)) 031 return v.getObject(); 032 return null; 033 } 034 035 public String summary() { 036 CommaSeparatedStringBuilder s = new CommaSeparatedStringBuilder(); 037 CommaSeparatedStringBuilder t = new CommaSeparatedStringBuilder(); 038 CommaSeparatedStringBuilder sh = new CommaSeparatedStringBuilder(); 039 for (Variable v : list) 040 switch (v.getMode()) { 041 case INPUT: 042 s.append(v.summary()); 043 break; 044 case OUTPUT: 045 t.append(v.summary()); 046 break; 047 case SHARED: 048 sh.append(v.summary()); 049 break; 050 } 051 return "source variables [" + s.toString() + "], target variables [" + t.toString() + "], shared variables [" + sh.toString() + "]"; 052 } 053 054}