List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:com.datatorrent.lib.math.AverageMap.java
/** * Emits average for each key in end window. Data is precomputed during * process on input port Clears the internal data before return. *//*from w ww .ja v a 2s.c o m*/ @Override public void endWindow() { HashMap<K, V> atuples = new HashMap<K, V>(); for (Map.Entry<K, MutableDouble> e : sums.entrySet()) { K key = e.getKey(); atuples.put(key, getValue(e.getValue().doubleValue() / counts.get(key).doubleValue())); } if (!atuples.isEmpty()) { average.emit(atuples); } sums.clear(); counts.clear(); }
From source file:com.turt2live.xmail.mail.attachment.ItemAttachment.java
@Override public boolean giveTo(XMailEntity entity) { if (entity instanceof XMailPlayer) { XMailPlayer xp = (XMailPlayer) entity; CommandSender sender = xp.getOwner(); if (sender instanceof Player) { Player pl = (Player) sender; HashMap<Integer, ItemStack> overflow = pl.getInventory().addItem(item); if (overflow.isEmpty()) { return true; }//from w w w . j a v a 2 s.c o m } } return false; }
From source file:org.neo4j.gis.spatial.osm.OSMLayer.java
@SuppressWarnings("unchecked") /**/* ww w.j av a 2s. c o m*/ * <pre> * { "step": {"type": "GEOM", "direction": "INCOMING" * "step": {"type": "TAGS", "direction": "OUTGOING" * "properties": {"highway": "residential"} * } * } * } * </pre> * * This will work with OSM datasets, traversing from the geometry node * to the way node and then to the tags node to test if the way is a * residential street. */ public DynamicLayerConfig addDynamicLayerOnWayTags(String name, int type, HashMap<?, ?> tags) { JSONObject query = new JSONObject(); if (tags != null && !tags.isEmpty()) { JSONObject step2tags = new JSONObject(); JSONObject step2way = new JSONObject(); JSONObject properties = new JSONObject(); for (Object key : tags.keySet()) { Object value = tags.get(key); if (value != null && (value.toString().length() < 1 || value.equals("*"))) value = null; properties.put(key.toString(), value); } step2tags.put("properties", properties); step2tags.put("type", "TAGS"); step2tags.put("direction", "OUTGOING"); step2way.put("step", step2tags); step2way.put("type", "GEOM"); step2way.put("direction", "INCOMING"); query.put("step", step2way); } if (type > 0) { JSONObject properties = new JSONObject(); properties.put(PROP_TYPE, type); query.put("properties", properties); } System.out.println("Created dynamic layer query: " + query.toJSONString()); return addLayerConfig(name, type, query.toJSONString()); }
From source file:org.thingsplode.synapse.serializers.jackson.JacksonSerializer.java
private void registerHandlers(List<JsonSerializer> serializers, HashMap<Class, JsonDeserializer> deSerializers) { if (serializers != null && !serializers.isEmpty()) { serializers.forEach(s -> module.addSerializer(s)); }/* w w w .j a v a 2 s . c o m*/ if (deSerializers != null && !deSerializers.isEmpty()) { deSerializers.forEach((k, v) -> module.addDeserializer(k, v)); } }
From source file:org.openbaton.nfvo.core.core.VNFLifecycleOperationGranting.java
private VimInstance pickVimInstance(Collection<String> vimInstanceNames, HashMap<VimInstance, Integer> countVDUsOnVimInstances, VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) throws VimException, PluginException { if (countVDUsOnVimInstances.isEmpty()) { for (VimInstance vimInstance : vimInstanceRepository.findAll()) { Quota leftQuota = vimBroker.getLeftQuota(vimInstance); log.debug("Left Quota on VimInstance " + vimInstance.getName() + " at start is " + leftQuota); //Fetch the Flavor for getting allocated resources needed DeploymentFlavour flavor = null; for (DeploymentFlavour currentFlavor : vimInstance.getFlavours()) { if (currentFlavor.getFlavour_key() .equals(virtualNetworkFunctionRecord.getDeployment_flavour_key())) { flavor = currentFlavor; break; }// w ww . ja v a 2s.c om } //Subtract needed resources from the left resources int nc = 0; for (VirtualDeploymentUnit virtualDeploymentUnit : virtualNetworkFunctionRecord.getVdu()) { for (VNFComponent ignored : virtualDeploymentUnit.getVnfc()) { nc++; } } for (int i = 1; i <= nc; i++) { leftQuota.setInstances(leftQuota.getInstances() - 1); leftQuota.setCores(leftQuota.getCores() - flavor.getVcpus()); leftQuota.setRam(leftQuota.getRam() - flavor.getRam()); log.debug("Left Quota on VimInstance " + vimInstance.getName() + " after considering VDU is " + leftQuota); } //If one value is negative, it is not possible to deploy the VNFR on (at least on one VimInstance) -> return false if (leftQuota.getInstances() < 0 || leftQuota.getRam() < 0 || leftQuota.getCores() < 0) { log.warn("Not enough resources are available to deploy VNFR " + virtualNetworkFunctionRecord.getName()); continue; } return vimInstance; } } else { for (VimInstance vimInstance1 : countVDUsOnVimInstances.keySet()) { if (vimInstanceNames.contains(vimInstance1.getName())) { Quota leftQuota = vimBroker.getLeftQuota(vimInstance1); log.debug("Left Quota on VimInstance " + vimInstance1.getName() + " at start is " + leftQuota); //Fetch the Flavor for getting allocated resources needed DeploymentFlavour flavor = null; for (DeploymentFlavour currentFlavor : vimInstance1.getFlavours()) { if (currentFlavor.getFlavour_key() .equals(virtualNetworkFunctionRecord.getDeployment_flavour_key())) { flavor = currentFlavor; break; } } //Subtract needed resources from the left resources for (int i = 1; i <= countVDUsOnVimInstances.get(vimInstance1); i++) { leftQuota.setInstances(leftQuota.getInstances() - 1); leftQuota.setCores(leftQuota.getCores() - flavor.getVcpus()); leftQuota.setRam(leftQuota.getRam() - flavor.getRam()); log.debug("Left Quota on VimInstance " + vimInstance1.getName() + " after considering VDU is " + leftQuota); } //If one value is negative, it is not possible to deploy the VNFR on (at least on one VimInstance) -> return false if (leftQuota.getInstances() < 0 || leftQuota.getRam() < 0 || leftQuota.getCores() < 0) { log.warn("Not enough resources are available to deploy VNFR " + virtualNetworkFunctionRecord.getName()); continue; } return vimInstance1; } } } return null; }
From source file:org.apache.hadoop.hive.ql.parse.MapReduceCompiler.java
@Override protected void setInputFormat(Task<? extends Serializable> task) { if (task instanceof ExecDriver) { MapWork work = ((MapredWork) task.getWork()).getMapWork(); HashMap<String, Operator<? extends OperatorDesc>> opMap = work.getAliasToWork(); if (!opMap.isEmpty()) { for (Operator<? extends OperatorDesc> op : opMap.values()) { setInputFormat(work, op); }/*from www . jav a2 s .c o m*/ } } else if (task instanceof ConditionalTask) { List<Task<? extends Serializable>> listTasks = ((ConditionalTask) task).getListTasks(); for (Task<? extends Serializable> tsk : listTasks) { setInputFormat(tsk); } } if (task.getChildTasks() != null) { for (Task<? extends Serializable> childTask : task.getChildTasks()) { setInputFormat(childTask); } } }
From source file:org.metis.utils.Utils.java
/** * Recursively steps through JSON object and arrays of objects. We support * only a single object or an array of objects, where each object represents * an entity (e.g., a student, a customer, an account, etc.). * //w w w . j a va 2 s .c o m * All objects must have the same identical set of keys. * * @param jp * @param params * @throws Exception */ private static void parseJson(JsonParser jp, List<Map<String, String>> rows) throws Exception { // get the next json token JsonToken current = jp.nextToken(); // base case: return if we've reached end of json stream if (current == null) { return; } // all rows must have the identical set of keys! Map<String, String> firstRow = null; if (!rows.isEmpty()) { firstRow = rows.get(0); } // we only accept objects or arrays of objects switch (current) { case START_OBJECT: HashMap<String, String> row = new HashMap<String, String>(); while (jp.nextToken() != END_OBJECT) { // parser should be on 'key' token String key = jp.getCurrentName().toLowerCase(); // ensure all rows have the identical set of keys! if (firstRow != null && firstRow.get(key) == null) { String eStr = "parseJson: given list of json objects do " + "not have identical set of keys"; LOG.error(eStr); throw new Exception(eStr); } // now advance to 'value' token jp.nextToken(); String value = jp.getText(); row.put(key, value); } // if row is not null, add it to the rows list if (!row.isEmpty()) { // ensure all rows have the identical set of keys! if (firstRow != null && firstRow.size() != row.size()) { String eStr = "parseJson: given list of json objects do " + "not have identical set of keys; number of " + "keys vary"; LOG.error(eStr); throw new Exception(eStr); } rows.add(row); } break; case START_ARRAY: case END_ARRAY: break; default: LOG.error("parseJson: ERROR, json token is neither object nor array"); throw new Exception("parseJson: ERROR, json token is neither object nor array"); } // go on to the next start-of-array, end-of-array, start-of-object, or // end of stream parseJson(jp, rows); }
From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java
@Test public void testPopulateCustomersFormedByLoanOfficerReturnsIfSummaryListIsEmpty() throws Exception { HashMap staffSummariesMock = createMock(HashMap.class); expect(staffSummariesMock.isEmpty()).andReturn(true); replay(staffSummariesMock);/* w ww. j av a 2 s . c o m*/ branchReportPersistence.populateTotalClientsEnrolledByPersonnel(staffSummariesMock); verify(staffSummariesMock); }
From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java
@Test public void testPopulateCustomersFormedThisMonthSetsCustomersEnrolledThisMonth() throws Exception { HashMap staffSummariesMock = createMock(HashMap.class); expect(staffSummariesMock.isEmpty()).andReturn(true); replay(staffSummariesMock);// w w w . ja v a 2 s .c o m branchReportPersistence.populateClientsEnrolledByPersonnelThisMonth(staffSummariesMock); verify(staffSummariesMock); }
From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java
@Test public void testPopulateLoanArrearsAmountReturnsIfSummaryListisEmpty() throws Exception { HashMap staffSummariesMock = createMock(HashMap.class); expect(staffSummariesMock.isEmpty()).andReturn(true); replay(staffSummariesMock);// www .ja v a2s . c o m branchReportPersistence.populateLoanArrearsAmountForPersonnel(staffSummariesMock, DEFAULT_CURRENCY); verify(staffSummariesMock); }