@Test public void testPutRemoveGet() { Map<Integer, Integer> myMap = new MyMap<>(); Map<Integer, Integer> control = new HashMap<>(); for (int i = 0; i < N; i++) { int k = random.nextInt(); int v = random.nextInt(); myMap.put(k, v); control.put(k, v); } Set<Integer> keysToRemove = new HashSet<>(); for (int k : control.keySet()) { if (random.nextBoolean()) { keysToRemove.add(k); } } for (int k : keysToRemove) { control.remove(k); myMap.remove(k); } assertEquals(myMap.size(), control.size()); for (int k : control.keySet()) { assertEquals(myMap.get(k), control.get(k)); int r = random.nextInt(); assertEquals(myMap.get(r), control.get(r)); } }
public void forgetTax(ICFAccTaxObj Obj, boolean forgetSubObjects) { ICFAccTaxObj obj = Obj; CFAccTaxPKey pkey = obj.getPKey(); if (members.containsKey(pkey)) { ICFAccTaxObj keepObj = members.get(pkey); // Detach object from alternate, duplicate, all and PKey indexes if (indexByTenantIdx != null) { CFAccTaxByTenantIdxKey keyTenantIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx); if (mapTenantIdx != null) { mapTenantIdx.remove(keepObj.getPKey()); } } if (indexByUNameIdx != null) { CFAccTaxByUNameIdxKey keyUNameIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey(); keyUNameIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyUNameIdx.setRequiredName(keepObj.getRequiredName()); indexByUNameIdx.remove(keyUNameIdx); } if (allTax != null) { allTax.remove(keepObj.getPKey()); } members.remove(pkey); if (forgetSubObjects) {} } }
// Store the invariant for later printing. Ignore duplicate // invariants at the same program point. private static boolean store_invariant( String predicate, String index, HashedConsequent consequent, String pptname) { if (!pptname_to_conditions.containsKey(pptname)) { pptname_to_conditions.put(pptname, new HashMap<String, Map<String, HashedConsequent>>()); } Map<String, Map<String, HashedConsequent>> cluster_to_conditions = pptname_to_conditions.get(pptname); if (!cluster_to_conditions.containsKey(predicate)) { cluster_to_conditions.put(predicate, new HashMap<String, HashedConsequent>()); } Map<String, HashedConsequent> conditions = cluster_to_conditions.get(predicate); if (conditions.containsKey(index)) { HashedConsequent old = conditions.get(index); if (old.fakeFor != null && consequent.fakeFor == null) { // We already saw (say) "x != y", but we're "x == y", so replace it. conditions.remove(index); conditions.remove(old.fakeFor); conditions.put(index, consequent); return true; } return false; } else { conditions.put(index, consequent); return true; } }
public void updateSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) { CFSecuritySecDevicePKey pkey = schema.getFactorySecDevice().newPKey(); pkey.setRequiredSecUserId(Buff.getRequiredSecUserId()); pkey.setRequiredDevName(Buff.getRequiredDevName()); CFSecuritySecDeviceBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory() .newStaleCacheDetectedException( getClass(), "updateSecDevice", "Existing record not found", "SecDevice", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "updateSecDevice", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); CFSecuritySecDeviceByUserIdxKey existingKeyUserIdx = schema.getFactorySecDevice().newUserIdxKey(); existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFSecuritySecDeviceByUserIdxKey newKeyUserIdx = schema.getFactorySecDevice().newUserIdxKey(); newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema .getTableSecUser() .readDerivedByIdIdx(Authorization, Buff.getRequiredSecUserId())) { throw CFLib.getDefaultExceptionFactory() .newUnresolvedRelationException( getClass(), "updateSecDevice", "Container", "SecDeviceSecUser", "SecUser", null); } } } // Update is valid Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByUserIdx.get(existingKeyUserIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByUserIdx.containsKey(newKeyUserIdx)) { subdict = dictByUserIdx.get(newKeyUserIdx); } else { subdict = new HashMap<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff>(); dictByUserIdx.put(newKeyUserIdx, subdict); } subdict.put(pkey, Buff); }
public void deleteOptFullRange( CFSecurityAuthorization Authorization, CFDbTestOptFullRangeBuff Buff) { final String S_ProcName = "CFDbTestRamOptFullRangeTable.deleteOptFullRange() "; CFDbTestOptFullRangePKey pkey = schema.getFactoryOptFullRange().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); CFDbTestOptFullRangeBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "deleteOptFullRange", pkey); } CFDbTestOptFullRangeByUDescrIdxKey keyUDescrIdx = schema.getFactoryOptFullRange().newUDescrIdxKey(); keyUDescrIdx.setRequiredTenantId(existing.getRequiredTenantId()); keyUDescrIdx.setRequiredDescription(existing.getRequiredDescription()); CFDbTestOptFullRangeByTenantIdxKey keyTenantIdx = schema.getFactoryOptFullRange().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId()); // Validate reverse foreign keys // Delete is valid Map<CFDbTestOptFullRangePKey, CFDbTestOptFullRangeBuff> subdict; dictByPKey.remove(pkey); dictByUDescrIdx.remove(keyUDescrIdx); subdict = dictByTenantIdx.get(keyTenantIdx); subdict.remove(pkey); }
public void deleteLoaderBehaviour( CFSecurityAuthorization Authorization, CFDbTestLoaderBehaviourBuff Buff) { final String S_ProcName = "CFDbTestRamLoaderBehaviourTable.deleteLoaderBehaviour() "; CFDbTestLoaderBehaviourPKey pkey = schema.getFactoryLoaderBehaviour().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); CFDbTestLoaderBehaviourBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "deleteLoaderBehaviour", pkey); } CFDbTestLoaderBehaviourByUNameIdxKey keyUNameIdx = schema.getFactoryLoaderBehaviour().newUNameIdxKey(); keyUNameIdx.setRequiredName(existing.getRequiredName()); // Validate reverse foreign keys // Delete is valid Map<CFDbTestLoaderBehaviourPKey, CFDbTestLoaderBehaviourBuff> subdict; dictByPKey.remove(pkey); dictByUNameIdx.remove(keyUNameIdx); }
public void forgetSecDevice(ICFSecuritySecDeviceObj Obj, boolean forgetSubObjects) { ICFSecuritySecDeviceObj obj = Obj; CFSecuritySecDevicePKey pkey = obj.getPKey(); if (members.containsKey(pkey)) { ICFSecuritySecDeviceObj keepObj = members.get(pkey); // Detach object from alternate, duplicate, all and PKey indexes if (indexByUserIdx != null) { CFSecuritySecDeviceByUserIdxKey keyUserIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey(); keyUserIdx.setRequiredSecUserId(keepObj.getRequiredSecUserId()); Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx = indexByUserIdx.get(keyUserIdx); if (mapUserIdx != null) { mapUserIdx.remove(keepObj.getPKey()); } } if (allSecDevice != null) { allSecDevice.remove(keepObj.getPKey()); } members.remove(pkey); if (forgetSubObjects) {} } }
/** * @param host * @param notify * @return */ private boolean remove(SiteHost host, boolean notify) { Logger.info("WorkPool.remove, work site %s", host); boolean success = false; this.lockSingle(); try { mapTime.remove(host); WorkSite site = mapSite.remove(host); if (site != null) { for (Naming naming : site.list()) { SiteSet set = mapNaming.get(naming); if (set != null) { set.remove(host); } if (set == null || set.isEmpty()) { mapNaming.remove(naming); } } success = true; if (notify) { CallPool.getInstance().refreshWorkSite(); } } } catch (Throwable exp) { Logger.error(exp); } finally { this.unlockSingle(); } return success; }
/** Applies a delete resource commit. */ protected boolean deleteResource(Commit<DeleteResource> commit) { try { ResourceHolder resourceHolder = resources.remove(commit.operation().resource()); if (resourceHolder == null) { throw new ResourceManagerException("unknown resource: " + commit.operation().resource()); } // Delete the resource state machine and close the resource state machine executor. try { resourceHolder.stateMachine.delete(); resourceHolder.executor.close(); } finally { resourceHolder.commit.close(); } // Close all commits that opened sessions to the resource. for (SessionHolder sessionHolder : resourceHolder.sessions.values()) { sessionHolder.commit.close(); } keys.remove(resourceHolder.key); return true; } finally { commit.close(); } }
public void deleteISOCurrency(CFBamAuthorization Authorization, CFBamISOCurrencyBuff Buff) { final String S_ProcName = "CFBamRamISOCurrencyTable.deleteISOCurrency() "; CFBamISOCurrencyPKey pkey = schema.getFactoryISOCurrency().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); CFBamISOCurrencyBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "deleteISOCurrency", pkey); } CFBamISOCurrencyByCcyCdIdxKey keyCcyCdIdx = schema.getFactoryISOCurrency().newCcyCdIdxKey(); keyCcyCdIdx.setRequiredISOCode(existing.getRequiredISOCode()); CFBamISOCurrencyByCcyNmIdxKey keyCcyNmIdx = schema.getFactoryISOCurrency().newCcyNmIdxKey(); keyCcyNmIdx.setRequiredName(existing.getRequiredName()); // Validate reverse foreign keys // Delete is valid schema .getTableISOCountryCurrency() .deleteISOCountryCurrencyByCurrencyIdx(Authorization, Buff.getRequiredId()); Map<CFBamISOCurrencyPKey, CFBamISOCurrencyBuff> subdict; dictByPKey.remove(pkey); dictByCcyCdIdx.remove(keyCcyCdIdx); dictByCcyNmIdx.remove(keyCcyNmIdx); }
public synchronized PolicyCollection getDocument(final File file) throws PoliciesParseException { // cacheTotal++; CacheItem entry = cache.get(file); long checkTime = System.currentTimeMillis(); if (null == entry || ((checkTime - entry.cacheTime) > FILE_CHECK_DELAY)) { final long lastmod = file.lastModified(); if (null == entry || lastmod > entry.modTime) { if (!file.exists()) { CacheItem remove = cache.remove(file); entry = null; // cacheRemove++; } else { // cacheMiss++; PolicyCollection entry1 = createEntry(file); if (null != entry1) { entry = new CacheItem(entry1, lastmod); cache.put(file, entry); } else { cache.remove(file); entry = null; } } } else { // cacheUnmodifiedHit++; entry.touch(checkTime); } } else { // cacheHit++; } return null != entry ? entry.policyCollection : null; }
public void deleteSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) { final String S_ProcName = "CFAsteriskRamSecDeviceTable.deleteSecDevice() "; CFSecuritySecDevicePKey pkey = schema.getFactorySecDevice().newPKey(); pkey.setRequiredSecUserId(Buff.getRequiredSecUserId()); pkey.setRequiredDevName(Buff.getRequiredDevName()); CFSecuritySecDeviceBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "deleteSecDevice", pkey); } CFSecuritySecDeviceByUserIdxKey keyUserIdx = schema.getFactorySecDevice().newUserIdxKey(); keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); // Validate reverse foreign keys // Delete is valid Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdict; dictByPKey.remove(pkey); subdict = dictByUserIdx.get(keyUserIdx); subdict.remove(pkey); }
private void processImageResponse( ImageResponse response, String graphObjectId, ImageView imageView) { pendingRequests.remove(graphObjectId); if (response.getError() != null) { callOnErrorListener(response.getError()); } if (imageView == null) { // This was a pre-fetch request. if (response.getBitmap() != null) { // Is the cache too big? if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) { // Find the oldest one and remove it. String oldestId = prefetchedProfilePictureIds.remove(0); prefetchedPictureCache.remove(oldestId); } prefetchedPictureCache.put(graphObjectId, response); } } else if (graphObjectId.equals(imageView.getTag())) { Exception error = response.getError(); Bitmap bitmap = response.getBitmap(); if (error == null && bitmap != null) { imageView.setImageBitmap(bitmap); imageView.setTag(response.getRequest().getImageUri()); } } }
public void setTransientProperty(Object key1, Object key2, Object value) { synchronized (transient_properties) { Map<Object, Object> l1 = (Map<Object, Object>) transient_properties.get(key1); if (l1 == null) { if (value == null) { return; } l1 = new HashMap<Object, Object>(); transient_properties.put(key1, l1); } if (value == null) { l1.remove(key2); if (l1.size() == 0) { transient_properties.remove(key1); } } else { l1.put(key2, value); } } }
public void forgetServiceType(ICFSecurityServiceTypeObj Obj, boolean forgetSubObjects) { ICFSecurityServiceTypeObj obj = Obj; CFSecurityServiceTypePKey pkey = obj.getPKey(); if (members.containsKey(pkey)) { ICFSecurityServiceTypeObj keepObj = members.get(pkey); // Detach object from alternate, duplicate, all and PKey indexes if (indexByUDescrIdx != null) { CFSecurityServiceTypeByUDescrIdxKey keyUDescrIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey(); keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription()); indexByUDescrIdx.remove(keyUDescrIdx); } if (allServiceType != null) { allServiceType.remove(keepObj.getPKey()); } members.remove(pkey); if (forgetSubObjects) { ((ICFSecuritySchemaObj) schema) .getServiceTableObj() .forgetServiceByTypeIdx(keepObj.getRequiredServiceTypeId()); } } }
private Object unmarshall(PersistentEntity persistentEntity, Long id, Map<String, Object> data) { log.debug("unmarshalling entity {}, props {}, {}", id, data); EntityAccess entityAccess = new EntityAccess(persistentEntity, persistentEntity.newInstance()); entityAccess.setConversionService(persistentEntity.getMappingContext().getConversionService()); entityAccess.setIdentifier(id); data.remove("__id__"); for (PersistentProperty property : entityAccess.getPersistentEntity().getPersistentProperties()) { String propertyName = property.getName(); if (property instanceof Simple) { // implicitly sets version property as well entityAccess.setProperty(propertyName, data.remove(propertyName)); // } else if (property instanceof OneToOne) { // log.error("property " + property.getName() + " is of type " + // property.getClass().getSuperclass()); } else if (property instanceof ToOne) { ToOne to = (ToOne) property; CypherResult cypherResult = getSession() .getNativeInterface() .execute( CypherBuilder.findRelationshipEndpointIdsFor(to), Collections.singletonMap("id", id)); Map<String, Object> row = IteratorUtil.singleOrNull(cypherResult); if (row != null) { Long endpointId = (Long) row.get("id"); entityAccess.setProperty( propertyName, getMappingContext() .getProxyFactory() .createProxy(session, to.getAssociatedEntity().getJavaClass(), endpointId)); } } else if ((property instanceof OneToMany) || (property instanceof ManyToMany)) { LazyEnititySet lazyEnititySet = new LazyEnititySet( entityAccess, (Association) property, getMappingContext().getProxyFactory(), getSession()); entityAccess.setProperty(propertyName, lazyEnititySet); } else { throw new IllegalArgumentException( "property $property.name is of type ${property.class.superclass}"); } } if (!data.isEmpty()) { GroovyObject go = (GroovyObject) (entityAccess.getEntity()); go.setProperty(Neo4jGormEnhancer.UNDECLARED_PROPERTIES, data); } firePostLoadEvent(entityAccess.getPersistentEntity(), entityAccess); return entityAccess.getEntity(); }
public void removeDestination(Coordinate coordinate, int dimension) { GlobalCoordinate key = new GlobalCoordinate(coordinate, dimension); Integer id = protectorIdByCoordinate.get(key); if (id != null) { protectorById.remove(id); protectorIdByCoordinate.remove(key); } }
public void removeRitualFromList() { if (ritualMap.containsValue(this)) { ritualMap.remove(ritualMap.remove(this.name)); } if (keyList.contains(this.name)) { keyList.remove(this.name); } }
private void removeid(Widget wdg) { if (rwidgets.containsKey(wdg)) { int id = rwidgets.get(wdg); widgets.remove(id); rwidgets.remove(wdg); } for (Widget child = wdg.child; child != null; child = child.next) removeid(child); }
@Transactional @Override @CacheEvict(value = "hooks", allEntries = true) public CommandProcessingResult updateHook(final Long hookId, final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForUpdate(command.json()); final Hook hook = retrieveHookBy(hookId); final HookTemplate template = hook.getHookTemplate(); final Map<String, Object> changes = hook.update(command); if (!changes.isEmpty()) { if (changes.containsKey(templateIdParamName)) { final Long ugdTemplateId = command.longValueOfParameterNamed(templateIdParamName); final Template ugdTemplate = this.ugdTemplateRepository.findOne(ugdTemplateId); if (ugdTemplate == null) { changes.remove(templateIdParamName); throw new TemplateNotFoundException(ugdTemplateId); } hook.updateUgdTemplate(ugdTemplate); } if (changes.containsKey(eventsParamName)) { final Set<HookResource> events = assembleSetOfEvents(command.arrayOfParameterNamed(eventsParamName)); final boolean updated = hook.updateEvents(events); if (!updated) { changes.remove(eventsParamName); } } if (changes.containsKey(configParamName)) { final String configJson = command.jsonFragment(configParamName); final Set<HookConfiguration> config = assembleConfig(command.mapValueOfParameterNamed(configJson), template); final boolean updated = hook.updateConfig(config); if (!updated) { changes.remove(configParamName); } } this.hookRepository.saveAndFlush(hook); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(hookId) // .with(changes) // .build(); } catch (final DataIntegrityViolationException dve) { handleHookDataIntegrityIssues(command, dve); return null; } }
protected void exportToBEncodedMap(Map map, boolean for_export) throws IOException { String cla = this.getClass().getName(); if (cla.startsWith(MY_PACKAGE)) { cla = cla.substring(MY_PACKAGE.length()); } ImportExportUtils.exportString(map, "_impl", cla); ImportExportUtils.exportLong(map, "_type", type); ImportExportUtils.exportString(map, "_uid", uid); ImportExportUtils.exportString(map, "_name", classification); ImportExportUtils.exportBoolean(map, "_autoname", isNameAutomatic); ImportExportUtils.exportLong(map, "_rn", 1); ImportExportUtils.exportString(map, "_lname", name); ImportExportUtils.exportString(map, "_image_id", image_id); if (secondary_uid != null) { ImportExportUtils.exportString(map, "_suid", secondary_uid); } if (!for_export) { ImportExportUtils.exportLong(map, "_ls", last_seen); ImportExportUtils.exportBoolean(map, "_hide", hidden); ImportExportUtils.exportBoolean(map, "_ahide", auto_hidden); } ImportExportUtils.exportBoolean(map, "_rm", can_remove); ImportExportUtils.exportBoolean(map, "_genericUSB", isGenericUSB); ImportExportUtils.exportBoolean(map, "_man", manual); if (tagged) { ImportExportUtils.exportBoolean(map, "_tag", tagged); } Map<String, Object> pp_copy; synchronized (persistent_properties) { pp_copy = new HashMap<String, Object>(persistent_properties); } if (for_export) { pp_copy.remove(PP_IP_ADDRESS); pp_copy.remove(PP_COPY_OUTSTANDING); pp_copy.remove(PP_COPY_TO_FOLDER); pp_copy.remove(PP_REND_WORK_DIR); map.put("_pprops", pp_copy); } else { map.put("_pprops", pp_copy); } }
public void removeChannel(Channel channel) { lock.lock(); try { if (channel.getDirection() == Direction.OUT) { BrokerHost registeredHost = null; for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToProducerChannelMap.entrySet()) { List<Channel> channels = e.getValue(); Iterator<Channel> channelIterator = channels.iterator(); while (channelIterator.hasNext()) { Channel c = channelIterator.next(); if (c.equals(channel)) { registeredHost = e.getKey(); channelIterator.remove(); // if there are no more channels remove the producer if (channels.size() == 0) { Manageable producer = producers.remove(registeredHost); producer.stop(); } break; } } if (registeredHost != null) { break; } } } else if (channel.getDirection() == Direction.IN) { BrokerHost registeredHost = null; for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToConsumerChannelMap.entrySet()) { List<Channel> channels = e.getValue(); Iterator<Channel> channelIterator = channels.iterator(); while (channelIterator.hasNext()) { Channel c = channelIterator.next(); if (c.equals(channel)) { registeredHost = e.getKey(); channelIterator.remove(); // if there are no more channels remove the producer if (channels.size() == 0) { ConsumingWorker worker = consumingWorkers.remove(registeredHost); worker.stop(); Manageable consumer = consumers.remove(registeredHost); consumer.stop(); } break; } } if (registeredHost != null) { break; } } } } finally { lock.unlock(); } }
@Test public void removeFromMap() { HazelcastClient hClient = getHazelcastClient(); Map map = hClient.getMap("removeFromMap"); assertNull(map.put("a", "b")); assertEquals("b", map.get("a")); assertEquals("b", map.remove("a")); assertNull(map.remove("a")); assertNull(map.get("a")); }
public void removeDescriptor(IArtifactKey key, IProgressMonitor monitor) { for (IArtifactDescriptor nextDescriptor : artifactDescriptors) { if (key.equals(nextDescriptor.getArtifactKey())) artifactDescriptors.remove(nextDescriptor); } if (keysToLocations.containsKey(key)) { URI theLocation = keysToLocations.get(key); locationsToContents.remove(theLocation); keysToLocations.remove(key); } }
/** * Removes an NPC from the Registry when removed from Citizens. * * @param event NPCRemoveEvent */ @EventHandler public void onRemove(NPCRemoveEvent event) { NPC npc = event.getNPC(); getDenizen(npc).action("remove", null); if (_isRegistered(npc)) { denizenNPCs.remove(npc.getId()); npcInventories.remove(npc.getId()); } FlagManager.clearNPCFlags(npc.getId()); }
@Override public void removeElement(String label) { if (vocabs.containsKey(label)) { vocabs.remove(label); } if (tokens.containsKey(label)) { tokens.remove(label); } }
/** Handle a read event from a socket specified by the key. */ private void read(SelectionKey key) throws IOException { SocketChannel socketChannel = (SocketChannel) key.channel(); SocketAddress remoteAdr = socketChannel.socket().getRemoteSocketAddress(); // Clear out our read buffer so it's ready for new data readBuffer.clear(); // Attempt to read off the channel int numRead; try { numRead = socketChannel.read(readBuffer); } catch (IOException e) { // The remote forcibly closed the connection, cancel // the selection key and close the channel. key.cancel(); socketChannel.close(); clients.remove(remoteAdr); pendingWriteData.remove(socketChannel); logger.fine( "Connection forcibly closed(" + remoteAdr + ")! Remaining connections: " + clients.size()); throw new IOException("Remote forcibly closed the connection"); } if (numRead == -1) { // Remote entity shut the socket down cleanly. Do the // same from our end and cancel the channel. key.channel().close(); key.cancel(); clients.remove(remoteAdr); pendingWriteData.remove(socketChannel); logger.fine("Connection Closed(" + remoteAdr + ")! Remaining connections: " + clients.size()); throw new IOException("Remote closed the connection"); } // Make a correctly sized copy of the data before handing it to the client // byte[] rspByteData = new byte[numRead]; // System.arraycopy(readBuffer.array(), 0, rspByteData, 0, numRead); try { Object rspData = Converter.toObject(readBuffer.array()); // Hand the data off to our worker thread if (worker != null) { logger.finer("Handling incoming message..."); worker.processData(this, socketChannel.getRemoteAddress(), rspData); } else { logger.fine("No worker set, message unhandled!"); } } catch (Exception e) { e.printStackTrace(); } }
public final void clearCache() { getCache().clear(); getView().refresh(); size_ = -1; final Map<String, Object> requestScope = getRequestScope(); String thisToString = this.toString(); requestScope.remove("viewnav-" + thisToString); requestScope.remove("viewentries-" + thisToString); requestScope.remove("lastFetchedIndex-" + thisToString); }
private BundleManager removeBundleManager(long bundleId) { BundleManager bundleManager = bundleManagers.remove(bundleId); if (bundleManager == null) { log.warn(this + " tried to remove unknown bundle manager for bundle " + bundleId); return null; } for (String type : bundleManager) { typedBundleManagers.remove(type); } return bundleManager; }
/** * Translate the given abstract syntax trees to elements. * * @param trees a list of abstract syntax trees. * @throws java.io.IOException TODO * @return a list of elements corresponding to the top level classes in the abstract syntax trees */ public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees) throws IOException { prepareCompiler(); ListBuffer<JCCompilationUnit> roots = null; if (trees == null) { // If there are still files which were specified to be compiled // (i.e. in fileObjects) but which have not yet been entered, // then we make sure they have been parsed and add them to the // list to be entered. if (notYetEntered.size() > 0) { if (!parsed) parse(); // TODO would be nice to specify files needed to be parsed for (JavaFileObject file : fileObjects) { JCCompilationUnit unit = notYetEntered.remove(file); if (unit != null) { if (roots == null) roots = new ListBuffer<JCCompilationUnit>(); roots.append(unit); } } notYetEntered.clear(); } } else { for (CompilationUnitTree cu : trees) { if (cu instanceof JCCompilationUnit) { if (roots == null) roots = new ListBuffer<JCCompilationUnit>(); roots.append((JCCompilationUnit) cu); notYetEntered.remove(cu.getSourceFile()); } else throw new IllegalArgumentException(cu.toString()); } } if (roots == null) return List.nil(); try { List<JCCompilationUnit> units = compiler.enterTrees(roots.toList()); if (notYetEntered.isEmpty()) compiler = compiler.processAnnotations(units); ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>(); for (JCCompilationUnit unit : units) { for (JCTree node : unit.defs) { if (node.getTag() == JCTree.CLASSDEF) { JCClassDecl cdef = (JCClassDecl) node; if (cdef.sym != null) // maybe null if errors in anno processing elements.append(cdef.sym); } } } return elements.toList(); } finally { compiler.log.flush(); } }