001 /* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020 package net.sf.gridarta.model.archetypetype; 021 022 import java.util.ArrayList; 023 import java.util.List; 024 import org.jetbrains.annotations.NotNull; 025 026 /** 027 * Maintains a list of section names while parsing {@link ArchetypeAttribute 028 * ArchetypeAttributes}. 029 * @author Andreas Kirschbaum 030 */ 031 public class SectionNames { 032 033 /** 034 * The name of the "General" section. 035 */ 036 public static final String GENERAL_SECTION = "General"; 037 038 /** 039 * The name of the "Special" section. 040 */ 041 public static final String SPECIAL_SECTION = "Special"; 042 043 /** 044 * The section names in display order. 045 */ 046 @NotNull 047 private final List<String> sectionNames = new ArrayList<String>(); 048 049 /** 050 * Creates a new instance. 051 */ 052 public SectionNames() { 053 sectionNames.add(GENERAL_SECTION); 054 sectionNames.add(SPECIAL_SECTION); 055 } 056 057 /** 058 * Defines a section name and returns the section ID. 059 * @param sectionName the section name to define 060 * @return the section ID 061 */ 062 public int defineSectionName(final String sectionName) { 063 final int sectionId = sectionNames.indexOf(sectionName); 064 if (sectionId != -1) { 065 return sectionId; 066 } 067 068 sectionNames.add(sectionName); 069 return sectionNames.size() - 1; 070 } 071 072 /** 073 * Returns the number of defined section names. 074 * @return the number of defined section names 075 */ 076 public int getSectionNames() { 077 return sectionNames.size(); 078 } 079 080 }