/*
 * Copyright 2012 s_wolff.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.aegee.runanddine.pathfinder.optimizers;

import org.aegee.runanddine.pathfinder.OptGroup;

/**
 * Class for wrapping
 * <code>OptGroup</code>s. This wrapper is used to map
 * <code>AbstractGroup</code>s to
 * <code>OptGroup</code>s due to this class offers a more convenient way of
 * defining the relation between abstract groups and opt groups. It allows to
 * use permutations as the ids of
 * <code>OptGroupWrapper</code> objects can be chosen freely whereas
 * <code>OptGroup</code> ids reflect only an database id.
 *
 * @author s_wolff
 */
public class OptGroupWrapper {

    private OptGroup wrappedOptGroup;
    private int id;
    private int abstractGroupMapping;

    /**
     * Create an unbound
     * <code>OptGroupWrapper</code> that still have to be mapped to an abstract
     * group. Note that the passed id will not be validated.
     *
     * @param wrappedOptGroup the
     * <code>OptGroup</code> that is wrapped
     * @param id id of the new
     * <code>OptGroupWrapper</code> object
     */
    public OptGroupWrapper(OptGroup wrappedOptGroup, int id) {
        this.wrappedOptGroup = wrappedOptGroup;
        this.id = id;
    }

    /**
     * Creates a bound object with an initial mapping between
     * <code>OptGroup</code> and
     * <code>AbstractGroup</code> via ids.
     *
     * @param wrappedOptGroup the
     * <code>OptGroup</code> that is wrapped
     * @param id id of the new
     * @param abstractGroupMapping id of a
     * <code>AbstractGroup</code> that is represented by the new object
     */
    public OptGroupWrapper(OptGroup wrappedOptGroup, int id, int abstractGroupMapping) {
        this.wrappedOptGroup = wrappedOptGroup;
        this.id = id;
        this.abstractGroupMapping = abstractGroupMapping;
    }

    /**
     * Provides the id of this opt group wrapper. Note that this is not the id
     * of the
     * <code>OptGroup</code> that is represented by this object. It is an id
     * that allows mapping abstract groups to opt groups by applying a
     * permutation of ids.
     *
     * @return id of this object
     */
    public int getId() {
        return this.id;
    }

    /**
     * Provides the id of the abstract group that is represented by the wrapped
     * opt group. Id est this method returns the id of an abstract group that is
     * mapped to the
     * <code>getId()</code> value of this object.
     *
     * @return the id of an abstract group represented by this object
     */
    public int getAbstractGroupMapping() {
        return abstractGroupMapping;
    }

    /**
     * Sets the id of an abstract group that will be represented by this object.
     * In other words this sets a mapping from the provided parameter to the
     * <code>getId()</code> value of this object.
     *
     * @param abstractGroupMapping an abstract group id
     */
    public void setAbstractGroupMapping(int abstractGroupMapping) {
        this.abstractGroupMapping = abstractGroupMapping;
    }

    /**
     * Provides the
     * <code>OptGroup</code> that is wrapped by this object.
     *
     * @return wrapped
     * <code>OptGroup</code> reference
     */
    public OptGroup getWrappedOptGroup() {
        return wrappedOptGroup;
    }
}
