What is a good Map to use for writing Registries

satya - Tuesday, September 15, 2009 9:07:36 AM

I am not sure if SparseArray is the right kind, but one kind

I am not sure if SparseArray is the right kind, but one kind

satya - Tuesday, September 15, 2009 9:09:21 AM

Here is an example of how I have used it


public class DialogRegistry 
{
   SparseArray<IDialogProtocol> idsToDialogs
   = new SparseArray();
   public void registerDialog(IDialogProtocol dialog)
   {
      idsToDialogs.put(dialog.getDialogId(),dialog);
   }
   
   public Dialog create(int id)
   {
      IDialogProtocol dp = idsToDialogs.get(id);
      if (dp == null) return null;
      
      return dp.create();
   }
   public void prepare(Dialog dialog, int id)
   {
      IDialogProtocol dp = idsToDialogs.get(id);
      if (dp == null)
      {
          throw new 
          RuntimeException("Dialog id is not registered:" + id);
      }
      dp.prepare(dialog);
   }
}

satya - Tuesday, September 15, 2009 9:09:54 AM

android API SparseArray

Search for: android API SparseArray