io.vavr.collection.Vector.of()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(190)

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

Vector.of介绍

[英]Returns a singleton Vector, i.e. a Vector of one element.
[中]返回单个向量,即一个元素的向量。

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Vector#of(Object)}
 *
 * @param <T>     Component type of element.
 * @param element An element.
 * @return A new {@link Vector} instance containing the given element
 */
public static <T> Vector<T> Vector(T element) {
  return Vector.of(element);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Vector#of(Object)}
 *
 * @param <T>     Component type of element.
 * @param element An element.
 * @return A new {@link Vector} instance containing the given element
 */
public static <T> IndexedSeq<T> IndexedSeq(T element) {
  return Vector.of(element);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Vector#of(Object...)}
 *
 * @param <T>      Component type of elements.
 * @param elements Zero or more elements.
 * @return A new {@link Vector} instance containing the given elements
 * @throws NullPointerException if {@code elements} is null
 */
@SuppressWarnings("varargs")
@SafeVarargs
public static <T> Vector<T> Vector(T... elements) {
  return Vector.of(elements);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Vector#of(Object...)}
 *
 * @param <T>      Component type of elements.
 * @param elements Zero or more elements.
 * @return A new {@link Vector} instance containing the given elements
 * @throws NullPointerException if {@code elements} is null
 */
@SuppressWarnings("varargs")
@SafeVarargs
public static <T> IndexedSeq<T> IndexedSeq(T... elements) {
  return Vector.of(elements);
}
// -- Array

代码示例来源:origin: vavr-io/vavr

@Override
public Vector<T> sorted() {
  if (isEmpty()) {
    return this;
  } else {
    @SuppressWarnings("unchecked")
    final T[] list = (T[]) toJavaArray();
    Arrays.sort(list);
    return Vector.of(list);
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public Vector<Vector<T>> permutations() {
  if (isEmpty()) {
    return empty();
  } else if (length() == 1) {
    return of(this);
  } else {
    Vector<Vector<T>> results = empty();
    for (T t : distinct()) {
      for (Vector<T> ts : remove(t).permutations()) {
        results = results.append(of(t).appendAll(ts));
      }
    }
    return results;
  }
}

代码示例来源:origin: vavr-io/vavr

static IndexedSeq<CharSeq> apply(CharSeq elements, int k) {
    if (k == 0) {
      return Vector.of(CharSeq.empty());
    } else {
      return elements.zipWithIndex().flatMap(
          t -> apply(elements.drop(t._2 + 1), (k - 1)).map((CharSeq c) -> c.prepend(t._1))
      );
    }
  }
}

代码示例来源:origin: vavr-io/vavr

static <T> Vector<Vector<T>> apply(Vector<T> elements, int k) {
    return (k == 0)
        ? Vector.of(Vector.empty())
        : elements.zipWithIndex().flatMap(
        t -> apply(elements.drop(t._2 + 1), (k - 1)).map((Vector<T> c) -> c.prepend(t._1)));
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public IndexedSeq<CharSeq> permutations() {
  if (isEmpty()) {
    return Vector.empty();
  } else {
    if (length() == 1) {
      return Vector.of(this);
    } else {
      IndexedSeq<CharSeq> result = Vector.empty();
      for (Character t : distinct()) {
        for (CharSeq ts : remove(t).permutations()) {
          result = result.append(CharSeq.of(t).appendAll(ts));
        }
      }
      return result;
    }
  }
}

代码示例来源:origin: io.vavr/vavr

/**
 * Alias for {@link Vector#of(Object)}
 *
 * @param <T>     Component type of element.
 * @param element An element.
 * @return A new {@link Vector} instance containing the given element
 */
public static <T> IndexedSeq<T> IndexedSeq(T element) {
  return Vector.of(element);
}

代码示例来源:origin: io.vavr/vavr

/**
 * Alias for {@link Vector#of(Object)}
 *
 * @param <T>     Component type of element.
 * @param element An element.
 * @return A new {@link Vector} instance containing the given element
 */
public static <T> Vector<T> Vector(T element) {
  return Vector.of(element);
}

代码示例来源:origin: martincooper/java-datatable

/**
 * DataColumn constructor.
 *
 * @param type Stores the type of data stored in this column.
 * @param columnName The column name.
 * @param data The data items stored in the column.
 */
public DataColumn(Class<T> type, String columnName, T[] data) {
  this(type, columnName, Vector.of(data));
}

代码示例来源:origin: io.vavr/vavr

@Override
public Vector<T> sorted() {
  if (isEmpty()) {
    return this;
  } else {
    @SuppressWarnings("unchecked")
    final T[] list = (T[]) toJavaArray();
    Arrays.sort(list);
    return Vector.of(list);
  }
}

代码示例来源:origin: io.vavr/vavr

static IndexedSeq<CharSeq> apply(CharSeq elements, int k) {
    if (k == 0) {
      return Vector.of(CharSeq.empty());
    } else {
      return elements.zipWithIndex().flatMap(
          t -> apply(elements.drop(t._2 + 1), (k - 1)).map((CharSeq c) -> c.prepend(t._1))
      );
    }
  }
}

代码示例来源:origin: io.vavr/vavr

static <T> Vector<Vector<T>> apply(Vector<T> elements, int k) {
    return (k == 0)
        ? Vector.of(Vector.empty())
        : elements.zipWithIndex().flatMap(
        t -> apply(elements.drop(t._2 + 1), (k - 1)).map((Vector<T> c) -> c.prepend(t._1)));
  }
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testVectorOfString() throws Exception {
  String src0 = "A";
  String src1 = "B";
  String src2 = "C";
  Vector<String> src = Vector.of(src0, src1, src2);
  String json = MAPPER.writeValueAsString(new ParameterizedVectorPojo<>(src));
  Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
  ParameterizedVectorPojo<java.lang.String> restored = 
      MAPPER.readValue(json, new TypeReference<ParameterizedVectorPojo<java.lang.String>>(){});
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testVectorOfString() throws Exception {
  String src0 = "A";
  String src1 = "B";
  String src2 = "C";
  Vector<String> src = Vector.of(src0, src1, src2);
  String json = MAPPER.writeValueAsString(new VectorOfString().setValue(src));
  Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
  VectorOfString restored = MAPPER.readValue(json, VectorOfString.class);
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testVectorOfTuple() throws Exception {
  String src00 = "A";
  String src01 = "B";
  Tuple2<String, String> src0 = Tuple.of(src00, src01);
  Vector<Tuple2<String, String>> src = Vector.of(src0);
  String json = MAPPER.writeValueAsString(new ParameterizedVectorPojo<>(src));
  Assert.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}");
  ParameterizedVectorPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = 
      MAPPER.readValue(json, new TypeReference<ParameterizedVectorPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testVector() throws Exception {
  Vector<I> src = Vector.of(new A(), new B());
  String json = MAPPER.writeValueAsString(new VectorPojo().setValue(src));
  Assert.assertEquals(json, "{\"value\":[{\"type\":\"a\"},{\"type\":\"b\"}]}");
  VectorPojo pojo = MAPPER.readValue(json, VectorPojo.class);
  Vector<I> restored = pojo.getValue();
  Assert.assertTrue(restored.get(0) instanceof A);
  Assert.assertTrue(restored.get(1) instanceof B);
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testVector() throws Exception {
  Vector<A> src = Vector.of(new B("a", "b"));
  String json = MAPPER.writeValueAsString(new VectorPojo().setValue(src));
  Assert.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}");
  VectorPojo pojo = MAPPER.readValue(json, VectorPojo.class);
  Vector<A> restored = pojo.getValue();
  Assert.assertTrue(restored.get(0) instanceof B);
  Assert.assertEquals(restored.get(0).a, "a");
  Assert.assertEquals(((B) restored.get(0)).b, "b");
}

相关文章