List of usage examples for com.google.common.primitives UnsignedInts remainder
@CheckReturnValue public static int remainder(int dividend, int divisor)
From source file:se.sics.caracaldb.utils.ByteArrayFormatter.java
public static byte[] fromHexString(String str) { if (str.equals("(null)")) { return null; }//from ww w .j av a2s . com if (str.equals("")) { return new byte[0]; } String nospacestr = str.replaceAll("\\s", ""); // take away spaces if (UnsignedInts.remainder(nospacestr.length(), 2) != 0) { throw new NumberFormatException("String should contain only pairs of [0-F] (should be even)!"); } int expectedLength = nospacestr.length() / 2; String[] byteBlocks = nospacestr.split("(?<=\\G.{2})"); // split in parts of length 2 if (expectedLength != byteBlocks.length) { System.out.println("Blocks: " + Arrays.toString(byteBlocks)); throw new NumberFormatException("String should contain only pairs of [0-F]!"); } byte[] bytes = new byte[byteBlocks.length]; for (int i = 0; i < bytes.length; i++) { bytes[i] = UnsignedBytes.parseUnsignedByte(byteBlocks[i], 16); } return bytes; }
From source file:se.sics.caracaldb.global.LookupTable.java
private Set<Integer> findReplicationSetSizes() { Set<Integer> sizes = new TreeSet<Integer>(); for (Entry<ByteBuffer, ImmutableMap<String, String>> e : schemas.metaData.entrySet()) { ByteBuffer id = e.getKey(); ImmutableMap<String, String> meta = e.getValue(); String rfS = J6.orDefault(meta.get("rfactor"), "3"); Integer rf = Integer.parseInt(rfS); String forceMasterS = J6.orDefault(meta.get("forceMaster"), "false"); boolean forceMaster = Boolean.parseBoolean(forceMasterS); if (forceMaster) { // they better all have the same rfactor or weird things are going to happen^^ masterRepSize = rf;// w ww.ja v a 2s. c o m } sizes.add(rf); if (UnsignedInts.remainder(rf, 2) == 0) { BootstrapServer.LOG.warn( "Schema {} uses a replication factor of {}. " + "It is recommended to use uneven factors.", schemas.schemaNames.get(id), rf); } if (rf < 3) { throw new RuntimeException("Replication factor for any schema must be >=3!"); } if (rf > hosts.size()) { throw new RuntimeException( "Replication factor for any schema can't be larger than the initial number of hosts!" + "If you think you have enough hosts for rf=" + rf + " consider incrementing the value of caraca.bootThreshold."); } } if (masterRepSize < 0) { // in case there are no forceMaster schemata masterRepSize = 3; } return sizes; }