// Path: library/src/main/java/no/agens/cassowarylayout/util/DimensionParser.java
// public class DimensionParser {
// 
//     private static Pattern pattern = Pattern.compile("^(wrapContent|matchParent)|(\\d+)(px|dp|sp|pt|in|mm)");
// 
//     public static Double getDimension(String widthHeightString, Context context) {
// 
//         Double widthHeight = null;
// 
//         Matcher matcher = pattern.matcher(widthHeightString);
// 
//         matcher.find();
// 
//         if (matcher.matches()) {
//             if  (matcher.group(2) == null) {
//                 widthHeight = (double)RelativeLayout.LayoutParams.MATCH_PARENT;
//                 if ("wrapContent".equals(matcher.group(1))) {
//                     widthHeight = (double)RelativeLayout.LayoutParams.WRAP_CONTENT;
//                 }
//             } else {
//                 String value = matcher.group(2);
//                 String unit = matcher.group(3);
//                 try {
//                     widthHeight = (double)TypedValue.applyDimension(getUnitFromString(unit), Integer.parseInt(value), context.getResources().getDisplayMetrics());
//                     //widthHeight = Integer.parseInt(widthHeightString.substring(0, widthHeightString.));
//                 } catch (NumberFormatException e) {
//                     // ignore
//                 }
//             }
//         }
// 
//         return widthHeight;
// 
//     }
// 
//     private static int getUnitFromString(String unitString) {
// 
//         int unit = TypedValue.COMPLEX_UNIT_DIP;
//         if ("px".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_PX;
//         } else if ("dp".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_DIP;
//         } else if ("sp".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_SP;
//         } else if ("pt".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_PT;
//         } else if ("in".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_IN;
//         } else if ("mm".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_MM;
//         }
//         return unit;
//     }
// }
// 
// Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java
// public class TimerUtil {
//     public static long since(long since) {
//         return (System.nanoTime() - since) / 1000000;
//     }
// }


import android.content.Context;
import android.util.Log;
import org.pybee.cassowary.Constraint;
import org.pybee.cassowary.ConstraintNotFound;
import org.pybee.cassowary.Expression;
import org.pybee.cassowary.SimplexSolver;
import org.pybee.cassowary.Variable;
import java.util.HashMap;
import no.agens.cassowarylayout.util.DimensionParser;
import no.agens.cassowarylayout.util.TimerUtil;
package no.agens.cassowarylayout;





/**
 * Created by alex on 01/11/14.
 */
public class CassowaryModel {

    private Context context;

    private static final String LOG_TAG = "CassowaryModel";

    public CassowaryModel(Context context) {
        this.context = context;
        setupCassowary();
    }

    private HashMap<String, ChildNode> nodes = new HashMap<String, ChildNode>();

    private SimplexSolver solver = new SimplexSolver();

    private ContainerNode containerNode = new ContainerNode(solver);

    private ConstraintParser.CassowaryVariableResolver cassowaryVariableResolver = new ConstraintParser.CassowaryVariableResolver() {
        @Override
        public Variable resolveVariable(String variableName) {
            return CassowaryModel.this.resolveVariable(variableName);
        }

        @Override
        public Expression resolveConstant(String constantName) {

            Expression expression = null;
            Double value;

            try {
                value = Double.parseDouble(constantName);
            } catch (NumberFormatException e) {
// Path: library/src/main/java/no/agens/cassowarylayout/util/DimensionParser.java
// public class DimensionParser {
// 
//     private static Pattern pattern = Pattern.compile("^(wrapContent|matchParent)|(\\d+)(px|dp|sp|pt|in|mm)");
// 
//     public static Double getDimension(String widthHeightString, Context context) {
// 
//         Double widthHeight = null;
// 
//         Matcher matcher = pattern.matcher(widthHeightString);
// 
//         matcher.find();
// 
//         if (matcher.matches()) {
//             if  (matcher.group(2) == null) {
//                 widthHeight = (double)RelativeLayout.LayoutParams.MATCH_PARENT;
//                 if ("wrapContent".equals(matcher.group(1))) {
//                     widthHeight = (double)RelativeLayout.LayoutParams.WRAP_CONTENT;
//                 }
//             } else {
//                 String value = matcher.group(2);
//                 String unit = matcher.group(3);
//                 try {
//                     widthHeight = (double)TypedValue.applyDimension(getUnitFromString(unit), Integer.parseInt(value), context.getResources().getDisplayMetrics());
//                     //widthHeight = Integer.parseInt(widthHeightString.substring(0, widthHeightString.));
//                 } catch (NumberFormatException e) {
//                     // ignore
//                 }
//             }
//         }
// 
//         return widthHeight;
// 
//     }
// 
//     private static int getUnitFromString(String unitString) {
// 
//         int unit = TypedValue.COMPLEX_UNIT_DIP;
//         if ("px".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_PX;
//         } else if ("dp".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_DIP;
//         } else if ("sp".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_SP;
//         } else if ("pt".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_PT;
//         } else if ("in".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_IN;
//         } else if ("mm".equals(unitString)) {
//             unit = TypedValue.COMPLEX_UNIT_MM;
//         }
//         return unit;
//     }
// }
// 
// Path: library/src/main/java/no/agens/cassowarylayout/util/TimerUtil.java
// public class TimerUtil {
//     public static long since(long since) {
//         return (System.nanoTime() - since) / 1000000;
//     }
// }


// Path: library/src/main/java/no/agens/cassowarylayout/CassowaryModel.java
import android.content.Context;
import android.util.Log;
import org.pybee.cassowary.Constraint;
import org.pybee.cassowary.ConstraintNotFound;
import org.pybee.cassowary.Expression;
import org.pybee.cassowary.SimplexSolver;
import org.pybee.cassowary.Variable;
import java.util.HashMap;
import no.agens.cassowarylayout.util.DimensionParser;
import no.agens.cassowarylayout.util.TimerUtil;

package no.agens.cassowarylayout;





/**
 * Created by alex on 01/11/14.
 */
public class CassowaryModel {

    private Context context;

    private static final String LOG_TAG = "CassowaryModel";

    public CassowaryModel(Context context) {
        this.context = context;
        setupCassowary();
    }

    private HashMap<String, ChildNode> nodes = new HashMap<String, ChildNode>();

    private SimplexSolver solver = new SimplexSolver();

    private ContainerNode containerNode = new ContainerNode(solver);

    private ConstraintParser.CassowaryVariableResolver cassowaryVariableResolver = new ConstraintParser.CassowaryVariableResolver() {
        @Override
        public Variable resolveVariable(String variableName) {
            return CassowaryModel.this.resolveVariable(variableName);
        }

        @Override
        public Expression resolveConstant(String constantName) {

            Expression expression = null;
            Double value;

            try {
                value = Double.parseDouble(constantName);
            } catch (NumberFormatException e) {
                value = DimensionParser.getDimension(constantName, getContext());