List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.silverpeas.util.MapUtil.java
public static <K, V> boolean equals(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) { Map<K, V> onlyOnRight = new HashMap<K, V>(right); for (Map.Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey();//from w w w . j a v a 2s .c om V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (!ObjectUtils.equals(leftValue, rightValue)) { return false; } } else { return false; } } return onlyOnRight.isEmpty(); }
From source file:com.linkedin.helix.tools.ClusterStateVerifier.java
public static <K, V> boolean compareMap(Map<K, V> map1, Map<K, V> map2) { boolean isEqual = true; if (map1 == null && map2 == null) { // OK// ww w . j av a2 s . c om } else if (map1 == null && map2 != null) { if (!map2.isEmpty()) { isEqual = false; } } else if (map1 != null && map2 == null) { if (!map1.isEmpty()) { isEqual = false; } } else { // verify size if (map1.size() != map2.size()) { isEqual = false; } // verify each <key, value> in map1 is contained in map2 for (K key : map1.keySet()) { if (!map1.get(key).equals(map2.get(key))) { LOG.debug("different value for key: " + key + "(map1: " + map1.get(key) + ", map2: " + map2.get(key) + ")"); isEqual = false; break; } } } return isEqual; }
From source file:co.jirm.mapper.definition.SqlParameterDefinition.java
static Map<String, SqlParameterDefinition> getSqlBeanParameters(Class<?> k, SqlObjectConfig config) { Map<String, SqlParameterDefinition> parameters = new LinkedHashMap<String, SqlParameterDefinition>(); Constructor<?> cons[] = k.getDeclaredConstructors(); for (Constructor<?> c : cons) { if (c.isAnnotationPresent(JsonCreator.class)) { return getSqlBeanParametersFromJsonCreatorConstructor(c, config); }// w w w .ja va 2s . c om if (c.isAnnotationPresent(ConstructorProperties.class)) { return getSqlBeanParametersFromConstructorProperties(c, config); } } check.argument(!parameters.isEmpty(), "No SQL columns/parameters found for: {}", k); return parameters; }
From source file:controllers.Facets.java
private static QueryBuilder createQuery(String id, String q, String author, String name, String subject, String publisher, String issued, String medium, String set, String nwbibspatial, String nwbibsubject, String owner, String t, String location) { final Map<Parameter, String> parameters = Parameter .select(new ImmutableMap.Builder<Parameter, String>() /*@formatter:off*/ .put(Parameter.ID, id).put(Parameter.Q, q).put(Parameter.AUTHOR, author) .put(Parameter.NAME, name).put(Parameter.SUBJECT, subject) .put(Parameter.PUBLISHER, publisher).put(Parameter.ISSUED, issued) .put(Parameter.MEDIUM, medium).put(Parameter.SET, set) .put(Parameter.NWBIBSPATIAL, nwbibspatial).put(Parameter.NWBIBSUBJECT, nwbibsubject) .put(Parameter.LOCATION, location).build());/*@formatter:on*/ QueryBuilder query = parameters.isEmpty() ? QueryBuilders.matchAllQuery() : new Search(parameters, Index.LOBID_RESOURCES).owner(owner).type(t).createQuery(); return query; }
From source file:eu.eidas.util.Preconditions.java
/** * Ensures that a Map reference passed as a parameter to the calling method is neither null nor empty. * * @param reference a Map reference//from w w w . j a va 2 s .co m * @param referenceName the Map name which will appear in the exception message * @return the non-null Map reference that was validated * @throws IllegalArgumentException if {@code reference} is null or empty */ @Nonnull public static <K, V> Map<K, V> checkNotEmpty(Map<K, V> reference, @Nonnull String referenceName) throws IllegalArgumentException { checkNotNull(reference, referenceName); if (reference.isEmpty()) { throw new IllegalArgumentException(referenceName + " cannot be empty"); } return reference; }
From source file:cmd.SMSDcmd.java
/** * * @param inputHandler//w w w.java 2s . c om * @param outputHandler * @param argumentHandler * @throws IOException * @throws CDKException * @throws CloneNotSupportedException */ public static void runSingleQuerySingleTarget(InputHandler inputHandler, OutputHandler outputHandler, ArgumentHandler argumentHandler) throws IOException, CDKException, CloneNotSupportedException { IAtomContainer query = inputHandler.getQuery(); IAtomContainer target = inputHandler.getTarget(); boolean removeHydrogens = argumentHandler.isApplyHRemoval(); /* * check connectivity */ if (argumentHandler.isImage()) { boolean flag = ConnectivityChecker.isConnected(query); if (!flag) { logger.error("WARNING : Skipping file " + inputHandler.getQueryName() + " not connectted "); return; } flag = ConnectivityChecker.isConnected(target); if (!flag) { logger.error("WARNING : Skipping target AtomContainer " + inputHandler.getTargetName() + " as it is not connected."); return; } } String fileNameQ = "Query"; String fileNameT = "Target"; if (target.getProperty(CDKConstants.TITLE) != null) { fileNameQ = target.getProperty(CDKConstants.TITLE) == null ? fileNameT : (String) target.getProperty(CDKConstants.TITLE); target.setID(fileNameQ); argumentHandler.setTargetMolOutName(target.getID()); } if (query.getProperty(CDKConstants.TITLE) != null) { fileNameT = query.getProperty(CDKConstants.TITLE) == null ? fileNameQ : (String) query.getProperty(CDKConstants.TITLE); query.setID(fileNameT); argumentHandler.setQueryMolOutName(query.getID()); } /* * remove hydrogens */ if (removeHydrogens) { query = new AtomContainer(AtomContainerManipulator.removeHydrogens(query)); query.setID(fileNameQ); target = new AtomContainer(AtomContainerManipulator.removeHydrogens(target)); target.setID(fileNameT); } String out = ".out"; if (!argumentHandler.isAppendMode()) { outputHandler.startAppending(out); } else { outputHandler.startNew(out); } ExtAtomContainerManipulator.aromatizeDayLight(query); ExtAtomContainerManipulator.aromatizeDayLight(target); if (argumentHandler.isApplyHAdding()) { AtomContainerManipulator.convertImplicitToExplicitHydrogens(query); AtomContainerManipulator.convertImplicitToExplicitHydrogens(target); } long startTime = System.currentTimeMillis(); BaseMapping smsd; boolean matchBonds = argumentHandler.isMatchBondType(); boolean matchRings = argumentHandler.isMatchRingType(); boolean matchAtomTypes = argumentHandler.isMatchAtomType(); if (argumentHandler.isSubstructureMode()) { smsd = runSubstructure(query, target, argumentHandler.getChemFilter(), matchBonds, matchRings, matchAtomTypes); } else { smsd = run(query, target, argumentHandler.getChemFilter(), matchBonds, matchRings, matchAtomTypes); } query = query.getBuilder().newInstance(IAtomContainer.class, smsd.getFirstAtomMapping().getQuery()); target = target.getBuilder().newInstance(IAtomContainer.class, smsd.getFirstAtomMapping().getTarget()); long endTime = System.currentTimeMillis(); long executionTime = endTime - startTime; // write out the input AtomContainers to files outputHandler.writeQueryMol(smsd.getFirstAtomMapping().getQuery()); outputHandler.writeTargetMol(smsd.getFirstAtomMapping().getTarget()); String queryPath = argumentHandler.getQueryFilepath(); String targetPath = argumentHandler.getTargetFilepath(); Map<IAtom, IAtom> mcs = smsd.getFirstAtomMapping().getMappingsByAtoms(); int nAtomsMatched = (mcs == null) ? 0 : mcs.size(); double tanimotoSimilarity = smsd.getTanimotoSimilarity(); //print out all mappings if (mcs != null && !mcs.isEmpty() && argumentHandler.isAllMapping()) { outputHandler.printHeader(queryPath, targetPath, nAtomsMatched); int counter = 0; for (AtomAtomMapping aam : smsd.getAllAtomMapping()) { Map<Integer, Integer> mapping = aam.getMappingsByIndex(); if (argumentHandler.isImage() && !mapping.isEmpty()) { double stereoScore = smsd.getStereoScore(counter); String label = outputHandler.makeLabel(tanimotoSimilarity, stereoScore); outputHandler.addImage(query, target, label, mapping); } outputHandler.printMapping((counter + 1), mapping); counter += 1; } } //print out top one else if (mcs != null && !mcs.isEmpty() && !argumentHandler.isAllMapping()) { Map<Integer, Integer> mcsNumber = smsd.getFirstAtomMapping().getMappingsByIndex(); double stereoScore = smsd.getStereoScore(0); outputHandler.printHeader(queryPath, targetPath, nAtomsMatched); String qrefName = inputHandler.getQRefName(); String trefName = inputHandler.getTRefName(); outputHandler.printTopMapping(nAtomsMatched, mcs, mcsNumber, qrefName, trefName); if (argumentHandler.isImage() && !mcsNumber.isEmpty()) { String label = outputHandler.makeLabel(tanimotoSimilarity, stereoScore); outputHandler.makeImage(query, target, label, mcsNumber); } } double tanimotoGraph = smsd.getTanimotoSimilarity(); // double tanimotoAtom = smsd.getTanimotoAtomSimilarity(); // double tanimotoBond = smsd.getTanimotoBondSimilarity(); double euclidianGraph = smsd.getEuclideanDistance(); // outputHandler.writeResults(queryLocal, targetLocal, tanimotoGraph, tanimotoAtom, tanimotoBond, euclidianGraph, nAtomsMatched, executionTime); outputHandler.writeResults(query, target, tanimotoGraph, euclidianGraph, nAtomsMatched, executionTime); if (mcs != null && !mcs.isEmpty() && argumentHandler.isImage()) { String qName = inputHandler.getQueryName(); String tName = inputHandler.getTargetName(); outputHandler.writeImage(qName, tName); } if (argumentHandler.shouldOutputSubgraph()) { IAtomContainer subgraph = smsd.getFirstAtomMapping().getCommonFragment(); String outpath = argumentHandler.getOutputFilepath(); String outtype = argumentHandler.getOutputFiletype(); outputHandler.writeMol(outtype, subgraph, outpath); } outputHandler.closeFiles(); }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Adding all data of streamings./* ww w . ja v a 2 s .c o m*/ * @param con * @param media * @param streamings * @throws SQLException */ private static void decorateStreamings(final Connection con, List<Media> media, Map<String, Streaming> streamings) throws SQLException { if (!streamings.isEmpty()) { Collection<Collection<String>> idGroups = CollectionUtil .split(new ArrayList<String>(streamings.keySet())); StringBuilder queryBase = new StringBuilder( "select S.mediaId, S.homepageUrl, S.provider from SC_Gallery_Streaming S where S" + ".mediaId in "); for (Collection<String> mediaIds : idGroups) { PreparedStatement prepStmt = null; ResultSet rs = null; try { prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString()); DBUtil.setParameters(prepStmt, mediaIds); rs = prepStmt.executeQuery(); while (rs.next()) { String mediaId = rs.getString(1); mediaIds.remove(mediaId); Streaming currentStreaming = streamings.get(mediaId); currentStreaming.setHomepageUrl(rs.getString(2)); currentStreaming.setProvider(StreamingProvider.from(rs.getString(3))); } } finally { DBUtil.close(rs, prepStmt); } // Not found for (String mediaIdNotFound : mediaIds) { Streaming currentStreaming = streamings.remove(mediaIdNotFound); media.remove(currentStreaming); SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateStreamings()", "root.MSG_GEN_PARAM_VALUE", "streaming not found (removed from result): " + mediaIdNotFound); } } } }
From source file:com.swordlord.jalapeno.datacontainer.DataContainer.java
/** * Filters the given rows./*from ww w.jav a 2s .co m*/ * * @param <T> * The row type * @param rows * The rows to process * @param filter * The filter or null * @param context * The binding context or null * @param dt * The table to which the rows belong * @return The filtered rows */ private static <T> List<T> filter(List<T> rows, ViewFilter filter, DataBindingContext context, DataTableBase dt) { if (rows.isEmpty() || filter == null) { return rows; } final String strFilter = filter.getFilter(); // Complex filters need to be created "manually" if (strFilter.charAt(0) == '?') { return complexFilter(rows, context, dt, strFilter); } // Trivial filters are done directly by Cayenne final Expression exp = Expression.fromString(strFilter); // expression without parameters? final Map<String, Object> args = filter.getArguments(); if (args.isEmpty()) { return new ArrayList<T>(exp.filterObjects(rows)); } return new ArrayList<T>(exp.expWithParameters(args, false).filterObjects(rows)); }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Adding all data of photos.// w w w . ja va2 s .c o m * @param con * @param media * @param photos * @throws SQLException */ private static void decoratePhotos(final Connection con, List<Media> media, Map<String, Photo> photos) throws SQLException { if (!photos.isEmpty()) { Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(photos.keySet())); StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX) .append("P.resolutionW, P.resolutionH from SC_Gallery_Internal I join SC_Gallery_Photo P on I" + ".mediaId = P.mediaId where I.mediaId in "); for (Collection<String> mediaIds : idGroups) { PreparedStatement prepStmt = null; ResultSet rs = null; try { prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString()); DBUtil.setParameters(prepStmt, mediaIds); rs = prepStmt.executeQuery(); while (rs.next()) { String mediaId = rs.getString(1); mediaIds.remove(mediaId); Photo currentPhoto = photos.get(mediaId); decorateInternalMedia(rs, currentPhoto); currentPhoto.setDefinition(Definition.of(rs.getInt(8), rs.getInt(9))); } } finally { DBUtil.close(rs, prepStmt); } // Not found for (String mediaIdNotFound : mediaIds) { Photo currentPhoto = photos.remove(mediaIdNotFound); media.remove(currentPhoto); SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decoratePhotos()", "root.MSG_GEN_PARAM_VALUE", "photo not found (removed from result): " + mediaIdNotFound); } } } }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Adding all data of sounds./* ww w.j a v a2 s . co m*/ * @param con * @param media * @param sounds * @throws SQLException */ private static void decorateSounds(final Connection con, List<Media> media, Map<String, Sound> sounds) throws SQLException { if (!sounds.isEmpty()) { Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(sounds.keySet())); StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX) .append("S.bitrate, S.duration from SC_Gallery_Internal I join SC_Gallery_Sound S on I.mediaId " + "= S.mediaId where I.mediaId in "); for (Collection<String> mediaIds : idGroups) { PreparedStatement prepStmt = null; ResultSet rs = null; try { prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString()); DBUtil.setParameters(prepStmt, mediaIds); rs = prepStmt.executeQuery(); while (rs.next()) { String mediaId = rs.getString(1); mediaIds.remove(mediaId); Sound currentSound = sounds.get(mediaId); decorateInternalMedia(rs, currentSound); currentSound.setBitrate(rs.getLong(8)); currentSound.setDuration(rs.getLong(9)); } } finally { DBUtil.close(rs, prepStmt); } // Not found for (String mediaIdNotFound : mediaIds) { Sound currentSound = sounds.remove(mediaIdNotFound); media.remove(currentSound); SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateSounds()", "root.MSG_GEN_PARAM_VALUE", "sound not found (removed from result): " + mediaIdNotFound); } } } }