
org.databene.edifatto.model.Composite Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edifatto Show documentation
Show all versions of edifatto Show documentation
'Edifatto' is an open source software library for parsing,
generating and verifying EDIFACT and X12 documents written by Volker Bergmann.
/*
* Copyright (C) 2013-2014 Volker Bergmann ([email protected]).
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.databene.edifatto.model;
import java.util.ArrayList;
import java.util.List;
import org.databene.edifatto.definition.CompositeDefinition;
/**
* Combines {@link Component}s to a group.
* Created: 28.06.2014 15:57:59
* @since 2.0.0
* @author Volker Bergmann
*/
public class Composite extends AbstractSegmentItem implements EdiParent {
private static final long serialVersionUID = 1L;
private CompositeDefinition definition;
private List children;
public Composite(CompositeDefinition definition, Segment segment) {
super(segment);
setParent(segment);
this.definition = definition;
this.children = new ArrayList();
}
@Override
public CompositeDefinition getDefinition() {
return definition;
}
public void setDefinition(CompositeDefinition definition) {
this.definition = definition;
}
@Override
public int getChildCount() {
return children.size();
}
@Override
public Component getChild(int index) {
return children.get(index);
}
public List getChildren() {
return children;
}
@Override
public void addChild(Component child) {
child.setParent(this);
children.add(child);
}
@Override
public void removeChild(Component child) {
children.remove(child);
}
@Override
public void accept(EdiVisitor visitor) {
visitor.startVisit(this);
for (Component component : children)
component.accept(visitor);
visitor.endVisit(this);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < children.size(); i++) {
if (i > 0)
builder.append(':');
builder.append(children.get(i));
}
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy