APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.org.jline.reader.impl

public final Class KillRing

extends Object
Class Inheritance

The kill ring class keeps killed text in a fixed size ring. In this class we also keep record of whether or not the last command was a kill or a yank. Depending on this, the class may behave different. For instance, two consecutive kill-word commands fill the same slot such that the next yank will return the two previously killed words instead that only the last one. Likewise yank pop requires that the previous command was either a yank or a yank-pop.

Field Summary

Modifier and TypeField and Description
private static final int
DEFAULT_SIZE

Default size is 60, like in emacs.

private int
private boolean
private boolean
private final String[]

Constructor Summary

AccessConstructor and Description
public
KillRing(int
the size of the ring
size
)

Creates a new kill ring of the given size.

public
KillRing()

Creates a new kill ring of the default size.

Method Summary

Modifier and TypeMethod and Description
public void
add(String
the string to add
str
)

Adds the string to the kill-ring.

public void
addBackwards(String
the string to add
str
)

Adds the string to the kill-ring product of killing backwards.

public boolean

Returns:

true if the last command was a yank
lastYank
()

Returns true if the last command was a yank.

private void
next()

Moves the pointer to the current slot forward.

private void
prev()

Moves the pointer to the current slot backwards.

public void
resetLastKill()

Resets the last-kill state.

public void
resetLastYank()

Resets the last-yank state.

public String

Returns:

the text in the current position
yank
()

Yanks a previously killed text.

public String

Returns:

the text in the previous position
yankPop
()

Moves the pointer to the current slot back and returns the text in that position.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SIZEback to summary
private static final int DEFAULT_SIZE

Default size is 60, like in emacs.

lastKillback to summary
private boolean lastKill
lastYankback to summary
private boolean lastYank
slotsback to summary
private final String[] slots

Constructor Detail

KillRingback to summary
public KillRing(int size)

Creates a new kill ring of the given size.

Parameters
size:int

the size of the ring

KillRingback to summary
public KillRing()

Creates a new kill ring of the default size. See DEFAULT_SIZE.

Method Detail

addback to summary
public void add(String str)

Adds the string to the kill-ring. Also sets lastYank to false and lastKill to true.

Parameters
str:String

the string to add

addBackwardsback to summary
public void addBackwards(String str)

Adds the string to the kill-ring product of killing backwards. If the previous command was a kill text one then adds the text at the beginning of the previous kill to avoid that two consecutive backwards kills followed by a yank leaves things reversed.

Parameters
str:String

the string to add

lastYankback to summary
public boolean lastYank()

Returns true if the last command was a yank.

Returns:boolean

true if the last command was a yank

nextback to summary
private void next()

Moves the pointer to the current slot forward. If the end of the slots is reached then points back to the beginning.

prevback to summary
private void prev()

Moves the pointer to the current slot backwards. If the beginning of the slots is reached then traverses the slot backwards until one with not null content is found.

resetLastKillback to summary
public void resetLastKill()

Resets the last-kill state.

resetLastYankback to summary
public void resetLastYank()

Resets the last-yank state.

yankback to summary
public String yank()

Yanks a previously killed text. Returns null if the ring is empty.

Returns:String

the text in the current position

yankPopback to summary
public String yankPop()

Moves the pointer to the current slot back and returns the text in that position. If the previous command was not yank returns null.

Returns:String

the text in the previous position