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:alba.components.FilteredShowFileRequestHandler.java

public static boolean isHiddenFile(SolrQueryRequest req, SolrQueryResponse rsp, String fnameIn,
        boolean reportError, Set<String> hiddenFiles) {
    String fname = fnameIn.toUpperCase(Locale.ROOT);
    if (hiddenFiles.contains(fname) || hiddenFiles.contains("*")) {
        if (reportError) {
            log.error("Cannot access " + fname);
            rsp.setException(//from  w  w  w  .j  av a 2s . c o  m
                    new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fnameIn));
        }
        return true;
    }

    // This is slightly off, a valid path is something like ./schema.xml. I don't think it's worth the effort though
    // to fix it to handle all possibilities though.
    if (fname.indexOf("..") >= 0 || fname.startsWith(".")) {
        if (reportError) {
            log.error("Invalid path: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fnameIn));
        }
        return true;
    }

    // Make sure that if the schema is managed, we don't allow editing. Don't really want to put
    // this in the init since we're not entirely sure when the managed schema will get initialized relative to this
    // handler.
    SolrCore core = req.getCore();
    IndexSchema schema = core.getLatestSchema();
    if (schema instanceof ManagedIndexSchema) {
        String managed = schema.getResourceName();

        if (fname.equalsIgnoreCase(managed)) {
            return true;
        }
    }
    return false;
}

From source file:net.intelliant.util.UtilCommon.java

public static String getModifiedHtmlWithAbsoluteImagePath(String html) {
    if (UtilValidate.isEmpty(html)) {
        return html;
    }/*from   w w w  . ja  v  a 2 s  .  c o m*/
    org.jsoup.nodes.Document doc = Jsoup.parse(html);
    Elements images = doc.select("img[src~=(?i)\\.(jpg|jpeg|png|gif)]");

    if (images != null && images.size() > 0) {
        String srcAttributeValue = "";
        StringBuilder finalLocation = new StringBuilder();
        Set<String> imageSrc = new HashSet<String>();

        for (Element image : images) {
            srcAttributeValue = image.attr("src");

            if (!imageSrc.contains(srcAttributeValue)) {
                int separatorIndex = srcAttributeValue.lastIndexOf("/");
                if (separatorIndex == -1) {
                    separatorIndex = srcAttributeValue
                            .lastIndexOf("\\"); /** just in case some one plays with html source. */
                }
                String outputFileName = null;
                if (separatorIndex != -1) {
                    String originalFileName = srcAttributeValue.substring(separatorIndex + 1);
                    outputFileName = originalFileName;
                }
                finalLocation = new StringBuilder(imageUploadLocation);
                finalLocation = finalLocation.append(outputFileName);

                imageSrc.add(srcAttributeValue);
                html = StringUtil.replaceString(html, srcAttributeValue, finalLocation.toString());
            }
        }
    }
    return html;
}

From source file:hermes.impl.LoaderSupport.java

public static void populateBean(Object bean, PropertySetConfig propertySet)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
    if (propertySet != null) {
        Set appliedProperties = new HashSet();

        for (Iterator iter = propertySet.getProperty().iterator(); iter.hasNext();) {
            PropertyConfig propertyConfig = (PropertyConfig) iter.next();

            if (appliedProperties.contains(propertyConfig.getName())) {
                iter.remove();//ww  w .j  a  va 2s  . co m
            } else {
                try {

                    BeanUtils.setProperty(bean, propertyConfig.getName(),
                            TextUtils.replaceClasspathVariables(propertyConfig.getValue()));

                    appliedProperties.add(propertyConfig.getName());

                    log.debug("set " + bean.getClass().getName() + " " + propertyConfig.getName() + "="
                            + TextUtils.replaceClasspathVariables(propertyConfig.getValue()));
                } catch (InvocationTargetException t) {
                    log.error(
                            "unable to set property name=" + propertyConfig.getName() + " value="
                                    + propertyConfig.getValue() + " on object of class "
                                    + bean.getClass().getName() + ": " + t.getCause().getMessage(),
                            t.getCause());
                }
            }
        }
    }
}

From source file:IntArray.java

public static IntArray composeNew(IntArray src, IntArray add, IntArray remove) {
    if (remove == null) {
        if (src == null) {
            return add;
        }//  w  ww.  jav  a 2  s . c  o m
        if (add != null) {
            IntArray newArray = new IntArray(add.length() + src.length());
            newArray.addAll(src);
            newArray.addAll(add);
            return newArray;
        }
        return src;
    } else {
        if (src == null && add == null) {
            return null;
        }
        int newLength = 0;
        if (add != null) {
            newLength += add.length();
        }
        if (src != null) {
            newLength += src.length();
        }
        IntArray newArray = new IntArray(newLength);
        Set<Integer> set = new HashSet<Integer>(remove.length() + 1, 1.0f);
        for (int i = 0; i < remove.length(); i++) {
            set.add(remove.get(i));
        }
        newArray.addAll(src);
        for (int i = 0; i < newArray.length(); i++) {
            int value = newArray.get(i);
            if (set.contains(value)) {
                boolean swapSuccessful = false;
                for (int j = newArray.length() - 1; j >= i + 1; j--) {
                    int backValue = newArray.get(j);
                    newArray.arrayCount--;
                    if (!set.contains(backValue)) {
                        newArray.getArray()[i] = backValue;
                        swapSuccessful = true;
                        break;
                    }
                }
                if (!swapSuccessful) // all elements from pos in remove
                {
                    newArray.arrayCount--;
                }
            }
        }
        if (add != null) {
            for (int i = 0; i < add.length(); i++) {
                int value = add.get(i);
                if (!set.contains(value)) {
                    newArray.add(value);
                }
            }
        }
        return newArray;
    }
}

From source file:com.linkedin.databus.bootstrap.utils.BootstrapSeederMain.java

public static void init(String[] args) throws Exception {
    parseArgs(args);/*from w ww.j a v a2  s.c o  m*/

    // Load the source configuration JSON file
    //File sourcesJson = new File("integration-test/config/sources-member2.json");
    File sourcesJson = new File(_sSourcesConfigFile);

    ObjectMapper mapper = new ObjectMapper();
    PhysicalSourceConfig physicalSourceConfig = mapper.readValue(sourcesJson, PhysicalSourceConfig.class);
    physicalSourceConfig.checkForNulls();

    Config config = new Config();

    ConfigLoader<StaticConfig> configLoader = new ConfigLoader<StaticConfig>("databus.seed.", config);
    _sStaticConfig = configLoader.loadConfig(_sBootstrapConfigProps);

    // Make sure the URI from the configuration file identifies an Oracle JDBC source.
    String uri = physicalSourceConfig.getUri();
    if (!uri.startsWith("jdbc:oracle")) {
        throw new InvalidConfigException("Invalid source URI (" + physicalSourceConfig.getUri()
                + "). Only jdbc:oracle: URIs are supported.");
    }

    String sourceTypeStr = physicalSourceConfig.getReplBitSetter().getSourceType();
    if (SourceType.TOKEN.toString().equalsIgnoreCase(sourceTypeStr))
        throw new InvalidConfigException(
                "Token Source-type for Replication bit setter config cannot be set for trigger-based Databus relay !!");

    // Create the OracleDataSource used to get DB connection(s)
    try {
        Class oracleDataSourceClass = OracleJarUtils.loadClass("oracle.jdbc.pool.OracleDataSource");
        Object ods = oracleDataSourceClass.newInstance();
        Method setURLMethod = oracleDataSourceClass.getMethod("setURL", String.class);
        setURLMethod.invoke(ods, uri);
        _sDataStore = (DataSource) ods;
    } catch (Exception e) {
        String errMsg = "Error creating a data source object ";
        LOG.error(errMsg, e);
        throw e;
    }

    //TODO: Need a better way than relaying on RelayFactory for generating MonitoredSourceInfo
    OracleEventProducerFactory factory = new BootstrapSeederOracleEventProducerFactory(
            _sStaticConfig.getController().getPKeyNameMap());

    // Parse each one of the logical sources
    _sources = new ArrayList<OracleTriggerMonitoredSourceInfo>();
    FileSystemSchemaRegistryService schemaRegistryService = FileSystemSchemaRegistryService
            .build(_sStaticConfig.getSchemaRegistry().getFileSystem());

    Set<String> seenUris = new HashSet<String>();
    for (LogicalSourceConfig sourceConfig : physicalSourceConfig.getSources()) {
        String srcUri = sourceConfig.getUri();
        if (seenUris.contains(srcUri)) {
            String msg = "Uri (" + srcUri
                    + ") is used for more than one sources. Currently Bootstrap Seeder cannot support seeding sources with the same URI together. Please have them run seperately !!";
            LOG.fatal(msg);
            throw new InvalidConfigException(msg);
        }
        seenUris.add(srcUri);
        OracleTriggerMonitoredSourceInfo source = factory.buildOracleMonitoredSourceInfo(sourceConfig.build(),
                physicalSourceConfig.build(), schemaRegistryService);
        _sources.add(source);
    }
    _sSeeder = new BootstrapDBSeeder(_sStaticConfig.getBootstrap(), _sources);

    _sBootstrapBuffer = new BootstrapEventBuffer(_sStaticConfig.getController().getCommitInterval() * 2);

    _sWriterThread = new BootstrapSeederWriterThread(_sBootstrapBuffer, _sSeeder);

    _sReader = new BootstrapSrcDBEventReader(_sDataStore, _sBootstrapBuffer, _sStaticConfig.getController(),
            _sources, _sSeeder.getLastRows(), _sSeeder.getLastKeys(), 0);
}

From source file:com.ocs.dynamo.domain.model.util.EntityModelUtil.java

/**
 * Copies all simple attribute values from one entity to the other
 * /*from w ww . ja v a  2s. co  m*/
 * @param source
 *            the source entity
 * @param target
 *            the target entity
 * @param model
 */
public static <T> void copySimpleAttributes(T source, T target, EntityModel<T> model, String... ignore) {
    Set<String> toIgnore = new HashSet<>();
    if (ignore != null) {
        toIgnore = Sets.newHashSet(ignore);
    }
    toIgnore.addAll(ALWAYS_IGNORE);

    for (AttributeModel am : model.getAttributeModels()) {
        if ((AttributeType.BASIC.equals(am.getAttributeType())
                || AttributeType.LOB.equals(am.getAttributeType())) && !toIgnore.contains(am.getName())) {
            if (!DynamoConstants.ID.equals(am.getName())) {
                Object value = ClassUtils.getFieldValue(source, am.getName());
                if (ClassUtils.canSetProperty(target, am.getName())) {
                    if (value != null) {
                        ClassUtils.setFieldValue(target, am.getName(), value);
                    } else {
                        ClassUtils.clearFieldValue(target, am.getName(), am.getType());
                    }
                }

            }
        }
    }
}

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

/**
 * Sets all the settable properties on the given target object which are not
 * in the given ignore set.// ww  w .j a v  a2s  .  co m
 * <p>
 * TODO merge this with what is in Architect's TestUtils class. This was
 * originally refactored out of there.
 * 
 * @param target
 *            The object to change the properties of
 * @param propertiesToIgnore
 *            The properties of target not to modify or read
 * @return A Map describing the new values of all the non-ignored, readable
 *         properties in target.
 */
public static Map<String, Object> setAllInterestingProperties(Object target, Set<String> propertiesToIgnore,
        NewValueMaker valueMaker) throws Exception {

    PropertyDescriptor props[] = PropertyUtils.getPropertyDescriptors(target);
    for (int i = 0; i < props.length; i++) {
        Object oldVal = null;
        if (PropertyUtils.isReadable(target, props[i].getName()) && props[i].getReadMethod() != null
                && !propertiesToIgnore.contains(props[i].getName())) {
            oldVal = PropertyUtils.getProperty(target, props[i].getName());
        }
        if (PropertyUtils.isWriteable(target, props[i].getName()) && props[i].getWriteMethod() != null
                && !propertiesToIgnore.contains(props[i].getName())) {

            Object newVal = valueMaker.makeNewValue(props[i].getPropertyType(), oldVal, props[i].getName());

            System.out.println("Changing property \"" + props[i].getName() + "\" to \"" + newVal + "\"");
            PropertyUtils.setProperty(target, props[i].getName(), newVal);

        }
    }

    // read them all back at the end in case there were dependencies between properties
    return TestUtils.getAllInterestingProperties(target, propertiesToIgnore);
}

From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java

private static void traverseTree(Node node, ChecksumGeneratorOptions opts, JsonWriter out) throws IOException {
    Set<String> nodeTypes = opts.getIncludedNodeTypes();
    Set<String> nodeTypeExcludes = opts.getExcludedNodeTypes();
    if (node != null) {
        String primaryNodeType;//ww  w  . j  ava  2s.c  o m
        try {
            primaryNodeType = node.getPrimaryNodeType().getName();
            if (nodeTypes.contains(primaryNodeType) && !nodeTypeExcludes.contains(primaryNodeType)) {
                generateNodeJSON(node, opts, out);
            } else {
                NodeIterator nodeIterator = node.getNodes();
                while (nodeIterator.hasNext()) {
                    primaryNodeType = node.getPrimaryNodeType().getName();
                    Node child = nodeIterator.nextNode();
                    if (nodeTypes.contains(primaryNodeType)) {
                        generateNodeJSON(child, opts, out);
                    } else {
                        traverseTree(child, opts, out);
                    }
                }
            }
        } catch (RepositoryException e) {
            log.error("Error while traversing tree {}", e.getMessage());
        }
    }
}

From source file:edu.stanford.muse.groups.SimilarGroupMethods.java

/** just return freqs of each item in the given corpus */
@SuppressWarnings("unused")
private static <T extends Comparable<? super T>> Map<T, Integer> computeIndivFreqs(List<Group<T>> input) {
    Map<T, Integer> result = new LinkedHashMap<T, Integer>();
    for (Group<T> g : input) {
        // sometimes same person is present twice on the
        // same message, in that case, do not double count
        Set<T> set = new LinkedHashSet<T>();
        for (T t : g.elements) {
            if (set.contains(t))
                continue;

            Integer I = result.get(t);
            if (I == null)
                result.put(t, 1);//from   w  ww  .j  a v a  2 s  . co m
            else
                result.put(t, I + 1);
        }
    }
    return result;
}

From source file:net.openid.appauth.AdditionalParamsProcessor.java

static Map<String, String> checkAdditionalParams(@Nullable Map<String, String> params,
        @NonNull Set<String> builtInParams) {
    if (params == null) {
        return Collections.emptyMap();
    }/*from   w  w  w  .  j  a  va 2  s . c o m*/

    Map<String, String> additionalParams = new LinkedHashMap<>();
    for (Map.Entry<String, String> entry : params.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        checkNotNull(key, "additional parameter keys cannot be null");
        checkNotNull(value, "additional parameter values cannot be null");

        checkArgument(!builtInParams.contains(key),
                "Parameter %s is directly supported via the authorization request builder, "
                        + "use the builder method instead",
                key);
        additionalParams.put(key, value);
    }

    return Collections.unmodifiableMap(additionalParams);
}