Example usage for java.util LinkedHashMap containsKey

List of usage examples for java.util LinkedHashMap containsKey

Introduction

In this page you can find the example usage for java.util LinkedHashMap containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:nl.systemsgenetics.eqtlannotation.EncodeMultipleTfbsOverlap.java

private static LinkedHashMap<String, HashMap<String, ArrayList<EncodeNarrowPeak>>> readMultipleTfbsInformation(
        String inputFolderTfbsData) throws IOException {
    LinkedHashMap<String, HashMap<String, ArrayList<EncodeNarrowPeak>>> data = new LinkedHashMap<>();
    File file = new File(inputFolderTfbsData);
    File[] files = file.listFiles();
    ArrayList<String> vecFiles = new ArrayList<>();
    for (File f : files) {
        //            System.out.println(f.getAbsolutePath());
        vecFiles.add(f.getAbsolutePath());
    }/*from  w  w w .  j av a2s.co m*/

    for (String fileToRead : vecFiles) {
        TextFile reader = new TextFile(fileToRead, TextFile.R);

        String[] storingInformation = fileToRead.split("_");
        //            String cellLine = storingInformation[1].replace("TFBS\\","");
        String transcriptionFactor = storingInformation[2].replace(".narrowPeak", "");
        if (storingInformation.length > 4) {
            for (int i = 3; i < (storingInformation.length - 1); ++i) {
                transcriptionFactor = transcriptionFactor + "_"
                        + storingInformation[i].replace(".narrowPeak", "");
            }
        }

        String row;
        while ((row = reader.readLine()) != null) {

            String[] parts = StringUtils.split(row, '\t');
            if (!data.containsKey(transcriptionFactor)) {
                data.put(transcriptionFactor, new HashMap<String, ArrayList<EncodeNarrowPeak>>());
            }
            if (!data.get(transcriptionFactor).containsKey(parts[0])) {
                data.get(transcriptionFactor).put(parts[0], new ArrayList<EncodeNarrowPeak>());
            }
            data.get(transcriptionFactor).get(parts[0]).add(new EncodeNarrowPeak(parts, fileToRead));
        }

        reader.close();

    }
    ArrayList<String> cleanList = new ArrayList<>();
    for (Entry<String, HashMap<String, ArrayList<EncodeNarrowPeak>>> tfInformation : data.entrySet()) {
        System.out.println("Transcription factor: " + tfInformation.getKey());
        int counter = 0;
        for (Entry<String, ArrayList<EncodeNarrowPeak>> tfEntry : tfInformation.getValue().entrySet()) {
            Collections.sort(tfEntry.getValue());
            counter += tfEntry.getValue().size();
        }
        System.out.println("\tcontacts: " + counter);

        //remove all with less than 750 contacts
        //            if(counter<750){
        //                cleanList.add(tfInformation.getKey());
        //            }
    }

    for (String k : cleanList) {
        data.remove(k);
    }

    return data;
}

From source file:ca.sfu.federation.model.ParametricModel.java

/**
 * Remove a NamedObject from the Context.
 *
 * @param Named The NamedObject to be removed.
 * @throws IllegalArgumentException The NamedObject does not exist in the
 * Context./*from  w w  w . j av  a 2 s . c om*/
 */
public void remove(INamed Named) throws IllegalArgumentException {
    String itemName = Named.getName();
    LinkedHashMap elementsByName = (LinkedHashMap) this.getElementMap();
    if (elementsByName.containsKey(itemName)) {
        // stop listening on the NamedObject
        if (Named instanceof Observable) {
            Observable o = (Observable) Named;
            o.deleteObserver(this);
        }
        // remove the NamedObject from the collection
        this.elements.remove(Named);
        // notify observers
        this.setChanged();
        this.notifyObservers(Integer.valueOf(ApplicationContext.EVENT_ELEMENT_DELETED));
    } else {
        throw new IllegalArgumentException(
                "The object '" + itemName + "' does not exist in the current Context.");
    }
}

From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupRtBoxPlot.java

protected String getPeakName(IPeakGroupDescriptor pgd) {
    String rt = "mean rt: " + String.format("%.2f", pgd.getMeanApexTime()) + "+/-"
            + String.format("%.2f", pgd.getApexTimeStdDev()) + "; median rt: "
            + String.format("%.2f", pgd.getMedianApexTime()) + ": ";
    LinkedHashMap<String, Integer> names = new LinkedHashMap<>();
    if (!pgd.getDisplayName().equals(pgd.getName())) {
        return rt + pgd.getDisplayName();
    }/*from   w ww .  ja  v  a  2  s  .  c om*/
    for (IPeakAnnotationDescriptor ipad : pgd.getPeakAnnotationDescriptors()) {
        if (names.containsKey(ipad.getName())) {
            names.put(ipad.getName(), names.get(ipad.getName()) + 1);
        } else {
            names.put(ipad.getName(), 1);
        }
    }
    if (names.isEmpty()) {
        return rt + "<NA>";
    }
    if (names.size() > 1) {
        StringBuilder sb = new StringBuilder();
        for (String key : names.keySet()) {
            sb.append(key);
            sb.append(" (" + names.get(key) + ")");
            sb.append(" | ");
        }
        return rt + sb.replace(sb.length() - 1, sb.length() - 1, "").toString();
    } else {
        return rt + names.keySet().toArray(new String[0])[0];
    }
}

From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupBoxPlot.java

protected String getPeakName(IPeakGroupDescriptor pgd) {
    String rt = "mean area: " + String.format("%.2f", pgd.getMeanArea(normalizer)) + "+/-"
            + String.format("%.2f", pgd.getAreaStdDev(normalizer)) + "; median area: "
            + String.format("%.2f", pgd.getMedianArea(normalizer)) + ": ";
    LinkedHashMap<String, Integer> names = new LinkedHashMap<>();
    if (!pgd.getDisplayName().equals(pgd.getName())) {
        return rt + pgd.getDisplayName();
    }// w  ww.  j  a v  a2 s .  co m
    for (IPeakAnnotationDescriptor ipad : pgd.getPeakAnnotationDescriptors()) {
        if (names.containsKey(ipad.getName())) {
            names.put(ipad.getName(), names.get(ipad.getName()) + 1);
        } else {
            names.put(ipad.getName(), 1);
        }
    }
    if (names.isEmpty()) {
        return rt + "<NA>";
    }
    if (names.size() > 1) {
        StringBuilder sb = new StringBuilder();
        for (String key : names.keySet()) {
            sb.append(key);
            sb.append(" (" + names.get(key) + ")");
            sb.append(" | ");
        }
        return rt + sb.replace(sb.length() - 1, sb.length() - 1, "").toString();
    } else {
        return rt + names.keySet().toArray(new String[0])[0];
    }
}

From source file:org.eclipse.php.composer.api.entities.AbstractJsonObject.java

@Override
protected Object buildJson() {
    LinkedList<String> propsOrder = new LinkedList<String>(sortOrder);

    // First: create an index to search for field names and add them to the
    // props order
    HashMap<String, Field> namedFields = new HashMap<String, Field>();
    for (Field field : getFields(this.getClass())) {
        field.setAccessible(true);//  w w w.  jav a2 s . c o  m
        String fieldName = getFieldName(field);
        namedFields.put(fieldName, field);
        propsOrder.add(fieldName);
    }

    // add properties that aren't in the hashmap yet
    for (Entry<String, V> entry : properties.entrySet()) {
        propsOrder.add(entry.getKey());
    }

    // Second: find property contents (either field or property key)
    LinkedHashMap<String, Object> out = new LinkedHashMap<String, Object>();
    for (String entry : propsOrder) {
        if (out.containsKey(entry)) {
            continue;
        }
        Object value = null;

        // search class fields first
        if (namedFields.containsKey(entry)) {
            try {
                value = namedFields.get(entry).get(this);
            } catch (Exception e) {
                log.error(e);
            }
        }

        // check properties
        else if (properties.containsKey(entry)) {
            value = properties.get(entry);
        }

        value = getJsonValue(value);

        if (value == null || value.equals("")) { //$NON-NLS-1$
            continue;
        }

        // add to output
        out.put(entry, value);
    }

    return out;
}

From source file:com.intellij.plugins.haxe.haxelib.HaxeLibrary.java

private void collectDependentsInternal(
        /*modifies*/ final @NotNull LinkedHashMap<String, HaxeLibraryDependency> collection) {
    List<HaxeLibraryDependency> dependencies = getDirectDependents();

    for (HaxeLibraryDependency dependency : dependencies) {
        if (!collection.containsKey(dependency.getKey())) { // Don't go down the same path again...
            // TODO: Deal with version mismatches here.  Add multiple versions, but don't add a specific version if the latest version is equal to it.
            collection.put(dependency.getKey(), dependency);
            HaxeLibrary depLib = dependency.getLibrary();
            if (null != depLib) {
                depLib.collectDependentsInternal(collection);
            } // TODO: Else mark dependency unfulfilled somehow??
        } else {//from  w w w. j  a v a2  s .  c o m
            HaxeLibraryDependency contained = collection.get(dependency.getKey());
            LOG.assertLog(contained != null, "Couldn't get a contained object.");
            if (contained != null) {
                contained.addReliant(dependency);
            }
        }
    }
}

From source file:org.openmrs.module.muzima.handler.JsonEncounterQueueDataHandler.java

private void createObs(final Encounter encounter, final Obs parentObs, final Concept concept, final Object o) {
    String value = null;/*from   ww  w. ja  v  a2  s . c o  m*/
    Obs obs = new Obs();
    obs.setConcept(concept);

    //check and parse if obs_value / obs_datetime object
    if (o instanceof LinkedHashMap) {
        LinkedHashMap obj = (LinkedHashMap) o;
        if (obj.containsKey("obs_value")) {
            value = (String) obj.get("obs_value");
        }
        if (obj.containsKey("obs_datetime")) {
            String dateString = (String) obj.get("obs_datetime");
            Date obsDateTime = parseDate(dateString);
            obs.setObsDatetime(obsDateTime);
        }
    } else {
        value = o.toString();
    }
    // find the obs value :)
    if (concept.getDatatype().isNumeric()) {
        obs.setValueNumeric(Double.parseDouble(value));
    } else if (concept.getDatatype().isDate() || concept.getDatatype().isTime()
            || concept.getDatatype().isDateTime()) {
        obs.setValueDatetime(parseDate(value));
    } else if (concept.getDatatype().isCoded()) {
        String[] valueCodedElements = StringUtils.split(value, "\\^");
        int valueCodedId = Integer.parseInt(valueCodedElements[0]);
        Concept valueCoded = Context.getConceptService().getConcept(valueCodedId);
        if (valueCoded == null) {
            queueProcessorException.addException(
                    new Exception("Unable to find concept for value coded with id: " + valueCodedId));
        } else {
            obs.setValueCoded(valueCoded);
        }
    } else if (concept.getDatatype().isText()) {
        obs.setValueText(value);
    }
    // only add if the value is not empty :)
    encounter.addObs(obs);
    if (parentObs != null) {
        parentObs.addGroupMember(obs);
    }
}

From source file:ca.sfu.federation.model.Assembly.java

/**
 * Add a NamedObject./*from   ww  w  .j  a  v a 2  s  .  c  om*/
 * @param Named NamedObject to be added.
 * @throws IllegalArgumentException An object identified by the same name already exists in the Context.
 */
@Override
public void add(INamed Named) throws IllegalArgumentException {
    LinkedHashMap elementsByName = (LinkedHashMap) this.getElementMap();
    if (!elementsByName.containsKey(Named.getName())) {
        // add object
        this.elements.add(Named);
        // observe element for changes
        if (Named instanceof Observable) {
            Observable o = (Observable) Named;
            o.addObserver(this);
        }
        // notify observers of change
        this.setChanged();
        this.notifyObservers(Integer.valueOf(ApplicationContext.EVENT_ELEMENT_ADD));
    } else {
        throw new IllegalArgumentException(
                "An object identified by the same name already exists in the Context.");
    }
}

From source file:ca.sfu.federation.model.Assembly.java

/**
 * Remove a NamedObject from the Context.
 * @param Named The NamedObject to be removed.
 * @throws IllegalArgumentException The NamedObject does not exist in the Context.
 *///www.jav  a2s .  c o  m
@Override
public void remove(INamed Named) throws IllegalArgumentException {
    String childname = Named.getName();
    LinkedHashMap elementsByName = (LinkedHashMap) this.getElementMap();
    if (elementsByName.containsKey(childname)) {
        // stop listening on the NamedObject
        if (Named instanceof Observable) {
            Observable o = (Observable) Named;
            o.deleteObserver(this);
        }
        // remove the NamedObject from the collection
        this.elements.remove(Named);
        // notify observers
        this.setChanged();
        this.notifyObservers(Integer.valueOf(ApplicationContext.EVENT_ELEMENT_DELETED));
    } else {
        throw new IllegalArgumentException(
                "The object '" + childname + "' does not exist in the current Context.");
    }
}

From source file:com.redhat.topicindex.security.FedoraAccountSystem.java

@SuppressWarnings("unchecked")
private boolean authenticate() throws LoginException {
    if (password == null || username == null)
        throw new LoginException("No Username/Password found");
    if (password.equals("") || username.equals(""))
        throw new LoginException("No Username/Password found");

    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(FEDORA_JSON_URL);

    try {//from  www  .j  av  a  2 s.c  om
        // Generate the data to send
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new NameValuePair("username", username));
        formparams.add(new NameValuePair("user_name", username));
        formparams.add(new NameValuePair("password", String.valueOf(password)));
        formparams.add(new NameValuePair("login", "Login"));

        method.addParameters(formparams.toArray(new NameValuePair[formparams.size()]));

        // Send the data and get the response
        client.executeMethod(method);

        // Handle the response
        BufferedReader br = new BufferedReader(
                new InputStreamReader(new ByteArrayInputStream(method.getResponseBody())));

        JSONParser parser = new JSONParser();
        ContainerFactory containerFactory = new ContainerFactory() {
            public List creatArrayContainer() {
                return new LinkedList();
            }

            public Map createObjectContainer() {
                return new LinkedHashMap();
            }
        };

        // Parse the response to check authentication success and valid groups
        String line;
        while ((line = br.readLine()) != null) {
            Map json = (Map) parser.parse(line, containerFactory);
            if (json.containsKey("success") && json.containsKey("person")) {
                if (json.get("person") instanceof LinkedHashMap) {
                    LinkedHashMap person = (LinkedHashMap) json.get("person");
                    if (person.get("status").equals("active")) {
                        if (person.containsKey("approved_memberships")) {
                            if (person.get("approved_memberships") instanceof LinkedList) {
                                if (!checkCLAAgreement(((LinkedList) person.get("approved_memberships")))) {
                                    throw new LoginException("FAS authentication failed for " + username
                                            + ". Contributor License Agreement not yet signed");
                                }
                            } else if (person.get("approved_memberships") instanceof LinkedHashMap) {
                                if (!checkCLAAgreement(((LinkedHashMap) person.get("approved_memberships")))) {
                                    throw new LoginException("FAS authentication failed for " + username
                                            + ". Contributor License Agreement not yet signed");
                                }
                            }
                        } else {
                            throw new LoginException("FAS authentication failed for " + username
                                    + ". Contributor License Agreement not yet signed");
                        }
                    } else {
                        throw new LoginException(
                                "FAS authentication failed for " + username + ". Account is not active");
                    }
                }
            } else {
                throw new LoginException("Error: FAS authentication failed for " + username);
            }
        }
    } catch (LoginException e) {
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
    return true;
}