/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.util;

import org.spongepowered.api.util.orientation.Orientation;

import java.util.Optional;

public final class SpongeOrientation implements Orientation {

    public static final class Factory implements Orientation.Factory {

        @Override
        public Optional<Orientation> fromDegrees(final int degrees) {
            if (degrees % 45 == 0) {
                return Optional.of(new SpongeOrientation(degrees % 360));
            }

            return Optional.empty();
        }
    }

    private final int angle;

    public SpongeOrientation(final int angle) {
        if (angle % 45 != 0) {
            throw new IllegalArgumentException("The angle should be a multiple of 45 degrees!");
        }
        this.angle = angle % 360;
    }

    @Override
    public int angle() {
        return this.angle;
    }

    @Override
    public int hashCode() {
        return this.angle;
    }

    @Override
    public boolean equals(final Object anotherObject) {
        if (anotherObject == null) return false;
        if (anotherObject == this) return true;
        if (anotherObject instanceof SpongeOrientation) {
            SpongeOrientation anotherOrientation = (SpongeOrientation) anotherObject;
            return anotherOrientation.angle == this.angle;
        }
        return false;
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "{angle=" + this.angle + "}";
    }
}

@@ -2231,29 +2231,19 @@
  Object 
-anotherObject
+obj
 ) %7B%0A    
@@ -2254,79 +2254,34 @@
 if (
-anotherObject == null) return false;%0A        if (anotherObject == this)
+obj == this) %7B%0A           
  ret
@@ -2302,25 +2302,28 @@
     
-if (anotherObject
+%7D%0A%0A        if (!(obj
  ins
@@ -2348,16 +2348,17 @@
 ntation)
+)
  %7B%0A     
@@ -2368,86 +2368,33 @@
     
-SpongeOrientation anotherOrientation = (SpongeOrientation) anotherObject;%0A
+return false;%0A   
     
+ %7D%0A%0A
     
@@ -2408,15 +2408,16 @@
 urn 
-another
+((Sponge
 Orie
@@ -2423,16 +2423,22 @@
 entation
+) obj)
 .angle =
@@ -2455,40 +2455,8 @@
 le;%0A
-        %7D%0A        return false;%0A
     

Implement requested changes for PR#3433