List of usage examples for java.lang Float floatToIntBits
@HotSpotIntrinsicCandidate public static int floatToIntBits(float value)
From source file:com.antsdb.saltedfish.server.mysql.PacketEncoder.java
private boolean writeValueFast(ByteBuf buffer, FieldMeta meta, long pValue) { DataType type = meta.getType();/*from www . j a v a 2 s .c o m*/ byte format = Value.getFormat(null, pValue); if (type.getSqlType() == Types.TINYINT) { if (format == Value.FORMAT_INT4) { buffer.writeByte(Int4.get(pValue)); return true; } else if (format == Value.FORMAT_INT8) { buffer.writeByte((int) Int8.get(null, pValue)); return true; } } else if (type.getJavaType() == Boolean.class) { boolean b = FishBool.get(null, pValue); buffer.writeByte(b ? 1 : 0); return true; } else if (type.getJavaType() == Integer.class) { if (format == Value.FORMAT_INT4) { BufferUtils.writeUB4(buffer, Int4.get(pValue)); return true; } else if (format == Value.FORMAT_INT8) { BufferUtils.writeUB4(buffer, (int) Int8.get(null, pValue)); return true; } } else if (type.getJavaType() == Long.class) { if (format == Value.FORMAT_INT4) { BufferUtils.writeLongLong(buffer, Int4.get(pValue)); return true; } else if (format == Value.FORMAT_INT8) { BufferUtils.writeLongLong(buffer, Int8.get(null, pValue)); return true; } } else if (type.getJavaType() == Float.class) { if (format == Value.FORMAT_FLOAT4) { BufferUtils.writeUB4(buffer, Float.floatToIntBits(Float4.get(null, pValue))); return true; } } else if (type.getJavaType() == Double.class) { if (format == Value.FORMAT_FLOAT4) { BufferUtils.writeLongLong(buffer, Double.doubleToLongBits(Float8.get(null, pValue))); return true; } } return false; }
From source file:byps.test.TestUtils.java
private static boolean compare(PrimitiveTypes lhs, PrimitiveTypes rhs) { if (lhs == rhs) return true; if (rhs == null) return false; if (lhs.boolVal != rhs.boolVal) return false; if (lhs.byteVal != rhs.byteVal) return false; if (lhs.charVal != rhs.charVal) return false; if (Double.doubleToLongBits(lhs.doubleVal) != Double.doubleToLongBits(rhs.doubleVal)) return false; if (Float.floatToIntBits(lhs.floatVal) != Float.floatToIntBits(rhs.floatVal)) return false; if (lhs.intVal != rhs.intVal) return false; if (lhs.longVal != rhs.longVal) return false; if (lhs.shortVal != rhs.shortVal) return false; if (!(lhs.stringVal != null ? lhs.stringVal : "").equals(rhs.stringVal != null ? rhs.stringVal : "")) return false; return true;//from w w w .j ava 2 s.c om }
From source file:org.jahia.services.render.filter.AbstractFilter.java
@Override public int hashCode() { int result = this.getClass().getName().hashCode(); result = 31 * result + Float.floatToIntBits(priority); return result; }
From source file:org.apache.nutch.crawl.CrawlDatum.java
public int hashCode() { int res = 0;//from w w w. ja va 2s.c o m if (signature != null) { for (int i = 0; i < signature.length / 4; i += 4) { res ^= (signature[i] << 24 + signature[i + 1] << 16 + signature[i + 2] << 8 + signature[i + 3]); } } if (metaData != null) { res ^= metaData.entrySet().hashCode(); } return res ^ status ^ ((int) fetchTime) ^ ((int) modifiedTime) ^ retries ^ fetchInterval ^ Float.floatToIntBits(score); }
From source file:com.antsdb.saltedfish.server.mysql.PacketEncoder.java
private void writeValueSlow(ByteBuf buffer, FieldMeta meta, long pValue) { Object value = FishObject.get(null, pValue); DataType type = meta.getType();/* w w w.j av a 2s . co m*/ if (type.getSqlType() == Types.TINYINT) { buffer.writeByte((Integer) value); } else if (type.getJavaType() == Integer.class) { BufferUtils.writeUB4(buffer, (Integer) value); } else if (type.getJavaType() == Long.class) { BufferUtils.writeLongLong(buffer, (Long) value); } else if (type.getJavaType() == Float.class) { BufferUtils.writeUB4(buffer, Float.floatToIntBits((Float) value)); } else if (type.getJavaType() == Double.class) { BufferUtils.writeLongLong(buffer, Double.doubleToLongBits((Double) value)); } else if (type.getJavaType() == Timestamp.class) { BufferUtils.writeTimestamp(buffer, (Timestamp) value); } else if (type.getJavaType() == Date.class) { BufferUtils.writeDate(buffer, (Date) value); } else if (type.getJavaType() == byte[].class) { BufferUtils.writeWithLength(buffer, (byte[]) value); } else { BufferUtils.writeLenString(buffer, value.toString(), this.cs); } }
From source file:byps.test.TestUtils.java
private static boolean compare(Matrix2D lhs, Matrix2D rhs) { if (lhs == rhs) return true; if (rhs == null) return false; if (lhs.getClass() != rhs.getClass()) return false; Matrix2D other = (Matrix2D) rhs;//from w w w .jav a 2 s . co m if (Float.floatToIntBits(lhs._11) != Float.floatToIntBits(other._11)) return false; if (Float.floatToIntBits(lhs._12) != Float.floatToIntBits(other._12)) return false; if (Float.floatToIntBits(lhs._13) != Float.floatToIntBits(other._13)) return false; if (Float.floatToIntBits(lhs._21) != Float.floatToIntBits(other._21)) return false; if (Float.floatToIntBits(lhs._22) != Float.floatToIntBits(other._22)) return false; if (Float.floatToIntBits(lhs._23) != Float.floatToIntBits(other._23)) return false; if (Float.floatToIntBits(lhs._31) != Float.floatToIntBits(other._31)) return false; if (Float.floatToIntBits(lhs._32) != Float.floatToIntBits(other._32)) return false; if (Float.floatToIntBits(lhs._33) != Float.floatToIntBits(other._33)) return false; return true; }
From source file:org.freedesktop.dbus.Message.java
/** * Appends a value to the message.//from ww w. ja va 2 s . c o m * The type of the value is read from a D-Bus signature and used to marshall * the value. * * @param sigb * A buffer of the D-Bus signature. * @param sigofs * The offset into the signature corresponding to this value. * @param data * The value to marshall. * @return The offset into the signature of the end of this value's type. */ @SuppressWarnings("unchecked") private int appendone(byte[] sigb, int sigofs, Object data) throws DBusException { try { int i = sigofs; if (log.isTraceEnabled()) { log.trace(this.bytecounter); log.trace("Appending type: " + ((char) sigb[i]) + " value: " + data); } // pad to the alignment of this type. pad(sigb[i]); switch (sigb[i]) { case ArgumentType.BYTE: appendByte(((Number) data).byteValue()); break; case ArgumentType.BOOLEAN: appendint(((Boolean) data).booleanValue() ? 1 : 0, 4); break; case ArgumentType.DOUBLE: long l = Double.doubleToLongBits(((Number) data).doubleValue()); appendint(l, 8); break; case ArgumentType.FLOAT: int rf = Float.floatToIntBits(((Number) data).floatValue()); appendint(rf, 4); break; case ArgumentType.UINT32: appendint(((Number) data).longValue(), 4); break; case ArgumentType.INT64: appendint(((Number) data).longValue(), 8); break; case ArgumentType.UINT64: if (this.big) { appendint(((UInt64) data).top(), 4); appendint(((UInt64) data).bottom(), 4); } else { appendint(((UInt64) data).bottom(), 4); appendint(((UInt64) data).top(), 4); } break; case ArgumentType.INT32: appendint(((Number) data).intValue(), 4); break; case ArgumentType.UINT16: appendint(((Number) data).intValue(), 2); break; case ArgumentType.INT16: appendint(((Number) data).shortValue(), 2); break; case ArgumentType.STRING: case ArgumentType.OBJECT_PATH: // Strings are marshalled as a UInt32 with the length, // followed by the String, followed by a null byte. String payload = data.toString(); byte[] payloadbytes = null; try { payloadbytes = payload.getBytes("UTF-8"); } catch (UnsupportedEncodingException UEe) { throw new DBusException("System does not support UTF-8 encoding", UEe); } if (log.isTraceEnabled()) { log.trace("Appending String of length " + payloadbytes.length); } appendint(payloadbytes.length, 4); appendBytes(payloadbytes); appendBytes(padding[1]); // pad(ArgumentType.STRING);? do we need this? break; case ArgumentType.SIGNATURE: // Signatures are marshalled as a byte with the length, // followed by the String, followed by a null byte. // Signatures are generally short, so preallocate the array // for the string, length and null byte. if (data instanceof Type[]) payload = Marshalling.getDBusType((Type[]) data); else payload = (String) data; byte[] pbytes = payload.getBytes(); preallocate(2 + pbytes.length); appendByte((byte) pbytes.length); appendBytes(pbytes); appendByte((byte) 0); break; case ArgumentType.ARRAY: // Arrays are given as a UInt32 for the length in bytes, // padding to the element alignment, then elements in // order. The length is the length from the end of the // initial padding to the end of the last element. if (log.isTraceEnabled()) { if (data instanceof Object[]) log.trace("Appending array: " + Arrays.deepToString((Object[]) data)); } byte[] alen = new byte[4]; appendBytes(alen); pad(sigb[++i]); long c = this.bytecounter; // optimise primatives if (data.getClass().isArray() && data.getClass().getComponentType().isPrimitive()) { byte[] primbuf; int algn = getAlignment(sigb[i]); int len = Array.getLength(data); switch (sigb[i]) { case ArgumentType.BYTE: primbuf = (byte[]) data; break; case ArgumentType.INT16: case ArgumentType.INT32: case ArgumentType.INT64: primbuf = new byte[len * algn]; for (int j = 0, k = 0; j < len; j++, k += algn) marshallint(Array.getLong(data, j), primbuf, k, algn); break; case ArgumentType.BOOLEAN: primbuf = new byte[len * algn]; for (int j = 0, k = 0; j < len; j++, k += algn) marshallint(Array.getBoolean(data, j) ? 1 : 0, primbuf, k, algn); break; case ArgumentType.DOUBLE: primbuf = new byte[len * algn]; if (data instanceof float[]) for (int j = 0, k = 0; j < len; j++, k += algn) marshallint(Double.doubleToRawLongBits(((float[]) data)[j]), primbuf, k, algn); else for (int j = 0, k = 0; j < len; j++, k += algn) marshallint(Double.doubleToRawLongBits(((double[]) data)[j]), primbuf, k, algn); break; case ArgumentType.FLOAT: primbuf = new byte[len * algn]; for (int j = 0, k = 0; j < len; j++, k += algn) marshallint(Float.floatToRawIntBits(((float[]) data)[j]), primbuf, k, algn); break; default: throw new MarshallingException("Primative array being sent as non-primative array."); } appendBytes(primbuf); } else if (data instanceof List) { Object[] contents = ((List<Object>) data).toArray(); int diff = i; ensureBuffers(contents.length * 4); for (Object o : contents) diff = appendone(sigb, i, o); i = diff; } else if (data instanceof Map) { int diff = i; ensureBuffers(((Map<Object, Object>) data).size() * 6); for (Map.Entry<Object, Object> o : ((Map<Object, Object>) data).entrySet()) diff = appendone(sigb, i, o); if (i == diff) { // advance the type parser even on 0-size arrays. Vector<Type> temp = new Vector<>(); byte[] temp2 = new byte[sigb.length - diff]; System.arraycopy(sigb, diff, temp2, 0, temp2.length); String temp3 = new String(temp2); int temp4 = Marshalling.getJavaType(temp3, temp, 1); diff += temp4; } i = diff; } else { Object[] contents = (Object[]) data; ensureBuffers(contents.length * 4); int diff = i; for (Object o : contents) diff = appendone(sigb, i, o); i = diff; } if (log.isTraceEnabled()) { log.trace("start: " + c + " end: " + this.bytecounter + " length: " + (this.bytecounter - c)); } marshallint(this.bytecounter - c, alen, 0, 4); break; case ArgumentType.STRUCT1: // Structs are aligned to 8 bytes // and simply contain each element marshalled in order Object[] contents; if (data instanceof Container) contents = ((Container) data).getParameters(); else contents = (Object[]) data; ensureBuffers(contents.length * 4); int j = 0; for (i++; sigb[i] != ArgumentType.STRUCT2; i++) i = appendone(sigb, i, contents[j++]); break; case ArgumentType.DICT_ENTRY1: // Dict entries are the same as structs. if (data instanceof Map.Entry) { i++; i = appendone(sigb, i, ((Map.Entry<Object, Object>) data).getKey()); i++; i = appendone(sigb, i, ((Map.Entry<Object, Object>) data).getValue()); i++; } else { contents = (Object[]) data; j = 0; for (i++; sigb[i] != ArgumentType.DICT_ENTRY2; i++) i = appendone(sigb, i, contents[j++]); } break; case ArgumentType.VARIANT: // Variants are marshalled as a signature // followed by the value. if (data instanceof Variant) { Variant<?> var = (Variant<?>) data; appendone(new byte[] { ArgumentType.SIGNATURE }, 0, var.getSig()); appendone((var.getSig()).getBytes(), 0, var.getValue()); } else if (data instanceof Object[]) { contents = (Object[]) data; appendone(new byte[] { ArgumentType.SIGNATURE }, 0, contents[0]); appendone(((String) contents[0]).getBytes(), 0, contents[1]); } else { String sig = Marshalling.getDBusType(data.getClass())[0]; appendone(new byte[] { ArgumentType.SIGNATURE }, 0, sig); appendone((sig).getBytes(), 0, data); } break; } return i; } catch (ClassCastException CCe) { throw new MarshallingException( String.format("Trying to marshall to unconvertable type (from %s to %s).", data.getClass().getName(), sigb[sigofs]), CCe); } }
From source file:org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.java
public static int hashCode(Object o, ObjectInspector objIns) { if (o == null) { return 0; }// w ww . j av a 2 s . c o m switch (objIns.getCategory()) { case PRIMITIVE: { PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) objIns); switch (poi.getPrimitiveCategory()) { case VOID: return 0; case BOOLEAN: return ((BooleanObjectInspector) poi).get(o) ? 1 : 0; case BYTE: return ((ByteObjectInspector) poi).get(o); case SHORT: return ((ShortObjectInspector) poi).get(o); case INT: return ((IntObjectInspector) poi).get(o); case LONG: { long a = ((LongObjectInspector) poi).get(o); return (int) ((a >>> 32) ^ a); } case FLOAT: return Float.floatToIntBits(((FloatObjectInspector) poi).get(o)); case DOUBLE: { // This hash function returns the same result as Double.hashCode() // while DoubleWritable.hashCode returns a different result. long a = Double.doubleToLongBits(((DoubleObjectInspector) poi).get(o)); return (int) ((a >>> 32) ^ a); } case STRING: { // This hash function returns the same result as String.hashCode() when // all characters are ASCII, while Text.hashCode() always returns a // different result. Text t = ((StringObjectInspector) poi).getPrimitiveWritableObject(o); int r = 0; for (int i = 0; i < t.getLength(); i++) { r = r * 31 + t.getBytes()[i]; } return r; } case CHAR: return ((HiveCharObjectInspector) poi).getPrimitiveWritableObject(o).hashCode(); case VARCHAR: return ((HiveVarcharObjectInspector) poi).getPrimitiveWritableObject(o).hashCode(); case BINARY: return ((BinaryObjectInspector) poi).getPrimitiveWritableObject(o).hashCode(); case DATE: return ((DateObjectInspector) poi).getPrimitiveWritableObject(o).hashCode(); case TIMESTAMP: TimestampWritable t = ((TimestampObjectInspector) poi).getPrimitiveWritableObject(o); return t.hashCode(); case INTERVAL_YEAR_MONTH: HiveIntervalYearMonthWritable intervalYearMonth = ((HiveIntervalYearMonthObjectInspector) poi) .getPrimitiveWritableObject(o); return intervalYearMonth.hashCode(); case INTERVAL_DAY_TIME: HiveIntervalDayTimeWritable intervalDayTime = ((HiveIntervalDayTimeObjectInspector) poi) .getPrimitiveWritableObject(o); return intervalDayTime.hashCode(); case DECIMAL: return ((HiveDecimalObjectInspector) poi).getPrimitiveWritableObject(o).hashCode(); default: { throw new RuntimeException("Unknown type: " + poi.getPrimitiveCategory()); } } } case LIST: { int r = 0; ListObjectInspector listOI = (ListObjectInspector) objIns; ObjectInspector elemOI = listOI.getListElementObjectInspector(); for (int ii = 0; ii < listOI.getListLength(o); ++ii) { r = 31 * r + hashCode(listOI.getListElement(o, ii), elemOI); } return r; } case MAP: { int r = 0; MapObjectInspector mapOI = (MapObjectInspector) objIns; ObjectInspector keyOI = mapOI.getMapKeyObjectInspector(); ObjectInspector valueOI = mapOI.getMapValueObjectInspector(); Map<?, ?> map = mapOI.getMap(o); for (Map.Entry<?, ?> entry : map.entrySet()) { r += hashCode(entry.getKey(), keyOI) ^ hashCode(entry.getValue(), valueOI); } return r; } case STRUCT: int r = 0; StructObjectInspector structOI = (StructObjectInspector) objIns; List<? extends StructField> fields = structOI.getAllStructFieldRefs(); for (StructField field : fields) { r = 31 * r + hashCode(structOI.getStructFieldData(o, field), field.getFieldObjectInspector()); } return r; case UNION: UnionObjectInspector uOI = (UnionObjectInspector) objIns; byte tag = uOI.getTag(o); return hashCode(uOI.getField(o), uOI.getObjectInspectors().get(tag)); default: throw new RuntimeException("Unknown type: " + objIns.getTypeName()); } }
From source file:tds.assessment.Segment.java
@Override public int hashCode() { int result = key != null ? key.hashCode() : 0; result = 31 * result + (label != null ? label.hashCode() : 0); result = 31 * result + (selectionAlgorithm != null ? selectionAlgorithm.hashCode() : 0); result = 31 * result + (segmentId != null ? segmentId.hashCode() : 0); result = 31 * result + (startAbility != +0.0f ? Float.floatToIntBits(startAbility) : 0); result = 31 * result + (subject != null ? subject.hashCode() : 0); result = 31 * result + (assessmentKey != null ? assessmentKey.hashCode() : 0); result = 31 * result + position;//from ww w .j a va 2s .c om result = 31 * result + minItems; result = 31 * result + maxItems; result = 31 * result + fieldTestMinItems; result = 31 * result + fieldTestMaxItems; result = 31 * result + (fieldTestStartDate != null ? fieldTestStartDate.hashCode() : 0); result = 31 * result + (fieldTestEndDate != null ? fieldTestEndDate.hashCode() : 0); result = 31 * result + fieldTestStartPosition; result = 31 * result + fieldTestEndPosition; result = 31 * result + refreshMinutes; result = 31 * result + (blueprintWeight != +0.0f ? Float.floatToIntBits(blueprintWeight) : 0); result = 31 * result + (itemWeight != +0.0f ? Float.floatToIntBits(itemWeight) : 0); result = 31 * result + (abilityOffset != +0.0f ? Float.floatToIntBits(abilityOffset) : 0); result = 31 * result + candidateSet1Size; result = 31 * result + (candidateSet1Order != null ? candidateSet1Order.hashCode() : 0); result = 31 * result + randomizer; result = 31 * result + initialRandom; result = 31 * result + (abilityWeight != +0.0f ? Float.floatToIntBits(abilityWeight) : 0); result = 31 * result + (adaptiveVersion != null ? adaptiveVersion.hashCode() : 0); result = 31 * result + (reportingCandidateAbilityWeight != +0.0f ? Float.floatToIntBits(reportingCandidateAbilityWeight) : 0); result = 31 * result + (precisionTarget != +0.0f ? Float.floatToIntBits(precisionTarget) : 0); result = 31 * result + (precisionTargetMetWeight != +0.0f ? Float.floatToIntBits(precisionTargetMetWeight) : 0); result = 31 * result + (precisionTargetNotMetWeight != +0.0f ? Float.floatToIntBits(precisionTargetNotMetWeight) : 0); result = 31 * result + (adaptiveCut != +0.0f ? Float.floatToIntBits(adaptiveCut) : 0); result = 31 * result + (tooCloseStandardErrors != +0.0f ? Float.floatToIntBits(tooCloseStandardErrors) : 0); result = 31 * result + (terminationOverallInformation ? 1 : 0); result = 31 * result + (terminationReportingCategoryInfo ? 1 : 0); result = 31 * result + (terminationMinCount ? 1 : 0); result = 31 * result + (terminationTooClose ? 1 : 0); result = 31 * result + (terminationFlagsAnd ? 1 : 0); result = 31 * result + (slope != +0.0f ? Float.floatToIntBits(slope) : 0); result = 31 * result + (intercept != +0.0f ? Float.floatToIntBits(intercept) : 0); result = 31 * result + (forms != null ? forms.hashCode() : 0); result = 31 * result + (strands != null ? strands.hashCode() : 0); result = 31 * result + (items != null ? items.hashCode() : 0); return result; }
From source file:com.milaboratory.core.alignment.KAlignerParameters.java
@Override public int hashCode() { int result = mapperKValue; result = 31 * result + (floatingLeftBound ? 1 : 0); result = 31 * result + (floatingRightBound ? 1 : 0); result = 31 * result + (mapperAbsoluteMinScore != +0.0f ? Float.floatToIntBits(mapperAbsoluteMinScore) : 0); result = 31 * result + (mapperRelativeMinScore != +0.0f ? Float.floatToIntBits(mapperRelativeMinScore) : 0); result = 31 * result + (mapperMatchScore != +0.0f ? Float.floatToIntBits(mapperMatchScore) : 0); result = 31 * result + (mapperMismatchPenalty != +0.0f ? Float.floatToIntBits(mapperMismatchPenalty) : 0); result = 31 * result//from www. j a va 2 s .co m + (mapperOffsetShiftPenalty != +0.0f ? Float.floatToIntBits(mapperOffsetShiftPenalty) : 0); result = 31 * result + minAlignmentLength; result = 31 * result + maxAdjacentIndels; result = 31 * result + mapperMinSeedsDistance; result = 31 * result + mapperMaxSeedsDistance; result = 31 * result + alignmentStopPenalty; result = 31 * result + scoring.hashCode(); return result; }