java.util.BitSet.stream()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中java.util.BitSet.stream()方法的一些代码示例,展示了BitSet.stream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet.stream()方法的具体详情如下:
包路径:java.util.BitSet
类名称:BitSet
方法名:stream

BitSet.stream介绍

暂无

代码示例

代码示例来源:origin: pholser/junit-quickcheck

  1. @Override public List<BitSet> doShrink(SourceOfRandomness random, BitSet larger) {
  2. if (larger.length() == 0)
  3. return emptyList();
  4. List<BitSet> shrinks = new ArrayList<>();
  5. shrinks.addAll(larger.stream()
  6. .mapToObj(i -> larger.get(0, i))
  7. .collect(toList()));
  8. shrinks.addAll(larger.stream()
  9. .mapToObj(i -> {
  10. BitSet smaller = (BitSet) larger.clone();
  11. smaller.clear(i);
  12. return smaller;
  13. })
  14. .collect(toList()));
  15. return shrinks;
  16. }

代码示例来源:origin: spring-projects/spring-integration

  1. /**
  2. * Set the file permissions after uploading, e.g. 0600 for
  3. * owner read/write. Only applies to file systems that support posix
  4. * file permissions.
  5. * @param chmod the permissions.
  6. * @throws IllegalArgumentException if the value is higher than 0777.
  7. * @since 5.0
  8. */
  9. public void setChmod(int chmod) {
  10. Assert.isTrue(chmod >= 0 && chmod <= 0777, // NOSONAR permissions octal
  11. "'chmod' must be between 0 and 0777 (octal)");
  12. if (!FileUtils.IS_POSIX) {
  13. this.logger.error("'chmod' setting ignored - the file system does not support Posix attributes");
  14. return;
  15. }
  16. BitSet bits = BitSet.valueOf(new byte[] { (byte) chmod, (byte) (chmod >> 8) }); // NOSONAR
  17. this.permissions = bits.stream()
  18. .boxed()
  19. .map((b) -> POSIX_FILE_PERMISSIONS[b])
  20. .collect(Collectors.toSet());
  21. }

代码示例来源:origin: org.infinispan/infinispan-commons

  1. @Override
  2. public IntStream intStream() {
  3. return bitSet.stream();
  4. }

代码示例来源:origin: org.opencypher/grammar

  1. public void verifyRequiredAttributes( BitSet required )
  2. {
  3. if ( required.cardinality() != 0 )
  4. {
  5. throw new IllegalArgumentException( required.stream().mapToObj( ( i ) -> attributes[i].name ).collect(
  6. Collectors.joining( ", ", "Missing required attributes: ", "" ) ) );
  7. }
  8. }
  9. }

代码示例来源:origin: stackoverflow.com

  1. BitSet primes = genPrimes(1000); // generate primes up to 1000
  2. System.out.println(primes.cardinality()); // print number of primes
  3. // print all primes like {2, 3, 5, ...}
  4. System.out.println(primes);
  5. // print all primes one per line
  6. for(int prime = primes.nextSetBit(0); prime >= 0; prime = primes.nextSetBit(prime+1))
  7. System.out.println(prime);
  8. // print all primes one per line using java 8:
  9. primes.stream().forEach(System.out::println);

代码示例来源:origin: hibernate/hibernate-search

  1. private void consumeIds(List<Integer> target, int size, BitSet source, BitSet consumed) {
  2. target.clear();
  3. source.stream().limit( size ).forEach( target::add );
  4. ListIterator<Integer> iterator = target.listIterator();
  5. while ( iterator.hasNext() ) {
  6. int index = iterator.next();
  7. iterator.set( threadIdIntervalFirst + index );
  8. source.clear( index );
  9. consumed.set( index );
  10. }
  11. }

代码示例来源:origin: org.springframework.shell/spring-shell-core

  1. public List<String> wordsUsed(List<String> words) {
  2. return wordsUsed.stream().mapToObj(index -> words.get(index)).collect(Collectors.toList());
  3. }

代码示例来源:origin: org.springframework.shell/spring-shell-core

  1. public List<String> wordsUsedForValue(List<String> words) {
  2. return wordsUsedForValue.stream().mapToObj(index -> words.get(index)).collect(Collectors.toList());
  3. }

代码示例来源:origin: com.pholser/junit-quickcheck-generators

  1. @Override public List<BitSet> doShrink(SourceOfRandomness random, BitSet larger) {
  2. if (larger.length() == 0)
  3. return emptyList();
  4. List<BitSet> shrinks = new ArrayList<>();
  5. shrinks.addAll(larger.stream()
  6. .mapToObj(i -> larger.get(0, i))
  7. .collect(toList()));
  8. shrinks.addAll(larger.stream()
  9. .mapToObj(i -> {
  10. BitSet smaller = (BitSet) larger.clone();
  11. smaller.clear(i);
  12. return smaller;
  13. })
  14. .collect(toList()));
  15. return shrinks;
  16. }

代码示例来源:origin: stackoverflow.com

  1. public static int nextStall(BitSet bs) {
  2. // Find the position of the stall (or wall)
  3. // For which the next stall/wall is the most distant
  4. // bs.stream() returns stream of positions of the set bits
  5. int pos = bs.stream().boxed()
  6. .max(Comparator.comparingInt(v -> bs.nextSetBit(v+1) - v)).get();
  7. // Return the middle position in the gap
  8. return (pos+bs.nextSetBit(pos+1))/2;
  9. }
  10. public static void printStalls(BitSet bs) {
  11. // Iterate over all the bit positions except the walls
  12. // walls have positions 0 and bs.length()
  13. System.out.println(IntStream.range(1, bs.length() - 1)
  14. .mapToObj(idx -> bs.get(idx) ? "X" : "_").collect(Collectors.joining()));
  15. }

代码示例来源:origin: stackoverflow.com

  1. public static List<Integer> primesBest(int max) {
  2. BitSet prime=new BitSet();
  3. prime.set(1, max>>1);
  4. for(int i=3; i<max; i+=2)
  5. if(prime.get((i-1)>>1))
  6. for(int b=i*3; b<max; b+=i*2) prime.clear((b-1)>>1);
  7. return IntStream.concat( IntStream.of(2),
  8. prime.stream().map(i->i+i+1)).boxed().collect(Collectors.toList());
  9. }

代码示例来源:origin: stackoverflow.com

  1. public static <E> Set<Set<E>> getAllCombinations(Collection<E> inputSet) {
  2. // use inputSet.stream().distinct().collect(Collectors.toList());
  3. // to get only distinct combinations
  4. // (in case source contains duplicates, i.e. is not a Set)
  5. List<E> input = new ArrayList<>(inputSet);
  6. final int size = input.size();
  7. // sort out input that is too large. In fact, even lower numbers might
  8. // be way too large. But using <63 bits allows to use long values
  9. if(size>=63) throw new OutOfMemoryError("not enough memory for "
  10. +BigInteger.ONE.shiftLeft(input.size()).subtract(BigInteger.ONE)+" permutations");
  11. // the actual operation is quite compact when using the Stream API
  12. return LongStream.range(1, 1L<<size) /* .parallel() */
  13. .mapToObj(l -> BitSet.valueOf(new long[] {l}).stream()
  14. .mapToObj(input::get).collect(Collectors.toSet()))
  15. .collect(Collectors.toSet());
  16. }

代码示例来源:origin: stackoverflow.com

  1. public static void permuteSubsequence(String s) {
  2. if(s.isEmpty()) {
  3. System.out.println();
  4. return;
  5. }
  6. String lower = s.toLowerCase(), upper = s.toUpperCase();
  7. if(s.length()!=lower.length() || s.length()!=upper.length())
  8. throw new UnsupportedOperationException("non trivial case mapping");
  9. LongStream.range(0, 1L<<Math.min(lower.length(), 62))
  10. .mapToObj(l -> {
  11. StringBuilder sb=new StringBuilder(lower);
  12. BitSet.valueOf(new long[] { l }).stream()
  13. .forEach(ix -> sb.setCharAt(ix, upper.charAt(ix)));
  14. return sb.toString();
  15. })
  16. .forEach(System.out::println);
  17. }

代码示例来源:origin: one.util/streamex

  1. static PartialCollector<ObjIntBox<BitSet>, boolean[]> booleanArray() {
  2. return new PartialCollector<>(() -> new ObjIntBox<>(new BitSet(), 0), (box1, box2) -> {
  3. box2.a.stream().forEach(i -> box1.a.set(i + box1.b));
  4. box1.b = StrictMath.addExact(box1.b, box2.b);
  5. }, box -> {
  6. boolean[] res = new boolean[box.b];
  7. box.a.stream().forEach(i -> res[i] = true);
  8. return res;
  9. }, NO_CHARACTERISTICS);
  10. }

代码示例来源:origin: stackoverflow.com

  1. boolean[] bitSetToArray(BitSet bs, int width) {
  2. boolean[] result = new boolean[width]; // all false
  3. bs.stream().forEach(i -> result[i] = true);
  4. return result;
  5. }
  6. List<boolean[]> bool(int n) {
  7. return IntStream.range(0, (int)Math.pow(2, n))
  8. .mapToObj(i -> bitSetToArray(BitSet.valueOf(new long[] { i }), n))
  9. .collect(toList());
  10. }

代码示例来源:origin: one.util/streamex

  1. /**
  2. * Returns an {@code IntStreamEx} of indices for which the specified
  3. * {@link BitSet} contains a bit in the set state. The indices are returned
  4. * in order, from lowest to highest. The size of the stream is the number of
  5. * bits in the set state, equal to the value returned by the
  6. * {@link BitSet#cardinality()} method.
  7. *
  8. * <p>
  9. * The bit set must remain constant during the execution of the terminal
  10. * stream operation. Otherwise, the result of the terminal stream operation
  11. * is undefined.
  12. *
  13. * @param bitSet a {@link BitSet} to produce the stream from
  14. * @return a stream of integers representing set indices
  15. * @see BitSet#stream()
  16. */
  17. public static IntStreamEx of(BitSet bitSet) {
  18. return seq(bitSet.stream());
  19. }

代码示例来源:origin: stackoverflow.com

  1. public static void permuteSubsequence(String s) {
  2. int[] permutable = IntStream.range(0, s.length())
  3. .filter(i->Character.toLowerCase(s.charAt(i))!=Character.toUpperCase(s.charAt(i)))
  4. .toArray();
  5. if(permutable.length == 0) {
  6. System.out.println(s);
  7. return;
  8. }
  9. String lower = s.toLowerCase(), upper = s.toUpperCase();
  10. if(s.length()!=lower.length() || s.length()!=upper.length())
  11. throw new UnsupportedOperationException("non trivial case mapping");
  12. LongStream.range(0, 1L<<Math.min(permutable.length, 62))
  13. .mapToObj(l -> {
  14. StringBuilder sb=new StringBuilder(lower);
  15. BitSet.valueOf(new long[] { l }).stream()
  16. .map(bit -> permutable[bit])
  17. .forEach(ix -> sb.setCharAt(ix, upper.charAt(ix)));
  18. return sb.toString();
  19. })
  20. .forEach(System.out::println);
  21. }

代码示例来源:origin: stackoverflow.com

  1. builder.append(other.builder);
  2. repeated.or(other.repeated);
  3. other.seen.stream().forEach(c -> (seen.get(c)? repeated: seen).set(c));
  4. return this;

代码示例来源:origin: bedatadriven/activityinfo

  1. private List<Integer> toList(BitSet bitSet) {
  2. return bitSet.stream().boxed().collect(Collectors.toList());
  3. }

代码示例来源:origin: apache/asterixdb

  1. /**
  2. * Updates the outputs references of a replicate operator to points to the valid parents.
  3. * @param replicateToOutputs where the replicate operators are stored with its valid parents.
  4. * @param newOutputs the valid parents of replicate operator.
  5. */
  6. private void cleanup(Map<Mutable<ILogicalOperator>, BitSet> replicateToOutputs,
  7. List<Pair<Mutable<ILogicalOperator>, Boolean>> newOutputs) {
  8. replicateToOutputs.forEach((repRef, allOutputs) -> {
  9. newOutputs.clear();
  10. // get the indexes that are set in the BitSet
  11. allOutputs.stream().forEach(outIndex -> {
  12. newOutputs.add(new Pair<>(((AbstractReplicateOperator) repRef.getValue()).getOutputs().get(outIndex),
  13. ((AbstractReplicateOperator) repRef.getValue()).getOutputMaterializationFlags()[outIndex]));
  14. });
  15. ((AbstractReplicateOperator) repRef.getValue()).setOutputs(newOutputs);
  16. });
  17. }

相关文章