Package com.google.gson

Examples of com.google.gson.GsonBuilder.create()


    Type matrixType = new TypeToken<Matrix>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    builder.registerTypeAdapter(matrixType, new JsonMatrixAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, matrixType);
  }

  public Matrix assign(double value) {
    int[] c = size();
View Full Code Here


  public static Vector decodeVector(String formattedString) {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    return gson.fromJson(formattedString, vectorType);
  }

  public String getName() {
    return name;
View Full Code Here

  public String asFormatString() {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, vectorType);
  }

  /**
   * Compare whether two Vector implementations have the same elements, regardless of the implementation and name. Two
View Full Code Here

    String format = model.asFormatString(null);
    assertEquals("format", "nm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    NormalModel model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }

  public void testDirichletSampledNormalModel() {
View Full Code Here

    String format = model.asFormatString(null);
    assertEquals("format", "snm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    SampledNormalModel model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }

  public void testDirichletASNormalModel() {
View Full Code Here

    String format = model.asFormatString(null);
    assertEquals("format", "asnm{n=0 m=[1.100, 2.200, 3.300] sd=[1.100, 2.200, 3.300]}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    AsymmetricSampledNormalModel model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }

  public void testDirichletL1Model() {
View Full Code Here

    String format = model.asFormatString(null);
    assertEquals("format", "l1m{n=0 c=[1.100, 2.200, 3.300]}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    L1Model model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }

  public void testDirichletNormalModelClusterAsFormatString() {
View Full Code Here

    NormalModel model = new NormalModel(m, 0.75);
    Printable cluster = new DirichletCluster<VectorWritable>(model, 35.0);
    String json = cluster.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    DirichletCluster<VectorWritable> result = gson.fromJson(json, clusterType);
    assertNotNull("result null", result);
    assertEquals("model", cluster.asFormatString(null), result.asFormatString(null));
  }
View Full Code Here

    Printable cluster = new DirichletCluster<VectorWritable>(model, 35.0);
    String json = cluster.asJsonString();

    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    DirichletCluster<VectorWritable> result = gson.fromJson(json, clusterType);
    assertNotNull("result null", result);
    assertEquals("model", cluster.asFormatString(null), result.asFormatString(null));
  }
View Full Code Here

    Printable cluster = new DirichletCluster<VectorWritable>(model, 35.0);
    String json = cluster.asJsonString();

    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    DirichletCluster<VectorWritable> result = gson.fromJson(json, clusterType);
    assertNotNull("result null", result);
    assertEquals("model", cluster.asFormatString(null), result.asFormatString(null));
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.