fj.data.List.length()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(92)

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

List.length介绍

[英]The length of this list.
[中]此列表的长度。

代码示例

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * The length of this list.
 *
 * @return The length of this list.
 */
public int length() { return 1 + tail.length(); }

代码示例来源:origin: org.functionaljava/functionaljava

public int size() {
  return length();
 }
};

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * A function that converts lists to array blocking queue.
 *
 * @param fair The argument to pass to the constructor of the array blocking queue.
 * @return A function that converts lists to array blocking queue.
 */
public static <A> F<List<A>, ArrayBlockingQueue<A>> List_ArrayBlockingQueue(final boolean fair) {
 return as -> new ArrayBlockingQueue<>(as.length(), fair, as.toCollection());
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-model

/**
 * Practical criterion for detecting a real join: having more data/composite atoms.
 *
 * May produces some false negatives for crazy abusive nested joins of boolean atoms (using JOIN instead of AND).
 */
public static boolean isRealJoin(List<Function> subAtoms) {
  //TODO: reuse a shared static filter fct object.
  List<Function> dataAndCompositeAtoms = subAtoms.filter(new F<Function, Boolean>() {
    @Override
    public Boolean f(Function atom) {
      return isDataOrLeftJoinOrJoinAtom(atom);
    }
  });
  return dataAndCompositeAtoms.length() > 1;
}

代码示例来源:origin: org.functionaljava/functionaljava

public final boolean isSuffixOf(final Equal<A> eq, final List<A> xs) {
 final Iterator<A> i = iterator();
 final Iterator<A> j = xs.drop(xs.length() - length()).iterator();
 while (i.hasNext() && j.hasNext()) {
  if (!eq.eq(i.next(), j.next())) {
   return false;
  }
 }
 return !i.hasNext();
}

代码示例来源:origin: ontop/ontop

/**
 * All the other atoms are currently presumed to be boolean atoms
 */
private static void checkNonDataOrCompositeAtomSupport(List<Function> otherAtoms,
                            List<Function> booleanAtoms)
    throws DatalogProgram2QueryConverterImpl.NotSupportedConversionException {
  if (booleanAtoms.length() < otherAtoms.length()) {
    HashSet<Function> unsupportedAtoms = new HashSet<>(otherAtoms.toCollection());
    unsupportedAtoms.removeAll(booleanAtoms.toCollection());
    throw new DatalogProgram2QueryConverterImpl.NotSupportedConversionException(
        "Conversion of the following atoms to the intermediate query is not (yet) supported: "
            + unsupportedAtoms);
  }
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization

/**
 * All the other atoms are currently presumed to be boolean atoms
 */
private static void checkNonDataOrCompositeAtomSupport(List<Function> otherAtoms,
                            List<Function> booleanAtoms,
                            Optional<Function> optionalGroupAtom)
    throws DatalogProgram2QueryConverterImpl.NotSupportedConversionException {
  int groupCount = optionalGroupAtom.isPresent()? 1 : 0;
  if (booleanAtoms.length() + groupCount < otherAtoms.length()) {
    HashSet<Function> unsupportedAtoms = new HashSet<>(otherAtoms.toCollection());
    unsupportedAtoms.removeAll(booleanAtoms.toCollection());
    if (groupCount == 1)
      unsupportedAtoms.remove(optionalGroupAtom.get());
    throw new DatalogProgram2QueryConverterImpl.NotSupportedConversionException(
        "Conversion of the following atoms to the intermediate query is not (yet) supported: "
            + unsupportedAtoms);
  }
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns a array projection of this list.
 *
 * @param c The class type of the array to return.
 * @return A array projection of this list.
 */
@SuppressWarnings({"unchecked", "UnnecessaryFullyQualifiedName"})
public final Array<A> toArray(final Class<A[]> c) {
 final A[] a = (A[]) java.lang.reflect.Array.newInstance(c.getComponentType(), length());
 List<A> x = this;
 for (int i = 0; i < length(); i++) {
  a[i] = x.head();
  x = x.tail();
 }
 return Array.array(a);
}

代码示例来源:origin: org.functionaljava/functionaljava

public static BitSet listBitSet(final List<Boolean> list) {
  final int n = list.length();
  if (n > MAX_BIT_SIZE) {
    throw new IllegalArgumentException("Does not support lists greater than " + MAX_BIT_SIZE + " bits, actual size is " + n);
  }
  long result = 0;
  for (Boolean b: list) {
    result = (result << 1) | toInt(b);
  }
  return longBitSet(result);
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the element at the given index if it exists, fails otherwise.
 *
 * @param i The index at which to get the element to return.
 * @return The element at the given index if it exists, fails otherwise.
 */
public final A index(final int i) {
 if (i < 0 || i > length() - 1)
  throw error("index " + i + " out of range on list with length " + length());
 else {
  List<A> xs = this;
  for (int c = 0; c < i; c++) {
   xs = xs.tail();
  }
  return xs.head();
 }
}

代码示例来源:origin: org.functionaljava/functionaljava

public final Object[] toArrayObject() {
 final int length = length();
 final Object[] a = new Object[length];
 List<A> x = this;
 for (int i = 0; i < length; i++) {
  a[i] = x.head();
  x = x.tail();
 }
 return a;
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization

private static Optional<Function> extractOptionalGroupAtom(List<Function> atoms)
    throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException {
  List<Function> groupAtoms = atoms.filter(atom -> atom.getFunctionSymbol().equals(
      DatalogAlgebraOperatorPredicates.SPARQL_GROUP));
  switch(groupAtoms.length()) {
    case 0:
      return Optional.empty();
    case 1:
      return Optional.of(groupAtoms.head());
    default:
      throw new DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException("Multiple GROUP atoms found in the same body! " +
          groupAtoms);
  }
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization

/**
 * TODO: explain
 */
private static Optional<JoinOrFilterNode> createFilterOrJoinNode(IntermediateQueryFactory iqFactory,
                                 List<Function> dataAndCompositeAtoms,
                                 List<Function> booleanAtoms) {
  Optional<ImmutableExpression> optionalFilter = createFilterExpression(booleanAtoms);
  int dataAndCompositeAtomCount = dataAndCompositeAtoms.length();
  Optional<JoinOrFilterNode> optionalRootNode;
  /*
   * Filter as a root node
   */
  if (optionalFilter.isPresent() && (dataAndCompositeAtomCount == 1)) {
    optionalRootNode = Optional.of(iqFactory.createFilterNode(optionalFilter.get()));
  }
  else if (dataAndCompositeAtomCount > 1) {
    optionalRootNode = Optional.of(iqFactory.createInnerJoinNode(optionalFilter));
  }
  /*
   * No need to create a special root node (will be the unique data atom)
   */
  else {
    optionalRootNode = Optional.empty();
  }
  return optionalRootNode;
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Zips this list with the index of its element as a pair.
 *
 * @return A new list with the same length as this list.
 */
public final List<P2<A, Integer>> zipIndex() {
 return zipWith(range(0, length()), a -> i -> p(a, i));
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-model

/**
 * Folds a list of data/composite atoms and joining conditions into a JOIN(...) with a 3-arity.
 *
 */
public static Function foldJoin(List<Function> dataOrCompositeAtoms, Function joiningCondition) {
  int length = dataOrCompositeAtoms.length();
  if (length < 2) {
    throw new IllegalArgumentException("At least two atoms should be given");
  }
  Function firstAtom = dataOrCompositeAtoms.head();
  Function secondAtom = foldJoin(dataOrCompositeAtoms.tail());
  return DATALOG_FACTORY.getSPARQLJoin(firstAtom, secondAtom, joiningCondition);
}

代码示例来源:origin: ontop/ontop

/**
 * Folds a list of boolean atoms into one AND(AND(...)) boolean atom.
 */
public Expression foldBooleanConditions(List<Function> booleanAtoms) {
  if (booleanAtoms.length() == 0)
    return TRUE_EQ;
  Expression firstBooleanAtom = convertOrCastIntoBooleanAtom( booleanAtoms.head());
  return booleanAtoms.tail().foldLeft(new F2<Expression, Function, Expression>() {
    @Override
    public Expression f(Expression previousAtom, Function currentAtom) {
      return termFactory.getFunctionAND(previousAtom, currentAtom);
    }
  }, firstBooleanAtom);
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-model

/**
 * Folds a list of data/composite atoms into a JOIN (if necessary)
 * by adding EQ(t,t) as a joining condition.
 */
private static Function foldJoin(List<Function> dataOrCompositeAtoms) {
  int length = dataOrCompositeAtoms.length();
  if (length == 1)
    return dataOrCompositeAtoms.head();
  else if (length == 0)
    throw new IllegalArgumentException("At least one atom should be given.");
  else {
    Function firstAtom = dataOrCompositeAtoms.head();
    /**
     * Folds the data/composite atom list into a JOIN(JOIN(...)) meta-atom.
     */
    return dataOrCompositeAtoms.tail().foldLeft(new F2<Function, Function, Function>() {
      @Override
      public Function f(Function firstAtom, Function secondAtom) {
        return DATALOG_FACTORY.getSPARQLJoin(firstAtom, secondAtom, TRUE_EQ);
      }
    }, firstAtom);
  }
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-model

/**
 * Folds a list of boolean atoms into one AND(AND(...)) boolean atom.
 */
public static Expression foldBooleanConditions(List<Function> booleanAtoms) {
  if (booleanAtoms.length() == 0)
    return TRUE_EQ;
  Expression firstBooleanAtom = convertOrCastIntoBooleanAtom( booleanAtoms.head());
  return booleanAtoms.tail().foldLeft(new F2<Expression, Function, Expression>() {
    @Override
    public Expression f(Expression previousAtom, Function currentAtom) {
      return TERM_FACTORY.getFunctionAND(previousAtom, currentAtom);
    }
  }, firstBooleanAtom);
}

代码示例来源:origin: novarto-oss/sane-dbc

@Test
public void iterableBinder()
{
  List<P2<String, String>> data = arrayList(p("x1", "y1"), p("x2", "y2"), p("x3", "y3"));
  String sql = format(
      "INSERT INTO MySqlTest_FOO(X,Y) VALUES ({0})",
      SqlStringUtils.placeholderRows(data.length(), 2)
  );
  UpdateOp insert = new UpdateOp(
      sql,
      Binders.iterableBinder((pos, ps, x) -> {
        int currentPosition = pos;
        ps.setString(currentPosition++, x._1());
        ps.setString(currentPosition++, x._2());
        return currentPosition;
      }, data)
  );
  int updateCount = DB.transact(insert);
  assertThat(updateCount, is(3));
  List<P2<String, String>> readData = DB.submit(new SelectOp.FjList<>("SELECT X,Y FROM MySqlTest_FOO", NO_BINDER,
      rs -> p(rs.getString(1), rs.getString(2))));
  assertThat(readData, is(data));
}

代码示例来源:origin: org.functionaljava/functionaljava

final P2<List<A>, List<A>> s = splitAt(length() / 2);
return new Merge().merge(s._1().sort(o), s._2().sort(o), o);

相关文章