ListLong2ArrayLong.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.jaxb;

  21. import java.util.ArrayList;

  22. import javax.xml.bind.annotation.adapters.XmlAdapter;

  23. /**
  24.  * ListLong2ArrayLong
  25.  *
  26.  * @author Nardi Lorenzo (nardi@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class ListLong2ArrayLong extends XmlAdapter<ArrayList<Long>, long[]>
  31. {
  32.     @Override
  33.     public ArrayList<Long> marshal(long[] array) throws Exception {
  34.         if(array==null || array.length<=0){
  35.             return null;
  36.         }
  37.         ArrayList<Long> list = new ArrayList<Long>();
  38.         for(int i=0; i<array.length; i++)
  39.             list.add(array[i]);
  40.         return list;
  41.     }
  42.     @Override
  43.     public long[] unmarshal(ArrayList<Long> list) throws Exception {
  44.         if(list==null || list.size()<=0){
  45.             return null;
  46.         }
  47.         long[] array =  new long[list.size()];
  48.         for(int i=0; i<list.size(); i++){
  49.             array[i] = list.get(i).longValue();
  50.         }
  51.         return array;
  52.     }
  53. }