List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:fr.simon.marquis.secretcodes.util.Utils.java
public static boolean addSecretCode(Context ctx, SecretCode value) { HashSet<SecretCode> secretCodes = new HashSet<SecretCode>(getSecretCodes(ctx)); boolean exist = secretCodes.contains(value); if (exist) {//from w w w .j ava 2 s . c o m secretCodes.remove(value); } secretCodes.add(value); saveSecretCodes(ctx, new ArrayList<SecretCode>(secretCodes)); return !exist; }
From source file:Main.java
/** * @param collectionOfCollection//from w w w. ja v a 2 s .c o m * a Collection<Collection<T>> * * @return a Set<T> containing all values of all Collections<T> * without any duplicates */ public static <T> Set<T> unionOfListOfLists(final Collection<? extends Collection<T>> collectionOfCollection) { if (collectionOfCollection == null || collectionOfCollection.isEmpty()) { return new HashSet<T>(0); } final HashSet<T> union = new HashSet<T>(); for (final Collection<T> col : collectionOfCollection) { if (col != null) { for (final T t : col) { if (t != null) { union.add(t); } } } } return union; }
From source file:eionet.cr.web.action.PingActionBean.java
/** * Utility method for obtaining the set of ping whitelist (i.e. hosts allowed to call CR's ping API) from configuration. * * @return The ping whitelist as a hash-set *//*from w ww .ja v a2s .c o m*/ private static HashSet<String> getPingWhiteList() { HashSet<String> result = new HashSet<String>(); result.add("localhost"); result.add("127.0.0.1"); result.add("0:0:0:0:0:0:0:1"); result.add("::1"); String property = GeneralConfig.getProperty(GeneralConfig.PING_WHITELIST); if (!StringUtils.isBlank(property)) { String[] split = property.split("\\s*,\\s*"); for (int i = 0; i < split.length; i++) { if (StringUtils.isNotBlank(split[i])) { result.add(split[i].trim().toLowerCase()); } } } return result; }
From source file:Main.java
/** * Keeps and returns the original list./*from w ww .j av a2 s.c o m*/ * * @param <T> * @param list * @return removes any duplicates in the list. Keeps the first occurrence of duplicates. */ public static <T> List<T> removeDuplicates(List<T> list) { HashSet<T> set = new HashSet<T>(list.size()); ListIterator<T> i = list.listIterator(); while (i.hasNext()) { T cur = i.next(); if (set.contains(cur)) { i.remove(); } else { set.add(cur); } } return list; }
From source file:com.dtolabs.rundeck.core.common.NodeEntryFactory.java
/** * Create NodeEntryImpl from map data. It will convert "tags" of type String as a comma separated list of tags, or * "tags" a collection of strings into a set. It will remove properties excluded from allowed import. * * @param map input map data//from w ww . ja va 2s . com * * @return * * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") public static NodeEntryImpl createFromMap(final Map<String, Object> map) throws IllegalArgumentException { final NodeEntryImpl nodeEntry = new NodeEntryImpl(); final HashMap<String, Object> newmap = new HashMap<String, Object>(map); for (final String excludeProp : excludeProps) { newmap.remove(excludeProp); } if (null != newmap.get("tags") && newmap.get("tags") instanceof String) { String tags = (String) newmap.get("tags"); String[] data; if ("".equals(tags.trim())) { data = new String[0]; } else { data = tags.split(","); } final HashSet set = new HashSet(); for (final String s : data) { if (null != s && !"".equals(s.trim())) { set.add(s.trim()); } } newmap.put("tags", set); } else if (null != newmap.get("tags") && newmap.get("tags") instanceof Collection) { Collection tags = (Collection) newmap.get("tags"); HashSet data = new HashSet(); for (final Object tag : tags) { if (null != tag && !"".equals(tag.toString().trim())) { data.add(tag.toString().trim()); } } newmap.put("tags", data); } else if (null != newmap.get("tags")) { Object o = newmap.get("tags"); newmap.put("tags", new HashSet(Arrays.asList(o.toString().trim()))); } try { BeanUtils.populate(nodeEntry, newmap); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } if (null == nodeEntry.getNodename()) { throw new IllegalArgumentException("Required property 'nodename' was not specified"); } if (null == nodeEntry.getHostname()) { throw new IllegalArgumentException("Required property 'hostname' was not specified"); } if (null == nodeEntry.getAttributes()) { nodeEntry.setAttributes(new HashMap<String, String>()); } //populate attributes with any keys outside of nodeprops for (final Map.Entry<String, Object> entry : newmap.entrySet()) { if (!ResourceXMLConstants.allPropSet.contains(entry.getKey())) { nodeEntry.setAttribute(entry.getKey(), (String) entry.getValue()); } } return nodeEntry; }
From source file:ai.grakn.graql.internal.util.StringConverter.java
/** * @return all Graql keywords/*from ww w . j ava 2s.co m*/ */ private static Stream<String> getKeywords() { HashSet<String> keywords = new HashSet<>(); for (int i = 1; GraqlLexer.VOCABULARY.getLiteralName(i) != null; i++) { String name = GraqlLexer.VOCABULARY.getLiteralName(i); keywords.add(name.replaceAll("'", "")); } return keywords.stream().filter(keyword -> !ALLOWED_ID_KEYWORDS.contains(keyword)); }
From source file:com.jiangyifen.ec2.servlet.http.common.utils.AnalyzeIfaceJointUtil.java
/** * @Description ????EC2?ip?/*from w ww. ja v a 2 s. c om*/ * * @author JRH * @date 201487 ?7:15:10 * @return HashSet<String> */ public static HashSet<String> getAuthorizeIps() { HashSet<String> authorizeIpsSet = new HashSet<String>(); String authorize_ips_str = props.getProperty(AUTHORIZE_IPS); if (authorize_ips_str != null && !"".equals(authorize_ips_str)) { for (String ip : authorize_ips_str.split(",")) { authorizeIpsSet.add(ip); } } return authorizeIpsSet; }
From source file:com.hortonworks.streamline.streams.catalog.service.CatalogService.java
public static Collection<Class<? extends Storable>> getStorableClasses() { InputStream resourceAsStream = CatalogService.class.getClassLoader().getResourceAsStream("storables.props"); HashSet<Class<? extends Storable>> classes = new HashSet<>(); try {//from w ww . jav a 2 s.co 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:edu.cudenver.bios.matrix.OrthogonalPolynomials.java
/** * Computes orthogonal polynomial contrasts for the specified data values. Currently only * supports fitting (not prediction contrasts). * /*from www. java 2 s .c om*/ * @param x the points at which the polynomials will be evaluated * @param maxDegree contrasts will be computed for degrees 1 to maxDegree * @return matrix containing 0th,1st, 2nd,...maxDegree-th degree contrasts in each column * @throws IllegalArgumentException */ public static RealMatrix orthogonalPolynomialCoefficients(double[] x, int maxDegree) throws IllegalArgumentException { if (x == null) throw new IllegalArgumentException("no data specified"); if (maxDegree < 1) throw new IllegalArgumentException("max polynomial degree must be greater than 1"); // count number of unique values HashSet<Double> s = new HashSet<Double>(); for (double i : x) s.add(i); int uniqueCount = s.size(); if (maxDegree >= uniqueCount) throw new IllegalArgumentException( "max polynomial degree must be less than the number of unique points"); // center the data double xBar = StatUtils.mean(x); double[] xCentered = new double[x.length]; for (int i = 0; i < x.length; i++) xCentered[i] = x[i] - xBar; // compute an "outer product" of the centered x vector and a vector // containing the sequence 0 to maxDegree-1, but raise the x values // to the power in the sequence array double[][] xOuter = new double[x.length][maxDegree + 1]; int row = 0; for (double xValue : xCentered) { for (int col = 0; col <= maxDegree; col++) { xOuter[row][col] = Math.pow(xValue, col); } row++; } // do some mysterious QR decomposition stuff. See Emerson (1968) RealMatrix outerVector = new Array2DRowRealMatrix(xOuter); QRDecomposition qrDecomp = new QRDecomposition(outerVector); RealMatrix z = MatrixUtils.getDiagonalMatrix(qrDecomp.getR()); RealMatrix raw = qrDecomp.getQ().multiply(z); // column sum of squared elements in raw double[] normalizingConstants = new double[raw.getColumnDimension()]; for (int col = 0; col < raw.getColumnDimension(); col++) { normalizingConstants[col] = 0; for (row = 0; row < raw.getRowDimension(); row++) { double value = raw.getEntry(row, col); normalizingConstants[col] += value * value; } } // now normalize the raw values for (int col = 0; col < raw.getColumnDimension(); col++) { double normalConstantSqrt = Math.sqrt(normalizingConstants[col]); for (row = 0; row < raw.getRowDimension(); row++) { raw.setEntry(row, col, raw.getEntry(row, col) / normalConstantSqrt); } } return raw; }
From source file:EndmemberExtraction.java
public static int[] assignInitialLabels(double[][] data, int nData, int nDim, int imgDim1, int imgDim2, double minThresholdAngle, double maxThresholdAngle, double stepSize, double minThresholdAbundance, String filepath) {//from ww w.ja va 2s. com int[] exemplarLabel = new int[nData]; int[][] exemplarMat; iterativeORASIS(data, nData, nDim, minThresholdAngle, maxThresholdAngle, stepSize, minThresholdAbundance, exemplarLabel); HashSet<Integer> uniqueExemplars = new HashSet<>(); for (int i = 0; i < nData; i++) { uniqueExemplars.add(exemplarLabel[i]); } //System.out.println("Unique exemplars:"); HashMap<Integer, Integer> exemplars = new HashMap<>(); int count = 0; for (int i : uniqueExemplars) { if (i != -1) { exemplars.put(i, count); //System.out.print(i+"\t"); count++; } } System.out.println("Exemplar Count:" + count); //System.out.println(); for (int i = 0; i < nData; i++) { if (exemplarLabel[i] != -1) { exemplarLabel[i] = exemplars.get(exemplarLabel[i]); } } exemplarMat = reshape(exemplarLabel, imgDim1, imgDim2); IO.writeData(exemplarMat, imgDim1, imgDim2, filepath + "exemplarMat.txt"); /* for(int i=0;i<imgDim1;i++){ System.out.print(i+" : "); for(int j=0;j<imgDim2;j++){ System.out.print(exemplarMat[i][j]+"\t"); } System.out.println(); } */ //Display exemplar classification image File exemplarImg = new File(filepath + "ExemplarImg.png"); ImageProc.imagesc(exemplarImg, exemplarMat, uniqueExemplars.size(), imgDim1, imgDim2); return exemplarLabel; }