Package components.sortingmachine
Class SortingMachine3<T>
java.lang.Object
components.sortingmachine.SortingMachineSecondary<T>
components.sortingmachine.SortingMachine3<T>
- Type Parameters:
T- type ofSortingMachineentries
- All Implemented Interfaces:
SortingMachine<T>,SortingMachineKernel<T>,Standard<SortingMachine<T>>,Iterable<T>
SortingMachine represented as a Queue (using an embedding of
insertion 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 IS_SORTED($this.entries, [relation computed by $this.machineOrder.compare method])- Abstraction Relation (interpretation mapping between $this and this):
this = ($this.insertionMode, $this.machineOrder, multiset_entries($this.entries))
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAddsxto the contents ofthis.final voidChanges the mode ofthisfrom insertion to extraction.final voidclear()Resetsthisto an initial value.final booleanReports whetherthisis 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()ReportsComparatorbeing used for sorting bythis.final TRemoves and returns some "first" ("smallest") entry from the contents ofthis.final intsize()Reports the number of entries inthis.final voidtransferFrom(SortingMachine<T> source) Setsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis.Methods inherited from class components.sortingmachine.SortingMachineSecondary
equals, hashCode, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SortingMachine3
Constructor from order.- Parameters:
order- total preorder for sorting
-
-
Method Details
-
newInstance
Description copied from interface:StandardReturns a new object with the same dynamic type asthis, having an initial value. If the typeThas a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT. IfTdoes 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"
thiswith an initial value
-
clear
Description copied from interface:StandardResetsthisto an initial value. If the typeThas a no-argument constructor, thenthissatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thenthissatisfies the contract of the constructor call that was used to initialize#this. -
transferFrom
Description copied from interface:StandardSetsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis. If the typeThas a no-argument constructor, thensourcesatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thensourcesatisfies 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:SortingMachineKernelAddsxto the contents ofthis.- Parameters:
x- the element to be added
-
changeToExtractionMode
Description copied from interface:SortingMachineKernelChanges the mode ofthisfrom insertion to extraction. -
removeFirst
Description copied from interface:SortingMachineKernelRemoves and returns some "first" ("smallest") entry from the contents ofthis.- Returns:
- the entry removed
-
isInInsertionMode
Description copied from interface:SortingMachineKernelReports whetherthisis in insertion mode.- Returns:
- true iff
thisis in insertion mode
-
order
Description copied from interface:SortingMachineKernelReportsComparatorbeing used for sorting bythis.- Returns:
- Comparator used for sorting
-
size
Description copied from interface:SortingMachineKernelReports the number of entries inthis.- Returns:
- the (multiset) size of
this.contents
-
iterator
-