Package com.linkedin.data

Examples of com.linkedin.data.DataMap


    {
      adds.add(new StringArray());
      adds.get(i).add("add " + i);
    }
    List<Object> badInput = asList(true, 1, 2L, 3.0f, 4.0, ByteString.empty(), new StringMap(), new IntegerArray(), null);
    List<Object> badOutput = asList(true, 1, 2L, 3.0f, 4.0, ByteString.empty(), new DataMap());

    testArray(ArrayOfStringArrayTemplate.class, ArrayOfStringArrayTemplate.SCHEMA, input, adds);
    testArrayBadInput(ArrayOfStringArrayTemplate.class, ArrayOfStringArrayTemplate.SCHEMA, input, badInput, badOutput);
  }
View Full Code Here


  /**
   * Initialize a new {@link PatchTree}.
   */
  public PatchTree()
  {
    _representation = new DataMap();
  }
View Full Code Here

   */
  public void addOperation(PathSpec path, PatchOperation op)
  {
    List<String> segments = path.getPathComponents();

    DataMap map = _representation;
    for (int ii = 0; ii<segments.size() - 1; ++ii)
    {
      String segment = Escaper.escapePathSegment(segments.get(ii));
      Object o = map.get(segment);
      if (o == null)
      {
        DataMap childMap = new DataMap();
        map.put(segment, childMap);
        map = childMap;
      }
      else
      {
View Full Code Here

                      instruction);
    }
    else
    {

      DataMap data = (DataMap) instruction.getData();
      DataMap op = (DataMap) instruction.getOperation();

      Object opWildcard = op.get(FilterConstants.WILDCARD);
      Object dataWildcard = data.get(FilterConstants.WILDCARD);

      if ((opWildcard != null && opWildcard.equals(FilterConstants.NEGATIVE))
          || (dataWildcard != null && dataWildcard.equals(FilterConstants.NEGATIVE)))
      {
        handleNegativeWildcard(data);
      }
      else
      {
          //process array range
          composeArrayRange(data, op, instrCtx);

          // process all fields
          for (Entry<String, Object> entry : op.entrySet())
          {
            String fieldName = entry.getKey();
            Object opMask = entry.getValue();
            Object dataMask = data.get(fieldName);
View Full Code Here

  protected Status determineStatus(DataElement element)
  {
    Status status = null;
    element.pathAsList(_path);
    DataMap currentOpMap = _opMap;
    int i;
    for (i = 0; i < _path.size(); i++)
    {
      Object pathComponent = _path.get(i);
      if (i < _patchedPath.length)
      {
        if (_patchedPath[i].equals(pathComponent) == false)
        {
          status = Status.NONE;
          break;
        }
        status = Status.IS_DESCENDANT_MODIFIED;
        continue;
      }
      Object nextValue = currentOpMap.get(pathComponent);
      if (nextValue == null || nextValue.getClass() != DataMap.class)
      {
        Object setValue = currentOpMap.get(PatchConstants.SET_COMMAND);
        if (setValue != null && setValue.getClass() == DataMap.class &&
            ((DataMap) setValue).get(pathComponent) != null)
        {
          status = Status.IS_SET_VALUE;
          break;
        }
        status = Status.NONE;
        break;
      }
      status = Status.IS_DESCENDANT_MODIFIED;
      currentOpMap = (DataMap) nextValue;
    }
    if (i == _path.size())
    {
      if (i >= _patchedPath.length)
      {
        for (String keys : currentOpMap.keySet())
        {
          if (keys.startsWith(PatchConstants.COMMAND_PREFIX))
          {
            status = Status.IS_CHILD_MODIFIED;
            break;
          }
        }
      }
      if (status != Status.IS_CHILD_MODIFIED && i <= _patchedPath.length && ! currentOpMap.isEmpty())
      {
        status = Status.IS_DESCENDANT_MODIFIED;
      }
    }
    else if (status == null)
View Full Code Here

   * @return a PatchTree as described above.
  *
  */
  public static PatchTree diff(DataMap original, DataMap modified)
  {
    DataMap result = diffMaps(original, modified);
    if (result == null)
    {
      return new PatchTree();
    }
    return new PatchTree(result);
View Full Code Here

    _instrCtx = instrCtx;

    final Instruction instruction = _instrCtx.getCurrentInstruction();

    final Object dataValue = instruction.getData();
    final DataMap opNode = getOperation(instruction);

    filter(dataValue, opNode);
  }
View Full Code Here

    return new PatchTree(result);
  }

  private static DataMap diffMaps(DataMap original, DataMap modified)
  {
    DataMap result = null;
    for (String key : original.keySet())
    {
      if (! modified.containsKey(key))
      {
        result = result==null ? new DataMap() : result;
        PatchOpFactory.REMOVE_FIELD_OP.store(result, key);
      }
      else
      {
        Object oValue = original.get(key);
        Object mValue = modified.get(key);
        if ((mValue.getClass() == DataMap.class) && (oValue.getClass() == DataMap.class))
        {
          DataMap subDiff = diffMaps((DataMap)oValue, (DataMap)mValue);
          if (subDiff != null)
          {
            result = result==null ? new DataMap() : result;
            result.put(Escaper.escapePathSegment(key), subDiff);
          }
        }
        else if (! oValue.equals(mValue))
        {
          result = result==null ? new DataMap() : result;
          PatchOpFactory.setFieldOp(mValue).store(result, key);
        }
      }
    }
    for (Map.Entry<String, Object> entry : modified.entrySet())
    {
      if (! original.containsKey(entry.getKey()))
      {
        result = result==null ? new DataMap() : result;
        PatchOpFactory.setFieldOp(entry.getValue()).store(result, entry.getKey());
      }
    }
    return result;
  }
View Full Code Here

    public static final RecordDataSchema SCHEMA = (RecordDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"record\", \"name\" : \"Foo\", \"fields\" : [ { \"name\" : \"bar\", \"type\" : \"string\" } ] }");
    public static final RecordDataSchema.Field FIELD_bar = SCHEMA.getField("bar");

    public FooRecord()
    {
      super(new DataMap(), SCHEMA);
    }
View Full Code Here

  {
    for (String good : goodInputs)
    {
      NamedDataSchema dataSchema = (NamedDataSchema) TestUtil.dataSchemaFromString(good);

      DataMap mapFromSchema = Conversions.dataSchemaToDataMap(dataSchema);
      DataMap mapFromString = TestUtil.dataMapFromString(good);

      assertEquals(mapFromSchema, mapFromString);
    }
  }
View Full Code Here

TOP

Related Classes of com.linkedin.data.DataMap

Copyright © 2018 www.massapicom. 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.