Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2012 Goodow.com
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.goodow.realtime;
import com.goodow.realtime.model.util.JsonSerializer;
import com.goodow.realtime.model.util.ModelFactory;
import com.goodow.realtime.operation.Operation;
import com.goodow.realtime.operation.create.CreateOperation;
import com.goodow.realtime.operation.list.ListTarget;
import com.goodow.realtime.operation.list.json.JsonDeleteOperation;
import com.goodow.realtime.operation.list.json.JsonInsertOperation;
import com.goodow.realtime.operation.list.json.JsonReplaceOperation;
import com.goodow.realtime.operation.util.JsonUtility;
import com.google.common.annotations.GwtIncompatible;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportAfterCreateMethod;
import org.timepedia.exporter.client.ExportPackage;
import org.timepedia.exporter.client.NoExport;
import java.util.Comparator;
import java.util.Set;
import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonValue;
/**
* A collaborative list. A list can contain other Realtime collaborative objects, custom
* collaborative objects, primitive values, or objects that can be serialized to JSON.
*
* Changes to the list will automatically be synced with the server and other collaborators. To
* listen for changes, add EventListeners for the following event types:
*
* This class should not be instantiated directly. To create a new list, use
* {@link com.goodow.realtime.Model#createList(Object...)}.
*/
@ExportPackage(ModelFactory.PACKAGE_PREFIX_REALTIME)
@Export(all = true)
public class CollaborativeList extends CollaborativeObject {
@GwtIncompatible(ModelFactory.JS_REGISTER_PROPERTIES)
@ExportAfterCreateMethod
// @formatter:off
public native static void __jsniRunAfter__() /*-{
var _ = $wnd.good.realtime.CollaborativeList.prototype;
// Object.defineProperties(_, {
// id : {
// get : function() {
// return [email protected]::id;
// }
// },
// length : {
// get : function() {
// return [email protected]::length()();
// },
// set : function(length) {
// return [email protected]::setLength(I)(length);
// }
// }
// });
_.asArray = function() {
var values = [];
for ( var i = 0, len = this.length(); i < len; i++) {
values[i] = this.get(i);
}
return values;
};
_.get = function(index) {
[email protected]::checkIndex(IZ)(index, false)
var p = [email protected]::snapshot[index];
if (p === undefined) {
return undefined;
} else if (p[0] != @com.goodow.realtime.model.util.JsonSerializer::REFERENCE_TYPE) {
return p[1];
} else {
var v = [email protected]::get(I)(index);
return @org.timepedia.exporter.client.ExporterUtil::wrap(Ljava/lang/Object;)(v);
}
};
_.indexOf = function(value, opt_comparatorFn) {
if (opt_comparatorFn === undefined) {
var v = @org.timepedia.exporter.client.ExporterUtil::gwtInstance(Ljava/lang/Object;)(value);
return [email protected]::indexOf(Ljava/lang/Object;Ljava/util/Comparator;)(v, null);
} else {
for ( var i = 0, len = this.length(); i < len; i++) {
if (opt_comparatorFn(value, this.get(i)) == 0) {
return i;
}
}
return -1;
}
};
_.insert = function(index, value) {
var v = @org.timepedia.exporter.client.ExporterUtil::gwtInstance(Ljava/lang/Object;)(value);
[email protected]::insert(ILjava/lang/Object;)(index,v);
};
_.lastIndexOf = function(value, opt_comparatorFn) {
if (opt_comparatorFn === undefined) {
var v = @org.timepedia.exporter.client.ExporterUtil::gwtInstance(Ljava/lang/Object;)(value);
return [email protected]::lastIndexOf(Ljava/lang/Object;Ljava/util/Comparator;)(v, null);
} else {
for ( var i = this.length() - 1; i >= 0; i--) {
if (opt_comparatorFn(value, this.get(i)) == 0) {
return i;
}
}
return -1;
}
};
_.push = function(value) {
this.insert(this.length(), value);
return this.length();
};
_.removeValue = function(value) {
var v = @org.timepedia.exporter.client.ExporterUtil::gwtInstance(Ljava/lang/Object;)(value);
return [email protected]::removeValue(Ljava/lang/Object;)(v);
};
_.set = function(index, value) {
var v = @org.timepedia.exporter.client.ExporterUtil::gwtInstance(Ljava/lang/Object;)(value);
[email protected]::set(ILjava/lang/Object;)(index,v);
};
}-*/;
// @formatter:on
private final JsonArray snapshot;
/**
* @param model The document model.
*/
CollaborativeList(Model model) {
super(model);
snapshot = Json.createArray();
}
public void addValuesAddedListener(EventHandler handler) {
addEventListener(EventType.VALUES_ADDED, handler, false);
}
public void addValuesRemovedListener(EventHandler handler) {
addEventListener(EventType.VALUES_REMOVED, handler, false);
}
public void addValuesSetListener(EventHandler handler) {
addEventListener(EventType.VALUES_SET, handler, false);
}
/**
* Returns a copy of the contents of this collaborative list as an array. Changes to the returned
* object will not affect the original collaborative list.
*
* @return A copy of the contents of this collaborative list.
*/
@SuppressWarnings("unchecked")
@NoExport
public T[] asArray() {
int length = length();
Object[] objects = new Object[length];
for (int i = 0; i < length; i++) {
objects[i] = get(i);
}
return (T[]) objects;
}
/**
* Removes all values from the list.
*/
public void clear() {
int length = length();
if (length == 0) {
return;
}
removeRange(0, length);
}
/**
* Gets the value at the given index.
*
* @param index The index.
* @return The value at the given index.
* @exception java.lang.ArrayIndexOutOfBoundsException
*/
@SuppressWarnings("unchecked")
@NoExport
public T get(int index) {
checkIndex(index, false);
return (T) JsonSerializer.deserializeObject(snapshot.get(index), model.objects);
}
/**
* Returns the first index of the given value, or -1 if it cannot be found.
*
* @param value The value to find.
* @param opt_comparator Optional comparator function used to determine the equality of two items.
* @return The index of the given value, or -1 if it cannot be found.
*/
@NoExport
public int indexOf(Object value, Comparator