Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:expansionBlocks.ProcessCommunities.java

private static Map<Entity, Double> fusion(Map<Entity, Double> c1, Map<Entity, Double> c2) {
    Map<Entity, Double> result = new HashMap<>();
    Map<Entity, Double> c1c = new HashMap<>(c1);
    Map<Entity, Double> c2c = new HashMap<>(c2);
    Set<Long> intersection = new HashSet(CollectionUtils.intersection(c1c.keySet(), c2c.keySet()));
    for (Map.Entry<Entity, Double> e : c1c.entrySet()) {
        Entity id = e.getKey();/*  w ww .  j  a  va2s .  c om*/
        Double d = e.getValue();
        if (intersection.contains(id)) {
            Double d2 = c2c.get(id);
            d = (d + d2) / 2;
            c2c.remove(id);
        }
        result.put(id, d);
    }
    for (Map.Entry<Entity, Double> e : c2c.entrySet()) {
        Entity id = e.getKey();
        Double d = e.getValue();
        result.put(id, d);
    }
    return result;

}

From source file:com.aliyun.odps.mapred.bridge.utils.ValidatorFactory.java

private static boolean validateColumns(String[] columns, Column[] schema, StringBuilder errorMsg) {
    Set<String> schemaColums = new HashSet<String>();
    for (int i = 0; i < schema.length; ++i) {
        schemaColums.add(schema[i].getName());
    }/* w ww.j ava 2 s  . co  m*/
    for (int i = 0; i < columns.length; ++i) {
        if (!schemaColums.contains(columns[i])) {
            errorMsg.append("Can't find column " + columns[i] + " from key schema.");
            return false;
        }
    }
    return true;
}

From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java

public static String cleanFileName(String badFileName) {
    if (StringUtils.isNotBlank(badFileName)) {
        List<Integer> bads = Arrays.asList(34, 60, 62, 124, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 58, 42, 63, 92, 47);
        Set<Integer> badChars = new HashSet<>();
        badChars.addAll(bads);/*from   w  ww .  j  ava  2s .  c  om*/

        StringBuilder cleanName = new StringBuilder();
        for (int i = 0; i < badFileName.length(); i++) {
            int c = (int) badFileName.charAt(i);
            if (badChars.contains(c) == false) {
                cleanName.append((char) c);
            }
        }
        return cleanName.toString();
    }
    return badFileName;
}

From source file:ca.sqlpower.testutil.TestUtils.java

/**
 * Gets all the settable properties on the given target object
 * which are not in the given ignore set, and stuffs them into a Map.
 * /*  w w  w  .  j  a v  a 2s . c  o m*/
 * @param target The object to change the properties of
 * @param propertiesToIgnore The properties of target not to modify or read
 * @return The aforementioned stuffed map
 */
public static Map<String, Object> getAllInterestingProperties(Object target, Set<String> propertiesToIgnore)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Map<String, Object> newDescription = new HashMap<String, Object>();
    PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(target);
    for (int i = 0; i < props.length; i++) {
        if (PropertyUtils.isReadable(target, props[i].getName()) && props[i].getReadMethod() != null
                && !propertiesToIgnore.contains(props[i].getName())) {
            newDescription.put(props[i].getName(), PropertyUtils.getProperty(target, props[i].getName()));
        }
    }
    return newDescription;
}

From source file:sk.lazyman.gizmo.util.GizmoUtils.java

private static List<CustomerProjectPartDto> listCustomersProjects(List<CustomerProjectPartDto> dbList) {
    List<CustomerProjectPartDto> list = new ArrayList<>();

    Set<Integer> addedCustomers = new HashSet<>();
    Set<Integer> addedProjects = new HashSet<>();
    for (CustomerProjectPartDto dto : dbList) {
        if (!addedCustomers.contains(dto.getCustomerId())) {
            list.add(new CustomerProjectPartDto(dto.getCustomerName(), dto.getCustomerId()));
            addedCustomers.add(dto.getCustomerId());
        }//from w ww.j  a  v  a 2 s  .co m
        if (!addedProjects.contains(dto.getProjectId())) {
            list.add(new CustomerProjectPartDto(dto.getCustomerName(), dto.getProjectName(),
                    dto.getCustomerId(), dto.getProjectId()));
            addedProjects.add(dto.getProjectId());
        }
    }

    return list;
}

From source file:org.apache.parquet.cli.json.AvroJson.java

private static Schema closestPrimitive(Set<Schema.Type> possible, Schema.Type... types) {
    for (Schema.Type type : types) {
        if (possible.contains(type) && PRIMITIVES.containsKey(type)) {
            return PRIMITIVES.get(type);
        }//www  .  j  a v a  2s  .c  o m
    }
    return null;
}

From source file:com.tweetlanes.android.model.ComposeTweetDefault.java

private static String getReplyToUserNamesAsString(String userScreenName, TwitterStatuses inReplyToStatusList) {
    String replyingToUsers = "";
    Set<String> screenNameSet = new HashSet<String>();

    // Note: There are 2 for loops here so that we cleanly handle the case
    // where a user replies to their own tweet.

    for (int i = 0; i < inReplyToStatusList.getStatusCount(); i++) {
        TwitterStatus status = inReplyToStatusList.getStatus(i);
        String author = status.getAuthorScreenName();
        if (screenNameSet.contains(author.toLowerCase()) == false) {
            screenNameSet.add(author.toLowerCase());
            replyingToUsers += "@" + author + " ";
        }/*from  ww  w .  j  av a2s.com*/

        if (status.mIsRetweet) {
            String tweeter = status.mUserScreenName;
            if (screenNameSet.contains(tweeter.toLowerCase()) == false) {
                screenNameSet.add(tweeter.toLowerCase());
                replyingToUsers += "@" + tweeter + " ";
            }
        }
    }

    if (userScreenName != null) {
        screenNameSet.add(userScreenName.toLowerCase());
    }

    for (int i = 0; i < inReplyToStatusList.getStatusCount(); i++) {
        TwitterStatus status = inReplyToStatusList.getStatus(i);
        String[] userMentions = status.mUserMentions;
        if (userMentions != null) {
            for (String screenName : userMentions) {
                if (screenNameSet.contains(screenName.toLowerCase()) == false) {
                    screenNameSet.add(screenName.toLowerCase());
                    replyingToUsers += "@" + screenName + " ";
                }
            }
        }
    }

    return replyingToUsers;
}

From source file:org.wso2.carbon.apimgt.gateway.handlers.Utils.java

public static void setFaultPayload(MessageContext messageContext, OMElement payload) {
    org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext)
            .getAxis2MessageContext();
    JsonUtil.removeJsonPayload(axis2MC);
    messageContext.getEnvelope().getBody().addChild(payload);
    Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String acceptType = (String) headers.get(HttpHeaders.ACCEPT);
    Set<String> supportedMimes = new HashSet<String>(Arrays.asList("application/x-www-form-urlencoded",
            "multipart/form-data", "text/html", "application/xml", "text/xml", "application/soap+xml",
            "text/plain", "application/json", "application/json/badgerfish", "text/javascript"));

    // If an Accept header has been provided and is supported by the Gateway
    if (!StringUtils.isEmpty(acceptType) && supportedMimes.contains(acceptType)) {
        axis2MC.setProperty(Constants.Configuration.MESSAGE_TYPE, acceptType);
    } else {//from  w  w  w .j  a va2s. c  o  m
        // If there isn't Accept Header in the request, will use error_message_type property
        // from _auth_failure_handler_.xml file
        if (messageContext.getProperty("error_message_type") != null) {
            axis2MC.setProperty(Constants.Configuration.MESSAGE_TYPE,
                    messageContext.getProperty("error_message_type"));
        }
    }
}

From source file:com.wrmsr.wava.transform.Transforms.java

public static Node eliminateUnreferencedLabels(Node root, Set<Name> referencedNames) {
    return rewriteNode(root, new Visitor<Void, Node>() {
        @Override/*w w w .  j  a  va2  s  .  c o  m*/
        protected Node visitNode(Node node, Void context) {
            return node;
        }

        @Override
        public Node visitLabel(Label node, Void context) {
            if (!referencedNames.contains(node.getName())) {
                return node.getBody();
            } else {
                return node;
            }
        }

        @Override
        public Node visitLoop(Loop node, Void context) {
            if (!referencedNames.contains(node.getName())) {
                return node.getBody();
            } else {
                return node;
            }
        }
    }, null);
}

From source file:com.btisystems.pronx.ems.App.java

private static boolean isObjectExcluded(final ObjectIdentifierValue oidValue, final Set<String> excludedRoots) {
    LOG.debug("check exlusion:{} {}", oidValue.toString(), excludedRoots);
    return excludedRoots != null && excludedRoots.contains(oidValue.toString());
}