agones.dev/agones@v1.53.0/sdks/unity/model/GameServerSpec.cs (about)

     1  // Copyright 2019 Google LLC
     2  // All Rights Reserved.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  using System;
    17  using System.Collections.Generic;
    18  using System.Text;
    19  
    20  namespace Agones.Model
    21  {
    22      /// <summary>
    23      /// GameServerSpec
    24      /// </summary>
    25      public class GameServerSpec : IEquatable<GameServerSpec>
    26      {
    27          /// <summary>
    28          /// Initializes a new instance of the <see cref="GameServerSpec" /> class.
    29          /// </summary>
    30          public GameServerSpec(IReadOnlyDictionary<string, object> data)
    31          {
    32              this.Health = new SpecHealth((Dictionary<string, object>) data["health"]);
    33          }
    34  
    35          public SpecHealth Health { get; set; }
    36  
    37          /// <summary>
    38          /// Returns the string presentation of the object
    39          /// </summary>
    40          /// <returns>String presentation of the object</returns>
    41          public override string ToString()
    42          {
    43              var sb = new StringBuilder();
    44              sb.Append("class GameServerSpec {\n");
    45              sb.Append("  Health: ").Append(Health).Append("\n");
    46              sb.Append("}\n");
    47              return sb.ToString();
    48          }
    49  
    50          /// <summary>
    51          /// Returns true if objects are equal
    52          /// </summary>
    53          /// <param name="input">Object to be compared</param>
    54          /// <returns>Boolean</returns>
    55          public override bool Equals(object input)
    56          {
    57              return this.Equals(input as GameServerSpec);
    58          }
    59  
    60          /// <summary>
    61          /// Returns true if GameServerSpec instances are equal
    62          /// </summary>
    63          /// <param name="input">Instance of GameServerSpec to be compared</param>
    64          /// <returns>Boolean</returns>
    65          public bool Equals(GameServerSpec input)
    66          {
    67              if (input == null)
    68                  return false;
    69  
    70              return
    71              (
    72                  this.Health == input.Health ||
    73                  (this.Health != null &&
    74                   this.Health.Equals(input.Health))
    75              );
    76          }
    77  
    78          /// <summary>
    79          /// Gets the hash code
    80          /// </summary>
    81          /// <returns>Hash code</returns>
    82          public override int GetHashCode()
    83          {
    84              unchecked // Overflow is fine, just wrap
    85              {
    86                  int hashCode = 41;
    87                  if (this.Health != null)
    88                      hashCode = hashCode * 59 + this.Health.GetHashCode();
    89                  return hashCode;
    90              }
    91          }
    92      }
    93  }