@Test public void testWithNullAsKeyAndValue() throws Exception { final T cache = getInstance(1000, 1000); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(null)); assertNull(cache.get(null)); // Add entry with null as key and value ... cache.put(null, null); assertEquals(1, (long) cache.size()); assertTrue(cache.contains(null)); assertNull(cache.get(null)); // Add another entry ... cache.put(new Object(), new Object()); assertEquals(2, (long) cache.size()); // Remove entry with null as key ... assertNull(cache.remove(null).getValue()); assertEquals(1, (long) cache.size()); assertFalse(cache.contains(null)); assertNull(cache.get(null)); // Try to remove entry with null as key again ... assertNull(cache.remove(null)); assertEquals(1, (long) cache.size()); assertFalse(cache.contains(null)); assertNull(cache.get(null)); }
private void compactNodes(T node) { for (int i = 0; i < node.getChildCount(); i++) { MPSTreeNode child = (MPSTreeNode) node.getChildAt(i); if (myBuilder.isNamespaceNode(child)) { compactNodes((T) child); } } if (node.getParent() != null && // skip root node.getChildCount() == 1 && myBuilder.isNamespaceNode((MPSTreeNode) node.getChildAt(0))) { T child = (T) node.getChildAt(0); myBuilder.setName(node, myBuilder.getName(node) + "." + myBuilder.getName(child)); Enumeration children = child.children(); List<MPSTreeNode> oldChildren = new ArrayList<MPSTreeNode>(); while (children.hasMoreElements()) { oldChildren.add((MPSTreeNode) children.nextElement()); } for (MPSTreeNode c : oldChildren) { child.remove(c); node.add(c); } node.remove(child); } }
public static <T extends TreeNode> T remove(T node) { if (node == null) { return null; } node.remove(); return node; }
public void remove(T dao, Long id) { try { dao.remove(id); } catch (DAOException ex) { throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage()); } }
@Test public void testWithNullAsValue() throws Exception { final T cache = getInstance(1000, 1000); final Object o = new Object(); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(o)); assertNull(cache.get(o)); // Add entry with null as value ... cache.put(o, null); assertEquals(1, (long) cache.size()); assertTrue(cache.contains(o)); assertNull(cache.get(o)); // Remove entry with null as value ... assertNull(cache.remove(o).getValue()); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(o)); assertNull(cache.get(o)); // Try to remove entry with null as value again ... assertNull(cache.remove(o)); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(o)); assertNull(cache.get(o)); }
public void fillNode(MPSTreeNode root) { sortTree(myRootNamespace); compactNodes(myRootNamespace); Enumeration children = myRootNamespace.children(); List<MPSTreeNode> oldChildren = new ArrayList<MPSTreeNode>(); while (children.hasMoreElements()) { oldChildren.add((MPSTreeNode) children.nextElement()); } for (MPSTreeNode node : oldChildren) { myRootNamespace.remove(node); root.add(node); } }
private Connection<Object> findConnection(List<DaemonStatus> statuses) { for (DaemonStatus status : statuses) { Address address = status.getAddress(); try { return new TcpOutgoingConnector<Object>( new DefaultMessageSerializer<Object>(getClass().getClassLoader())) .connect(address); } catch (ConnectException e) { // this means the daemon died without removing its address from the registry // we can safely remove this address now daemonRegistry.remove(address); } } return null; }
private <T extends ModelEntity> void _delete(T entity, List<ProcessingEvent> events) throws PersistenceException { // give the event notifiers an opportunity to act, prior to deletion entity.remove(); entityManager.remove(entity); }
@Override public Element remove(final Object key) { return copyElementForReadIfNeeded(store.remove(key)); }