Java tutorial
/* * @(#)PlintDirection.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; import com.ex.model.Connector; /** * This class represents notation <b>Connector Id 1, Plint Number 1 <--> Connector Id 2, Plint Number 2</b> * @author ESimakin <john-24@list.ru> * */ public class PlintDirection extends MutablePair<ImmutablePair<Long, Integer>, ImmutablePair<Long, Integer>> { private static final long serialVersionUID = -357775269872475119L; public PlintDirection() { } /** * Create one of Plint Direction. Left and right pairs will be connected. * @param left Immutable pair that represents notation <b>Connector Id 1, Plint Number 1</b> * @param right Immutable pair that represents notation <b>Connector Id 2, Plint Number 2</b> */ public PlintDirection(ImmutablePair<Long, Integer> left, ImmutablePair<Long, Integer> right) { super(left, right); } /** * Create one of Plint Direction. Left and right pairs will be connected. * @param connectorIdLeft Unique identifier of left Connector * @param plintNumberLeft Plint Number in the left Connector * @param connectorIdRight Unique identifier of right Connector * @param plintNumberRight Plint Number in the right Connector */ public PlintDirection(long connectorIdLeft, int plintNumberLeft, long connectorIdRight, int plintNumberRight) { super(new ImmutablePair<Long, Integer>(connectorIdLeft, plintNumberLeft), new ImmutablePair<Long, Integer>(connectorIdRight, plintNumberRight)); } /** * Create one of Plint Direction. Left and right pairs will be connected. * @param connL Left Connector * @param plintNumberL Plint Number in the left Connector * @param connR Right Connector * @param plintNumberR Plint Number in the right Connector */ public PlintDirection(Connector connL, int plintNumberL, Connector connR, int plintNumberR) { super(new ImmutablePair<Long, Integer>(connL.getId(), plintNumberL), new ImmutablePair<Long, Integer>(connR.getId(), plintNumberR)); if (plintNumberL > connL.getNumberOfPlints().intValue()) { throw new IllegalArgumentException(); } if (plintNumberR > connR.getNumberOfPlints().intValue()) { throw new IllegalArgumentException(); } } /** * Gets unique identifier of left (or first) {@link com.ex.model.Connector Connector}. * @return Left unique identifier (id) */ public long getConnectorIdLeft() { return this.left.left.longValue(); } /** * Gets Plint number at left ImmutablePair. * @return Left Plint number */ public int getPlintNumberLeft() { return this.left.right.intValue(); } /** * Gets unique identifier of right (or second) {@link com.ex.model.Connector Connector}. * @return Right unique identifier (id) */ public long getConnectorIdRight() { return this.right.left.longValue(); } /** * Gets Plint number at right ImmutablePair. * @return Right Plint number */ public int getPlintNumberRight() { return this.right.right.intValue(); } /** * Gets <b>left</b> Immutable Pair of Connector and Plint Number. * @return Immutable pair that represents notation <b>Connector Id 1, Plint Number 1</b> */ public ImmutablePair<Long, Integer> getConnectorPlintPairLeft() { return this.left; } /** * Gets <b>right</b> Immutable Pair of Connector and Plint Number. * @return Immutable pair that represents notation <b>Connector Id 2, Plint Number 2</b> */ public ImmutablePair<Long, Integer> getConnectorPlintPairRight() { return this.right; } /** * Sets <b>left</b> Immutable Pair of Connector and Plint Number. * @param pair Immutable pair that represents notation <b>Connector Id 1, Plint Number 1</b> */ public void setConnectorPlintPairLeft(ImmutablePair<Long, Integer> pair) { this.left = pair; } /** * Sets <b>right</b> Immutable Pair of Connector and Plint Number. * @param pair Immutable pair that represents notation <b>Connector Id 2, Plint Number 2</b> */ public void setConnectorPlintPairRight(ImmutablePair<Long, Integer> pair) { this.right = pair; } @Override public String toString() { return this.left.left.toString() + ", " + this.left.right.toString() + " <--> " + this.right.left.toString() + ", " + this.right.right.toString(); } }