List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:com.datatorrent.lib.util.WindowDataManagerTest.java
@Test public void testDelete() throws IOException { Map<Integer, String> dataOf1 = Maps.newHashMap(); dataOf1.put(1, "one"); dataOf1.put(2, "two"); dataOf1.put(3, "three"); Map<Integer, String> dataOf2 = Maps.newHashMap(); dataOf2.put(4, "four"); dataOf2.put(5, "five"); dataOf2.put(6, "six"); Map<Integer, String> dataOf3 = Maps.newHashMap(); dataOf2.put(7, "seven"); dataOf2.put(8, "eight"); dataOf2.put(9, "nine"); for (int i = 1; i <= 9; ++i) { testMeta.storageManager.save(dataOf1, 1, i); }/* w ww.ja v a2s . c o m*/ testMeta.storageManager.save(dataOf2, 2, 1); testMeta.storageManager.save(dataOf3, 3, 1); testMeta.storageManager.partitioned(Lists.<WindowDataManager>newArrayList(testMeta.storageManager), Sets.newHashSet(2, 3)); testMeta.storageManager.setup(testMeta.context); testMeta.storageManager.deleteUpTo(1, 6); Path appPath = new Path(testMeta.applicationPath + '/' + testMeta.storageManager.getRecoveryPath()); FileSystem fs = FileSystem.newInstance(appPath.toUri(), new Configuration()); FileStatus[] fileStatuses = fs.listStatus(new Path(appPath, Integer.toString(1))); Assert.assertEquals("number of windows for 1", 3, fileStatuses.length); TreeSet<String> windows = Sets.newTreeSet(); for (FileStatus fileStatus : fileStatuses) { windows.add(fileStatus.getPath().getName()); } Assert.assertEquals("window list for 1", Sets.newLinkedHashSet(Arrays.asList("7", "8", "9")), windows); Assert.assertEquals("no data for 2", false, fs.exists(new Path(appPath, Integer.toString(2)))); Assert.assertEquals("no data for 3", false, fs.exists(new Path(appPath, Integer.toString(3)))); }
From source file:com.datatorrent.lib.io.IdempotentStorageManagerTest.java
@Test public void testDelete() throws IOException { Map<Integer, String> dataOf1 = Maps.newHashMap(); dataOf1.put(1, "one"); dataOf1.put(2, "two"); dataOf1.put(3, "three"); Map<Integer, String> dataOf2 = Maps.newHashMap(); dataOf2.put(4, "four"); dataOf2.put(5, "five"); dataOf2.put(6, "six"); Map<Integer, String> dataOf3 = Maps.newHashMap(); dataOf2.put(7, "seven"); dataOf2.put(8, "eight"); dataOf2.put(9, "nine"); for (int i = 1; i <= 9; ++i) { testMeta.storageManager.save(dataOf1, 1, i); }/* www. j a v a2s. c o m*/ testMeta.storageManager.save(dataOf2, 2, 1); testMeta.storageManager.save(dataOf3, 3, 1); testMeta.storageManager.partitioned(Lists.<IdempotentStorageManager>newArrayList(testMeta.storageManager), Sets.newHashSet(2, 3)); testMeta.storageManager.setup(testMeta.context); testMeta.storageManager.deleteUpTo(1, 6); Path appPath = new Path(testMeta.applicationPath + '/' + testMeta.storageManager.recoveryPath); FileSystem fs = FileSystem.newInstance(appPath.toUri(), new Configuration()); FileStatus[] fileStatuses = fs.listStatus(new Path(appPath, Integer.toString(1))); Assert.assertEquals("number of windows for 1", 3, fileStatuses.length); TreeSet<String> windows = Sets.newTreeSet(); for (FileStatus fileStatus : fileStatuses) { windows.add(fileStatus.getPath().getName()); } Assert.assertEquals("window list for 1", Sets.newLinkedHashSet(Arrays.asList("7", "8", "9")), windows); Assert.assertEquals("no data for 2", false, fs.exists(new Path(appPath, Integer.toString(2)))); Assert.assertEquals("no data for 3", false, fs.exists(new Path(appPath, Integer.toString(3)))); }
From source file:net.spfbl.core.Reverse.java
private static TreeSet<String> getIPv4Set(String host) throws NamingException { TreeSet<String> ipSet = new TreeSet<String>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "A" }); if (atributes != null) { Attribute attribute = atributes.get("A"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { String ip = (String) attribute.get(index); if (SubnetIPv4.isValidIPv4(ip)) { ip = SubnetIPv4.normalizeIPv4(ip); ipSet.add(ip); }// ww w. j a v a 2 s.c o m } } } return ipSet; }
From source file:org.ala.spatial.web.services.LayerDistancesWSController.java
private String makeCSV(String type) { Map<String, Double> map = LayerDistanceIndex.loadDistances(); TreeSet<String> layerSet = new TreeSet<String>(); for (String k : map.keySet()) { String[] ks = k.split(" "); layerSet.add(ks[0]); layerSet.add(ks[1]);//from www . j ava2s . com } ArrayList<String> layerList = new ArrayList<String>(layerSet); //match against layers ArrayList<Layer> layerMatch = new ArrayList<Layer>(layerList.size()); for (int i = 0; i < layerList.size(); i++) { layerMatch.add(null); } List<Field> fields = Client.getFieldDao().getFields(); List<Layer> layers = Client.getLayerDao().getLayers(); for (int i = 0; i < layerList.size(); i++) { for (int j = 0; j < fields.size(); j++) { if (fields.get(j).getId().equals(layerList.get(i))) { for (int k = 0; k < layers.size(); k++) { if ((fields.get(j).getSpid() + "").equals(layers.get(k).getId() + "")) { layerMatch.set(i, layers.get(k)); break; } } break; } } } //output lower association matrix StringBuilder sb = new StringBuilder(); for (int i = 0; i < layerList.size(); i++) { if (i > 0) { if (type.equals("name")) { sb.append(layerMatch.get(i).getName()); } else if (type.equals("displayname")) { sb.append(layerMatch.get(i).getDisplayname()); } } sb.append(","); int size = (i == 0) ? layerList.size() - 1 : i; for (int j = 0; j < size; j++) { if (i == 0) { if (type.equals("name")) { sb.append(layerMatch.get(j).getName()); } else if (type.equals("displayname")) { sb.append(layerMatch.get(j).getDisplayname()); } } else { String key = (layerList.get(i).compareTo(layerList.get(j)) < 0) ? layerList.get(i) + " " + layerList.get(j) : layerList.get(j) + " " + layerList.get(i); if (key != null && map.get(key) != null) { sb.append(map.get(key)); } } if (j < size - 1) { sb.append(","); } } sb.append("\n"); } return sb.toString(); }
From source file:net.spfbl.core.Reverse.java
private static TreeSet<String> getIPv6Set(String host) throws NamingException { TreeSet<String> ipSet = new TreeSet<String>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "AAAA" }); if (atributes != null) { Attribute attribute = atributes.get("AAAA"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { String ip = (String) attribute.get(index); if (SubnetIPv6.isValidIPv6(ip)) { ip = SubnetIPv6.normalizeIPv6(ip); ipSet.add(ip); }//from ww w .j a v a 2s.com } } } return ipSet; }
From source file:edu.clemson.lph.utils.LabeledCSVParser.java
/** * Sort everything but the top row/*ww w . j a v a 2s . c o m*/ * NOTE: This is a unique sort the values in iCol should be unique or duplicates will be trimmed randomly. * @param iCol column to sort (see LabeledCSVParser.getLabelIdx( ColumnLabel ) ) * @param bNumbericCompare set to true to parse column to an number before comparing */ @Override public void sort(int iCol, boolean bNumericCompare, boolean bUniqueSort) { final int iSortCol = iCol; final boolean bNumeric = bNumericCompare; final boolean bUnique = bUniqueSort; // final ArrayList<List<String>> aRowsHold = (ArrayList<List<String>>)aRows.clone(); if (aRows == null || iRows <= 1 || iCol < 0 || iCol >= aRows.get(0).size()) return; ArrayList<String> lHeader = (ArrayList<String>) aRows.get(0); List<List<String>> lRows = aRows.subList(1, aRows.size()); Comparator<List<String>> compRows = new Comparator<List<String>>() { // Compare Strings in the indicated column. The only weird part is // numeric comparison. Try casting to Double. If both fail they are equal // if one fails it is GREATER than the other so it sorts later in the list. @Override public int compare(List<String> arg0, List<String> arg1) { int iRet = 0; String s0 = arg0.get(iSortCol); String s1 = arg1.get(iSortCol); if (bNumeric) { Double d0 = null; Double d1 = null; try { d0 = Double.parseDouble(s0); } catch (NumberFormatException e) { } try { d1 = Double.parseDouble(s1); } catch (NumberFormatException e) { } if (d0 != null && d1 != null) iRet = Double.compare(d0, d1); else if (d0 != null && d1 == null) return -1; else if (d0 == null && d1 != null) iRet = 1; else iRet = 0; } else { iRet = s0.compareTo(s1); } // If the compared column values are equal find SOMETHING different or the set logic // will only include the first row with that value if (!bUnique && iRet == 0) { for (int i = arg0.size() - 1; i >= 0; i--) { if (i != iSortCol) { String s0a = arg0.get(i); String s1a = arg1.get(i); iRet = s0a.compareTo(s1a); if (iRet != 0) { break; } } } } return iRet; } }; TreeSet<List<String>> setRows = new TreeSet<List<String>>(compRows); for (List<String> lRow : lRows) setRows.add(lRow); aRows.clear(); aRows.add(lHeader); for (List<String> lRow : setRows) { aRows.add(lRow); } iRows = aRows.size(); }
From source file:com.datatorrent.lib.util.FSWindowDataManagerTest.java
@Test public void testDelete() throws IOException { testMeta.storageManager.setup(testMeta.context); Map<Integer, String> dataOf1 = Maps.newHashMap(); dataOf1.put(1, "one"); dataOf1.put(2, "two"); dataOf1.put(3, "three"); Map<Integer, String> dataOf2 = Maps.newHashMap(); dataOf2.put(4, "four"); dataOf2.put(5, "five"); dataOf2.put(6, "six"); Map<Integer, String> dataOf3 = Maps.newHashMap(); dataOf2.put(7, "seven"); dataOf2.put(8, "eight"); dataOf2.put(9, "nine"); for (int i = 1; i <= 9; ++i) { testMeta.storageManager.save(dataOf1, 1, i); }// w w w. j a v a2 s. c o m testMeta.storageManager.save(dataOf2, 2, 1); testMeta.storageManager.save(dataOf3, 3, 1); testMeta.storageManager.partitioned(Lists.<WindowDataManager>newArrayList(testMeta.storageManager), Sets.newHashSet(2, 3)); testMeta.storageManager.setup(testMeta.context); testMeta.storageManager.deleteUpTo(1, 6); Path appPath = new Path(testMeta.applicationPath + '/' + testMeta.storageManager.getRecoveryPath()); FileSystem fs = FileSystem.newInstance(appPath.toUri(), new Configuration()); FileStatus[] fileStatuses = fs.listStatus(new Path(appPath, Integer.toString(1))); Assert.assertEquals("number of windows for 1", 3, fileStatuses.length); TreeSet<String> windows = Sets.newTreeSet(); for (FileStatus fileStatus : fileStatuses) { windows.add(fileStatus.getPath().getName()); } Assert.assertEquals("window list for 1", Sets.newTreeSet(Arrays.asList("7", "8", "9")), windows); Assert.assertEquals("no data for 2", false, fs.exists(new Path(appPath, Integer.toString(2)))); Assert.assertEquals("no data for 3", false, fs.exists(new Path(appPath, Integer.toString(3)))); testMeta.storageManager.teardown(); }
From source file:com.joliciel.csvLearner.maxent.MaxentBestFeatureObserver.java
@SuppressWarnings("unchecked") private void initialise() { Object[] dataStructures = maxentModel.getDataStructures(); outcomeNames = (String[]) dataStructures[2]; TreeSet<String> outcomeSet = new TreeSet<String>(); for (String outcome : outcomeNames) outcomeSet.add(outcome); outcomeList.addAll(outcomeSet);/*from w w w . j a va 2 s . c om*/ this.predicateTable = (IndexHashTable<String>) dataStructures[1]; predicates = new String[predicateTable.size()]; predicateTable.toArray(predicates); modelParameters = (Context[]) dataStructures[0]; }
From source file:byps.test.TestRemoteListTypes.java
@Test public void testRemoteListMapSetListInteger() throws RemoteException { log.info("testRemoteListMapSetListInteger("); ListListTypes obj = new ListListTypes(); List<Map<Integer, List<TreeSet<Integer>>>> list = new ArrayList<Map<Integer, List<TreeSet<Integer>>>>(); for (int i = 0; i < 2; i++) { Map<Integer, List<TreeSet<Integer>>> map = new TreeMap<Integer, List<TreeSet<Integer>>>(); for (int j = 0; j < 3; j++) { List<TreeSet<Integer>> list3 = new ArrayList<TreeSet<Integer>>(); for (int k = 0; k < 4; k++) { TreeSet<Integer> set = new TreeSet<Integer>(); for (int n = 0; n < 5; n++) { Integer pt = (i + 1) * (j + 1) * (k + 1) * (n + 1); set.add(pt); }/*from www.j a v a 2s. co m*/ list3.add(set); } map.put(j, list3); } list.add(map); } obj.int3 = list; remote.setInt4(obj.int3); TestUtils.assertEquals(log, "int4", obj.int3, remote.getInt4()); log.info(")testRemoteListMapSetListInteger"); }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.BuildNumberPropertiesProvider.java
@NotNull @Override// www .jav a 2s . c o m public Collection<String> getParametersAvailableOnAgent(@NotNull final SBuild build) { TreeSet<String> parameters = new TreeSet<String>(); for (int id : this.configurationService.getAllSharedBuildNumberIds()) parameters.add(BuildNumberPropertiesProvider.PARAMETER_PREFIX + id); return parameters; }