content: /**
   * Copyright 2012 Alessandro Bahgat Shehata
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.abahgat.suffixtree;
  
  import java.util.HashSet;
  import java.util.Set;
  
  public class Utils {
      
      /**
       * Normalize an input string
       * 
       * @param in the input string to normalize
       * @return <tt>in</tt> all lower-case, without any non alphanumeric character
       */
      public static String normalize(String in) {
          StringBuilder out = new StringBuilder();
          String l = in.toLowerCase();
          for (int i = 0; i < l.length(); ++i) {
              char c = l.charAt(i);
              if (c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
                  out.append(c);
              }
          }
          return out.toString();
      }
  
      /**
       * Computes the set of all the substrings contained within the <tt>str</tt>
       * 
       * It is fairly inefficient, but it is used just in tests ;)
       * @param str the string to compute substrings of
       * @return the set of all possible substrings of str
       */
      public static Set<String> getSubstrings(String str) {
          Set<String> ret = new HashSet<String>();
          // compute all substrings
          for (int len = 1; len <= str.length(); ++len) {
              for (int start = 0; start + len <= str.length(); ++start) {
                  String itstr = str.substring(start, start + len);
                  ret.add(itstr);
              }
          }
  
          return ret;
      }
  }
  