congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
HollowSchemaParser
Code IndexAdd Tabnine to your IDE (free)

How to use
HollowSchemaParser
in
com.netflix.hollow.core.schema

Best Java code snippets using com.netflix.hollow.core.schema.HollowSchemaParser (Showing top 20 results out of 315)

origin: Netflix/hollow

/**
 * Parse a collection of {@link HollowSchema}s from the provided String.
 *
 * @param schemas the schemas as a string
 * @return the list of schema
 * @throws IOException if the schema cannot be parsed
 */
public static List<HollowSchema> parseCollectionOfSchemas(String schemas) throws IOException {
  return parseCollectionOfSchemas(new StringReader(schemas));
}
origin: Netflix/hollow

/**
 * Parse a single {@link HollowSchema} from the provided String.
 *
 * @param schema the schema as a string
 * @return the schema
 * @throws IOException if the schema cannot be parsed
 */
public static HollowSchema parseSchema(String schema) throws IOException {
  StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(schema));
  configureTokenizer(tokenizer);
  return parseSchema(tokenizer);
}
origin: Netflix/hollow

private static HollowSetSchema parseSetSchema(String typeName, StreamTokenizer tokenizer) throws IOException {
  int tok = tokenizer.nextToken();
  if(tokenizer.ttype != '<')
    throw new IOException("Invalid Syntax: Expected '<' after 'Set' for type " + typeName);
  tok = tokenizer.nextToken();
  if(tok != StreamTokenizer.TT_WORD) {
    log.warning("Invalid Syntax: Expected element type declaration: " + typeName);
  }
  String elementType = tokenizer.sval;
  tok = tokenizer.nextToken();
  if(tokenizer.ttype != '>')
    throw new IOException("Invalid Syntax: Expected '>' element type declaration: " + typeName);
  tok = tokenizer.nextToken();
  String hashKeyPaths[] = parseHashKey(tokenizer);
  if(tokenizer.ttype != ';')
    throw new IOException("Invalid Syntax: Expected semicolon after Set schema declaration: " + typeName);
  return new HollowSetSchema(typeName, elementType, hashKeyPaths);
}
origin: Netflix/hollow

private static HollowSchema parseSchema(StreamTokenizer tokenizer) throws IOException {
  int tok = tokenizer.nextToken();
  while(tok != StreamTokenizer.TT_WORD) {
    if(tok == StreamTokenizer.TT_EOF)
      return null;
    tok = tokenizer.nextToken();
  }
  String typeName = tokenizer.sval;
  tok = tokenizer.nextToken();
  if(tok == StreamTokenizer.TT_WORD) {
    if("List".equals(tokenizer.sval)) {
      return parseListSchema(typeName, tokenizer);
    } else if("Set".equals(tokenizer.sval)) {
      return parseSetSchema(typeName, tokenizer);
    } else if("Map".equals(tokenizer.sval)) {
      return parseMapSchema(typeName, tokenizer);
    } else {
      throw new IOException("Invalid syntax: expected one of '{', 'List', 'Set', or 'Map' after type declaration for '" + typeName + "'");
    }
  }
  return parseObjectSchema(typeName, tokenizer);
}
origin: Netflix/hollow

@Test
public void parsesListSchema() throws IOException {
  String listSchema = "ListOfTypeA List<TypeA>;\n";
  HollowListSchema schema = (HollowListSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("ListOfTypeA", schema.getName());
  Assert.assertEquals("TypeA", schema.getElementType());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
origin: Netflix/hollow

private static String[] parseHashKey(StreamTokenizer tokenizer) throws IOException {
  return parseKeyFieldPaths(tokenizer, "HashKey");
}
origin: Netflix/hollow

private static HollowObjectSchema parseObjectSchema(String typeName, StreamTokenizer tokenizer) throws IOException {
  String keyFieldPaths[] = parsePrimaryKey(tokenizer);
  if (tokenizer.ttype != '{') {
    throw new IOException("Invalid syntax: expecting '{' for '" + typeName + "'");
origin: Netflix/hollow

@Test
public void parsesSetSchema() throws IOException {
  String listSchema = "SetOfTypeA Set<TypeA>;\n";
  HollowSetSchema schema = (HollowSetSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("SetOfTypeA", schema.getName());
  Assert.assertEquals("TypeA", schema.getElementType());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
origin: Netflix/hollow

private static String[] parsePrimaryKey(StreamTokenizer tokenizer) throws IOException {
  return parseKeyFieldPaths(tokenizer, "PrimaryKey");
}
origin: Netflix/hollow

@Test
public void parsesMapSchema() throws IOException {
  String listSchema = "MapOfStringToTypeA Map<String, TypeA>;\n";
  HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("MapOfStringToTypeA", schema.getName());
  Assert.assertEquals("String", schema.getKeyType());
  Assert.assertEquals("TypeA", schema.getValueType());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
origin: Netflix/hollow

/**
 * Reads a schema file into the provided HollowWriteStateEngine. The schema file must be on the classpath.
 *
 * @param schemaFilePath the path to the schema
 * @param engine the write state engine
 * @throws IOException if the schema could not be read
 */
public static void readSchemaFileIntoWriteState(String schemaFilePath, HollowWriteStateEngine engine)
    throws IOException {
  InputStream input = null;
  try {
    input = HollowWriteStateCreator.class.getClassLoader().getResourceAsStream(schemaFilePath);
    Collection<HollowSchema> schemas =
      HollowSchemaParser.parseCollectionOfSchemas(new BufferedReader(new InputStreamReader(input)));
    populateStateEngineWithTypeWriteStates(engine, schemas);
  } finally {
    if (input != null) {
      input.close();
    }
  }
}
origin: Netflix/hollow

/**
 * Parse a collection of {@link HollowSchema}s from the provided Reader.
 *
 * @param reader the reader
 * @return the list of schema
 * @throws IOException if the schema cannot be parsed
 */
public static List<HollowSchema> parseCollectionOfSchemas(Reader reader) throws IOException {
  StreamTokenizer tokenizer = new StreamTokenizer(reader);
  configureTokenizer(tokenizer);
  List<HollowSchema> schemaList = new ArrayList<HollowSchema>();
  HollowSchema schema = parseSchema(tokenizer);
  while (schema != null) {
    schemaList.add(schema);
    schema = parseSchema(tokenizer);
  }
  return schemaList;
}
origin: Netflix/hollow

private static HollowMapSchema parseMapSchema(String typeName, StreamTokenizer tokenizer) throws IOException {
  int tok = tokenizer.nextToken();
  if(tokenizer.ttype != '<')
    throw new IOException("Invalid Syntax: Expected '<' after 'Map' for type " + typeName);
  tok = tokenizer.nextToken();
  if(tok != StreamTokenizer.TT_WORD) {
    log.warning("Invalid Syntax: Expected element type declaration: " + typeName);
  }
  String keyType = tokenizer.sval;
  tok = tokenizer.nextToken();
  if(tokenizer.ttype != ',')
    throw new IOException("Invalid Syntax: Expected ',' after key type declaration: " + typeName);
  tok = tokenizer.nextToken();
  if(tok != StreamTokenizer.TT_WORD) {
    log.warning("Invalid Syntax: Expected value type declaration: " + typeName);
  }
  String valueType = tokenizer.sval;
  tok = tokenizer.nextToken();
  if(tokenizer.ttype != '>')
    throw new IOException("Invalid Syntax: Expected '>' after value type declaration: " + typeName);
  tok = tokenizer.nextToken();
  String hashKeyPaths[] = parseHashKey(tokenizer);
  if(tokenizer.ttype != ';')
    throw new IOException("Invalid Syntax: Expected semicolon after Map schema declaration: " + typeName);
  return new HollowMapSchema(typeName, keyType, valueType, hashKeyPaths);
}
origin: Netflix/hollow

@Test
public void parsesSetSchemaWithMultiFieldKey() throws IOException {
  String listSchema = "SetOfTypeA Set<TypeA> @HashKey(id.value, region.country.id, key);\n";
  HollowSetSchema schema = (HollowSetSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("SetOfTypeA", schema.getName());
  Assert.assertEquals("TypeA", schema.getElementType());
  Assert.assertEquals(new PrimaryKey("TypeA", "id.value", "region.country.id", "key"), schema.getHashKey());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
origin: Netflix/hollow

@Test
public void parsesManySchemas() throws IOException {
  String manySchemas =
      "/* This is a comment\n" +
          "   consisting of multiple lines */\n" +
          " TypeA {\n" +
          "    int a1;\n" +
          "    \tstring a2; //This is a comment\n" +
          "    String a3;\n" +
          "}\n\n"+
          "MapOfStringToTypeA Map<String, TypeA>;\n"+
          "ListOfTypeA List<TypeA>;\n"+
          "TypeB { float b1; double b2; boolean b3; }";
  List<HollowSchema> schemas = HollowSchemaParser.parseCollectionOfSchemas(manySchemas);
  Assert.assertEquals(4, schemas.size());
}
origin: Netflix/hollow

@Test
public void parsesSetSchemaWithKey() throws IOException {
  String listSchema = "SetOfTypeA Set<TypeA> @HashKey(id.value);\n";
  HollowSetSchema schema = (HollowSetSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("SetOfTypeA", schema.getName());
  Assert.assertEquals("TypeA", schema.getElementType());
  Assert.assertEquals(new PrimaryKey("TypeA", "id.value"), schema.getHashKey());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
origin: Netflix/hollow

  @Test
  public void testParseCollectionOfSchemas_reader() throws Exception {
    InputStream input = null;
    try {
      input = getClass().getResourceAsStream("/schema1.txt");
      List<HollowSchema> schemas =
          HollowSchemaParser.parseCollectionOfSchemas(new BufferedReader(new InputStreamReader(input)));
      Assert.assertEquals("Should have two schemas", 2, schemas.size());
      Assert.assertEquals("Should have Minion schema", "Minion", schemas.get(0).getName());
      Assert.assertEquals("Should have String schema", "String", schemas.get(1).getName());
    } finally {
      if (input != null) {
        input.close();
      }
    }
  }
}
origin: Netflix/hollow

@Test
public void parsesMapSchemaWithMultiFieldPrimaryKey() throws IOException {
  String listSchema = "MapOfStringToTypeA Map<String, TypeA> @HashKey(id.value, region.country.id, key);\n";
  HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("MapOfStringToTypeA", schema.getName());
  Assert.assertEquals("String", schema.getKeyType());
  Assert.assertEquals("TypeA", schema.getValueType());
  Assert.assertEquals(new PrimaryKey("String", "id.value", "region.country.id", "key"), schema.getHashKey());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
origin: Netflix/hollow

@Test
public void sortsSchemasEvenIfDependencyTypesNotPresent() throws IOException {
  String schemasText = "TypeA { TypeB b; }"
            + "TypeB { TypeC c; }";
  
  
  List<HollowSchema> schemas = HollowSchemaParser.parseCollectionOfSchemas(schemasText);
  
  List<HollowSchema> sortedSchemas = HollowSchemaSorter.dependencyOrderedSchemaList(schemas);
  Assert.assertEquals(2, sortedSchemas.size());
  Assert.assertEquals("TypeB", sortedSchemas.get(0).getName());
  Assert.assertEquals("TypeA", sortedSchemas.get(1).getName());
}

origin: Netflix/hollow

@Test
public void parsesMapSchemaWithPrimaryKey() throws IOException {
  String listSchema = "MapOfStringToTypeA Map<String, TypeA> @HashKey(value);\n";
  HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema);
  Assert.assertEquals("MapOfStringToTypeA", schema.getName());
  Assert.assertEquals("String", schema.getKeyType());
  Assert.assertEquals("TypeA", schema.getValueType());
  Assert.assertEquals(new PrimaryKey("String", "value"), schema.getHashKey());
  Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString()));
}
com.netflix.hollow.core.schemaHollowSchemaParser

Javadoc

Parses text representations of HollowSchema.

The text representations are the same format obtained via toString() on a HollowSchema.

Most used methods

  • parseCollectionOfSchemas
    Parse a collection of HollowSchemas from the provided String.
  • parseSchema
    Parse a single HollowSchema from the provided String.
  • configureTokenizer
  • parseHashKey
  • parseKeyFieldPaths
  • parseListSchema
  • parseMapSchema
  • parseObjectSchema
  • parsePrimaryKey
  • parseSetSchema

Popular in Java

  • Finding current android device location
  • requestLocationUpdates (LocationManager)
  • addToBackStack (FragmentTransaction)
  • putExtra (Intent)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now