private static Map<String, PsiType> getCompatibleTypeNames(
      @NotNull PsiType type, @Nullable PsiType min, PsiManager manager, GlobalSearchScope scope) {
    if (type instanceof PsiDisjunctionType) type = ((PsiDisjunctionType) type).getLeastUpperBound();

    // if initial type is not assignable to min type we don't take into consideration min type.
    if (min != null && !TypesUtil.isAssignable(min, type, manager, scope)) {
      min = null;
    }

    Map<String, PsiType> map = new LinkedHashMap<String, PsiType>();
    final PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(type);
    if (unboxed != null) type = unboxed;
    final Set<PsiType> set = new LinkedHashSet<PsiType>();
    set.add(type);
    while (!set.isEmpty()) {
      PsiType cur = set.iterator().next();
      set.remove(cur);
      if (!map.containsValue(cur)
          && (min == null || TypesUtil.isAssignable(min, cur, manager, scope))) {
        if (isPartiallySubstituted(cur)) {
          LOG.assertTrue(cur instanceof PsiClassType);
          PsiClassType rawType = ((PsiClassType) cur).rawType();
          map.put(rawType.getPresentableText(), rawType);
        } else {
          map.put(cur.getPresentableText(), cur);
        }
        for (PsiType superType : cur.getSuperTypes()) {
          if (!map.containsValue(superType)) {
            set.add(superType);
          }
        }
      }
    }
    return map;
  }
  /** Test that the full list iterator contract is correct. */
  public void testFullMapIterator() {
    if (supportsFullIterator() == false) {
      return;
    }

    super.testFullMapIterator();

    OrderedMapIterator it = makeFullOrderedMapIterator();
    Map map = getMap();

    assertEquals(true, it.hasNext());
    assertEquals(false, it.hasPrevious());
    Set set = new HashSet();
    while (it.hasNext()) {
      // getKey
      Object key = it.next();
      assertSame("it.next() should equals getKey()", key, it.getKey());
      assertTrue("Key must be in map", map.containsKey(key));
      assertTrue("Key must be unique", set.add(key));

      // getValue
      Object value = it.getValue();
      if (isGetStructuralModify() == false) {
        assertSame("Value must be mapped to key", map.get(key), value);
      }
      assertTrue("Value must be in map", map.containsValue(value));

      assertEquals(true, it.hasPrevious());

      verify();
    }
    while (it.hasPrevious()) {
      // getKey
      Object key = it.previous();
      assertSame("it.previous() should equals getKey()", key, it.getKey());
      assertTrue("Key must be in map", map.containsKey(key));
      assertTrue("Key must be unique", set.remove(key));

      // getValue
      Object value = it.getValue();
      if (isGetStructuralModify() == false) {
        assertSame("Value must be mapped to key", map.get(key), value);
      }
      assertTrue("Value must be in map", map.containsValue(value));

      assertEquals(true, it.hasNext());

      verify();
    }
  }
示例#3
0
  @Test
  public void canCheckContentsOfMap() {

    Map<String, String> map = new HashMap<>();

    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    assertTrue(map.containsKey("key1"));
    assertFalse(map.containsKey("key23"));

    assertTrue(map.containsValue("value2"));
    assertFalse(map.containsValue("value23"));
  }
示例#4
0
  public static void main(String[] args) {
    Map map = new TreeMap();

    if (map.containsValue("gemutlichkeit"))
      throw new RuntimeException("containsValue optimistic (non-null)");

    if (map.containsValue(null)) throw new RuntimeException("containsValue optimistic (null)");

    map.put("a", null);
    map.put("b", "gemutlichkeit");

    if (!map.containsValue("gemutlichkeit"))
      throw new RuntimeException("containsValue pessimistic (non-null)");

    if (!map.containsValue(null)) throw new RuntimeException("containsValue pessimistic (null)");
  }
示例#5
0
 /**
  * Metodo que adiciona um filtro ou grupo.
  *
  * @param filtro do tipo IFiltro.
  * @param juncao a forma de uniao com o próximo filtro, deve ser null caso nao tenha outro filtro.
  * @throws ParametroException ocorre caso seja adicionado mais de um filtro com junçao null.
  */
 public void add(IFiltro filtro, EJuncao juncao) throws IllegalArgumentException {
   if (juncao == null && filtros.containsValue(null)) {
     throw new IllegalArgumentException("Falta a juncao!");
   } else {
     filtros.put(filtro, juncao);
   }
 }
示例#6
0
  /**
   * Add a zone to the zone picker.
   *
   * @param zone the zone to enable picking on.
   */
  public void add(Zone zone) {
    // check if we already have this zone
    if (zoneMap.containsValue(zone)) return;

    if (zoneMap.size() == POSSIBLE_COLORS) {
      // We've run out of pick colours :( oh no
      System.err.printf(
          "The number of zones has exceeded the maximum number of pickable zones (%d). This recently added zone (%s) will not be pickable.",
          POSSIBLE_COLORS, zone);
      return;
    }

    // get a new colour
    zone.setPickColor(new Color(currentColor, false));
    int pixelColor = 0xff + (currentColor << 8);
    zoneMap.put(pixelColor, zone);

    // dont bother searching if we're out of colours anyways
    if (zoneMap.size() < POSSIBLE_COLORS) {
      while (zoneMap.containsKey(pixelColor)) {
        currentColor += 1;
        pixelColor = 0xff + (currentColor << 8);
      }
    }

    // add all of the zone's child zones
    for (Zone child : zone.getChildren()) this.add(child);
  }
示例#7
0
 public boolean containsValue(Object o) {
   boolean wasInterrupted = beforeRead();
   try {
     return c_.containsValue(o);
   } finally {
     afterRead(wasInterrupted);
   }
 }
 public void removeRitualFromList() {
   if (ritualMap.containsValue(this)) {
     ritualMap.remove(ritualMap.remove(this.name));
   }
   if (keyList.contains(this.name)) {
     keyList.remove(this.name);
   }
 }
示例#9
0
 static void valTest(Map s, Object[] key) {
   int size = s.size();
   int sum = 0;
   timer.start("Traverse key or value  ", size);
   if (s.containsValue(MISSING)) ++sum;
   timer.finish();
   reallyAssert(sum == 0);
   checkSum += sum;
 }
示例#10
0
文件: PetMap.java 项目: hanchensu/TIJ
 public static void main(String[] args) {
   Map<String, Pet> petMap = new HashMap<String, Pet>();
   petMap.put("My Cat", new Cat("Molly"));
   petMap.put("My Dog", new Dog("Ginger"));
   petMap.put("My Hamster", new Hamster("Bosco"));
   print(petMap);
   Pet dog = petMap.get("My Dog");
   print(dog);
   print(petMap.containsKey("My Dog"));
   print(petMap.containsValue(dog));
 }
示例#11
0
  @Override
  public void indexRow(GenericRow row) {
    // Find matching leaves in StarTree for row
    currentMatchingNodes.clear();
    StarTreeTableRow tableRow = extractValues(row);
    findMatchingLeaves(starTreeBuilder.getTree(), tableRow.getDimensions(), currentMatchingNodes);

    // Only write the raw value, maintaining sort order (we will write aggregates when sealing)
    for (StarTreeIndexNode node : currentMatchingNodes) {
      Map<Integer, Integer> pathValues = node.getPathValues();
      if (!pathValues.containsValue(StarTreeIndexNode.all())) {
        StarTreeTableRange range = starTreeBuilder.getDocumentIdRange(node.getNodeId());
        StarTreeTable subTable =
            starTreeBuilder.getTable().view(range.getStartDocumentId(), range.getDocumentCount());

        Integer nextMatchingDocumentId =
            starTreeBuilder.getNextDocumentId(tableRow.getDimensions());
        if (nextMatchingDocumentId == null) {
          throw new IllegalStateException("Could not assign document ID for row " + tableRow);
        }

        // Write using that document ID to all columns
        for (final String column : dictionaryCreatorMap.keySet()) {
          Object columnValueToIndex = row.getValue(column);
          if (schema.getFieldSpecFor(column).isSingleValueField()) {
            System.out.println(column + ": " + columnValueToIndex);
            int dictionaryIndex = dictionaryCreatorMap.get(column).indexOfSV(columnValueToIndex);
            ((SingleValueForwardIndexCreator) forwardIndexCreatorMap.get(column))
                .index(nextMatchingDocumentId, dictionaryIndex);
            if (config.createInvertedIndexEnabled()) {
              invertedIndexCreatorMap
                  .get(column)
                  .add(nextMatchingDocumentId, (Object) dictionaryIndex);
            }
          } else {
            int[] dictionaryIndex = dictionaryCreatorMap.get(column).indexOfMV(columnValueToIndex);
            ((MultiValueForwardIndexCreator) forwardIndexCreatorMap.get(column))
                .index(nextMatchingDocumentId, dictionaryIndex);
            if (config.createInvertedIndexEnabled()) {
              invertedIndexCreatorMap.get(column).add(nextMatchingDocumentId, dictionaryIndex);
            }
          }
        }
      }
    }
  }
示例#12
0
  /**
   * Evaluates a URI and adds it to the namespace map as a namespace.
   *
   * @param uri URI
   */
  protected void addNamespaceURI(URI uri) {

    if (uri == null) {
      throw new IllegalArgumentException("URI argument is null.");
    }

    // extract URI without fragment
    String uriString = uri.toString();
    String newURI = null;

    if (uriString != null) {

      // determine what comes last a '#' or '/'
      int hashindex = uriString.lastIndexOf('#');
      int slashindex = uriString.lastIndexOf('/');

      // validate (URI must contain a forward slash)
      if (slashindex == -1) {
        // namespace may have been evaluated already
        return;
      }

      // is there a '/' after the '#'?
      if (slashindex > hashindex) {

        // remove everything after the last '/'
        int index = uriString.lastIndexOf('/');
        newURI = uriString.substring(0, index) + "/";
      } else {

        // '#' comes after last '/' (remove entire fragment)
        newURI = uriString.replaceAll(uri.getFragment(), "");
      }

      // only add namespace if it is new
      if ((newURI != null) && (!namespaces.containsValue(newURI))) {
        // add to namespaces
        namespaces.put("ns" + namespaces.size(), newURI);
      }
    }
  }
示例#13
0
  /**
   * Тестирование на HashMap
   *
   * @throws Exception
   */
  @Test
  public void testOnHashMap() throws Exception {
    Map<UserHashcode, Picture> users = new HashMap<>();
    users.put(user1, user1.getPicture());
    assertTrue(users.containsKey(user1));

    // user3 копия user1 но не содержится в ключах Map. Поиск идет по equals, а он не переопределен
    assertFalse(users.containsKey(user3));

    // В Map есть только user1, но присутствует value для user3,
    // т.к. у класса Picture переопределены оба метода, хотя объекты pic1 и pic3 разные по ссылкам
    assertTrue(users.containsValue(pic3));
    // Объекты разные, а хэш-коды - одинаковые
    assertFalse(pic1 == pic3);
    assertEquals(pic1.hashCode(), pic3.hashCode());

    users.put(user2, user2.getPicture());
    users.put(user3, user3.getPicture());

    // user3 не перезатирает user1, т.к. ключи не равны по equals, а только по hashCode
    assertEquals(3, users.size());
  }
  public static String getHumanReadableMediaTypeFromMimeType(String mediaType) {

    try {
      if (humanReadableMediaTypeMap == null) {
        populateMediaTypeMappings();
      }

      if (humanReadableMediaTypeMap.containsValue(mediaType)) {
        for (Map.Entry<String, String> entry : humanReadableMediaTypeMap.entrySet()) {
          if (entry.getValue().equals(mediaType)) {
            return entry.getKey();
          }
        }
      }
      return mediaType;

    } catch (RegistryException e) {
      String msg = FAILED_TO_READ_THE_THE_HUMAN_READABLE_MEDIA_TYPE_MIME_TYPE_MAPPINGS_FILE_MSG;
      log.error(msg);
    }

    return null;
  }
示例#15
0
文件: Map1.java 项目: xjpsjtu/Tij
 public static void test(Map m) {
   fill(m, testData1);
   // Map has "Set" behavior for keys:
   fill(m, testData1);
   printKeys(m);
   printValues(m);
   print(m);
   String key = testData1[4][0];
   String value = testData1[4][1];
   System.out.println("m.containKey(\"" + key + "\"):" + m.containsKey(key));
   System.out.println("m.get(\"" + key + "\"):" + m.get(key));
   System.out.println("m.containsValue(\"" + value + "\"):" + m.containsValue(value));
   Map m2 = fill(new TreeMap(), testData2);
   m.putAll(m2);
   printKeys(m);
   m.remove(testData2[0][0]);
   printKeys(m);
   m.clear();
   System.out.println("m.isEmpty(): " + m.isEmpty());
   fill(m, testData1);
   // Operations on the Set change the Map:
   m.keySet().removeAll(m.keySet());
   System.out.println("m.isEmpty(): " + m.isEmpty());
 }
示例#16
0
 /**
  * Check whether this zone picker has already registered a zone
  *
  * @param zone a zone
  * @return whether the specified zone has already been added to the zone picker
  */
 public boolean contains(Zone zone) {
   return zoneMap.containsValue(zone);
 }
示例#17
0
 public boolean containsValue(Object value) {
   return young.containsValue(value) || old.containsValue(value);
 }
示例#18
0
 public boolean containsValue(Object value) {
   return sortValuesMap.containsValue(value);
 }
示例#19
0
 @SuppressWarnings("rawtypes")
 private boolean isLocked(int projectId) {
   Map app = ContextManager.getApplication();
   Map projectLockList = (Map) app.get(ContextManager.KEY_PROJECT_LOCK_LIST);
   return projectLockList != null && projectLockList.containsValue(projectId) ? true : false;
 }
示例#20
0
 @Override
 public boolean containsValue(Object value) {
   return delegateMap.containsValue(value);
 }
示例#21
0
 public boolean containsValue(Object value) {
   return parameterMap.containsValue(value);
 }
示例#22
0
 public boolean isRedundant(@NotNull PsiImportStatementBase importStatement) {
   return !myImportStatements.containsValue(importStatement);
 }
 public boolean containsValue(Object value) {
   return map.containsValue(value);
 }
示例#24
0
 protected boolean containerContains(Object o) {
   return map.containsValue(o);
 }
示例#25
0
 public boolean containsValue(Object value) {
   buildIfNeeded();
   return map.containsValue(value);
 }
 public boolean containsValue(Object o) {
   return delegate.containsValue(o);
 }
 @Test
 public void testContainsValue() {
   assertTrue(dict.containsValue("world"));
   assertTrue(dict.containsValue("World"));
   assertFalse(dict.containsValue("bar"));
 }
示例#28
0
 @Override
 @SuppressWarnings("element-type-mismatch")
 public boolean containsValue(Object value) {
   return backing.containsValue(value);
 }