Author: robbie Date: Mon Oct 6 14:50:55 2014 New Revision: 1629675 URL: http://svn.apache.org/r1629675 Log: PROTON-618: update line endings only, for consistency with other files
Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Binary.java qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedByte.java qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedInteger.java qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedLong.java qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedShort.java Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Binary.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Binary.java?rev=1629675&r1=1629674&r2=1629675&view=diff ============================================================================== --- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Binary.java (original) +++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Binary.java Mon Oct 6 14:50:55 2014 @@ -1,189 +1,189 @@ -/* - * - * 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.qpid.proton.amqp; - -import java.nio.ByteBuffer; -import java.util.Collection; - -import static java.lang.Math.min; - -public final class Binary -{ - - private final byte[] _data; - private final int _offset; - private final int _length; - private int _hashCode; - - public Binary(final byte[] data) - { - this(data, 0, data.length); - } - - public Binary(final byte[] data, final int offset, final int length) - { - _data = data; - _offset = offset; - _length = length; - } - - public ByteBuffer asByteBuffer() - { - return ByteBuffer.wrap(_data, _offset, _length); - } - - @Override - public final int hashCode() - { - int hc = _hashCode; - if(hc == 0) - { - for (int i = 0; i < _length; i++) - { - hc = 31*hc + (0xFF & _data[_offset + i]); - } - _hashCode = hc; - } - return hc; - } - - @Override - public final boolean equals(Object o) - { - if (this == o) - { - return true; - } - - if (o == null || getClass() != o.getClass()) - { - return false; - } - - Binary buf = (Binary) o; - final int size = _length; - if (size != buf._length) - { - return false; - } - - final byte[] myData = _data; - final byte[] theirData = buf._data; - int myOffset = _offset; - int theirOffset = buf._offset; - final int myLimit = myOffset + size; - - while(myOffset < myLimit) - { - if (myData[myOffset++] != theirData[theirOffset++]) - { - return false; - } - } - - return true; - } - - - public int getArrayOffset() - { - return _offset; - } - - public byte[] getArray() - { - return _data; - } - - public int getLength() - { - return _length; - } - - public String toString() - { - StringBuilder str = new StringBuilder(); - - - for (int i = 0; i < _length; i++) - { - byte c = _data[_offset + i]; - - if (c > 31 && c < 127 && c != '\\') - { - str.append((char)c); - } - else - { - str.append(String.format("\\x%02x", c)); - } - } - - return str.toString(); - - } - - public static Binary combine(final Collection<Binary> binaries) - { - - if(binaries.size() == 1) - { - return binaries.iterator().next(); - } - - int size = 0; - for(Binary binary : binaries) - { - size += binary.getLength(); - } - byte[] data = new byte[size]; - int offset = 0; - for(Binary binary : binaries) - { - System.arraycopy(binary._data, binary._offset, data, offset, binary._length); - offset += binary._length; - } - return new Binary(data); - } - - public Binary subBinary(final int offset, final int length) - { - return new Binary(_data, _offset+offset, length); - } - - public static Binary create(ByteBuffer buffer) - { - if( buffer == null ) - return null; - if( buffer.isDirect() || buffer.isReadOnly() ) - { - byte data[] = new byte [buffer.remaining()]; - ByteBuffer dup = buffer.duplicate(); - dup.get(data); - return new Binary(data); - } - else - { - return new Binary(buffer.array(), buffer.arrayOffset()+buffer.position(), buffer.remaining()); - } - } - -} +/* + * + * 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.qpid.proton.amqp; + +import java.nio.ByteBuffer; +import java.util.Collection; + +import static java.lang.Math.min; + +public final class Binary +{ + + private final byte[] _data; + private final int _offset; + private final int _length; + private int _hashCode; + + public Binary(final byte[] data) + { + this(data, 0, data.length); + } + + public Binary(final byte[] data, final int offset, final int length) + { + _data = data; + _offset = offset; + _length = length; + } + + public ByteBuffer asByteBuffer() + { + return ByteBuffer.wrap(_data, _offset, _length); + } + + @Override + public final int hashCode() + { + int hc = _hashCode; + if(hc == 0) + { + for (int i = 0; i < _length; i++) + { + hc = 31*hc + (0xFF & _data[_offset + i]); + } + _hashCode = hc; + } + return hc; + } + + @Override + public final boolean equals(Object o) + { + if (this == o) + { + return true; + } + + if (o == null || getClass() != o.getClass()) + { + return false; + } + + Binary buf = (Binary) o; + final int size = _length; + if (size != buf._length) + { + return false; + } + + final byte[] myData = _data; + final byte[] theirData = buf._data; + int myOffset = _offset; + int theirOffset = buf._offset; + final int myLimit = myOffset + size; + + while(myOffset < myLimit) + { + if (myData[myOffset++] != theirData[theirOffset++]) + { + return false; + } + } + + return true; + } + + + public int getArrayOffset() + { + return _offset; + } + + public byte[] getArray() + { + return _data; + } + + public int getLength() + { + return _length; + } + + public String toString() + { + StringBuilder str = new StringBuilder(); + + + for (int i = 0; i < _length; i++) + { + byte c = _data[_offset + i]; + + if (c > 31 && c < 127 && c != '\\') + { + str.append((char)c); + } + else + { + str.append(String.format("\\x%02x", c)); + } + } + + return str.toString(); + + } + + public static Binary combine(final Collection<Binary> binaries) + { + + if(binaries.size() == 1) + { + return binaries.iterator().next(); + } + + int size = 0; + for(Binary binary : binaries) + { + size += binary.getLength(); + } + byte[] data = new byte[size]; + int offset = 0; + for(Binary binary : binaries) + { + System.arraycopy(binary._data, binary._offset, data, offset, binary._length); + offset += binary._length; + } + return new Binary(data); + } + + public Binary subBinary(final int offset, final int length) + { + return new Binary(_data, _offset+offset, length); + } + + public static Binary create(ByteBuffer buffer) + { + if( buffer == null ) + return null; + if( buffer.isDirect() || buffer.isReadOnly() ) + { + byte data[] = new byte [buffer.remaining()]; + ByteBuffer dup = buffer.duplicate(); + dup.get(data); + return new Binary(data); + } + else + { + return new Binary(buffer.array(), buffer.arrayOffset()+buffer.position(), buffer.remaining()); + } + } + +} Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java?rev=1629675&r1=1629674&r2=1629675&view=diff ============================================================================== --- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java (original) +++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java Mon Oct 6 14:50:55 2014 @@ -1,94 +1,94 @@ -/* - * - * 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.qpid.proton.amqp; - -import java.util.concurrent.ConcurrentHashMap; - -public final class Symbol implements Comparable<Symbol>, CharSequence -{ - private final String _underlying; - private static final ConcurrentHashMap<String, Symbol> _symbols = new ConcurrentHashMap<String, Symbol>(2048); - - private Symbol(String underlying) - { - _underlying = underlying; - } - - public int length() - { - return _underlying.length(); - } - - public int compareTo(Symbol o) - { - return _underlying.compareTo(o._underlying); - } - - public char charAt(int index) - { - return _underlying.charAt(index); - } - - public CharSequence subSequence(int beginIndex, int endIndex) - { - return _underlying.subSequence(beginIndex, endIndex); - } - - @Override - public String toString() - { - return _underlying; - } - - @Override - public int hashCode() - { - return _underlying.hashCode(); - } - - public static Symbol valueOf(String symbolVal) - { - return getSymbol(symbolVal); - } - - public static Symbol getSymbol(String symbolVal) - { - if(symbolVal == null) - { - return null; - } - Symbol symbol = _symbols.get(symbolVal); - if(symbol == null) - { - symbolVal = symbolVal.intern(); - symbol = new Symbol(symbolVal); - Symbol existing; - if((existing = _symbols.putIfAbsent(symbolVal, symbol)) != null) - { - symbol = existing; - } - } - return symbol; - } - - -} +/* + * + * 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.qpid.proton.amqp; + +import java.util.concurrent.ConcurrentHashMap; + +public final class Symbol implements Comparable<Symbol>, CharSequence +{ + private final String _underlying; + private static final ConcurrentHashMap<String, Symbol> _symbols = new ConcurrentHashMap<String, Symbol>(2048); + + private Symbol(String underlying) + { + _underlying = underlying; + } + + public int length() + { + return _underlying.length(); + } + + public int compareTo(Symbol o) + { + return _underlying.compareTo(o._underlying); + } + + public char charAt(int index) + { + return _underlying.charAt(index); + } + + public CharSequence subSequence(int beginIndex, int endIndex) + { + return _underlying.subSequence(beginIndex, endIndex); + } + + @Override + public String toString() + { + return _underlying; + } + + @Override + public int hashCode() + { + return _underlying.hashCode(); + } + + public static Symbol valueOf(String symbolVal) + { + return getSymbol(symbolVal); + } + + public static Symbol getSymbol(String symbolVal) + { + if(symbolVal == null) + { + return null; + } + Symbol symbol = _symbols.get(symbolVal); + if(symbol == null) + { + symbolVal = symbolVal.intern(); + symbol = new Symbol(symbolVal); + Symbol existing; + if((existing = _symbols.putIfAbsent(symbolVal, symbol)) != null) + { + symbol = existing; + } + } + return symbol; + } + + +} Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedByte.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedByte.java?rev=1629675&r1=1629674&r2=1629675&view=diff ============================================================================== --- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedByte.java (original) +++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedByte.java Mon Oct 6 14:50:55 2014 @@ -1,134 +1,134 @@ -/* - * - * 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.qpid.proton.amqp; - -public final class UnsignedByte extends Number implements Comparable<UnsignedByte> -{ - private final byte _underlying; - private static final UnsignedByte[] cachedValues = new UnsignedByte[256]; - - static - { - for(int i = 0; i<256; i++) - { - cachedValues[i] = new UnsignedByte((byte)i); - } - } - - public UnsignedByte(byte underlying) - { - _underlying = underlying; - } - - @Override - public byte byteValue() - { - return _underlying; - } - - @Override - public short shortValue() - { - return (short) intValue(); - } - - @Override - public int intValue() - { - return ((int)_underlying) & 0xFF; - } - - @Override - public long longValue() - { - return ((long) _underlying) & 0xFFl; - } - - @Override - public float floatValue() - { - return (float) longValue(); - } - - @Override - public double doubleValue() - { - return (double) longValue(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - UnsignedByte that = (UnsignedByte) o; - - if (_underlying != that._underlying) - { - return false; - } - - return true; - } - - public int compareTo(UnsignedByte o) - { - return Integer.signum(intValue() - o.intValue()); - } - - @Override - public int hashCode() - { - return _underlying; - } - - @Override - public String toString() - { - return String.valueOf(intValue()); - } - - public static UnsignedByte valueOf(byte underlying) - { - final int index = ((int) underlying) & 0xFF; - return cachedValues[index]; - } - - public static UnsignedByte valueOf(final String value) - throws NumberFormatException - { - int intVal = Integer.parseInt(value); - if(intVal < 0 || intVal >= (1<<8)) - { - throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0 + "-" + (1<<8) +")."); - } - return valueOf((byte)intVal); - } - -} +/* + * + * 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.qpid.proton.amqp; + +public final class UnsignedByte extends Number implements Comparable<UnsignedByte> +{ + private final byte _underlying; + private static final UnsignedByte[] cachedValues = new UnsignedByte[256]; + + static + { + for(int i = 0; i<256; i++) + { + cachedValues[i] = new UnsignedByte((byte)i); + } + } + + public UnsignedByte(byte underlying) + { + _underlying = underlying; + } + + @Override + public byte byteValue() + { + return _underlying; + } + + @Override + public short shortValue() + { + return (short) intValue(); + } + + @Override + public int intValue() + { + return ((int)_underlying) & 0xFF; + } + + @Override + public long longValue() + { + return ((long) _underlying) & 0xFFl; + } + + @Override + public float floatValue() + { + return (float) longValue(); + } + + @Override + public double doubleValue() + { + return (double) longValue(); + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + UnsignedByte that = (UnsignedByte) o; + + if (_underlying != that._underlying) + { + return false; + } + + return true; + } + + public int compareTo(UnsignedByte o) + { + return Integer.signum(intValue() - o.intValue()); + } + + @Override + public int hashCode() + { + return _underlying; + } + + @Override + public String toString() + { + return String.valueOf(intValue()); + } + + public static UnsignedByte valueOf(byte underlying) + { + final int index = ((int) underlying) & 0xFF; + return cachedValues[index]; + } + + public static UnsignedByte valueOf(final String value) + throws NumberFormatException + { + int intVal = Integer.parseInt(value); + if(intVal < 0 || intVal >= (1<<8)) + { + throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0 + "-" + (1<<8) +")."); + } + return valueOf((byte)intVal); + } + +} Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedInteger.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedInteger.java?rev=1629675&r1=1629674&r2=1629675&view=diff ============================================================================== --- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedInteger.java (original) +++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedInteger.java Mon Oct 6 14:50:55 2014 @@ -1,149 +1,149 @@ -/* - * - * 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.qpid.proton.amqp; - -public final class UnsignedInteger extends Number implements Comparable<UnsignedInteger> -{ - private final int _underlying; - private static final UnsignedInteger[] cachedValues = new UnsignedInteger[256]; - - static - { - for(int i = 0; i < 256; i++) - { - cachedValues[i] = new UnsignedInteger(i); - } - } - - public static final UnsignedInteger ZERO = cachedValues[0]; - public static final UnsignedInteger ONE = cachedValues[1]; - public static final UnsignedInteger MAX_VALUE = new UnsignedInteger(0xffffffff); - - - public UnsignedInteger(int underlying) - { - _underlying = underlying; - } - - @Override - public int intValue() - { - return _underlying; - } - - @Override - public long longValue() - { - return ((long) _underlying) & 0xFFFFFFFFl; - } - - @Override - public float floatValue() - { - return (float) longValue(); - } - - @Override - public double doubleValue() - { - return (double) longValue(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - UnsignedInteger that = (UnsignedInteger) o; - - if (_underlying != that._underlying) - { - return false; - } - - return true; - } - - public int compareTo(UnsignedInteger o) - { - return Long.signum(longValue() - o.longValue()); - } - - @Override - public int hashCode() - { - return _underlying; - } - - @Override - public String toString() - { - return String.valueOf(longValue()); - } - - public static UnsignedInteger valueOf(int underlying) - { - if((underlying & 0xFFFFFF00) == 0) - { - return cachedValues[underlying]; - } - else - { - return new UnsignedInteger(underlying); - } - } - - public UnsignedInteger add(final UnsignedInteger i) - { - int val = _underlying + i._underlying; - return UnsignedInteger.valueOf(val); - } - - public UnsignedInteger subtract(final UnsignedInteger i) - { - int val = _underlying - i._underlying; - return UnsignedInteger.valueOf(val); - } - - public static UnsignedInteger valueOf(final String value) - { - long longVal = Long.parseLong(value); - return valueOf(longVal); - } - - public static UnsignedInteger valueOf(final long longVal) - { - if(longVal < 0L || longVal >= (1L<<32)) - { - throw new NumberFormatException("Value \""+longVal+"\" lies outside the range [" + 0L + "-" + (1L<<32) +")."); - } - return valueOf((int)longVal); - } - -} +/* + * + * 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.qpid.proton.amqp; + +public final class UnsignedInteger extends Number implements Comparable<UnsignedInteger> +{ + private final int _underlying; + private static final UnsignedInteger[] cachedValues = new UnsignedInteger[256]; + + static + { + for(int i = 0; i < 256; i++) + { + cachedValues[i] = new UnsignedInteger(i); + } + } + + public static final UnsignedInteger ZERO = cachedValues[0]; + public static final UnsignedInteger ONE = cachedValues[1]; + public static final UnsignedInteger MAX_VALUE = new UnsignedInteger(0xffffffff); + + + public UnsignedInteger(int underlying) + { + _underlying = underlying; + } + + @Override + public int intValue() + { + return _underlying; + } + + @Override + public long longValue() + { + return ((long) _underlying) & 0xFFFFFFFFl; + } + + @Override + public float floatValue() + { + return (float) longValue(); + } + + @Override + public double doubleValue() + { + return (double) longValue(); + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + UnsignedInteger that = (UnsignedInteger) o; + + if (_underlying != that._underlying) + { + return false; + } + + return true; + } + + public int compareTo(UnsignedInteger o) + { + return Long.signum(longValue() - o.longValue()); + } + + @Override + public int hashCode() + { + return _underlying; + } + + @Override + public String toString() + { + return String.valueOf(longValue()); + } + + public static UnsignedInteger valueOf(int underlying) + { + if((underlying & 0xFFFFFF00) == 0) + { + return cachedValues[underlying]; + } + else + { + return new UnsignedInteger(underlying); + } + } + + public UnsignedInteger add(final UnsignedInteger i) + { + int val = _underlying + i._underlying; + return UnsignedInteger.valueOf(val); + } + + public UnsignedInteger subtract(final UnsignedInteger i) + { + int val = _underlying - i._underlying; + return UnsignedInteger.valueOf(val); + } + + public static UnsignedInteger valueOf(final String value) + { + long longVal = Long.parseLong(value); + return valueOf(longVal); + } + + public static UnsignedInteger valueOf(final long longVal) + { + if(longVal < 0L || longVal >= (1L<<32)) + { + throw new NumberFormatException("Value \""+longVal+"\" lies outside the range [" + 0L + "-" + (1L<<32) +")."); + } + return valueOf((int)longVal); + } + +} Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedLong.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedLong.java?rev=1629675&r1=1629674&r2=1629675&view=diff ============================================================================== --- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedLong.java (original) +++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedLong.java Mon Oct 6 14:50:55 2014 @@ -1,160 +1,160 @@ -/* - * - * 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.qpid.proton.amqp; - -import java.math.BigInteger; - -public final class UnsignedLong extends Number implements Comparable<UnsignedLong> -{ - private static final BigInteger TWO_TO_THE_SIXTY_FOUR = new BigInteger( new byte[] { (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }); - private static final BigInteger LONG_MAX_VALUE = BigInteger.valueOf(Long.MAX_VALUE); - - private static final UnsignedLong[] cachedValues = new UnsignedLong[256]; - - static - { - for(int i = 0; i<256; i++) - { - cachedValues[i] = new UnsignedLong(i); - } - } - - public static final UnsignedLong ZERO = cachedValues[0]; - - private final long _underlying; - - - public UnsignedLong(long underlying) - { - _underlying = underlying; - } - - @Override - public int intValue() - { - return (int) _underlying; - } - - @Override - public long longValue() - { - return _underlying; - } - - public BigInteger bigIntegerValue() - { - if(_underlying >= 0L) - { - return BigInteger.valueOf(_underlying); - } - else - { - return TWO_TO_THE_SIXTY_FOUR.add(BigInteger.valueOf(_underlying)); - } - } - - @Override - public float floatValue() - { - return (float) longValue(); - } - - @Override - public double doubleValue() - { - return (double) longValue(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - UnsignedLong that = (UnsignedLong) o; - - if (_underlying != that._underlying) - { - return false; - } - - return true; - } - - public int compareTo(UnsignedLong o) - { - return bigIntegerValue().compareTo(o.bigIntegerValue()); - } - - @Override - public int hashCode() - { - return (int)(_underlying ^ (_underlying >>> 32)); - } - - @Override - public String toString() - { - return String.valueOf(bigIntegerValue()); - } - - public static UnsignedLong valueOf(long underlying) - { - if((underlying & 0xFFL) == underlying) - { - return cachedValues[(int)underlying]; - } - else - { - return new UnsignedLong(underlying); - } - } - - public static UnsignedLong valueOf(final String value) - { - BigInteger bigInt = new BigInteger(value); - - return valueOf(bigInt); - } - - public static UnsignedLong valueOf(BigInteger bigInt) - { - if(bigInt.signum() == -1 || bigInt.bitLength() > 64) - { - throw new NumberFormatException("Value \""+bigInt+"\" lies outside the range [0 - 2^64)."); - } - else if(bigInt.compareTo(LONG_MAX_VALUE)>=0) - { - return UnsignedLong.valueOf(bigInt.longValue()); - } - else - { - return UnsignedLong.valueOf(TWO_TO_THE_SIXTY_FOUR.subtract(bigInt).negate().longValue()); - } - } -} +/* + * + * 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.qpid.proton.amqp; + +import java.math.BigInteger; + +public final class UnsignedLong extends Number implements Comparable<UnsignedLong> +{ + private static final BigInteger TWO_TO_THE_SIXTY_FOUR = new BigInteger( new byte[] { (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }); + private static final BigInteger LONG_MAX_VALUE = BigInteger.valueOf(Long.MAX_VALUE); + + private static final UnsignedLong[] cachedValues = new UnsignedLong[256]; + + static + { + for(int i = 0; i<256; i++) + { + cachedValues[i] = new UnsignedLong(i); + } + } + + public static final UnsignedLong ZERO = cachedValues[0]; + + private final long _underlying; + + + public UnsignedLong(long underlying) + { + _underlying = underlying; + } + + @Override + public int intValue() + { + return (int) _underlying; + } + + @Override + public long longValue() + { + return _underlying; + } + + public BigInteger bigIntegerValue() + { + if(_underlying >= 0L) + { + return BigInteger.valueOf(_underlying); + } + else + { + return TWO_TO_THE_SIXTY_FOUR.add(BigInteger.valueOf(_underlying)); + } + } + + @Override + public float floatValue() + { + return (float) longValue(); + } + + @Override + public double doubleValue() + { + return (double) longValue(); + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + UnsignedLong that = (UnsignedLong) o; + + if (_underlying != that._underlying) + { + return false; + } + + return true; + } + + public int compareTo(UnsignedLong o) + { + return bigIntegerValue().compareTo(o.bigIntegerValue()); + } + + @Override + public int hashCode() + { + return (int)(_underlying ^ (_underlying >>> 32)); + } + + @Override + public String toString() + { + return String.valueOf(bigIntegerValue()); + } + + public static UnsignedLong valueOf(long underlying) + { + if((underlying & 0xFFL) == underlying) + { + return cachedValues[(int)underlying]; + } + else + { + return new UnsignedLong(underlying); + } + } + + public static UnsignedLong valueOf(final String value) + { + BigInteger bigInt = new BigInteger(value); + + return valueOf(bigInt); + } + + public static UnsignedLong valueOf(BigInteger bigInt) + { + if(bigInt.signum() == -1 || bigInt.bitLength() > 64) + { + throw new NumberFormatException("Value \""+bigInt+"\" lies outside the range [0 - 2^64)."); + } + else if(bigInt.compareTo(LONG_MAX_VALUE)>=0) + { + return UnsignedLong.valueOf(bigInt.longValue()); + } + else + { + return UnsignedLong.valueOf(TWO_TO_THE_SIXTY_FOUR.subtract(bigInt).negate().longValue()); + } + } +} Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedShort.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedShort.java?rev=1629675&r1=1629674&r2=1629675&view=diff ============================================================================== --- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedShort.java (original) +++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/amqp/UnsignedShort.java Mon Oct 6 14:50:55 2014 @@ -1,134 +1,134 @@ -/* - * - * 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.qpid.proton.amqp; - -public final class UnsignedShort extends Number implements Comparable<UnsignedShort> -{ - private final short _underlying; - private static final UnsignedShort[] cachedValues = new UnsignedShort[256]; - - public static final UnsignedShort MAX_VALUE = new UnsignedShort((short) -1); - - static - { - for(short i = 0; i < 256; i++) - { - cachedValues[i] = new UnsignedShort(i); - } - } - - public UnsignedShort(short underlying) - { - _underlying = underlying; - } - - public short shortValue() - { - return _underlying; - } - - @Override - public int intValue() - { - return _underlying & 0xFFFF; - } - - @Override - public long longValue() - { - return ((long) _underlying) & 0xFFFFl; - } - - @Override - public float floatValue() - { - return (float) intValue(); - } - - @Override - public double doubleValue() - { - return (double) intValue(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - UnsignedShort that = (UnsignedShort) o; - - if (_underlying != that._underlying) - { - return false; - } - - return true; - } - - public int compareTo(UnsignedShort o) - { - return Integer.signum(intValue() - o.intValue()); - } - - @Override - public int hashCode() - { - return _underlying; - } - - @Override - public String toString() - { - return String.valueOf(longValue()); - } - - public static UnsignedShort valueOf(short underlying) - { - if((underlying & 0xFF00) == 0) - { - return cachedValues[underlying]; - } - else - { - return new UnsignedShort(underlying); - } - } - - public static UnsignedShort valueOf(final String value) - { - int intVal = Integer.parseInt(value); - if(intVal < 0 || intVal >= (1<<16)) - { - throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0 + "-" + (1<<16) +")."); - } - return valueOf((short)intVal); - - } -} +/* + * + * 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.qpid.proton.amqp; + +public final class UnsignedShort extends Number implements Comparable<UnsignedShort> +{ + private final short _underlying; + private static final UnsignedShort[] cachedValues = new UnsignedShort[256]; + + public static final UnsignedShort MAX_VALUE = new UnsignedShort((short) -1); + + static + { + for(short i = 0; i < 256; i++) + { + cachedValues[i] = new UnsignedShort(i); + } + } + + public UnsignedShort(short underlying) + { + _underlying = underlying; + } + + public short shortValue() + { + return _underlying; + } + + @Override + public int intValue() + { + return _underlying & 0xFFFF; + } + + @Override + public long longValue() + { + return ((long) _underlying) & 0xFFFFl; + } + + @Override + public float floatValue() + { + return (float) intValue(); + } + + @Override + public double doubleValue() + { + return (double) intValue(); + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + UnsignedShort that = (UnsignedShort) o; + + if (_underlying != that._underlying) + { + return false; + } + + return true; + } + + public int compareTo(UnsignedShort o) + { + return Integer.signum(intValue() - o.intValue()); + } + + @Override + public int hashCode() + { + return _underlying; + } + + @Override + public String toString() + { + return String.valueOf(longValue()); + } + + public static UnsignedShort valueOf(short underlying) + { + if((underlying & 0xFF00) == 0) + { + return cachedValues[underlying]; + } + else + { + return new UnsignedShort(underlying); + } + } + + public static UnsignedShort valueOf(final String value) + { + int intVal = Integer.parseInt(value); + if(intVal < 0 || intVal >= (1<<16)) + { + throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0 + "-" + (1<<16) +")."); + } + return valueOf((short)intVal); + + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org