protected function findUnit($unitName, $validUnits = null) {
        $units = $this->getUnits();
        $nunits = count($units);
        for ($i = 0; $i < $nunits; $i++) {
            if (($validUnits != null) && (!array_search($units[$i]['name'], $validUnits) )){
                continue;
            }
            if (($units[$i]['name'] == $unitName) || ($this->aliasMatch($units[$i], $unitName) )){
                return $i;
            }
        }
        throw new \InvalidArgumentException(sprintf('Invalid unit "%s" for type "%s"',$unitName,  $this->getType()));
    }