/** * Finds out if this set is a subset of the given set. * * @param otherSet The other set. * @return <code>true</code> if all elements in this set are also present in the other set, <code>false</code> otherwise. */ public synchronized boolean isSubsetOfSet(NSSet otherSet) { for (NSObject o : this.set) { if (!otherSet.containsObject(o)) return false; } return true; }
/** * Returns all objects contained in the set. * * @return An array of all objects in the set. */ public synchronized NSObject[] allObjects() { return this.set.toArray(new NSObject[this.count()]); }
this.indent(ascii, level); NSObject[] array = this.allObjects(); ascii.append(ASCIIPropertyListParser.ARRAY_BEGIN_TOKEN); int indexOfLastNewLine = ascii.lastIndexOf(NEWLINE);
private Set<Object> deserializeSet() { Set<NSObject> originalSet = ((NSSet)this).getSet(); Set<Object> clonedSet; if(originalSet instanceof LinkedHashSet) { clonedSet = new LinkedHashSet<Object>(originalSet.size()); } else { clonedSet = new TreeSet<Object>(); } for(NSObject o : originalSet) { clonedSet.add(o.toJavaObject()); } return clonedSet; }
@Override public NSSet clone() { NSObject[] clonedSet = new NSObject[this.set.size()]; int i = 0; for(NSObject element : this.set) { clonedSet[i++] = element != null ? element.clone() : null; } return new NSSet(this.ordered, clonedSet); }
/** * Returns the XML representation for this set. * There is no official XML representation specified for sets. * In this implementation it is represented by an array. * * @param xml The XML StringBuilder * @param level The indentation level */ @Override void toXML(StringBuilder xml, int level) { this.indent(xml, level); xml.append("<array>"); xml.append(NSObject.NEWLINE); for (NSObject o : this.set) { o.toXML(xml, level + 1); xml.append(NSObject.NEWLINE); } this.indent(xml, level); xml.append("</array>"); }
for (NSObject o : set.allObjects()) { int v = getMinimumRequiredVersion(o); if (v > minVersion)
this.indent(ascii, level); NSObject[] array = this.allObjects(); ascii.append(ASCIIPropertyListParser.ARRAY_BEGIN_TOKEN); int indexOfLastNewLine = ascii.lastIndexOf(NEWLINE);
private Object deserializeArray(NSObject payload, Class<?> clazz) { Class<?> elementClass = getClassForName(clazz.getComponentType().getName()); if (payload instanceof NSArray) { NSObject[] array = ((NSArray) payload).getArray(); Object result = Array.newInstance(elementClass, array.length); for (int i = 0; i < array.length; i++) { Array.set(result, i, this.toJavaObject(array[i], elementClass, null)); } return result; } if (payload instanceof NSSet) { Set<NSObject> set = ((NSSet) payload).getSet(); Object result = Array.newInstance(elementClass, set.size()); int i = 0; for (NSObject aSet : set) { Array.set(result, i, this.toJavaObject(aSet, elementClass, null)); i++; } return result; } if (payload instanceof NSData) { return deserializeData((NSData) payload, elementClass); } throw new IllegalArgumentException("Unable to map " + payload.getClass().getSimpleName() + " to " + clazz.getName()); }
int contentOffset = lengthAndOffset[1]; NSSet set = new NSSet(true); for (int i = 0; i < length; i++) { int objRef = (int) parseUnsignedInt(this.bytes, offset + contentOffset + i * this.objectRefSize, offset + contentOffset + (i + 1) * this.objectRefSize); set.addObject(this.parseObject(objRef)); int contentOffset = lengthAndOffset[1]; NSSet set = new NSSet(); for (int i = 0; i < length; i++) { int objRef = (int) parseUnsignedInt(this.bytes, offset + contentOffset + i * this.objectRefSize, offset + contentOffset + (i + 1) * this.objectRefSize); set.addObject(this.parseObject(objRef));
for (NSObject nsObject : ((NSSet) payload).getSet()) { result.add(this.toJavaObject(nsObject, elemClass, elemTypes));
/** * Finds out whether at least one object is present in both sets. * * @param otherSet The other set. * @return <code>false</code> if the intersection of both sets is empty, <code>true</code> otherwise. */ public synchronized boolean intersectsSet(NSSet otherSet) { for (NSObject o : this.set) { if (otherSet.containsObject(o)) return true; } return false; }