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:edu.ku.brc.specify.tasks.services.PickListUtils.java

/**
 * @param localizableIO/*from  ww  w .ja va 2  s. c o  m*/
 * @param hash HashSet of names of picklists to be pre-selected (can be null)
 */
public static void exportPickList(final LocalizableIOIFace localizableIO, final HashSet<String> hash) {
    // Cancel is Export All PickLists

    List<PickList> items = getPickLists(localizableIO, true, false);
    List<PickList> selectedItems = new ArrayList<PickList>();
    if (hash != null) {
        for (PickList pl : items) {
            if (hash.contains(pl.getName())) {
                selectedItems.add(pl);
            }
        }
    }

    Window window = UIRegistry.getTopWindow();
    boolean isDialog = window instanceof Dialog;

    ToggleButtonChooserDlg<PickList> pickDlg;
    if (isDialog) {
        pickDlg = new ToggleButtonChooserDlg<PickList>((Dialog) window, getI18n("PL_EXPORT"), items);
    } else {
        pickDlg = new ToggleButtonChooserDlg<PickList>((JFrame) window, getI18n("PL_EXPORT"), items);
    }

    pickDlg.setUseScrollPane(true);
    pickDlg.setAddSelectAll(true);
    pickDlg.createUI();
    pickDlg.setSelectedObjects(selectedItems);
    UIHelper.centerAndShow(pickDlg);

    Integer cnt = null;
    if (!pickDlg.isCancelled()) {
        items = pickDlg.getSelectedObjects();

        String dlgTitle = getResourceString(getI18n("RIE_ExportResource"));

        FileDialog dlg;
        if (isDialog) {
            dlg = new FileDialog((Dialog) window, dlgTitle, FileDialog.SAVE);
        } else {
            dlg = new FileDialog((Frame) window, dlgTitle, FileDialog.SAVE);
        }
        dlg.setDirectory(UIRegistry.getUserHomeDir());
        dlg.setFile(getPickListXMLName());

        UIHelper.centerAndShow(dlg);

        String dirStr = dlg.getDirectory();
        String fileName = dlg.getFile();

        if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) {
            String ext = FilenameUtils.getExtension(fileName);
            if (StringUtils.isEmpty(ext) || !ext.equalsIgnoreCase("xml")) {
                fileName += ".xml";
            }

            try {
                File xmlFile = new File(dirStr + File.separator + fileName);

                ArrayList<BldrPickList> bldrPickLists = new ArrayList<BldrPickList>();
                for (PickList pl : items) {
                    bldrPickLists.add(new BldrPickList(pl));
                }
                DataBuilder.writePickListsAsXML(xmlFile, bldrPickLists);
                cnt = bldrPickLists.size();

            } catch (Exception ex) {
                ex.printStackTrace();
            }
            UIRegistry.displayInfoMsgDlgLocalized(getI18n(cnt != null ? "PL_WASEXPORT" : "PL_ERR_IMP"), cnt);
        }
    }
}

From source file:com.ccoe.build.core.utils.FileUtils.java

public static void modifyPropertyFile(File file, Map<String, String> map) {
    List<String> postContent = new ArrayList<String>();
    try {/*  w w w .j  a va 2  s  . com*/
        List<String> originalContent = org.apache.commons.io.FileUtils.readLines(file);
        HashSet<String> keySet = new HashSet<String>();

        for (String line : originalContent) {
            if (line.trim().startsWith("#")) {
                postContent.add(line);
                continue;
            }

            String key = line.split("=")[0];
            keySet.add(key);

            if (!map.containsKey(key)) {
                postContent.add(line);
            } else {
                postContent.add(key + "=" + map.get(key));
            }
        }

        for (String key : map.keySet()) {
            if (!keySet.contains(key)) {
                postContent.add(key + "=" + map.get(key));
            }
        }

        System.out.println("keySet : " + keySet);

        org.apache.commons.io.FileUtils.writeLines(file, postContent);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.pclinuxos.rpm.util.FileUtils.java

/**
 * The method generated a string which contains all differences between two files, here for 
 * two lists with package names./* w w w  . jav a 2  s.c  o m*/
 * 
 * @param before original package count
 * @param after the content of this file will be search in "before"
 * @return if errors occured null else a string with differences which are not in "before".
 */
public static String compareRpmLists(File before, File after) {

    String out = null;

    try {

        BufferedReader l1Reader = new BufferedReader(new FileReader(before));
        BufferedReader l2Reader = new BufferedReader(new FileReader(after));

        HashSet<String> bef = new HashSet<String>();
        HashSet<String> aft = new HashSet<String>();

        String read = l1Reader.readLine();

        while (read != null) {

            bef.add(read);
            read = l1Reader.readLine();
        }

        l1Reader.close();
        read = l2Reader.readLine();

        while (read != null) {

            aft.add(read);
            read = l2Reader.readLine();
        }

        l2Reader.close();

        for (String pkg : aft) {

            if (bef.contains(pkg)) {

                out = out + " " + pkg;
            }
        }
    } catch (FileNotFoundException e) {

        out = null;
    } catch (IOException e) {

        out = null;
    }

    return out;
}

From source file:org.geowebcache.layer.MetaTile.java

@SuppressWarnings("rawtypes")
protected static void disposePlanarImageChain(PlanarImage pi, HashSet<PlanarImage> visited) {
    Vector sinks = pi.getSinks();
    // check all the sinks (the image might be in the middle of a chain)
    if (sinks != null) {
        for (Object sink : sinks) {
            if (sink instanceof PlanarImage && !visited.contains(sink)) {
                disposePlanarImageChain((PlanarImage) sink, visited);
            } else if (sink instanceof BufferedImage) {
                ((BufferedImage) sink).flush();
            }//from   w w  w.  j  a  v  a2s  .  c  om
        }
    }
    // dispose the image itself
    pi.dispose();
    visited.add(pi);

    // check the image sources
    Vector sources = pi.getSources();
    if (sources != null) {
        for (Object child : sources) {
            if (child instanceof PlanarImage && !visited.contains(child)) {
                disposePlanarImageChain((PlanarImage) child, visited);
            } else if (child instanceof BufferedImage) {
                ((BufferedImage) child).flush();
            }
        }
    }

    // ImageRead might also hold onto a image input stream that we have to close
    if (pi instanceof RenderedOp) {
        RenderedOp op = (RenderedOp) pi;
        for (Object param : op.getParameterBlock().getParameters()) {
            if (param instanceof ImageInputStream) {
                ImageInputStream iis = (ImageInputStream) param;
                try {
                    iis.close();
                } catch (IOException e) {
                    // fine, we tried
                }
            }
        }
    }
}

From source file:main.java.repartition.SimpleTr.java

static double getDeltaIdt(WorkloadBatch wb, SimpleTr t, MigrationPlan m) {

    int span = m.fromSet.size();
    double idt = (double) (span) * (1 / t.period);

    int incident_span = 0;
    double incident_idt = 0.0d;

    for (Entry<Integer, HashSet<Integer>> entry : t.serverDataSet.entrySet()) {

        HashSet<Integer> unique_trSet = new HashSet<Integer>();

        for (Integer d_id : entry.getValue()) {
            SimpleVertex v = wb.hgr.getVertex(d_id);

            for (SimpleHEdge h : wb.hgr.getIncidentEdges(v)) {
                Transaction incident_tr = wb.getTransaction(h.getId());

                if (incident_tr.getTr_id() != t.id) {
                    if (!unique_trSet.contains(incident_tr.getTr_id())) {
                        incident_span += getIncidentSpan(incident_tr, m);
                    }/*  w  w w . j  a va  2  s .  c  o  m*/

                    unique_trSet.add(incident_tr.getTr_id());
                }
            }
        }
    }

    // Calculate incident idt
    incident_idt = (double) (incident_span) * (1 / t.period);

    // Calculate total idt
    double total_idt = idt + incident_idt;

    // Finally, calculate the delta
    double delta_idt = (double) (total_idt / (Global.servers * WorkloadExecutor.sum_of_one_by_period));

    // Return Net Improvement Per Data Migration (NIPDM)
    return delta_idt;
    //return ((double) (delta_idt)/m.req_data_mgr);      
}

From source file:com.clustercontrol.repository.util.FacilityTreeCache.java

private static boolean hasAnyCommonRoleId(HashSet<String> roleIdSet, List<String> roleIdList) {
    for (String roleId : roleIdList) {
        if (roleIdSet.contains(roleId)) {
            return true;
        }//from  w w  w. j  av  a  2  s.  c  om
    }
    return false;
}

From source file:edu.stanford.muse.index.NER.java

public static void main2(String args[]) throws IOException, ClassNotFoundException {
    String text = "Rishabh has so far not taken to drama, so it was wonderful to see him involved and actively participating. ";
    boolean normalizeByLength = false;

    System.err.println("Started reading");
    long start_time = System.currentTimeMillis();
    List<String> names = new ArrayList<String>();
    HashSet<String> namesAdded = new HashSet<String>();
    long end_time = System.currentTimeMillis();
    for (String name : names) {
        if (!namesAdded.contains(name)) {
            System.out.println(name);
            namesAdded.add(name);//from   ww w  . j a v a  2s .c  om
        }
    }
    System.err.println("Reading done in " + (end_time - start_time));
    start_time = System.currentTimeMillis();

    List<Pair<String, Float>> entities = namesFromText(text, true, NER.defaultTokenTypeWeights,
            normalizeByLength, 1);
    end_time = System.currentTimeMillis();
    System.err.println("Done name recognition in: " + (end_time - start_time));

    for (Pair<String, Float> name : entities) {
        System.out.println(name.getFirst() + " : " + name.getSecond());
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java

private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
        List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited) {
    log.debug(/*from www .j a va2s. c  o m*/
            "starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ...");
    HashSet<String> range = new HashSet<String>();

    for (ObjectPropertyStatement ops : stmts) {
        if (ops.getPropertyURI().equals(predicateUri))
            range.add(ops.getObjectURI());
    }

    int removeCount = 0;
    ListIterator<Individual> it = individuals.listIterator();
    while (it.hasNext()) {
        Individual ind = it.next();
        if (range.contains(ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited))) {
            it.remove();
            ++removeCount;
        }
    }
    log.debug("removed " + removeCount + " duplicate range individuals");
    return individuals;
}

From source file:amie.keys.CombinationsExplorationNew.java

public static HashSet<HashSet<Integer>> buidPropertyGraphNew(int property) {
    HashSet<HashSet<Integer>> propertyPowerSets = new HashSet<>();
    for (HashSet<Integer> nonKeyInt : nonKeysInt) {
        if (nonKeyInt.contains(property)) {
            HashSet<Integer> remainingSet = new HashSet<>(nonKeyInt);
            remainingSet.addAll(nonKeyInt);
            remainingSet.remove(property);
            propertyPowerSets.addAll(powerSet(remainingSet));
        }/* w w w  .  j  av a  2  s  .  c o  m*/
    }
    return propertyPowerSets;
}

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;/*ww w .  j a va 2s  .  co  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();
}