com.ex.data.Direction.java Source code

Java tutorial

Introduction

Here is the source code for com.ex.data.Direction.java

Source

/*
 * @(#)Direction.java
 * 
 * Copyright (c) 2013 Eugene Simakin <john-24@list.ru>
 *
 * 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 com.ex.data;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.MutablePair;

/**
 * This class represents one of connected directions. You should use Set collection
 * for represents all connected directions (recommended). Direction is an immutable.
 * Notation: <b>ConnId_1 [Begin_Plint : End_Plint] <--> ConnId_2 [Begin_Plint : End_Plint] </b>
 * @author ESimakin <john-24@list.ru>
 *
 */
public final class Direction extends
        MutablePair<ImmutablePair<Long, ImmutablePair<Integer, Integer>>, ImmutablePair<Long, ImmutablePair<Integer, Integer>>> {

    private static final long serialVersionUID = 5661988705153195756L;

    /**
     * Create Direction.
     * @param connIdLeft Id of first Connector
     * @param beginPlintLeft Number of begin Plint in first pair
     * @param endPlintLeft Number of end Plint in first pair
     * @param connIdRight Id of second Connector
     * @param beginPlintRight Number of begin Plint in second pair
     * @param endPlintRight Number of end Plint in second pair
     */
    public Direction(long connIdLeft, int beginPlintLeft, int endPlintLeft, long connIdRight, int beginPlintRight,
            int endPlintRight) {
        super(new ImmutablePair<>(connIdLeft, new ImmutablePair<>(beginPlintLeft, endPlintLeft)),
                new ImmutablePair<>(connIdRight, new ImmutablePair<>(beginPlintRight, endPlintRight)));
    }

    /**
     * Gets unique identifier of left (or first) {@link com.ex.model.Connector Connector}.
     * <b>ConnId_1</b> [Begin_Plint : End_Plint] <--> ConnId_2 [Begin_Plint : End_Plint]
     * @return Unique identifier (id)
     */
    public long getConnectorIdLeft() {
        return this.left.left.longValue();
    }

    /**
     * Gets unique identifier of right (or second) {@link com.ex.model.Connector Connector}.
     * ConnId_1 [Begin_Plint : End_Plint] <--> <b>ConnId_2</b> [Begin_Plint : End_Plint]
     * @return Unique identifier (id)
     */
    public long getConnectorIdRight() {
        return this.right.left.longValue();
    }

    /**
     * Gets begin Plint of left (or first) pair. 
     * ConnId_1 [<b>Begin_Plint</b> : End_Plint] <--> ConnId_2 [Begin_Plint : End_Plint]
     * @return Number of Plint
     */
    public int getBeginPlintLeft() {
        return this.left.right.left.intValue();
    }

    /**
     * Gets begin Plint of right (or second) pair.
     * ConnId_1 [Begin_Plint : End_Plint] <--> ConnId_2 [<b>Begin_Plint</b> : End_Plint]
     * @return Number of Plint
     */
    public int getBeginPlintRight() {
        return this.right.right.left.intValue();
    }

    /**
     * Gets end Plint of left (or first) pair.
     * ConnId_1 [Begin_Plint : <b>End_Plint</b>] <--> ConnId_2 [Begin_Plint : End_Plint]
     * @return Number of Plint
     */
    public int getEndPlintLeft() {
        return this.left.right.right.intValue();
    }

    /**
     * Gets end Plint of right (or second) pair.
     * ConnId_1 [Begin_Plint : End_Plint] <--> ConnId_2 [Begin_Plint : <b>End_Plint</b>]
     * @return Number of Plint
     */
    public int getEndPlintRight() {
        return this.right.right.right.intValue();
    }

    @Override
    public String toString() {
        return this.left.left.toString() + " [ " + this.left.right.left.toString() + " : "
                + this.left.right.right.toString() + " ] <--> " + this.right.left.toString() + " [ "
                + this.right.right.left.toString() + " : " + this.right.right.right.toString() + " ] ";
    }
}