Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.waveprotocol.box.common.comms.jso; import static org.waveprotocol.wave.communication.gwt.JsonHelper.*; import com.google.gwt.core.client.*; /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import org.waveprotocol.wave.federation.ProtocolDocumentOperation; import org.waveprotocol.wave.federation.jso.ProtocolDocumentOperationJsoImpl; /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import org.waveprotocol.box.common.comms.DocumentSnapshot; import org.waveprotocol.box.common.comms.DocumentSnapshotUtil; import org.waveprotocol.wave.communication.Blob; import org.waveprotocol.wave.communication.ProtoEnums; import org.waveprotocol.wave.communication.gwt.*; import org.waveprotocol.wave.communication.json.*; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** * Client implementation of DocumentSnapshot backed by a GWT JavaScriptObject. * * Generated from org/waveprotocol/box/common/comms/waveclient-rpc.proto. Do not edit. */ /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** We have to use fully-qualified name of the GsonSerializable class here in order to make it * visible in case of nested classes. */ public final class DocumentSnapshotJsoImpl extends org.waveprotocol.wave.communication.gwt.JsonMessage implements DocumentSnapshot { private static final String keyDocumentId = "1"; private static final String keyDocumentOperation = "2"; private static final String keyAuthor = "3"; private static final String keyContributor = "4"; private static final String keyLastModifiedVersion = "5"; private static final String keyLastModifiedTime = "6"; protected DocumentSnapshotJsoImpl() { } public static DocumentSnapshotJsoImpl create() { DocumentSnapshotJsoImpl instance = (DocumentSnapshotJsoImpl) JsonMessage.createJsonMessage(); // Force all lists to start with an empty list rather than no property for // the list. This is so that the native JS equality works, since (obviously) // {} != {"foo": []} while in the context of messages they should be. instance.clearContributor(); return instance; } @Override public void copyFrom(DocumentSnapshot message) { super.copyFrom((DocumentSnapshotJsoImpl) message); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public String getDocumentId() { return hasProperty(this, keyDocumentId) ? getPropertyAsString(this, keyDocumentId) : null; } @Override public void setDocumentId(String value) { setPropertyAsString(this, keyDocumentId, value); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public ProtocolDocumentOperation getDocumentOperation() { return hasProperty(this, keyDocumentOperation) ? ((ProtocolDocumentOperationJsoImpl) getPropertyAsObject(this, keyDocumentOperation)) : null; } @Override public void setDocumentOperation(ProtocolDocumentOperation model) { setPropertyAsObject(this, keyDocumentOperation, (ProtocolDocumentOperationJsoImpl) model); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public String getAuthor() { return hasProperty(this, keyAuthor) ? getPropertyAsString(this, keyAuthor) : null; } @Override public void setAuthor(String value) { setPropertyAsString(this, keyAuthor, value); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public List<String> getContributor() { initArray(this, keyContributor); List<String> list = new ArrayList<String>(); for (int i = 0; i < getContributorSize(); i++) { list.add(getContributor(i)); } return list; } @Override public void addAllContributor(List<String> values) { for (String value : values) { addContributor(value); } } @Override @SuppressWarnings("unchecked") public String getContributor(int n) { initArray(this, keyContributor); JsArrayString array = getPropertyAsObject(this, keyContributor).cast(); if (n < 0) throw new IllegalArgumentException("index " + n + " < 0"); if (array.length() <= n) throw new IllegalArgumentException("index " + n + ">= array length " + array.length()); return array.get(n); } @Override public void setContributor(int n, String value) { if (n < 0) throw new IllegalArgumentException("index " + n + " < 0"); initArray(this, keyContributor); ((JsArrayString) getPropertyAsObject(this, keyContributor)).set(n, value); } @Override public int getContributorSize() { return hasProperty(this, keyContributor) ? ((JsArray<?>) getPropertyAsObject(this, keyContributor)).length() : 0; } @Override public void addContributor(String value) { initArray(this, keyContributor); ((JsArrayString) getPropertyAsObject(this, keyContributor)).push(value); } @Override public void clearContributor() { clearArray(this, keyContributor); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public long getLastModifiedVersion() { return hasProperty(this, keyLastModifiedVersion) ? getPropertyAsLong(this, keyLastModifiedVersion) : 0L; } @Override public void setLastModifiedVersion(long value) { setPropertyAsLong(this, keyLastModifiedVersion, value); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public long getLastModifiedTime() { return hasProperty(this, keyLastModifiedTime) ? getPropertyAsLong(this, keyLastModifiedTime) : 0L; } @Override public void setLastModifiedTime(long value) { setPropertyAsLong(this, keyLastModifiedTime, value); } @Override public boolean isEqualTo(Object o) { if (o instanceof DocumentSnapshotJsoImpl) { return nativeIsEqualTo(o); } else if (o instanceof DocumentSnapshot) { return DocumentSnapshotUtil.isEqual(this, (DocumentSnapshot) o); } else { return false; } } }