我是新來的Java,我的工作寬度Android SDK中創建的HashMap作爲高速緩存的對象,問題的關鍵對象
進出口產生了很多這是在50%TE同一對象的,所以我認爲我可以實現簡單的緩存機制
private HashMap<CachePathKey, Path> mCachedPaths;
public Path GenerateRealPath(final Sprite pSprite,final int pStartIndex){
CachePathKey mCachedKey = new CachePathKey(mPathID, pStartIndex, MyGame.mCamera.getZoomFactor(), pSprite.getWidth(), pSprite.getHeight());
if (!mCachedPaths.containsKey(mCachedKey)){
//generate Path Object to p
mCachedPaths.put(mCachedKey,p);
return p;
} else {
return mCachedPaths.get(mCachedKey);
}
和CachePathKey是:
class CachePathKey {
private int mPathID;
private int mStartIndex;
private float mZF;
private float mWidthSprite;
private float mHeightSprite;
public CachePathKey(int pPathID, int pStartIndex, float pZf,
float pWidthSprite, float pHeightSprite) {
this.mPathID =pPathID;
this.mStartIndex = pStartIndex;
this.mZF = pZf;
this.mWidthSprite = pWidthSprite;
this.mHeightSprite = pHeightSprite;
}
}
,但我已經爲空值密鑰時調試,並在返回的containsKey總是假
我做錯了什麼?
所有這些都是唯一的,一個可以有(mPathID = 1,mZF = 1)或(mPathID = 1,mZF = 0.9f) –
你需要唯一地識別你的物體什麼情況你做什麼 –
作品像魅力!謝謝 –