package org.pfaa.chemica.model;

public class IndustrialMaterialUtils {

	public static Condition getCanonicalCondition(IndustrialMaterial material, State state) {
		Integer temp = getCanonicalTemperature(material, state);
		if (temp == null) {
			return null;
		}
		return new Condition(temp, Constants.STANDARD_PRESSURE);
	}

	private static Integer getCanonicalTemperature(IndustrialMaterial material, State state) {
		switch(state) {
		case SOLID:
			if (material instanceof Fusible) {
				Fusion fusion = ((Fusible)material).getFusion();
				if (fusion != null) {
					return Math.min(fusion.getTemperature() - 1, Constants.STANDARD_TEMPERATURE);
				}
			}
			if (material instanceof Vaporizable) {
				Vaporization vaporization = ((Vaporizable)material).getVaporization();
				if (vaporization != null) {
					return Math.min(vaporization.getTemperature() - 1, Constants.STANDARD_TEMPERATURE);
				}
			}
			break;
		case LIQUID:
			if (material instanceof Fusible) {
				Fusion fusion = ((Fusible)material).getFusion();
				if (fusion != null) {
					return Math.max(fusion.getTemperature(), Constants.STANDARD_TEMPERATURE);
				} else {
					return null;
				}
			}
			break;
		case GAS:
			if (material instanceof Vaporizable) {
				Vaporization vaporization = ((Vaporizable)material).getVaporization();
				if (vaporization != null) {
					return Math.max(vaporization.getTemperature(), Constants.STANDARD_TEMPERATURE);
				} else {
					return null;
				}
			}
			break;
		default:
		}
		return Constants.STANDARD_TEMPERATURE;
	}

}

@@ -1013,32 +1013,327 @@
 l).getFusion();%0A
+%09%09%09%09int lowerBound = Constants.STANDARD_TEMPERATURE;%0A%09%09%09%09if (material instanceof Vaporizable) %7B%0A%09%09%09%09%09Vaporization vaporization = ((Vaporizable) material).getVaporization();%0A%09%09%09%09%09if (vaporization != null) %7B%0A%09%09%09%09%09%09lowerBound = Math.min(lowerBound, vaporization.getTemperature() - 1);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A
 %09%09%09%09if (fusion !
@@ -1392,38 +1392,18 @@
 (), 
-Constants.STANDARD_TEMPERATURE
+lowerBound
 );%0A%09

support liquid condition for room temp gases