List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.baasbox.controllers.Social.java
/** * Returns for the current user the linked accounts to external * social providers.// w w w .j a v a 2 s. c o m * * * @return a json representation of the list of connected social networks * 404 if no social networks are connected */ @With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class }) public static Result socialLogins() { try { ODocument user = UserService.getCurrentUser(); Map<String, ODocument> logins = user.field(UserDao.ATTRIBUTES_SYSTEM + "." + UserDao.SOCIAL_LOGIN_INFO); if (logins == null || logins.isEmpty()) { return notFound(); } else { List<UserInfo> result = new ArrayList<UserInfo>(); for (ODocument d : logins.values()) { UserInfo i = UserInfo.fromJson(d.toJSON()); result.add(i); } return ok(Json.toJson(result)); } } catch (Exception e) { return internalServerError(ExceptionUtils.getMessage(e)); } }
From source file:com.baasbox.controllers.Social.java
/** * Unlink given social network from current user. * In case that the user was generated by any social network and * at the moment of the unlink the user has only one social network connected * the controller will throw an Exception with a clear message. * Otherwise a 200 code will be returned * @param socialNetwork//ww w . ja va 2 s . co m * @return * @throws SqlInjectionException */ @With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class }) public static Result unlink(String socialNetwork) throws SqlInjectionException { ODocument user = null; try { user = UserService.getCurrentUser(); } catch (Exception e) { internalServerError(ExceptionUtils.getMessage(e)); } Map<String, ODocument> logins = user.field(UserDao.ATTRIBUTES_SYSTEM + "." + UserDao.SOCIAL_LOGIN_INFO); if (logins == null || logins.isEmpty() || !logins.containsKey(socialNetwork) || logins.get(socialNetwork) == null) { return notFound("User's account is not linked with " + StringUtils.capitalize(socialNetwork)); } else { boolean generated = UserService.isSocialAccount(DbHelper.getCurrentUserNameFromConnection()); if (logins.size() == 1 && generated) { return internalServerError("User's account can't be unlinked."); } else { try { UserService.removeSocialLoginTokens(user, socialNetwork); return ok(); } catch (Exception e) { return internalServerError(ExceptionUtils.getMessage(e)); } } } }
From source file:org.zenoss.zep.impl.PluginServiceImpl.java
/** * Sorts plug-ins in the order of their dependencies, so all dependencies * come before the plug-in which depends on them. * * @param <T>//w w w. java 2 s.c o m * The type of {@link EventPlugin}. * @param plugins * Map of plug-ins keyed by the plug-in ID. * @return A sorted list of plug-ins in order based on their dependencies. */ static <T extends EventPlugin> List<T> sortPluginsByDependencies(Map<String, T> plugins) { List<T> sorted = new ArrayList<T>(plugins.size()); Map<String, T> mutablePlugins = new HashMap<String, T>(plugins); while (!mutablePlugins.isEmpty()) { for (Iterator<T> it = mutablePlugins.values().iterator(); it.hasNext();) { T plugin = it.next(); boolean allDependenciesResolved = true; final Set<String> pluginDependencies = plugin.getDependencies(); if (pluginDependencies != null) { for (String dep : pluginDependencies) { T depPlugin = mutablePlugins.get(dep); if (depPlugin != null) { allDependenciesResolved = false; break; } } } if (allDependenciesResolved) { sorted.add(plugin); it.remove(); } } } return sorted; }
From source file:com.baidu.rigel.biplatform.parser.util.ConditionUtil.java
/** * contexCondition??//from w ww .j a va2 s. com * simpleMergeContexsCondition * @param contexs * @return */ public static Map<Condition, Set<String>> simpleMergeContexsCondition(Collection<CompileContext> contexs) { Map<Condition, Set<String>> result = new HashMap<Condition, Set<String>>(); if (CollectionUtils.isNotEmpty(contexs)) { Map<Condition, Set<String>> condition = null; for (CompileContext contex : contexs) { // ????? condition = new HashMap<Condition, Set<String>>(contex.getConditionVariables()); if (result.isEmpty()) { result.putAll(condition); } else if (MapUtils.isNotEmpty(condition)) { for (Entry<Condition, Set<String>> entry : result.entrySet()) { if (condition.containsKey(entry.getKey())) { entry.getValue().addAll(condition.get(entry.getKey())); condition.remove(entry.getKey()); } } if (MapUtils.isNotEmpty(condition)) { result.putAll(condition); } } } } return result; }
From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java
/** * Tabulates a given String -> Object Map. * /* w w w . j a v a 2 s . co m*/ * @param keyHeader * the key header * @param valueHeader * the value header * @param rows * Map containing key value pairs forming the rows * @param out * PrintWriter to write the output to * @param nestLevel * the nesting level * @throws IOException * Signals that an I/O exception has occurred. */ public static void tabulate(String keyHeader, String valueHeader, Map<String, Object> rows, PrintWriter out, int nestLevel) throws IOException { if (rows.isEmpty()) { return; } // Calculate column lengths int maxKeyLength = keyHeader.length(), maxValLength = valueHeader.length(); for (Map.Entry<String, Object> entry : rows.entrySet()) { maxKeyLength = Math.max(maxKeyLength, entry.getKey().length()); maxValLength = Math.max(maxValLength, getValueLength(entry.getValue())); } // Output Header outputRow(out, maxKeyLength, keyHeader, valueHeader, nestLevel); indent(out, nestLevel); for (int col = 0; col < maxKeyLength; col++) { out.print('-'); } out.print(' '); for (int col = 0; col < maxValLength; col++) { out.print('-'); } out.println(); // Output Body for (Map.Entry<String, Object> entry : rows.entrySet()) { outputRow(out, maxKeyLength, entry.getKey(), entry.getValue(), nestLevel); } out.println(); }
From source file:com.iisigroup.cap.utils.CapBeanUtil.java
/** * <pre>//w ww .j a v a 2 s . c om * mapbean * </pre> * * @param <T> * T extends GenericBean * @param prefix * fieldId? * @param map * {fieldId=fieldValue} * @param entry * the bean * @param clazz * the bean class * @return T */ @SuppressWarnings("rawtypes") public static <T extends GenericBean> T map2Bean(String prefix, Map<String, Object> map, T entry, Class clazz) { if (map != null && !map.isEmpty()) { Field[] cols = getField(clazz, true); for (Field f : cols) { String key = prefix + f.getName(); if (map.containsKey(key)) { Object value; value = map.get(key); setField(entry, f.getName(), value); } } } return entry; }
From source file:com.iisigroup.cap.utils.CapBeanUtil.java
/** * <pre>// w w w .ja v a2 s . c om * mapbean * </pre> * * @param <T> * T extends GenericBean * @param map * {fieldId=fieldValue} * @param entry * the bean * @param cols * columns * @return T */ public static <T extends GenericBean> T map2Bean(Map<String, Object> map, T entry, String[] cols) { if (map != null && !map.isEmpty()) { for (String f : cols) { String key = f; if (map.containsKey(key)) { Object value; value = map.get(key); setField(entry, f, value); } } } return entry; }
From source file:gridool.db.partitioning.phihash.csv.grace.CsvGraceHashPartitioningJob.java
private static GridNode mapPrimaryFragment(final String pkeysField, final Map<GridNode, MutableInt> mappedNodes, final int tablePartitionNo, final GridRouter router) throws GridException { assert (mappedNodes.isEmpty()); final byte[] distkey = StringUtils.getBytes(pkeysField); GridNode mappedNode = router.selectNode(distkey); if (mappedNode == null) { throw new GridException("Could not find any node in cluster."); }/*from w ww .j av a 2 s . co m*/ MutableInt newHidden = new MutableInt(tablePartitionNo); mappedNodes.put(mappedNode, newHidden); return mappedNode; }
From source file:Main.java
public static Map getMap(Map mapOld, Map newMap) { Iterator iter = mapOld.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object obj = entry.getValue(); if (obj instanceof Map) { getMap((Map) obj, newMap); } else {// ww w. ja v a2 s . c o m String key1 = (String) key; String value1 = (String) obj; if (!newMap.isEmpty()) { int nn = 0; Iterator iter1 = newMap.entrySet().iterator(); while (iter1.hasNext()) { Map.Entry entry1 = (Map.Entry) iter1.next(); String key2 = (String) entry1.getKey(); String[] arr1 = key2.split("\\|"); String e1 = arr1[0]; int n1 = Integer.parseInt(arr1[1]); if (key1.split("\\|")[0].equals(e1) && n1 >= nn) { nn = n1 + 1; } } newMap.put(key1.split("\\|")[0] + "|" + nn, value1); } else { newMap.put(key1, value1); } } } return newMap; }
From source file:de.iteratec.iteraplan.common.GeneralHelper.java
/** * /*from ww w.j a v a2 s . c o m*/ * Filter BusinessObjects from a InformationSystemRelease Object by a given Map of Business Objects and a return the Association between Informations System and Business Object. * * @param rel * Information System Release * @param businessObjects * Map of Business Objects * @param isLeftEndSearchedBB * Decision to use the right or left end of association between IS and BO.<br/> * true == the left end is used <br/> * false == the right end is used<br/> * @return Association Object between BO and IS */ public static Set<Isr2BoAssociation> filterAbstractAssociationsByBusinessObjects(InformationSystemRelease rel, Map<String, BusinessObject> businessObjects, boolean isLeftEndSearchedBB) { if (businessObjects == null || businessObjects.isEmpty()) { return rel.getBusinessObjectAssociations(); } Set<Isr2BoAssociation> isr2BoAssociationSet = Sets.newHashSet(); for (Iterator<Isr2BoAssociation> iter = rel.getBusinessObjectAssociations().iterator(); iter.hasNext();) { Isr2BoAssociation ass = iter.next(); BuildingBlock buildingBlock; if (isLeftEndSearchedBB) { buildingBlock = ass.getLeftEnd(); } else { buildingBlock = ass.getRightEnd(); } if (businessObjects.get(buildingBlock.getNonHierarchicalName()) != null) { isr2BoAssociationSet.add(ass); } } return isr2BoAssociationSet; }