hw1: Make the Queues actually Queues and not stacks
This commit is contained in:
parent
9a0c17edb7
commit
4badbec943
4 changed files with 145 additions and 123 deletions
|
@ -2,26 +2,10 @@
|
|||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b097df70-ddbc-49a8-ab62-9674f3f49e84" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/.idea/compiler.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/.idea/libraries/Maven__junit_junit_4_12.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/IE1.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/pom.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/src/semaphore/MyBulkSemaphore.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../../IE1/src/semaphore/MySemaphore.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/Ex2.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/explicit/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/implicit/ImplicitValetQueue.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/implicit/Main.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../Ex1/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../Ex1/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/semaphore/Car.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/semaphore/Car.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/semaphore/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/semaphore/Main.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/implicit/ImplicitValetQueue.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/implicit/ImplicitValetQueue.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/semaphore/ValetQueue.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/semaphore/ValetQueue.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../submission.tex" beforeDir="false" afterPath="$PROJECT_DIR$/../submission.tex" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -30,19 +14,18 @@
|
|||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="DefaultGradleProjectSettings">
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="delegatedBuild" value="true" />
|
||||
<option name="isMigrated" value="true" />
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf>
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/Car.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="25" column="13" lean-forward="true" selection-start-line="25" selection-start-column="13" selection-end-line="25" selection-end-column="13" />
|
||||
<caret line="25" column="13" selection-start-line="25" selection-start-column="13" selection-end-line="25" selection-end-column="13" />
|
||||
<folding>
|
||||
<element signature="e#502#503#0" expanded="true" />
|
||||
<element signature="e#532#533#0" expanded="true" />
|
||||
<element signature="e#526#527#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -51,8 +34,8 @@
|
|||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/ValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="15" column="32" lean-forward="true" selection-start-line="15" selection-start-column="32" selection-end-line="15" selection-end-column="32" />
|
||||
<state relative-caret-position="135">
|
||||
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -60,8 +43,8 @@
|
|||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/implicit/ImplicitValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="60">
|
||||
<caret line="9" column="13" selection-start-line="9" selection-start-column="13" selection-end-line="9" selection-end-column="13" />
|
||||
<state relative-caret-position="240">
|
||||
<caret line="21" column="9" selection-start-line="21" selection-start-column="9" selection-end-line="21" selection-end-column="9" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -75,11 +58,11 @@
|
|||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/Main.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="13" column="65" selection-start-line="13" selection-start-column="65" selection-end-line="13" selection-end-column="65" />
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="43" selection-start-line="9" selection-start-column="43" selection-end-line="9" selection-end-column="43" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -87,8 +70,8 @@
|
|||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/explicit/Main.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="225">
|
||||
<caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
|
||||
<state relative-caret-position="180">
|
||||
<caret line="15" selection-start-line="15" selection-end-line="15" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -105,11 +88,11 @@
|
|||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="70">
|
||||
<caret line="36" column="62" selection-start-line="36" selection-start-column="62" selection-end-line="36" selection-end-column="62" />
|
||||
<state relative-caret-position="168">
|
||||
<caret line="22" selection-start-line="22" selection-end-line="26" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -133,27 +116,17 @@
|
|||
<list>
|
||||
<option value="$PROJECT_DIR$/src/semaphore/Car.java" />
|
||||
<option value="$PROJECT_DIR$/src/semaphore/ImplicitValetQueue.java" />
|
||||
<option value="$PROJECT_DIR$/src/semaphore/ValetQueue.java" />
|
||||
<option value="$PROJECT_DIR$/src/semaphore/ExplicitValetQueue.java" />
|
||||
<option value="$PROJECT_DIR$/src/semaphore/Main.java" />
|
||||
<option value="$PROJECT_DIR$/src/explicit/Main.java" />
|
||||
<option value="$PROJECT_DIR$/src/implicit/Main.java" />
|
||||
<option value="$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java" />
|
||||
<option value="$PROJECT_DIR$/src/implicit/ImplicitValetQueue.java" />
|
||||
<option value="$PROJECT_DIR$/src/semaphore/ValetQueue.java" />
|
||||
<option value="$PROJECT_DIR$/src/semaphore/Main.java" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectConfigurationFiles">
|
||||
<option name="files">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/.idea/Ex2.iml" />
|
||||
<option value="$PROJECT_DIR$/.idea/misc.xml" />
|
||||
<option value="$PROJECT_DIR$/.idea/vcs.xml" />
|
||||
<option value="$PROJECT_DIR$/.idea/modules.xml" />
|
||||
<option value="$PROJECT_DIR$/.idea/uiDesigner.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds" extendedState="6">
|
||||
<component name="ProjectFrameBounds" fullScreen="true">
|
||||
<option name="width" value="1680" />
|
||||
<option name="height" value="1050" />
|
||||
</component>
|
||||
|
@ -163,8 +136,6 @@
|
|||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="Scope" />
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
|
@ -199,9 +170,12 @@
|
|||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="Scope" />
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="aspect.path.notification.shown" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
|
@ -230,7 +204,7 @@
|
|||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager" selected="Application.Main (1)">
|
||||
<component name="RunManager" selected="Application.Main">
|
||||
<configuration name="Main (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="explicit.Main" />
|
||||
<module name="Ex2" />
|
||||
|
@ -244,6 +218,19 @@
|
|||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Main (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="implicit.Main" />
|
||||
<module name="Ex2" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="implicit.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="semaphore.Main" />
|
||||
<module name="Ex2" />
|
||||
|
@ -259,8 +246,9 @@
|
|||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.Main (1)" />
|
||||
<item itemvalue="Application.Main" />
|
||||
<item itemvalue="Application.Main (2)" />
|
||||
<item itemvalue="Application.Main (1)" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
|
@ -274,57 +262,69 @@
|
|||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1571167105834</updated>
|
||||
<workItem from="1571167107083" duration="2054000" />
|
||||
<workItem from="1571167107083" duration="2304000" />
|
||||
<workItem from="1571299023277" duration="932000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="2054000" />
|
||||
<option name="totallyTimeSpent" value="3236000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="0" y="23" width="1680" height="1027" extended-state="6" />
|
||||
<frame x="0" y="0" width="1680" height="1050" extended-state="6" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Designer" />
|
||||
<window_info id="Image Layers" />
|
||||
<window_info id="Capture Tool" />
|
||||
<window_info id="UI Designer" />
|
||||
<window_info id="Favorites" side_tool="true" />
|
||||
<window_info id="Learn" />
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24969475" />
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25274727" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Terminal" />
|
||||
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Event Log" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Database Changes" />
|
||||
<window_info anchor="bottom" id="Version Control" />
|
||||
<window_info anchor="bottom" id="Messages" />
|
||||
<window_info id="Designer" order="2" />
|
||||
<window_info id="Image Layers" order="3" />
|
||||
<window_info id="Capture Tool" order="4" />
|
||||
<window_info id="UI Designer" order="5" />
|
||||
<window_info id="Favorites" order="6" side_tool="true" />
|
||||
<window_info id="Learn" order="7" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Find" order="1" />
|
||||
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32941177" />
|
||||
<window_info anchor="bottom" id="Run" order="2" weight="0.32857144" />
|
||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
||||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||
<window_info anchor="bottom" id="TODO" order="6" />
|
||||
<window_info anchor="right" id="Maven" />
|
||||
<window_info anchor="right" id="Palette" />
|
||||
<window_info anchor="right" id="Capture Analysis" />
|
||||
<window_info anchor="right" id="Database" />
|
||||
<window_info anchor="right" id="Palette	" />
|
||||
<window_info anchor="right" id="Theme Preview" />
|
||||
<window_info anchor="bottom" id="Terminal" order="7" />
|
||||
<window_info anchor="bottom" id="Docker" order="8" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Messages" order="10" />
|
||||
<window_info anchor="bottom" id="Database Changes" order="11" />
|
||||
<window_info anchor="bottom" id="Version Control" order="12" />
|
||||
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
|
||||
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
|
||||
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
|
||||
<window_info anchor="right" id="Maven" order="3" />
|
||||
<window_info anchor="right" id="Palette" order="4" />
|
||||
<window_info anchor="right" id="Capture Analysis" order="5" />
|
||||
<window_info anchor="right" id="Database" order="6" />
|
||||
<window_info anchor="right" id="Palette	" order="7" />
|
||||
<window_info anchor="right" id="Theme Preview" order="8" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/CarSimulation.java">
|
||||
<entry file="jar:///Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home/lib/src.zip!/java.base/java/util/concurrent/locks/ReentrantLock.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="30">
|
||||
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
|
||||
<state relative-caret-position="200">
|
||||
<caret line="148" column="22" selection-start-line="148" selection-start-column="22" selection-end-line="148" selection-end-column="22" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/Car.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="25" column="13" selection-start-line="25" selection-start-column="13" selection-end-line="25" selection-end-column="13" />
|
||||
<folding>
|
||||
<element signature="e#502#503#0" expanded="true" />
|
||||
<element signature="e#526#527#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -335,35 +335,41 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/Car.java">
|
||||
<entry file="file://$PROJECT_DIR$/src/explicit/Main.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="25" column="13" lean-forward="true" selection-start-line="25" selection-start-column="13" selection-end-line="25" selection-end-column="13" />
|
||||
<state relative-caret-position="180">
|
||||
<caret line="15" selection-start-line="15" selection-end-line="15" />
|
||||
<folding>
|
||||
<element signature="e#502#503#0" expanded="true" />
|
||||
<element signature="e#532#533#0" expanded="true" />
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/Main.java">
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/CarSimulation.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="13" column="65" selection-start-line="13" selection-start-column="65" selection-end-line="13" selection-end-column="65" />
|
||||
<state relative-caret-position="30">
|
||||
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/ValetQueue.java">
|
||||
<entry file="file://$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="15" column="32" lean-forward="true" selection-start-line="15" selection-start-column="32" selection-end-line="15" selection-end-column="32" />
|
||||
<state relative-caret-position="168">
|
||||
<caret line="22" selection-start-line="22" selection-end-line="26" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/implicit/ImplicitValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="60">
|
||||
<caret line="9" column="13" selection-start-line="9" selection-start-column="13" selection-end-line="9" selection-end-column="13" />
|
||||
<state relative-caret-position="240">
|
||||
<caret line="21" column="9" selection-start-line="21" selection-start-column="9" selection-end-line="21" selection-end-column="9" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/ValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -374,27 +380,10 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/explicit/Main.java">
|
||||
<entry file="file://$PROJECT_DIR$/src/semaphore/Main.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="225">
|
||||
<caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="jar:///Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home/lib/src.zip!/java.base/java/util/concurrent/locks/ReentrantLock.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="200">
|
||||
<caret line="148" column="22" selection-start-line="148" selection-start-column="22" selection-end-line="148" selection-end-column="22" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/explicit/ExplicitValetQueue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="70">
|
||||
<caret line="36" column="62" selection-start-line="36" selection-start-column="62" selection-end-line="36" selection-end-column="62" />
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="43" selection-start-line="9" selection-start-column="43" selection-end-line="9" selection-end-column="43" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
|
|
@ -14,11 +14,17 @@ public class ExplicitValetQueue implements Queue<Car> {
|
|||
private final int queueMaxSize;
|
||||
private final ReentrantLock lock;
|
||||
private final Condition full, empty;
|
||||
private int firstFree = 0, firstFull = 0, nElements = 0;
|
||||
|
||||
|
||||
public ExplicitValetQueue(int queueMaxSize) {
|
||||
this.queueMaxSize = queueMaxSize;
|
||||
waitingCars = new ArrayList<>(this.queueMaxSize);
|
||||
|
||||
for (int i = 0; i < queueMaxSize; i++) {
|
||||
waitingCars.add(null);
|
||||
}
|
||||
|
||||
lock = new ReentrantLock();
|
||||
full = lock.newCondition();
|
||||
empty = lock.newCondition();
|
||||
|
@ -28,11 +34,13 @@ public class ExplicitValetQueue implements Queue<Car> {
|
|||
public void put(Car element) throws InterruptedException {
|
||||
lock.lock();
|
||||
try {
|
||||
while (waitingCars.size() >= this.queueMaxSize) {
|
||||
while (nElements == this.queueMaxSize) {
|
||||
full.await();
|
||||
}
|
||||
|
||||
waitingCars.add(element);
|
||||
waitingCars.set(firstFree, element);
|
||||
firstFree = (firstFree + 1) % queueMaxSize;
|
||||
nElements++;
|
||||
System.out.println("Car with plate " + element.getPlate() + " in queue");
|
||||
System.out.println("Now waiting: " + waitingCars);
|
||||
|
||||
|
@ -47,11 +55,15 @@ public class ExplicitValetQueue implements Queue<Car> {
|
|||
final Car c;
|
||||
lock.lock();
|
||||
try {
|
||||
while (waitingCars.isEmpty()) {
|
||||
while (nElements == 0) {
|
||||
empty.await();
|
||||
}
|
||||
|
||||
c = waitingCars.remove(waitingCars.size() - 1);
|
||||
c = waitingCars.get(this.firstFull);
|
||||
waitingCars.set(this.firstFull, null);
|
||||
firstFull = (firstFull + 1) % queueMaxSize;
|
||||
nElements--;
|
||||
|
||||
System.out.println("Car with plate " + c.getPlate() + " will be parked now");
|
||||
System.out.println("Now waiting: " + waitingCars);
|
||||
|
||||
|
|
|
@ -10,19 +10,27 @@ import java.util.concurrent.Semaphore;
|
|||
public class ImplicitValetQueue implements Queue<Car> {
|
||||
private final List<Car> waitingCars;
|
||||
private final int queueMaxSize;
|
||||
private int firstFree = 0, firstFull = 0, nElements = 0;
|
||||
|
||||
|
||||
public ImplicitValetQueue(int queueMaxSize) {
|
||||
this.queueMaxSize = queueMaxSize;
|
||||
waitingCars = new ArrayList<>(this.queueMaxSize);
|
||||
|
||||
for (int i = 0; i < queueMaxSize; i++) {
|
||||
waitingCars.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void put(Car element) throws InterruptedException {
|
||||
while (waitingCars.size() >= queueMaxSize) {
|
||||
while (nElements == queueMaxSize) {
|
||||
wait();
|
||||
}
|
||||
|
||||
waitingCars.add(element);
|
||||
waitingCars.set(firstFree, element);
|
||||
firstFree = (firstFree + 1) % queueMaxSize;
|
||||
nElements++;
|
||||
System.out.println("Car with plate " + element.getPlate() + " in queue");
|
||||
System.out.println("Now waiting: " + waitingCars);
|
||||
notifyAll();
|
||||
|
@ -30,10 +38,14 @@ public class ImplicitValetQueue implements Queue<Car> {
|
|||
|
||||
@Override
|
||||
public synchronized Car take() throws InterruptedException {
|
||||
while (waitingCars.isEmpty()) {
|
||||
while (nElements == 0) {
|
||||
wait();
|
||||
}
|
||||
Car c = waitingCars.remove(waitingCars.size() - 1);
|
||||
final Car c = waitingCars.get(this.firstFull);
|
||||
waitingCars.set(this.firstFull, null);
|
||||
firstFull = (firstFull + 1) % queueMaxSize;
|
||||
nElements--;
|
||||
|
||||
System.out.println("Car with plate " + c.getPlate() + " will be parked now");
|
||||
System.out.println("Now waiting: " + waitingCars);
|
||||
notifyAll();
|
||||
|
|
|
@ -8,10 +8,16 @@ public class ValetQueue implements Queue<Car> {
|
|||
private final List<Car> waitingCars;
|
||||
private final int queueMaxSize;
|
||||
private final Semaphore full, empty, mutex;
|
||||
private int firstFree = 0, firstFull = 0;
|
||||
|
||||
public ValetQueue(int queueMaxSize) {
|
||||
this.queueMaxSize = queueMaxSize;
|
||||
waitingCars = new ArrayList<>(this.queueMaxSize);
|
||||
|
||||
for (int i = 0; i < queueMaxSize; i++) {
|
||||
waitingCars.add(null);
|
||||
}
|
||||
|
||||
empty = new Semaphore (this.queueMaxSize);
|
||||
full = new Semaphore(0);
|
||||
mutex = new Semaphore(1);
|
||||
|
@ -21,7 +27,8 @@ public class ValetQueue implements Queue<Car> {
|
|||
public void put(Car element) throws InterruptedException {
|
||||
empty.acquire();
|
||||
mutex.acquire();
|
||||
waitingCars.add(element);
|
||||
waitingCars.set(firstFree, element);
|
||||
firstFree = (firstFree + 1) % queueMaxSize;
|
||||
System.out.println("Car with plate " + element.getPlate() + " in queue");
|
||||
System.out.println("Now waiting: " + waitingCars);
|
||||
mutex.release();
|
||||
|
@ -33,7 +40,9 @@ public class ValetQueue implements Queue<Car> {
|
|||
final Car c;
|
||||
full.acquire();
|
||||
mutex.acquire();
|
||||
c = waitingCars.remove(waitingCars.size() - 1);
|
||||
c = waitingCars.get(this.firstFull);
|
||||
waitingCars.set(this.firstFull, null);
|
||||
firstFull = (firstFull + 1) % queueMaxSize;
|
||||
System.out.println("Car with plate " + c.getPlate() + " will be parked now");
|
||||
System.out.println("Now waiting: " + waitingCars);
|
||||
mutex.release();
|
||||
|
|
Reference in a new issue