@Override public NSArray clone() { NSObject[] clonedArray = new NSObject[this.array.length]; for(int i = 0; i < this.array.length; i++) { clonedArray[i] = this.array[i] != null ? this.array[i].clone() : null; } return new NSArray(clonedArray); }
private static NSArray fromCollection(Collection<?> collection) { List<NSObject> payload = new ArrayList<NSObject>(collection.size()); for (Object elem : collection) { payload.add(fromJavaObject(elem)); } return new NSArray(payload.toArray(new NSObject[payload.size()])); }
private static NSObject fromArray(Object object, Class<?> objClass) { Class<?> elementClass = objClass.getComponentType(); if(elementClass == byte.class || elementClass == Byte.class) { return fromData(object); } int size = Array.getLength(object); NSObject[] array = new NSObject[size]; for (int i = 0; i < size; i++) { array[i] = fromJavaObject(Array.get(object, i)); } return new NSArray(array); }
@Override public <T extends Serializable> void setListForKey(final List<T> value, final String key) { final NSArray list = new NSArray(value.size()); int i = 0; for(Serializable serializable : value) { list.setValue(i, serializable.<NSDictionary>serialize(SerializerFactory.get())); i++; } dict.put(key, list); }
@Override public void write(final Collection<S> collection, final Local file) throws AccessDeniedException { final NSArray list = new NSArray(collection.size()); int i = 0; for(S bookmark : collection) { list.setValue(i, bookmark.<NSDictionary>serialize(SerializerFactory.get())); i++; } final String content = list.toXMLPropertyList(); final OutputStream out = file.getOutputStream(false); try { IOUtils.write(content, out, Charset.forName("UTF-8")); } catch(IOException e) { throw new AccessDeniedException(String.format("Cannot create file %s", file.getAbsolute()), e); } finally { IOUtils.closeQuietly(out); } }
} else if (type.equals("array")) { List<Node> children = filterElementNodes(n.getChildNodes()); NSArray array = new NSArray(children.size()); for (int i = 0; i < children.size(); i++) { array.setValue(i, parseObject(children.get(i)));
/** * Parses an array from the current parsing position. * The prerequisite for calling this method is, that an array begin token has been read. * * @return The array found at the parsing position. */ private NSArray parseArray() throws ParseException { //Skip begin token this.skip(); this.skipWhitespacesAndComments(); List<NSObject> objects = new LinkedList<NSObject>(); while (!this.accept(ARRAY_END_TOKEN)) { objects.add(this.parseObject()); this.skipWhitespacesAndComments(); if (this.accept(ARRAY_ITEM_DELIMITER_TOKEN)) { this.skip(); } else { break; //must have reached end of array } this.skipWhitespacesAndComments(); } //parse end token this.read(ARRAY_END_TOKEN); return new NSArray(objects.toArray(new NSObject[objects.size()])); }
public static NSObject toNsObject(JsonArray a) { NSArray array = new NSArray(a.size()); int index=0; for(JsonElement v: a) { NSObject value; if(v.isObject()) { value=toNsObject(v.asObject()); } else if(v.isArray()) { value = toNsObject(v.asArray()); } else { value=toNsObject(v.asPrimitive()); } array.setValue(index++, value); } return array; }
int arrayOffset = lengthAndOffset[1]; NSArray array = new NSArray(length); for (int i = 0; i < length; i++) { int objRef = (int) parseUnsignedInt(this.bytes, offset + arrayOffset + i * this.objectRefSize, offset + arrayOffset + (i + 1) * this.objectRefSize);