Java tutorial
//package com.java2s; /* * TMQL4J - Javabased TMQL Engine * * Copyright: Copyright 2010 Topic Maps Lab, University of Leipzig. http://www.topicmapslab.de/ * License: Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html * * @author Sven Krosse * @email krosse@informatik.uni-leipzig.de * */ import java.util.Map; import java.util.Map.Entry; public class Main { /** * Method checks if one map contain at least the same entries like the * other. The third parameter are used to enable a mapping the the keys of * the first and the second map. * * @param map * the map to check * @param containment * the entries which has to contain * @param mapping * the key-mapping between the both maps * @return <code>true</code> if the first map contain at least the same * entries like the other, <code>false</code> otherwise. */ public static final boolean containsAll(Map<String, Object> map, Map<String, Object> containment, final Map<String, String> mapping) { /* * iterate over entries, which should be contained */ for (Entry<String, Object> entry : containment.entrySet()) { String key = entry.getKey(); /* * check if key has to map */ if (mapping.containsKey(key)) { key = mapping.get(key); } /* * check if key is contained or if key is fn:count */ if (map.containsKey(key) || entry.getKey().equalsIgnoreCase("fn:count")) { if (map.get(key).equals(entry.getValue())) { continue; } } return false; } return true; } }