Skip to main content
added 8 characters in body
Source Link
Malachi
  • 29.1k
  • 11
  • 87
  • 188

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWordssetWords, getWordsgetWords, setWordCountsetWordCount, setWordsetWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

    Note that you can use TreeMap instead of HashMap to keep the keys in a sorted order, so that if you iterate over words.entrySet(), you will always iterate in sorted order. (You can also provide a custom Comparator to the TreeMap if you are not satisfied with the built-in sorting)

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

    Note that you can use TreeMap instead of HashMap to keep the keys in a sorted order, so that if you iterate over words.entrySet(), you will always iterate in sorted order. (You can also provide a custom Comparator to the TreeMap if you are not satisfied with the built-in sorting)

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

    Note that you can use TreeMap instead of HashMap to keep the keys in a sorted order, so that if you iterate over words.entrySet(), you will always iterate in sorted order. (You can also provide a custom Comparator to the TreeMap if you are not satisfied with the built-in sorting)

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

added 295 characters in body
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

    Note that you can use TreeMap instead of HashMap to keep the keys in a sorted order, so that if you iterate over words.entrySet(), you will always iterate in sorted order. (You can also provide a custom Comparator to the TreeMap if you are not satisfied with the built-in sorting)

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

    Note that you can use TreeMap instead of HashMap to keep the keys in a sorted order, so that if you iterate over words.entrySet(), you will always iterate in sorted order. (You can also provide a custom Comparator to the TreeMap if you are not satisfied with the built-in sorting)

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

added 501 characters in body
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • You can store the number of times each word occurs with a HashMap<String, Integer> instead.

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

There are a couple of things you should think about or fix:

  • Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.

  • No need to call super() inside your constructor, the default empty super constructor is automatically called.

  • Use "constructor chaining" in WordArrayList, and TextAnalyzer. That is, call one constructor from another. For example,

      public TextAnalyzer(String text) {
          this(text, REG_SPLIT_EXP);
      }
    
  • You have a whole lot of unnecessary methods: setWords, getWords, setWordCount, setWord. You don't use them and I really don't think that you need them.

  • Use private final for fields that should be initialized once and then never change, such as private final String word; in the WordData class. Apply this wherever possible.

  • private int position; is not used in WordData, and I don't think you need to use it either. Select and press the Delete button on your keyboard

  • I suggest naming the class WordList instead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to know

  • Calling generateWordArrayList multiple times would produce strange results.

  • convertToArray is private, contains one line, and is only called from one location: Does it really need to be it's own method?

  • Use a "for-each" loop to improve readability when iterating:

      for (String str : splitTextArray)
    
  • You can store the number of times each word occurs with a HashMap<String, Integer> instead. To initialize the HashMap, you can use this:

      Map<String, Integer> words = new HashMap<String, Integer>();
      for (String str : splitTextArray) {
          if (words.containsKey(str))
              words.put(str, words.get(str) + 1);
          else words.put(str, 1);
      }
    

Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.

Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312
Loading