1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.item; 17 18 import org.json.JSONObject; 19 20 /** 21 * Interface for all items that are created by any parser. 22 */ 23 public interface IItem { 24 25 /** 26 * Merges the item and another into an item with the most complete information. 27 * 28 * <p> 29 * Goes through each field in the item preferring non-null fields over null fields. 30 * </p> 31 * 32 * @param other The other item 33 * @return The product of both items combined. 34 * @throws ConflictingItemException If the two items are not consistent. 35 */ merge(IItem other)36 public IItem merge(IItem other) throws ConflictingItemException; 37 38 /** 39 * Checks that the item and another are consistent. 40 * 41 * <p> 42 * Consistency means that no individual fields in either item conflict with the other. 43 * However, one item might contain more complete information. Two items of different types 44 * are never consistent. 45 * </p> 46 * 47 * @param other The other item. 48 * @return True if the objects are the same type and all the fields are either equal or one of 49 * the fields is null. 50 */ isConsistent(IItem other)51 public boolean isConsistent(IItem other); 52 53 /** 54 * Get a JSON representation of the item. 55 * 56 * @return The representation of the item as a {@link JSONObject}. 57 */ toJson()58 public JSONObject toJson(); 59 } 60