Back to project page android-nfc-reader.
The source code is released under:
MIT License
If you think the Android project android-nfc-reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.mklbravo.lib.nfcreader.tags; /*from ww w . j a v a 2 s . co m*/ import java.util.ArrayList; public class MifareClassicTag extends AbstractTag{ public MifareClassicTag(byte[] pTagId) { super(pTagId); } private ArrayList<Sector> sectorList = new ArrayList<Sector>(); public ArrayList<Sector> getSectorList(){ return sectorList; } public Sector getSector(int pIndex){ Sector sector = null; for(Sector actualSector: sectorList){ if(actualSector.index == pIndex){ sector = actualSector; break; } } return sector; } public void addData(int sectorIndex,int blockIndex,byte[] data){ Sector sector = getOrCreateSector(sectorIndex); sector.addData(blockIndex,data); } private Sector getOrCreateSector(int sectorIndex){ Sector sector = getSector(sectorIndex); if(sector == null) { sector = new Sector(sectorIndex); addSectorToList(sector); } return sector; } private void addSectorToList(Sector sector){ if(sectorList.contains(sector)) sectorList.remove(sector); sectorList.add(sector); } public class Sector{ public Sector(int pIndex){ index = pIndex; } private int index; public int getIndex(){ return index; } private ArrayList<Block> blockList = new ArrayList<Block>(); public ArrayList<Block> getBlockList() { return blockList; } public Block getBlock(int blockIndex){ Block block = null; for(Block actualBlock: blockList){ if(actualBlock.index == blockIndex){ block = actualBlock; break; } } return block; } public void addData(int blockIndex,byte[] data){ Block block = new Block(blockIndex,data); addBlock(block); } private void addBlock(Block block){ if(blockList.contains(block)) blockList.remove(block); blockList.add(block); } @Override public boolean equals(Object pSector) { Sector sector = (Sector)pSector; return this.index == sector.index; } public class Block{ public Block(int pIndex, byte[] pData){ index = pIndex; data = pData; } private int index; public int getIndex(){ return index; } private byte[] data; public byte[] getData(){ return data; } @Override public boolean equals(Object pBlock) { Block block = (Block) pBlock; return this.index == block.index; } } } }