public function merge($map, $file = null)
    {
        $map = MapBuilder::build($map);
        if ($file === null) {
            $file = $map->file;
        }
        $sourceIndex = $this->sources->getIndexByName($file);
        if ($sourceIndex === null) {
            return false;
        }
        $mSources = [];
        $oSources = $map->sources->getNames();
        if (!empty($oSources)) {
            foreach ($oSources as $index => $name) {
                if ($index === 0) {
                    $this->sources->rename($sourceIndex, $name);
                    if ($index !== $sourceIndex) {
                        $mSources[$index] = $sourceIndex;
                    }
                } else {
                    $nIndex = $this->sources->add($name);
                    if ($nIndex !== $index) {
                        $mSources[$index] = $nIndex;
                    }
                }
            }
        }
        $mNames = [];
        foreach ($map->names->getNames() as $index => $name) {
            $nIndex = $this->names->add($name);
            if ($nIndex !== $index) {
                $mNames[$index] = $nIndex;
            }
        }
        $this->context->getMappings()->merge($map->context->getMappings(), $sourceIndex, $mSources, $mNames);
        return true;
    }