List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Process the gst rates for a summary.//from w w w .j a v a2 s . c o m * * @param summary the summary * @return the collection */ private final Collection<RevenueBean> processGSTRates(final Collection<RevenueBean> summary) { final Collection<RevenueBean> results = new ArrayList<RevenueBean>(); final TreeMap<Double, Double> gstRates = new TreeMap<Double, Double>(); // Construct a map with all of the GST rates that are used for (RevenueBean revenue : summary) { for (Double gstRate : revenue.getGSTValues().keySet()) { gstRates.put(gstRate, 0.0); } } // Build a new results collection with the correct number of GST rates for (RevenueBean revenue : summary) { for (Double gstRate : gstRates.keySet()) { // If the GST rate is not part of the revenue analysis add it with 0 value if (!revenue.getGSTValues().containsKey(gstRate)) { revenue.setGSTValue(gstRate, 0.0); } } results.add(revenue); } return results; }
From source file:com.vgi.mafscaling.Rescale.java
private void calculateNewGs(ArrayList<Double> newVoltArray, ArrayList<Double> newGsArray) { TreeMap<Double, Integer> vgsTree = new TreeMap<Double, Integer>(); for (int i = origVoltArray.size() - 1; i >= 0; --i) vgsTree.put(origVoltArray.get(i), i); Map.Entry<Double, Integer> kv; double x0, y0, x, y, x1, y1; for (int i = 1; i < newVoltArray.size(); ++i) { x = newVoltArray.get(i);/*from w w w . j a v a 2 s . c o m*/ kv = vgsTree.floorEntry(x); if (kv == null) { newGsArray.add(0.0); continue; } x0 = kv.getKey(); if (x0 == x) { newGsArray.add(origGsArray.get(kv.getValue())); continue; } y0 = origGsArray.get(kv.getValue()); kv = vgsTree.ceilingEntry(x); if (kv == null) { newGsArray.add(0.0); continue; } x1 = kv.getKey(); y1 = origGsArray.get(kv.getValue()); y = Utils.linearInterpolation(x, x0, x1, y0, y1); newGsArray.add(y); } }
From source file:com.webcohesion.enunciate.modules.objc_client.ObjCXMLClientModule.java
@Override public void call(EnunciateContext context) { if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) { info("No JAXB XML data types: Objective-C XML client will not be generated."); return;// w w w .j a v a 2s. c om } if (usesUnmappableElements()) { warn("Web service API makes use of elements that cannot be handled by the Objective-C XML client. Objective-C XML client will not be generated."); return; } List<String> namingConflicts = JAXBErrors .findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext()); if (namingConflicts != null && !namingConflicts.isEmpty()) { error("JAXB naming conflicts have been found:"); for (String namingConflict : namingConflicts) { error(namingConflict); } error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:"); error("1. Explicitly exclude one or the other."); error("2. Put the annotations on the property instead of the field."); error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation."); throw new EnunciateException("JAXB naming conflicts detected."); } EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext(); Map<String, String> packageIdentifiers = getPackageIdentifiers(); String packageIdentifierPattern = getPackageIdentifierPattern(); if ((packageIdentifierPattern != null)) { for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { String pckg = typeDefinition.getPackage().getQualifiedName().toString(); if (!packageIdentifiers.containsKey(pckg)) { try { packageIdentifiers.put(pckg, String.format(packageIdentifierPattern, pckg.split("\\.", 9))); } catch (IllegalFormatException e) { warn("Unable to format package %s with format pattern %s (%s)", pckg, packageIdentifierPattern, e.getMessage()); } } } } } Map<String, Object> model = new HashMap<String, Object>(); String slug = getSlug(); model.put("slug", slug); File srcDir = getSourceDir(); TreeMap<String, String> translations = new TreeMap<String, String>(); translations.put("id", getTranslateIdTo()); model.put("clientSimpleName", new ClientSimpleNameMethod(translations)); List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>(); ExtensionDepthComparator comparator = new ExtensionDepthComparator(); for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator); if (position < 0) { position = -position - 1; } schemaTypes.add(position, typeDefinition); } } model.put("schemaTypes", schemaTypes); NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod( getTypeDefinitionNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers); model.put("nameForTypeDefinition", nameForTypeDefinition); model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers)); TreeMap<String, String> conversions = new TreeMap<String, String>(); for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { if (typeDefinition.isEnum()) { conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition)); } else { conversions.put(typeDefinition.getQualifiedName().toString(), (String) nameForTypeDefinition.calculateName(typeDefinition)); } } } ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext); model.put("classnameFor", classnameFor); model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition, jaxbContext)); model.put("objcBaseName", slug); model.put("separateCommonCode", isSeparateCommonCode()); model.put("findRootElement", new FindRootElementMethod(jaxbContext)); model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext)); model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes())); model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod()); model.put("file", new FileDirective(srcDir, this.enunciate.getLogger())); Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes()); facetIncludes.addAll(getFacetIncludes()); Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes()); facetExcludes.addAll(getFacetExcludes()); FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes); model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter)); if (!isUpToDateWithSources(srcDir)) { debug("Generating the C data structures and (de)serialization functions..."); URL apiTemplate = getTemplateURL("api.fmt"); try { processTemplate(apiTemplate, model); } catch (IOException e) { throw new EnunciateException(e); } catch (TemplateException e) { throw new EnunciateException(e); } } else { info("Skipping C code generation because everything appears up-to-date."); } ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "objc.client.library", "Objective C Client Library"); FileArtifact sourceHeader = new FileArtifact(getName(), "objc.client.h", new File(srcDir, slug + ".h")); sourceHeader.setPublic(false); sourceHeader.setArtifactType(ArtifactType.sources); FileArtifact sourceImpl = new FileArtifact(getName(), "objc.client.m", new File(srcDir, slug + ".m")); sourceImpl.setPublic(false); sourceImpl.setArtifactType(ArtifactType.sources); String description = readResource("library_description.fmt", model, nameForTypeDefinition); //read in the description from file artifactBundle.setDescription(description); artifactBundle.addArtifact(sourceHeader); artifactBundle.addArtifact(sourceImpl); if (isSeparateCommonCode()) { FileArtifact commonSourceHeader = new FileArtifact(getName(), "objc.common.client.h", new File(srcDir, "enunciate-common.h")); commonSourceHeader.setPublic(false); commonSourceHeader.setArtifactType(ArtifactType.sources); commonSourceHeader.setDescription("Common header needed for all projects."); FileArtifact commonSourceImpl = new FileArtifact(getName(), "objc.common.client.m", new File(srcDir, "enunciate-common.m")); commonSourceImpl.setPublic(false); commonSourceImpl.setArtifactType(ArtifactType.sources); commonSourceImpl.setDescription("Common implementation code needed for all projects."); artifactBundle.addArtifact(commonSourceHeader); artifactBundle.addArtifact(commonSourceImpl); } this.enunciate.addArtifact(artifactBundle); }
From source file:decision_tree_learning.Matrix.java
double mostCommonValue(int col) { TreeMap<Double, Integer> tm = new TreeMap<Double, Integer>(); for (int i = 0; i < rows(); i++) { double v = get(i, col); if (v != MISSING) { Integer count = tm.get(v); if (count == null) tm.put(v, new Integer(1)); else//from w w w .j a v a2 s . c om tm.put(v, new Integer(count.intValue() + 1)); } } int maxCount = 0; double val = MISSING; Iterator<Entry<Double, Integer>> it = tm.entrySet().iterator(); while (it.hasNext()) { Entry<Double, Integer> e = it.next(); if (e.getValue() > maxCount) { maxCount = e.getValue(); val = e.getKey(); } } return val; }
From source file:com.jci.utils.CommonUtils.java
/** * Gets the git json mapping./*from w w w. j av a 2 s. c o m*/ * * @param destName the dest name * @param jasonValue the jason value * @return the git json mapping * @throws JsonParseException the json parse exception * @throws JsonMappingException the json mapping exception * @throws IOException Signals that an I/O exception has occurred. */ public TreeMap<String, HashMap<Integer, String>> getGitJsonMapping(String destName, String jasonValue) throws JsonParseException, JsonMappingException, IOException { HashMap<Integer, String> map = null; ObjectMapper mapper = new ObjectMapper(); TreeMap<String, HashMap<Integer, String>> mappingList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); TypeReference<HashMap<Integer, String>> typeRef = new TypeReference<HashMap<Integer, String>>() { }; map = mapper.readValue(jasonValue, typeRef); mappingList.put(destName, map); return mappingList; }
From source file:com.sfs.whichdoctor.analysis.AgedDebtorsAnalysisDAOImpl.java
/** * Post process the aged debtors groupings. * * @param groupings the groupings/*from w w w . j av a 2s . c o m*/ * @param showZeroBalances the show zero balances * @return the tree map */ private TreeMap<String, AgedDebtorsGrouping> processGroups(final TreeMap<String, AgedDebtorsGrouping> groupings, final boolean showZeroBalances) { TreeMap<String, AgedDebtorsGrouping> processedGroupings = new TreeMap<String, AgedDebtorsGrouping>(); for (String groupName : groupings.keySet()) { AgedDebtorsGrouping group = groupings.get(groupName); TreeMap<String, AgedDebtorsRecord> records = new TreeMap<String, AgedDebtorsRecord>(); for (String orderKey : group.getRecords().keySet()) { AgedDebtorsRecord record = group.getRecords().get(orderKey); if (showZeroBalances || record.getTotal() != 0) { records.put(orderKey, record); for (int id : record.getPeriodBreakdown().keySet()) { AgedDebtorsPeriod period = record.getPeriodBreakdown().get(id); AgedDebtorsPeriod groupPeriod = group.getPeriodBreakdown(period); // Update the running totals for the period of the grouping groupPeriod.setOutstandingDebitValue( groupPeriod.getOutstandingDebitValue() + period.getOutstandingDebitValue()); groupPeriod.setUnallocatedRefundValue( groupPeriod.getUnallocatedRefundValue() + period.getUnallocatedRefundValue()); groupPeriod.setUnallocatedCreditValue( groupPeriod.getUnallocatedCreditValue() + period.getUnallocatedCreditValue()); groupPeriod.setUnallocatedReceiptValue( groupPeriod.getUnallocatedReceiptValue() + period.getUnallocatedReceiptValue()); group.getPeriodBreakdown().put(id, groupPeriod); } // Update the running totals for the grouping group.setOutstandingDebitValue( group.getOutstandingDebitValue() + record.getOutstandingDebitValue()); group.setUnallocatedRefundValue( group.getUnallocatedRefundValue() + record.getUnallocatedRefundValue()); group.setUnallocatedCreditValue( group.getUnallocatedCreditValue() + record.getUnallocatedCreditValue()); group.setUnallocatedReceiptValue( group.getUnallocatedReceiptValue() + record.getUnallocatedReceiptValue()); } } group.setRecords(records); processedGroupings.put(groupName, group); } return processedGroupings; }
From source file:org.powertac.customer.model.LiftTruckTest.java
@Test public void basicConfig() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("customer.model.liftTruck.instances", "twoShift,threeShift"); map.put("customer.model.liftTruck.twoShift.shiftData", "block,1,2,3,4,5, shift,8,10,8, shift,18,10,6," + "block,6, shift,8,10,3"); map.put("customer.model.liftTruck.threeShift.shiftData", "block,1,2,3,4,5, shift,6,8,8, shift,14,8,6, shift,22,8,4," + "block,6,7, shift,6,8,3, shift,14,8,2"); config = new MapConfiguration(map); Configurator configurator = new Configurator(); configurator.setConfiguration(config); Collection<?> instances = configurator.configureInstances(LiftTruck.class); assertEquals("two instances", 2, instances.size()); Map<String, LiftTruck> trucks = mapNames(instances); LiftTruck twoshift = trucks.get("twoShift"); assertNotNull("found twoShift", twoshift); twoshift.ensureShifts();//from ww w .ja v a 2 s. co m Shift[] schedule = twoshift.getShiftSchedule(); assertNotNull("schedule exists", schedule); assertEquals("correct size", 168, schedule.length); assertNull("idle Mon 0:00", schedule[0]); Shift s1 = schedule[8]; assertNotNull("entry for 8:00 Monday", s1); assertEquals("8:00 Monday start", 8, s1.getStart()); assertEquals("8:00 trucks", 8, s1.getTrucks()); assertEquals("s1 runs to 17:00", s1, schedule[17]); Shift s2 = schedule[18]; assertNotNull("second shift exists", s2); assertEquals("18:00 start", 18, s2.getStart()); assertEquals("Tue 3:00", s2, schedule[27]); assertEquals("Tue 3:00 trucks", 6, s2.getTrucks()); assertNull("Idle Tue 4:00", schedule[28]); assertEquals("Tue 8:00 is s1", s1, schedule[32]); assertEquals("Tue 18:00 is s2", s2, schedule[42]); assertEquals("Fri 18:00 is s2", s2, schedule[18 + LiftTruck.HOURS_DAY * 4]); assertEquals("Sat 3:00 is s2", s2, schedule[3 + LiftTruck.HOURS_DAY * 5]); assertNull("Sat 4:00 is null", schedule[4 + LiftTruck.HOURS_DAY * 5]); Shift s3 = schedule[8 + LiftTruck.HOURS_DAY * 5]; assertNotNull("Sat day shift", s3); assertEquals("Sat trucks", 3, s3.getTrucks()); assertNull("idle Sun", schedule[8 + LiftTruck.HOURS_DAY * 6]); LiftTruck threeshift = trucks.get("threeShift"); assertNotNull("found threeshift", threeshift); threeshift.ensureShifts(); schedule = threeshift.getShiftSchedule(); assertNotNull("exists", schedule); assertEquals("size", 168, schedule.length); assertNull("idle Mon midnight", schedule[0]); assertNull("idle 5:00 Mon", schedule[5]); s1 = schedule[6]; assertNotNull("not idle 6:00 Mon", s1); assertEquals("s1 start", 6, s1.getStart()); assertEquals("s1 dur", 8, s1.getDuration()); assertEquals("s1 trucks", 8, s1.getTrucks()); assertEquals("s1 Mon 13:00", s1, schedule[13]); s2 = schedule[14]; assertNotNull("not idle Mon 14:00", s2); assertNotSame("different from s1", s1, s2); assertEquals("s2 start", 14, s2.getStart()); assertEquals("s2 dur", 8, s2.getDuration()); assertEquals("s2 trucks", 6, s2.getTrucks()); assertEquals("s2 Mon 21:00", s2, schedule[21]); s3 = schedule[22]; assertNotNull("not idle Mon 22:00", s3); assertNotSame("different from s1", s1, s3); assertNotSame("different from s2", s2, s3); assertEquals("s3 start", 22, s3.getStart()); assertEquals("s3 dur", 8, s3.getDuration()); assertEquals("s3 trucks", 4, s3.getTrucks()); assertEquals("s3 Tue 5:00", s3, schedule[29]); // check Friday - Sat AM assertEquals("Fri 0:00", s3, schedule[LiftTruck.HOURS_DAY * 4]); assertEquals("Fri 5:00", s3, schedule[5 + LiftTruck.HOURS_DAY * 4]); assertEquals("Fri 6:00", s1, schedule[6 + LiftTruck.HOURS_DAY * 4]); assertEquals("Fri 13:00", s1, schedule[13 + LiftTruck.HOURS_DAY * 4]); assertEquals("Fri 14:00", s2, schedule[14 + LiftTruck.HOURS_DAY * 4]); assertEquals("Fri 21:00", s2, schedule[21 + LiftTruck.HOURS_DAY * 4]); assertEquals("Fri 22:00", s3, schedule[22 + LiftTruck.HOURS_DAY * 4]); assertEquals("Sat 5:00", s3, schedule[5 + LiftTruck.HOURS_DAY * 5]); Shift s4 = schedule[6 + LiftTruck.HOURS_DAY * 5]; assertNotNull("not idle Sat 6:00", s4); assertNotSame("different from s1", s1, s4); assertNotSame("different from s2", s2, s4); assertNotSame("different from s3", s3, s4); assertEquals("s4 start", 6, s4.getStart()); assertEquals("s4 dur", 8, s4.getDuration()); assertEquals("s4 trucks", 3, s4.getTrucks()); assertEquals("Sat 6:00", s4, schedule[6 + LiftTruck.HOURS_DAY * 5]); assertEquals("Sat 13:00", s4, schedule[13 + LiftTruck.HOURS_DAY * 5]); Shift s5 = schedule[14 + LiftTruck.HOURS_DAY * 5]; assertNotNull("not idle Sat 14:00", s5); assertNotSame("different from s1", s1, s5); assertNotSame("different from s2", s2, s5); assertNotSame("different from s3", s3, s5); assertNotSame("different from s4", s4, s5); assertEquals("s5 start", 14, s5.getStart()); assertEquals("s5 dur", 8, s5.getDuration()); assertEquals("s5 trucks", 2, s5.getTrucks()); assertEquals("Sat 14:00", s5, schedule[14 + LiftTruck.HOURS_DAY * 5]); assertEquals("Sat 21:00", s5, schedule[21 + LiftTruck.HOURS_DAY * 5]); assertNull("idle Sat 22:00", schedule[22 + LiftTruck.HOURS_DAY * 5]); assertNull("idle Sun 0:00", schedule[LiftTruck.HOURS_DAY * 6]); assertNull("idle Sun 5:00", schedule[5 + LiftTruck.HOURS_DAY * 6]); assertEquals("Sun 6:00", s4, schedule[6 + LiftTruck.HOURS_DAY * 6]); assertEquals("Sun 13:00", s4, schedule[13 + LiftTruck.HOURS_DAY * 6]); assertEquals("Sun 14:00", s5, schedule[14 + LiftTruck.HOURS_DAY * 6]); assertEquals("Sun 21:00", s5, schedule[21 + LiftTruck.HOURS_DAY * 6]); assertNull("idle Sun 22:00", schedule[22 + LiftTruck.HOURS_DAY * 6]); }
From source file:com.sec.ose.osi.report.standard.data.BillOfMaterialsRowGenerator.java
private String getFileCountForFolders(ArrayList<IdentifiedFilesRow> fileEntList) { TreeMap<String, Integer> map = new TreeMap<String, Integer>(); // parent path, value if (fileEntList == null || fileEntList.size() == 0) return "<None>"; for (IdentifiedFilesRow ent : fileEntList) { String parentPath = (new File(ent.getFullPath())).getParent(); if (parentPath == null) parentPath = ""; if (map.containsKey(parentPath) == false) { map.put(parentPath, 0); }/*from w ww . jav a2 s . c o m*/ map.put(parentPath, map.get(parentPath) + 1); } if (map.size() == 0) return ""; if (map.size() == 1) return ("(" + map.get(map.firstKey()) + " files)\n"); String msg = ""; for (String path : map.keySet()) { msg += path; if (!path.endsWith("/")) msg += "/ "; msg += "(" + map.get(path) + " files)\n"; } msg = msg.replace("\\", "/"); if (msg.length() > 0) { return msg.substring(0, msg.length() - 1); } return ""; }
From source file:org.powertac.officecomplexcustomer.OfficeComplexControllableCapacitiesTests.java
@Before public void setUp() { customerRepo.recycle();/*from w w w.j a va2 s . c om*/ brokerRepo.recycle(); tariffRepo.recycle(); tariffSubscriptionRepo.recycle(); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); officeComplexCustomerService.clearConfiguration(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("officecomplex-customer-test"); broker1 = new Broker("Joe"); now = new DateTime(2011, 1, 10, 0, 0, 0, 0, DateTimeZone.UTC).toInstant(); timeService.setCurrentTime(now); timeService.setBase(now.getMillis()); exp = now.plus(TimeService.WEEK * 10); defaultTariffSpec = new TariffSpecification(broker1, PowerType.CONSUMPTION).withExpiration(exp) .withMinDuration(TimeService.WEEK * 8).addRate(new Rate().withValue(-0.222)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); defaultTariffSpecControllable = new TariffSpecification(broker1, PowerType.INTERRUPTIBLE_CONSUMPTION) .withExpiration(exp).withMinDuration(TimeService.WEEK * 8) .addRate(new Rate().withValue(-0.121).withMaxCurtailment(0.3)); defaultTariffControllable = new Tariff(defaultTariffSpecControllable); defaultTariffControllable.init(); defaultTariffControllable.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpecControllable); when(mockTariffMarket.getDefaultTariff(PowerType.CONSUMPTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.INTERRUPTIBLE_CONSUMPTION)) .thenReturn(defaultTariffControllable); accountingArgs = new ArrayList<Object[]>(); // mock the AccountingService, capture args doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); accountingArgs.add(args); return null; } }).when(mockAccounting).addTariffTransaction(isA(TariffTransaction.Type.class), isA(Tariff.class), isA(CustomerInfo.class), anyInt(), anyDouble(), anyDouble()); // Set up serverProperties mock ReflectionTestUtils.setField(officeComplexCustomerService, "serverPropertiesService", mockServerProperties); config = new Configurator(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); config.configureSingleton(args[0]); return null; } }).when(mockServerProperties).configureMe(anyObject()); TreeMap<String, String> map = new TreeMap<String, String>(); map.put("officecomplexcustomer.officeComplexCustomerService.configFile1", "OfficeComplexType1.properties"); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }
From source file:org.powertac.officecomplexcustomer.OfficeComplexCustomerServiceTests.java
@Before public void setUp() { customerRepo.recycle();//ww w. j av a2 s .co m brokerRepo.recycle(); tariffRepo.recycle(); tariffSubscriptionRepo.recycle(); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); officeComplexCustomerService.clearConfiguration(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("officecomplex-customer-test"); broker1 = new Broker("Joe"); now = new DateTime(2011, 1, 10, 0, 0, 0, 0, DateTimeZone.UTC).toInstant(); timeService.setCurrentTime(now); timeService.setBase(now.getMillis()); exp = now.plus(TimeService.WEEK * 10); defaultTariffSpec = new TariffSpecification(broker1, PowerType.CONSUMPTION).withExpiration(exp) .withMinDuration(TimeService.WEEK * 8).addRate(new Rate().withValue(-0.5)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); when(mockTariffMarket.getDefaultTariff(PowerType.CONSUMPTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.INTERRUPTIBLE_CONSUMPTION)).thenReturn(defaultTariff); accountingArgs = new ArrayList<Object[]>(); // mock the AccountingService, capture args doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); accountingArgs.add(args); return null; } }).when(mockAccounting).addTariffTransaction(isA(TariffTransaction.Type.class), isA(Tariff.class), isA(CustomerInfo.class), anyInt(), anyDouble(), anyDouble()); // Set up serverProperties mock ReflectionTestUtils.setField(officeComplexCustomerService, "serverPropertiesService", mockServerProperties); config = new Configurator(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); config.configureSingleton(args[0]); return null; } }).when(mockServerProperties).configureMe(anyObject()); TreeMap<String, String> map = new TreeMap<String, String>(); map.put("officecomplexcustomer.officeComplexCustomerService.configFile1", "OfficeComplexType1.properties"); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }