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

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

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

BitSet.stream介绍

暂无

代码示例

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

@Override public List<BitSet> doShrink(SourceOfRandomness random, BitSet larger) {
  if (larger.length() == 0)
    return emptyList();
  List<BitSet> shrinks = new ArrayList<>();
  shrinks.addAll(larger.stream()
    .mapToObj(i -> larger.get(0, i))
    .collect(toList()));
  shrinks.addAll(larger.stream()
    .mapToObj(i -> {
      BitSet smaller = (BitSet) larger.clone();
      smaller.clear(i);
      return smaller;
    })
    .collect(toList()));
  return shrinks;
}

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

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

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

@Override
public IntStream intStream() {
 return bitSet.stream();
}

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

public void verifyRequiredAttributes( BitSet required )
  {
    if ( required.cardinality() != 0 )
    {
      throw new IllegalArgumentException( required.stream().mapToObj( ( i ) -> attributes[i].name ).collect(
          Collectors.joining( ", ", "Missing required attributes: ", "" ) ) );
    }
  }
}

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

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

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

private void consumeIds(List<Integer> target, int size, BitSet source, BitSet consumed) {
  target.clear();
  source.stream().limit( size ).forEach( target::add );
  ListIterator<Integer> iterator = target.listIterator();
  while ( iterator.hasNext() ) {
    int index = iterator.next();
    iterator.set( threadIdIntervalFirst + index );
    source.clear( index );
    consumed.set( index );
  }
}

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

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

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

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

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

@Override public List<BitSet> doShrink(SourceOfRandomness random, BitSet larger) {
  if (larger.length() == 0)
    return emptyList();
  List<BitSet> shrinks = new ArrayList<>();
  shrinks.addAll(larger.stream()
    .mapToObj(i -> larger.get(0, i))
    .collect(toList()));
  shrinks.addAll(larger.stream()
    .mapToObj(i -> {
      BitSet smaller = (BitSet) larger.clone();
      smaller.clear(i);
      return smaller;
    })
    .collect(toList()));
  return shrinks;
}

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

public static int nextStall(BitSet bs) {
  // Find the position of the stall (or wall)
  // For which the next stall/wall is the most distant
  // bs.stream() returns stream of positions of the set bits
  int pos = bs.stream().boxed()
        .max(Comparator.comparingInt(v -> bs.nextSetBit(v+1) - v)).get();
  // Return the middle position in the gap
  return (pos+bs.nextSetBit(pos+1))/2;
}

public static void printStalls(BitSet bs) {
  // Iterate over all the bit positions except the walls
  // walls have positions 0 and bs.length()
  System.out.println(IntStream.range(1, bs.length() - 1)
      .mapToObj(idx -> bs.get(idx) ? "X" : "_").collect(Collectors.joining()));
}

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

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

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

public static <E> Set<Set<E>> getAllCombinations(Collection<E> inputSet) {
  // use inputSet.stream().distinct().collect(Collectors.toList());
  // to get only distinct combinations
  //  (in case source contains duplicates, i.e. is not a Set)
  List<E> input = new ArrayList<>(inputSet);
  final int size = input.size();
  // sort out input that is too large. In fact, even lower numbers might
  // be way too large. But using <63 bits allows to use long values
  if(size>=63) throw new OutOfMemoryError("not enough memory for "
    +BigInteger.ONE.shiftLeft(input.size()).subtract(BigInteger.ONE)+" permutations");

  // the actual operation is quite compact when using the Stream API
  return LongStream.range(1, 1L<<size) /* .parallel() */
    .mapToObj(l -> BitSet.valueOf(new long[] {l}).stream()
      .mapToObj(input::get).collect(Collectors.toSet()))
    .collect(Collectors.toSet());
}

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

public static void permuteSubsequence(String s) {
  if(s.isEmpty()) {
    System.out.println();
    return;
  }
  String lower = s.toLowerCase(), upper = s.toUpperCase();
  if(s.length()!=lower.length() || s.length()!=upper.length())
    throw new UnsupportedOperationException("non trivial case mapping");
  LongStream.range(0, 1L<<Math.min(lower.length(), 62))
    .mapToObj(l -> {
      StringBuilder sb=new StringBuilder(lower);
      BitSet.valueOf(new long[] { l }).stream()
         .forEach(ix -> sb.setCharAt(ix, upper.charAt(ix)));
      return sb.toString();
    })
    .forEach(System.out::println);
}

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

static PartialCollector<ObjIntBox<BitSet>, boolean[]> booleanArray() {
  return new PartialCollector<>(() -> new ObjIntBox<>(new BitSet(), 0), (box1, box2) -> {
    box2.a.stream().forEach(i -> box1.a.set(i + box1.b));
    box1.b = StrictMath.addExact(box1.b, box2.b);
  }, box -> {
    boolean[] res = new boolean[box.b];
    box.a.stream().forEach(i -> res[i] = true);
    return res;
  }, NO_CHARACTERISTICS);
}

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

boolean[] bitSetToArray(BitSet bs, int width) {
  boolean[] result = new boolean[width]; // all false
  bs.stream().forEach(i -> result[i] = true);
  return result;
}

List<boolean[]> bool(int n) {
  return IntStream.range(0, (int)Math.pow(2, n))
    .mapToObj(i -> bitSetToArray(BitSet.valueOf(new long[] { i }), n))
    .collect(toList());
}

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

/**
 * Returns an {@code IntStreamEx} of indices for which the specified
 * {@link BitSet} contains a bit in the set state. The indices are returned
 * in order, from lowest to highest. The size of the stream is the number of
 * bits in the set state, equal to the value returned by the
 * {@link BitSet#cardinality()} method.
 *
 * <p>
 * The bit set must remain constant during the execution of the terminal
 * stream operation. Otherwise, the result of the terminal stream operation
 * is undefined.
 *
 * @param bitSet a {@link BitSet} to produce the stream from
 * @return a stream of integers representing set indices
 * @see BitSet#stream()
 */
public static IntStreamEx of(BitSet bitSet) {
  return seq(bitSet.stream());
}

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

public static void permuteSubsequence(String s) {
  int[] permutable = IntStream.range(0, s.length())
    .filter(i->Character.toLowerCase(s.charAt(i))!=Character.toUpperCase(s.charAt(i)))
    .toArray();
  if(permutable.length == 0) {
    System.out.println(s);
    return;
  }
  String lower = s.toLowerCase(), upper = s.toUpperCase();
  if(s.length()!=lower.length() || s.length()!=upper.length())
    throw new UnsupportedOperationException("non trivial case mapping");
  LongStream.range(0, 1L<<Math.min(permutable.length, 62))
    .mapToObj(l -> {
      StringBuilder sb=new StringBuilder(lower);
      BitSet.valueOf(new long[] { l }).stream()
         .map(bit -> permutable[bit])
         .forEach(ix -> sb.setCharAt(ix, upper.charAt(ix)));
      return sb.toString();
    })
    .forEach(System.out::println);
}

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

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

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

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

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

/**
 * Updates the outputs references of a replicate operator to points to the valid parents.
 * @param replicateToOutputs where the replicate operators are stored with its valid parents.
 * @param newOutputs the valid parents of replicate operator.
 */
private void cleanup(Map<Mutable<ILogicalOperator>, BitSet> replicateToOutputs,
    List<Pair<Mutable<ILogicalOperator>, Boolean>> newOutputs) {
  replicateToOutputs.forEach((repRef, allOutputs) -> {
    newOutputs.clear();
    // get the indexes that are set in the BitSet
    allOutputs.stream().forEach(outIndex -> {
      newOutputs.add(new Pair<>(((AbstractReplicateOperator) repRef.getValue()).getOutputs().get(outIndex),
          ((AbstractReplicateOperator) repRef.getValue()).getOutputMaterializationFlags()[outIndex]));
    });
    ((AbstractReplicateOperator) repRef.getValue()).setOutputs(newOutputs);
  });
}

相关文章