Skip to content

Commit

Permalink
c# Petrol pump - everything but the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
iCodeIT committed Dec 17, 2014
1 parent efaf451 commit f533479
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 45 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
1 change: 1 addition & 0 deletions c#/Book/PetrolPump/PetrolPump/PetrolPump/PetrolPump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Chapter3\Section8\Keypad.cs" />
<Compile Include="Chapter3\Section8\KeypadPump.cs" />
<Compile Include="Pump\Delivery.cs" />
<Compile Include="Pump\FillState.cs" />
<Compile Include="Pump\Formatters.cs" />
<Compile Include="Pump\Fuel.cs" />
<Compile Include="Pump\Inputs.cs" />
Expand Down
28 changes: 28 additions & 0 deletions c#/Book/PetrolPump/PetrolPump/PetrolPump/Pump/FillState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace PetrolPump.Pump
{
public class FillState
{
public enum Type
{
IDLE,
FILLING,
SALE_COMPLETE
}

public FillState(Type mode)
{
this.Mode = mode;
this.Sale = null;
}

public FillState(Type mode, Sale sale)
{
this.Mode = mode;
this.Sale = sale;
}

public readonly Type Mode;
public readonly Sale Sale;
}

}
86 changes: 43 additions & 43 deletions c#/Sodium/Sodium.sln
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sodium", "Sodium.csproj", "{D2080704-D359-4743-B568-5D976F9882A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "..\Tests\Tests.csproj", "{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Release|Any CPU.Build.0 = Release|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Sodium.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.FileWidth = 120
$1.TabWidth = 4
$1.IndentWidth = 2
$1.inheritsSet = Mono
$1.inheritsScope = text/plain
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.ElseIfNewLinePlacement = SameLine
$2.AfterDelegateDeclarationParameterComma = True
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sodium", "Sodium.csproj", "{D2080704-D359-4743-B568-5D976F9882A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "..\Tests\Tests.csproj", "{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BD22EFF-873C-48CF-B8E6-075ACA62F48C}.Release|Any CPU.Build.0 = Release|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2080704-D359-4743-B568-5D976F9882A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Sodium.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.FileWidth = 120
$1.TabWidth = 4
$1.IndentWidth = 2
$1.inheritsSet = Mono
$1.inheritsScope = text/plain
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.ElseIfNewLinePlacement = SameLine
$2.AfterDelegateDeclarationParameterComma = True
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions c#/Sodium/src/Sodium/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Schema;

namespace Sodium
{
Expand Down Expand Up @@ -65,6 +66,14 @@ public override bool Equals(object obj)
return false;
}

public override int GetHashCode()
{
var hash = IsPresent.GetHashCode();
if (value != null)
hash = (hash * 397) ^ value.GetHashCode();
return hash;
}

public bool Equals(Optional<T> other)
{
if (IsPresent && other.IsPresent)
Expand Down
4 changes: 2 additions & 2 deletions c#/Sodium/src/Sodium/PriorityQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void TrickleDown(int index, HeapEntry<TA> he)

public IEnumerator GetEnumerator()
{
return new PriorityQueueEnumerator<TA>(this);
return new PriorityQueueEnumerator(this);
}
#endregion

Expand Down Expand Up @@ -202,7 +202,7 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex

#region Priority Queue enumerator
[Serializable]
private class PriorityQueueEnumerator<TA> : IEnumerator<TA> where TA : IComparable<TA>
private class PriorityQueueEnumerator : IEnumerator<TA>
{
private int index;
private PriorityQueue<TA> pq;
Expand Down

0 comments on commit f533479

Please sign in to comment.