package ball;
public class Configuration
{
static public int MaxDigit = 7;
}
package ball;
public class HistoryRecordEntry
{
private int[] Number;
public HistoryRecordEntry()
{
Number = new int[Configuration.MaxDigit];
}
public int getNumberFromDigit(int Digit)
{
return Number[Digit];
}
public void fillData(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7 )
{
Number[0] = arg1;
Number[1] = arg2;
Number[2] = arg3;
Number[3] = arg4;
Number[4] = arg5;
Number[5] = arg6;
Number[6] = arg7;
}
}
package ball;
public class MainFrame
{
("unused")
public static void main(String[] args)
{
Processor processor = new Processor();
HistoryRecordEntry entry = new HistoryRecordEntry();
// fill history data
//2003001
processor.insert(10, 11, 12, 13, 26, 28, 11);
processor.insert( 4, 9, 19, 20, 21, 26, 12);
processor.insert( 1, 7, 10, 23, 28, 32, 16);
processor.insert( 4, 6, 7, 10, 13, 25, 3);
processor.insert( 4, 6, 15, 17, 30, 31, 16);
processor.insert( 1, 3, 10, 21, 26, 27, 6);
processor.insert( 1, 9, 19, 21, 23, 26, 7);
processor.insert( 5, 8, 9, 14, 17, 23, 8);
processor.insert( 5, 9, 18, 20, 22, 30, 9);
processor.insert( 1, 2, 8, 13, 17, 24, 13);
processor.insert( 4, 5, 11, 12, 30, 32, 15);
processor.insert( 2, 12, 16, 17, 27, 30, 12); // 2003012
processor.insert( 8, 13, 17, 21, 23, 32, 12);
processor.insert( 3, 5, 7, 8, 21, 31, 2);
processor.insert( 4, 11, 19, 25, 26, 32, 13);
processor.insert(11, 17, 28, 30, 31, 33, 6);
processor.insert( 5, 8, 18, 23, 25, 31, 6); // 2003017
System.out.println("Current Number: " + processor.getTotalRecordNumber());
processor.start();
}
}
package ball;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.Map.Entry;
/* example: 13 occurs 15 time
* 2 occurs 12 time
*/
public class OccuranceForEachNumber
{
private HashMap<Integer,Integer> OccuranceEachDigit = null;
private HashMap<Integer,Vector<Integer>> CondensedOccurance = null;
public OccuranceForEachNumber()
{
OccuranceEachDigit = new HashMap<Integer,Integer>();
}
public boolean isNumberExist(int Number)
{
return OccuranceEachDigit.containsKey(Number);
}
public void updateNumberOccurance(int Number)
{
int CurrentOccurance = OccuranceEachDigit.get(Number);
CurrentOccurance++;
OccuranceEachDigit.put(Number,CurrentOccurance);
}
public void initialNumberOccurance(int Number)
{
OccuranceEachDigit.put(Number, 1);
}
public void ListOccuranceForEachNumber()
{
Set<Entry<Integer, Integer>> set = OccuranceEachDigit.entrySet();
Iterator<Entry<Integer, Integer>> itor = set.iterator();
while(itor.hasNext())
{
Entry<Integer, Integer> entry = itor.next();
int Digit = entry.getKey();
System.out.println("Number: " + Digit + " Occurance: " + entry.getValue() );
}
}
public void condense()
{
if (CondensedOccurance != null )
CondensedOccurance.clear();
CondensedOccurance = new HashMap<Integer,Vector<Integer>>();
Set<Entry<Integer, Integer>> set = OccuranceEachDigit.entrySet();
Iterator<Entry<Integer, Integer>> itor = set.iterator();
while(itor.hasNext())
{
Entry<Integer, Integer> entry = itor.next();
int NumberwithOccurance = entry.getKey();
int Occurance = entry.getValue();
if( CondensedOccurance.containsKey(entry.getValue()) == false)
{
Vector<Integer> NumberListWithSameOccurance = new Vector<Integer>();
NumberListWithSameOccurance.add(NumberwithOccurance);
CondensedOccurance.put(Occurance, NumberListWithSameOccurance);
}
else
{
Vector<Integer> existingNumberList = CondensedOccurance.get(Occurance);
existingNumberList.add(NumberwithOccurance);
CondensedOccurance.put(Occurance, existingNumberList);
}
}
Set<Entry<Integer, Vector<Integer>>> Revertset = CondensedOccurance.entrySet();
Iterator<Entry<Integer, Vector<Integer>>> Revertitor = Revertset.iterator();
while(Revertitor.hasNext())
{
Entry<Integer, Vector<Integer>> entry = Revertitor.next();
System.out.println("Occruance: " + entry.getKey());
for( int i = 0 ; i < entry.getValue().size(); i ++)
{
System.out.println("Number with same Occurance: " + entry.getValue().elementAt(i));
}
}
}
}
package ball;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;
public class OccuranceOverview
{
private HashMap<Integer,OccuranceForEachNumber> OccuranceOverview = null;
public OccuranceOverview()
{
OccuranceOverview = new HashMap<Integer,OccuranceForEachNumber>();
for ( int i = 0 ; i < Configuration.MaxDigit; i++ )
{
OccuranceForEachNumber Occurance4EachNumber = new OccuranceForEachNumber();
OccuranceOverview.put(i,Occurance4EachNumber);
}
}
public OccuranceForEachNumber getOccuranceInstanceByDigit(int Digit)
{
return OccuranceOverview.get(Digit);
}
public void updateDigitOccurance(int Digit,OccuranceForEachNumber OccuranceInstance)
{
OccuranceOverview.put(Digit, OccuranceInstance);
}
public void listOccuranceForEachDigit()
{
Set<Entry<Integer, OccuranceForEachNumber>> set = OccuranceOverview.entrySet();
Iterator<Entry<Integer, OccuranceForEachNumber>> itor = set.iterator();
while(itor.hasNext())
{
Entry<Integer, OccuranceForEachNumber> entry = itor.next();
int Digit = entry.getKey();
System.out.println("**************** Digit: " + Digit + " Information Begin! *************");
entry.getValue().ListOccuranceForEachNumber();
System.out.println("**************** Condensed Information! **********");
entry.getValue().condense();
}
}
}
package ball;
import java.util.Vector;
public class Processor
{
private Vector<HistoryRecordEntry> RecordList = null;
public Processor()
{
RecordList = new Vector<HistoryRecordEntry>();
}
public void insert(int arg1, int arg2,int arg3,int arg4,int arg5,int arg6, int arg7)
{
HistoryRecordEntry entry = new HistoryRecordEntry();
entry.fillData(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
RecordList.add(entry);
}
public int getTotalRecordNumber()
{
return RecordList.size();
}
public void start()
{
OccuranceForEachNumber Occurance4EachNumber = null;
OccuranceOverview OccuranceOverviewTool = new OccuranceOverview();
for ( int i = 0 ; i < RecordList.size(); i++)
{
HistoryRecordEntry entry = RecordList.get(i);
for( int j = 0; j < Configuration.MaxDigit; j++) // 0 ~6
{
int NumberPerDigit = entry.getNumberFromDigit(j); // example digit 0 number 9
Occurance4EachNumber = OccuranceOverviewTool.getOccuranceInstanceByDigit(j);
if ( Occurance4EachNumber.isNumberExist(NumberPerDigit) == true )
{
Occurance4EachNumber.updateNumberOccurance(NumberPerDigit);
}
else
{
Occurance4EachNumber.initialNumberOccurance(NumberPerDigit);
}
OccuranceOverviewTool.updateDigitOccurance(j,Occurance4EachNumber);
}
}
OccuranceOverviewTool.listOccuranceForEachDigit();
}
}