Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:SerialVersionUID.java

static void buildJarSet(File dir, HashSet jarFiles) throws MalformedURLException {
    File[] files = dir.listFiles();
    int count = files != null ? files.length : 0;
    System.out.println("Checking dir: " + dir + ", count=" + count);
    for (int n = 0; n < count; n++) {
        File child = files[n];//from   www  . java2  s  . co m
        // Ignore the server tmp directory
        if (child.isDirectory() && child.getName().equals("tmp") == false)
            buildJarSet(child, jarFiles);
        else if (child.getName().endsWith(".jar"))
            jarFiles.add(child.toURL());
    }
}

From source file:dk.statsbiblioteket.doms.licensemodule.validation.LicenseValidator.java

public static ArrayList<String> filterGroups(ArrayList<License> licenses) {
    HashSet<String> groups = new HashSet<String>();
    for (License current : licenses) {
        for (LicenseContent currentContent : current.getLicenseContents()) {
            groups.add(currentContent.getName());
        }//  w w  w .  j  av a2  s .  c o m
    }
    return new ArrayList<String>(groups);
}

From source file:com.dtolabs.rundeck.plugin.resources.gcp.InstanceToNodeMapper.java

/**
 * Convert an GCP GCE Instance to a RunDeck INodeEntry based on the mapping input
 *///from   w ww . j  av a2s  .c om
@SuppressWarnings("unchecked")
static INodeEntry instanceToNode(final Instance inst, final Properties mapping) throws GeneratorException {
    final NodeEntryImpl node = new NodeEntryImpl();
    logger.error("instancetoNode call");
    //evaluate single settings.selector=tags/* mapping
    if ("tags/*".equals(mapping.getProperty("attributes.selector"))) {
        //iterate through instance tags and generate settings
        /*for (final String tag : inst.getTags().getItems()) {
        if (null == node.getAttributes()) {
            node.setAttribute(new HashMap<String, String>());
        }
        node.getAttribute().put(tag.getKey(), tag.getValue());
        }*/
    }
    if (null != mapping.getProperty("tags.selector")) {
        final String selector = mapping.getProperty("tags.selector");
        final String value = applySelector(inst, selector, mapping.getProperty("tags.default"), true);
        if (null != value) {
            final String[] values = value.split(",");
            final HashSet<String> tagset = new HashSet<String>();
            for (final String s : values) {
                tagset.add(s.trim());
            }
            if (null == node.getTags()) {
                node.setTags(tagset);
            } else {
                final HashSet orig = new HashSet(node.getTags());
                orig.addAll(tagset);
                node.setTags(orig);
            }
        }
    }
    if (null == node.getTags()) {
        node.setTags(new HashSet());
    }
    final HashSet orig = new HashSet(node.getTags());
    //apply specific tag selectors
    final Pattern tagPat = Pattern.compile("^tag\\.(.+?)\\.selector$");
    //evaluate tag selectors
    for (final Object o : mapping.keySet()) {
        final String key = (String) o;
        final String selector = mapping.getProperty(key);
        //split selector by = if present
        final String[] selparts = selector.split("=");
        final Matcher m = tagPat.matcher(key);
        if (m.matches()) {
            final String tagName = m.group(1);
            if (null == node.getAttributes()) {
                node.setAttributes(new HashMap<String, String>());
            }
            final String value = applySelector(inst, selparts[0], null);
            if (null != value) {
                if (selparts.length > 1 && !value.equals(selparts[1])) {
                    continue;
                }
                //use add the tag if the value is not null
                orig.add(tagName);
            }
        }
    }
    node.setTags(orig);

    //apply default values which do not have corresponding selector
    final Pattern attribDefPat = Pattern.compile("^([^.]+?)\\.default$");
    //evaluate selectors
    for (final Object o : mapping.keySet()) {
        final String key = (String) o;
        final String value = mapping.getProperty(key);
        final Matcher m = attribDefPat.matcher(key);
        if (m.matches() && (!mapping.containsKey(key + ".selector")
                || "".equals(mapping.getProperty(key + ".selector")))) {
            final String attrName = m.group(1);
            if (null == node.getAttributes()) {
                node.setAttributes(new HashMap<String, String>());
            }
            if (null != value) {
                node.getAttributes().put(attrName, value);
            }
        }
    }

    final Pattern attribPat = Pattern.compile("^([^.]+?)\\.selector$");
    //evaluate selectors
    for (final Object o : mapping.keySet()) {
        final String key = (String) o;
        final String selector = mapping.getProperty(key);
        final Matcher m = attribPat.matcher(key);
        if (m.matches()) {
            final String attrName = m.group(1);
            if (attrName.equals("tags")) {
                //already handled
                continue;
            }
            if (null == node.getAttributes()) {
                node.setAttributes(new HashMap<String, String>());
            }
            final String value = applySelector(inst, selector, mapping.getProperty(attrName + ".default"));
            if (null != value) {
                //use nodename-settingname to make the setting unique to the node
                node.getAttributes().put(attrName, value);
            }
        }
    }
    String hostSel = mapping.getProperty("hostname.selector");
    //logger.error("This is the hostSel variable " + hostSel);
    String host = applySelector(inst, hostSel, mapping.getProperty("hostname.default"));
    //logger.error("This is the host variable " + host);
    //logger.error("This is the hostname.default mapping param " + mapping.getProperty("hostname.default"));
    if (null == node.getHostname()) {
        System.err.println("Unable to determine hostname for instance: " + inst.getId());
        return null;
    }
    String name = node.getNodename();
    if (null == name || "".equals(name)) {
        name = node.getHostname();
    }
    if (null == name || "".equals(name)) {
        name = inst.getId().toString();
    }
    node.setNodename(name);

    // Set ssh port on hostname if not 22
    String sshport = node.getAttributes().get("sshport");
    if (sshport != null && !sshport.equals("") && !sshport.equals("22")) {
        node.setHostname(node.getHostname() + ":" + sshport);
    }

    return node;
}

From source file:com.sun.faban.harness.webclient.ResultAction.java

/**
 * This method is responsible for uploading the runs to repository.
 * @param uploadSet//from w  ww  .ja v a 2s.c  om
 * @param replaceSet
 * @return HashSet
 * @throws java.io.IOException
 */
public static HashSet<String> uploadRuns(String[] runIds, HashSet<File> uploadSet, HashSet<String> replaceSet)
        throws IOException {
    // 3. Upload the run
    HashSet<String> duplicates = new HashSet<String>();

    // Prepare run id set for cross checking.
    HashSet<String> runIdSet = new HashSet<String>(runIds.length);
    for (String runId : runIds) {
        runIdSet.add(runId);
    }

    // Prepare the parts for the request.
    ArrayList<Part> params = new ArrayList<Part>();
    params.add(new StringPart("host", Config.FABAN_HOST));
    for (String replaceId : replaceSet) {
        params.add(new StringPart("replace", replaceId));
    }
    for (File jarFile : uploadSet) {
        params.add(new FilePart("jarfile", jarFile));
    }
    Part[] parts = new Part[params.size()];
    parts = params.toArray(parts);

    // Send the request for each reposotory.
    for (URL repository : Config.repositoryURLs) {
        URL repos = new URL(repository, "/controller/uploader/upload_runs");
        PostMethod post = new PostMethod(repos.toString());
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        int status = client.executeMethod(post);

        if (status == HttpStatus.SC_FORBIDDEN)
            logger.warning("Server denied permission to upload run !");
        else if (status == HttpStatus.SC_NOT_ACCEPTABLE)
            logger.warning("Run origin error!");
        else if (status != HttpStatus.SC_CREATED)
            logger.warning(
                    "Server responded with status code " + status + ". Status code 201 (SC_CREATED) expected.");
        for (File jarFile : uploadSet) {
            jarFile.delete();
        }

        String response = post.getResponseBodyAsString();

        if (status == HttpStatus.SC_CREATED) {

            StringTokenizer t = new StringTokenizer(response.trim(), "\n");
            while (t.hasMoreTokens()) {
                String duplicateRun = t.nextToken().trim();
                if (duplicateRun.length() > 0)
                    duplicates.add(duplicateRun.trim());
            }

            for (Iterator<String> iter = duplicates.iterator(); iter.hasNext();) {
                String runId = iter.next();
                if (!runIdSet.contains(runId)) {
                    logger.warning("Unexpected archive response from " + repos + ": " + runId);
                    iter.remove();
                }
            }
        } else {
            logger.warning("Message from repository: " + response);
        }
    }
    return duplicates;
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.AbstractDiscoveryController.java

public static int curPendingFileCount(String projectName) {
    HashSet<String> fileSet = new HashSet<String>();
    UIResponseObserver observer = null;//from   w  w  w .j  a v  a 2 s.co m
    ArrayList<String> files = new ArrayList<String>();

    ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, observer);

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    return fileSet.size();
}

From source file:ro.weednet.contactssync.platform.ContactManager.java

public static void deleteMissingContacts(Context context, List<RawContact> localContacts,
        List<RawContact> serverContacts) {
    if (localContacts.size() == 0) {
        return;/*from  ww  w.j a  va  2 s. c o  m*/
    }

    final ContentResolver resolver = context.getContentResolver();
    final BatchOperation batchOperation = new BatchOperation(context, resolver);

    final HashSet<String> contactsIds = new HashSet<String>();
    for (RawContact rawContact : serverContacts) {
        contactsIds.add(rawContact.getUid());
    }

    for (RawContact rawContact : localContacts) {
        if (!contactsIds.contains(rawContact.getUid())) {
            final long rawContactId = rawContact.getRawContactId();
            if (rawContactId > 0) {
                ContactManager.deleteContact(context, rawContactId, batchOperation);
            }
        }
    }

    batchOperation.execute();
}

From source file:com.intellij.plugins.haxe.ide.annotator.HaxeSemanticAnnotator.java

public static void check(final HaxeVarDeclaration var, final AnnotationHolder holder) {
    HaxeFieldModel field = new HaxeFieldModel(var);
    if (field.isProperty()) {
        checkProperty(field, holder);/*from   w  w w. j a v  a  2 s .  c  o  m*/
    }
    if (field.hasInitializer() && field.hasTypeTag()) {
        TypeTagChecker.check(field.getPsi(), field.getTypeTagPsi(), field.getInitializerPsi(), false, holder);
    }

    // Checking for variable redefinition.
    HashSet<HaxeClassModel> classSet = new HashSet<HaxeClassModel>();
    HaxeClassModel fieldDeclaringClass = field.getDeclaringClass();
    classSet.add(fieldDeclaringClass);
    while (fieldDeclaringClass != null) {
        fieldDeclaringClass = fieldDeclaringClass.getParentClass();
        if (classSet.contains(fieldDeclaringClass)) {
            break;
        } else {
            classSet.add(fieldDeclaringClass);
        }
        if (fieldDeclaringClass != null) {
            for (HaxeFieldModel parentField : fieldDeclaringClass.getFields()) {
                if (parentField.getName().equals(field.getName())) {
                    if (parentField.isStatic()) {
                        holder.createWarningAnnotation(field.getNameOrBasePsi(),
                                "Field '" + field.getName() + "' overrides a static field of a superclass.");
                    } else {
                        holder.createErrorAnnotation(field.getDeclarationPsi(),
                                "Redefinition of variable '" + field.getName()
                                        + "' in subclass is not allowed. Previously declared at '"
                                        + fieldDeclaringClass.getName() + "'.");
                    }
                    break;
                }
            }
        }
    }
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.AbstractDiscoveryController.java

public static int curIdentifiedFileCount(String projectName) {
    HashSet<String> fileSet = new HashSet<String>();
    UIResponseObserver observer = null;//from ww  w  . ja  v a 2 s  .  com
    ArrayList<String> files = new ArrayList<String>();

    ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, observer);

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    return fileSet.size();
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.AbstractDiscoveryController.java

public static int originPendingFileCount(String projectName) {

    HashSet<String> fileSet = new HashSet<String>();
    UIResponseObserver observer = null;//from  w w  w. j  a v a  2  s.c  o m
    ArrayList<String> files = new ArrayList<String>();

    ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, observer);

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    return fileSet.size();
}

From source file:com.oneis.javascript.Runtime.java

private static void recursiveSealObjects(ScriptableObject object, ScriptableObject scope, HashSet<Object> seen,
        boolean sealThisObject) {
    // Avoid infinite recursion
    if (seen.contains(object)) {
        return;/*from w w w.j a  va2  s .  c  o  m*/
    }
    seen.add(object);

    for (Object propertyName : object.getAllIds()) {
        // Seal any getter or setters
        boolean foundGetter = false;
        if (propertyName instanceof String) // ConsString is checked -- property names are always proper Strings
        {
            for (int s = 0; s <= 1; s++) {
                boolean setter = (s == 0);
                Object gs = object.getGetterOrSetter((String) propertyName, 0, setter); // ConsString is checked
                if (gs != null && gs instanceof ScriptableObject) {
                    if (!setter) {
                        foundGetter = true;
                    }
                    recursiveSealObjects((ScriptableObject) gs, scope, seen, true);
                }
            }
        }
        // If there wasn't a getter, seal the property
        if (!foundGetter) {
            Object property = null;
            if (propertyName instanceof String) // ConsString is checked
            {
                property = object.get((String) propertyName, scope); // ConsString is checked
            } else if (propertyName instanceof Integer) {
                property = object.get(((Integer) propertyName).intValue(), scope);
            }
            if (property != null && property instanceof ScriptableObject) {
                recursiveSealObjects((ScriptableObject) property, scope, seen, true);
            }
        }
    }
    // Seal the prototype too?
    Scriptable prototype = object.getPrototype();
    if (prototype != null && prototype instanceof ScriptableObject) {
        recursiveSealObjects((ScriptableObject) prototype, scope, seen, true);
    }
    // Seal the parent scope?
    Scriptable parentScope = object.getParentScope();
    if (parentScope != null && parentScope instanceof ScriptableObject) {
        recursiveSealObjects((ScriptableObject) parentScope, scope, seen, true);
    }

    // Seal this object
    if (sealThisObject) {
        object.sealObject();
    }
}