@Test
  public void zip() {
    List<Object> nulls = Collections.nCopies(this.lazyIterable.size(), null);
    List<Object> nullsPlusOne = Collections.nCopies(this.lazyIterable.size() + 1, null);
    List<Object> nullsMinusOne = Collections.nCopies(this.lazyIterable.size() - 1, null);

    LazyIterable<Pair<Integer, Object>> pairs = this.lazyIterable.zip(nulls);
    Assert.assertEquals(
        this.lazyIterable.toSet(), pairs.collect(Functions.<Integer>firstOfPair()).toSet());
    Assert.assertEquals(nulls, pairs.collect(Functions.<Object>secondOfPair(), Lists.mutable.of()));

    LazyIterable<Pair<Integer, Object>> pairsPlusOne = this.lazyIterable.zip(nullsPlusOne);
    Assert.assertEquals(
        this.lazyIterable.toSet(), pairsPlusOne.collect(Functions.<Integer>firstOfPair()).toSet());
    Assert.assertEquals(
        nulls, pairsPlusOne.collect(Functions.<Object>secondOfPair(), Lists.mutable.of()));

    LazyIterable<Pair<Integer, Object>> pairsMinusOne = this.lazyIterable.zip(nullsMinusOne);
    Assert.assertEquals(this.lazyIterable.size() - 1, pairsMinusOne.size());
    Assert.assertTrue(
        this.lazyIterable.containsAllIterable(
            pairsMinusOne.collect(Functions.<Integer>firstOfPair())));

    Assert.assertEquals(
        this.lazyIterable.zip(nulls).toSet(),
        this.lazyIterable.zip(nulls, UnifiedSet.<Pair<Integer, Object>>newSet()));
  }
  @Test
  public void zip() {
    ImmutableBag<String> immutableBag = this.newBag();
    List<Object> nulls = Collections.nCopies(immutableBag.size(), null);
    List<Object> nullsPlusOne = Collections.nCopies(immutableBag.size() + 1, null);
    List<Object> nullsMinusOne = Collections.nCopies(immutableBag.size() - 1, null);

    ImmutableBag<Pair<String, Object>> pairs = immutableBag.zip(nulls);
    Assert.assertEquals(
        immutableBag, pairs.collect((Function<Pair<String, ?>, String>) Pair::getOne));
    Assert.assertEquals(
        HashBag.newBag(nulls), pairs.collect((Function<Pair<?, Object>, Object>) Pair::getTwo));

    ImmutableBag<Pair<String, Object>> pairsPlusOne = immutableBag.zip(nullsPlusOne);
    Assert.assertEquals(
        immutableBag, pairsPlusOne.collect((Function<Pair<String, ?>, String>) Pair::getOne));
    Assert.assertEquals(
        HashBag.newBag(nulls),
        pairsPlusOne.collect((Function<Pair<?, Object>, Object>) Pair::getTwo));

    ImmutableBag<Pair<String, Object>> pairsMinusOne = immutableBag.zip(nullsMinusOne);
    Assert.assertEquals(immutableBag.size() - 1, pairsMinusOne.size());
    Assert.assertTrue(
        immutableBag.containsAllIterable(
            pairsMinusOne.collect((Function<Pair<String, ?>, String>) Pair::getOne)));

    Assert.assertEquals(
        immutableBag.zip(nulls), immutableBag.zip(nulls, HashBag.<Pair<String, Object>>newBag()));
  }
  @Test
  public void zip() {
    ImmutableMap<String, String> map =
        this.newMapWithKeysValues("1", "One", "2", "Two", "3", "Three", "4", "Four");

    List<Object> nulls = Collections.nCopies(map.size(), null);
    List<Object> nullsPlusOne = Collections.nCopies(map.size() + 1, null);

    RichIterable<Pair<String, Object>> pairs = map.zip(nulls);
    Assert.assertEquals(
        map.toSet(), pairs.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet());
    Assert.assertEquals(
        nulls, pairs.collect((Function<Pair<?, Object>, Object>) Pair::getTwo, Lists.mutable.of()));

    RichIterable<Pair<String, Object>> pairsPlusOne = map.zip(nullsPlusOne);
    Assert.assertEquals(
        map.toSet(),
        pairsPlusOne.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet());
    Assert.assertEquals(
        nulls,
        pairsPlusOne.collect((Function<Pair<?, Object>, Object>) Pair::getTwo, Lists.mutable.of()));

    if (map.notEmpty()) {
      List<Object> nullsMinusOne = Collections.nCopies(map.size() - 1, null);
      RichIterable<Pair<String, Object>> pairsMinusOne = map.zip(nullsMinusOne);
      Assert.assertEquals(map.size() - 1, pairsMinusOne.size());
    }

    Assert.assertEquals(
        map.zip(nulls).toSet(), map.zip(nulls, UnifiedSet.<Pair<String, Object>>newSet()));
  }
  @Test
  public void zip() {
    MutableMap<String, String> map = this.classUnderTest();

    List<Object> nulls = Collections.nCopies(map.size(), null);
    List<Object> nullsPlusOne = Collections.nCopies(map.size() + 1, null);

    RichIterable<Pair<String, Object>> pairs = map.zip(nulls);
    Assert.assertEquals(
        map.toSet(), pairs.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet());
    Assert.assertEquals(
        nulls, pairs.collect((Function<Pair<?, Object>, Object>) Pair::getTwo, Lists.mutable.of()));

    RichIterable<Pair<String, Object>> pairsPlusOne = map.zip(nullsPlusOne);
    Assert.assertEquals(
        map.toSet(),
        pairsPlusOne.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet());
    Assert.assertEquals(
        nulls,
        pairsPlusOne.collect((Function<Pair<?, Object>, Object>) Pair::getTwo, Lists.mutable.of()));

    if (map.notEmpty()) {
      List<Object> nullsMinusOne = Collections.nCopies(map.size() - 1, null);
      RichIterable<Pair<String, Object>> pairsMinusOne = map.zip(nullsMinusOne);
      Assert.assertEquals(map.size() - 1, pairsMinusOne.size());
      Assert.assertTrue(
          map.values()
              .containsAll(
                  pairsMinusOne.collect((Function<Pair<String, ?>, String>) Pair::getOne).toSet()));
    }

    Assert.assertEquals(
        map.zip(nulls).toSet(), map.zip(nulls, UnifiedSet.<Pair<String, Object>>newSet()));
  }
  @NotNull
  public static List<Color> generateLinearColorSequence(
      @NotNull List<Color> anchorColors, int count) {
    if (count == 0) return Collections.emptyList();
    if (anchorColors.isEmpty()) return Collections.nCopies(count, JBColor.GRAY);
    if (anchorColors.size() == 1) return Collections.nCopies(count, anchorColors.get(0));

    List<Color> result = new ArrayList<>();
    result.add(anchorColors.get(0));

    int segmentCount = anchorColors.size() - 1;
    int colorPerSegment = (count - 1) / segmentCount;
    if (count - 1 > colorPerSegment * segmentCount) colorPerSegment++; // divide rounding up

    for (int i = 0; i < segmentCount; i++) {
      Color color1 = anchorColors.get(i);
      Color color2 = anchorColors.get(i + 1);

      List<Color> linearColors = generateLinearColorSequence(color1, color2, colorPerSegment + 1);

      // skip first element from sequence to avoid duplication from connected segments
      result.addAll(linearColors.subList(1, linearColors.size()));
    }
    return result.subList(0, count);
  }
    @SuppressWarnings({"rawtypes", "unchecked"})
    public AnnotationDifferDocumentFeaturesImpl(int correct, int missing, int spurious) {
      super();

      this.spurious = spurious;
      this.missing = missing;
      this.correctMatches = correct;

      keyList = new ArrayList(Collections.nCopies(getKeysCount(), null));
      responseList = new ArrayList(Collections.nCopies(getResponsesCount(), null));
    }
Esempio n. 7
0
    @Test
    public void testManyVarcharBindValues() throws Exception {

        // [#1726] Check if large amounts of VARCHAR bind values can be handled
        Record record = create().select(Collections.nCopies(1000, val("abc"))).fetchOne();
        assertEquals(1000, record.size());
        assertEquals(Collections.nCopies(1000, "abc"), asList(record.intoArray()));

        assertEquals(1, create().selectOne()
            .where(val("abc").in(Collections.nCopies(1000, val("abc")).toArray(new Field[0])))
            .fetchOne(0));
    }
 @Test
 public void aggregateInPlaceByWithBatchSize() {
   MutableList<Integer> list =
       LazyIterate.adapt(Collections.nCopies(1000, 1))
           .concatenate(Collections.nCopies(2000, 2))
           .concatenate(Collections.nCopies(3000, 3))
           .toList()
           .shuffleThis();
   MapIterable<String, AtomicInteger> aggregation =
       ParallelIterate.aggregateInPlaceBy(
           list, String::valueOf, ATOMIC_INTEGER_NEW, AtomicInteger::addAndGet, 100);
   Assert.assertEquals(1000, aggregation.get("1").intValue());
   Assert.assertEquals(4000, aggregation.get("2").intValue());
   Assert.assertEquals(9000, aggregation.get("3").intValue());
 }
  public void testDelayedTasksThatFiredAtTheSameTimeAreExecutedConcurrently()
      throws InterruptedException, ExecutionException {
    final AppScheduledExecutorService service = new AppScheduledExecutorService(getName());
    final List<LogInfo> log = Collections.synchronizedList(new ArrayList<>());
    int delay = 500;

    int N = 20;
    List<? extends Future<?>> futures =
        ContainerUtil.map(
            Collections.nCopies(N, ""),
            __ ->
                service.schedule(
                    () -> {
                      log.add(new LogInfo(0));
                      TimeoutUtil.sleep(10 * 1000);
                    },
                    delay,
                    TimeUnit.MILLISECONDS));

    for (Future<?> future : futures) {
      future.get();
    }

    assertEquals(N, log.size());
    Set<Thread> usedThreads = ContainerUtil.map2Set(log, logInfo -> logInfo.currentThread);

    assertEquals(N, usedThreads.size());
    service.shutdownAppScheduledExecutorService();
    assertTrue(service.awaitTermination(10, TimeUnit.SECONDS));
  }
  public static List<Integer> multiply(List<Integer> num1, List<Integer> num2) {
    final int sign = num1.get(0) < 0 ^ num2.get(0) < 0 ? -1 : 1;
    num1.set(0, Math.abs(num1.get(0)));
    num2.set(0, Math.abs(num2.get(0)));

    List<Integer> result = new ArrayList<>(Collections.nCopies(num1.size() + num2.size(), 0));
    for (int i = num1.size() - 1; i >= 0; --i) {
      for (int j = num2.size() - 1; j >= 0; --j) {
        int temp = result.get(i + j + 1) + num1.get(i) * num2.get(j);
        result.set(i + j + 1, temp);
        temp = result.get(i + j) + result.get(i + j + 1) / 10;
        result.set(i + j, temp);
        temp = result.get(i + j + 1) % 10;
        result.set(i + j + 1, temp);
      }
    }

    // Remove the leading zeroes.
    int first_not_zero = 0;
    while (first_not_zero < result.size() && result.get(first_not_zero) == 0) {
      ++first_not_zero;
    }
    result = result.subList(first_not_zero, result.size());
    if (result.isEmpty()) {
      return Arrays.asList(0);
    }
    result.set(0, result.get(0) * sign);
    return result;
  }
 private void addSourcesContentMap(Appendable out) throws IOException {
   boolean found = false;
   List<String> contents = new ArrayList<>();
   contents.addAll(Collections.nCopies(sourceFileMap.size(), ""));
   for (Map.Entry<String, String> entry : sourceFileContentMap.entrySet()) {
     Integer index = sourceFileMap.get(entry.getKey());
     if (index != null && index < contents.size()) {
       contents.set(index, entry.getValue());
       found = true;
     }
   }
   if (!found) {
     return;
   }
   appendFieldStart(out, "sourcesContent");
   out.append("[");
   for (int i = 0; i < contents.size(); i++) {
     if (i != 0) {
       out.append(",");
     }
     out.append(escapeString(contents.get(i)));
   }
   out.append("]");
   appendFieldEnd(out);
 }
Esempio n. 12
0
    public PreparedResult prepareQueryable(Queryable queryable, RelDataType resultType) {
      queryString = null;
      Class runtimeContextClass = Object.class;
      final Argument[] arguments = {new Argument(connectionVariable, runtimeContextClass, null)};
      ClassDeclaration decl = init(arguments);

      final RelOptQuery query = new RelOptQuery(planner);
      final RelOptCluster cluster =
          query.createCluster(env, rexBuilder.getTypeFactory(), rexBuilder);

      RelNode rootRel = new LixToRelTranslator(cluster).translate(queryable);

      if (timingTracer != null) {
        timingTracer.traceTime("end sql2rel");
      }

      final RelDataType jdbcType = makeStruct(rexBuilder.getTypeFactory(), resultType);
      fieldOrigins = Collections.nCopies(jdbcType.getFieldCount(), null);

      // Structured type flattening, view expansion, and plugging in
      // physical storage.
      rootRel = flattenTypes(rootRel, true);

      // Trim unused fields.
      rootRel = trimUnusedFields(rootRel);

      rootRel = optimize(resultType, rootRel);
      containsJava = treeContainsJava(rootRel);

      if (timingTracer != null) {
        timingTracer.traceTime("end optimization");
      }

      return implement(resultType, rootRel, SqlKind.SELECT, decl, arguments);
    }
Esempio n. 13
0
 public List<List<String>> solveNQueens(int n) {
   List<List<String>> result = new ArrayList<>();
   List<String> curr =
       new ArrayList<>(Collections.nCopies(n, new String(new char[n]).replace('\0', '.')));
   nQueens(result, curr, 0);
   return result;
 }
  private Parameter[] getMatchingParameterListForSetters(PicoContainer container)
      throws PicoCompositionException {
    if (injectionMembers == null) {
      initializeInjectionMembersAndTypeLists();
    }

    final List<Object> matchingParameterList =
        new ArrayList<Object>(Collections.nCopies(injectionMembers.size(), null));

    final Parameter[] currentParameters =
        parameters != null ? parameters : createDefaultParameters(injectionTypes);
    final Set<Integer> nonMatchingParameterPositions =
        matchParameters(container, matchingParameterList, currentParameters);

    final Set<Type> unsatisfiableDependencyTypes = new HashSet<Type>();
    for (int i = 0; i < matchingParameterList.size(); i++) {
      if (matchingParameterList.get(i) == null) {
        unsatisfiableDependencyTypes.add(injectionTypes[i]);
      }
    }
    if (unsatisfiableDependencyTypes.size() > 0) {
      unsatisfiedDependencies(container, unsatisfiableDependencyTypes);
    } else if (nonMatchingParameterPositions.size() > 0) {
      throw new PicoCompositionException(
          "Following parameters do not match any of the injectionMembers for "
              + getComponentImplementation()
              + ": "
              + nonMatchingParameterPositions.toString());
    }
    return matchingParameterList.toArray(new Parameter[matchingParameterList.size()]);
  }
Esempio n. 15
0
  /**
   * We will test this by setting up two threads, asserting on the hash values the instances
   * generate for each thread
   *
   * @throws InterruptedException
   * @throws ExecutionException
   */
  @Test
  public void test_001_concurrent_match() throws InterruptedException, ExecutionException {

    // Setup callable method that reports the hashcode for the thread
    int threadCount = 2;
    Callable<Integer> task =
        new Callable<Integer>() {
          @Override
          public Integer call() {
            return Match.getInstance().hashCode();
          }
        };

    // Create n tasks to execute
    List<Callable<Integer>> tasks = Collections.nCopies(threadCount, task);

    // Execute the task for both tasks
    ExecutorService es = Executors.newFixedThreadPool(threadCount);
    List<Future<Integer>> futures = es.invokeAll(tasks);
    int hash1 = futures.get(0).get();
    int hash2 = futures.get(1).get();

    // The two hashcodes must NOT be equal
    Assert.assertThat(hash1, not(equalTo(hash2)));
  }
Esempio n. 16
0
  /**
   * @param authenticatedUser
   * @param analysisTypes
   * @param guid
   * @param dataGroups
   * @param limits
   * @param serviceTypes
   * @param userIdFilters
   * @return list of videos or null if none was found
   * @throws IllegalArgumentException
   */
  public static VideoList searchByGUID(
      UserIdentity authenticatedUser,
      EnumSet<AnalysisType> analysisTypes,
      String guid,
      DataGroups dataGroups,
      Limits limits,
      EnumSet<ServiceType> serviceTypes,
      long[] userIdFilters)
      throws IllegalArgumentException {
    if (VideoList.isEmpty(
        ServiceInitializer.getDAOHandler()
            .getDAO(VideoDAO.class)
            .search(
                authenticatedUser,
                null,
                Collections.nCopies(1, guid),
                null,
                null,
                null,
                null))) { // do not use serviceTypes or userIdFilters for existence check of
                          // reference video
      throw new IllegalArgumentException(
          "Invalid " + Definitions.PARAMETER_GUID + " or permission denied.");
    }

    return VideoSearchTask.getTaskByGUID(
            authenticatedUser, analysisTypes, dataGroups, guid, limits, serviceTypes, userIdFilters)
        .execute();
  }
Esempio n. 17
0
 public static void main(String[] args) throws Exception {
   List<String> signals = new ArrayList<>();
   Timestamp start = null;
   Timestamp end = null;
   String filename = null;
   for (int i = 0; i < args.length; i++) {
     String arg = args[i];
     if (arg.equals("-s")) {
       i++;
       start = format.parse(args[i]);
     } else if (arg.equals("-e")) {
       i++;
       end = format.parse(args[i]);
     } else if (arg.equals("-o")) {
       i++;
       filename = args[i];
     } else {
       signals.add(arg);
     }
   }
   List<TimeSeries> data = RrdToolDB.fetchData(signals, start, end);
   Map<String, TimeSeries> series = new HashMap<>();
   for (int i = 0; i < signals.size(); i++) {
     series.put(signals.get(i), data.get(i));
   }
   TimeSeriesMulti correlated = TimeSeriesMulti.synchronizeSeries(series);
   final Point3DWithLabelDataset dataset =
       Point3DWithLabelDatasets.build(
           correlated.getValues().get(signals.get(0)),
           correlated.getValues().get(signals.get(1)),
           correlated.getValues().get(signals.get(2)),
           Collections.nCopies(correlated.getValues().get(signals.get(0)).size(), "label"));
   BubbleUtil.createBubblePlot(filename, dataset, "DATASETLABEL", "", "", "", "", Timestamp.now());
 }
  @Test(dataProvider = "ploidyData")
  public void testFirst(final int ploidy) {
    final GenotypeAlleleCounts subject = GenotypeAlleleCounts.first(ploidy);
    Assert.assertNotNull(subject);
    Assert.assertEquals(subject.ploidy(), ploidy);
    Assert.assertEquals(subject.distinctAlleleCount(), 1);
    Assert.assertEquals(subject.alleleCountAt(0), ploidy);
    Assert.assertEquals(subject.alleleCountFor(0), ploidy);
    Assert.assertEquals(subject.alleleRankFor(0), 0);
    Assert.assertEquals(subject.alleleRankFor(1), -2);
    Assert.assertTrue(subject.containsAllele(0));
    Assert.assertFalse(subject.containsAllele(1));
    Assert.assertEquals(subject.alleleIndexAt(0), 0);
    Assert.assertEquals(subject.maximumAlleleIndex(), 0);
    Assert.assertEquals(subject.minimumAlleleIndex(), 0);
    Assert.assertTrue(subject.compareTo(subject) == 0);
    Assert.assertTrue(subject.equals(subject));
    Assert.assertEquals(subject.index(), 0);
    Assert.assertEquals(
        subject.asAlleleList(testAlleles), Collections.nCopies(ploidy, testAlleles.get(0)));
    for (int maximumAlleleIndex = 0;
        maximumAlleleIndex <= MAXIMUM_ALLELE_INDEX;
        maximumAlleleIndex++) {
      final int[] expected = new int[maximumAlleleIndex + 1];
      expected[0] = ploidy;
      Assert.assertEquals(subject.alleleCountsByIndex(maximumAlleleIndex), expected);
    }

    Assert.assertNotNull(subject.toString());
    Assert.assertEquals(
        subject.toUnphasedGenotypeString(),
        ploidy == 1 ? "0" : Strings.repeat("0/", ploidy - 1) + "0");
  }
Esempio n. 19
0
  @Override
  public void writeExternal(Element element) throws WriteExternalException {
    List<HighlightSeverity> list = getOrderAsList(getOrderMap());
    for (HighlightSeverity severity : list) {
      Element info = new Element(INFO_TAG);
      String severityName = severity.getName();
      final SeverityBasedTextAttributes infoType = getAttributesBySeverity(severity);
      if (infoType != null) {
        infoType.writeExternal(info);
        final Color color = myRendererColors.get(severityName);
        if (color != null) {
          info.setAttribute(COLOR_ATTRIBUTE, Integer.toString(color.getRGB() & 0xFFFFFF, 16));
        }
        element.addContent(info);
      }
    }

    if (myReadOrder != null && !myReadOrder.isEmpty()) {
      myReadOrder.writeExternal(element);
    } else if (!getDefaultOrder().equals(list)) {
      final JDOMExternalizableStringList ext =
          new JDOMExternalizableStringList(Collections.nCopies(getOrderMap().size(), ""));
      getOrderMap()
          .forEachEntry(
              new TObjectIntProcedure<HighlightSeverity>() {
                @Override
                public boolean execute(HighlightSeverity orderSeverity, int oIdx) {
                  ext.set(oIdx, orderSeverity.getName());
                  return true;
                }
              });
      ext.writeExternal(element);
    }
  }
  Object calculateImpl(final String newName) {
    // If the name does not match, disconnect and connect
    if (!Objects.equals(newName, previousName)) {
      if (currentExpressions != null) {
        for (DesiredRateExpression<?> desiredRateExpression : currentExpressions) {
          if (desiredRateExpression != null) {
            getDirector().disconnectReadExpression(desiredRateExpression);
          }
        }
      }

      List<DesiredRateExpression<?>> newExpressions = new ArrayList<>();
      if (newName != null) {
        newExpressions.addAll(Collections.nCopies(3, (DesiredRateExpression<?>) null));
      }

      // Connect new expressions
      if (newName != null) {
        DesiredRateExpression<?> newExpression = channel(newName, Object.class);
        getDirector().disconnectReadExpression(newExpression);
        newExpressions.set(0, newExpression);
        newExpression = channel(newName + ".LLIM", Object.class);
        getDirector().disconnectReadExpression(newExpression);
        newExpressions.set(1, newExpression);
        newExpression = channel(newName + ".ULIM", Object.class);
        getDirector().disconnectReadExpression(newExpression);
        newExpressions.set(2, newExpression);
      }

      previousName = newName;
      currentExpressions = newExpressions;
    }

    // No return value
    if (newName == null) {
      return null;
    }

    // Extract values
    VNumberArray array = (VNumberArray) currentExpressions.get(0).getFunction().readValue();
    VNumber lowerRange = (VNumber) currentExpressions.get(1).getFunction().readValue();
    VNumber upperRange = (VNumber) currentExpressions.get(2).getFunction().readValue();
    if (array == null || lowerRange == null || upperRange == null) {
      return null;
    }

    return ValueFactory.newVNumberArray(
        array.getData(),
        array.getSizes(),
        Arrays.asList(
            ValueFactory.newDisplay(
                VTableFactory.range(
                        lowerRange.getValue().doubleValue(), upperRange.getValue().doubleValue())
                    .createListNumber(array.getSizes().getInt(0) + 1),
                "")),
        array,
        array,
        array);
  }
Esempio n. 21
0
 @Test
 public void testCommonSuffix() {
   checkCollectorEmpty("suffix", "", MoreCollectors.commonSuffix());
   List<String> input = Arrays.asList("defabc", "degfabc", "dfgfgabc", "efghabc", "dfgabc");
   checkShortCircuitCollector(
       "suffix", "abc", input.size(), input::stream, MoreCollectors.commonSuffix());
   List<CharSequence> inputSeq =
       Arrays.asList(
           new StringBuffer("degfabc"),
           "dfgfgabc",
           new StringBuilder("efghabc"),
           "defabc",
           "dfgabc");
   checkShortCircuitCollector(
       "suffix", "abc", inputSeq.size(), inputSeq::stream, MoreCollectors.commonSuffix());
   List<String> input2 = Arrays.asList("defabc", "defgabc", "dabcdfgfg", "efghabc", "dfgabc");
   checkShortCircuitCollector("suffix", "", 3, input2::stream, MoreCollectors.commonSuffix());
   List<String> inputHalf = new ArrayList<>();
   inputHalf.addAll(Collections.nCopies(1000, "abc"));
   inputHalf.addAll(Collections.nCopies(1000, "def"));
   checkShortCircuitCollector(
       "suffix", "", 1001, inputHalf::stream, MoreCollectors.commonSuffix());
   List<String> inputSurrogate =
       Arrays.asList("\ud801\udc2fabc", "\ud802\udc2fabc", "\ud803\udc2fabc");
   checkShortCircuitCollector(
       "suffix",
       "abc",
       inputSurrogate.size(),
       inputSurrogate::stream,
       MoreCollectors.commonSuffix());
   List<String> inputSurrogateBad = Arrays.asList("x\udc2fabc", "y\udc2fabc", "z\udc2fabc");
   checkShortCircuitCollector(
       "suffix",
       "\udc2fabc",
       inputSurrogateBad.size(),
       inputSurrogateBad::stream,
       MoreCollectors.commonSuffix());
   List<String> inputSurrogateMix =
       Arrays.asList("\ud801\udc2fabc", "x\udc2fabc", "\ud801\udc14abc");
   checkShortCircuitCollector(
       "suffix",
       "abc",
       inputSurrogateMix.size(),
       inputSurrogateMix::stream,
       MoreCollectors.commonSuffix());
 }
Esempio n. 22
0
 public CFSM(int numProcesses, List<ChannelId> channelIds) {
   super(numProcesses, channelIds);
   fsms = Util.newList(Collections.nCopies(numProcesses, (FSM) null));
   unSpecifiedPids = numProcesses;
   firstSyntheticChIndex = Integer.MAX_VALUE;
   localEventsChIndex = Integer.MAX_VALUE;
   invs = Util.newList();
 }
  private boolean processFilesConcurrently(
      @NotNull Set<VirtualFile> files,
      @NotNull final ProgressIndicator indicator,
      @NotNull final Processor<VirtualFile> processor) {
    final List<VirtualFile> fileList = new ArrayList<VirtualFile>(files);
    // fine but grabs all CPUs
    // return JobLauncher.getInstance().invokeConcurrentlyUnderProgress(fileList, indicator, false,
    // false, processor);

    int parallelism = CacheUpdateRunner.indexingThreadCount();
    final Callable<Boolean> processFileFromSet =
        () -> {
          final boolean[] result = {true};
          ProgressManager.getInstance()
              .executeProcessUnderProgress(
                  () -> {
                    while (true) {
                      ProgressManager.checkCanceled();
                      VirtualFile file;
                      synchronized (fileList) {
                        file = fileList.isEmpty() ? null : fileList.remove(fileList.size() - 1);
                      }
                      if (file == null) {
                        break;
                      }
                      if (!processor.process(file)) {
                        result[0] = false;
                        break;
                      }
                    }
                  },
                  indicator);
          return result[0];
        };
    List<Future<Boolean>> futures =
        ContainerUtil.map(
            Collections.nCopies(parallelism, ""),
            s -> myApplication.executeOnPooledThread(processFileFromSet));

    List<Boolean> results =
        ContainerUtil.map(
            futures,
            future -> {
              try {
                return future.get();
              } catch (Exception e) {
                LOG.error(e);
              }
              return false;
            });

    return !ContainerUtil.exists(
        results,
        result -> {
          return result != null && !result; // null means PCE
        });
  }
 @Test
 public void updateValue() {
   MutableMapIterable<Integer, Integer> map = this.newMap();
   Iterate.forEach(
       Interval.oneTo(1000), each -> map.updateValue(each % 10, () -> 0, integer -> integer + 1));
   Assert.assertEquals(Interval.zeroTo(9).toSet(), map.keySet());
   Assert.assertEquals(
       FastList.newList(Collections.nCopies(10, 100)), FastList.newList(map.values()));
 }
Esempio n. 25
0
 @Test
 public void testLarge() throws Exception {
   Message m = new Message();
   // list size 80 MB
   m.l = new ArrayList<Integer>(Collections.nCopies(20 * 1024 * 1024, 1000000007));
   Message m2 = marshaller.parse(marshaller.stream(m));
   assertNotSame(m, m2);
   assertEquals(m.l.size(), m2.l.size());
 }
Esempio n. 26
0
 /**
  * Creates a record that can store the kind of data described by the supplied metadata, possibly
  * setting all the fields to the <code>null</code> value.
  *
  * @param metadata the metadata describing the data this record may hold
  * @param nullFields <code>true</code> to indicate that all fields should be set to <code>null
  *     </code>.
  * @throws NullPointerException if the supplied metadata is <code>null</code>.
  */
 public Record(RecordMetadata metadata, boolean nullFields) {
   this.metadata = new RecordMetadata(metadata.getFieldMetadata());
   this.data =
       new ArrayList<Field<? extends Serializable>>(
           Collections.nCopies(this.metadata.getFieldCount(), (Field<Serializable>) null));
   if (nullFields) {
     this.nullFields(this.getMetadata().getFieldNames());
   }
 }
Esempio n. 27
0
 /**
  * Try to pass non-existing object as uninteresting, with non-ignoring setting.
  *
  * @throws IOException
  */
 public void testNotIgnoreNonExistingObjects() throws IOException {
   final ObjectId nonExisting = ObjectId.fromString("0000000000000000000000000000000000000001");
   try {
     createVerifyOpenPack(EMPTY_LIST_OBJECT, Collections.nCopies(1, nonExisting), false, false);
     fail("Should have thrown MissingObjectException");
   } catch (MissingObjectException x) {
     // expected
   }
 }
  @Test
  public void checkOnlyOneThreadExecutesPing() throws InterruptedException, ExecutionException {
    Callable<PingResult> task = createTask();
    List<Callable<PingResult>> tasks = Collections.nCopies(3, task);
    ExecutorService executorService = Executors.newFixedThreadPool(3);
    List<Future<PingResult>> futures = executorService.invokeAll(tasks);

    assertEquals("We are fine.", futures.get(0).get().getMessage());
    assertEquals("only for initialization", futures.get(1).get().getMessage());
    assertEquals("only for initialization", futures.get(2).get().getMessage());
  }
Esempio n. 29
0
 @Test
 public void testIntersecting() {
   for (int i = 0; i < 5; i++) {
     List<List<String>> input =
         Arrays.asList(
             Arrays.asList("aa", "bb", "cc"),
             Arrays.asList("cc", "bb", "dd"),
             Arrays.asList("ee", "dd"),
             Arrays.asList("aa", "bb", "dd"));
     checkShortCircuitCollector(
         "#" + i, Collections.emptySet(), 3, input::stream, MoreCollectors.intersecting());
     List<List<Integer>> copies = new ArrayList<>(Collections.nCopies(100, Arrays.asList(1, 2)));
     checkShortCircuitCollector(
         "#" + i, StreamEx.of(1, 2).toSet(), 100, copies::stream, MoreCollectors.intersecting());
     copies.addAll(Collections.nCopies(100, Arrays.asList(3)));
     checkShortCircuitCollector(
         "#" + i, Collections.emptySet(), 101, copies::stream, MoreCollectors.intersecting());
     checkCollectorEmpty("#" + i, Collections.emptySet(), MoreCollectors.intersecting());
   }
 }
Esempio n. 30
0
 /**
  * Tells whether the hash formed by appending the given index to the given salt is a key, after
  * applying the hashing function.
  *
  * @param salt Salt.
  * @param index Index to append to the salt.
  * @param hashFunction Hashing function. Can be the MD5 or the stretched MD5 for example.
  * @return Is the hash formed with the salt and index a key?
  */
 private static boolean isKey(String salt, int index, UnaryOperator<String> hashFunction) {
   Matcher matcher = TRIPLET_PATTERN.matcher(hashFunction.apply(salt + index));
   if (matcher.find()) {
     String search = String.join("", Collections.nCopies(5, matcher.group(1)));
     for (int i = index + 1; i < index + 1001; i++) {
       if (hashFunction.apply(salt + i).indexOf(search) >= 0) {
         return true;
       }
     }
   }
   return false;
 }