ApacheClient.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.id;

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

  23. import org.openspcoop2.utils.UtilsException;
  24. import org.openspcoop2.utils.id.apache.serial.EnumTypeGenerator;
  25. import org.openspcoop2.utils.regexp.RegularExpressionEngine;

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

  35.     public static void main(String[] args) throws Exception {
  36.         test();
  37.     }
  38.    
  39.     public static void test() throws Exception {
  40.        
  41.         ApacheIdentifierGenerator generator = new ApacheIdentifierGenerator();
  42.         ApacheGeneratorConfiguration config = new ApacheGeneratorConfiguration();
  43.        
  44.         config.setType(EnumTypeGenerator.PREFIXED_ALPHANUMERIC);
  45.         config.setPrefix("PREFIX");
  46.        
  47.         config.setSize("PREFIX".length()+3);
  48.         //config.setInitialStringValue("PREFIXbb");
  49.        
  50.         config.setStartDigit('3');
  51.         config.setEndDigit('9');
  52.        
  53.         config.setStartLetter('b');
  54.         config.setEndLetter('z');
  55.        
  56.         config.setEnableLowerCaseLetter(true);
  57.         config.setEnableUpperCaseLetter(true);
  58.        
  59.         config.setWrap(false);
  60.        
  61.         generator.initialize(config);
  62.        
  63.        
  64.         List<String> check = new ArrayList<>();
  65.        
  66.         String v = null;
  67.         int i = 0;
  68.         try{
  69.             for (; i < 10000; i++) {
  70.                 v = generator.newID().toString();
  71.                 if(!RegularExpressionEngine.isMatch((v+""),"^[a-zA-Z0-9]*$")){
  72.                     throw new UtilsException("Deve essere fornito [a-zA-Z0-9] trovato ["+v+"]");
  73.                 }
  74.                 if(!check.contains(v)){
  75.                     check.add(v);
  76.                 }else{
  77.                     throw new Exception("Valore ["+v+"] gia generato");
  78.                 }
  79.                 if(i<20){
  80.                     System.out.println("VALORE ["+i+"]: "+v);
  81.                 }else if(i%50 == 0 )
  82.                     System.out.println("VALORE ["+i+"]: "+v);
  83.             }
  84.         }finally{
  85.             System.out.println("VALORE LAST ["+i+"]: "+v);
  86.         }
  87.        
  88.        
  89.     }
  90. }