public String[] getEmail() { LinkedSet<String> ls = new LinkedSet<String>(); int counter = 0; String bod = this.getBody(); String from = this.getFrom(); Scanner f = new Scanner(from); Scanner b = new Scanner(bod); String pattern = "^[A-Za-z0-9]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; while (b.hasNext()) { String newString = b.next(); String finalString = newString.replaceAll(pattern, ""); if (newString.matches(pattern)) { ls.add(newString); counter++; } } while (f.hasNext()) { String newString = f.next(); String finalString = newString.replaceAll(pattern, ""); if (newString.matches(pattern)) { ls.add(newString); counter++; } } String[] Lastemails = new String[ls.size()]; if (ls.size() > 0) { for (int i = 0; i < ls.size(); i++) { Lastemails[i] = ls.get(i + 1); } } return Lastemails; }
public static void main(String[] args) { LinkedSet<Integer> l = new LinkedSet<>(); LinkedSet<Integer> sub = new LinkedSet<>(); sub.add(1); l.add(3); l.add(1); l.add(2); l.add(4); l.add(5); sub.add(10); sub.add(4); sub.add(5); sub.add(2); String s1 = "oi"; String s2 = "oioi"; int c = check(s1, s2); System.out.println(c); System.out.println(l.equals(sub)); int n = 2; print(n); }
public boolean equals(LinkedSet<T> l) { return size() == l.size() && containsAll(l); }
@Test public void testBasic() { LinkedSet<String> set = new LinkedSet<String>(true); Assert.assertNull(set.put("navis")); Assert.assertEquals("navis", set.get("navis")); Assert.assertEquals("navis", set.remove("navis")); set.put("navis1"); set.put("navis2"); set.put("navis3"); set.put("navis4"); Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis2", "navis3", "navis4")); Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis3", "navis4")); Assert.assertEquals("navis2", set.get("navis2")); Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2")); Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis3", "navis4")); Assert.assertEquals("navis3", set.removeMark("navis3")); Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2")); Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis3")); set.put("navis5"); Assert.assertTrue( TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2", "navis5")); Assert.assertTrue( TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis3", "navis5")); Assert.assertNull(set.get("navis3")); Assert.assertTrue( TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2", "navis5")); Assert.assertTrue( TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis3", "navis5")); Assert.assertEquals("navis3", set.put("navis3")); Assert.assertTrue( TestUtils.equals(set.values(), "navis1", "navis4", "navis2", "navis5", "navis3")); Assert.assertTrue( TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis5", "navis3")); Assert.assertEquals("navis3", set.remove("navis3")); Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis4", "navis2", "navis5")); Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis5")); }