List of usage examples for java.util Set clear
void clear();
From source file:Main.java
public static void main(String[] argv) throws Exception { Set set1 = new HashSet(); set1.clear(); }
From source file:Test.java
public static void main(String[] args) throws Exception { Path profile = Paths.get("/user/Admin/.profile"); PosixFileAttributes attrs = Files.readAttributes(profile, PosixFileAttributes.class); Set<PosixFilePermission> posixPermissions = attrs.permissions(); posixPermissions.clear(); String owner = attrs.owner().getName(); String perms = PosixFilePermissions.toString(posixPermissions); System.out.format("%s %s%n", owner, perms); posixPermissions.add(OWNER_READ);//from ww w . j a va 2s . co m posixPermissions.add(GROUP_READ); posixPermissions.add(OWNER_READ); posixPermissions.add(OWNER_WRITE); Files.setPosixFilePermissions(profile, posixPermissions); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set set1 = new HashSet(); Set set2 = new HashSet(); set1.retainAll(set2);//from w ww . ja v a 2 s . com // Remove all elements from a set set1.clear(); }
From source file:MainClass.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); elements = new String[] { "E", "F" }; set.addAll(Arrays.asList(elements)); System.out.println(set);/*from ww w . j a va2 s . c o m*/ set.clear(); System.out.println(set); }
From source file:Main.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set<String> set = new HashSet<String>(Arrays.asList(elements)); elements = new String[] { "E", "F" }; set.addAll(Arrays.asList(elements)); System.out.println(set);// www.j ava 2 s. c o m set.clear(); System.out.println(set); }
From source file:MainClass.java
public static void main(String[] a) { Set s = new HashSet(); s.add("A");//from ww w. j a v a 2 s. c o m s.add("B"); s.add("C"); s.add("D"); s.add("E"); s.add("F"); s.add("H"); Collections.unmodifiableSet(s); s = Collections.unmodifiableSet(s); s.clear(); }
From source file:squash.tools.FakeBookingCreator.java
public static void main(String[] args) throws IOException { int numberOfDays = 21; int numberOfCourts = 5; int maxCourtSpan = 5; int numberOfSlots = 16; int maxSlotSpan = 3; int minSurnameLength = 2; int maxSurnameLength = 20; int minBookingsPerDay = 0; int maxBookingsPerDay = 8; LocalDate startDate = LocalDate.of(2016, 7, 5); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); List<Booking> bookings = new ArrayList<>(); for (LocalDate date = startDate; date.isBefore(startDate.plusDays(numberOfDays)); date = date.plusDays(1)) { int numBookings = ThreadLocalRandom.current().nextInt(minBookingsPerDay, maxBookingsPerDay + 1); List<Booking> daysBookings = new ArrayList<>(); for (int bookingIndex = 0; bookingIndex < numBookings; bookingIndex++) { String player1 = RandomStringUtils.randomAlphabetic(1) + "." + RandomStringUtils.randomAlphabetic( ThreadLocalRandom.current().nextInt(minSurnameLength, maxSurnameLength + 1)); String player2 = RandomStringUtils.randomAlphabetic(1) + "." + RandomStringUtils.randomAlphabetic( ThreadLocalRandom.current().nextInt(minSurnameLength, maxSurnameLength + 1)); Set<ImmutablePair<Integer, Integer>> bookedCourts = new HashSet<>(); daysBookings.forEach((booking) -> { addBookingToSet(booking, bookedCourts); });/*from www. j a v a2 s . co m*/ Booking booking; Set<ImmutablePair<Integer, Integer>> courtsToBook = new HashSet<>(); do { // Loop until we create a booking of free courts int court = ThreadLocalRandom.current().nextInt(1, numberOfCourts + 1); int courtSpan = ThreadLocalRandom.current().nextInt(1, Math.min(maxCourtSpan + 1, numberOfCourts - court + 2)); int slot = ThreadLocalRandom.current().nextInt(1, numberOfSlots + 1); int slotSpan = ThreadLocalRandom.current().nextInt(1, Math.min(maxSlotSpan + 1, numberOfSlots - slot + 2)); booking = new Booking(court, courtSpan, slot, slotSpan, player1 + "/" + player2); booking.setDate(date.format(formatter)); courtsToBook.clear(); addBookingToSet(booking, courtsToBook); } while (Boolean.valueOf(Sets.intersection(courtsToBook, bookedCourts).size() > 0)); daysBookings.add(booking); } bookings.addAll(daysBookings); } // Encode bookings as JSON // Create the node factory that gives us nodes. JsonNodeFactory factory = new JsonNodeFactory(false); // Create a json factory to write the treenode as json. JsonFactory jsonFactory = new JsonFactory(); ObjectNode rootNode = factory.objectNode(); ArrayNode bookingsNode = rootNode.putArray("bookings"); for (int i = 0; i < bookings.size(); i++) { Booking booking = bookings.get(i); ObjectNode bookingNode = factory.objectNode(); bookingNode.put("court", booking.getCourt()); bookingNode.put("courtSpan", booking.getCourtSpan()); bookingNode.put("slot", booking.getSlot()); bookingNode.put("slotSpan", booking.getSlotSpan()); bookingNode.put("name", booking.getName()); bookingNode.put("date", booking.getDate()); bookingsNode.add(bookingNode); } // Add empty booking rules array - just so restore works rootNode.putArray("bookingRules"); rootNode.put("clearBeforeRestore", true); try (JsonGenerator generator = jsonFactory.createGenerator(new File("FakeBookings.json"), JsonEncoding.UTF8)) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_EMPTY); mapper.setSerializationInclusion(Include.NON_NULL); mapper.writeTree(generator, rootNode); } }
From source file:edu.cmu.ark.QuestionTransducer.java
/** * main method for testing stage 2 in isolation. The QuestionAsker class's main method should be * used to generate questions from the end-to-end system. * //from w w w .j a va2s. co m * @param args */ public static void main(String[] args) { QuestionTransducer qt = new QuestionTransducer(); AnalysisUtilities.getInstance(); String buf; Tree inputTree; boolean printParse = false; boolean printOriginal = false; boolean treeInput = false; boolean printFeatures = false; Set<Question> inputTrees = new HashSet<Question>(); qt.setAvoidPronounsAndDemonstratives(true); for (int i = 0; i < args.length; i++) { if (args[i].equals("--debug")) { GlobalProperties.setDebug(true); } else if (args[i].equals("--print-parse")) { printParse = true; } else if (args[i].equals("--print-original")) { printOriginal = true; } else if (args[i].equals("--print-features")) { printFeatures = true; } else if (args[i].equals("--print-extracted-phrases")) { qt.setPrintExtractedPhrases(true); } else if (args[i].equals("--tree-input")) { treeInput = true; } else if (args[i].equals("--keep-pro")) { qt.setAvoidPronounsAndDemonstratives(false); } else if (args[i].equals("--properties")) { GlobalProperties.loadProperties(args[i + 1]); } } try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //take input from the user on stdin if (GlobalProperties.getDebug()) System.err.println("\nInput Declarative Sentence:"); while ((buf = br.readLine()) != null) { if (treeInput) { buf = AnalysisUtilities.preprocessTreeString(buf); inputTree = AnalysisUtilities.getInstance().readTreeFromString(buf); AnalysisUtilities.getInstance().normalizeTree(inputTree); } else { if (AnalysisUtilities.filterOutSentenceByPunctuation(buf)) { continue; } buf = AnalysisUtilities.preprocess(buf); if (printOriginal) System.out.println("\n" + buf); ParseResult parseRes = AnalysisUtilities.getInstance().parseSentence(buf); inputTree = parseRes.parse; if (GlobalProperties.getDebug()) System.err.println("Parse Score: " + parseRes.score); } if (printParse) System.out.println(inputTree); inputTrees.clear(); Question tmp = new Question(); tmp.setIntermediateTree(inputTree.deepCopy()); tmp.setSourceTree(inputTree); inputTrees.add(tmp); //iterate over the trees given by the input List<Question> questions; for (Question q : inputTrees) { try { qt.generateQuestionsFromParse(q); questions = qt.getQuestions(); QuestionTransducer.removeDuplicateQuestions(questions); //iterate over the questions for each tree for (Question curQuestion : questions) { System.out.print(curQuestion.yield()); if (printFeatures) { System.out.print("\t"); int cnt = 0; for (Double val : curQuestion.featureValueList()) { if (cnt > 0) System.out.print(";"); System.out.print(NumberFormat.getInstance().format(val)); cnt++; } } System.out.println(); } } catch (Exception e) { e.printStackTrace(); } } if (GlobalProperties.getDebug()) System.err.println("\nInput Declarative Sentence:"); } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static long populate(Set set, int size) { long start, stop, result = 0; for (int i = 0; i < 100; i++) { set.clear(); start = System.nanoTime(); for (int j = 0; j < size; j++) { set.add(j);/*from w w w . j a va 2 s . com*/ } stop = System.nanoTime(); result += stop - start; } return result / 100; }
From source file:Main.java
public static <E> Collection<E> unique(Collection<? extends E> src, Collection<E> dest) { Set<E> set = new HashSet<>(); for (E element : src) { if (!set.contains(element)) { set.add(element);//from w ww . jav a 2 s.com dest.add(element); } } set.clear(); return dest; }