Package components.sortingmachine
Class SortingMachine1L<T>
java.lang.Object
components.sortingmachine.SortingMachineSecondary<T>
components.sortingmachine.SortingMachine1L<T>
- Type Parameters:
T
- type ofSortingMachine
entries
- All Implemented Interfaces:
SortingMachine<T>
,SortingMachineKernel<T>
,Standard<SortingMachine<T>>
,Iterable<T>
SortingMachine
represented as java.util.List
(using an embedding of java.util.Collections.sort
), with implementations of primary methods.- Mathematical Definitions:
IS_TOTAL_PREORDER ( r: binary relation on T ) : boolean is for all x, y, z: T ((r(x, y) or r(y, x)) and (if (r(x, y) and r(y, z)) then r(x, z))) IS_SORTED ( s: string of T, r: binary relation on T ) : boolean is for all x, y: T where (<x, y> is substring of s) (r(x, y))
- Representation Invariant (concrete invariant of $this):
IS_TOTAL_PREORDER([relation computed by $this.machineOrder.compare method]) and if not $this.insertionMode then IS_SORTED($this.entries, [relation computed by $this.machineOrder.compare method])
- Abstraction Relation (interpretation mapping between $this and this):
this = ($this.insertionMode, $this.machineOrder, [value of $this.entries])
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Addsx
to the contents ofthis
.final void
Changes the mode ofthis
from insertion to extraction.final void
clear()
Resetsthis
to an initial value.final boolean
Reports whetherthis
is in insertion mode.iterator()
final SortingMachine<T>
Returns a new object with the same dynamic type asthis
, having an initial value.final Comparator<T>
order()
ReportsComparator
being used for sorting bythis
.final T
Removes and returns some "first" ("smallest") entry from the contents ofthis
.final int
size()
Reports the number of entries inthis
.final void
transferFrom
(SortingMachine<T> source) Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
.Methods inherited from class components.sortingmachine.SortingMachineSecondary
equals, hashCode, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SortingMachine1L
Constructor from order.- Parameters:
order
- total preorder for sorting
-
-
Method Details
-
newInstance
Description copied from interface:Standard
Returns a new object with the same dynamic type asthis
, having an initial value. If the typeT
has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initializethis
.- Returns:
- new object "like"
this
with an initial value
-
clear
Description copied from interface:Standard
Resetsthis
to an initial value. If the typeT
has a no-argument constructor, thenthis
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thenthis
satisfies the contract of the constructor call that was used to initialize#this
. -
transferFrom
Description copied from interface:Standard
Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
. If the typeT
has a no-argument constructor, thensource
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thensource
satisfies the contract of the constructor call that was used to initialize#source
.- Parameters:
source
- object whose value is to be transferred
-
add
Description copied from interface:SortingMachineKernel
Addsx
to the contents ofthis
.- Parameters:
x
- the element to be added
-
changeToExtractionMode
Description copied from interface:SortingMachineKernel
Changes the mode ofthis
from insertion to extraction. -
removeFirst
Description copied from interface:SortingMachineKernel
Removes and returns some "first" ("smallest") entry from the contents ofthis
.- Returns:
- the entry removed
-
isInInsertionMode
Description copied from interface:SortingMachineKernel
Reports whetherthis
is in insertion mode.- Returns:
- true iff
this
is in insertion mode
-
order
Description copied from interface:SortingMachineKernel
ReportsComparator
being used for sorting bythis
.- Returns:
- Comparator used for sorting
-
size
Description copied from interface:SortingMachineKernel
Reports the number of entries inthis
.- Returns:
- the (multiset) size of
this.contents
-
iterator
-