?? modulespec.java
字號(hào):
case SPEC_TYPE_TILE: errMsg += "components as it is a 'tile only' specific option"; break; case SPEC_TYPE_COMP: errMsg += "tiles as it is a 'component only' specific option"; break; } throw new Error(errMsg); } if(tileCompVal==null) tileCompVal = new Hashtable(); specValType[t][c] = SPEC_TILE_COMP; tileCompVal.put("t"+t+"c"+c,value); } /** * Gets value of specified tile-component. This method calls getSpec but * has a public access. * * @param t Tile index * * @param c Component index * * @return The value of this tile-component (Must be casted before use) * * @see #setTileCompVal * * @see #getSpec * */ public Object getTileCompVal(int t,int c){ if ( specType != SPEC_TYPE_TILE_COMP ) { throw new Error("Illegal use of ModuleSpec class"); } return getSpec(t,c); } /** * Gets value of specified tile-component without knowing if a * specific tile-component value has been previously entered. It * first check if a tile-component specific value has been * entered, then if a tile specific value exist, then if a * component specific value exist. If not the default value is * returned. * * @param t Tile index * * @param c Component index * * @return Value for this tile component. * */ protected Object getSpec(int t,int c){ switch(specValType[t][c]){ case SPEC_DEF: return getDefault(); case SPEC_COMP_DEF: return getCompDef(c); case SPEC_TILE_DEF: return getTileDef(t); case SPEC_TILE_COMP: return tileCompVal.get("t"+t+"c"+c); default: throw new IllegalArgumentException("Not recognized spec type"); } } /** * Return the spec type of the given tile-component. * * @param t Tile index * * @param c Component index * */ public byte getSpecValType(int t,int c){ return specValType[t][c]; } /** * Whether or not specifications have been entered for the given * component. * * @param c Index of the component * * @return True if component specification has been defined * */ public boolean isCompSpecified(int c){ if(compDef==null || compDef[c]==null) return false; else return true; } /** * Whether or not specifications have been entered for the given * tile. * * @param t Index of the tile * * @return True if tile specification has been entered * */ public boolean isTileSpecified(int t){ if(tileDef==null || tileDef[t]==null) return false; else return true; } /** * Whether or not a tile-component specification has been defined * * @param t Tile index * * @param c Component index * * @return True if a tile-component specification has been defined. * */ public boolean isTileCompSpecified(int t,int c){ if(tileCompVal==null || tileCompVal.get("t"+t+"c"+c)==null) return false; else return true; } /** * This method is responsible of parsing tile indexes set and * component indexes set for an option. Such an argument must * follow the following policy:<br> * * <tt>t\<indexes set\></tt> or <tt>c\<indexes set\></tt> where * tile or component indexes are separated by commas or a * dashes. * * <p><u>Example:</u><br> * <li> <tt>t0,3,4</tt> means tiles with indexes 0, 3 and 4.<br> * <li> <tt>t2-4</tt> means tiles with indexes 2,3 and 4.<br> * * It returns a boolean array skteching which tile or component are * concerned by the next parameters. * * @param word The word to parse. * * @param maxIdx Maximum authorized index * * @return Indexes concerned by this parameter. * */ public static final boolean[] parseIdx(String word, int maxIdx){ int nChar = word.length(); // Number of characters char c = word.charAt(0); // current character int idx = -1; // Current (tile or component) index int lastIdx = -1; // Last (tile or component) index boolean isDash = false; // Whether or not last separator was a dash boolean[] idxSet = new boolean[maxIdx]; int i=1; // index of the current character while(i<nChar){ c = word.charAt(i); if(Character.isDigit(c)){ if(idx==-1) idx = 0; idx = idx*10+ (c-'0'); } else{ if(idx==-1 || (c!=',' && c!='-')){ throw new IllegalArgumentException("Bad construction for "+ "parameter: "+word); } if(idx<0 || idx>=maxIdx){ throw new IllegalArgumentException("Out of range index in "+ "parameter `"+word+"' : "+ +idx); } // Found a comma if(c==','){ if(isDash){ // Previously found a dash, fill idxSet for(int j=lastIdx+1; j<idx; j++){ idxSet[j] = true; } } isDash = false; } else // Found a dash isDash = true; // Udate idxSet idxSet[idx] = true; lastIdx = idx; idx=-1; } i++; } // Process last found index if(idx<0 || idx>=maxIdx){ throw new IllegalArgumentException("Out of range index in "+ "parameter `"+word+"' : "+idx); } if(isDash) for(int j=lastIdx+1; j<idx; j++){ idxSet[j] = true; } idxSet[idx] = true; return idxSet; } /** * Returns a tile-component representative using default value. * * @return Tile component index in an array (first element: tile * index, second element: component index). * */ public int[] getDefRep(){ int[] tcidx = new int[2]; for(int t=nTiles-1; t>=0; t--){ for(int c=nComp-1; c>=0; c--){ if(specValType[t][c]==SPEC_DEF){ tcidx[0] = t; tcidx[1] = c; return tcidx; } } } throw new IllegalArgumentException("No representative for "+ "default value"); } /** * Returns a component representative using tile default value. * * @param t Tile index * * @return component index of the representant * */ public int getTileDefRep(int t){ for(int c=nComp-1; c>=0; c--) if(specValType[t][c]==SPEC_TILE_DEF){ return c; } throw new IllegalArgumentException("No representative for tile "+ "default value"); } /** * Returns a tile representative using component default value. * * @param c Component index * * @return tile index of the representant * */ public int getCompDefRep(int c){ for(int t=nTiles-1; t>=0; t--) { if(specValType[t][c]==SPEC_COMP_DEF){ return t; } } throw new IllegalArgumentException("No representative for component "+ "default value, c="+c); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -