Java tutorial
/* * * Copyright 2015 Andrey Yakovlev * * 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 jodtemplate.pptx; import java.util.ArrayList; import java.util.Collections; import java.util.List; import jodtemplate.Relationship; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; public class Slide { private Relationship relationship; private final List<Relationship> otherRelationships = new ArrayList<>(); private Presentation presentation; public Presentation getPresentation() { return presentation; } public void setPresentation(final Presentation presentation) { this.presentation = presentation; } public Relationship getRelationship() { return relationship; } public void setRelationship(final Relationship relationship) { this.relationship = relationship; } public List<Relationship> getOtherRelationships() { return Collections.unmodifiableList(new ArrayList<>(otherRelationships)); } public void addOtherRelationship(final Relationship relationship) { if (relationship != null) { otherRelationships.add(relationship); } } public Relationship getRelationshipById(final String rId) { for (final Relationship rel : otherRelationships) { if (rId.equals(rel.getId())) { return rel; } } return null; } public Relationship getRelationshipByTarget(final String target) { for (final Relationship rel : otherRelationships) { if (target.equals(rel.getTarget())) { return rel; } } return null; } public String getNextId() { int id = 1; for (final Relationship rel : otherRelationships) { final String numStr = StringUtils.removeStart(rel.getId(), Relationship.ID_PREFIX); if (NumberUtils.isDigits(numStr)) { final int num = Integer.parseInt(numStr); if (num >= id) { id = num + 1; } } } return Relationship.ID_PREFIX + id; } }