<commit_before>/*Copyright (C) 2010-2012 Institute for Software Integrated Systems (ISIS)
This software was developed by the Institute for Software Integrated
Systems (ISIS) at Vanderbilt University, Tennessee, USA for the 
Transformative Apps program under DARPA, Contract # HR011-10-C-0175.
The United States Government has unlimited rights to this software. 
The US government has the right to use, modify, reproduce, release, 
perform, display, or disclose computer software or computer software 
documentation in whole or in part, in any manner and for any 
purpose whatsoever, and to have or authorize others to do so.
 */

package edu.vu.isis.ammo.core.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import edu.vu.isis.ammo.INetPrefKeys;
import edu.vu.isis.ammo.core.R;
import edu.vu.isis.ammo.core.network.NetChannel;

public class ReliableMulticast extends ModelChannel {

    public static String KEY = "ReliableMulticastUiChannel";
    boolean election = false;
    int[] status = null;
    String formalIP = "formal ip";
    String port = "port";

    protected ReliableMulticast(Context context, String name, NetChannel channel) {
        super(context, name);
        this.formalIP = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_HOST,
                INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_HOST);
        this.port = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_PORT,
                String.valueOf(INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_PORT));
        this.election = !this.prefs.getBoolean(INetPrefKeys.RELIABLE_MULTICAST_DISABLED,
                INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_ENABLED);

        mNetChannel = channel;
    }

    private static ReliableMulticast instance = null;

    public static ReliableMulticast getInstance(Context context, NetChannel channel)
    {
        if (instance == null)
            instance = new ReliableMulticast(context, "ReliableMulticast Channel", channel);
        return instance;
    }
    public static ReliableMulticast getMediaInstance(Context context, NetChannel channel) {
      // initialize the gateway media from the shared preferences
      return new ReliableMulticast(context, "Reliable Multicast Media Channel", channel);
    }    

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
        if (key.equals(INetPrefKeys.RELIABLE_MULTICAST_HOST)) {
            this.formalIP = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_HOST,
                    INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_HOST);
            callOnNameChange();
        } else if (key.equals(INetPrefKeys.RELIABLE_MULTICAST_PORT)) {
            this.port = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_PORT,
                    String.valueOf(INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_PORT));
            callOnNameChange();
        }
    }

    @Override
    public void enable() {
        this.setElection(true);
    }

    @Override
    public void disable() {
        this.setElection(false);
    }

    @Override
    public void toggle() {
        this.setElection(!this.election);
    }

    // FIXME : Should this view only user interface be writing this value?
    private void setElection(boolean b)
    {
        this.election = b;
        Editor editor = this.prefs.edit();
        editor.putBoolean(INetPrefKeys.RELIABLE_MULTICAST_DISABLED, !this.election);
        editor.commit();
    }

    @Override
    public boolean isEnabled() {
        return this.election;
    }

    @Override
    public View getView(View row, LayoutInflater inflater) {

        row = inflater.inflate(edu.vu.isis.ammo.core.R.layout.reliable_multicast_item, null);

        TextView formal = (TextView) row.findViewById(R.id.reliable_multicast_formal);
        TextView name = (TextView) row.findViewById(R.id.reliable_multicast_name);
        ((TextView) row.findViewById(R.id.channel_type)).setText(ReliableMulticast.KEY);

        name.setText(this.name);
        formal.setText(this.formalIP + ":" + this.port);
        // set vals
        return row;
    }

    @Override
    public int[] getStatus() {
        return this.status;
    }

    @Override
    public void setStatus(int[] statusCode) {
        this.status = statusCode;
    }
}<commit_msg>Fixed ui display for ReliableMulticastMedia channel<commit_after>/*Copyright (C) 2010-2012 Institute for Software Integrated Systems (ISIS)
This software was developed by the Institute for Software Integrated
Systems (ISIS) at Vanderbilt University, Tennessee, USA for the 
Transformative Apps program under DARPA, Contract # HR011-10-C-0175.
The United States Government has unlimited rights to this software. 
The US government has the right to use, modify, reproduce, release, 
perform, display, or disclose computer software or computer software 
documentation in whole or in part, in any manner and for any 
purpose whatsoever, and to have or authorize others to do so.
 */

package edu.vu.isis.ammo.core.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import edu.vu.isis.ammo.INetPrefKeys;
import edu.vu.isis.ammo.core.R;
import edu.vu.isis.ammo.core.network.NetChannel;

public class ReliableMulticast extends ModelChannel {

    public static String KEY = "ReliableMulticastUiChannel";
    boolean election = false;
    int[] status = null;
    String formalIP = "formal ip";
    String port = "port";
    private boolean isMediaChannel = false;
    private String media_port;

    public boolean isMediaChannel() {
      return isMediaChannel;
    }
    public void setMediaChannel(boolean isMediaChannel) {
      this.isMediaChannel = isMediaChannel;
    }
    
    protected ReliableMulticast(Context context, String name, NetChannel channel) {
        super(context, name);
        this.formalIP = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_HOST,
                INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_HOST);
        this.port = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_PORT,
                String.valueOf(INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_PORT));
        this.media_port = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_MEDIA_PORT,
                String.valueOf(INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_MEDIA_PORT));
        this.election = !this.prefs.getBoolean(INetPrefKeys.RELIABLE_MULTICAST_DISABLED,
                INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_ENABLED);

        mNetChannel = channel;
    }

    private static ReliableMulticast instance = null;

    public static ReliableMulticast getInstance(Context context, NetChannel channel)
    {
        if (instance == null)
            instance = new ReliableMulticast(context, "ReliableMulticast Channel", channel);
        return instance;
    }
    public static ReliableMulticast getMediaInstance(Context context, NetChannel channel) {
      // turn on the media channel flag 
      // initialize the gateway media from the shared preferences
      
      ReliableMulticast rm = new ReliableMulticast(context, "Reliable Multicast Media Channel", channel);
      rm.setMediaChannel(true);
      return rm;
    }    

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
        if (key.equals(INetPrefKeys.RELIABLE_MULTICAST_HOST)) {
            this.formalIP = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_HOST,
                    INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_HOST);
            callOnNameChange();
        } else if (key.equals(INetPrefKeys.RELIABLE_MULTICAST_PORT)) {
            this.port = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_PORT,
                    String.valueOf(INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_PORT));
            callOnNameChange();
        } else if (key.equals(INetPrefKeys.RELIABLE_MULTICAST_MEDIA_PORT)) {
            this.media_port = this.prefs.getString(INetPrefKeys.RELIABLE_MULTICAST_MEDIA_PORT,
                String.valueOf(INetPrefKeys.DEFAULT_RELIABLE_MULTICAST_MEDIA_PORT));
            callOnNameChange();
        }
    }

    @Override
    public void enable() {
        this.setElection(true);
    }

    @Override
    public void disable() {
        this.setElection(false);
    }

    @Override
    public void toggle() {
        this.setElection(!this.election);
    }

    // FIXME : Should this view only user interface be writing this value?
    private void setElection(boolean b)
    {
        this.election = b;
        Editor editor = this.prefs.edit();
        editor.putBoolean(INetPrefKeys.RELIABLE_MULTICAST_DISABLED, !this.election);
        editor.commit();
    }

    @Override
    public boolean isEnabled() {
        return this.election;
    }

    @Override
    public View getView(View row, LayoutInflater inflater) {

        row = inflater.inflate(edu.vu.isis.ammo.core.R.layout.reliable_multicast_item, null);

        TextView formal = (TextView) row.findViewById(R.id.reliable_multicast_formal);
        TextView name = (TextView) row.findViewById(R.id.reliable_multicast_name);
        ((TextView) row.findViewById(R.id.channel_type)).setText(ReliableMulticast.KEY);

        name.setText(this.name);
        
        if (isMediaChannel) 
          formal.setText(this.formalIP + ":" + this.media_port);
        else 
          formal.setText(this.formalIP + ":" + this.port);
        // set vals
        return row;
    }

    @Override
    public int[] getStatus() {
        return this.status;
    }

    @Override
    public void setStatus(int[] statusCode) {
        this.status = statusCode;
    }
}
{'fraction_non_alphanumeric': 0.08385343265552647, 'fraction_numerical': 0.0034225890879806724, 'mean_word_length': 3.1482254697286014, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7591717', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2834, 'n_words': 650}