Example usage for java.util HashMap remove

List of usage examples for java.util HashMap remove

Introduction

In this page you can find the example usage for java.util HashMap remove.

Prototype

public V remove(Object key) 

Source Link

Document

Removes the mapping for the specified key from this map if present.

Usage

From source file:uk.ac.horizon.ug.exploding.client.Client.java

/** remove a Fact from the cache without signalling state change */
public void removeFactSilent(Object fact) {
    if (fact == null)
        return;//  w w w  . j a va 2 s. c o  m
    log("removeFactSilent", "fact", fact.toString());
    synchronized (facts) {
        String typeName = getFactType(fact);
        HashMap<Object, Object> typeFacts = facts.get(typeName);
        if (typeFacts != null) {
            Object id = getFactID(fact);
            if (id != null) {
                if (typeFacts.remove(id) == null)
                    Log.w(TAG, "removeFactSilent could not find " + typeName + " " + id);
            } else
                Log.w(TAG, "removeFactSilent called with object without id: " + fact);
        } else
            Log.w(TAG, "removeFactSilent could not find any " + typeName);
    }
}

From source file:de.ingrid.iplug.scheduler.FileJobStore.java

public boolean removeJob(SchedulingContext ctxt, String jobName, String groupName)
        throws JobPersistenceException {
    JobDetail job = (JobDetail) this.fJobsByName.get(getFullName(groupName, jobName));
    if (job == null) {
        return false;
    }//from  w ww  .  j  av  a  2s.c  o  m

    Trigger[] triggers = getTriggersForJob(ctxt, jobName, groupName);
    for (int i = 0; i < triggers.length; i++) {
        removeTrigger(ctxt, triggers[i].getName(), triggers[i].getGroup());
    }

    synchronized (this.fJobsByName) {
        HashMap groupMap = (HashMap) this.fJobsByGroup.get(groupName);
        if (groupMap != null) {
            groupMap.remove(jobName);
            if (groupMap.size() == 0)
                this.fJobsByGroup.remove(groupName);
        }
        this.fJobsByName.remove(job.getFullName());
        this.fBlockedJobs.remove(job);
        this.fSerializer.saveJobs(this.fJobsByName);
    }

    return true;
}

From source file:de.ingrid.iplug.scheduler.FileJobStore.java

public boolean removeTrigger(SchedulingContext ctxt, String triggerName, String groupName)
        throws JobPersistenceException {
    synchronized (this.fTriggersByName) {
        // remove from triggers map
        Trigger trigger = (Trigger) this.fTriggersByName.remove(getFullName(groupName, triggerName));
        if (trigger == null) {
            return false;
        }//w ww .  j  a  va2s .  c o  m
        this.fSerializer.saveTriggers(this.fTriggersByName);

        // remove from triggers by group
        HashMap grpMap = (HashMap) this.fTriggersByGroup.get(groupName);
        if (grpMap != null) {
            grpMap.remove(triggerName);
            if (grpMap.size() == 0)
                this.fTriggersByGroup.remove(groupName);
        }
        this.fOrderedTriggers.remove(trigger);
        JobDetail jobDetail = retrieveJob(ctxt, trigger.getJobName(), trigger.getJobGroup());

        // remove state
        setTriggerState(ctxt, trigger, Trigger.STATE_NONE);

        if (!jobDetail.isDurable()
                && getTriggersForJob(ctxt, jobDetail.getName(), jobDetail.getGroup()).length == 0) {
            removeJob(ctxt, jobDetail.getName(), jobDetail.getGroup());
        }
    }

    return true;
}

From source file:org.kitodo.dataeditor.ruleset.UniversalRule.java

/**
 * Combines two rules into each other. The first rule, if in doubt, is more
 * specific to the order of elements, otherwise its the same as around.
 * This is so if rule is nesting, and additional rule is found for key, then
 * merged and nesting rule is first and thus more specific to the case but
 * other rule otherwise considered as well. This is important but difficult
 * to implement and so it is done now./*from w  ww  .jav  a2 s .c  om*/
 *
 * @param one
 *            a rule
 * @param another
 *            the other rule
 * @return merged rule
 */
private Rule merge(Rule one, Rule another) {
    Rule merged = new Rule();

    /*
     * We assume that both rules are the same only, otherwise this would be
     * a problem. Recursively, this is not a problem, because the program
     * pays attention.
     */
    merged.setDivision(one.getDivision());
    merged.setKey(one.getKey());
    merged.setValue(one.getValue());

    mergeQuantities(one, another, merged);

    // here too, if one is forbidden then forbidden
    merged.setUnspecified(one.getUnspecified().equals(Unspecified.FORBIDDEN)
            || another.getUnspecified().equals(Unspecified.FORBIDDEN) ? Unspecified.FORBIDDEN
                    : Unspecified.UNRESTRICTED);

    // and for sub-rule is recursive
    HashMap<Triple<String, String, String>, Rule> anotherPermits = new LinkedHashMap<>();
    for (Rule anotherPermit : another.getPermits()) {
        anotherPermits.put(formAKeyForARuleInATemporaryMap(anotherPermit), anotherPermit);
    }
    List<Rule> mergedPermits = new LinkedList<>();
    for (Rule onePermit : one.getPermits()) {
        Triple<String, String, String> key = formAKeyForARuleInATemporaryMap(onePermit);
        if (anotherPermits.containsKey(key)) {
            mergedPermits.add(merge(onePermit, anotherPermits.get(key)));
            anotherPermits.remove(key);
        } else {
            mergedPermits.add(onePermit);
        }
    }
    mergedPermits.addAll(anotherPermits.values());
    merged.setPermits(mergedPermits);

    return merged;
}

From source file:edu.mit.broad.genepattern.gp.services.GenePatternClientImpl.java

private void handleInputFileParameter(ParameterInfo parameter, ParameterInfo parameterTemplate) {
    HashMap<String, String> attributes = new HashMap<String, String>();
    parameter.setAttributes(attributes);
    attributes.put(CLIENT_FILENAME_ATTRIBUTE, parameter.getValue());
    parameter.setInputFile(true);/*from   w w  w.jav  a  2  s .  c o  m*/
    if (parameter.getValue() != null && new File(parameter.getValue()).exists()) {
        attributes.put(TYPE_ATTRIBUTE, FILE_TYPE);
        attributes.put(MODE_ATTRIBUTE, INPUT_MODE);
    } else if (parameter.getValue() != null) {
        attributes.remove(TYPE_ATTRIBUTE);
        attributes.put(MODE_ATTRIBUTE, URL_INPUT_MODE);
    }
}

From source file:org.wso2.carbon.application.deployer.internal.ApplicationManager.java

/**
 * Remove a faulty cApp for a particular tenant
 *
 * @param tenantId// w w w  . j a  v  a 2 s .c  o m
 * @param appFilePath
 */
public void removeFaultyCarbonApp(String tenantId, String appFilePath) {
    HashMap<String, Exception> faultycApps = tenantfaultycAppMap.get(tenantId);
    synchronized (faultycApps) {
        if (faultycApps != null) {
            faultycApps.remove(appFilePath);
        }
    }
}

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

/**
 * Test method for 'java.util.HashMap.remove(Object)'.
 *///from w  w  w  . jav  a 2 s  .c o m
public void testRemove() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(hashMap);

    assertNull(hashMap.remove(null));
    hashMap.put(null, VALUE_TEST_REMOVE);
    assertNotNull(hashMap.remove(null));

    hashMap.put(KEY_TEST_REMOVE, VALUE_TEST_REMOVE);
    assertEquals(hashMap.remove(KEY_TEST_REMOVE), VALUE_TEST_REMOVE);
    assertNull(hashMap.remove(KEY_TEST_REMOVE));
}

From source file:org.eclipse.gyrex.jobs.internal.commands.UpdateScheduleEntryCmd.java

@Override
protected void doExecute(final String storageId, final String scheduleId) throws Exception {
    final ScheduleImpl schedule = ScheduleStore.load(storageId, scheduleId, true);

    if (schedule.isEnabled()) {
        printf("Schedule %s is enabled, please disable first!", scheduleId);
        return;/*w ww . j  a v  a2  s  .c o m*/
    }

    if (!IdHelper.isValidId(entryId))
        throw new IllegalArgumentException("invalid entry id");

    final IScheduleEntryWorkingCopy entry = schedule.getEntry(entryId);

    String action;
    if ((null != enable) && enable) {
        // enable
        action = "Enabled";
        entry.setEnabled(true);
    } else if ((null != disable) && disable) {
        // disable
        action = "Disabled";
        entry.setEnabled(false);
    } else {
        // update
        action = "Updated";

        // queue id
        if (null != queueId) {
            entry.setQueueId(queueId);
        } else if ((null != removeQueueId) && removeQueueId) {
            entry.setQueueId(null);
        }

        // cron
        if (null != cronExpression) {
            try {
                entry.setCronExpression(cronExpression);
            } catch (final Exception e) {
                throw new IllegalArgumentException(
                        "invalid cron expression, please see http://en.wikipedia.org/wiki/Cron#CRON_expression",
                        e);
            }
        }

        // parameter
        final HashMap<String, String> newParameter = new HashMap<String, String>(entry.getJobParameter());
        if (null != parameterToSet) {
            for (final String param : parameterToSet) {
                final String[] args = StringUtils.split(param, "=", 2);
                if ((null == args) || (args.length != 2))
                    throw new IllegalArgumentException(
                            String.format("cannot parse parameter to set: %s; please check syntax", param));
                newParameter.put(args[0], args[1]);
            }
            entry.setJobParameter(newParameter);
        }
        if (null != parameterToRemove) {
            for (final String key : parameterToRemove) {
                newParameter.remove(key);
            }
            entry.setJobParameter(newParameter);
        }

        // trigger after
        if (null != precedingEntries) {
            entry.setPrecedingEntries(precedingEntries.toArray(new String[precedingEntries.size()]));
        }
        if ((null != resetPrecedingEntries) && resetPrecedingEntries.booleanValue()) {
            entry.setPrecedingEntries(new String[0]);
        }
    }

    ScheduleStore.flush(storageId, schedule);
    printf("%s entry %s in schedule %s!", action, entryId, scheduleId);
}

From source file:com.mtgi.jmx.export.naming.AppendNamingStrategy.java

public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
    ObjectName base = delegate.getObjectName(managedBean, beanKey);

    @SuppressWarnings("unchecked")
    HashMap<String, String> properties = new HashMap<String, String>(base.getKeyPropertyList());
    //change the domain if required
    String domain = this.domain;
    if (domain == null)
        domain = base.getDomain();//w  ww  .  ja v a2  s.  c  o m
    else {
        String oldDomain = base.getDomain();
        if (oldDomain != null) {
            //append the prior domain name onto the package property.
            String pkg = properties.get("package");
            pkg = (pkg == null) ? oldDomain : pkg + "." + oldDomain;
            properties.put("package", pkg);
        }
    }

    //append extra key if required
    if (key != null && value != null) {
        //append the extra key to the object name
        String oldValue = properties.remove(key);
        properties.put(key, value);

        //move the displaced prior value to a different property
        if (oldValue != null && renameKey != null) {
            String prefix = properties.remove(renameKey);
            if (prefix != null)
                oldValue = prefix + "." + oldValue;
            properties.put(renameKey, oldValue);
        }
    }

    StringBuffer buf = new StringBuffer();
    buf.append(quote(domain));
    char sep = ':';
    //enforce a canonical order on all specified properties
    for (String prop : PROPERTY_ORDER) {
        String value = properties.remove(prop);
        if (value != null) {
            buf.append(sep).append(prop).append('=').append(quote(value));
            sep = ',';
        }
    }
    //all remaining properties get appended in unspecified order
    for (Iterator<Map.Entry<String, String>> it = properties.entrySet().iterator(); it.hasNext();) {
        Map.Entry<String, String> prop = it.next();
        it.remove();
        buf.append(sep).append(prop.getKey()).append('=').append(quote(prop.getValue()));
        sep = ',';
    }

    return ObjectName.getInstance(buf.toString());
}

From source file:cr.ac.siua.tec.utils.impl.AssistancePDFGenerator.java

/**
 * Fills the PDF file (asistente.pdf) with the ticket values and returns base64 encoded string.
 *//*from  w ww .  ja v  a  2s. c  om*/
@Override
public String generate(HashMap<String, String> formValues) {
    String originalPdf = PDFGenerator.RESOURCES_PATH + "asistente.pdf";
    try {
        PDDocument _pdfDocument = PDDocument.load(originalPdf);
        PDDocumentCatalog docCatalog = _pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();

        //Set some fields manually.
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        if (month > 10 || month < 5)
            acroForm.getField("Semestre").setValue("PRIMER");
        else
            acroForm.getField("Semestre").setValue("SEGUNDO");

        if (month > 10 && acroForm.getField("Semestre").getValue().equals("PRIMER"))
            year++;

        acroForm.getField("Ao").setValue(String.valueOf(year));
        formValues.remove("Queue");
        acroForm.getField(formValues.get("Banco")).setValue("x");
        formValues.remove("Banco");
        acroForm.getField(formValues.get("Tipo de asistencia")).setValue("x");
        formValues.remove("Tipo de asistencia");

        //Iterates through remaining custom fields.
        for (Map.Entry<String, String> entry : formValues.entrySet()) {
            acroForm.getField(entry.getKey()).setValue(entry.getValue());
        }
        return encodePDF(_pdfDocument);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("Excepcin al llenar el PDF.");
        return null;
    }
}