Java Collections.singleton Examples

Java Collections.singleton - 30 examples found. These are the top rated real world Java examples of java.util.Collections.singleton extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  public void testUpdateDeltaOnly() throws Exception {
    // local root with just a base in it
    makeLocalFile("00005.base.cueball");

    MockFetcher fetcher = new MockFetcher(LOCAL_ROOT, "00006.delta.cueball", "00007.delta.cueball");
    MockCueballMerger merger = new MockCueballMerger();
    CueballUpdater updater =
        new CueballUpdater(LOCAL_ROOT, 12, 5, fetcher, merger, new NoCompressionCodec(), 1);

    updater.update(7, Collections.singleton(45));

    // make sure fetcher got the right args
    assertEquals(5, fetcher.latestLocalVersion);
    assertEquals(Collections.singleton(45), fetcher.excludeVersions);

    // make sure the merger got the right args
    assertEquals(LOCAL_ROOT + "/00005.base.cueball", merger.latestBase);
    assertEquals(
        new HashSet<String>(
            Arrays.asList(
                LOCAL_ROOT + "/00006.delta.cueball", LOCAL_ROOT + "/00007.delta.cueball")),
        merger.deltas);
    assertEquals(12, merger.keyHashSize);
    assertEquals(5, merger.valueSize);
    assertEquals(LOCAL_ROOT + "/00007.base.cueball", merger.newBasePath);

    // make sure that the mock base created by the merger still exists
    assertTrue(localFileExists("/00007.base.cueball"));
    // old base should be deleted
    assertFalse(localFileExists("/00005.base.cueball"));
    // delta that was fetched should be deleted
    assertFalse(localFileExists(LOCAL_ROOT + "/00006.delta.cueball"));
    assertFalse(localFileExists(LOCAL_ROOT + "/00007.delta.cueball"));
  }
  @Test
  public void ensureRecordsTest() {
    int empId = 11303;
    List<PayPeriod> payPeriods =
        periodService.getOpenPayPeriods(PayPeriodType.AF, empId, SortOrder.ASC);
    // Print existing records
    Set<TimeRecord> existingRecords =
        timeRecordService
            .getTimeRecords(Collections.singleton(empId), payPeriods, TimeRecordStatus.getAll())
            .stream()
            .map(TimeRecord::new)
            .collect(Collectors.toSet());
    logger.info("-------- EXISTING RECORDS --------");
    printRecords(existingRecords);

    Stopwatch sw = Stopwatch.createStarted();
    // Generate records
    manager.ensureRecords(empId);
    logger.info("generation took {} ms", sw.stop().elapsed(TimeUnit.MILLISECONDS));

    // Print difference
    Set<TimeRecord> newRecords =
        new TreeSet<>(
            timeRecordService.getTimeRecords(
                Collections.singleton(empId), payPeriods, TimeRecordStatus.getAll()));
    logger.info("-------- NEW RECORDS --------");
    printRecords(Sets.difference(newRecords, existingRecords));
  }
 @Test
 public void testPowerSetOfThreeElementsHasCorrectSubsets() {
   LongSet<Set<String>> powerSet =
       LongPowerSet.create(new HashSet<>(Arrays.asList("a", "b", "c")));
   assertEquals("expect 8 subsets in the power set of a 3 element set", 8, powerSet.longSize());
   Set<Set<String>> constructedSet = new HashSet<>();
   for (Set<String> subset : powerSet) {
     constructedSet.add(subset);
   }
   Set<String> emptySet = Collections.emptySet();
   Set<String> singleElementSet1 = Collections.singleton("a");
   Set<String> singleElementSet2 = Collections.singleton("b");
   Set<String> singleElementSet3 = Collections.singleton("c");
   Set<String> twoElementSet1 = new HashSet<>(Arrays.asList("a", "b"));
   Set<String> twoElementSet2 = new HashSet<>(Arrays.asList("a", "c"));
   Set<String> twoElementSet3 = new HashSet<>(Arrays.asList("b", "c"));
   Set<String> threeElementSet = new HashSet<>(Arrays.asList("a", "b", "c"));
   Set<Set<String>> expectedSet =
       new HashSet<>(
           Arrays.asList(
               emptySet,
               singleElementSet1,
               singleElementSet2,
               singleElementSet3,
               twoElementSet1,
               twoElementSet2,
               twoElementSet3,
               threeElementSet));
   assertEquals(
       "expect iterated contents of power set to be correct", expectedSet, constructedSet);
   assertTrue("expect power set to contain correct subsets", powerSet.containsAll(expectedSet));
 }
Example #4
0
  /**
   * Put cas authentication attributes into model.
   *
   * @param model the model
   * @param registeredService the registered service
   * @return the cas authentication attributes
   */
  protected Map<String, Object> getCasProtocolAuthenticationAttributes(
      final Map<String, Object> model, final RegisteredService registeredService) {

    final Map<String, Object> filteredAuthenticationAttributes =
        new HashMap<>(getAuthenticationAttributes(model));

    filteredAuthenticationAttributes.put(
        CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_AUTHENTICATION_DATE,
        Collections.singleton(getAuthenticationDate(model)));
    filteredAuthenticationAttributes.put(
        CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_FROM_NEW_LOGIN,
        Collections.singleton(isAssertionBackedByNewLogin(model)));
    filteredAuthenticationAttributes.put(
        CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME,
        Collections.singleton(isRememberMeAuthentication(model)));

    final Optional<MultifactorAuthenticationProvider> contextProvider =
        getSatisfiedMultifactorAuthenticationProvider(model);
    if (contextProvider.isPresent() && StringUtils.isNotBlank(authenticationContextAttribute)) {
      filteredAuthenticationAttributes.put(
          this.authenticationContextAttribute,
          Collections.singleton(contextProvider.get().getId()));
    }

    return filteredAuthenticationAttributes;
  }
    protected void merge(
        VariantGraph into,
        Iterable<Token> witnessTokens,
        Map<Token, VariantGraphVertex> alignments) {
      Preconditions.checkArgument(!Iterables.isEmpty(witnessTokens), "Empty witness");
      final Witness witness = Iterables.getFirst(witnessTokens, null).getWitness();

      LOG.debug("{} + {}: Merge comparand into graph", into, witness);
      witnessTokenVertices = Maps.newHashMap();
      VariantGraphVertex last = into.getStart();
      final Set<Witness> witnessSet = Collections.singleton(witness);
      for (Token token : witnessTokens) {
        VariantGraphVertex matchingVertex = alignments.get(token);
        if (matchingVertex == null) {
          matchingVertex = into.add(token);
        } else {
          if (LOG.isTraceEnabled()) {
            LOG.trace("Adding matched {} to {}", token, matchingVertex);
          }
          matchingVertex.add(Collections.singleton(token));
        }
        witnessTokenVertices.put(token, matchingVertex);

        into.connect(last, matchingVertex, witnessSet);
        last = matchingVertex;
      }
      into.connect(last, into.getEnd(), witnessSet);
    }
Example #6
0
  public void testPreferenceDependencies() throws RaplaException {
    Allocatable allocatable = facade.newResource();
    facade.store(allocatable);

    CalendarSelectionModel calendar = facade.newCalendarModel(facade.getUser());
    calendar.setSelectedObjects(Collections.singleton(allocatable));
    calendar.setViewId(WeekViewFactory.WEEK_VIEW);
    CalendarModelConfiguration config = ((CalendarModelImpl) calendar).createConfiguration();

    RaplaMap<CalendarModelConfiguration> calendarList =
        facade.newRaplaMap(Collections.singleton(config));

    Preferences preferences = facade.getPreferences();
    Preferences editPref = facade.edit(preferences);
    TypedComponentRole<RaplaMap<CalendarModelConfiguration>> TEST_ENTRY =
        new TypedComponentRole<RaplaMap<CalendarModelConfiguration>>("TEST");
    editPref.putEntry(TEST_ENTRY, calendarList);
    facade.store(editPref);
    try {
      facade.remove(allocatable);
      fail("DependencyException should have thrown");
    } catch (DependencyException ex) {
    }

    calendarList = facade.newRaplaMap(new ArrayList<CalendarModelConfiguration>());
    editPref = facade.edit(preferences);
    editPref.putEntry(TEST_ENTRY, calendarList);
    facade.store(editPref);

    facade.remove(allocatable);
  }