本文整理匯總了Java中java.util.HashMap.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java HashMap.isEmpty方法的具體用法?Java HashMap.isEmpty怎麽用?Java HashMap.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.isEmpty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createInternal
import java.util.HashMap; //導入方法依賴的package包/類
@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);
}
示例2: getChartData
import java.util.HashMap; //導入方法依賴的package包/類
@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;
}
示例3: printDeviceList
import java.util.HashMap; //導入方法依賴的package包/類
/**
* 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());
}
}
示例4: getChartData
import java.util.HashMap; //導入方法依賴的package包/類
@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;
}
示例5: getPercentages
import java.util.HashMap; //導入方法依賴的package包/類
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);
}
示例6: getChartData
import java.util.HashMap; //導入方法依賴的package包/類
@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;
}
示例7: getChartData
import java.util.HashMap; //導入方法依賴的package包/類
@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;
}
示例8: getChartData
import java.util.HashMap; //導入方法依賴的package包/類
@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;
}
示例9: createCanonicalParameterString
import java.util.HashMap; //導入方法依賴的package包/類
/**
* 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;
}
示例10: occurenceAdder
import java.util.HashMap; //導入方法依賴的package包/類
/**
* 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);
}
}
}
示例11: init
import java.util.HashMap; //導入方法依賴的package包/類
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);
}
示例12: getChartData
import java.util.HashMap; //導入方法依賴的package包/類
@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;
}
示例13: scanResources
import java.util.HashMap; //導入方法依賴的package包/類
/**
* 掃描可用資源到緩存
*/
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);
}
}
示例14: handleControllerNodeIPChanges
import java.util.HashMap; //導入方法依賴的package包/類
/**
* 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);
}
}
}
示例15: callPostFileAPI
import java.util.HashMap; //導入方法依賴的package包/類
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;
}