~shadow-h511/+junk/cs211

« back to all changes in this revision

Viewing changes to resursiveSS/src/edu/ewu/eastern/seaking/recur_substr/SubstringGenerator.java

  • Committer: Sam Dodrill
  • Date: 2011-11-07 08:18:16 UTC
  • Revision ID: shadow.h511@gmail.com-20111107081816-2lyhnfnu0se7r8ky
 recursive substring stuff mostly done

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package edu.ewu.eastern.seaking.recur_substr;
 
2
/**
 
3
 * 
 
4
 * @author Sam Dodrill
 
5
 * @version 1.0
 
6
 * @category education
 
7
 *
 
8
 */
 
9
public class SubstringGenerator {
 
10
        /**
 
11
         *      
 
12
         * @param s
 
13
         * This calls another function to do the substring generation,
 
14
         * this might reach the call stack depth limit.
 
15
         * 
 
16
         */
 
17
        public static void generateSubstrings(String s) {
 
18
                if(isNumberReallyBig(s.length())) {
 
19
                        System.out.println("String too big, enter smaller string");
 
20
                } else {
 
21
                        generateSubstrings(s, 0);
 
22
                }
 
23
        }
 
24
        
 
25
        /**
 
26
         * 
 
27
         * @param s
 
28
         * @param index
 
29
         * Calls the recursive substring sprayer
 
30
         * 
 
31
         */
 
32
        public static void generateSubstrings(String s, int index) {
 
33
                spraySubstrings(s.substring(index));
 
34
                generateSubstrings(s, index++);
 
35
        }
 
36
        
 
37
        /**
 
38
         * 
 
39
         * @param s
 
40
         * @param index
 
41
         * The recursive substring sprayer
 
42
         * 
 
43
         */
 
44
        public static void spraySubstrings(String s) {
 
45
                if(s.length() != 0) {
 
46
                        System.out.println(s.substring(0));
 
47
                        spraySubstrings(s.substring(1));
 
48
                }
 
49
        }
 
50
        
 
51
        /**
 
52
         * 
 
53
         * @param n
 
54
         * @return if the number is considered really big
 
55
         * better function name would be isbignum?
 
56
         */
 
57
        private static boolean isNumberReallyBig(int n) {
 
58
                if(n > 1000000) {
 
59
                        return true;
 
60
                } else {
 
61
                        return false;
 
62
                }
 
63
        }
 
64
}