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:com.alibaba.jstorm.ui.UIUtils.java

public static void checkKey(List<String> ret, Set<String> temp, String key) {
    if (temp.contains(key)) {
        ret.add(key);/*w w w .ja v a 2 s .  c o  m*/
        temp.remove(key);
    }
    return;
}

From source file:com.uber.hoodie.hadoop.realtime.AbstractRealtimeRecordReader.java

/**
 * Given a comma separated list of field names and positions at which they appear on Hive, return
 * a ordered list of field names, that can be passed onto storage.
 *//*from  ww w  . j a v  a2s  .  c o  m*/
public static List<String> orderFields(String fieldNameCsv, String fieldOrderCsv,
        String partitioningFieldsCsv) {

    String[] fieldOrders = fieldOrderCsv.split(",");
    Set<String> partitioningFields = Arrays.stream(partitioningFieldsCsv.split(","))
            .collect(Collectors.toSet());
    List<String> fieldNames = Arrays.stream(fieldNameCsv.split(","))
            .filter(fn -> !partitioningFields.contains(fn)).collect(Collectors.toList());

    // Hive does not provide ids for partitioning fields, so check for lengths excluding that.
    if (fieldNames.size() != fieldOrders.length) {
        throw new HoodieException(
                String.format("Error ordering fields for storage read. #fieldNames: %d, #fieldPositions: %d",
                        fieldNames.size(), fieldOrders.length));
    }
    TreeMap<Integer, String> orderedFieldMap = new TreeMap<>();
    for (int ox = 0; ox < fieldOrders.length; ox++) {
        orderedFieldMap.put(Integer.parseInt(fieldOrders[ox]), fieldNames.get(ox));
    }
    return new ArrayList<>(orderedFieldMap.values());
}

From source file:net.sf.groovyMonkey.dom.Utilities.java

public static Set<String> getAllAvailableBundles() {
    final Set<String> set = new TreeSet<String>();
    final Set<String> defaultBundles = getAllRequiredBundles();
    for (final Bundle bundle : context().getBundles())
        if (!defaultBundles.contains(bundle.getSymbolicName()))
            set.add(bundle.getSymbolicName());
    return set;/*from ww  w. j av a2  s  . c o m*/
}

From source file:info.jtrac.util.ItemUtils.java

private static String getAsHtml(Item item, HttpServletRequest request, HttpServletResponse response,
        MessageSource ms, Locale loc) {

    boolean isWeb = request != null && response != null;

    String tableStyle = " class='jtrac'";
    String tdStyle = "";
    String thStyle = "";
    String altStyle = " class='alt'";
    String labelStyle = " class='label'";

    if (!isWeb) {
        // inline CSS so that HTML mail works across most mail-reader clients
        String tdCommonStyle = "border: 1px solid black";
        tableStyle = " class='jtrac' style='border-collapse: collapse; font-family: Arial; font-size: 75%'";
        tdStyle = " style='" + tdCommonStyle + "'";
        thStyle = " style='" + tdCommonStyle + "; background: #CCCCCC'";
        altStyle = " style='background: #e1ecfe'";
        labelStyle = " style='" + tdCommonStyle
                + "; background: #CCCCCC; font-weight: bold; text-align: right'";
    }/*from  w w  w.  java 2s.c  o  m*/

    StringBuffer sb = new StringBuffer();
    sb.append("<table width='100%'" + tableStyle + ">");
    sb.append("<tr" + altStyle + ">");
    sb.append("  <td" + labelStyle + ">" + fmt("id", ms, loc) + "</td>");
    sb.append("  <td" + tdStyle + ">" + item.getRefId() + "</td>");
    sb.append("  <td" + labelStyle + ">" + fmt("relatedItems", ms, loc) + "</td>");
    sb.append("  <td colspan='3'" + tdStyle + ">");
    if (item.getRelatedItems() != null || item.getRelatingItems() != null) {
        String flowUrlParam = null;
        String flowUrl = null;
        if (isWeb) {
            flowUrlParam = "_flowExecutionKey=" + request.getAttribute("flowExecutionKey");
            flowUrl = "/flow?" + flowUrlParam;
        }
        if (item.getRelatedItems() != null) {
            // ItemViewForm itemViewForm = null;
            if (isWeb) {
                // itemViewForm = (ItemViewForm) request.getAttribute("itemViewForm");
                sb.append("<input type='hidden' name='_removeRelated'/>");
            }
            for (ItemItem itemItem : item.getRelatedItems()) {
                String refId = itemItem.getRelatedItem().getRefId();
                if (isWeb) {
                    String checked = "";
                    Set<Long> set = null; // itemViewForm.getRemoveRelated();
                    if (set != null && set.contains(itemItem.getId())) {
                        checked = " checked='true'";
                    }
                    String url = flowUrl + "&_eventId=viewRelated&itemId=" + itemItem.getRelatedItem().getId();
                    refId = "<a href='" + response.encodeURL(request.getContextPath() + url) + "'>" + refId
                            + "</a>" + "<input type='checkbox' name='removeRelated' value='" + itemItem.getId()
                            + "' title='" + fmt("remove", ms, loc) + "'" + checked + "/>";
                }
                sb.append(fmt(itemItem.getRelationText(), ms, loc) + " " + refId + " ");
            }
        }
        if (item.getRelatingItems() != null) {
            for (ItemItem itemItem : item.getRelatingItems()) {
                String refId = itemItem.getItem().getRefId();
                if (isWeb) {
                    String url = flowUrl + "&_eventId=viewRelated&itemId=" + itemItem.getItem().getId();
                    refId = "<a href='" + response.encodeURL(request.getContextPath() + url) + "'>" + refId
                            + "</a>";
                }
                sb.append(refId + " " + fmt(itemItem.getRelationText() + "This", ms, loc) + ". ");
            }
        }
    }
    sb.append("  </td>");
    sb.append("</tr>");
    sb.append("<tr>");
    sb.append("  <td width='15%'" + labelStyle + ">" + fmt("status", ms, loc) + "</td>");
    sb.append("  <td" + tdStyle + ">" + item.getStatusValue() + "</td>");
    sb.append("  <td" + labelStyle + ">" + fmt("loggedBy", ms, loc) + "</td>");
    sb.append("  <td" + tdStyle + ">" + item.getLoggedBy().getName() + "</td>");
    sb.append("  <td" + labelStyle + ">" + fmt("assignedTo", ms, loc) + "</td>");
    sb.append("  <td width='15%'" + tdStyle + ">"
            + (item.getAssignedTo() == null ? "" : item.getAssignedTo().getName()) + "</td>");
    sb.append("</tr>");
    sb.append("<tr" + altStyle + ">");
    sb.append("  <td" + labelStyle + ">" + fmt("summary", ms, loc) + "</td>");
    sb.append("  <td colspan='5'" + tdStyle + ">" + HtmlUtils.htmlEscape(item.getSummary()) + "</td>");
    sb.append("</tr>");
    sb.append("<tr>");
    sb.append("  <td valign='top'" + labelStyle + ">" + fmt("detail", ms, loc) + "</td>");
    sb.append("  <td colspan='5'" + tdStyle + ">" + fixWhiteSpace(item.getDetail()) + "</td>");
    sb.append("</tr>");

    int row = 0;
    Map<Field.Name, Field> fields = item.getSpace().getMetadata().getFields();
    for (Field.Name fieldName : item.getSpace().getMetadata().getFieldOrder()) {
        Field field = fields.get(fieldName);
        sb.append("<tr" + (row % 2 == 0 ? altStyle : "") + ">");
        sb.append("  <td" + labelStyle + ">" + field.getLabel() + "</td>");
        sb.append("  <td colspan='5'" + tdStyle + ">" + item.getCustomValue(fieldName) + "</td>");
        sb.append("</tr>");
        row++;
    }
    sb.append("</table>");

    //=========================== HISTORY ==================================
    sb.append("<br/>&nbsp;<b" + tableStyle + ">" + fmt("history", ms, loc) + "</b>");
    sb.append("<table width='100%'" + tableStyle + ">");
    sb.append("<tr>");
    sb.append("  <th" + thStyle + ">" + fmt("loggedBy", ms, loc) + "</th><th" + thStyle + ">"
            + fmt("status", ms, loc) + "</th>" + "<th" + thStyle + ">" + fmt("assignedTo", ms, loc) + "</th><th"
            + thStyle + ">" + fmt("comment", ms, loc) + "</th><th" + thStyle + ">" + fmt("timeStamp", ms, loc)
            + "</th>");
    List<Field> editable = item.getSpace().getMetadata().getEditableFields();
    for (Field field : editable) {
        sb.append("<th" + thStyle + ">" + field.getLabel() + "</th>");
    }
    sb.append("</tr>");

    if (item.getHistory() != null) {
        row = 1;
        for (History history : item.getHistory()) {
            sb.append("<tr valign='top'" + (row % 2 == 0 ? altStyle : "") + ">");
            sb.append("  <td" + tdStyle + ">" + history.getLoggedBy().getName() + "</td>");
            sb.append("  <td" + tdStyle + ">" + history.getStatusValue() + "</td>");
            sb.append("  <td" + tdStyle + ">"
                    + (history.getAssignedTo() == null ? "" : history.getAssignedTo().getName()) + "</td>");
            sb.append("  <td" + tdStyle + ">");
            Attachment attachment = history.getAttachment();
            if (attachment != null) {
                if (request != null && response != null) {
                    String href = response.encodeURL(request.getContextPath() + "/app/attachments/"
                            + attachment.getFileName() + "?filePrefix=" + attachment.getFilePrefix());
                    sb.append("<a target='_blank' href='" + href + "'>" + attachment.getFileName()
                            + "</a>&nbsp;");
                } else {
                    sb.append("(attachment:&nbsp;" + attachment.getFileName() + ")&nbsp;");
                }
            }
            sb.append(fixWhiteSpace(history.getComment()));
            sb.append("  </td>");
            sb.append("  <td" + tdStyle + ">" + history.getTimeStamp() + "</td>");
            for (Field field : editable) {
                sb.append("<td" + tdStyle + ">" + history.getCustomValue(field.getName()) + "</td>");
            }
            sb.append("</tr>");
            row++;
        }
    }
    sb.append("</table>");
    return sb.toString();
}

From source file:coq.DebugUnivInconst.java

static boolean containsAStrictInequality(Set<String> scc, ArrayList<Constraint> strictConstraints) {
    for (Constraint constr : strictConstraints)
        if (scc.contains(constr.lhs) && scc.contains(constr.rhs))
            return true;

    return false;
}

From source file:com.perl5.lang.perl.util.PerlSubUtil.java

/**
 * Recursively collecting superMethods//  ww  w  .j a va  2s. c o m
 *
 * @param subBase        base method to search
 * @param classRecursion class recursion set
 * @return empty list if we've already been in this class, or list of topmost methods
 */
@NotNull
private static PerlSubBase getTopLevelSuperMethod(@NotNull PerlSubBase subBase, Set<String> classRecursion) {
    String packageName = subBase.getPackageName();

    if (packageName == null || classRecursion.contains(packageName)) {
        return subBase;
    }

    classRecursion.add(packageName);

    PerlSubBase directSuperMethod = getDirectSuperMethod(subBase);
    return directSuperMethod == null ? subBase : getTopLevelSuperMethod(directSuperMethod, classRecursion);
}

From source file:gov.nih.nci.caintegrator.common.PermissibleValueUtil.java

private static <T> Set<String> retrieveValuesNotInPermissibleValues(Set<T> permissibleValues,
        Collection<T> uniqueValues) {
    Set<String> valuesNotInPemissibleList = new HashSet<String>();
    if (CollectionUtils.isNotEmpty(permissibleValues)) {
        for (T uniqueValue : uniqueValues) {
            if (!permissibleValues.contains(uniqueValue)
                    && StringUtils.isNotBlank(ObjectUtils.toString(uniqueValue))) {
                valuesNotInPemissibleList.add(toString(uniqueValue));
            }/*from  w  ww. j a  v a 2  s  . c o  m*/
        }
    }
    return valuesNotInPemissibleList;
}

From source file:io.wcm.wcm.commons.util.RunMode.java

/**
 * Use this to disable a component if none of its run modes are active. Component activation status is logged
 * with DEBUG level./*  ww w . j  av  a 2 s  . c o  m*/
 * This method is a replacement for the
 * <code>com.day.cq.commons.RunModeUtil#disableIfNoRunModeActive(RunMode, String[], ComponentContext, Logger)</code>
 * method which is deprecated.
 * @param runModes Run modes
 * @param allowedRunModes Allowed run modes
 * @param componentContext OSGI component context
 * @param log Logger
 * @return true if component was disabled
 */
public static boolean disableIfNoRunModeActive(Set<String> runModes, String[] allowedRunModes,
        ComponentContext componentContext, Logger log) {

    final String name = (String) componentContext.getProperties().get(ComponentConstants.COMPONENT_NAME);
    boolean result = false;

    boolean isActive = false;
    for (String runMode : allowedRunModes) {
        if (runModes.contains(runMode)) {
            isActive = true;
            break;
        }
    }
    if (!isActive) {
        if (log.isDebugEnabled()) {
            log.debug("Component '" + name + "' " + "disabled as none of its run modes ("
                    + StringUtils.join(allowedRunModes, ",") + ") " + "are currently active ("
                    + StringUtils.join(runModes, ",") + ").");
        }
        componentContext.disableComponent(name);
        result = true;
    } else if (log.isDebugEnabled()) {
        log.debug("Component '" + name + "' " + "enabled as at least one of its run modes ("
                + StringUtils.join(allowedRunModes, ",") + ") " + "are currently active ("
                + StringUtils.join(runModes, ",") + ").");
    }

    return result;
}

From source file:Main.java

public static int deepHashCode(Object obj) {
    Set visited = new HashSet();
    LinkedList<Object> stack = new LinkedList<Object>();
    stack.addFirst(obj);/*from   w w  w. j ava  2  s.  co  m*/
    int hash = 0;

    while (!stack.isEmpty()) {
        obj = stack.removeFirst();
        if (obj == null || visited.contains(obj)) {
            continue;
        }

        visited.add(obj);

        if (obj.getClass().isArray()) {
            int len = Array.getLength(obj);
            for (int i = 0; i < len; i++) {
                stack.addFirst(Array.get(obj, i));
            }
            continue;
        }

        if (obj instanceof Collection) {
            stack.addAll(0, (Collection) obj);
            continue;
        }

        if (obj instanceof Map) {
            stack.addAll(0, ((Map) obj).keySet());
            stack.addAll(0, ((Map) obj).values());
            continue;
        }

        if (hasCustomHashCode(obj.getClass())) {
            hash += obj.hashCode();
            continue;
        }

        Collection<Field> fields = getDeepDeclaredFields(obj.getClass());
        for (Field field : fields) {
            try {
                stack.addFirst(field.get(obj));
            } catch (Exception ignored) {
            }
        }
    }
    return hash;
}

From source file:com.frostwire.gui.library.Device.java

private static List<File> flatFiles(File[] files) {
    Set<File> set = new HashSet<File>();
    for (File f : files) {
        for (File cf : getFiles(f, 3)) {
            if (!set.contains(cf)) {
                set.add(cf);//from  w w  w. j av a 2 s .  com
            }
        }
    }

    return new ArrayList<File>(set);
}