/* Copyright (c) 2005 Stanford University and Christopher Bruns
 * 
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/*
 * Created on Feb 1, 2006
 * Original author: Christopher Bruns
 */
package org.simtk.isimsu;

/**
 *  
  * @author Christopher Bruns
  * 
  * Container for a single ion excess chemical potential and concentration.
  * Meant to be used as one component of many in a particular SaltCondition.
 */
public class IonConcentration 
implements ConstIonType, Comparable<IonConcentration>
{
    private IonSpecies ionSpecies; // Which ion type is this an instance of?
    private float concentration;
    private float excessChemicalPotential;
    private SaltCondition parentSaltCondition;
    
    public IonConcentration(IonSpecies ionSpecies, SaltCondition parentSaltCondition) {
        this.ionSpecies = ionSpecies;
        this.parentSaltCondition = parentSaltCondition;
    }

    public int compareTo(IonConcentration otherConcentration) {
        final int BEFORE = -1;
        final int EQUAL = 0;
        final int AFTER = 1;

        if (this == otherConcentration) return EQUAL;

        // Primary comparison by ion type
        int comparison = this.getIonSpecies().compareTo(otherConcentration.getIonSpecies());
        if ( comparison != EQUAL ) return comparison;    
        
        // Secondary increasing order by concentration
        if (this.getConcentration() < otherConcentration.getConcentration()) return BEFORE;
        if (this.getConcentration() > otherConcentration.getConcentration()) return AFTER;
        
        assert this.equals(otherConcentration) : "compareTo inconsistent with equals.";

        return EQUAL;       
    }
    
    public SaltCondition getParentSaltCondition() {return this.parentSaltCondition;}
    
    public float getConcentration() {return concentration;}
    public void setConcentration(float concentration) {this.concentration = concentration;}

    public float getExcessChemicalPotential() {
        return this.excessChemicalPotential;
    }
    public void setExcessChemicalPotential(float excessChemicalPotential) {
        this.excessChemicalPotential = excessChemicalPotential;
    }

    public IonSpecies getIonSpecies() {return ionSpecies;}
    
    public String getIonId() {return ionSpecies.getIonId();}
    public float getCharge() {return ionSpecies.getCharge();}
    public float getRadius() {return ionSpecies.getRadius();}
    public float getSurfaceWellDepth() {return ionSpecies.getSurfaceWellDepth();}
}
