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

The following examples show how to use java.util.HashMap#containsValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AVM2Deobfuscation.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
private String fooString(HashMap<DottedChain, DottedChain> deobfuscated, String orig, boolean firstUppercase, String usageType, RenameType renameType) {
    if (usageType == null) {
        usageType = "name";
    }

    String ret = null;
    boolean found;
    int rndSize = DEFAULT_FOO_SIZE;

    do {
        found = false;
        if (renameType == RenameType.TYPENUMBER) {
            ret = Helper.getNextId(usageType, usageTypesCount, true);
        } else if (renameType == RenameType.RANDOMWORD) {
            ret = IdentifiersDeobfuscation.fooString(firstUppercase, rndSize);
        }
        if (swf.as3StringConstantExists(ret)
                || IdentifiersDeobfuscation.isReservedWord2(ret)
                || deobfuscated.containsValue(DottedChain.parseWithSuffix(ret))) {
            found = true;
            rndSize++;
        }
    } while (found);
    deobfuscated.put(DottedChain.parseWithSuffix(orig), DottedChain.parseWithSuffix(ret));
    return ret;
}
 
Example 2
Source File: CheckValueOfHashMapExample.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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 3
Source File: Leetcode_205_String.java    From cs-summary-reflection with Apache License 2.0 6 votes vote down vote up
/**
 * 使用map集合
 *
 * <p>若s与t不等,直接返回false?
 */
public static boolean isIsomorphic2(String s, String t) {
    if (s == null || s.length() <= 1) return true;
    HashMap<Character, Character> hm = new HashMap<Character, Character>();
    for (int i = 0; i < s.length(); i++) {
        char c1 = s.charAt(i);
        char c2 = t.charAt(i);
        if (hm.containsKey(c1)) {
            // 若c1在集合中,判断c2和当前c2是否是相等
            if (hm.get(c1) == c2) continue; // 字符可以被字符自己替换
            else return false;
        } else {
            // c2在集合中
            if (hm.containsValue(c2)) return false;
            else {
                // 既没有c1,也没有c2,直接添加hash映射c1->c2
                hm.put(c1, c2);
            }
        }
    }
    return true;
}
 
Example 4
Source File: Leetcode_290_String.java    From cs-summary-reflection with Apache License 2.0 6 votes vote down vote up
public static boolean wordPattern_My(String pattern, String str) {
    if (pattern == null || str == null) return true;
    String[] strs = str.split(" ");
    if (pattern.length() != strs.length) return false;
    HashMap<Character, String> map = new HashMap<Character, String>();
    for (int i = 0; i < pattern.length(); i++) {
        if (map.containsKey(pattern.charAt(i))) {
            if (map.get(pattern.charAt(i)).equals(strs[i])) continue;
            else return false;
        } else {
            if (map.containsValue(strs[i])) return false;
            else map.put(pattern.charAt(i), strs[i]);
        }
    }
    return true;
}
 
Example 5
Source File: CommandUtil.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
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(ERROR_MESSAGE);
}
 
Example 6
Source File: InstructionalOfferingModifyAction.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 7
Source File: CommandUtil.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
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
Source File: ActionSourceGenerator.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public int getTempRegister(SourceGeneratorLocalData localData) {
    HashMap<String, Integer> registerVars = getRegisterVars(localData);
    for (int tmpReg = 0; tmpReg < 256; tmpReg++) {
        if (!registerVars.containsValue(tmpReg)) {
            registerVars.put("__temp" + tmpReg, tmpReg);
            return tmpReg;
        }
    }
    return 0; //?
}
 
Example 9
Source File: CommandUtil.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
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 10
Source File: CommandUtil.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
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(ERROR_MESSAGE);
}
 
Example 11
Source File: CommandUtil.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
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 12
Source File: ContactList.java    From XERUNG with Apache License 2.0 4 votes vote down vote up
@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 13
Source File: ContactList.java    From XERUNG with Apache License 2.0 4 votes vote down vote up
@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 14
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test3Bugs(HashMap<? extends CharSequence, ? extends CharSequence> map) {
    map.containsValue(3);
    map.containsKey(4.0);
    map.get(5.0);
    map.remove('r');
}
 
Example 15
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test4Bugs(HashMap<? super CharSequence, ? super CharSequence> map) {
    map.containsValue(3);
    map.containsKey('k');
    map.get(5.0);
    map.remove('r');
}
 
Example 16
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test1NoBugs(HashMap<String, String> map) {
    map.containsKey("Key");
    map.containsValue("Value");
    map.get("Get");
    map.remove("Remove");
}
 
Example 17
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test1Bugs(HashMap<String, String> map) {
    map.containsKey(new StringBuffer("Key"));
    map.containsValue(new StringBuffer("Value"));
    map.get(new StringBuffer("Get"));
    map.remove(new StringBuffer("Remove"));
}
 
Example 18
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test1aBugs(HashMap<? extends String, String> map) {
    map.containsKey(new StringBuffer("Key"));
    map.containsValue(new StringBuffer("Value"));
    map.get(new StringBuffer("Get"));
    map.remove(new StringBuffer("Remove"));
}
 
Example 19
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test4NoBugs(HashMap<? super CharSequence, ? super CharSequence> map) {
    map.containsValue(new StringBuffer("Value"));
    map.get(new StringBuffer("Get"));
}
 
Example 20
Source File: MapTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test3NoBugs(HashMap<? extends CharSequence, ? extends CharSequence> map) {
    map.containsValue(new StringBuffer("Value"));
    map.get(new StringBuffer("Get"));
    map.remove(new StringBuffer("Remove"));
}