001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ade.configuration; 029 030import java.util.List; 031 032import com.google.common.base.Optional; 033 034/** 035 * Represents a sequence of inherited module/sitemap configurations, together with an index into that list.<p> 036 * 037 * Used for computing the configuration inheritance. 038 * 039 */ 040public class CmsADEConfigurationSequence { 041 042 /** The list of configuration data. */ 043 private List<CmsADEConfigDataInternal> m_configDatas; 044 045 /** The index for the current configuration. */ 046 private int m_configIndex; 047 048 /** 049 * Creates a new instance for the given list of configuration data, with the index pointing to the last element.<p> 050 * 051 * @param configDatas the config data list 052 */ 053 public CmsADEConfigurationSequence(List<CmsADEConfigDataInternal> configDatas) { 054 055 this(configDatas, configDatas.size() - 1); 056 } 057 058 /** 059 * Creates a new instance.<p> 060 * 061 * @param configDatas the configuration data list 062 * @param index the index into the list 063 */ 064 protected CmsADEConfigurationSequence(List<CmsADEConfigDataInternal> configDatas, int index) { 065 066 assert(0 <= index) && (index < configDatas.size()); 067 m_configDatas = configDatas; 068 m_configIndex = index; 069 070 } 071 072 /** 073 * Gets the current configuration data.<p> 074 * 075 * @return the current configuration data 076 */ 077 public CmsADEConfigDataInternal getConfig() { 078 079 return m_configDatas.get(m_configIndex); 080 } 081 082 /** 083 * Returns a sequence which only differs from this instance in that its index is one less.<p> 084 * 085 * However, if the index of this instance is already 0, Optional.absent will be returned. 086 * 087 * @return the parent sequence, or Optional.absent if we are already at the start of the sequence 088 */ 089 public Optional<CmsADEConfigurationSequence> getParent() { 090 091 if (m_configIndex <= 0) { 092 return Optional.absent(); 093 } 094 return Optional.fromNullable(new CmsADEConfigurationSequence(m_configDatas, m_configIndex - 1)); 095 } 096 097}