public int hashCode() { int hash = 1; for (ByteIterator iter = iterator(); iter.hasNext(); ) { hash = 31 * hash + ((int) (iter.next())); } return hash; }
public boolean addAll(int index, ByteCollection collection) { boolean modified = false; for (ByteIterator iter = collection.iterator(); iter.hasNext(); ) { add(index++, iter.next()); modified = true; } return modified; }
public int indexOf(byte element) { int i = 0; for (ByteIterator iter = iterator(); iter.hasNext(); ) { if (iter.next() == element) { return i; } else { i++; } } return -1; }
public String toString() { StringBuffer buf = new StringBuffer(); buf.append("["); for (ByteIterator iter = iterator(); iter.hasNext(); ) { buf.append(iter.next()); if (iter.hasNext()) { buf.append(", "); } } buf.append("]"); return buf.toString(); }
/** * This function is called in the load phase which is executed using the -load or -loadindex * argument. It is used for inserting users and resources. Any field/value pairs in the values * HashMap for an entity will be written into the specified entity set with the specified entity * key. * * @param entitySet The name of the entity set with the following two possible values: users and * resources. BG passes these values in lower case. The implementation may manipulate the case * to tailor it for the purposes of a data store. * @param entityPK The primary key of the entity to insert. * @param values A HashMap of field/value pairs to insert for the entity, these pairs are the * other attributes for an entity and their values. The profile image is identified with the * "pic" key attribute and the thumbnail image is identified with the "tpic" key attribute. * @param insertImage Identifies if images should be inserted for users. if set to true the code * should populate each entity with an image; the size of the image is specified using the * imagesize parameter. * @return Zero on success, a non-zero error code on error. See this class's description for a * discussion of error codes. The code written for this function call should insert the entity * and its attributes. The code is responsible for inserting the PK and the other attributes * in the appropriate order. */ @Override public int insertEntity( String entitySet, String entityPK, HashMap<String, ByteIterator> values, boolean insertImage) { /** Insert Users and Resources data using JSON-like data model. */ JsonObject jsonObject = new JsonObject(); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { if (!entry.getKey().equals("pic") && !entry.getKey().equals("tpic")) { jsonObject.add(entry.getKey(), new JsonPrimitive(entry.getValue().toString())); } } try { transactionHelper.writeUser(entityPK, jsonObject); } catch (ConnectionException | AbortException e) { e.printStackTrace(); return -1; } /** Update Users data after inserting Resources. */ if (entitySet.equals(RESOURCES)) { try { ByteIterator wallUserID = values.get(WALL_USER_ID); jsonObject = transactionHelper.readUser(wallUserID.toString()); JsonArray jsonArray; if (jsonObject.has(RESOURCES)) { jsonArray = jsonObject.getAsJsonArray(RESOURCES); } else { jsonArray = new JsonArray(); } jsonArray.add(new JsonPrimitive(entityPK)); jsonObject.add(RESOURCES, jsonArray); transactionHelper.writeUser(wallUserID.toString(), jsonObject); } catch (ConnectionException | NotFoundException | AbortException e) { e.printStackTrace(); return -1; } } return 0; }
public boolean equals(Object that) { if (this == that) { return true; } else if (that instanceof ByteList) { ByteList thatList = (ByteList) that; if (size() != thatList.size()) { return false; } for (ByteIterator thatIter = thatList.iterator(), thisIter = iterator(); thisIter.hasNext(); ) { if (thisIter.next() != thatIter.next()) { return false; } } return true; } else { return false; } }