001    /*
002     * Copyright (C) 2010 eXo Platform SAS.
003     *
004     * This is free software; you can redistribute it and/or modify it
005     * under the terms of the GNU Lesser General Public License as
006     * published by the Free Software Foundation; either version 2.1 of
007     * the License, or (at your option) any later version.
008     *
009     * This software is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012     * Lesser General Public License for more details.
013     *
014     * You should have received a copy of the GNU Lesser General Public
015     * License along with this software; if not, write to the Free
016     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018     */
019    
020    package org.crsh.util;
021    
022    import java.util.ArrayList;
023    import java.util.HashMap;
024    import java.util.HashSet;
025    import java.util.LinkedList;
026    import java.util.List;
027    
028    /**
029     * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
030     * @version $Revision$
031     */
032    public class Utils {
033    
034      public static <E> ArrayList<E> newArrayList() {
035        return new ArrayList<E>();
036      }
037    
038      public static <E> LinkedList<E> newLinkedList() {
039        return new LinkedList<E>();
040      }
041    
042      public static <E> HashSet<E> newHashSet() {
043        return new HashSet<E>();
044      }
045    
046      public static <K, V> HashMap<K, V> newHashMap() {
047        return new HashMap<K, V>();
048      }
049    
050      public static <E>List<E> list(Iterable<E> iterable) {
051        ArrayList<E> list = new ArrayList<E>();
052        for (E t : iterable) {
053          list.add(t);
054        }
055        return list;
056      }
057    
058      public static String trimLeft(String s) {
059        if (s == null) {
060          throw new NullPointerException("No null string accepted");
061        }
062        int index = 0;
063        int len = s.length();
064        while (index < len) {
065          if (s.charAt(index) == ' ') {
066            index++;
067          } else {
068            break;
069          }
070        }
071        if (index > 0) {
072          return s.substring(index);
073        } else {
074          return s;
075        }
076      }
077    }