Example usage for java.util.regex Pattern matches

List of usage examples for java.util.regex Pattern matches

Introduction

In this page you can find the example usage for java.util.regex Pattern matches.

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:org.openmrs.module.hl7output.util.RHEA_ORU_R01Handler.java

/**
 * process an NK1 segment and add relationships if needed
 * /*www. ja v  a 2s.c om*/
 * @param patient
 * @param nk1
 * @throws HL7Exception
 * @should create a relationship from a NK1 segment
 * @should not create a relationship if one exists
 * @should create a person if the relative is not found
 * @should fail if the coding system is not 99REL
 * @should fail if the relationship identifier is formatted improperly
 * @should fail if the relationship type is not found
 */
protected void processNK1(Patient patient, NK1 nk1) throws HL7Exception {
    // guarantee we are working with our custom coding system
    String relCodingSystem = nk1.getRelationship().getNameOfCodingSystem().getValue();
    if (!relCodingSystem.equals(HL7Constants.HL7_LOCAL_RELATIONSHIP))
        throw new HL7Exception("Relationship coding system '" + relCodingSystem + "' unknown in NK1 segment.");

    // get the relationship type identifier
    String relIdentifier = nk1.getRelationship().getIdentifier().getValue();

    // validate the format of the relationship identifier
    if (!Pattern.matches("[0-9]+[AB]", relIdentifier))
        throw new HL7Exception("Relationship type '" + relIdentifier + "' improperly formed in NK1 segment.");

    // get the type ID
    Integer relTypeId = 0;
    try {
        relTypeId = Integer.parseInt(relIdentifier.substring(0, relIdentifier.length() - 1));
    } catch (NumberFormatException e) {
        throw new HL7Exception("Relationship type '" + relIdentifier + "' improperly formed in NK1 segment.");
    }

    // find the relationship type
    RelationshipType relType = Context.getPersonService().getRelationshipType(relTypeId);
    if (relType == null)
        throw new HL7Exception("Relationship type '" + relTypeId + "' in NK1 segment not found");

    // find the relative
    Person relative = getRelative(nk1);

    // determine if the patient is person A or B; the relIdentifier indicates
    // the relative's side of the relationship, so the patient is the inverse
    boolean patientIsPersonA = relIdentifier.endsWith("B");
    boolean patientCanBeEitherPerson = relType.getbIsToA().equals(relType.getaIsToB());

    // look at existing relationships to determine if a new one is needed
    Set<Relationship> rels = new HashSet<Relationship>();
    if (relative != null) {
        if (patientCanBeEitherPerson || patientIsPersonA)
            rels.addAll(Context.getPersonService().getRelationships(patient, relative, relType));
        if (patientCanBeEitherPerson || !patientIsPersonA)
            rels.addAll(Context.getPersonService().getRelationships(relative, patient, relType));
    }

    // create a relationship if none is found
    if (rels.isEmpty()) {

        // check the relative's existence
        if (relative == null) {
            // create one based on NK1 information
            relative = Context.getHL7Service().createPersonFromNK1(nk1);
            if (relative == null)
                throw new HL7Exception("could not create a new relative from NK1 segment");
        }

        // create the relationship
        Relationship relation = new Relationship();
        if (patientCanBeEitherPerson || patientIsPersonA) {
            relation.setPersonA(patient);
            relation.setPersonB(relative);
        } else {
            relation.setPersonA(relative);
            relation.setPersonB(patient);
        }
        relation.setRelationshipType(relType);
        Context.getPersonService().saveRelationship(relation);
    }
}

From source file:com.docd.purefm.utils.MimeTypes.java

public static boolean mimeTypeMatch(@NonNull final String mime, @NonNull final String input) {
    return Pattern.matches(mime.replace("*", ".*"), input);
}

From source file:it.jnrpe.plugin.CheckProcs.java

/**
 * Apply filters to processes output//from  ww  w.j  av  a 2s  .  c  om
 * 
 * @param values
 * @param filterAndValue
 * @return
 */
private List<Map<String, String>> applyFilters(List<Map<String, String>> values,
        Map<String, String> filterAndValue) {
    if (filterAndValue == null || filterAndValue.isEmpty()) {
        return values;
    }
    List<Map<String, String>> filtered = new ArrayList<Map<String, String>>();
    for (Map<String, String> map : values) {
        boolean matchesAll = true;
        for (Entry<String, String> entry : filterAndValue.entrySet()) {
            String filter = entry.getKey();
            String filterValue = entry.getValue();
            if (filter.contains(FILTER_COMMAND) || filter.contains(FILTER_USER)
                    || FILTER_ARG_ARRAY.equals(filter) || filter.contains(FILTER_PPID)) {
                if (!map.get(filter).contains(filterValue)) {
                    matchesAll = false;
                    break;
                }
            } else if (filter.contains(FILTER_EREG_ARG_ARRAY)
                    && !Pattern.matches(filterValue, map.get(FILTER_ARG_ARRAY))) {
                matchesAll = false;
                break;
            } else if (filter.contains(FILTER_VSZ) || filter.contains(FILTER_RSS)
                    || filter.contains(FILTER_MEMORY)) {
                int filterval = Integer.parseInt(filterValue);
                int value = Integer.parseInt(map.get(filter));
                if (value < filterval) {
                    matchesAll = false;
                    break;
                }
            }
        }
        if (matchesAll) {
            filtered.add(map);
        }
    }
    return filtered;
}

From source file:cx.fbn.nevernote.sql.REnSearch.java

private boolean matchListAll(List<String> list, String title) {
    if (list.size() == 0)
        return true;
    boolean negative = false;
    for (int i = 0; i < list.size(); i++) {
        int pos = list.get(i).indexOf(":");
        negative = false;//from www  .  j  av a  2 s. c o m
        if (list.get(i).startsWith("-"))
            negative = true;
        String filterName = cleanupWord(list.get(i).substring(pos + 1));
        filterName = filterName.replace("*", ".*"); // setup for regular expression pattern match
        boolean matches = Pattern.matches(filterName.toLowerCase(), title.toLowerCase());
        if (matches && negative)
            return false;
        if (matches && !negative)
            return true;
    }
    if (negative)
        return true;
    else
        return false;
}

From source file:net.spfbl.whois.SubnetIPv6.java

/**
 * Verifica se um CIDR  vlido na notao de IPv6.
 * @param cidr o CIDR a ser verificado.//from ww  w .j  a  va  2  s . co  m
 * @return verdadeiro se um CIDR  vlido na notao de IPv6.
 */
public static boolean isValidCIDRv6(String cidr) {
    if (cidr == null) {
        return false;
    } else {
        cidr = cidr.trim();
        cidr = cidr.toLowerCase();
        return Pattern.matches("^" + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + "([0-9a-fA-F]{1,4}:){1,7}:|"
                + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|"
                + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|"
                + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|"
                + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|"
                + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|"
                + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|"
                + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,})" + "/[0-9]{1,3}$", cidr);
    }
}

From source file:com.btmatthews.atlas.jcr.impl.JCRTemplate.java

/**
 * @param workspaceName The name of the workspace.
 * @param statement     The query statement.
 * @param language      The query language.
 * @param callback      The callback operation to be performed on each item in the query result.
 * @param offset        The offset in the query result to start processing.
 * @param limit         The maximum number of items to process.
 * @param <T>           The type returned by the callback operation.
 * @return A {@link List} containing the callback results.
 * @throws RepositoryAccessException If there was an error executing the query or processing the results.
 *///from  w  w  w .  j  ava  2  s .  c o m
public <T> List<T> withQueryResults(final String workspaceName, final String statement, final String language,
        final NodeCallback<T> callback, final long offset, final long limit) {

    assert workspaceName != null && Pattern.matches(WORKSPACE_PATTERN, workspaceName);
    assert statement != null && Pattern.matches(QUERY_PATTERN, statement);
    assert language != null && Pattern.matches(LANGUAGE_PATTERN, language);
    assert callback != null;
    assert offset >= 0;
    assert limit > 0;

    return withSession(workspaceName, session -> {
        final NodeIterator iterator = getQueryResults(session, statement, language, EMPTY_PARAMETERS, offset,
                limit);
        final List<T> results = new ArrayList<>((int) iterator.getSize());
        while (iterator.hasNext()) {
            final Node node = iterator.nextNode();
            if (node == null) {
                throw new RepositoryAccessException(NEXT_NODE_RETURNED_NULL);
            }
            final T result = callback.doInSessionWithNode(session, node);
            results.add(result);
        }
        return results;
    });
}

From source file:org.openmrs.module.hl7valuegroups.api.ValueGroupORUR01Handler.java

/**
 * process an NK1 segment and add relationships if needed
 *
 * @param patient/*from w w w  .j  a v a  2  s. c om*/
 * @param nk1
 * @throws HL7Exception
 * @should create a relationship from a NK1 segment
 * @should not create a relationship if one exists
 * @should create a person if the relative is not found
 * @should fail if the coding system is not 99REL
 * @should fail if the relationship identifier is formatted improperly
 * @should fail if the relationship type is not found
 */

protected void processNK1(Patient patient, NK1 nk1) throws HL7Exception {
    // guarantee we are working with our custom coding system
    String relCodingSystem = nk1.getRelationship().getNameOfCodingSystem().getValue();
    if (!relCodingSystem.equals(HL7Constants.HL7_LOCAL_RELATIONSHIP))
        throw new HL7Exception("Relationship coding system '" + relCodingSystem + "' unknown in NK1 segment.");

    // get the relationship type identifier
    String relIdentifier = nk1.getRelationship().getIdentifier().getValue();

    // validate the format of the relationship identifier
    if (!Pattern.matches("[0-9]+[AB]", relIdentifier))
        throw new HL7Exception("Relationship type '" + relIdentifier + "' improperly formed in NK1 segment.");

    // get the type ID
    Integer relTypeId = 0;
    try {
        relTypeId = Integer.parseInt(relIdentifier.substring(0, relIdentifier.length() - 1));
    } catch (NumberFormatException e) {
        throw new HL7Exception("Relationship type '" + relIdentifier + "' improperly formed in NK1 segment.");
    }

    // find the relationship type
    RelationshipType relType = Context.getPersonService().getRelationshipType(relTypeId);
    if (relType == null)
        throw new HL7Exception("Relationship type '" + relTypeId + "' in NK1 segment not found");

    // find the relative
    Person relative = getRelative(nk1);

    // determine if the patient is person A or B; the relIdentifier indicates
    // the relative's side of the relationship, so the patient is the inverse
    boolean patientIsPersonA = relIdentifier.endsWith("B");
    boolean patientCanBeEitherPerson = relType.getbIsToA().equals(relType.getaIsToB());

    // look at existing relationships to determine if a new one is needed
    Set<Relationship> rels = new HashSet<Relationship>();
    if (relative != null) {
        if (patientCanBeEitherPerson || patientIsPersonA)
            rels.addAll(Context.getPersonService().getRelationships(patient, relative, relType));
        if (patientCanBeEitherPerson || !patientIsPersonA)
            rels.addAll(Context.getPersonService().getRelationships(relative, patient, relType));
    }

    // create a relationship if none is found
    if (rels.isEmpty()) {

        // check the relative's existence
        if (relative == null) {
            // create one based on NK1 information
            relative = Context.getHL7Service().createPersonFromNK1(nk1);
            if (relative == null)
                throw new HL7Exception("could not create a new relative from NK1 segment");
        }

        // create the relationship
        Relationship relation = new Relationship();
        if (patientCanBeEitherPerson || patientIsPersonA) {
            relation.setPersonA(patient);
            relation.setPersonB(relative);
        } else {
            relation.setPersonA(relative);
            relation.setPersonB(patient);
        }
        relation.setRelationshipType(relType);
        Context.getPersonService().saveRelationship(relation);
    }
}

From source file:org.openmrs.module.pcslabinterface.LabORUR01Handler.java

/**
 * process an NK1 segment and add relationships if needed
 *//*from  w  w  w  . ja va  2 s . c o  m*/

protected void processNK1(Patient patient, NK1 nk1) throws HL7Exception {
    // guarantee we are working with our custom coding system
    String relCodingSystem = nk1.getRelationship().getNameOfCodingSystem().getValue();
    if (!relCodingSystem.equals(HL7Constants.HL7_LOCAL_RELATIONSHIP))
        throw new HL7Exception("Relationship coding system '" + relCodingSystem + "' unknown in NK1 segment.");

    // get the relationship type identifier
    String relIdentifier = nk1.getRelationship().getIdentifier().getValue();

    // validate the format of the relationship identifier
    if (!Pattern.matches("[0-9]+[AB]", relIdentifier))
        throw new HL7Exception("Relationship type '" + relIdentifier + "' improperly formed in NK1 segment.");

    // get the type ID
    Integer relTypeId;
    try {
        relTypeId = Integer.parseInt(relIdentifier.substring(0, relIdentifier.length() - 1));
    } catch (NumberFormatException e) {
        throw new HL7Exception("Relationship type '" + relIdentifier + "' improperly formed in NK1 segment.");
    }

    // find the relationship type
    RelationshipType relType = Context.getPersonService().getRelationshipType(relTypeId);
    if (relType == null)
        throw new HL7Exception("Relationship type '" + relTypeId + "' in NK1 segment not found");

    // find the relative
    Person relative = getRelative(nk1);

    // determine if the patient is person A or B; the relIdentifier indicates
    // the relative's side of the relationship, so the patient is the inverse
    boolean patientIsPersonA = relIdentifier.endsWith("B");
    boolean patientCanBeEitherPerson = relType.getbIsToA().equals(relType.getaIsToB());

    // look at existing relationships to determine if a new one is needed
    Set<Relationship> rels = new HashSet<Relationship>();
    if (relative != null) {
        if (patientCanBeEitherPerson || patientIsPersonA)
            rels.addAll(Context.getPersonService().getRelationships(patient, relative, relType));
        if (patientCanBeEitherPerson || !patientIsPersonA)
            rels.addAll(Context.getPersonService().getRelationships(relative, patient, relType));
    }

    // create a relationship if none is found
    if (rels.isEmpty()) {

        // check the relative's existence
        if (relative == null) {
            // create one based on NK1 information
            relative = Context.getHL7Service().createPersonFromNK1(nk1);
            if (relative == null)
                throw new HL7Exception("could not create a new relative from NK1 segment");
        }

        // create the relationship
        Relationship relation = new Relationship();
        if (patientCanBeEitherPerson || patientIsPersonA) {
            relation.setPersonA(patient);
            relation.setPersonB(relative);
        } else {
            relation.setPersonA(relative);
            relation.setPersonB(patient);
        }
        relation.setRelationshipType(relType);
        Context.getPersonService().saveRelationship(relation);
    }
}

From source file:ch.entwine.weblounge.common.impl.site.SiteImpl.java

/**
 * {@inheritDoc}/*from   w  w  w . j  a v a 2 s.co  m*/
 * 
 * @see ch.entwine.weblounge.common.site.Site#setIdentifier(java.lang.String)
 */
public void setIdentifier(String identifier) {
    if (identifier == null)
        throw new IllegalArgumentException("Site identifier must not be null");
    else if (!Pattern.matches(SITE_IDENTIFIER_REGEX, identifier))
        throw new IllegalArgumentException("Site identifier '" + identifier + "' is malformed");
    this.identifier = identifier;
}

From source file:net.spfbl.whois.SubnetIPv6.java

public static boolean isReverseIPv6(String reverse) {
    reverse = reverse.trim();/*  w  w  w  .  j  a va 2s  . c  om*/
    reverse = reverse.toLowerCase();
    return Pattern.matches("^" + "(\\.?[a-f0-9]{1,4})" + "(\\.[a-f0-9]{1,4}){31}" + "$\\.?", reverse);
}