Java Code Examples for java.util.HashMap.isEmpty()

The following are Jave code examples for showing how to use isEmpty() of the java.util.HashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: elasticsearch_my   File: MultiValuesSourceAggregatorFactory.java   View Source Code Vote up 6 votes
@Override
public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators,
                                 Map<String, Object> metaData) throws IOException {
    HashMap<String, VS> valuesSources = new HashMap<>();

    for (Map.Entry<String, ValuesSourceConfig<VS>> config : configs.entrySet()) {
        VS vs = config.getValue().toValuesSource(context.getQueryShardContext());
        if (vs != null) {
            valuesSources.put(config.getKey(), vs);
        }
    }
    if (valuesSources.isEmpty()) {
        return createUnmapped(parent, pipelineAggregators, metaData);
    }
    return doCreateInternal(valuesSources, parent, collectsFromSingleBucket, pipelineAggregators, metaData);
}
 
Example 2
Project: EpicBanRequests   File: Metrics.java   View Source Code Vote up 6 votes
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        JSONArray categoryValues = new JSONArray();
        categoryValues.add(entry.getValue());
        values.put(entry.getKey(), categoryValues);
    }
    data.put("values", values);
    return data;
}
 
Example 3
Project: sample-usbenum   File: UsbActivity.java   View Source Code Vote up 6 votes
/**
 * Print the list of currently visible USB devices.
 */
private void printDeviceList() {
    HashMap<String, UsbDevice> connectedDevices = mUsbManager.getDeviceList();

    if (connectedDevices.isEmpty()) {
        printResult("No Devices Currently Connected");
    } else {
        StringBuilder builder = new StringBuilder();
        builder.append("Connected Device Count: ");
        builder.append(connectedDevices.size());
        builder.append("\n\n");
        for (UsbDevice device : connectedDevices.values()) {
            //Use the last device detected (if multiple) to open
            builder.append(UsbHelper.readDevice(device));
            builder.append("\n\n");
        }
        printResult(builder.toString());
    }
}
 
Example 4
Project: JavaShell   File: Metrics.java   View Source Code Vote up 6 votes
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        JSONArray categoryValues = new JSONArray();
        categoryValues.add(entry.getValue());
        values.put(entry.getKey(), categoryValues);
    }
    data.put("values", values);
    return data;
}
 
Example 5
Project: JavaShell   File: Metrics.java   View Source Code Vote up 6 votes
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<Country, Integer> map = getValues(new HashMap<Country, Integer>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<Country, Integer> entry : map.entrySet()) {
        if (entry.getValue() == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        values.put(entry.getKey().getCountryIsoTag(), entry.getValue());
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.put("values", values);
    return data;
}
 
Example 6
Project: bskyblock   File: Metrics.java   View Source Code Vote up 6 votes
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        if (entry.getValue() == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        values.put(entry.getKey(), entry.getValue());
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.put("values", values);
    return data;
}
 
Example 7
Project: profile-manager   File: Utility.java   View Source Code Vote up 6 votes
public static HashMap<Profile, Float> getPercentages(HashMap<Profile, Double> distances, int informationSetSize) {
   Map<Profile, Float> result = new HashMap<Profile, Float>();

   if (distances.isEmpty() || distances == null) {
      return new HashMap<Profile, Float>();
   } else {
      for (Map.Entry<Profile, Double> entry : distances.entrySet()) {
         Profile profile = entry.getKey();
         Double distance = entry.getValue();

         // Calculate the percentage for the current distance
         // The maximum distance is sqrt(informationSetSize) because we have
         // 0-1 vectors
         // REMARK: Euclidean Distance Theory
         float maxDistance = (float) Math.sqrt(informationSetSize);
         float percentage = (float) (maxDistance - distance) * 100 / maxDistance;

         // put the percentage in Map formatted with two decimals.
         result.put(profile, (float) (Math.round(percentage * 100.0) / 100.0));
      }
   }
   // return the HashMap sorted by value (DESC)
   return (HashMap<Profile, Float>) MapUtil.sortByValueDESC(result);
}
 
Example 8
Project: SayNoToMcLeaks   File: Metrics.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
      protected JSONObject getChartData() {
          JSONObject data = new JSONObject();
          JSONObject values = new JSONObject();
          HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
          if (map == null || map.isEmpty()) {
              // Null = skip the chart
              return null;
          }
          boolean allSkipped = true;
          for (Map.Entry<String, Integer> entry : map.entrySet()) {
              if (entry.getValue() == 0) {
                  continue; // Skip this invalid
              }
              allSkipped = false;
              values.put(entry.getKey(), entry.getValue());
          }
          if (allSkipped) {
              // Null = skip the chart
              return null;
          }
          data.put("values", values);
          return data;
      }
 
Example 9
Project: GlobalPrefix   File: Metrics.java   View Source Code Vote up 6 votes
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<Country, Integer> map = getValues(new HashMap<Country, Integer>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<Country, Integer> entry : map.entrySet()) {
        if (entry.getValue() == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        values.put(entry.getKey().getCountryIsoTag(), entry.getValue());
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.put("values", values);
    return data;
}
 
Example 10
Project: ServerConnect   File: Metrics.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
      protected JSONObject getChartData() {
          JSONObject data = new JSONObject();
          JSONObject values = new JSONObject();
          HashMap<Country, Integer> map = getValues(new HashMap<Country, Integer>());
          if (map == null || map.isEmpty()) {
              // Null = skip the chart
              return null;
          }
          boolean allSkipped = true;
          for (Map.Entry<Country, Integer> entry : map.entrySet()) {
              if (entry.getValue() == 0) {
                  continue; // Skip this invalid
              }
              allSkipped = false;
              values.put(entry.getKey().getCountryIsoTag(), entry.getValue());
          }
          if (allSkipped) {
              // Null = skip the chart
              return null;
          }
          data.put("values", values);
          return data;
      }
 
Example 11
Project: api-aws-signature   File: AwsHelper.java   View Source Code Vote up 5 votes
/**
 * Use aws version 4 method to create the canonical parameter string
 * @param params
 * @return
 */
private String createCanonicalParameterString(HashMap<String, String> params) {
    String paramString = "";
    if (params != null && !params.isEmpty()) {
        TreeMap<String, String> sortedMap = new TreeMap<String, String>(params);
        for (Map.Entry<String, String> entry : sortedMap.entrySet()) {
            paramString = paramString + entry.getKey() + "=" + entry.getValue();
            if (!sortedMap.lastKey().equals(entry.getKey())) {
                paramString = paramString + "&";
            }
        }
    }
    return paramString;
}
 
Example 12
Project: mutaflow   File: FlowExtractor.java   View Source Code Vote up 5 votes
/**
 * Adds how often a sink occurred over all files and also checks whether a sink occurred for a file where no mutations happened.
 * @param sources
 * @param sinks
 * @param occurredForNoSource
 * @param sinkCounter
 */
private static void occurenceAdder(HashMap<String, HashSet<String>> sources, HashMap<String, HashSet<String>> sinks, HashSet<String> occurredForNoSource, HashMap<String, Integer> sinkCounter) {
	for (String sink : sinks.keySet()) {
		if (sinkCounter.containsKey(sink)) {
			sinkCounter.put(sink, sinkCounter.get(sink)+1);
		} else {
			sinkCounter.put(sink, 1);
		}
		
		if (sources.isEmpty()) {
			occurredForNoSource.add(sink);
		}
	}
}
 
Example 13
Project: jboot   File: FlashMessageManager.java   View Source Code Vote up 5 votes
public void init(Controller controller) {
    if (!(controller instanceof JbootController)) {
        return;
    }
    HashMap flash = ((JbootController) controller).getFlashAttrs();
    if (flash == null || flash.isEmpty()) {
        return;
    }
    controller.setSessionAttr(FLASH_SESSION_ATTR, flash);
    controller.setCookie(FLASH_COOKIE_ATTR, FLASH_COOKIE_VALUE, 60);
}
 
Example 14
Project: skLib   File: Metrics.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
      protected JSONObject getChartData() {
          JSONObject data = new JSONObject();
          JSONObject values = new JSONObject();
          HashMap<String, int[]> map = getValues(new HashMap<String, int[]>());
          if (map == null || map.isEmpty()) {
              // Null = skip the chart
              return null;
          }
          boolean allSkipped = true;
          for (Map.Entry<String, int[]> entry : map.entrySet()) {
              if (entry.getValue().length == 0) {
                  continue; // Skip this invalid
              }
              allSkipped = false;
              JSONArray categoryValues = new JSONArray();
              for (int categoryValue : entry.getValue()) {
                  categoryValues.add(categoryValue);
              }
              values.put(entry.getKey(), categoryValues);
          }
          if (allSkipped) {
              // Null = skip the chart
              return null;
          }
          data.put("values", values);
          return data;
      }
 
Example 15
Project: Anti-Rooktube   File: Metrics.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
      protected JSONObject getChartData() {
          JSONObject data = new JSONObject();
          JSONObject values = new JSONObject();
          HashMap<String, int[]> map = getValues(new HashMap<String, int[]>());
          if (map == null || map.isEmpty()) {
              // Null = skip the chart
              return null;
          }
          boolean allSkipped = true;
          for (Map.Entry<String, int[]> entry : map.entrySet()) {
              if (entry.getValue().length == 0) {
                  continue; // Skip this invalid
              }
              allSkipped = false;
              JSONArray categoryValues = new JSONArray();
              for (int categoryValue : entry.getValue()) {
                  categoryValues.add(categoryValue);
              }
              values.put(entry.getKey(), categoryValues);
          }
          if (allSkipped) {
              // Null = skip the chart
              return null;
          }
          data.put("values", values);
          return data;
      }
 
Example 16
Project: util4j   File: DefaultScriptSource.java   View Source Code Vote up 5 votes
/**
 * 扫描可用资源到缓存
 */
protected void scanResources()
{
	try {
		File scriptDirFile=new File(scriptDir);
		if(scriptDirFile.exists() && scriptDirFile.isDirectory())
		{
			if(scanFilter==null || (scanFilter!=null && scanFilter.accpetJars()))
			{
				for(File file:FileUtil.findJarFileByDir(scriptDirFile))
				{//扫描jar
					cacheJars.add(file.toURI().toURL());
				}
			}
			if(scanFilter==null || (scanFilter!=null && scanFilter.accpetDirClass()))
			{
				HashMap<String, File> map=FileUtil.findClassByDirAndSub(scriptDirFile);
				if(!map.isEmpty())
				{//扫描class文件
					DefaultDirClassFile df=new DefaultDirClassFile(new ArrayList<>(map.keySet()),
							scriptDirFile.toURI().toURL());
					cacheDirClassFile.add(df);
				}
			}
		}
	} catch (Exception e) {
		log.error(e.getMessage(),e);
	}
}
 
Example 17
Project: bskyblock   File: Metrics.java   View Source Code Vote up 5 votes
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<String, int[]> map = getValues(new HashMap<String, int[]>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<String, int[]> entry : map.entrySet()) {
        if (entry.getValue().length == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        JSONArray categoryValues = new JSONArray();
        for (int categoryValue : entry.getValue()) {
            categoryValues.add(categoryValue);
        }
        values.put(entry.getKey(), categoryValues);
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.put("values", values);
    return data;
}
 
Example 18
Project: ServerConnect   File: Metrics.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
      protected JSONObject getChartData() {
          JSONObject data = new JSONObject();
          JSONObject values = new JSONObject();
          HashMap<String, int[]> map = getValues(new HashMap<String, int[]>());
          if (map == null || map.isEmpty()) {
              // Null = skip the chart
              return null;
          }
          boolean allSkipped = true;
          for (Map.Entry<String, int[]> entry : map.entrySet()) {
              if (entry.getValue().length == 0) {
                  continue; // Skip this invalid
              }
              allSkipped = false;
              JSONArray categoryValues = new JSONArray();
              for (int categoryValue : entry.getValue()) {
                  categoryValues.add(categoryValue);
              }
              values.put(entry.getKey(), categoryValues);
          }
          if (allSkipped) {
              // Null = skip the chart
              return null;
          }
          data.put("values", values);
          return data;
      }
 
Example 19
Project: fresco_floodlight   File: Controller.java   View Source Code Vote up 4 votes
/**
 * Handle changes to the controller nodes IPs and dispatch update.
 */
protected void handleControllerNodeIPChanges() {
    HashMap<String,String> curControllerNodeIPs = new HashMap<String,String>();
    HashMap<String,String> addedControllerNodeIPs = new HashMap<String,String>();
    HashMap<String,String> removedControllerNodeIPs =new HashMap<String,String>();
    String[] colNames = { CONTROLLER_INTERFACE_CONTROLLER_ID,
                       CONTROLLER_INTERFACE_TYPE,
                       CONTROLLER_INTERFACE_NUMBER,
                       CONTROLLER_INTERFACE_DISCOVERED_IP };
    synchronized(controllerNodeIPsCache) {
        // We currently assume that interface Ethernet0 is the relevant
        // controller interface. Might change.
        // We could (should?) implement this using
        // predicates, but creating the individual and compound predicate
        // seems more overhead then just checking every row. Particularly,
        // since the number of rows is small and changes infrequent
        IResultSet res = storageSourceService.executeQuery(CONTROLLER_INTERFACE_TABLE_NAME,
                colNames,null, null);
        while (res.next()) {
            if (res.getString(CONTROLLER_INTERFACE_TYPE).equals("Ethernet") &&
                    res.getInt(CONTROLLER_INTERFACE_NUMBER) == 0) {
                String controllerID = res.getString(CONTROLLER_INTERFACE_CONTROLLER_ID);
                String discoveredIP = res.getString(CONTROLLER_INTERFACE_DISCOVERED_IP);
                String curIP = controllerNodeIPsCache.get(controllerID);

                curControllerNodeIPs.put(controllerID, discoveredIP);
                if (curIP == null) {
                    // new controller node IP
                    addedControllerNodeIPs.put(controllerID, discoveredIP);
                }
                else if (!curIP.equals(discoveredIP)) {
                    // IP changed
                    removedControllerNodeIPs.put(controllerID, curIP);
                    addedControllerNodeIPs.put(controllerID, discoveredIP);
                }
            }
        }
        // Now figure out if rows have been deleted. We can't use the
        // rowKeys from rowsDeleted directly, since the tables primary
        // key is a compound that we can't disassemble
        Set<String> curEntries = curControllerNodeIPs.keySet();
        Set<String> removedEntries = controllerNodeIPsCache.keySet();
        removedEntries.removeAll(curEntries);
        for (String removedControllerID : removedEntries)
            removedControllerNodeIPs.put(removedControllerID,
                                         controllerNodeIPsCache.get(removedControllerID));
        controllerNodeIPsCache.clear();
        controllerNodeIPsCache.putAll(curControllerNodeIPs);
        //counters.controllerNodeIpsChanged.updateCounterWithFlush();
        HAControllerNodeIPUpdate update = new HAControllerNodeIPUpdate(
                            curControllerNodeIPs, addedControllerNodeIPs,
                            removedControllerNodeIPs);
        if (!removedControllerNodeIPs.isEmpty() || !addedControllerNodeIPs.isEmpty()) {
            addUpdateToQueue(update);
        }
    }
}
 
Example 20
Project: opencps-v2   File: InvokeREST.java   View Source Code Vote up 2 votes
public JSONObject callPostFileAPI(long groupId, String httpMethod, String accept, String pathBase, String endPoint,
		String username, String password, HashMap<String, String> properties, File file,
		ServiceContext serviceContext) {

	JSONObject response = JSONFactoryUtil.createJSONObject();

	try {

		String authString = username + ":" + password;

		String authStringEnc = new String(Base64.getEncoder().encodeToString(authString.getBytes()));

		String requestURL = pathBase + endPoint;

		MultipartUtility multipart = new MultipartUtility(requestURL, "UTF-8", groupId, authStringEnc);
		// TODO; check logic here, if ref fileId in SERVER equal CLIENT

		multipart.addFilePart("file", file);

		if (!properties.isEmpty()) {
			for (Map.Entry m : properties.entrySet()) {
				multipart.addFormField(m.getKey().toString(), m.getValue().toString());

			}
		}

		List<String> res = multipart.finish();

		StringBuilder sb = new StringBuilder();

		for (String line : res) {
			sb.append(line);
		}

		response.put(RESTFulConfiguration.STATUS, HttpURLConnection.HTTP_OK);
		response.put(RESTFulConfiguration.MESSAGE, sb.toString());

	} catch (Exception e) {
		response.put(RESTFulConfiguration.STATUS, HttpURLConnection.HTTP_FORBIDDEN);
		response.put(RESTFulConfiguration.MESSAGE, e.getMessage());
	}

	return response;
}