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:com.o2d.pkayjava.editor.utils.runtime.EntityUtils.java

public static HashSet<Entity> getByUniqueId(Array<Integer> ids) {
    HashSet<Entity> entities = new HashSet<>();
    for (Integer id : ids) {
        Entity entity = com.o2d.pkayjava.editor.view.stage.Sandbox.getInstance()
                .getSceneControl().sceneLoader.entityFactory.getEntityByUniqueId(id);
        entities.add(entity);
    }//from   www.j  a v a 2  s. c  o  m
    return entities;
}

From source file:eu.digitisation.idiomaident.utils.CorpusFilter.java

private static HashSet getPosibleNames(String text) {
    HashSet<String> posibleNames = new HashSet();

    try {// w  w w .  j av a 2  s .c  o m
        WordScanner scanner = new WordScanner(text);

        String word = "";

        while ((word = scanner.nextWord()) != null) {
            //check the first letter
            if (word.matches("\\p{Upper}+.*")) {
                posibleNames.add(word);
            }
        }

        return posibleNames;
    } catch (IOException ex) {
        System.out.println(ex.toString());
    }

    return null;
}

From source file:com.hortonworks.registries.tag.service.CatalogTagService.java

public static Collection<Class<? extends Storable>> getStorableClasses() {
    InputStream resourceAsStream = CatalogTagService.class.getClassLoader()
            .getResourceAsStream("tagstorables.props");
    HashSet<Class<? extends Storable>> classes = new HashSet<>();
    try {/*from  w  w w  . ja  va 2  s  .  c o m*/
        List<String> classNames = IOUtils.readLines(resourceAsStream);
        for (String className : classNames) {
            classes.add((Class<? extends Storable>) Class.forName(className));
        }
    } catch (IOException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    return classes;
}

From source file:Main.java

public static String getAddressString(Address[] addresses) {
    if (addresses == null || addresses.length <= 0) {
        return "";
    }/*from   w w  w  .  ja v a  2  s .  com*/
    HashSet<String> foundAddress = new HashSet<String>();

    StringBuffer sb = new StringBuffer();
    InternetAddress addr = null;
    int length = addresses.length;
    for (int i = 0; i < length; i++) {
        addr = (InternetAddress) addresses[i];
        if (foundAddress.contains(addr.getAddress())) {
            continue;
        }
        foundAddress.add(addr.getAddress());

        if (addr.getPersonal() != null) {
            String personaladdr = getOneString(getTokens(addr.getPersonal(), "\r\n"), "");
            sb.append(personaladdr).append(" <").append(addr.getAddress()).append(">, ");
        } else {
            sb.append(addr.getAddress()).append(", ");
        }
    }
    String addressStr = sb.toString();
    return addressStr.substring(0, addressStr.length() - 2);
}

From source file:it.acubelab.smaph.SmaphUtils.java

/**
 * Turns a list of pairs <b,r>, where b is a bold and r is the position in
 * which the bold occurred, to the list of bolds and the hashmap between a
 * position and the list of bolds occurring in that position.
 * /*from ww  w  .  ja va2  s  . c  o m*/
 * @param boldAndRanks
 *            a list of pairs <b,r>, where b is a bold and r is the position
 *            in which the bold occurred.
 * @param positions
 *            where to store the mapping between a position (rank) and all
 *            bolds that appear in that position.
 * @param bolds
 *            where to store the bolds.
 */
public static void mapRankToBoldsLC(List<Pair<String, Integer>> boldAndRanks,
        HashMap<Integer, HashSet<String>> positions, HashSet<String> bolds) {

    for (Pair<String, Integer> boldAndRank : boldAndRanks) {
        String spot = boldAndRank.first.toLowerCase();
        int rank = boldAndRank.second;
        if (bolds != null)
            bolds.add(spot);
        if (positions != null) {
            if (!positions.containsKey(rank))
                positions.put(rank, new HashSet<String>());
            positions.get(rank).add(spot);
        }
    }

}

From source file:Main.java

public static void getTop(float[] array, ArrayList<Integer> rankList, int i) {
    int index = 0;
    int count = 0;
    HashSet<Integer> scanned = new HashSet<Integer>();
    float max = Float.MIN_VALUE;
    for (int m = 0; m < i && m < array.length; m++) {
        max = Float.MIN_VALUE;/*  ww w  . jav  a 2  s. com*/
        for (int no = 0; no < array.length; no++) {
            if (array[no] >= max && !scanned.contains(no)) {
                index = no;
                max = array[no];
            }
        }
        scanned.add(index);
        rankList.add(index);
        //System.out.println(m + "\t" + index);
    }
}

From source file:OAT.ui.util.UiUtil.java

public static DefaultMutableTreeNode addChildNode(DefaultMutableTreeNode parent, Object child) {
    HashSet hashSet = new HashSet();
    DefaultMutableTreeNode childNode;

    for (int i = 0; i < parent.getChildCount(); i++) {
        hashSet.add(parent.getChildAt(i).toString());
    }/*from   w  w  w  .  ja v  a  2 s  .c  o  m*/

    if (hashSet.add(child.toString())) {
        childNode = new DefaultMutableTreeNode(child);
        parent.insert(childNode, parent.getChildCount());
    } else {
        int i = 0;
        do {
            childNode = (DefaultMutableTreeNode) parent.getChildAt(i++);
            //System.out.println("childNode: " + childNode);
        } while (!childNode.toString().equals(child.toString()));
    }

    return childNode;
}

From source file:com.cburch.logisim.gui.main.SelectionAttributes.java

private static Set<Component> createSet(Collection<Component> comps) {
    boolean includeWires = true;
    for (Component comp : comps) {
        if (!(comp instanceof Wire)) {
            includeWires = false;/*from w w  w.  j a  v a2  s .c om*/
            break;
        }
    }

    if (includeWires) {
        return new HashSet<Component>(comps);
    } else {
        HashSet<Component> ret = new HashSet<Component>();
        for (Component comp : comps) {
            if (!(comp instanceof Wire))
                ret.add(comp);
        }
        return ret;
    }
}

From source file:index.partition.ZCurvePartitioner.java

public static ZCurvePartitioner createZcurveP() {
    ZCurvePartitioner zCurve = new ZCurvePartitioner();
    HashSet<Point> points = new HashSet<>();
    try {/*from w  ww .j  ava  2 s.c om*/
        BufferedReader reader = new BufferedReader(new FileReader(Global.POI_FILE));
        String line = reader.readLine();
        while ((line = reader.readLine()) != null) {
            try {
                POI poi = new POI(line);
                points.add(new Point(poi.getLat(), poi.getLng()));
            } catch (Exception e) {
                continue;
            }

        }
        zCurve.createFromPoints_inputNumSplits(points, Global.N_PARTITION);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return zCurve;
}

From source file:importer.handler.post.stages.Discriminator.java

/**
 * Merge two sets of space-delimited short version names
 * @param oldV the old version names/*from w  w w .  j  a v  a 2  s  .c  o  m*/
 * @param newV the new version names to add
 * @return the merged versions
 */
static String mergeVersions(String oldV, String newV) {
    if (oldV.length() == 0)
        return newV;
    else if (newV.length() == 0)
        return oldV;
    else {
        String[] oldVersions = oldV.split(" ");
        String[] newVersions = newV.split(" ");
        HashSet<String> all = new HashSet<String>();
        for (int i = 0; i < oldVersions.length; i++)
            all.add(oldVersions[i]);
        for (int i = 0; i < newVersions.length; i++)
            all.add(newVersions[i]);
        Iterator<String> iter = all.iterator();
        StringBuilder sb = new StringBuilder();
        while (iter.hasNext()) {
            String version = iter.next();
            sb.append(version);
            if (iter.hasNext())
                sb.append(" ");
        }
        return sb.toString();
    }
}