/**
* Filename : BaseItemCollection.java
* Created : Sep 3, 2006 by Administrator
*/
package org.tcm1998.accat;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
import org.tcm1998.accat.ItemFilter.FilterCriteria;
import org.tcm1998.accat.itemproperties.*;
import org.tcm1998.utils.ResourceUtils;
/**
* @author Administrator
*
*/
public class BaseItemCollection {
public static final int FILTER_PRIOS = 2;
public static final int FILTER_CATAGORYBUTTONS = 0;
public static final int FILTER_ITEMFILTER = 1;
//private ArrayList m_items;
private HashMap m_items;
private ArrayList m_availInfo;
private HashMap m_groups;
private HashMap m_sets;
private HashMap m_catagories;
private HashMap m_species;
private HashMap m_personalities;
private HashMap m_itemTypes;
private HashMap m_styles;
private class AvailCatagory{
ArrayList m_items;
String m_name;
}
private class ItemDescription{
String name;
int accatID; //
int gameID; //
HashMap properties;
boolean unorderable;
int normalPrice;
int sellPrice;
int reddPrice;
String available;
int itemTypeID; //
int catagoryID;
int groupID;
int setID;
int genre;
int color;
boolean lucky;
int styleID;
String seasonCode;
String todCode;
String peakSeasonCode;
String peakTodCode;
int size;
int personalityID;
int SpeciesID;
int Birthday;
boolean Male;
String remark;
boolean filtered[];
int fengShuiCode; // obsolete
}
BaseItemCollection(){
m_groups = new HashMap();
m_sets = new HashMap();
m_catagories = new HashMap();
m_species = new HashMap();
m_personalities = new HashMap();
m_itemTypes = new HashMap();
m_styles = new HashMap();
//m_items = new ArrayList();
m_items = new HashMap();
LoadBaseItemList();
LoadAvailabilityInfo();
}
public int[] GetAccatIds()
{
Object keys[] = m_items.keySet().toArray();
int numItems = keys.length;
int[]ids = new int[numItems];
for (int i=0; i< numItems; i++)
{
ids[i] = ((Integer)keys[i]).intValue();
}
return ids;
}
void LoadBaseItemList(){
String line;
BufferedReader buf_in = ResourceUtils.openResource(/*"alpha_order.txt"*/"base_itemlist_wii_temp.txt");
try{
if (buf_in != null){
line = buf_in.readLine();
while (line != null){
line = line.trim();
ItemDescription item = new ItemDescription();
LoadItem(item,line);
m_items.put(new Integer(item.accatID),item);
line = buf_in.readLine();
}
}
}
catch (IOException e){
}
}
void AddItemProperty(ItemDescription item, String name, ItemProperty prop)
{
item.properties.put(name,prop);
}
public String GetItemPropertyText(int id, String name)
{
String retVal = "";
ItemDescription item = (ItemDescription)m_items.get(new Integer(id));
if (item.properties.containsKey(name))
{
ItemProperty prop = (ItemProperty)item.properties.get(name);
retVal = prop.formatText();
}
return retVal;
}
void LoadItem(ItemDescription item, String line){
item.properties = new HashMap();
item.unorderable = true;
item.available = "";
item.peakSeasonCode = "";
item.peakTodCode = "";
boolean bSkipComma = false;
int iCounter = 0;
String param;
StringTokenizer st = new StringTokenizer(line,",",true); // include the tokens
while (st.hasMoreTokens()){
param = st.nextToken();
param = param.trim();
if (!param.equals(",")){
if (param.length() > 0){
switch (iCounter){
case 0:
item.name = param;
AddItemProperty(item,"name",new ItemTextProperty(param));
break;
case 1:
item.accatID = Integer.parseInt(param);
break;
case 2:
if (param.equals("unknown"))
{
item.gameID = 0;
}
else
{
item.gameID = Integer.parseInt(param.substring(0,4),16);
}
break;
case 3:
item.unorderable = (!param.equals("1"));
AddItemProperty(item,"Unorderable",new ItemBoolProperty(param));
break;
case 4:
if ((param.equals("NFS")) || (param.equals("unknown")) || (param.equals("n/a")))
{
item.normalPrice = 0;
}
else
{
item.normalPrice = Integer.parseInt(param);
}
AddItemProperty(item,"NormalPrice",new ItemSaleProperty(param));
break;
case 5:
if ((param.equals("NFS")) || (param.equals("unknown")) || (param.equals("n/a")) || (param.equals("no set price")))
{
item.sellPrice = 0;
}
else
{
item.sellPrice = Integer.parseInt(param);
}
AddItemProperty(item,"SellPrice",new ItemSaleProperty(param));
break;
case 6:
if ((param.equals("NFS")) || (param.equals("unknown")) || (param.equals("n/a")))
{
item.reddPrice = 0;
}
else
{
item.reddPrice = Integer.parseInt(param);
}
AddItemProperty(item,"ReddPrice",new ItemSaleProperty(param));
break;
case 7:
item.available = param;
AddItemProperty(item,"Available",new ItemAvailProperty(param));
break;
case 8:
item.itemTypeID = StoreInGroup(m_itemTypes,param);
//AddItemProperty(item,"ItemType",new ItemTypeProperty(param));
break;
case 9:
item.setID = StoreInGroup(m_sets,param);
AddItemProperty(item,"ItemSet",new ItemTextGroupProperty(param));
break;
case 10:
break; // item group
case 11:
item.genre = Integer.parseInt(param, 16);
AddItemProperty(item,"Genre",new ItemTextGroupProperty(param));
break;
case 12:
item.color = Integer.parseInt(param, 16);
break;
case 13:
break; // Transferable
case 14:
item.groupID = StoreInGroup(m_groups,param);
AddItemProperty(item,"ItemGroup",new ItemTextGroupProperty(param));
break;
case 15:
item.lucky = param.equals("1");
AddItemProperty(item,"Lucky",new ItemBoolProperty(param));
break;
case 16:
item.styleID = StoreInGroup(m_styles,param);
AddItemProperty(item,"Style",new ItemTextGroupProperty(param));
break;
case 17:
break; // mood
case 18:
item.seasonCode = param;
AddItemProperty(item,"Season",new ItemSeasonProperty(param));
break;
case 19:
item.peakSeasonCode = param;
AddItemProperty(item,"PeakSeason",new ItemSeasonProperty(param));
break;
case 20:
item.todCode = param;
AddItemProperty(item,"TOD",new ItemTODProperty(param));
break;
case 21:
item.peakTodCode = param;
AddItemProperty(item,"PTOD",new ItemTODProperty(param));
break;
case 22:
if (param.equals("unknown") | param.equals("n/a"))
{
item.size = 0;
}
else
{
item.size = Integer.parseInt(param);
}
AddItemProperty(item,"Size",new ItemNumericProperty(param));
break;
case 23:
item.personalityID = StoreInGroup(m_personalities,param);
AddItemProperty(item,"Personality",new ItemTextGroupProperty(param));
break;
case 24:
item.SpeciesID = StoreInGroup(m_species,param);
AddItemProperty(item,"Species",new ItemTextGroupProperty(param));
break;
case 25:
item.Birthday = 0;
break;
case 26:
item.Male = param.equals("1");
AddItemProperty(item,"Sex",new ItemBoolProperty(param));
break;
case 27:
break; // Catchphrase
case 28:
break; // Favorite Shirt
case 29:
break; // Favorite Clothing Style
case 30:
break; // Least Favorite Clothing Style
case 31:
break; // House Music
case 32:
item.remark = param;
AddItemProperty(item,"Remark",new ItemTextProperty(param));
break;
default:
break;
}
}
iCounter++;
bSkipComma = true;
}
else{
if (!bSkipComma){
iCounter++;
}
bSkipComma = false;
}
}
if (iCounter < 6){item.groupID = -1;}
if (iCounter < 7){item.setID = -1;}
}
void LoadAvailabilityInfo(){
m_availInfo = new ArrayList();
AvailCatagory cat = null;
String line;
BufferedReader buf_in = ResourceUtils.openResource("availability_wii.txt");
try{
if (buf_in != null){
line = buf_in.readLine();
while (line != null){
line = line.trim();
if (line.startsWith("_")){
cat = new AvailCatagory();
cat.m_items = new ArrayList();
cat.m_name = line.substring(1);
m_availInfo.add(cat);
}
else{
if (cat != null){
cat.m_items.add(line);
}
}
line = buf_in.readLine();
}
}
}
catch (IOException e){
}
}
// Construct availabity
// input code:
// bits 0-4 : Base
// bits 5-9 : Param 1
// bits 10-14: Param 2
String ConstructAvailability(String code)
{
String part = null;
String result = "";
int pos = -1;
StringTokenizer st = new StringTokenizer(code,"/",false); // include the tokens
while (st.hasMoreTokens()){
if (result.length() != 0)
{
result += " / ";
}
part = st.nextToken();
pos = part.indexOf('.');
if (pos != -1)
{
result += ConstructAvailabilityPart(part.substring(0, pos));
String[] itemlist = ParseAvailabilityItemIds(part.substring(pos+1));
String items = FormatItems(itemlist);
pos = result.indexOf("@@@");
if (pos != -1)
{
String totalResult = result.substring(0, pos-1); // we want to get rid of the space just before the @@@
totalResult += items;
totalResult += result.substring(pos+3);
result = totalResult;
}
}
else
{
result += ConstructAvailabilityPart(part);
}
}
return result;
}
private String ConstructAvailabilityPart(String code){
int iCode = Integer.parseInt(code);
int base = (iCode & 0x3f)-1;
int param;
int mask = 0x7C0;
int shift = 6;
String replaceString;
String paramString;
String baseString = ((String)((AvailCatagory)m_availInfo.get(0)).m_items.get(base));
baseString = baseString.replaceAll("#[^#]*#","");
int pos = baseString.indexOf('%');
while (pos != -1){
int parlen = 2;
param = getParam(baseString,pos);
if (param > 9){
parlen++;
}
//if (param == 0){
// paramString = ConstructFlowers(code);
//}
//else{
paramString = ((String)((AvailCatagory)m_availInfo.get(param)).m_items.get((iCode & mask)>>shift));
paramString = paramString.replaceAll("#[^#]*#","");
//}
replaceString = baseString.substring(pos,pos+parlen);
baseString = baseString.replaceAll(replaceString, paramString);
pos = baseString.indexOf('%');
shift+=5;
mask <<=5;
}
return baseString;
}
private String[] ParseAvailabilityItemIds(String ids)
{
String result = "";
StringTokenizer st = new StringTokenizer(ids, ".",false); // don't include the tokens
while (st.hasMoreTokens()){
if (result.length() != 0)
{
result += "/";
}
int id = new Integer(st.nextToken()).intValue();
result += GetItemName(id);
}
return result.split("/");
}
String FormatItems(String[] itemlist)
{
String result = "";
if (itemlist.length > 0)
{
if ("AEIOUaeiou".indexOf(itemlist[0].charAt(0)) != -1)
{
result += "n";
}
result += " ";
for (int item = 0; item<itemlist.length;item++)
{
if (item > 0)
{
result += ((item < (itemlist.length-1)) ? ", " : " or ");
}
result += itemlist[item];
}
}
return result;
}
String ConstructFlowers(int code)
{
String result;
String flowers[] = {"pansies","tulips","cosmos","roses"};
String colors[] = {"white","red","yellow","black","purple"};
String color1 = colors[(code & 0x380)>>7];
String color2 = colors[(code & 0x1c00)>>10];
String type = flowers[(code & 0x60)>>5];
if ((code & 8192) != 0){
result = "two " + color1 + " or two " + color2 + " " + type;
}
else if (!color1.equals(color2)){
result = color1 + " and " + color2 + " " + type;
}
else{
result = "two " + color1 + " " + type;
}
return result;
}
public String ConstructFengShui(int code){
int colorVal;
int mask;
String result = "";
String color[] = {"",""};
if ((code & 1) != 0){
result += "Lucky ";
}
mask = 0x06;
for (int index = 0;index < 2; index++){
colorVal = (code & mask) >> ((index * 2)+1);
switch (colorVal){
case 1:
color[index] = "Yellow";
break;
case 2:
color[index] = "Green";
break;
case 3:
color[index] = "Red";
break;
}
mask = 0x18;
}
result += color[0];
if (!color[1].equals("")){
result += "/";
result += color[1];
}
if (result.equals("")){
result = "None";
}
return result;
}
private String ConstructSplitTOD (String codes)
{
String result = "";
StringTokenizer st = new StringTokenizer(codes,"/",false); // exclude the tokens
while (st.hasMoreTokens()){
if (result.length() != 0)
{
result += " / ";
}
result += ConstructTOD(Integer.parseInt(st.nextToken(),16));
}
return result;
}
private String ConstructTOD(int code){
String result;
if (code == 0xFFFFFF){
result = "All day";
}
else{
int index;
boolean avail[] = new boolean[24];
String hours[] = {"12AM_1AM","1AM_1AM","2AM_3AM","3AM_4AM","4AM_5AM","5AM_6AM",
"6AM_7AM","7AM_8AM","8AM_9AM","9AM_10AM","10AM_11AM","11AM_12PM",
"12PM_1PM","1PM_2PM","2PM_3PM","3PM_4PM","4PM_5PM","5PM_6PM",
"6PM_7PM","7PM_8PM","8PM_9PM","9PM_10PM","10PM_11PM","11PM_12AM"};
int mask=0x800000;
for (index = 0;index <24;index++){
avail[index] = ((code & mask) != 0);
mask >>=1;
}
result = CreateRangesFromBoolArray(avail, hours, 24);
String tokens[] = result.split(", ");
result = "";
for (int iToken = 0; iToken < tokens.length; iToken++)
{
if (iToken != 0)
{
result += ", ";
}
result += FormatHourRange(tokens[iToken]);
}
}
return result;
}
// This function has been written for the time of day that fish and bugs are available
// This assumes that there are NO 1-hour ranges. If for some reason that functionality
// is needed this function should be expanded.
private String FormatHourRange(String range)
{
String result = "";
int pos1;
int pos2;
pos1 = range.indexOf('_');
pos2 = range.lastIndexOf('_');
if ((pos1 != -1) && (pos2 != -1))
{
result = range.substring(0, pos1) + " - " + range.substring(pos2+1);
}
return result;
}
private String CreateRangesFromBoolArray(boolean avail[],String fields[],int numFields){
String result="";
int valuesAvail = 0;
int valuesCount = 0;
int start;
for (int field=0;field<numFields;field++){
valuesAvail += (avail[field]?1:0);
}
if (valuesAvail > 0)
{
int startValue = 0;
int value = startValue;
do{
while (!avail[value])value++;
if (value == startValue){
do{
value = (value + (numFields-1)) % numFields;
}while (avail[value]);
value = (value + 1) % numFields;
}
result += fields[value];
start = value;
do{
value = (value+1) % numFields;
valuesCount++;
}while (avail[value]);
startValue = value;
value = (value + (numFields-1)) % numFields;
if (value != start){
result += " - ";
result += fields[value];
}
if (valuesCount < valuesAvail){
result += ", ";
}
value = startValue;
}while (valuesCount < valuesAvail);
}
return result;
}
private int getParam (String base, int start){
String temp = base;
int endPos = temp.indexOf(' ',start);
if (endPos == -1){
endPos = base.length();
}
temp = base.substring(start+1, endPos);
return Integer.parseInt(temp);
}
int StoreInGroup(HashMap map, String value){
int retVal = -1;
if (!map.containsValue(value)){
int key = map.size()+1;
map.put(new Integer(key),value);
retVal = key;
}
else{
Set entries = map.entrySet();
Iterator i = entries.iterator();
while (i.hasNext() && retVal==-1){
Map.Entry entry = (Map.Entry)i.next();
if (entry.getValue().equals(value)){
retVal = ((Integer)entry.getKey()).intValue();
}
}
}
return retVal;
}
private String GetElementFromStorage(HashMap map, int id){
String retVal = "";
if (id != -1){
if (map.containsKey(new Integer(id))){
retVal = (String)map.get(new Integer(id));
}
}
return retVal;
}
public String GetItemGroup(int id){
//int id = ((ItemDescription)m_items.get(number)).groupID;
String retVal = GetElementFromStorage(m_groups,id);
if ((retVal.equals("")) || (retVal.equals("0"))){
retVal = "-";
}
return retVal;
}
public String GetItemSet(int id){
int set_id = ((ItemDescription)m_items.get(new Integer(id))).setID;
return GetElementFromStorage(m_sets,set_id);
}
int GetNumberOfCatagories(){
return m_catagories.size();
}
int GetNumberOfItems(){
return m_items.size();
}
String GetItemName (int id){
return ((ItemDescription)m_items.get(new Integer(id))).name;
//return ((ItemDescription)m_items.get(number)).name;
}
String GetCatagoryName (int catagory){
return GetElementFromStorage(m_catagories,catagory);
}
String GetCatagory (int id){
//int id = ((ItemDescription)m_items.get(number)).catagoryID;
return GetCatagoryName(id);
}
public boolean IsUnOrderable (int id){
return ((ItemDescription)m_items.get(new Integer(id))).unorderable;
//return ((ItemDescription)m_items.get(number)).unorderable;
}
public boolean IsFiltered (int id, int prio){
if (prio >= FILTER_PRIOS){
prio = FILTER_PRIOS-1;
}
boolean filtered = true;
boolean filters[] = ((ItemDescription)m_items.get(new Integer(id))).filtered;
//boolean filters[] = ((ItemDescription)m_items.get(number)).filtered;
int index = 0;
do
{
filtered = filters[index];
}while (filtered && (index < prio));
return filtered;
}
public int GetItemNormalPrice (int id){
return ((ItemDescription)m_items.get(new Integer(id))).normalPrice;
//return ((ItemDescription)m_items.get(number)).normalPrice;
}
public int GetItemReddPrice (int id){
return ((ItemDescription)m_items.get(new Integer(id))).reddPrice;
//return ((ItemDescription)m_items.get(number)).reddPrice;
}
public int GetItemSellPrice (int id){
return ((ItemDescription)m_items.get(new Integer(id))).sellPrice;
//return ((ItemDescription)m_items.get(number)).sellPrice;
}
public int GetItemSize (int id){
return ((ItemDescription)m_items.get(new Integer(id))).size;
//return ((ItemDescription)m_items.get(number)).size;
}
public String GetItemAvailability (int id){
return ConstructAvailability(((ItemDescription)m_items.get(new Integer(id))).available);
//return ConstructAvailability(((ItemDescription)m_items.get(number)).available);
}
public String GetFengShui (int id){
return ConstructFengShui(((ItemDescription)m_items.get(new Integer(id))).fengShuiCode);
}
public String GetColours (int id){
return ConstructColours(((ItemDescription)m_items.get(new Integer(id))).color);
}
private String ConstructColours(int color) {
String[] AvailCols = {"Aqua","Beige","Black","Blue","Brown","Colourful","Gray","*Green#","Orange","Pink","Purple","*Red#","White","*Yellow#"};
String retVal = "";
if (color == 254)
{
retVal = "N/A";
}
else if (color == 255)
{
retVal = "unknown";
}
else
{
int colour1 = (color & 0xF0) >> 4;
int colour2 = (color & 0x0F);
retVal = AvailCols[colour1] + " / " + AvailCols[colour2];
}
return retVal;
}
public String GetLucky(int id){
return ((ItemDescription)m_items.get(new Integer(id))).lucky ? "1" : "0";
}
public String GetGenre(int id){
String retVal = "";
int GenreCode = ((ItemDescription)m_items.get(new Integer(id))).genre;
switch (GenreCode)
{
case 14:
retVal = "Unknown";
break;
case 15:
retVal = "n/a";
break;
default:
if ((GenreCode & 1) != 0)
{
retVal += "Retro";
}
else if ((GenreCode & 2) != 0)
{
retVal += "Trendy";
}
if (!retVal.equals(""))
{
retVal += " / ";
}
if ((GenreCode & 4) != 0)
{
retVal += "Dignified";
}
else if ((GenreCode & 8) != 0)
{
retVal += "Playful";
}
}
return retVal;
}
public String GetTOD (int id){
return ConstructSplitTOD(((ItemDescription)m_items.get(new Integer(id))).todCode);
}
public String GetPeakTOD (int id){
String result = "";
String ptCode = ((ItemDescription)m_items.get(new Integer(id))).peakTodCode;
//int ptCode = ((ItemDescription)m_items.get(number)).peakTodCode;
if (!ptCode.equals("")){
result = ConstructSplitTOD(ptCode);
}
return result;
}
public int FindItemId(String itemName){
Object keys[] = m_items.keySet().toArray();
int catSize = keys.length;
int item = 0;
int retVal = -1;
boolean found = false;
while ((!found) && (item < catSize)){
if (GetItemName(((Integer)keys[item]).intValue()).equals(itemName)){
found = true;
}
else{
item++;
}
}
if (found){
//retVal = ((ItemDescription)m_items.get(item)).accatID;
retVal = ((Integer)keys[item]).intValue();
}
return retVal;
}
public void doFilter (ItemFilter oFilter)
{
FilterCriteria criteria = null;
int iNumCrit = oFilter.getNumCriteria();
if (iNumCrit > 0)
{
criteria = oFilter.getCriteria(0);
initFilter (!criteria.negative, oFilter);
for (int iCrit = 0; iCrit < iNumCrit; iCrit++)
{
criteria = oFilter.getCriteria(iCrit);
// boolean bPeak = false;
switch (oFilter.getCriteriaId(criteria.type, true))
{
case ItemFilter.CR_ORDERABLE:
FilterOrderable(criteria.parameters[0] == 0, !criteria.negative);
break;
case ItemFilter.CR_PSEASON:
// bPeak = true;
case ItemFilter.CR_SEASON:
//FilterSeason(criteria.parameters[0],criteria.parameters[1],bPeak, !criteria.negative);
break;
case ItemFilter.CR_PTOD:
// bPeak = true;
case ItemFilter.CR_TOD:
//FilterTOD(criteria.parameters[0],criteria.parameters[1],bPeak, !criteria.negative);
break;
case ItemFilter.CR_FENGSHUI:
FilterFengShui(criteria.parameters[0], criteria.parameters[1], !criteria.negative);
break;
}
}
}
}
public void initFilter (boolean bClear, ItemFilter oFilter)
{
//boolean[] bUsedCrits = new boolean[m_catagories.size()];
for (int iCrit = 0; iCrit < oFilter.getNumCriteria();iCrit++)
{
switch (oFilter.getCriteriaId(oFilter.getCriteria(iCrit).type,true))
{
case ItemFilter.CR_ORDERABLE:
// for (int iCat = 0; iCat < m_catagories.size(); iCat++)
// {
//bUsedCrits[iCat] = true;
// }
break;
case ItemFilter.CR_FENGSHUI:
//bUsedCrits[0] = true;
case ItemFilter.CR_SEASON:
//bUsedCrits[3] = true;
case ItemFilter.CR_PSEASON:
case ItemFilter.CR_PTOD:
case ItemFilter.CR_TOD:
// bUsedCrits[9] = true;
// bUsedCrits[10] = true;
break;
}
}
boolean bfiltered = false;
Object keys[] = m_items.keySet().toArray();
for (int iItem = 0; iItem < keys.length; iItem++)
{
((ItemDescription)m_items.get(((Integer)keys[iItem]))).filtered[FILTER_ITEMFILTER] = bfiltered;
}
}
public int FilterOrderable (boolean orderable, boolean bAdd)
{
Object keys[] = m_items.keySet().toArray();
int total = 0;
for (int item = 0; item < m_items.size();item++)
{
if (((ItemDescription)m_items.get(((Integer)keys[item]))).unorderable != orderable)
{
((ItemDescription)m_items.get(((Integer)keys[item]))).filtered[FILTER_ITEMFILTER] = !bAdd;
total++;
}
}
return total;
}
/*
public int FilterSeason (int p_iSelection, int p_iMonth, boolean p_bPeak, boolean bAdd)
{
Object keys[] = m_items.keySet().toArray();
//int arrSeasons[]={4102,56,448,3584};
int total = 0;
for (int item = 0; item < m_items.size();item++)
{
int iSeason = (p_bPeak ?
//((ItemDescription)m_items.get(item)).peakSeasonCode :
((ItemDescription)m_items.get((Integer)keys[item])).peakSeasonCode:
//((ItemDescription)m_items.get(item)).seasonCode
((ItemDescription)m_items.get((Integer)keys[item])).seasonCode
);
// Hopefully temperary code to change the cloth season code to a month code
// if (cat == 3)
// {
// int iTemp = iSeason;
// iSeason = 0;
// for (int bit=0;bit < 4;bit++){
// if ((iTemp & (2 << bit)) != 0){
// iSeason |= arrSeasons[bit];
// }
// }
// }
// End of temp code
boolean bLastMonth = ((iSeason & (2 << ((p_iMonth+11) % 12))) != 0);
boolean bThisMonth = ((iSeason & (2 << p_iMonth)) != 0);
boolean bNextMonth = ((iSeason & (2 << ((p_iMonth+13) % 12))) != 0);
boolean bMatched = false;
switch (p_iSelection)
{
case 0: // available
bMatched = bThisMonth;
break;
case 1: // not available
bMatched = !bThisMonth;
break;
case 2: // last change
bMatched = (bThisMonth && !bNextMonth);
break;
case 3: // just missed
bMatched = (!bThisMonth && bLastMonth);
break;
case 4: // new
bMatched = (bThisMonth && !bLastMonth);
break;
}
if (bMatched)
{
((ItemDescription)m_items.get((Integer)keys[item])).filtered[FILTER_ITEMFILTER] = !bAdd;
//((ItemDescription)m_items.get(item)).filtered[FILTER_ITEMFILTER] = !bAdd;
total++;
}
}
return total;
}
private int FilterTOD (int p_iSelection, int p_iHour, boolean p_bPeak, boolean bAdd)
{
Object keys[] = m_items.keySet().toArray();
//int iMasks[]={0xF0,0xFF00,0x70000,0xF8000F,0x1F0,0xFE00,0xF0000,0xF0000F};
int total = 0;
for (int item = 0; item < m_items.size();item++)
{
int iTOD = (p_bPeak ?
((ItemDescription)m_items.get((Integer)keys[item])).peakTodCode:
((ItemDescription)m_items.get((Integer)keys[item])).todCode
//((ItemDescription)m_items.get(item)).peakTodCode :
//((ItemDescription)m_items.get(item)).todCode
);
boolean bLastHour = ((iTOD & (1 << ((p_iHour+23) % 24))) != 0);
boolean bThisHour = ((iTOD & (1 << p_iHour)) != 0);
boolean bNextHour = ((iTOD & (1 << ((p_iHour+25) % 24))) != 0);
boolean bMatched = false;
switch (p_iSelection)
{
case 0: // available
bMatched = bThisHour;
break;
case 1: // not available
bMatched = !bThisHour;
break;
case 2: // last change
bMatched = (bThisHour && !bNextHour);
break;
case 3: // just missed
bMatched = (!bThisHour && bLastHour);
break;
case 4: // new
bMatched = (bThisHour && !bLastHour);
break;
}
if (bMatched)
{
((ItemDescription)m_items.get((Integer)keys[item])).filtered[FILTER_ITEMFILTER] = !bAdd;
//((ItemDescription)m_items.get(item)).filtered[FILTER_ITEMFILTER] = !bAdd;
total++;
}
}
return total;
}
*/
private int FilterFengShui (int p_iSelection, int p_iColor, boolean bAdd)
{
Object keys[] = m_items.keySet().toArray();
int arrColors[]={6,4,2,30,20,10,26,18,22,1,7,5,3,31,21,11,27,19,23};
int total = 0;
for (int item = 0; item < m_items.size();item++)
{
int iFeng = ((ItemDescription)m_items.get((Integer)keys[item])).fengShuiCode;
//int iFeng = ((ItemDescription)m_items.get(item)).fengShuiCode;
int iColor = (iFeng & 0x1E);
boolean bLuck = ((iFeng & 1) != 0);
boolean bMatched = false;
switch (p_iSelection)
{
case 0: // Exact
if (p_iColor != 19){
bMatched = (iFeng == arrColors[p_iColor]);
}
else{
bMatched = (iFeng != 0);
}
break;
case 1: // Atleast
if ((p_iColor % 10) > 2){ // double colors, same as 'exact'
if (p_iColor != 19){
bMatched = (iFeng == arrColors[p_iColor]);
}
else{
bMatched = (iFeng != 0);
}
}
else{
bMatched = ((((iColor & 0x6)) == arrColors[p_iColor % 10]) ||
(((iColor & 0x18) >> 2) == arrColors[p_iColor % 10]));
}
if ((p_iColor > 8) && (p_iColor < 19)) // Must be lucky
{
bMatched &= bLuck;
bMatched |= ((p_iColor == 9) && (bLuck)); //ONLY lucky
}
break;
case 2: // Not
if ((p_iColor % 10) > 2){ // double colors, same as 'exact'
if (p_iColor != 19){
bMatched = !(iFeng == arrColors[p_iColor]);
}
else{
bMatched = (iFeng == 0);
}
}
else{
bMatched = !((((iColor & 0x6)) == arrColors[p_iColor % 10]) ||
(((iColor & 0x18) >> 2) == arrColors[p_iColor % 10]));
}
if ((p_iColor > 8) && (p_iColor <19)) // Must be lucky
{
bMatched |= !bLuck;
bMatched &= ((p_iColor != 9) || (!bLuck));
}
break;
}
if (bMatched)
{
((ItemDescription)m_items.get((Integer)keys[item])).filtered[FILTER_ITEMFILTER] = !bAdd;
//((ItemDescription)m_items.get(item)).filtered[FILTER_ITEMFILTER] = !bAdd;
total++;
}
}
return total;
}
}