Ive the following code which do the following
there is two Maps with properties and I need to check if properties with the same key and value is already exist, if yes thorow an exception
Map<String, Object> existingProperties = requires.get(requiresIndex).getProperties(); for (Map.Entry<String, Object> property : properties.entrySet()) { if (existingProperties.containsKey(property.getKey())){ if (existingProperties.get(property.getKey()) instanceof String && property.getValue() instanceof String ){ String existingValue = (String) existingProperties.get(property.getKey()); String newValue = (String) property.getValue(); if (existingValue.equals(newValue)){ throw new Exception("Property " + property.getKey() + " is existsing with value " + newValue + "in requires " + requiresName); } } } }
we are working on java8 and if there is better/shorter way to write it, it will be great