Java Code Examples for java.util.HashMap.containsValue()

The following are Jave code examples for showing how to use containsValue() of the java.util.HashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: CheckValueOfHashMapExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

    //create HashMap object
    HashMap hMap = new HashMap();

    //add key value pairs to HashMap
    hMap.put("1", "One");
    hMap.put("2", "Two");
    hMap.put("3", "Three");

    /*
      To check whether a particular value exists in HashMap use
      boolean containsValue(Object key) method of HashMap class.
      It returns true if the value is mapped to one or more keys in the
      HashMap otherwise false.
    */

    boolean blnExists = hMap.containsValue("Two");
    System.out.println("Two exists in HashMap ? : " + blnExists);
  }
 
Example 2
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: CommandUtil.java   View Source Code Vote up 5 votes
public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception {
    ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
    HashMap<String/* brokerName */, BrokerData> brokerAddrTable =
        clusterInfoSerializeWrapper.getBrokerAddrTable();
    Iterator<Map.Entry<String, BrokerData>> it = brokerAddrTable.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, BrokerData> entry = it.next();
        HashMap<Long, String> brokerAddrs = entry.getValue().getBrokerAddrs();
        if (brokerAddrs.containsValue(addr))
            return entry.getKey();
    }
    throw new Exception(
        "Make sure the specified broker addr exists or the nameserver which connected is correct.");
}
 
Example 3
Project: class-code   File: Balanced.java   View Source Code Vote up 5 votes
/**
Checks if a string is balanced or not.

 @param s is a non-null string
 @return true of the input <code>s</code> is balanced and false otherwise.
**/
public static boolean isBalanced(String s){
  Stack<Character> stack = new Stack<Character>();
  HashMap<Character, Character> symbols = new HashMap<Character, Character>();

  symbols.put(')' , '(');
  symbols.put('}' , '{');
  symbols.put(']' , '[');

  for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (symbols.containsValue(c)) {
      stack.push(c);
    }
    if (symbols.containsKey(c)) {
      if (stack.empty()) {
        return false;
      } else {
        Character temp = stack.pop();
        if (temp != symbols.get(c)) {
          return false;
        }
      }
    }
  }
  if (stack.empty()) {
    return true;
  }
  return false;
}
 
Example 4
Project: unitimes   File: InstructionalOfferingModifyAction.java   View Source Code Vote up 5 votes
private void deleteClasses(InstructionalOfferingModifyForm frm, InstrOfferingConfig ioc, Session hibSession, HashMap tmpClassIdsToRealClasses){
 	if (ioc.getSchedulingSubparts() != null) {
SchedulingSubpart ss = null;
ArrayList lst = new ArrayList();
      ArrayList subpartList = new ArrayList(ioc.getSchedulingSubparts());
      Collections.sort(subpartList, new SchedulingSubpartComparator());

      for(Iterator it = subpartList.iterator(); it.hasNext();){
      	ss = (SchedulingSubpart) it.next();
      	if (ss.getParentSubpart() == null){
      		buildClassList(ss.getClasses(), lst);
      	}
      }

      Class_ c;
      for (int i = (lst.size() - 1); i >= 0; i--){
      	c = (Class_) lst.get(i);
      	if (!frm.getClassIds().contains(c.getUniqueId().toString()) && !tmpClassIdsToRealClasses.containsValue(c)){
		if (c.getParentClass() != null){
			Class_ parent = c.getParentClass();
			parent.getChildClasses().remove(c);
			hibSession.update(parent);
		}
		c.getSchedulingSubpart().getClasses().remove(c);
		if (c.getPreferences() != null)
		    c.getPreferences().removeAll(c.getPreferences());
		
		c.deleteAllDependentObjects(hibSession, false);
		
		hibSession.delete(c);
      	}
      }
 	}
  }
 
Example 5
Project: fdt   File: ApMonMonitoringConstants.java   View Source Code Vote up 5 votes
private static String getName(Long param, HashMap hm) {
    if (param == null) return null;
    if (!hm.containsValue(param)) return null;

    for (Iterator it = hm.keySet().iterator(); it.hasNext(); ) {
        String key = (String) it.next();
        if (hm.get(key).equals(param)) return key;
    }

    //should not get normally here .... but who knows :)
    return null;
}
 
Example 6
Project: SoftUni   File: p06_MagicExchaneableWords.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    Scanner scann = new Scanner(System.in);

    String[] input = scann.nextLine().split("\\s+");
    char[] shorter = input[(input[0].length() > input[1].length()) ? 1 : 0].toCharArray();
    char[] longer = input[(input[0].length() <= input[1].length()) ? 1 : 0].toCharArray();

    boolean output = true;
    HashMap<Character, Character> mapper = new HashMap<Character, Character>();
    for (int i = 0; i < shorter.length; i++) {
        if(!mapper.containsKey(shorter[i])){
            if(mapper.containsValue(longer[i])){
                output = false;
                break;
            } else {
                mapper.put(shorter[i], longer[i]);
            }
        } else {
            if(longer[i] != mapper.get(shorter[i])){
                output = false;
                return;
            }
        }
    }

    for (int i = shorter.length; i < longer.length; i++) {
        if(!mapper.containsValue(longer[i])){
            output = false;
            break;
        }
    }

    System.out.println(output);
}
 
Example 7
Project: rmq4note   File: CommandUtil.java   View Source Code Vote up 5 votes
public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception {
    ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
    HashMap<String/* brokerName */, BrokerData> brokerAddrTable =
        clusterInfoSerializeWrapper.getBrokerAddrTable();
    Iterator<Map.Entry<String, BrokerData>> it = brokerAddrTable.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, BrokerData> entry = it.next();
        HashMap<Long, String> brokerAddrs = entry.getValue().getBrokerAddrs();
        if (brokerAddrs.containsValue(addr))
            return entry.getKey();
    }
    throw new Exception(
        "Make sure the specified broker addr exists or the nameserver which connected is correct.");
}
 
Example 8
Project: GitHub   File: RouterHelper.java   View Source Code Vote up 4 votes
@SingleClick // 防止连续点击
public static void go(String actionName, HashMap data, View view) {
    if (data.containsValue(null)) return;
    TRouter.go(actionName, data, view);
}
 
Example 9
Project: XERUNG   File: ContactList.java   View Source Code Vote up 4 votes
@Override
 protected Void doInBackground(Void... voids) {
     // Get Contact list from Phone

     if (phones != null) {
if(dbContact != null)
         	dbContact.truncateContactTable();
         HashMap<String, String> data = new HashMap<String, String>();
         while (phones.moveToNext()) {
             Bitmap bit_thumb = null;
             String id          = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
             String name        = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
             String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
             String EmailAddr   = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA2));
             String newPhinr    = phoneNumber.replaceAll("\\s+","").replaceAll("\\-", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("\\#", "").replaceAll("\\_", "");
             String image_thumb = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI));
             try {
                 if (image_thumb != null) {
                     bit_thumb = MediaStore.Images.Media.getBitmap(resolver, Uri.parse(image_thumb));
                 } else {

                 }
             } catch (IOException e) {
                 e.printStackTrace();
             }
             ContactBean selectUser = new ContactBean();
             if (!data.containsValue(newPhinr)) {
             	selectUser.setThumb(bit_thumb);
                 selectUser.setName(name);
                 selectUser.setNumber(newPhinr);
                 selectUser.setPhotoURI(image_thumb);
                 selectUser.setPinyin(HanziToPinyin.getPinYin(selectUser.getName()));
                 data.put(name, newPhinr);
		if(dbContact != null)
                 dbContact.addContact(selectUser);
                 if (newPhinr != null) {
                 	 selectUsers.add(selectUser);
                 	 nameNum.put(selectUser.getName(), selectUser.getNumber());
                 }
             }

         }
     } else {

     }
     phones.close();
     return null;
 }
 
Example 10
Project: XERUNG   File: ContactList.java   View Source Code Vote up 4 votes
@Override
 protected Void doInBackground(Void... voids) {
     // Get Contact list from Phone

     if (phones != null) {
if(dbContact != null)
         	dbContact.truncateContactTable();
         HashMap<String, String> data = new HashMap<String, String>();
         while (phones.moveToNext()) {
             Bitmap bit_thumb = null;
             String id          = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
             String name        = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
             String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
             String EmailAddr   = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA2));
             String newPhinr    = phoneNumber.replaceAll("\\s+","").replaceAll("\\-", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("\\#", "").replaceAll("\\_", "");
             String image_thumb = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI));
             try {
                 if (image_thumb != null) {
                     bit_thumb = MediaStore.Images.Media.getBitmap(resolver, Uri.parse(image_thumb));
                 } else {

                 }
             } catch (IOException e) {
                 e.printStackTrace();
             }
             ContactBean selectUser = new ContactBean();
             if (!data.containsValue(newPhinr)) {
             	selectUser.setThumb(bit_thumb);
                 selectUser.setName(name);
                 selectUser.setNumber(newPhinr);
                 selectUser.setPhotoURI(image_thumb);
                 selectUser.setPinyin(HanziToPinyin.getPinYin(selectUser.getName()));
                 data.put(name, newPhinr);
		if(dbContact != null)
                 dbContact.addContact(selectUser);
                 if (newPhinr != null) {
                 	 selectUsers.add(selectUser);
                 	 nameNum.put(selectUser.getName(), selectUser.getNumber());
                 }
             }

         }
     } else {

     }
     phones.close();
     return null;
 }