Android Open Source - YourWiFi Network Cache






From Project

Back to project page YourWiFi.

License

The source code is released under:

MIT License

If you think the Android project YourWiFi 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 com.akisute.yourwifi.app.model;
/* ww  w.  j a v  a  2 s.c  o m*/
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering;

import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class NetworkCache {

    // Key = BssId
    private final Cache<String, Network> mNetworks = CacheBuilder.newBuilder()
            .expireAfterWrite(30, TimeUnit.SECONDS)
            .build();

    public void put(Network network) {
        if (network != null) {
            mNetworks.put(network.getBssid(), network);
        }
    }

    public void clear() {
        mNetworks.invalidateAll();
    }

    public int getNetworkCount() {
        return (int) mNetworks.size();
    }

    public Network getNetwork(String bssid) {
        return mNetworks.asMap().get(bssid);
    }

    public List<Network> getAllNetworkList() {
        return getAllNetworkList(NetworkComparators.DEFAULT);
    }

    public List<Network> getAllNetworkList(Comparator<Network> comparator) {
        return Ordering.from(comparator).sortedCopy(mNetworks.asMap().values());
    }

    public int getEssidCount() {
        Map<String, Essid> essidMap = getEssidMap();
        return essidMap.size();
    }

    public Essid getEssid(String ssid) {
        Map<String, Essid> essidMap = getEssidMap();
        return essidMap.get(ssid);
    }

    public List<Essid> getAllEssidList() {
        return getAllEssidList(EssidComparators.DEFAULT);
    }

    public List<Essid> getAllEssidList(Comparator<Essid> comparator) {
        Map<String, Essid> essidMap = getEssidMap();
        return Ordering.from(comparator).sortedCopy(essidMap.values());
    }

    private Map<String, Essid> getEssidMap() {
        Multimap<String, Network> multimap = HashMultimap.create((int) mNetworks.size(), (int) mNetworks.size() / 2);
        for (Network network : mNetworks.asMap().values()) {
            multimap.put(network.getSsid(), network);
        }
        Map<String, Essid> resultMap = new HashMap<String, Essid>(multimap.keySet().size());
        for (Map.Entry<String, Collection<Network>> entry : multimap.asMap().entrySet()) {
            Essid essid = Essid.newInstance(entry.getValue());
            resultMap.put(entry.getKey(), essid);
        }
        return resultMap;
    }
}




Java Source Code List

com.akisute.yourwifi.app.Application.java
com.akisute.yourwifi.app.CloudLoginDialogFragment.java
com.akisute.yourwifi.app.EssidDetailActivity.java
com.akisute.yourwifi.app.EssidDetailFragment.java
com.akisute.yourwifi.app.EssidListFragment.java
com.akisute.yourwifi.app.MainActivity.java
com.akisute.yourwifi.app.NetworkMapFragment.java
com.akisute.yourwifi.app.NetworkRecordingService.java
com.akisute.yourwifi.app.RawNetworkListFragment.java
com.akisute.yourwifi.app.SettingsActivity.java
com.akisute.yourwifi.app.SettingsFragment.java
com.akisute.yourwifi.app.cloud.CloudManager.java
com.akisute.yourwifi.app.dagger.AndroidSystemModule.java
com.akisute.yourwifi.app.dagger.ApplicationModule.java
com.akisute.yourwifi.app.intent.Intents.java
com.akisute.yourwifi.app.model.BssidListAdapter.java
com.akisute.yourwifi.app.model.EssidComparators.java
com.akisute.yourwifi.app.model.EssidListAdapter.java
com.akisute.yourwifi.app.model.Essid.java
com.akisute.yourwifi.app.model.LocationScanManager.java
com.akisute.yourwifi.app.model.NetworkCache.java
com.akisute.yourwifi.app.model.NetworkComparators.java
com.akisute.yourwifi.app.model.NetworkScanManager.java
com.akisute.yourwifi.app.model.Network.java
com.akisute.yourwifi.app.model.RawNetworkListAdapter.java
com.akisute.yourwifi.app.util.GlobalEventBus.java
com.akisute.yourwifi.app.util.GlobalResources.java
com.akisute.yourwifi.app.util.GlobalSharedPreferences.java