コード例 #1
0
  public void testGetAndReadConfigurationFiles() throws Exception {
    File testConfFile = new File(getConfHomeDir(), "test.xml");

    FileUtils.fileWrite(testConfFile.getAbsolutePath(), "test");

    Map<String, String> confFileNames = nexusConfiguration.getConfigurationFiles();

    assertTrue(confFileNames.size() > 1);

    assertTrue(confFileNames.containsValue("nexus.xml"));

    assertTrue(confFileNames.containsValue("test.xml"));

    for (Map.Entry<String, String> entry : confFileNames.entrySet()) {
      if (entry.getValue().equals("test.xml")) {
        contentEquals(
            new ByteArrayInputStream("test".getBytes()),
            nexusConfiguration.getConfigurationAsStreamByKey(entry.getKey()).getInputStream());
      } else if (entry.getValue().equals("nexus.xml")) {
        contentEquals(
            new FileInputStream(new File(getNexusConfiguration())),
            nexusConfiguration.getConfigurationAsStreamByKey(entry.getKey()).getInputStream());
      }
    }
    FileUtils.forceDelete(testConfFile);
  }
コード例 #2
0
 /**
  * @see java.util.Map#containsValue(java.lang.Object)
  * @param value The value to find in the map.
  * @return true if the map contains this value.
  */
 public boolean containsValue(Object value) {
   boolean contains = items.containsValue(value);
   if (!contains && value instanceof COSObject) {
     contains = items.containsValue(((COSObject) value).getObject());
   }
   return contains;
 }
コード例 #3
0
  public void testEmpty() {
    assertTrue("empty map doesn't know it's empty", map.isEmpty());
    assertTrue("empty map doesn't know it's empty", map.size() == 0);
    assertFalse("empty map claims to contain key", map.containsKey(""));
    assertFalse("empty map claims to contain value", map.containsValue(""));
    assertFalse("empty map claims to contain null", map.containsKey(null));
    assertFalse("empty map claims to contain null", map.containsValue(null));
    assertTrue("removing non-existent key returns value", map.remove("foo") == null);

    // testing key set
    Set keys = map.keySet();
    assertTrue("empty map keyset is non-empty", keys.isEmpty());
    assertTrue("empty map keyset is non-empty", keys.size() == 0);
    assertFalse("empty map keyset contains value", keys.contains("foo"));
    assertFalse("empty map keyset contains value", keys.contains(null));
    Iterator it = keys.iterator();
    assertFalse("empty map keyset iterator returns value", it.hasNext());

    // testing values collection
    Collection values = map.values();
    assertTrue("empty map value collection is non-empty", values.isEmpty());
    assertTrue("empty map value collection is non-empty", values.size() == 0);
    assertFalse("empty map value collection contains non-value", values.contains("bar"));
    assertFalse("empty map value collection contains non-value", values.contains(null));
    it = values.iterator();
    assertFalse("empty map value collection iterator returns value", it.hasNext());
  }
コード例 #4
0
  @Test
  public void testFindByFilter() {
    // arrange
    Map<String, List<String>> multiValue = new HashMap<>();
    multiValue.put("title", Arrays.asList("Home"));
    MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>(multiValue);
    List<UserRole> userRoles = new ArrayList<>();
    UserRole userRole = this.buildUserRole();
    userRoles.add(userRole);
    List<User> users = new ArrayList<User>();
    users.add(userRole.getUser());

    Mockito.when(userRoleDao.findByFilter(queryParameters)).thenReturn(userRoles);
    Mockito.when(userRoleDao.count(queryParameters)).thenReturn(10L);
    Mockito.when(userService.fetchUsers(Matchers.anyList())).thenReturn(users);

    // act
    Map<String, Object> result = this.userRoleServiceImpl.findByFilter(queryParameters);

    // assert
    assertTrue(result.containsKey("count"));
    assertTrue(result.containsValue(10L));
    assertTrue(result.containsKey("data"));
    assertTrue(result.containsValue(userRoles));
    Mockito.verify(userRoleDao).count(queryParameters);
    Mockito.verify(userRoleDao).findByFilter(queryParameters);
  }
コード例 #5
0
 static void interchange(String[][] s) {
   int i = 0;
   int j = 0;
   int t = 0;
   String temp[] = new String[3];
   for (i = 0; i < length; i++) {
     System.out.println("i is " + i);
     System.out.println(
         "s[i][1].replace "
             + s[i][1].replaceAll("[^A-Za-z]", "")
             + " s[i][2].replace "
             + s[i][2].replaceAll("[^A-Za-z]", ""));
     if (map.containsValue(s[i][1].replaceAll("[^A-Za-z]", ""))
         || (map.containsValue(s[i][2].replaceAll("[^A-Za-z]", "")))) {
       System.out.println("Found " + s[i][1] + " " + s[i][2]);
       temp = s[i];
       System.out.println("transferred to temp " + temp[0] + " " + temp[1] + " " + temp[2]);
       for (j = i + 1; j < length; j++) {
         s[j - 1] = s[j];
       }
       s[j - 1] = temp;
       if (i != length - 1) {
         t++;
         if (t == length) break;
         i--;
       }
     } else t = 0;
   }
 }
コード例 #6
0
ファイル: TestMap.java プロジェクト: jtransc/jtransc
  /** Tests Map.put(Object, Object) */
  public void testMapPut() {
    if (!isAddRemoveModifiable()) return;

    resetEmpty();

    Object[] keys = getSampleKeys();
    Object[] values = getSampleValues();
    Object[] newValues = getNewSampleValues();

    for (int i = 0; i < keys.length; i++) {
      Object o = map.put(keys[i], values[i]);
      confirmed.put(keys[i], values[i]);
      verify();
      assertTrue("First map.put should return null", o == null);
      assertTrue("Map should contain key after put", map.containsKey(keys[i]));
      assertTrue("Map should contain value after put", map.containsValue(values[i]));
    }

    for (int i = 0; i < keys.length; i++) {
      Object o = map.put(keys[i], newValues[i]);
      confirmed.put(keys[i], newValues[i]);
      verify();
      assertEquals("Second map.put should return previous value", values[i], o);
      assertTrue("Map should still contain key after put", map.containsKey(keys[i]));
      assertTrue("Map should contain new value after put", map.containsValue(newValues[i]));

      // if duplicates are allowed, we're not guarunteed that the value
      // no longer exists, so don't try checking that.
      if (!useDuplicateValues()) {
        assertTrue(
            "Map should not contain old value after second put", !map.containsValue(values[i]));
      }
    }
  }
コード例 #7
0
  /** Tests the setArticleToOpenIssue function */
  public void testLinkArticles() {

    Newsletter newsletter = new Newsletter("BFH Newsletter", "blablabla", 6);
    Issue issue = newsletter.compileIssueAndCreateNew(2007, new Date());

    Article article1 =
        newsletter.addArticle("Article 1", "The newsletter project is really funny ;)");
    Article article2 =
        newsletter.addArticle("Article 2", "The newsletter project is really funny ;)");
    Article article3 =
        newsletter.addArticle("Article 3", "The newsletter project is really funny ;)");

    newsletter.setArticleToOpenIssue(article1.getId());
    newsletter.setArticleToOpenIssue(article2.getId());

    Map unlinkedArticles = newsletter.getUnlinkedArticles();
    Map issueArticles = issue.getArticles();

    assertFalse(unlinkedArticles.containsValue(article1));
    assertFalse(unlinkedArticles.containsValue(article2));
    assertTrue(unlinkedArticles.containsValue(article3));
    assertTrue(unlinkedArticles.size() == 1);

    assertTrue(issueArticles.containsValue(article1));
    assertTrue(issueArticles.containsValue(article2));
    assertFalse(issueArticles.containsValue(article3));
    assertTrue(issueArticles.size() == 2);
  }
コード例 #8
0
  @Test
  public void testGetRoundZeroForFourteenTeams() {
    this.doubleRoundRobinGenerator = new DoubleRoundRobinGenerator(14);

    Map<Integer, Integer> roundExpected = new HashMap<Integer, Integer>();
    roundExpected.put(0, 13);
    roundExpected.put(1, 12);
    roundExpected.put(2, 11);
    roundExpected.put(3, 10);
    roundExpected.put(4, 9);
    roundExpected.put(5, 8);
    roundExpected.put(6, 7);

    Map<Integer, Integer> round = doubleRoundRobinGenerator.getRound(0);

    assertEquals(roundExpected.size(), round.size());

    for (Map.Entry<Integer, Integer> match : roundExpected.entrySet()) {
      Integer home = match.getKey();
      Integer away = match.getValue();

      assertTrue(round.containsKey(home));
      assertTrue(round.containsValue(away));

      assertFalse(round.containsKey(away));
      assertFalse(round.containsValue(home));
    }
  }
コード例 #9
0
  @Test
  public void testGetRoundThirteenForFourteenTeams() {
    this.doubleRoundRobinGenerator = new DoubleRoundRobinGenerator(14);

    Map<Integer, Integer> roundExpected = new HashMap<Integer, Integer>();
    roundExpected.put(13, 0);
    roundExpected.put(12, 1);
    roundExpected.put(11, 2);
    roundExpected.put(10, 3);
    roundExpected.put(9, 4);
    roundExpected.put(8, 5);
    roundExpected.put(7, 6);

    Map<Integer, Integer> round = doubleRoundRobinGenerator.getRound(13);
    // 13 is the first revenge round

    assertEquals(roundExpected.size(), round.size());

    for (Map.Entry<Integer, Integer> match : roundExpected.entrySet()) {
      Integer home = match.getKey();
      Integer away = match.getValue();

      assertTrue(round.containsKey(home));
      assertTrue(round.containsValue(away));

      assertFalse(round.containsKey(away));
      assertFalse(round.containsValue(home));
    }
  }
コード例 #10
0
  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;
  }
コード例 #11
0
 @Test
 public void testContainsValue() throws Exception {
   Map map = createMap();
   ArrayVector value = new ArrayVector(2);
   assertThat(map.containsValue(value)).isFalse();
   value = new ArrayVector(1);
   map.put(new ArrayVector(2), value);
   assertThat(map.containsValue(value)).isTrue();
 }
コード例 #12
0
ファイル: Nave.java プロジェクト: tiagox/ing-software-untref
 public EstadoNave getEstado() {
   if (!posiciones.containsValue(EstadoPosicion.INTACTA)) {
     return EstadoNave.HUNDIDA;
   } else if (posiciones.containsValue(EstadoPosicion.TOCADA)) {
     return EstadoNave.AVERIADA;
   } else {
     return EstadoNave.INTACTA;
   }
 }
コード例 #13
0
ファイル: MyMapTest.java プロジェクト: KezhunNie/javasrc
 @Test
 // map.put("Netscape", "Mountain View, CA");
 // map.put("Microsoft", "Redmond, WA");
 public void testContains() {
   assertTrue(map.containsKey("Netscape"));
   assertTrue(map.containsValue("Mountain View, CA"));
   assertFalse(map.containsKey("Redmond, WA"));
   assertFalse(map.containsValue("Netscape"));
 }
コード例 #14
0
ファイル: PropNetFlattener.java プロジェクト: pkuzhf/ggp-base
  private List<GdlRule> getAllInstantiations() {
    List<GdlRule> rval = new ArrayList<>();

    for (Gdl gdl : description) {
      if (gdl instanceof GdlRelation) {
        GdlRelation relation = (GdlRelation) gdl;
        String name = relation.getName().toString();
        if (name.equals("base")) continue;

        rval.add(GdlPool.getRule(relation));
      }
    }

    for (Domain d : domains.values()) {
      for (RuleReference r : d.ruleRefs) {
        Set<Map<GdlVariable, GdlConstant>> varInstantiations = findSatisfyingInstantiations(r);

        for (Map<GdlVariable, GdlConstant> varInstantiation : varInstantiations) {
          if (varInstantiation.containsValue(null))
            throw new RuntimeException("Shouldn't instantiate anything to null.");
          rval.add(getInstantiation(r.originalRule, varInstantiation));
          if (rval.get(rval.size() - 1).toString().contains("null"))
            throw new RuntimeException(
                "Shouldn't instantiate anything to null: " + rval.get(rval.size() - 1).toString());
        }
      }
    }

    for (RuleReference ruleRef : extraRefs) {
      List<Condition> newConditions = new ArrayList<>();
      for (Condition c : ruleRef.conditions) {
        if (c.dom == null) c.updateDom();

        if (c.dom != null) newConditions.add(c);
      }
      if (newConditions.size() != ruleRef.conditions.size()) // Remove reference to constant terms
      ruleRef.conditions = newConditions;
    }
    for (RuleReference r : extraRefs) {
      Set<Map<GdlVariable, GdlConstant>> varInstantiations = findSatisfyingInstantiations(r);

      for (Map<GdlVariable, GdlConstant> varInstantiation : varInstantiations) {
        if (varInstantiation.containsValue(null))
          throw new RuntimeException("Shouldn't instantiate anything to null.");
        rval.add(getInstantiation(r.originalRule, varInstantiation));

        if (rval.get(rval.size() - 1).toString().contains("null"))
          throw new RuntimeException("Shouldn't instantiate anything to null.");
      }

      if (varInstantiations.size() == 0)
        rval.add(getInstantiation(r.originalRule, new HashMap<GdlVariable, GdlConstant>()));
    }

    return rval;
  }
コード例 #15
0
ファイル: EnumTest.java プロジェクト: PAMSE/APGBench
 public void testExtended1Map() {
     Map map = Extended1Enum.getEnumMap();
     assertNotNull(map);
     assertEquals(map.keySet().size(), Extended1Enum.getEnumList().size());
     
     assertTrue(map.containsValue(Extended1Enum.ALPHA));
     assertTrue(map.containsValue(Extended1Enum.BETA));
     assertSame(Extended1Enum.ALPHA, map.get("Alpha"));
     assertSame(Extended1Enum.BETA, map.get("Beta"));
 }
コード例 #16
0
ファイル: EnumTest.java プロジェクト: PAMSE/APGBench
 public void testOperationMap() {
     Map map = OperationEnum.getEnumMap();
     assertNotNull(map);
     assertEquals(map.keySet().size(), OperationEnum.getEnumList().size());
     
     assertTrue(map.containsValue(OperationEnum.PLUS));
     assertTrue(map.containsValue(OperationEnum.MINUS));
     assertSame(OperationEnum.PLUS, map.get("Plus"));
     assertSame(OperationEnum.MINUS, map.get("Minus"));
 }
コード例 #17
0
ファイル: MatchName.java プロジェクト: goldenheart/mytools
  public static void main(String[] args) {
    ConfirmUser confirmUser = new ConfirmUser("C:\\huangfei\\审过.xls", "sheet1");
    confirmUser.printRepeatUser();
    int size = confirmUser.getConfirmUsers().size();
    int size2 = confirmUser.getRepeatUsers().size();
    int size3 = confirmUser.getNoRepeatUsers().size();
    System.out.println("总:" + size + ",重:" + size2 + "不重:" + size3);

    CatalogUser catalogUser = new CatalogUser("C:\\huangfei\\目录.xls", "Sheet1");
    catalogUser.printRepeatUser();
    int size4 = catalogUser.getCatalogUsers().size();
    int size5 = catalogUser.getRepeatUsers().size();
    int size6 = catalogUser.getNoRepeatUsers().size();
    int size7 = catalogUser.getColorUsers().size();
    System.out.println("总:" + size4 + ",重:" + size5 + "不重:" + size6 + ",带颜色:" + size7);

    Map<Integer, String> repeatUsers = confirmUser.getRepeatUsers();
    Map<Integer, String> repeatUsers2 = catalogUser.getRepeatUsers();
    Set<Entry<Integer, String>> entrySet2 = repeatUsers2.entrySet();
    int count2 = 0;
    for (Entry<Integer, String> entry : entrySet2) {
      String value = entry.getValue();
      Integer key = entry.getKey();
      if (!repeatUsers.containsValue(value)) {
        System.out.println("未核查用户(重名):" + key + "号," + value);
        count2++;
      }
    }
    System.out.println("未核查用户(重名)共:" + count2 + "人");

    Map<Integer, String> noRepeatUsers = confirmUser.getNoRepeatUsers();
    Map<Integer, String> noRepeatUsers2 = catalogUser.getNoRepeatUsers();
    Set<Entry<Integer, String>> entrySet = noRepeatUsers2.entrySet();
    int count = 0;
    for (Entry<Integer, String> entry : entrySet) {
      String value = entry.getValue();
      Integer key = entry.getKey();
      if (!noRepeatUsers.containsValue(value)) {
        System.out.println("未核查用户(不重名):" + key + "号," + value);
        count++;
      }
    }
    System.out.println("未核查用户(不重名)共:" + count + "人");

    Map<Integer, String> colorUsers = catalogUser.getColorUsers();
    Set<Entry<Integer, String>> entrySet3 = colorUsers.entrySet();
    int count3 = 0;
    for (Entry<Integer, String> entry : entrySet3) {
      String value = entry.getValue();
      Integer key = entry.getKey();
      System.out.println("带颜色:" + key + "号," + value);
      count3++;
    }
    System.out.println("带颜色共:" + count3 + "人");
  }
コード例 #18
0
 public void testMapEntrySetContainsNefariousEntry() {
   Map<String, Integer> map = Maps.newTreeMap();
   Map<String, Integer> constrained = MapConstraints.constrainedMap(map, TEST_CONSTRAINT);
   map.put("foo", 1);
   Map.Entry<String, Integer> nefariousEntry = nefariousMapEntry(TEST_KEY, TEST_VALUE);
   Set<Map.Entry<String, Integer>> entries = constrained.entrySet();
   assertFalse(entries.contains(nefariousEntry));
   assertFalse(map.containsValue(TEST_VALUE));
   assertFalse(entries.containsAll(Collections.singleton(nefariousEntry)));
   assertFalse(map.containsValue(TEST_VALUE));
 }
コード例 #19
0
 // -----------------------------------------------------------------------
 public void testMap() {
   Map map = EnumUtils.getEnumMap(ColorEnum.class);
   assertTrue(map.containsValue(ColorEnum.RED));
   assertTrue(map.containsValue(ColorEnum.GREEN));
   assertTrue(map.containsValue(ColorEnum.BLUE));
   assertSame(ColorEnum.RED, map.get("Red"));
   assertSame(ColorEnum.GREEN, map.get("Green"));
   assertSame(ColorEnum.BLUE, map.get("Blue"));
   map = EnumUtils.getEnumMap(DummyEnum.class);
   assertEquals(0, map.size());
 }
コード例 #20
0
  @Test
  public void testContainsValue() {
    Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"));
    map.put(new SimpleKey("33"), new SimpleValue("44"));
    map.put(new SimpleKey("5"), new SimpleValue("6"));

    Assert.assertTrue(map.containsValue(new SimpleValue("2")));
    Assert.assertFalse(map.containsValue(new SimpleValue("441")));
    Assert.assertFalse(map.containsValue(new SimpleKey("5")));
  }
コード例 #21
0
ファイル: TableTest.java プロジェクト: changhwa/reserve
  @Test
  public void getByColumn() {
    table.put(1, 1, "Test1");
    table.put(1, 2, "Test2");
    table.put(2, 1, "Test3");

    Map<Integer, String> map = table.getByRow(1);

    assertThat(2, is(map.size()));
    assertThat(true, is(map.containsValue("Test1")));
    assertThat(true, is(map.containsValue("Test2")));
    assertThat(false, is(map.containsValue("Test3")));
  }
コード例 #22
0
  /** Test that the full list iterator contract is correct. */
  @Override
  public void testFullMapIterator() {
    if (!supportsFullIterator()) {
      return;
    }

    super.testFullMapIterator();

    final OrderedMapIterator<K, V> it = makeObject();
    final Map<K, V> map = getMap();

    assertEquals(true, it.hasNext());
    assertEquals(false, it.hasPrevious());
    final Set<K> set = new HashSet<K>();
    while (it.hasNext()) {
      // getKey
      final K 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
      final V value = it.getValue();
      if (!isGetStructuralModify()) {
        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
      final 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
      final Object value = it.getValue();
      if (!isGetStructuralModify()) {
        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();
    }
  }
コード例 #23
0
ファイル: ValuedEnumTest.java プロジェクト: BIORIMP/biorimp
  public void testMap() {
    Map map = ValuedColorEnum.getEnumMap();

    assertNotNull(map);

    assertEquals(map.keySet().size(), ValuedColorEnum.getEnumList().size());

    assertTrue(map.containsValue(ValuedColorEnum.RED));
    assertTrue(map.containsValue(ValuedColorEnum.GREEN));
    assertTrue(map.containsValue(ValuedColorEnum.BLUE));
    assertSame(ValuedColorEnum.RED, map.get("Red"));
    assertSame(ValuedColorEnum.GREEN, map.get("Green"));
    assertSame(ValuedColorEnum.BLUE, map.get("Blue"));
  }
コード例 #24
0
ファイル: TestMap.java プロジェクト: jtransc/jtransc
  /**
   * Tests Map.containsValue(Object) by verifying it returns false for all sample values on an empty
   * map and returns true for all sample values on a full map.
   */
  public void testMapContainsValue() {
    Object[] values = getSampleValues();

    resetEmpty();
    for (int i = 0; i < values.length; i++) {
      assertTrue("Empty map must not contain value", !map.containsValue(values[i]));
    }
    verify();

    resetFull();
    for (int i = 0; i < values.length; i++) {
      assertTrue("Map must contain value for a mapping in the map.", map.containsValue(values[i]));
    }
    verify();
  }
コード例 #25
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"));
  }
コード例 #26
0
ファイル: MatchName.java プロジェクト: goldenheart/mytools
 private void noRepeat() {
   Set<Entry<Integer, String>> entrySet = confirmUsers.entrySet();
   for (Entry<Integer, String> entry : entrySet) {
     Integer key = entry.getKey();
     String value = entry.getValue();
     if (repeatUsers.containsKey(key) && repeatUsers.containsValue(value)) {
       continue;
     }
     if (repeatUsers.containsValue(value)) {
       repeatUsers.put(key, value);
       continue;
     }
     noRepeatUsers.put(key, value);
   }
 }
コード例 #27
0
  /**
   * Closes the given <code>PageComponent</code>. This method disposes the <code>PageComponent
   * </code>, triggers all necessary events ("focus lost" and "closed"), and will activate another
   * <code>PageComponent</code> (if there is one).
   *
   * <p>Does nothing if this <code>ApplicationPage</code> doesn't contain the given <code>
   * PageComponent</code>.
   *
   * @param pageComponent the <code>PageComponent</code>
   */
  @Override
  public void close(PageComponent pageComponent) {
    if (!pageComponentMap.containsValue(pageComponent)) {
      return;
    }

    if (pageComponent == activeComponent) {
      fireFocusLost(pageComponent);
      activeComponent = null;
    }

    pageComponentMap.remove(pageComponent.getId());
    if (pageComponent instanceof ToolView) {
      ToolView toolView = (ToolView) pageComponent;
      doRemoveToolView(toolView);
    } else if (pageComponent instanceof DocView) {
      // todo - DocView docView = (DocView) pageComponent;
      // todo - doRemoveDocView(docView);
    }

    pageComponent.removePropertyChangeListener(pageComponentUpdater);

    fireHidden(pageComponent);
    fireClosed(pageComponent);

    pageComponent.dispose();

    if (activeComponent == null) {
      setActiveComponent();
    }
  }
コード例 #28
0
ファイル: TestMap.java プロジェクト: jtransc/jtransc
 private static void assertEmptyMap(Map map, final String[] keys, final Object[] values) {
   for (int i = 0; i < keys.length; i++) {
     assertFalse(keys[i], map.containsKey(keys[i]));
     assertFalse(keys[i], map.containsValue(values[i]));
     assertNull(keys[i], map.get(keys[i]));
   }
 }
コード例 #29
0
  /**
   * Activates the given <code>PageComponent</code>. Does nothing if it is already the active one.
   *
   * <p>Does nothing if this <code>ApplicationPage</code> doesn't contain the given <code>
   * PageComponent</code>.
   *
   * @param pageComponent the <code>PageComponent</code>
   */
  public void setActiveComponent(PageComponent pageComponent) {
    if (!pageComponentMap.containsValue(pageComponent)) {
      return;
    }

    Debug.trace("setActiveComponent: pageComponent = " + pageComponent);
    if (settingActiveComponent) {
      return;
    }

    // if pageComponent is already active, don't do anything
    if (this.activeComponent == pageComponent) {
      setActiveSelectionContext();
      return;
    }

    settingActiveComponent = true;

    if (this.activeComponent != null) {
      fireFocusLost(this.activeComponent);
    }
    giveFocusTo(pageComponent);
    this.activeComponent = pageComponent;
    fireFocusGained(this.activeComponent);

    setActiveSelectionContext();

    settingActiveComponent = false;
  }
コード例 #30
0
  private MyBooleanExpression(String expression) throws ParseException {
    expression = expression.replaceAll(" ", "").replaceAll("!", "~");
    this.repr = expression;
    Pattern pattern = Pattern.compile("[()~&|=>+]");
    String[] vars = pattern.split(expression);

    HashSet<String> varsSet = new HashSet<>(Arrays.asList(vars));
    varsSet.removeAll(Arrays.asList(new String[] {"", "1", "0"}));
    this.variables = varsSet.toArray(new String[0]);

    assert variables.length < 26;

    String shortExpr = new String(expression);
    for (int i = 0; i < variables.length; i++) {
      shortExpr = shortExpr.replaceAll(variables[i], "___" + i);
    }
    for (int i = 0; i < variables.length; i++) {
      shortExpr = shortExpr.replaceAll("___" + i, "" + (char) ('a' + i));
    }

    // System.out.println(shortExpr);

    BooleanExpression booleanExpression = new BooleanExpression(shortExpr);
    Map<Map<String, Boolean>, Map<BooleanExpression, Boolean>> truthTable =
        new TruthTable(booleanExpression).getResults();
    this.truthTable = new HashMap<>();

    for (Map<String, Boolean> map : truthTable.keySet()) {
      Map<BooleanExpression, Boolean> booleanMap = truthTable.get(map);
      boolean val = booleanMap.containsValue(true);
      satisfiabilitySetsCount += val ? 1 : 0;
      this.truthTable.put(map, val);
    }
  }