ListElement.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.web.lib.mvc;

  21. import java.io.Serializable;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. import java.util.Map;
  25. import java.util.Set;

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

  34.     /**
  35.      *
  36.      */
  37.     private static final long serialVersionUID = 1L;
  38.     private String oggetto;
  39.     private Map<String,Object> parameters = new HashMap<>();

  40.     public String getOggetto() {
  41.         return this.oggetto;
  42.     }
  43.     public void setOggetto(String oggetto) {
  44.         this.oggetto = oggetto;
  45.     }

  46.     public void addParameter(String key, Object object) {
  47.         this.getParameters().put(key, object);
  48.     }
  49.     public Object getParameter(String key) {
  50.         if (this.getParameters() != null)
  51.             return this.getParameters().get(key);
  52.         else
  53.             return null;
  54.     }
  55.     public Object removeParameter(String key) {
  56.         if (this.getParameters() != null)
  57.             return this.getParameters().remove(key);
  58.         else
  59.             return null;
  60.     }
  61.     public Object getParameter(int index) {
  62.         if (this.getParameters() != null) {
  63.             Set<?> keySet = this.getParameters().keySet();
  64.             Iterator<?> it = keySet.iterator();
  65.             int contatore = 0;
  66.             while (it.hasNext()) {
  67.                 String key = (String) it.next();
  68.                 if (contatore == index)
  69.                     return this.getParameters().get(key);
  70.                 contatore++;
  71.             }
  72.         }
  73.         return null;
  74.     }
  75.     public Object removeParameter(int index) {
  76.         if (this.getParameters() != null) {
  77.             Set<?> keySet = this.getParameters().keySet();
  78.             Iterator<?> it = keySet.iterator();
  79.             int contatore = 0;
  80.             while (it.hasNext()) {
  81.                 String key = (String) it.next();
  82.                 if (contatore == index)
  83.                     return this.getParameters().remove(key);
  84.                 contatore++;
  85.             }
  86.         }
  87.         return null;
  88.     }
  89.     public int sizeParameter() {
  90.         return this.getParameters().size();
  91.     }
  92.     // Ritorna una stringa contenente tutti i parametri codificati
  93.     // per essere inseriti come parametri di una url. Ad esempio:
  94.     // nome1=valore1&nome2=valore2&.....
  95.     public String formatParametersURL() {
  96.         StringBuilder formatParBuf = new StringBuilder();
  97.         if (this.getParameters() != null) {
  98.             Set<?> keySet = this.getParameters().keySet();
  99.             Iterator<?> it = keySet.iterator();
  100.             boolean firstEl = true;
  101.             while (it.hasNext()) {
  102.                 String key = (String) it.next();
  103.                 if (firstEl) {
  104.                     formatParBuf.append(key)
  105.                     .append("=")
  106.                     .append(this.getParameters().get(key));
  107.                     firstEl = false;
  108.                 } else {
  109.                     formatParBuf.append("&")
  110.                     .append(key)
  111.                     .append("=")
  112.                     .append(this.getParameters().get(key));
  113.                 }
  114.             }
  115.         }
  116.         return formatParBuf.toString();
  117.     }
  118.    
  119.     @Deprecated
  120.     public Map<String,Object> getParameters() {
  121.         return this.parameters;
  122.     }
  123.     @Deprecated
  124.     public void setParameters(Map<String,Object> parameters) {
  125.         this.parameters = parameters;
  126.     }
  127.    
  128. }