Compare formats’ encodings disregarding case.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Format.java
index c9c9b08..fab7967 100644 (file)
@@ -91,12 +91,52 @@ public class Format {
        }
 
        //
+       // MUTATORS
+       //
+
+       /**
+        * Returns a format with the same parameters as this format and the given
+        * number of channels.
+        *
+        * @param channels
+        *              The new number of channels
+        * @return A new format with the given number of channels
+        */
+       public Format channels(int channels) {
+               return new Format(channels, frequency, encoding);
+       }
+
+       /**
+        * Returns a new format with the same parameters as this format and the given
+        * frequency.
+        *
+        * @param frequency
+        *              The new frequency
+        * @return A new format with the given frequency
+        */
+       public Format frequency(int frequency) {
+               return new Format(channels, frequency, encoding);
+       }
+
+       /**
+        * Returns a new format with the same parameters as this format and the given
+        * encoding.
+        *
+        * @param encoding
+        *              The new encoding
+        * @return A new format with the given encoding
+        */
+       public Format encoding(String encoding) {
+               return new Format(channels, frequency, encoding);
+       }
+
+       //
        // OBJECT METHODS
        //
 
        @Override
        public int hashCode() {
-               return (channels << 16) ^ frequency ^ encoding.hashCode();
+               return (channels << 16) ^ frequency ^ encoding.toUpperCase().hashCode();
        }
 
        @Override
@@ -105,7 +145,7 @@ public class Format {
                        return false;
                }
                Format format = (Format) object;
-               return (format.channels == channels) && (format.frequency == frequency) && format.encoding.equals(encoding());
+               return (format.channels == channels) && (format.frequency == frequency) && format.encoding.equalsIgnoreCase(encoding());
        }
 
        @Override