Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Unified Diff: tools/immic/lib/src/resources/java/immi/ListPatch.java

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/immic/lib/src/resources/java/immi/ListPatch.java
diff --git a/tools/immic/lib/src/resources/java/immi/ListPatch.java b/tools/immic/lib/src/resources/java/immi/ListPatch.java
deleted file mode 100644
index 67504a0eb73cf6eab0f1ec40bdbba185ed4a17b4..0000000000000000000000000000000000000000
--- a/tools/immic/lib/src/resources/java/immi/ListPatch.java
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE.md file.
-
-// Generated file. Do not edit.
-
-package immi;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import dartino.ListPatchData;
-import dartino.ListRegionData;
-import dartino.ListRegionDataList;
-import dartino.NodeDataList;
-import dartino.NodePatchDataList;
-
-public final class ListPatch<N extends Node> implements Patch {
-
- // Public interface.
-
- @Override
- public boolean hasChanged() { return changed; }
-
- public List<N> getCurrent() { return current; }
- public List<N> getPrevious() { return previous; }
-
- public List<RegionPatch> getRegions() { return regions; }
-
- public static abstract class RegionPatch {
- public int getIndex() { return index; }
- public abstract int getCount();
- public boolean isRemove() { return false; }
- public boolean isInsert() { return false; }
- public boolean isUpdate() { return false; }
-
- RegionPatch(int index) {
- this.index = index;
- }
-
- static RegionPatch fromData(
- ListRegionData data,
- Type type,
- List<Node> previous,
- ImmiRoot root) {
- if (data.isRemove()) return new RemovePatch(data);
- if (data.isInsert()) return new InsertPatch(data, type, root);
- assert data.isUpdate();
- return new UpdatePatch(data, type, previous, root);
- }
-
- // Returns the change in size resulting from this region patch.
- abstract int delta();
-
- // Applies a region patch to the output list and returns the index increment
- // of the input list.
- abstract int apply(List<Node> output);
-
- private int index;
- }
-
- public static class RemovePatch extends RegionPatch {
- @Override public int getCount() { return count; }
- @Override public boolean isRemove() { return false; }
-
- int delta() { return -count; }
-
- int apply(List<Node> output) { return count; }
-
- private RemovePatch(ListRegionData data) {
- super(data.getIndex());
- count = data.getRemove();
- }
-
- private int count;
- }
-
- public static class InsertPatch extends RegionPatch {
- @Override public int getCount() { return nodes.size(); }
- @Override public boolean isInsert() { return true; }
-
- public List<Node> getNodes() { return nodes; }
-
- int delta() { return nodes.size(); }
-
- int apply(List<Node> output) {
- output.addAll(nodes);
- return 0;
- }
-
- private InsertPatch(ListRegionData data, Type type, ImmiRoot root) {
- super(data.getIndex());
- NodeDataList insertData = data.getInsert();
- int length = insertData.size();
- List<Node> mutableNodes = new ArrayList<Node>(length);
- if (type == Type.ANY_NODE) {
- for (int i = 0; i < length; ++i) {
- mutableNodes.add(new AnyNode(insertData.get(i), root));
- }
- } else {
- assert type == Type.SPECIFIC_NODE;
- for (int i = 0; i < length; ++i) {
- mutableNodes.add(AnyNode.fromData(insertData.get(i), root));
- }
- }
- nodes = Collections.unmodifiableList(mutableNodes);
- }
-
- private List<Node> nodes;
- }
-
- public static class UpdatePatch extends RegionPatch {
- @Override public int getCount() { return updates.size(); }
- @Override public boolean isUpdate() { return true; }
-
- public List<NodePatch> getUpdates() { return updates; }
-
- int delta() { return 0; }
-
- int apply(List<Node> output) {
- int length = updates.size();
- for (int i = 0; i < length; ++i) {
- output.add(updates.get(i).getCurrent());
- }
- return length;
- }
-
- private UpdatePatch(
- ListRegionData data,
- Type type,
- List<Node> previous,
- ImmiRoot root) {
- super(data.getIndex());
- NodePatchDataList updateData = data.getUpdate();
- int length = updateData.size();
- List<NodePatch> mutableUpdates = new ArrayList<NodePatch>(length);
- if (type == Type.ANY_NODE) {
- for (int i = 0; i < length; ++i) {
- mutableUpdates.add(new AnyNodePatch(
- updateData.get(i), (AnyNode)previous.get(getIndex() + i), root));
- }
- } else {
- assert type == Type.SPECIFIC_NODE;
- for (int i = 0; i < length; ++i) {
- mutableUpdates.add(AnyNodePatch.fromData(
- updateData.get(i), previous.get(getIndex() + i), root));
- }
- }
- updates = Collections.unmodifiableList(mutableUpdates);
- }
-
- private List<NodePatch> updates;
- }
-
- // Package private implementation.
-
- ListPatch(List<N> previous) {
- changed = false;
- this.previous = previous;
- current = previous;
- }
-
- ListPatch(ListPatchData data, List<N> previous, ImmiRoot root) {
- changed = true;
- this.previous = previous;
- Type type = Type.fromInt(data.getType());
- ListRegionDataList regions = data.getRegions();
- List<RegionPatch> patches = new ArrayList<RegionPatch>(regions.size());
- for (int i = 0; i < regions.size(); ++i) {
- // TODO(zerny): Separate ListPatch<AnyNode> from ListPatch<Node> and avoid
- // dynamic casts.
- patches.add(RegionPatch.fromData(
- regions.get(i), type, (List<Node>)previous, root));
- }
- this.regions = patches;
- this.current = applyWith(previous);
- }
-
- List<N> applyWith(List<N> previous) {
- int newSize = previous.size();
- for (int i = 0; i < regions.size(); ++i) {
- newSize += regions.get(i).delta();
- }
- int sourceIndex = 0;
- List<N> newArray = new ArrayList<N>(newSize);
- for (int i = 0; i < regions.size(); ++i) {
- RegionPatch patch = regions.get(i);
- while (sourceIndex < patch.index) {
- newArray.add(previous.get(sourceIndex++));
- }
- // TODO(zerny): Separate ListPatch<AnyNode> from ListPatch<Node> and avoid
- // dynamic casts.
- sourceIndex += patch.apply((List<Node>)newArray);
- }
- while (sourceIndex < previous.size()) {
- newArray.add(previous.get(sourceIndex++));
- }
- return Collections.unmodifiableList(newArray);
- }
-
- private enum Type {
- ANY_NODE, SPECIFIC_NODE;
-
- public static Type fromInt(int tag) {
- return tag == 0 ? ANY_NODE : SPECIFIC_NODE;
- }
- }
-
- private boolean changed;
- private List<N> previous;
- private List<N> current;
- private List<RegionPatch> regions;
-}
« no previous file with comments | « tools/immic/lib/src/resources/java/immi/ImmiService.java ('k') | tools/immic/lib/src/resources/java/immi/Node.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698