Android Open Source - CopresenceDataCollector Window Cache






From Project

Back to project page CopresenceDataCollector.

License

The source code is released under:

Copyright (c) 2014, Xiang Gao All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Re...

If you think the Android project CopresenceDataCollector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package wei.mark.standout;
/*from  w  w w.j av  a2  s .  c o m*/
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import wei.mark.standout.ui.Window;

import android.util.SparseArray;

public class WindowCache {
  public Map<Class<? extends StandOutWindow>, SparseArray<Window>> sWindows;

  public WindowCache() {
    sWindows = new HashMap<Class<? extends StandOutWindow>, SparseArray<Window>>();
  }

  /**
   * Returns whether the window corresponding to the class and id exists in
   * the {@link #sWindows} cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            Class corresponding to the window.
   * @return True if the window corresponding to the class and id exists in
   *         the cache, or false if it does not exist.
   */
  public boolean isCached(int id, Class<? extends StandOutWindow> cls) {
    return getCache(id, cls) != null;
  }

  /**
   * Returns the window corresponding to the id from the {@link #sWindows}
   * cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            The class of the implementation of the window.
   * @return The window corresponding to the id if it exists in the cache, or
   *         null if it does not.
   */
  public Window getCache(int id, Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      return null;
    }

    return l2.get(id);
  }

  /**
   * Add the window corresponding to the id in the {@link #sWindows} cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            The class of the implementation of the window.
   * @param window
   *            The window to be put in the cache.
   */
  public void putCache(int id, Class<? extends StandOutWindow> cls, Window window) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      l2 = new SparseArray<Window>();
      sWindows.put(cls, l2);
    }

    l2.put(id, window);
  }

  /**
   * Remove the window corresponding to the id from the {@link #sWindows}
   * cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            The class of the implementation of the window.
   */
  public void removeCache(int id, Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 != null) {
      l2.remove(id);
      if (l2.size() == 0) {
        sWindows.remove(cls);
      }
    }
  }

  /**
   * Returns the size of the {@link #sWindows} cache.
   * 
   * @return True if the cache corresponding to this class is empty, false if
   *         it is not empty.
   * @param cls
   *            The class of the implementation of the window.
   */
  public int getCacheSize(Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      return 0;
    }

    return l2.size();
  }

  /**
   * Returns the ids in the {@link #sWindows} cache.
   * 
   * @param cls
   *            The class of the implementation of the window.
   * @return The ids representing the cached windows.
   */
  public Set<Integer> getCacheIds(Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      return new HashSet<Integer>();
    }

    Set<Integer> keys = new HashSet<Integer>();
    for (int i = 0; i < l2.size(); i++) {
      keys.add(l2.keyAt(i));
    }
    return keys;
  }
  
  public int size() {
    return sWindows.size();
  }
}




Java Source Code List

org.sesy.coco.datacollector.ARPWorker.java
org.sesy.coco.datacollector.AlarmService.java
org.sesy.coco.datacollector.AppLauncher.java
org.sesy.coco.datacollector.AudioProc.java
org.sesy.coco.datacollector.AudioWorker.java
org.sesy.coco.datacollector.BindActivity.java
org.sesy.coco.datacollector.BluetoothWorker.java
org.sesy.coco.datacollector.CellWorker.java
org.sesy.coco.datacollector.Constants.java
org.sesy.coco.datacollector.DaemonService.java
org.sesy.coco.datacollector.DataMonitor.java
org.sesy.coco.datacollector.GpsWorker.java
org.sesy.coco.datacollector.HelpActivity.java
org.sesy.coco.datacollector.MainActivity.java
org.sesy.coco.datacollector.MyPreference.java
org.sesy.coco.datacollector.MyWidgetProvider.java
org.sesy.coco.datacollector.PluginManager.java
org.sesy.coco.datacollector.PrefManager.java
org.sesy.coco.datacollector.ReportErrActivity.java
org.sesy.coco.datacollector.SDSetupActivity.java
org.sesy.coco.datacollector.SensorActivity.java
org.sesy.coco.datacollector.SensorListener.java
org.sesy.coco.datacollector.SensordroneWorker.java
org.sesy.coco.datacollector.SettingActivity.java
org.sesy.coco.datacollector.StatusActivity.java
org.sesy.coco.datacollector.StatusManager.java
org.sesy.coco.datacollector.TriggerService.java
org.sesy.coco.datacollector.UpdateWidgetService.java
org.sesy.coco.datacollector.WifiWorker.java
org.sesy.coco.datacollector.WorkerService.java
org.sesy.coco.datacollector.audio.Convolution.java
org.sesy.coco.datacollector.audio.CrossCorrelation.java
org.sesy.coco.datacollector.audio.ExtAudioRecorder.java
org.sesy.coco.datacollector.audio.XCorrAndDistFromWav.java
org.sesy.coco.datacollector.communication.HttpFileUploader.java
org.sesy.coco.datacollector.database.Entry.java
org.sesy.coco.datacollector.file.FileHelper.java
org.sesy.coco.datacollector.log.ConfigureLog4J.java
org.sesy.coco.datacollector.net.NetInfo.java
org.sesy.coco.datacollector.plugin.PlugInterface.java
wei.mark.standout.StandOutWindow.java
wei.mark.standout.Utils.java
wei.mark.standout.WindowCache.java
wei.mark.standout.constants.StandOutFlags.java
wei.mark.standout.ui.TouchInfo.java
wei.mark.standout.ui.Window.java