Utilities.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.generic_project.utils;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. /**
  24.  * Utilities
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class Utilities {

  31.     public static String normalizedProjectName(String projectName){
  32.         StringBuilder bf = new StringBuilder();
  33.         boolean precedenteMaiuscolo = false;
  34.         for (int i = 0; i < projectName.length(); i++) {
  35.             char c = projectName.charAt(i);
  36.            
  37.             if(Utilities.isUpperCase(c)){
  38.                 if(!precedenteMaiuscolo && i>0){
  39.                     bf.append("_");
  40.                 }
  41.                 precedenteMaiuscolo = true;
  42.             }else{
  43.                 precedenteMaiuscolo = false;
  44.             }
  45.            
  46.             if( (bf.toString().length()>0) && (c=='_') && (bf.toString().charAt(bf.toString().length()-1)=='_') ){
  47.                 // nop, _ gia aggiunto
  48.             }else{
  49.                 bf.append(Utilities.toLowerCase(c));
  50.             }
  51.         }
  52.         return bf.toString().replaceAll("-", "");
  53.     }
  54.     private static boolean isUpperCase(char c){
  55.         String sC = c + "";
  56.         return sC.toUpperCase().equals(sC);
  57.     }
  58.     private static char toLowerCase(char c){
  59.         String sC = c + "";
  60.         return sC.toLowerCase().charAt(0);
  61.     }
  62.    
  63.    
  64.     public static boolean equals(Object o1,Object o2){
  65.         if(o1==null){
  66.             if(o2!=null){
  67.                 return false;
  68.             }
  69.             else{
  70.                 return true;
  71.             }
  72.         }
  73.         else{
  74.             if(o2==null){
  75.                 return false;
  76.             }
  77.             else{
  78.                 return o1.equals(o2);
  79.             }
  80.         }
  81.     }
  82.    
  83.     public static List<?> newList(Object ... object){
  84.         List<Object> list = new ArrayList<>();
  85.         for (int i = 0; i < object.length; i++) {
  86.                 list.add(object[i]);
  87.         }
  88.         return list;
  89.     }
  90. }