List of usage examples for java.lang StringBuilder hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:org.loklak.geo.GeoMark.java
public GeoMark(final GeoLocation loc, final String salt) { super(loc.lat(), loc.lon(), loc.getNames(), loc.getISO3166cc()); super.setPopulation(loc.getPopulation()); // using the population, we compute a location radius // example city: middle-high density city (10,000 persons per square kilometer) // a large city in that density is Seoul, South Korea: 23,480,000 persons on 2,266 square kilometer // a circle with the area of 1 km^2 has the radius: // double r = Math.sqrt(1000000 / Math.PI); // meter // the radius required to hold the population is double r = Math.sqrt(loc.getPopulation() * 1000000 / 10000 / Math.PI); // meter // we don't compute a random number for the actual fuzzy location of the marker // to make this reproducible, we use a hash of the name and location StringBuilder hs = new StringBuilder(40); hs.append(loc.getNames().iterator().next()); hs.append(loc.lat());//from w w w . jav a2 s .c o m hs.append(loc.lon()); hs.append(salt); int h = Math.abs(hs.hashCode()); if (h == Integer.MIN_VALUE) h = 0; // correction of the case that Math.abs is not possible // with that hash we compute an actual distance and an angle double dist = (h & 0xff) * r / 255.0d / 40000000 * 360; // 40 million meter (the earth) has an angle of 360 degree double angle = 2 * Math.PI * ((double) ((h & 0xfff00) >> 8)) / ((double) 0xfff); // now compute a point around the location on a circle for the mark this.mlat = this.lat() + Math.sin(angle) * dist; this.mlon = this.lon() + Math.cos(angle) * dist; }
From source file:com.aliyun.datahub.flume.sink.RecordBuilder.java
public RecordEntry buildRecord(Map<String, String> rowData) throws ParseException { RecordEntry recordEntry = new RecordEntry(topic.getRecordSchema()); for (Map.Entry<String, String> mapEntry : rowData.entrySet()) { String fieldName = mapEntry.getKey(); if (!columnMappings.containsKey(fieldName)) { throw new RuntimeException("field name: " + fieldName + " not existed in datahub!"); }/*from www.j av a 2 s .co m*/ Field field = columnMappings.get(fieldName); RecordUtil.setFieldValue(recordEntry, field, false, mapEntry.getValue(), columnDateformatMappings.containsKey(fieldName), dateFormat, configure.isBlankValueAsNull()); } if (columnShardMappings.size() > 0) { StringBuilder hashKey = new StringBuilder(); for (String col : configure.getShardColumnNames()) { hashKey.append(rowData.get(col)); } int hashCode = hashKey.hashCode() & Integer.MAX_VALUE; recordEntry.setShardId(shardIds.get(hashCode % shardIds.size())); } return recordEntry; }