Java 8 Observable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Observable class.

This code example shows how to use the following methods:getRows, getValues, addObserver
                        new String[] {
                            Settings.System.NAME,
                            Settings.System.VALUE,
                        }, null, null, null); 
 
                final ContentQueryMap cqm = new ContentQueryMap(
                        cursor, Settings.System.NAME, true, null);
                // Get the current state of the CQM. This forces a requery and means that the 
                // call to getValues() below won't do a requery(). 
                cqm.getRows();
                 
                // The cache won't notice changes until the loop runs. 
                Settings.System.putString(r, "test", "New Value");
                ContentValues v = cqm.getValues("test");
                String value = v.getAsString(Settings.System.VALUE);
                assertEquals("Value", value);
 
                // Use an Observer to find out when the cache does update. 
                cqm.addObserver(new Observer() {
                    public void update(Observable o, Object arg) {

6
CodeRank
This code example shows how to use the following methods:deleteObserver
 
    @Override 
    public void onStop() { 
        super.onStop(); 
        if (mSettingsObserver != null) {
            mContentQueryMap.deleteObserver(mSettingsObserver);
        } 
    } 
 
    private PreferenceScreen createPreferenceHierarchy() {
        PreferenceScreen root = getPreferenceScreen();
        if (root != null) {
            root.removeAll();
        } 
        addPreferencesFromResource(R.xml.location_settings); 
        root = getPreferenceScreen();
 
        mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
        mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
        mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
6
CodeRank
This code example shows how to use the following methods:notifyObservers
	} 
	 
	public synchronized void detectChanges() { 
		int latestRevision = getLatestRevision();
		if (lastRevision != latestRevision)
			hiveStatus.notifyObservers();
		lastRevision = latestRevision;
	} 
 
	public void run() { 
		while (true) { 
			try { 
				detectChanges(); 
				lastRun = System.currentTimeMillis();
			} catch (Exception e) {}
 
			try { 
				sleep(getConfiguredSleepPeriodMs());
			} catch (InterruptedException e) {}
		} 
5
CodeRank
This code example shows how to use the following methods:addObserver
    private float minTemp = 200;
    private float tempSum = 0.0f;
    private int numReadings;
 
    public StatisticsDisplay(Observable observable) {
        observable.addObserver(this);
    } 
 
    public void update(Observable observable, Object arg) {
        if (observable instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) observable;
            float temp = weatherData.getTemperature();
            tempSum += temp;
            numReadings++;
 
            if (temp > maxTemp) {
                maxTemp = temp;
            } 
 
            if (temp < minTemp) {
4
CodeRank
This code example shows how to use the following methods:addObserver
	private float minTemp = 200;
	private float tempSum= 0.0f;
	private int numReadings;
 
	public StatisticsDisplay(Observable observable) {
		observable.addObserver(this);
	} 
 
	public void update(Observable observable, Object arg) {
		if (observable instanceof WeatherData) {
			WeatherData weatherData = (WeatherData)observable;
			float temp = weatherData.getTemperature();
			tempSum += temp;
			numReadings++;
 
			if (temp > maxTemp) {
				maxTemp = temp;
			} 
  
			if (temp < minTemp) {
4
CodeRank
This code example shows how to use the following methods:addObserver
    private Observable observable;
 
    public ForecastDisplay(Observable observable)
    { 
	this.observable = observable;
	observable.addObserver(this);
    } 
 
    public void update(Observable obs, Object arg)
    { 
	if (obs instanceof WeatherData) {
	    WeatherData weatherData = (WeatherData)obs;
	    lastPressure = currentPressure;
	    currentPressure = weatherData.getPressure();;
	    display(); 
	} 
    } 
 
    public void display() 
    { 
4
CodeRank
This code example shows how to use the following methods:addObserver
    private float minTemp = 200;
    private float tempSum = 0.0f;
    private int numReadings;
 
    public StatisticsDisplay(Observable observable) {
        observable.addObserver(this);
    } 
 
    public void update(Observable observable, Object arg) {
        if (observable instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) observable;
            float temp = weatherData.getTemperature();
            tempSum += temp;
            numReadings++;
 
            if (temp > maxTemp) {
                maxTemp = temp;
            } 
 
            if (temp < minTemp) {
4
CodeRank
This code example shows how to use the following methods:addObserver
	private double temperature;
	private double humidity;
	 
	public CurrentConditionsDisplay(Observable observable) {
		this.observable = observable;
		observable.addObserver(this);
	} 
	 
	/** 
	 * This is called by notifyObservers 
	 * It is part of the Observer interface 
	 * The implementation determines what will  
	 * happen when the state of the Observable changes. 
	 */ 
	public void update(Observable obs, Object arg) {
		//instanceof ËüµÄ×÷ÓÃÊDzâÊÔËü×ó±ßµÄ¶ÔÏóÊÇ·ñÊÇËüÓұߵÄÀàµÄʵÀý£¬·µ»ØbooleanÀàÐ͵ÄÊý¾Ý 
		if (obs instanceof WeatherData) {
			WeatherData weatherData = (WeatherData)obs;
			this.temperature = weatherData.getTemperature();
			this.humidity = weatherData.getHumidity();
4
CodeRank
This code example shows how to use the following methods:addObserver
    private float humidity;
    Observable observable;
     
    public void registerObserver(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    } 
     
    @Override 
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData){
            WeatherData wd = (WeatherData)o;
            this.temperature = wd.getTemperature();
            this.humidity = wd.getHumidity();
            display(); 
        } 
    } 
 
    @Override 
    public void display() { 
4
CodeRank
This code example shows how to use the following methods:addObserver
    private float humidity;
    private float temperature;
 
    public CurrentConditionsDisplay(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    } 
 
    public void update(Observable observable,Object arg){
        if (observable instanceof WeatherData){
            WeatherData weatherData = (WeatherData)observable;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            display(); 
        } 
    } 
 
    public void display(){ 
        System.out.println("Current conditions: " + temperature);
    } 
4
CodeRank

Related Java 8 Observable Questions & Answers:

See Code Examples for Java 8 Observable Methods: