package org.matheclipse.core.generic;

import org.matheclipse.core.expression.F;
import org.matheclipse.core.generic.interfaces.IPositionConverter;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.core.interfaces.IInteger;

public class PositionConverter implements IPositionConverter{
	public IExpr toObject(final int i) {
		if (i < 3) {
			switch (i) {
			case 0:
				return F.C0;
			case 1:
				return F.C1;
			case 2:
				return F.C2;
			}
		}
		return F.integer(i);
	}

	public int toInt(final IExpr position) {
		if (position instanceof IInteger) {
			return ((IInteger)position).toInt();
		}
		return -1;
	}
}

 

Ads help maintain this website.