@Test public void testMultiSet() { HashMultiset<Integer> multiset = HashMultiset.create(); multiset.add(1); multiset.add(1); multiset.add(2); multiset.add(2); multiset.add(4); multiset.add(4); multiset.add(4); Assert.assertTrue(multiset.size() == 7); Assert.assertTrue(multiset.contains(4)); Assert.assertTrue(multiset.count(4) == 3); multiset.add(4, 5); Assert.assertTrue(multiset.count(4) == 8); }
/** * Appends the body of skeleton test code, that is, only html tag fields and getter methods to * retrieve the values of the variables into the given string builder. * * @param builder {@link StringBuilder} the generated test code will be appended to * @param templateInfo the {@link TemplateInfo} of the template whose skeleton test code we want * to generate */ private void appendFieldsAndGetters(StringBuilder builder, TemplateInfo templateInfo) { // Create new StringBuilder to separate methods group from fields group such // as "private int field1; private int field2; // private void method1() {} private void method2() {}". StringBuilder methodBuilder = new StringBuilder(); HashMultiset<String> varNameCounter = HashMultiset.create(); appendLine( builder, 1, "private static Pattern commentPattern = Pattern.compile(\"<!--POGEN,([^,]*),([^,]*),(.*?)-->\", Pattern.DOTALL);"); for (HtmlTagInfo tagInfo : templateInfo.getHtmlTagInfos()) { // Skip this variable if it has no parent html tag // TODO(kazuu): Deal with these variable with a more proper way if (!tagInfo.hasParentTag()) { continue; } String attrValue = tagInfo.getAttributeValue(); boolean isRepeated = tagInfo.isRepeated(); for (VariableInfo varInfo : tagInfo.getVariableInfos()) { // When the same template variable appears in other html tags, // varIndex > 1 is satisfied varNameCounter.add(varInfo.getName()); int varIndex = varNameCounter.count(varInfo.getName()); String newVarName = varInfo.getName() + convertToString(varIndex); appendElementGetter(builder, methodBuilder, newVarName, attrValue, isRepeated); if (!varInfo.isManipulableTag()) { appendTextGetter(methodBuilder, newVarName, tagInfo, varInfo, isRepeated); } for (String attrName : varInfo.getSortedAttributeNames()) { appendAttributeGetter(methodBuilder, newVarName, attrName, attrValue, isRepeated); } } } // Append method definitions after field definitions builder.append(methodBuilder); }
@BeforeExperiment void setUp() { hashMultiset = HashMultiset.create(size); linkedHashMultiset = LinkedHashMultiset.create(size); treeMultiset = TreeMultiset.create(); Random random = new Random(); int sizeRemaining = size; // TODO(kevinb): generate better test contents for multisets for (int i = 0; sizeRemaining > 0; i++) { // The JVM will return interned values for small ints. Integer value = random.nextInt(1000) + 128; int count = Math.min(random.nextInt(10) + 1, sizeRemaining); sizeRemaining -= count; hashMultiset.add(value, count); linkedHashMultiset.add(value, count); treeMultiset.add(value, count); } // TODO(kevinb): convert to assert once benchmark tests enable asserts by default Preconditions.checkState(hashMultiset.size() == size); }
public void updateMapData(World par1World, Entity par2Entity, MapData par3MapData) { if (par1World.provider.dimensionId == par3MapData.dimension && par2Entity instanceof EntityPlayer) { int var4 = 1 << par3MapData.scale; int var5 = par3MapData.xCenter; int var6 = par3MapData.zCenter; int var7 = MathHelper.floor_double(par2Entity.posX - (double) var5) / var4 + 64; int var8 = MathHelper.floor_double(par2Entity.posZ - (double) var6) / var4 + 64; int var9 = 128 / var4; if (par1World.provider.hasNoSky) { var9 /= 2; } MapData.MapInfo var10 = par3MapData.func_82568_a((EntityPlayer) par2Entity); ++var10.field_82569_d; for (int var11 = var7 - var9 + 1; var11 < var7 + var9; ++var11) { if ((var11 & 15) == (var10.field_82569_d & 15)) { int var12 = 255; int var13 = 0; double var14 = 0.0D; for (int var16 = var8 - var9 - 1; var16 < var8 + var9; ++var16) { if (var11 >= 0 && var16 >= -1 && var11 < 128 && var16 < 128) { int var17 = var11 - var7; int var18 = var16 - var8; boolean var19 = var17 * var17 + var18 * var18 > (var9 - 2) * (var9 - 2); int var20 = (var5 / var4 + var11 - 64) * var4; int var21 = (var6 / var4 + var16 - 64) * var4; HashMultiset var22 = HashMultiset.create(); Chunk var23 = par1World.getChunkFromBlockCoords(var20, var21); if (!var23.isEmpty()) { int var24 = var20 & 15; int var25 = var21 & 15; int var26 = 0; double var27 = 0.0D; int var29; if (par1World.provider.hasNoSky) { var29 = var20 + var21 * 231871; var29 = var29 * var29 * 31287121 + var29 * 11; if ((var29 >> 20 & 1) == 0) { var22.add(Blocks.dirt.getMapColor(0), 10); } else { var22.add(Blocks.stone.getMapColor(0), 100); } var27 = 100.0D; } else { for (var29 = 0; var29 < var4; ++var29) { for (int var30 = 0; var30 < var4; ++var30) { int var31 = var23.getHeightValue(var29 + var24, var30 + var25) + 1; Block var32 = Blocks.air; int var33 = 0; if (var31 > 1) { do { --var31; var32 = var23.func_150810_a(var29 + var24, var31, var30 + var25); var33 = var23.getBlockMetadata(var29 + var24, var31, var30 + var25); } while (var32.getMapColor(var33) == MapColor.field_151660_b && var31 > 0); if (var31 > 0 && var32.getMaterial().isLiquid()) { int var34 = var31 - 1; Block var35; do { var35 = var23.func_150810_a(var29 + var24, var34--, var30 + var25); ++var26; } while (var34 > 0 && var35.getMaterial().isLiquid()); } } var27 += (double) var31 / (double) (var4 * var4); var22.add(var32.getMapColor(var33)); } } } var26 /= var4 * var4; double var36 = (var27 - var14) * 4.0D / (double) (var4 + 4) + ((double) (var11 + var16 & 1) - 0.5D) * 0.4D; byte var39 = 1; if (var36 > 0.6D) { var39 = 2; } if (var36 < -0.6D) { var39 = 0; } MapColor var38 = (MapColor) Iterables.getFirst( Multisets.copyHighestCountFirst(var22), MapColor.field_151660_b); if (var38 == MapColor.field_151662_n) { var36 = (double) var26 * 0.1D + (double) (var11 + var16 & 1) * 0.2D; var39 = 1; if (var36 < 0.5D) { var39 = 2; } if (var36 > 0.9D) { var39 = 0; } } var14 = var27; if (var16 >= 0 && var17 * var17 + var18 * var18 < var9 * var9 && (!var19 || (var11 + var16 & 1) != 0)) { byte var37 = par3MapData.colors[var11 + var16 * 128]; byte var40 = (byte) (var38.colorIndex * 4 + var39); if (var37 != var40) { if (var12 > var16) { var12 = var16; } if (var13 < var16) { var13 = var16; } par3MapData.colors[var11 + var16 * 128] = var40; } } } } } if (var12 <= var13) { par3MapData.setColumnDirty(var11, var12, var13); } } } } }