public class Rotor
extends java.lang.Object
Constructor and Description |
---|
Rotor()
Create a Rotor with default settings starting at position 1
|
Rotor(int pos)
Create a Rotor with default settings starting at position pos
|
Rotor(int pos,
Rotor connection)
Creates a Rotor with default settings starting at position pos with a connection to another Rotor
When the rotor completes a full turn (as specified by fullTurn) it turns the connection
|
Modifier and Type | Method and Description |
---|---|
static Rotor |
createRotor(java.lang.String rotorName,
Rotor connection)
Creates a Rotor with the specified settings
|
static Rotor |
createRotor(java.lang.String from,
java.lang.String to,
Rotor connection,
int[] fullTurn)
Creates a Rotor with the specified settings
|
Rotor |
getConnection() |
int |
getCurrentPos() |
java.lang.String |
getName() |
void |
rotate()
Rotates the rotor and if it rotates a full turn, rotates the next one
|
void |
setConnection(Rotor connection) |
void |
setCurrentPos(char currPos)
Set the current position of the rotor.
|
void |
setCurrentPos(int currPos)
Set the current position of the rotor
|
void |
setName(java.lang.String name) |
java.lang.String |
toString() |
char |
translateLeftToRight(char input)
Translates a character to another (based on the wiring of the rotor)
This simulates a signal coming from the right side of the rotor and exiting from the left side
|
char[] |
translateLeftToRightSteps(char input)
Translates a character to another (based on the wiring of the rotor)
This simulates a signal coming from the right side of the rotor and exiting from the left side
|
char |
translateRightToLeft(char input)
Translates a character to another (based on the wiring of the rotor)
This simulates a signal coming from the left side of the rotor and exiting from the right side
|
char[] |
translateRightToLeftSteps(char input)
Translates a character to another (based on the wiring of the rotor)
This simulates a signal coming from the left side of the rotor and exiting from the right side
|
public Rotor()
public Rotor(int pos)
pos
- has to be an int between 1 and 26 (inclusive)public Rotor(int pos, Rotor connection)
pos
- has to be an int between 1 and 26 (inclusive)connection
- another rotorpublic static Rotor createRotor(java.lang.String from, java.lang.String to, Rotor connection, int[] fullTurn)
from
- from and to specify the wiring. from[i] -> to[i]
to
- both from and to must have length == 26
and both of them must contain all the alphabet in UPPERCASEconnection
- a connection to another rotor. When this rotor completes a full turn it turns the connection. Can be null
fullTurn
- Where is the full turn. If fullTurn is null
, it sets it to the default value of rotor "I"null
if there is an errorpublic static Rotor createRotor(java.lang.String rotorName, Rotor connection)
rotorName
- the name of a default rotor, acceptable names are (source)
connection
- a connection to another rotor. When this rotor completes a full turn it turns connection. Can be null
null
if there is an errorpublic int getCurrentPos()
public void setCurrentPos(int currPos)
currPos
- has to be an int between 1 and 26 (inclusive)public void setCurrentPos(char currPos)
currPos
- current position as a letter. currPos must be a letterpublic Rotor getConnection()
public void setConnection(Rotor connection)
connection
- set the connection (to another Rotor)public void rotate()
public char translateRightToLeft(char input)
input
- the character to translatepublic char translateLeftToRight(char input)
input
- the character to translatepublic char[] translateRightToLeftSteps(char input)
input
- the character to translatechar[lengh - 1] == char[4]
Format of result: input after filtration, input after shift, input after map, input after shift, output
public char[] translateLeftToRightSteps(char input)
input
- the character to translatechar[lengh - 1] == char[4]
Format of result: input after filtration, input after shift, input after map, input after shift, output
public java.lang.String getName()
public void setName(java.lang.String name)
name
- the name to setpublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()