public class Hash_Map_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating an empty HashMap 
        HashMap<String, Integer> hash_map = new HashMap<String, Integer>(); 
  
        // Mapping int values to string keys 
        hash_map.put("Geeks", 10); 
        hash_map.put("4", 15); 
        hash_map.put("Geeks", 20); 
        hash_map.put("Welcomes", 25); 
        hash_map.put("You", 30); 
  
        // Displaying the HashMap 
        System.out.println("The Mappings are: " + hash_map); 
  
        // Checking for the emptiness of Map 
        System.out.println("Is the map empty? " + hash_map.isEmpty()); 
    } 
} 

        

public class HashMapDemo {
   public static void main(String args[]) {
      
      // create hash map
      HashMap newmap = new HashMap();

      // populate hash map
      newmap.put(1, "tutorials");
      newmap.put(2, "point");
      newmap.put(3, "is best");

      // check if map is empty
      boolean val = newmap.isEmpty();

      // check the boolean value
      System.out.println("Is hash map empty: " + val);
   }    
}

        

public class HashMapIsEmptyOrNot {
 
    public static void main(String[] args) {
 
        // creating empty HashMap object of type <String, String>
        HashMap<String, String> hashMap = new HashMap<String, String>();
 
        // checking empty even before adding any Key-Value pairs
        boolean isEmpty1 = hashMap.isEmpty();
 
        System.out.println("1. Checking Empty"
                + " before adding any entries : " + isEmpty1);
 
        // adding key-value pairs to HashMap object
        hashMap.put("Google", "Sundar Pichai");
        hashMap.put("Facebook", "Mark Zuckerberg");
        hashMap.put("LinkedIn", "Reid Hoffman");
        hashMap.put("Apple", "Steve Jobs");
        hashMap.put("Microsoft", "Bill Gates");
 
        // checking empty adding few entries
        boolean isEmpty2 = hashMap.isEmpty();
 
        System.out.println("\n2. Checking Empty"
                + " before adding any entries : " + isEmpty2);
    }
}

        

public class HashMapEmptyExample {
    public static void main(String args[]) {
        
    // Creating a HashMap of int keys and String values
    HashMap<Integer, String> hashmap = new HashMap<Integer, String>();
 
    // Checking whether HashMap is empty or not
    /* isEmpty() method signature and description -
     * public boolean isEmpty(): Returns true if this map 
     * contains no key-value mappings.
     */
    System.out.println("Is HashMap Empty? "+hashmap.isEmpty());
    
    
    // Adding Key and Value pairs to HashMap
    hashmap.put(11,"Apple");
    hashmap.put(22,"Banana");
    hashmap.put(33,"Mango");
    hashmap.put(44,"Pear");
    hashmap.put(55,"PineApple");
     // Checking again whether HashMap is Empty or not
    System.out.println("Is HashMap Empty? "+hashmap.isEmpty());
 
    }
}

        

public class HashMapIsEmptyExample {

	public static void main(String args[]) throws InterruptedException {

		// declare the hashmap
		HashMap<String, String> mapStudent = new HashMap<>();

		// put contents of our HashMap
		mapStudent.put("12487912", "Shyra Travis");
		mapStudent.put("45129987", "Sharon Wallace");

		// check if the HashMap is empty or not
		if (!mapStudent.isEmpty()) {

			// printing the key value pairs available
			// if the hashmap is not empty
			for (String s : mapStudent.keySet()) {
				System.out.println("Student with id # " + s + " is " + mapStudent.get(s));
			}
		}
	}
}

        

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);
}

        

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;
}

        

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);
}

        

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;
}

        

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;
}        
main