String key = "Huh"; //$NON-NLS-1$ float totalWeight = 0.0f; RatEntry re = new RatEntry(); String line = null; while (null != (line = reader.readLine())) { continue; re.getUnits().add(name.intern()); re.getWeights().add(weight); totalWeight += weight; if (re.getUnits().size() > 0) { for (int i = 0; i < re.getWeights().size(); i++) { re.getWeights().set(i, re.getWeights().get(i) / totalWeight);
RatEntry(){ setUnits(new Vector<String>()); setWeights(new Vector<Float>()); }
testWeights.add(0.1F); RandomUnitGenerator.RatEntry mockRatEntry = Mockito.mock(RandomUnitGenerator.RatEntry.class); Mockito.when(mockRatEntry.getUnits()).thenReturn(testUnits); Mockito.when(mockRatEntry.getWeights()).thenReturn(testWeights); testRug.addRat("mockRat", mockRatEntry); otherWeights.add(0.2F); RandomUnitGenerator.RatEntry mockOtherRat = Mockito.mock(RandomUnitGenerator.RatEntry.class); Mockito.when(mockOtherRat.getUnits()).thenReturn(otherUnits); Mockito.when(mockOtherRat.getWeights()).thenReturn(otherWeights); testRug.addRat("Other RAT", mockOtherRat);
RatEntry re = ratMap.get(ratName); if (filter != null) { RatEntry filtered = new RatEntry(); float totalWeight = 0.0f; MechSummaryCache msc = MechSummaryCache.getInstance(); for (int i = 0; i < re.getUnits().size(); i++) { if (!re.getUnits().get(i).startsWith("@")) { MechSummary ms = msc.getMech(re.getUnits().get(i)); if (ms == null || !filter.test(ms)) { continue; filtered.getUnits().add(re.getUnits().get(i)); filtered.getWeights().add(re.getWeights().get(i)); totalWeight += re.getWeights().get(i); for (int i = 0; i < filtered.getWeights().size(); i++) { filtered.getWeights().set(i, filtered.getWeights().get(i) / totalWeight); if ((null != re) && (re.getUnits().size() > 0)) { for (int roll = 0; roll < numRolls; roll++) { double rand = getRandom(); int i = 0; while (i < re.getWeights().size() && rand > re.getWeights().get(i)) { rand -= re.getWeights().get(i); i++; String name = re.getUnits().get(i);