AbstractGenericProperties.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.utils.logger.beans.context.core;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.utils.logger.beans.Property;

  26. /**
  27.  * AbstractGenericProperties
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public abstract class AbstractGenericProperties implements Serializable {

  34.     /**
  35.      *
  36.      */
  37.     private static final long serialVersionUID = 1L;
  38.    
  39.     private List<String> _genericProperties_position = new ArrayList<>();
  40.     private Map<String,Property> genericProperties = new java.util.HashMap<String,Property>();

  41.    

  42.     public Map<String,Property> getGenericProperties() {
  43.         return this.genericProperties;
  44.     }
  45.     public List<Property> getGenericPropertiesAsList() {
  46.         List<Property> l = new ArrayList<Property>();
  47.         for (String key : this._genericProperties_position) {
  48.             l.add(this.genericProperties.get(key));
  49.         }
  50.         return l;
  51.     }
  52.    
  53.     public void addGenericProperty(Property property){
  54.         this.genericProperties.put(property.getName(),property);
  55.         this._genericProperties_position.add(property.getName());
  56.     }
  57.    
  58.     public Property getGenericProperty(String key){
  59.         return this.genericProperties.get(key);
  60.     }
  61.    
  62.     public Property removeGenericProperty(String key){
  63.         int index = -1;
  64.         for (int i = 0; i < this._genericProperties_position.size(); i++) {
  65.             if(key.equals(this._genericProperties_position.get(i))){
  66.                 index = i;
  67.                 break;
  68.             }
  69.         }
  70.         this._genericProperties_position.remove(index);
  71.         return this.genericProperties.remove(key);
  72.     }
  73.    
  74.     public Property getGenericProperty(int index){
  75.         return this.getGenericPropertiesAsList().get(index);
  76.     }
  77.    
  78.     public Property removeGenericProperty(int index){
  79.         Property p = this.getGenericPropertiesAsList().get(index);
  80.         this.genericProperties.remove(p.getName());
  81.         return p;
  82.     }
  83.    
  84.     public int sizeGenericProperties(){
  85.         return this.genericProperties.size();
  86.     }
  87.    
  88.     public void clearGenericProperties(){
  89.         this.genericProperties.clear();
  90.     }

  91. }