import java.util.*;import java.io.*;import java.lang.*;public class SegmentCount {   static void countIfInteresting(Segment s)     { if(s.isInteresting()) count(s);     };   public static void main(String [] args) throws IOException{        FileReader dataFile = new FileReader("duckling");        Word w1 = Word.readWord(dataFile);        Word w2 = Word.readWord(dataFile);        Word w3 = Word.readWord(dataFile);        Word w4 = Word.readWord(dataFile);        while(!w4.isEndoffileWord())          { //an optimization "knowing" body of Segment.isInteresting          if(w1.isStopword());            else              {countIfInteresting(new Segment(w1));               countIfInteresting(new Segment(w1,w2));               countIfInteresting(new Segment(w1,w2,w3));               countIfInteresting(new Segment(w1,w2,w3,w4));};            w1=w2;w2=w3;w3=w4;w4=Word.readWord(dataFile);          };        //the end        countIfInteresting(new Segment(w1));        countIfInteresting(new Segment(w1,w2));        countIfInteresting(new Segment(w1,w2,w3));        countIfInteresting(new Segment(w2));        countIfInteresting(new Segment(w2,w3));        countIfInteresting(new Segment(w3));                //System.out.println(segmentCounts);                //print out this occurring 3 or more times        //HashMap has no iterator, so the following absurdities needed        //Furthermore segmentCounts.entrySet() returns an Object        //which is supposed to be of class Entry;        //However Entry is an interface not implemented so        //typecast and operations are nonexisting;        //So compiler cannot eat        //   Iterator itr = segmentCounts.entrySet().iterator();        //   Entry keyVal; //"cannot resolve symbol"        //   while( itr.hasNext())        //     {keyVal = ((Entry)itr).next();// same here        //     ...}        // DESIGN BUG in Java libraries???                //So only possible way: take keys out and iterate over those        //in an inefficient way        Iterator itr = segmentCounts.keySet().iterator();        int count;        Segment s;        while( itr.hasNext())            { s = (Segment)itr.next();              count = ((IntegerVar)segmentCounts.get(s)).value;              if(count >=3 && s.words.length>2)                System.out.println(s+": "+count);};    };  private static HashMap segmentCounts = new HashMap(10000) ;    private static class IntegerVar //to be use in segmentCounts      {public int value;       public IntegerVar(int i){value=i;};       public void inc(){value++;};       public String toString(){return ""+value;};};     public static void count(Segment s)   {Object foundSegCount;    if( (foundSegCount = segmentCounts.get(s)) != null )       ((IntegerVar)foundSegCount).inc();    else      segmentCounts.put(s, new IntegerVar(1));   };     } 
