001package co.codewizards.cloudstore.core.util;
002
003import java.util.Arrays;
004
005/**
006 * @author Marco
007 * @author Sebastian Schefczyk
008 */
009public final class Util {
010        private Util() { }
011
012        /**
013         * Get the user name of the user who is currently authenticated at the operating system.
014         * This method simply calls <code>System.getProperty("user.name");</code>.
015         *
016         * @return the user name of the current operating system user.
017         */
018        public static final String getUserName()
019        {
020                return System.getProperty("user.name"); //$NON-NLS-1$
021        }
022
023        public static final <T, S extends T> boolean equal(final S one, final T two) {
024                return one == null ? two == null : one.equals(two);
025        }
026
027        public static final boolean equal(final boolean one, final boolean two) {
028                return one == two;
029        }
030
031        public static final boolean equal(final byte one, final byte two) {
032                return one == two;
033        }
034
035        public static final boolean equal(final short one, final short two) {
036                return one == two;
037        }
038
039        public static final boolean equal(final char one, final char two) {
040                return one == two;
041        }
042
043        public static final boolean equal(final int one, final int two) {
044                return one == two;
045        }
046
047        public static final boolean equal(final long one, final long two) {
048                return one == two;
049        }
050
051
052        public static final <T, S extends T> boolean equal(final S[] one, final T[] two) {
053                return Arrays.equals(one, two);
054        }
055
056        public static final boolean equal(final byte[] one, final byte[] two) {
057                return Arrays.equals(one, two);
058        }
059
060        public static final boolean equal(final boolean[] one, final boolean[] two) {
061                return Arrays.equals(one, two);
062        }
063
064        public static final boolean equal(final short[] one, final short[] two) {
065                return Arrays.equals(one, two);
066        }
067
068        public static final boolean equal(final char[] one, final char[] two) {
069                return Arrays.equals(one, two);
070        }
071
072        public static final boolean equal(final int[] one, final int[] two) {
073                return Arrays.equals(one, two);
074        }
075
076        public static final boolean equal(final long[] one, final long[] two) {
077                return Arrays.equals(one, two);
078        }
079
080        @SuppressWarnings("unchecked")
081        public static final <T> T cast(final Object o) {
082                return (T) o;
083        }
084
085        /**
086         * Gets the {@code String}-representation of the given {@code object} as it is constructed by the base-implementation
087         * {@link Object#toString()}.
088         * <p>
089         * This method does not invoke the object's {@code toString()} method, hence it makes
090         * no difference, if the object's class has an overridden version of the {@code toString()} method!
091         * <p>
092         * If the given {@code object} is <code>null</code>, the result is {@code "null"} (just like the result of
093         * {@link String#valueOf(Object)}).
094         * <p>
095         * If the given {@code object} is not <code>null</code>, the result consists of the fully qualified class-name followed
096         * by '@' and the object's hex-encoded {@linkplain System#identityHashCode(Object) identity-hash-code}. For example:
097         * {@code "my.package.Car@47c624e2"}.
098         *
099         * @param object the object for which to obtain the {@code String}-representation. May be <code>null</code>.
100         * @return the {@code String}-representation. Never <code>null</code>.
101         */
102        public static final String toIdentityString(final Object object) {
103                if (object == null)
104                        return String.valueOf(object); // result: "null"
105
106                return object.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(object));
107        }
108
109        public static void main(String[] args) {
110                System.out.println(toIdentityString(new Object()));
111        }
112
113        /**
114         * Does really nothing.
115         * <p>
116         * This method should be used in the catch of a try-catch-block, if there's really no action needed.
117         */
118        public static final void doNothing() { }
119}