// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. using System; namespace Google.Android.AppBundle.Editor { /// /// The device tier labels that can be recognized in an asset pack folder name. /// public class DeviceTier { /// /// Factory method. /// /// The tier level.> /// Thrown if the level is a negative int. public static DeviceTier From(int tier) { return new DeviceTier(tier); } /// /// Returns the tier level. /// /// Device tier levels determines the priority of what variation of app content gets /// served to a specific device, for device-targeted content. /// Tiers are evaluated from the highest to the lowest level; the highest /// tier matching a given device is selected for that device. /// public int Tier { get; private set; } /// /// Implicit conversion from DeviceTier to int. /// public static implicit operator int(DeviceTier deviceTier) { return deviceTier.Tier; } /// /// Implicit conversion from int to DeviceTier. /// public static implicit operator DeviceTier(int tier) { return new DeviceTier(tier); } /// /// ToString conversion. /// public override string ToString() { return Convert.ToString(Tier); } /// /// Equal comparision override for DeviceTier objects. /// public override bool Equals(object other) { var otherTier = other as DeviceTier; if (otherTier != null) { return Tier == otherTier.Tier; } return false; } /// /// Creates hash code for DeviceTier object from underlying tier value. /// public override int GetHashCode() { return Tier.GetHashCode(); } /// /// Constructor. /// /// The tier level.> /// Thrown if the level is a negative int. private DeviceTier(int tier) { if (tier < 0) { throw new ArgumentException( String.Format("Tier levels are required to be non-negative integers, but found {0}.", tier)); } Tier = tier; } } }