Example usage for java.util Collection contains

List of usage examples for java.util Collection contains

Introduction

In this page you can find the example usage for java.util Collection contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:com.example.app.support.address.AddressParser.java

/**
 * Passes the address to the jgeocoder address parser and
 * formats the results into a string map. Also handles
 * the strange case of highways -- that is, street type
 * PRECEDING street_number.//w  ww  .j a v a 2  s. c  o m
 *
 * @param address the address
 * @param autoCorrectSpelling flag.
 *
 * @return the results.
 */
private static Map<AddressComponent, String> prepareAddressForParsingAndParse(String address,
        boolean autoCorrectSpelling) {
    Map<AddressComponent, String> results = jGeocodeParseAddress(address, autoCorrectSpelling);
    if (results == null) {
        return null; // Something went wrong in the process of parsing the address
    }

    String splitStreetNumber = results.get(NUMBER);
    String splitStreetDir = results.get(PREDIR);
    String splitStreetName = results.get(STREET);
    String splitStreetType = results.get(TYPE);
    String splitUnitNumber = results.get(LINE2);

    Collection<String> streetDirs = getStreetDirs();

    /* if the street name is a direction then chances
     * are that the street direction was pulled into
     * the street name incorrectly and the street name
     * is in the unit number (following conditional)
     */
    if (splitStreetName != null && streetDirs.contains(splitStreetName.toLowerCase())
            && splitStreetDir == null) {
        splitStreetDir = splitStreetName;
        splitStreetName = null;
    }

    // We need to do some switching if the street name is null (usually a result of Hwy 19 or Road 5)
    // -- Second case --> Or if street type is null and unit number is non null we assume that part of the street
    // name got pulled into the unit number
    if ((splitStreetName == null && splitStreetType != null && splitUnitNumber != null)
            || (splitStreetType == null && splitUnitNumber != null)) {
        if (splitStreetName == null) {
            splitStreetName = "";
        }

        // if we have a street type then we are going to want to pull in
        // the first part of the unit number into street name (e.g. hwy 19 or road 52)
        if (splitStreetType != null) {
            Pattern p1 = Pattern.compile("^\\s?(\\S+)\\s?");
            Matcher m1 = p1.matcher(splitUnitNumber);

            if (m1.find()) {
                String streetTypePart = m1.group(1);
                splitStreetName = createStreetName(splitStreetName, splitStreetType, streetTypePart);
                splitUnitNumber = splitUnitNumber.substring(m1.end(0));
                // since we pulled in the street type we don't want to pull it in again if the next matcher matches
                splitStreetType = null;
            }
        }

        // Get the indexes of unit or a hash mark as clues for where to split
        int unitIndex = splitUnitNumber.toLowerCase().indexOf("unit");
        int hashIndex = splitUnitNumber.indexOf(HASHCODE_VALUE);

        // Part of the unit number to be removed and added to street name
        String partOfStreetName = "";
        // We want to leave the part of the unit number that has a hash mark or the string "unit"
        // in the unit number
        if (unitIndex != -1 || hashIndex != -1) {
            if (unitIndex != -1) {

                if (unitIndex == 0) // Unit number starts with a # so the whole unit number stays as the unit number
                {
                    partOfStreetName = "";
                } else {
                    partOfStreetName = splitUnitNumber.substring(0, unitIndex - 1);
                }
                splitUnitNumber = splitUnitNumber.substring(unitIndex);
            } else {
                if (hashIndex == 0) // Unit number starts with a # so the whole unit number stays as the unit number
                {
                    partOfStreetName = "";
                } else {
                    partOfStreetName = splitUnitNumber.substring(0, hashIndex - 1);
                }
                splitUnitNumber = splitUnitNumber.substring(hashIndex);
            }
            splitStreetName = createStreetName(splitStreetName, splitStreetType, partOfStreetName);
        } else // We can't find any clues regarding what part of the unit number is actually the unit number
        {
            // Pattern to get the last string so we can look at it to see if it looks like a unit number
            // We assume that any string less than 3 characters or that is a number is a unit number
            Pattern p2 = Pattern.compile("\\s?(\\S+)$");
            Matcher m2 = p2.matcher(splitUnitNumber);

            if (m2.find()) {
                // the last word in the unit number is what we look at to try to guess
                // whether it is a unit number
                String lastWord = m2.group(1);
                if (lastWord.length() < 3 || isNumeric(lastWord)) {
                    partOfStreetName = splitUnitNumber.substring(0, m2.start(0));
                    splitStreetName = createStreetName(splitStreetName, splitStreetType, partOfStreetName);
                    splitUnitNumber = lastWord;
                } else {
                    splitStreetName += ' ' + splitUnitNumber;
                    splitUnitNumber = null;
                }
            }
        }
        // Either streetType was pulled into streetName or it started as null so it should be null
        splitStreetType = null;

        // set splitUnitNumber to null if it's empty
        if (splitUnitNumber != null && splitUnitNumber.isEmpty()) {
            splitUnitNumber = null;
        }
    }

    results.put(NUMBER, splitStreetNumber);
    results.put(PREDIR, splitStreetDir);
    results.put(STREET, splitStreetName);
    results.put(TYPE, splitStreetType);
    results.put(LINE2, splitUnitNumber);

    return results;
}

From source file:com.lfv.yada.net.client.Distributor.java

public synchronized void remove(Collection<Integer> channels) {

    if (channels.contains(confinedChannelId)) {
        confinedRecipient = null;//from  w w  w .  ja  v a2 s.  c o m
        confinedChannelId = 0;
    }

    if (radioChannelList.removeAll(channels)) {
        // Rebuild
        radioUnicastList.clear();
        radioUsesMulticast = false;
        Iterator<Integer> iter = radioChannelList.iterator();
        while (iter.hasNext()) {
            int channelId = iter.next().intValue();
            addRadioChannel(channelId);
        }
    }
}

From source file:org.apigw.authserver.svc.impl.ResourceOwnerServicesImplTest.java

@Test
public void findChildrenOfLegalGuardian() {
    String legalGuardianWithOneChild = "198112040384";
    String childOfLegalGuardianWithOneChild = "200506237528";
    tokenServices.createAccessToken(legalGuardianWithOneChild, childOfLegalGuardianWithOneChild, CLIENT,
            Arrays.asList(new String[] { READ_SCOPE }));

    Collection<String> children = resourceOwnerServices.findChildrenOfLegalGuardian(legalGuardianWithOneChild);

    assertEquals(1, children.size());//from   w  w  w .jav  a2 s . co m
    assertTrue(children.contains(childOfLegalGuardianWithOneChild));

    String legalGuardianWithThreeChildren = "196708101891";
    String childOne = "199305017809";
    String childTwo = "199609096319";
    String childThree = "199903298710";
    tokenServices.createAccessToken(legalGuardianWithThreeChildren, childOne, CLIENT,
            Arrays.asList(new String[] { READ_SCOPE }));
    tokenServices.createAccessToken(legalGuardianWithThreeChildren, childTwo, CLIENT,
            Arrays.asList(new String[] { READ_SCOPE }));
    tokenServices.createAccessToken(legalGuardianWithThreeChildren, childThree, CLIENT,
            Arrays.asList(new String[] { READ_SCOPE }));

    children = resourceOwnerServices.findChildrenOfLegalGuardian(legalGuardianWithThreeChildren);
    assertEquals(3, children.size());
    assertTrue(children.contains(childOne));
    assertTrue(children.contains(childTwo));
    assertTrue(children.contains(childThree));
}

From source file:com.netflix.simianarmy.aws.conformity.rule.InstanceInSecurityGroup.java

/**
 * Checks whether the collection of security group names are valid. The default implementation here is to check
 * whether the security groups contain the required security groups. The method can be overridden for different
 * rules.//from   w ww  . ja v a2s.  c o  m
 * @param sgNames
 *      The collection of security group names
 * @return
 *      true if the security group names are valid, false otherwise.
 */
protected boolean checkSecurityGroups(Collection<String> sgNames) {
    for (String requiredSg : requiredSecurityGroupNames) {
        if (!sgNames.contains(requiredSg)) {
            LOGGER.info(String.format("Required security group %s is not found.", requiredSg));
            return false;
        }
    }
    return true;
}

From source file:bz.tsung.jsonapi4j.models.Relationship.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*  w ww  . j  ava  2 s  .  c  o m*/

    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    Data<Resource> that = ((Relationship) o).getData();

    if (that == null || data == null) {
        return that == data;
    }

    Collection<ResourceIdentifier> resourceIdentifiers = data.toResourceIdentifiers();
    Collection<ResourceIdentifier> theirIdentifiers = that.toResourceIdentifiers();

    for (ResourceIdentifier resourceIdentifier : resourceIdentifiers) {
        if (!theirIdentifiers.contains(resourceIdentifier)) {
            return false;
        }
    }
    return true;
}

From source file:bz.tsung.jsonapi4j.models.JsonApiDocument.java

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof JsonApiDocument)) {
        return false;
    }/*from w ww  .  jav a 2 s.  c om*/
    JsonApiDocument other = (JsonApiDocument) obj;
    Collection<Resource> resources = data.get();
    if ((resources == null || other.getData().get() == null) && resources != other.getData().get()) {
        return false;
    } else if (resources != null) {
        if (resources.size() != other.getData().get().size()) {
            return false;
        } else {
            Collection<Resource> others = other.getData().get();
            for (Resource resource : resources) {
                if (!others.contains(resource)) {
                    return false;
                }
            }
        }
    }
    // TODO: Verify links and meta?
    if (other.getIncluded() == null) {
        return included.isEmpty();
    }

    Collection<Resource> otherIncluded = other.getIncluded();
    for (Resource resource : included) {
        if (!otherIncluded.contains(resource)) {
            return false;
        }
    }
    return true;
}

From source file:org.duracloud.account.security.vote.BaseAccessDecisionVoter.java

protected int voteHasRole(String role, Collection<String> userRoles) {
    return userRoles.contains(role) ? ACCESS_GRANTED : ACCESS_DENIED;
}

From source file:com.cloudera.oryx.app.als.FeatureVectors.java

/**
 * Given IDs that are part of a new model, and whose values are going to be sent later,
 * retain only IDs that are also in the new model (or have been recently seen -- possibly since
 * last model was built), and remove the rest.
 *
 * @param newModelIDs new model IDs//from w  w  w. ja  v a2s.  c  o  m
 */
public void retainRecentAndIDs(Collection<String> newModelIDs) {
    try (AutoLock al = lock.autoWriteLock()) {
        vectors.removeIf((key, value) -> !newModelIDs.contains(key) && !recentIDs.contains(key));
        recentIDs.clear();
    }
}

From source file:GuestManagerImplTest.java

/**
 * Test of deleteGuest method, of class GuestManagerImpl.
 *//*from   w ww.  j a v a2 s . c om*/
@Test
public void testDeleteGuest() {
    Guest g1 = newGuest("Lojza", "1234");
    Guest g2 = newGuest("Fred", "5678");
    manager.createGuest(g1);
    manager.createGuest(g2);
    assertNotNull(g1.getGuestID());
    assertNotNull(g2.getGuestID());
    assertEquals(manager.getAllGuests().size(), 2);
    manager.deleteGuest(g2);
    assertEquals(manager.getAllGuests().size(), 1);
    Collection<Guest> all = manager.getAllGuests();
    assertTrue(all.contains(g1));
}

From source file:com.xpn.xwiki.user.api.XWikiUser.java

/**
 * Check if the user belongs to a group or not.
 * //from   ww  w . ja  va 2  s .c o  m
 * @param groupName The group to check.
 * @param context The current {@link XWikiContext context}.
 * @return <tt>true</tt> if the user does belong to the specified group, false otherwise or if an exception occurs.
 * @throws XWikiException If an error occurs when checking the groups.
 * @since Platform-1.3
 */
public boolean isUserInGroup(String groupName, XWikiContext context) throws XWikiException {
    if (!StringUtils.isEmpty(getUser())) {
        XWikiGroupService groupService = context.getWiki().getGroupService(context);

        DocumentReference groupReference = this.currentMixedDocumentReferenceResolver.resolve(groupName);

        Collection<DocumentReference> groups = groupService
                .getAllGroupsReferencesForMember(getUserReference(context), 0, 0, context);

        if (groups.contains(groupReference)) {
            return true;
        }
    }

    return false;
}