Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.jiangyifen.ec2.servlet.http.common.filter.HttpCommonFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    try {// w w w  .  j a  va 2 s .co  m
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String requestURI = request.getRequestURI(); // ??:

        //         System.out.println(">JRH--->>>HttpCommonFilter.class-----requestURI-------"+requestURI);

        if (!requestURI.startsWith("/ec2/http/common/")) { // ???uri 
            chain.doFilter(new XssHttpServletRequestWrapper(request), response); // 
        } else {
            CommonRespBo commonRespBo = new CommonRespBo(); // ??
            commonRespBo.setCode(0);

            String remoteIp = request.getRemoteAddr();

            if (AnalyzeIfaceJointUtil.IP_FILTERABLE_VALUE) { // ?? IP 
                HashSet<String> ipSet = AnalyzeIfaceJointUtil.AUTHORIZE_IPS_SET;
                if (ipSet == null || !ipSet.contains(remoteIp)) { // IP ?IP??EC2 ?IP
                    commonRespBo.setCode(-1);
                    commonRespBo.setMessage("EC2????");
                    logger.warn(
                            "JRH - IFACE EC2?EC2????");
                    operateResponse(response, commonRespBo);
                    return;
                }
            }

            if (AnalyzeIfaceJointUtil.JOINT_LICENSE_NECESSARY_VALUE) { // EC2???License ??accessId  accessKey ?
                if (jointLicenseService == null) {
                    jointLicenseService = SpringContextHolder.getBean("jointLicenseService");
                }

                String accessId = StringUtils.trimToEmpty(request.getParameter("accessId"));
                String accessKey = StringUtils.trimToEmpty(request.getParameter("accessKey"));
                if ("".equals(accessId) || "".equals(accessKey)) { // ???
                    commonRespBo.setCode(-1);
                    commonRespBo
                            .setMessage("?(accessId) (accessKey) ???");
                    logger.warn(
                            "JRH - IFACE EC2??(accessId) (accessKey) ????");
                    operateResponse(response, commonRespBo);
                    return;
                }

                JointLicense jointLicense = jointLicenseService.getByIdKey(accessId, accessKey);
                if (jointLicense == null) { // License?
                    commonRespBo.setCode(-1);
                    commonRespBo.setMessage("?(accessId)  (accessKey) ?");
                    logger.warn(
                            "JRH - IFACE EC2??(accessId)  (accessKey) ?");
                    operateResponse(response, commonRespBo);
                    return;
                }

                request.setAttribute("domainId", jointLicense.getDomainId()); // ?
            } else {
                request.setAttribute("domainId", 1L); // ?
            }

            chain.doFilter(new XssHttpServletRequestWrapper(request), response); // , 
        }
    } catch (Exception e) {
        logger.error("JRH - IFACE EC2??" + e.getMessage(), e);
    }
}

From source file:adams.data.image.ImageMetaDataHelper.java

/**
 * Reads the meta-data from the file (Commons Imaging).
 *
 * @param file   the file to read the meta-data from
 * @return      the meta-data/*from w  w  w. ja v  a  2 s  .  com*/
 * @throws Exception   if failed to read meta-data
 */
public static SpreadSheet commons(File file) throws Exception {
    SpreadSheet sheet;
    Row row;
    org.apache.commons.imaging.common.ImageMetadata meta;
    String[] parts;
    String key;
    String value;
    org.apache.commons.imaging.ImageInfo info;
    String infoStr;
    String[] lines;
    HashSet<String> keys;

    sheet = new DefaultSpreadSheet();

    // header
    row = sheet.getHeaderRow();
    row.addCell("K").setContent("Key");
    row.addCell("V").setContent("Value");

    keys = new HashSet<String>();

    // meta-data
    meta = Imaging.getMetadata(file.getAbsoluteFile());
    if (meta != null) {
        for (Object item : meta.getItems()) {
            key = null;
            value = null;
            if (item instanceof ImageMetadata.Item) {
                key = ((ImageMetadata.Item) item).getKeyword().trim();
                value = ((ImageMetadata.Item) item).getText().trim();
            } else {
                parts = item.toString().split(": ");
                if (parts.length == 2) {
                    key = parts[0].trim();
                    value = parts[1].trim();
                }
            }
            if (key != null) {
                if (!keys.contains(key)) {
                    keys.add(key);
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(fixDateTime(Utils.unquote(value)));
                }
            }
        }
    }

    // image info
    info = Imaging.getImageInfo(file.getAbsoluteFile());
    if (info != null) {
        infoStr = info.toString();
        lines = infoStr.split(System.lineSeparator());
        for (String line : lines) {
            parts = line.split(": ");
            if (parts.length == 2) {
                key = parts[0].trim();
                value = parts[1].trim();
                if (!keys.contains(key)) {
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(Utils.unquote(value));
                    keys.add(key);
                }
            }
        }
    }

    return sheet;
}

From source file:adams.data.image.ImageMetaDataHelper.java

/**
 * Reads the meta-data from the file (using Sanselan).
 * //from w  w w  .j a va2s .  co m
 * @param file   the file to read the meta-data from
 * @return      the meta-data
 * @throws Exception   if failed to read meta-data
 */
public static SpreadSheet sanselan(File file) throws Exception {
    SpreadSheet sheet;
    Row row;
    org.apache.sanselan.common.IImageMetadata meta;
    String[] parts;
    String key;
    String value;
    org.apache.sanselan.ImageInfo info;
    String infoStr;
    String[] lines;
    HashSet<String> keys;

    sheet = new DefaultSpreadSheet();

    // header
    row = sheet.getHeaderRow();
    row.addCell("K").setContent("Key");
    row.addCell("V").setContent("Value");

    keys = new HashSet<String>();

    // meta-data
    meta = Sanselan.getMetadata(file.getAbsoluteFile());
    if (meta != null) {
        for (Object item : meta.getItems()) {
            key = null;
            value = null;
            if (item instanceof ImageMetadata.Item) {
                key = ((ImageMetadata.Item) item).getKeyword().trim();
                value = ((ImageMetadata.Item) item).getText().trim();
            } else {
                parts = item.toString().split(": ");
                if (parts.length == 2) {
                    key = parts[0].trim();
                    value = parts[1].trim();
                }
            }
            if (key != null) {
                if (!keys.contains(key)) {
                    keys.add(key);
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(fixDateTime(Utils.unquote(value)));
                }
            }
        }
    }

    // image info
    info = Sanselan.getImageInfo(file.getAbsoluteFile());
    if (info != null) {
        infoStr = info.toString();
        lines = infoStr.split(System.lineSeparator());
        for (String line : lines) {
            parts = line.split(": ");
            if (parts.length == 2) {
                key = parts[0].trim();
                value = parts[1].trim();
                if (!keys.contains(key)) {
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(Utils.unquote(value));
                    keys.add(key);
                }
            }
        }
    }

    return sheet;
}

From source file:com.github.frapontillo.pulse.crowd.remstopword.simple.SimpleStopWordRemover.java

/**
 * Check if a word is considered as a stop-word among the input dictionaries.
 *
 * @param word      The {@link String} to check.
 * @param fileNames Specifies the list of dictionary files to be used to check for stop words.
 *
 * @return true if the word is considered a stop word, false otherwise.
 *///  w ww  .j  a va2  s  . c o m
private boolean isStopWord(String word, List<String> fileNames) {
    if (word == null) {
        return true;
    }
    HashSet<String> dict = getDictionariesByFileNames(fileNames);
    return dict.contains(word.toLowerCase());
}

From source file:org.another.logserver.config.Configurator.java

/**
 * Initializes the component./*w ww.  j  a v a  2  s  . c  o m*/
 */
@PostConstruct
public void init() {
    LOGGER.debug("Defined endpoints: {}", (Object[]) endPoints);

    this.configuredEndPoints = new ConcurrentHashMap<>();

    HashSet<String> endPointsHashSet = new HashSet<>();
    Collections.addAll(endPointsHashSet, endPoints);

    if (endPointsHashSet.contains(EndPointDefinition.REST_ENDPOINT.getShortDefinition())) {
        configureRestEndPoint();
    }

    if (endPointsHashSet.contains(EndPointDefinition.TCP_ENDPOINT.getShortDefinition())) {
        configureTCPEndPoint();
    }

    LOGGER.debug("Finalizing Configure task");

}

From source file:com.thoughtworks.go.plugin.configrepo.contract.tasks.CRPluggableTask.java

private void validateKeyUniqueness(ErrorCollection errors, String location) {
    if (this.configuration == null)
        return;//w  w  w.  j av a  2 s  .c o m
    HashSet<String> keys = new HashSet<>();
    for (CRConfigurationProperty property1 : this.configuration) {
        String key = property1.getKey();
        if (keys.contains(key))
            errors.addError(location,
                    String.format("Configuration property %s is defined more than once", property1));
        else
            keys.add(key);
    }
}

From source file:mml.handler.get.MMLGetImgHandler.java

/**
 * Compile a page ref list that is the intersection of pageRefs and names
 * @param names the image names found on disk
 * @return the sorted and available list of page-refs
 *//*from w  w  w.  j  a v  a  2 s  .com*/
private String[] sortByPageRefs(String[] names) {
    ArrayList<String> available = new ArrayList<String>();
    HashSet<String> set = new HashSet<String>();
    for (String name : names)
        set.add(name);
    for (String ref : pageRefs) {
        if (set.contains(ref))
            available.add(ref);
    }
    String[] array = new String[available.size()];
    available.toArray(array);
    return array;
}

From source file:com.fstx.stdlib.author.old.AuthorizationBeanBuilderTest.java

public void testBuildAuthorizationBean() throws DAOException {

    AuthorizationBean ab = new AuthorizationBeanBuilder().buildAuthorizationBean(u1.getUsername());
    HashSet myRights = ab.getRights();

    assertEquals(myRights.size(), 4);//  ww w .  j ava2s.  c om
    assertTrue(myRights.contains("right1"));
    assertTrue(myRights.contains("right2"));
    assertTrue(myRights.contains("right3"));
    assertTrue(myRights.contains("Otherright2"));

    //            Iterator i = ab.getRights().iterator();
    //            String grTemp;
    //            while(i.hasNext())
    //            {
    //               grTemp = (String)i.next();
    //               
    //               log.info("My Sting: "+grTemp);
    //            }
    //            
}

From source file:com.sm.store.cluster.BuildClusterNodes.java

public List<ClusterNodes> build() {
    List<HierarchicalConfiguration> list = (List<HierarchicalConfiguration>) config.configurationsAt(CLUSTERS);
    if (list == null || list.size() == 0)
        throw new RuntimeException("list is null or freq ==0 for node " + CLUSTERS);
    List<ClusterNodes> toReturn = new CopyOnWriteArrayList<ClusterNodes>();
    StringBuilder stringBuilder = new StringBuilder();
    HashSet<Short> sets = new HashSet<Short>();
    int error = 0;
    for (HierarchicalConfiguration each : list) {
        ClusterNodes clusterNode = buildClusterNodes(each);
        if (sets.contains(clusterNode.getId())) {
            error++;//from www  .  j ava 2 s . co  m
            stringBuilder.append(" cluster no " + clusterNode.getId());
        } else
            sets.add(clusterNode.getId());
        toReturn.add(clusterNode);
    }
    if (error > 0) {
        throw new RuntimeException(
                error + " duplicate clusters , " + stringBuilder.toString() + " in clusters.xml");
    } else
        return toReturn;
}

From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzObjectProperties.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) {
        return;//from   ww w  .  java  2s . co  m
    }

    VitroRequest vreq = new VitroRequest(request);

    String vClassURI = vreq.getParameter("vClassURI");
    if (vClassURI == null || vClassURI.trim().equals("")) {
        return;
    }

    String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    respo += "<options>";

    ObjectPropertyDao odao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
    PropertyInstanceDao piDao = vreq.getUnfilteredWebappDaoFactory().getPropertyInstanceDao();
    VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();

    // incomplete list of classes to check, but better than before
    List<String> superclassURIs = vcDao.getAllSuperClassURIs(vClassURI);
    superclassURIs.add(vClassURI);
    superclassURIs.addAll(vcDao.getEquivalentClassURIs(vClassURI));

    Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>();
    for (String classURI : superclassURIs) {
        Collection<PropertyInstance> propInsts = piDao.getAllPropInstByVClass(classURI);
        try {
            for (PropertyInstance propInst : propInsts) {
                propInstMap.put(propInst.getPropertyURI(), propInst);
            }
        } catch (NullPointerException ex) {
            continue;
        }
    }
    List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>();
    propInsts.addAll(propInstMap.values());
    Collections.sort(propInsts);

    Iterator propInstIt = propInsts.iterator();
    HashSet opropURIs = new HashSet();
    while (propInstIt.hasNext()) {
        PropertyInstance pi = (PropertyInstance) propInstIt.next();
        if (!(opropURIs.contains(pi.getPropertyURI()))) {
            opropURIs.add(pi.getPropertyURI());
            ObjectProperty oprop = (ObjectProperty) odao.getObjectPropertyByURI(pi.getPropertyURI());
            if (oprop != null) {
                respo += "<option>" + "<key>" + oprop.getLocalName() + "</key>" + "<value>" + oprop.getURI()
                        + "</value>" + "</option>";
            }
        }
    }
    respo += "</options>";
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();

    out.println(respo);
    out.flush();
    out.close();
}