IO-507: Rename ByteOrderFactory to ByteOrderUtils to have a common naming schema
Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/928da12b Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/928da12b Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/928da12b Branch: refs/heads/master Commit: 928da12b15c987e16b2481c43614c8e868be1c04 Parents: bfe3c22 Author: Benedikt Ritter <brit...@apache.org> Authored: Sat Sep 30 15:51:36 2017 +0200 Committer: Benedikt Ritter <brit...@apache.org> Committed: Sat Sep 30 15:51:36 2017 +0200 ---------------------------------------------------------------------- src/changes/changes.xml | 2 +- .../org/apache/commons/io/ByteOrderFactory.java | 79 -------------------- .../org/apache/commons/io/ByteOrderUtils.java | 79 ++++++++++++++++++++ .../apache/commons/io/ByteOrderFactoryTest.java | 43 ----------- .../apache/commons/io/ByteOrderUtilsTest.java | 43 +++++++++++ 5 files changed, 123 insertions(+), 123 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-io/blob/928da12b/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4d59a71..a1d39a7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -111,7 +111,7 @@ The <action> type attribute can be add,update,fix,remove. Add infinite circular input stream </action> <action issue="IO-507" dev="ggregory" type="add"> - Add a ByteOrderFactory class. + Add a ByteOrderUtils class. </action> <action issue="IO-518" dev="jochen" type="add"> Add ObservableInputStream http://git-wip-us.apache.org/repos/asf/commons-io/blob/928da12b/src/main/java/org/apache/commons/io/ByteOrderFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/io/ByteOrderFactory.java b/src/main/java/org/apache/commons/io/ByteOrderFactory.java deleted file mode 100644 index 7c24a16..0000000 --- a/src/main/java/org/apache/commons/io/ByteOrderFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * - * http://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. - */ - -package org.apache.commons.io; - -import java.nio.ByteOrder; -import java.util.Locale; - -/** - * Converts Strings to {@link ByteOrder} instances. - * - * @since 2.6 - */ -public final class ByteOrderFactory { - - private static final Locale ComparisonLocale = Locale.ROOT; - - /** - * Big endian. - */ - public static final String BIG_ENDIAN = "Big"; - - /** - * Little endian. - */ - public static final String LITTLE_ENDIAN = "Little"; - - private ByteOrderFactory() { - } - - /** - * Parses the String argument as a {@link ByteOrder}, ignoring case. - * <p> - * Returns {@code ByteOrder.LITTLE_ENDIAN} if the given value is {@code "little"} or {@code "LITTLE_ENDIAN"}. - * </p> - * <p> - * Returns {@code ByteOrder.BIG_ENDIAN} if the given value is {@code "big"} or {@code "BIG_ENDIAN"}. - * </p> - * Examples: - * <ul> - * <li>{@code ByteOrderFactory.parseByteOrder("little")} returns {@code ByteOrder.LITTLE_ENDIAN}</li> - * <li>{@code ByteOrderFactory.parseByteOrder("big")} returns {@code ByteOrder.BIG_ENDIAN}</li> - * </ul> - * - * @param value - * the {@code String} containing the ByteOrder representation to be parsed - * @return the ByteOrder represented by the string argument - * @throws IllegalArgumentException - * if the {@code String} containing the ByteOrder representation to be parsed is unknown. - */ - public static ByteOrder parseByteOrder(final String value) { - final String valueUp = value.toUpperCase(ComparisonLocale); - final String bigEndianUp = BIG_ENDIAN.toUpperCase(ComparisonLocale); - final String littleEndianUp = LITTLE_ENDIAN.toUpperCase(ComparisonLocale); - if (bigEndianUp.equals(valueUp) || ByteOrder.BIG_ENDIAN.toString().equals(valueUp)) { - return ByteOrder.BIG_ENDIAN; - } - if (littleEndianUp.equals(valueUp) || ByteOrder.LITTLE_ENDIAN.toString().equals(valueUp)) { - return ByteOrder.LITTLE_ENDIAN; - } - throw new IllegalArgumentException("Unsupported byte order setting: " + value + ", expeced one of " + ByteOrder.LITTLE_ENDIAN + ", " + - LITTLE_ENDIAN + ", " + ByteOrder.BIG_ENDIAN + ", " + bigEndianUp); - } - -} http://git-wip-us.apache.org/repos/asf/commons-io/blob/928da12b/src/main/java/org/apache/commons/io/ByteOrderUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/io/ByteOrderUtils.java b/src/main/java/org/apache/commons/io/ByteOrderUtils.java new file mode 100644 index 0000000..e7a66f5 --- /dev/null +++ b/src/main/java/org/apache/commons/io/ByteOrderUtils.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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. + */ + +package org.apache.commons.io; + +import java.nio.ByteOrder; +import java.util.Locale; + +/** + * Converts Strings to {@link ByteOrder} instances. + * + * @since 2.6 + */ +public final class ByteOrderUtils { + + private static final Locale ComparisonLocale = Locale.ROOT; + + /** + * Big endian. + */ + public static final String BIG_ENDIAN = "Big"; + + /** + * Little endian. + */ + public static final String LITTLE_ENDIAN = "Little"; + + private ByteOrderUtils() { + } + + /** + * Parses the String argument as a {@link ByteOrder}, ignoring case. + * <p> + * Returns {@code ByteOrder.LITTLE_ENDIAN} if the given value is {@code "little"} or {@code "LITTLE_ENDIAN"}. + * </p> + * <p> + * Returns {@code ByteOrder.BIG_ENDIAN} if the given value is {@code "big"} or {@code "BIG_ENDIAN"}. + * </p> + * Examples: + * <ul> + * <li>{@code ByteOrderUtils.parseByteOrder("little")} returns {@code ByteOrder.LITTLE_ENDIAN}</li> + * <li>{@code ByteOrderUtils.parseByteOrder("big")} returns {@code ByteOrder.BIG_ENDIAN}</li> + * </ul> + * + * @param value + * the {@code String} containing the ByteOrder representation to be parsed + * @return the ByteOrder represented by the string argument + * @throws IllegalArgumentException + * if the {@code String} containing the ByteOrder representation to be parsed is unknown. + */ + public static ByteOrder parseByteOrder(final String value) { + final String valueUp = value.toUpperCase(ComparisonLocale); + final String bigEndianUp = BIG_ENDIAN.toUpperCase(ComparisonLocale); + final String littleEndianUp = LITTLE_ENDIAN.toUpperCase(ComparisonLocale); + if (bigEndianUp.equals(valueUp) || ByteOrder.BIG_ENDIAN.toString().equals(valueUp)) { + return ByteOrder.BIG_ENDIAN; + } + if (littleEndianUp.equals(valueUp) || ByteOrder.LITTLE_ENDIAN.toString().equals(valueUp)) { + return ByteOrder.LITTLE_ENDIAN; + } + throw new IllegalArgumentException("Unsupported byte order setting: " + value + ", expeced one of " + ByteOrder.LITTLE_ENDIAN + ", " + + LITTLE_ENDIAN + ", " + ByteOrder.BIG_ENDIAN + ", " + bigEndianUp); + } + +} http://git-wip-us.apache.org/repos/asf/commons-io/blob/928da12b/src/test/java/org/apache/commons/io/ByteOrderFactoryTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/ByteOrderFactoryTest.java b/src/test/java/org/apache/commons/io/ByteOrderFactoryTest.java deleted file mode 100644 index bf17a09..0000000 --- a/src/test/java/org/apache/commons/io/ByteOrderFactoryTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * - * http://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. - */ -package org.apache.commons.io; - -import java.nio.ByteOrder; - -import org.junit.Assert; -import org.junit.Test; - -public class ByteOrderFactoryTest { - - private ByteOrder parseByteOrder(final String value) { - return ByteOrderFactory.parseByteOrder(value); - } - - @Test - public void testParseBig() { - Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("big")); - Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("Big")); - Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("BIG")); - } - - @Test - public void testParseLittle() { - Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("little")); - Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("Little")); - Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("LITTLE")); - } -} http://git-wip-us.apache.org/repos/asf/commons-io/blob/928da12b/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java b/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java new file mode 100644 index 0000000..2affec4 --- /dev/null +++ b/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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. + */ +package org.apache.commons.io; + +import java.nio.ByteOrder; + +import org.junit.Assert; +import org.junit.Test; + +public class ByteOrderUtilsTest { + + private ByteOrder parseByteOrder(final String value) { + return ByteOrderUtils.parseByteOrder(value); + } + + @Test + public void testParseBig() { + Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("big")); + Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("Big")); + Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("BIG")); + } + + @Test + public void testParseLittle() { + Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("little")); + Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("Little")); + Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("LITTLE")); + } +}