repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
maruohon/justenoughdimensions
src/main/java/fi/dy/masa/justenoughdimensions/network/PacketHandler.java
// Path: src/main/java/fi/dy/masa/justenoughdimensions/reference/Reference.java // public class Reference // { // public static final String MOD_ID = "justenoughdimensions"; // public static final String MOD_NAME = "Just Enough Dimensions"; // public static final String MOD_VERSION = "@MOD_VERSION@"; // public static final String FINGERPRINT = "@FINGERPRINT@"; // // public static final String PROXY_CLIENT = "fi.dy.masa.justenoughdimensions.proxy.ClientProxy"; // public static final String PROXY_SERVER = "fi.dy.masa.justenoughdimensions.proxy.CommonProxy"; // }
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; import fi.dy.masa.justenoughdimensions.reference.Reference;
package fi.dy.masa.justenoughdimensions.network; public class PacketHandler {
// Path: src/main/java/fi/dy/masa/justenoughdimensions/reference/Reference.java // public class Reference // { // public static final String MOD_ID = "justenoughdimensions"; // public static final String MOD_NAME = "Just Enough Dimensions"; // public static final String MOD_VERSION = "@MOD_VERSION@"; // public static final String FINGERPRINT = "@FINGERPRINT@"; // // public static final String PROXY_CLIENT = "fi.dy.masa.justenoughdimensions.proxy.ClientProxy"; // public static final String PROXY_SERVER = "fi.dy.masa.justenoughdimensions.proxy.CommonProxy"; // } // Path: src/main/java/fi/dy/masa/justenoughdimensions/network/PacketHandler.java import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; import fi.dy.masa.justenoughdimensions.reference.Reference; package fi.dy.masa.justenoughdimensions.network; public class PacketHandler {
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MOD_ID.toLowerCase());
maruohon/justenoughdimensions
src/main/java/fi/dy/masa/justenoughdimensions/config/JustEnoughDimensionsGuiFactory.java
// Path: src/main/java/fi/dy/masa/justenoughdimensions/reference/Reference.java // public class Reference // { // public static final String MOD_ID = "justenoughdimensions"; // public static final String MOD_NAME = "Just Enough Dimensions"; // public static final String MOD_VERSION = "@MOD_VERSION@"; // public static final String FINGERPRINT = "@FINGERPRINT@"; // // public static final String PROXY_CLIENT = "fi.dy.masa.justenoughdimensions.proxy.ClientProxy"; // public static final String PROXY_SERVER = "fi.dy.masa.justenoughdimensions.proxy.CommonProxy"; // }
import java.util.ArrayList; import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.fml.client.DefaultGuiFactory; import net.minecraftforge.fml.client.config.GuiConfig; import net.minecraftforge.fml.client.config.IConfigElement; import fi.dy.masa.justenoughdimensions.reference.Reference;
package fi.dy.masa.justenoughdimensions.config; public class JustEnoughDimensionsGuiFactory extends DefaultGuiFactory { public JustEnoughDimensionsGuiFactory() {
// Path: src/main/java/fi/dy/masa/justenoughdimensions/reference/Reference.java // public class Reference // { // public static final String MOD_ID = "justenoughdimensions"; // public static final String MOD_NAME = "Just Enough Dimensions"; // public static final String MOD_VERSION = "@MOD_VERSION@"; // public static final String FINGERPRINT = "@FINGERPRINT@"; // // public static final String PROXY_CLIENT = "fi.dy.masa.justenoughdimensions.proxy.ClientProxy"; // public static final String PROXY_SERVER = "fi.dy.masa.justenoughdimensions.proxy.CommonProxy"; // } // Path: src/main/java/fi/dy/masa/justenoughdimensions/config/JustEnoughDimensionsGuiFactory.java import java.util.ArrayList; import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.fml.client.DefaultGuiFactory; import net.minecraftforge.fml.client.config.GuiConfig; import net.minecraftforge.fml.client.config.IConfigElement; import fi.dy.masa.justenoughdimensions.reference.Reference; package fi.dy.masa.justenoughdimensions.config; public class JustEnoughDimensionsGuiFactory extends DefaultGuiFactory { public JustEnoughDimensionsGuiFactory() {
super(Reference.MOD_ID, getTitle());
datenhahn/componentrenderer
componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/client/detailskeys/DetailsOpenCloseServerRpc.java // public interface DetailsOpenCloseServerRpc extends ServerRpc { // // /** // * Sets the details of a row visible or hidden. // * // * @param rowIndex the rowIndex of the row, this is the rowIndex of an IndexedContainer, // * this is NOT the rowId (= id in the container) or the // * rowKey (= internal key in clienside grid implementation) // * @param visible set the details to visible (= true) or hidden (= false) // */ // void setDetailsVisible(int rowIndex, boolean visible); // }
import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.client.detailskeys.DetailsOpenCloseServerRpc;
/** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer; /** * Handles the expansion and collapsing of the detailsrow with STRG+DOWN (expand) and STRG+UP (collapse). * * @author Jonas Hahn ([email protected]) */ public class DetailsKeysExtension extends Grid.AbstractGridExtension { private DetailsKeysExtension(final Grid grid) { super.extend(grid); registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); } public static DetailsKeysExtension extend(Grid grid) { return new DetailsKeysExtension(grid); }
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/client/detailskeys/DetailsOpenCloseServerRpc.java // public interface DetailsOpenCloseServerRpc extends ServerRpc { // // /** // * Sets the details of a row visible or hidden. // * // * @param rowIndex the rowIndex of the row, this is the rowIndex of an IndexedContainer, // * this is NOT the rowId (= id in the container) or the // * rowKey (= internal key in clienside grid implementation) // * @param visible set the details to visible (= true) or hidden (= false) // */ // void setDetailsVisible(int rowIndex, boolean visible); // } // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.client.detailskeys.DetailsOpenCloseServerRpc; /** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer; /** * Handles the expansion and collapsing of the detailsrow with STRG+DOWN (expand) and STRG+UP (collapse). * * @author Jonas Hahn ([email protected]) */ public class DetailsKeysExtension extends Grid.AbstractGridExtension { private DetailsKeysExtension(final Grid grid) { super.extend(grid); registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); } public static DetailsKeysExtension extend(Grid grid) { return new DetailsKeysExtension(grid); }
public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc {
datenhahn/componentrenderer
componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection;
/** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; /** * A typed version of the grid using a {@link BeanItemContainer} to store * the typed grid data and a {@link GeneratedPropertyContainer} to provide * generated component-columns. * * Also offers some convenience methods for this use-case (typed, use of components). * * @author Jonas Hahn ([email protected]) */ public class ComponentGrid<T> extends Grid { private final ComponentGridDecorator<T> componentGridDecorator; public ComponentGrid(Class<T> typeOfRows) { super(); setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); } public ComponentGridDecorator<T> getComponentGridDecorator() { return componentGridDecorator; }
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection; /** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; /** * A typed version of the grid using a {@link BeanItemContainer} to store * the typed grid data and a {@link GeneratedPropertyContainer} to provide * generated component-columns. * * Also offers some convenience methods for this use-case (typed, use of components). * * @author Jonas Hahn ([email protected]) */ public class ComponentGrid<T> extends Grid { private final ComponentGridDecorator<T> componentGridDecorator; public ComponentGrid(Class<T> typeOfRows) { super(); setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); } public ComponentGridDecorator<T> getComponentGridDecorator() { return componentGridDecorator; }
public FocusPreserveExtension getFocusPreserveExtension() {
datenhahn/componentrenderer
componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection;
public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { return componentGridDecorator.addComponentColumn(propertyId, generator); } /** * Refreshes the grid preserving its current cell focus. */ public ComponentGrid<T> refresh() { componentGridDecorator.refresh(); return this; } /** * Remove all items from the underlying {@link BeanItemContainer} and add * the new beans. * * @param beans a collection of beans * @return the grid for method chaining */ public ComponentGrid<T> setRows(Collection<T> beans) { componentGridDecorator.setRows(beans); return this; } /** * Generates component header fields using the passed {@link ComponentHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection; public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { return componentGridDecorator.addComponentColumn(propertyId, generator); } /** * Refreshes the grid preserving its current cell focus. */ public ComponentGrid<T> refresh() { componentGridDecorator.refresh(); return this; } /** * Remove all items from the underlying {@link BeanItemContainer} and add * the new beans. * * @param beans a collection of beans * @return the grid for method chaining */ public ComponentGrid<T> setRows(Collection<T> beans) { componentGridDecorator.setRows(beans); return this; } /** * Generates component header fields using the passed {@link ComponentHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */
public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) {
datenhahn/componentrenderer
componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection;
/** * Remove all items from the underlying {@link BeanItemContainer} and add * the new beans. * * @param beans a collection of beans * @return the grid for method chaining */ public ComponentGrid<T> setRows(Collection<T> beans) { componentGridDecorator.setRows(beans); return this; } /** * Generates component header fields using the passed {@link ComponentHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */ public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { componentGridDecorator.generateHeaders(generator); return this; } /** * Generates text header fields using the passed {@link TextHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection; /** * Remove all items from the underlying {@link BeanItemContainer} and add * the new beans. * * @param beans a collection of beans * @return the grid for method chaining */ public ComponentGrid<T> setRows(Collection<T> beans) { componentGridDecorator.setRows(beans); return this; } /** * Generates component header fields using the passed {@link ComponentHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */ public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { componentGridDecorator.generateHeaders(generator); return this; } /** * Generates text header fields using the passed {@link TextHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */
public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) {
datenhahn/componentrenderer
componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection;
* Generates component header fields using the passed {@link ComponentHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */ public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { componentGridDecorator.generateHeaders(generator); return this; } /** * Generates text header fields using the passed {@link TextHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */ public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { componentGridDecorator.generateHeaders(generator); return this; } /** * Generates html header fields using the passed {@link HtmlHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.v7.ui.Grid; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import java.util.Collection; * Generates component header fields using the passed {@link ComponentHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */ public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { componentGridDecorator.generateHeaders(generator); return this; } /** * Generates text header fields using the passed {@link TextHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */ public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { componentGridDecorator.generateHeaders(generator); return this; } /** * Generates html header fields using the passed {@link HtmlHeaderGenerator} and * sets them to the columns. * * @param generator the header generator * @return the grid for method chaining */
public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) {
datenhahn/componentrenderer
componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/TestbenchCachingGridTab.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // }
import com.vaadin.server.Sizeable; import com.vaadin.ui.Component; import com.vaadin.ui.TabSheet; import com.vaadin.v7.ui.ComboBox; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.VerticalLayout; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import java.util.HashMap; import java.util.Map;
/* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.demo; /** * Regression Test for * Issue #32: Vanishing components, when using cached components * * see also * * https://github.com/datenhahn/componentrenderer/pull/31 * * @author Jonas Hahn ([email protected]) */ public class TestbenchCachingGridTab extends VerticalLayout { public TestbenchCachingGridTab() { init(); }
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // Path: componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/TestbenchCachingGridTab.java import com.vaadin.server.Sizeable; import com.vaadin.ui.Component; import com.vaadin.ui.TabSheet; import com.vaadin.v7.ui.ComboBox; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.VerticalLayout; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import java.util.HashMap; import java.util.Map; /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.demo; /** * Regression Test for * Issue #32: Vanishing components, when using cached components * * see also * * https://github.com/datenhahn/componentrenderer/pull/31 * * @author Jonas Hahn ([email protected]) */ public class TestbenchCachingGridTab extends VerticalLayout { public TestbenchCachingGridTab() { init(); }
class TestComponentGenerator implements ComponentGenerator<Customer> {
datenhahn/componentrenderer
componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/TestbenchCachingGridTab.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // }
import com.vaadin.server.Sizeable; import com.vaadin.ui.Component; import com.vaadin.ui.TabSheet; import com.vaadin.v7.ui.ComboBox; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.VerticalLayout; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import java.util.HashMap; import java.util.Map;
return comboBox; } private ComboBox create(final Customer data) { final ComboBox comboBox = new ComboBox(); comboBox.setWidth(150, Sizeable.Unit.PIXELS); comboBox.setHeight(50, Sizeable.Unit.PIXELS); comboBox.addItems(Customer.Food.FISH, Customer.Food.HAMBURGER, Customer.Food.VEGETABLES); comboBox.setValue(data.getFood()); return comboBox; } } private void init() { setSizeFull(); setMargin(true); setSpacing(true); TabSheet sheet = new TabSheet(); sheet.setSizeFull(); sheet.addTab(createGrid(), "Tab 1"); sheet.addTab(createGrid(), "Tab 2"); addComponent(sheet); setExpandRatio(sheet, 1.0f); } private Grid createGrid() {
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // Path: componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/TestbenchCachingGridTab.java import com.vaadin.server.Sizeable; import com.vaadin.ui.Component; import com.vaadin.ui.TabSheet; import com.vaadin.v7.ui.ComboBox; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.VerticalLayout; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import java.util.HashMap; import java.util.Map; return comboBox; } private ComboBox create(final Customer data) { final ComboBox comboBox = new ComboBox(); comboBox.setWidth(150, Sizeable.Unit.PIXELS); comboBox.setHeight(50, Sizeable.Unit.PIXELS); comboBox.addItems(Customer.Food.FISH, Customer.Food.HAMBURGER, Customer.Food.VEGETABLES); comboBox.setValue(data.getFood()); return comboBox; } } private void init() { setSizeFull(); setMargin(true); setSpacing(true); TabSheet sheet = new TabSheet(); sheet.setSizeFull(); sheet.addTab(createGrid(), "Tab 1"); sheet.addTab(createGrid(), "Tab 2"); addComponent(sheet); setExpandRatio(sheet, 1.0f); } private Grid createGrid() {
ComponentGrid<Customer> grid = new ComponentGrid<>(Customer.class);
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/testbench/MemoryIT.java
// Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/testbench/util/JmxMemoryUtil.java // public class JmxMemoryUtil { // private ObjectName memory; // private MBeanServerConnection remote; // private JMXServiceURL target; // // public JmxMemoryUtil() throws IOException, AttachNotSupportedException, AgentLoadException, // AgentInitializationException, AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, MalformedObjectNameException { // final AttachProvider attachProvider = AttachProvider.providers().get(0); // // VirtualMachineDescriptor descriptor = null; // for (VirtualMachineDescriptor virtualMachineDescriptor : attachProvider.listVirtualMachines()) { // descriptor = virtualMachineDescriptor; // if (isJettyDescriptor(descriptor)) { // break; // } // } // // if (descriptor == null) { // throw new RuntimeException("No jetty descriptor found, did you start jetty using mvn jetty:run?"); // } // // final VirtualMachine virtualMachine = attachProvider.attachVirtualMachine(descriptor); // virtualMachine.loadAgent(System.getProperty("java.home") // + "/../jre/lib/management-agent.jar", "com.sun.management.jmxremote"); // final Object // portObject = // virtualMachine.getAgentProperties().get("com.sun.management.jmxremote.localConnectorAddress"); // // target = new JMXServiceURL(portObject + ""); // // // } // // private void reconnect() throws IOException, MalformedObjectNameException { // final JMXConnector connector = JMXConnectorFactory.connect(target); // remote = connector.getMBeanServerConnection(); // memory = new ObjectName("java.lang:type=Memory"); // } // // public long currentMem() throws AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, IOException, MalformedObjectNameException // { // reconnect(); // CompositeData cd = (CompositeData) remote.getAttribute(memory, "HeapMemoryUsage"); // return ((Long) cd.get("used")) / 1024; // } // // public long maxMem() throws AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, IOException, MalformedObjectNameException // { // reconnect(); // CompositeData cd = (CompositeData) remote.getAttribute(memory, "HeapMemoryUsage"); // return ((Long) cd.get("max")) / 1024; // } // // public String memString() throws AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, IOException, MalformedObjectNameException // { // return currentMem() + " / " + maxMem() + " used"; // } // // public void forceGc() throws ReflectionException, MBeanException, InstanceNotFoundException, IOException, // MalformedObjectNameException { // reconnect(); // remote.invoke(memory, "gc", null, null); // try { // Thread.sleep(100); // remote.invoke(memory, "gc", null, null); // Thread.sleep(100); // remote.invoke(memory, "gc", null, null); // Thread.sleep(100); // } catch (InterruptedException e) { // e.printStackTrace(); // } // } // // private boolean isJettyDescriptor(VirtualMachineDescriptor virtualMachineDescriptor) { // if (virtualMachineDescriptor.displayName() // .equals("org.codehaus.plexus.classworlds.launcher.Launcher jetty:run")) // { // System.out.println(virtualMachineDescriptor.displayName()); // return true; // } // return false; // } // }
import com.vaadin.testbench.elements.GridElement; import de.datenhahn.vaadin.componentrenderer.testbench.util.JmxMemoryUtil; import org.apache.commons.lang3.time.StopWatch; import org.junit.Test; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.Is.is; import static org.junit.Assert.fail;
System.out.println(" BATCH_SIZE: " + BATCH_SIZE); setupOperaDriver(); getDriver().get("http://localhost:8080/testbench"); runMemoryTest(); } public void profileInternetExplorer() throws InterruptedException, IOException { System.out.println("\n\n=== Test Internet Explorer"); System.out.println(" BATCH_SIZE: " + BATCH_SIZE); setupInternetExplorerDriverDriver(); getDriver().get("http://localhost:8080/testbench"); for (int i = 1; i <= 3; i++) { runMemoryTest(); } } /** * This test scrolls MAX_SCROLL lines in BATCH_SIZE lines per scroll. * And outputs the memory usage after every scroll. The heap size * before and after the scroll is recorded. * After the scroll a garbage collection is triggered and it is * checked that there is no memory leak (memory which can't be collected). */ private void runMemoryTest() throws IOException { try {
// Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/testbench/util/JmxMemoryUtil.java // public class JmxMemoryUtil { // private ObjectName memory; // private MBeanServerConnection remote; // private JMXServiceURL target; // // public JmxMemoryUtil() throws IOException, AttachNotSupportedException, AgentLoadException, // AgentInitializationException, AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, MalformedObjectNameException { // final AttachProvider attachProvider = AttachProvider.providers().get(0); // // VirtualMachineDescriptor descriptor = null; // for (VirtualMachineDescriptor virtualMachineDescriptor : attachProvider.listVirtualMachines()) { // descriptor = virtualMachineDescriptor; // if (isJettyDescriptor(descriptor)) { // break; // } // } // // if (descriptor == null) { // throw new RuntimeException("No jetty descriptor found, did you start jetty using mvn jetty:run?"); // } // // final VirtualMachine virtualMachine = attachProvider.attachVirtualMachine(descriptor); // virtualMachine.loadAgent(System.getProperty("java.home") // + "/../jre/lib/management-agent.jar", "com.sun.management.jmxremote"); // final Object // portObject = // virtualMachine.getAgentProperties().get("com.sun.management.jmxremote.localConnectorAddress"); // // target = new JMXServiceURL(portObject + ""); // // // } // // private void reconnect() throws IOException, MalformedObjectNameException { // final JMXConnector connector = JMXConnectorFactory.connect(target); // remote = connector.getMBeanServerConnection(); // memory = new ObjectName("java.lang:type=Memory"); // } // // public long currentMem() throws AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, IOException, MalformedObjectNameException // { // reconnect(); // CompositeData cd = (CompositeData) remote.getAttribute(memory, "HeapMemoryUsage"); // return ((Long) cd.get("used")) / 1024; // } // // public long maxMem() throws AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, IOException, MalformedObjectNameException // { // reconnect(); // CompositeData cd = (CompositeData) remote.getAttribute(memory, "HeapMemoryUsage"); // return ((Long) cd.get("max")) / 1024; // } // // public String memString() throws AttributeNotFoundException, MBeanException, ReflectionException, // InstanceNotFoundException, IOException, MalformedObjectNameException // { // return currentMem() + " / " + maxMem() + " used"; // } // // public void forceGc() throws ReflectionException, MBeanException, InstanceNotFoundException, IOException, // MalformedObjectNameException { // reconnect(); // remote.invoke(memory, "gc", null, null); // try { // Thread.sleep(100); // remote.invoke(memory, "gc", null, null); // Thread.sleep(100); // remote.invoke(memory, "gc", null, null); // Thread.sleep(100); // } catch (InterruptedException e) { // e.printStackTrace(); // } // } // // private boolean isJettyDescriptor(VirtualMachineDescriptor virtualMachineDescriptor) { // if (virtualMachineDescriptor.displayName() // .equals("org.codehaus.plexus.classworlds.launcher.Launcher jetty:run")) // { // System.out.println(virtualMachineDescriptor.displayName()); // return true; // } // return false; // } // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/testbench/MemoryIT.java import com.vaadin.testbench.elements.GridElement; import de.datenhahn.vaadin.componentrenderer.testbench.util.JmxMemoryUtil; import org.apache.commons.lang3.time.StopWatch; import org.junit.Test; import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.Is.is; import static org.junit.Assert.fail; System.out.println(" BATCH_SIZE: " + BATCH_SIZE); setupOperaDriver(); getDriver().get("http://localhost:8080/testbench"); runMemoryTest(); } public void profileInternetExplorer() throws InterruptedException, IOException { System.out.println("\n\n=== Test Internet Explorer"); System.out.println(" BATCH_SIZE: " + BATCH_SIZE); setupInternetExplorerDriverDriver(); getDriver().get("http://localhost:8080/testbench"); for (int i = 1; i <= 3; i++) { runMemoryTest(); } } /** * This test scrolls MAX_SCROLL lines in BATCH_SIZE lines per scroll. * And outputs the memory usage after every scroll. The heap size * before and after the scroll is recorded. * After the scroll a garbage collection is triggered and it is * checked that there is no memory leak (memory which can't be collected). */ private void runMemoryTest() throws IOException { try {
JmxMemoryUtil jmxMemoryUtil = new JmxMemoryUtil();
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue;
/* * Licensed under the Apache License,Version2.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. */ /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { ComponentGrid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator();
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue; /* * Licensed under the Apache License,Version2.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. */ /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { ComponentGrid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator();
assertTrue(containsExtension(grid, FocusPreserveExtension.class));
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue;
/* * Licensed under the Apache License,Version2.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. */ /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { ComponentGrid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertTrue(containsExtension(grid, FocusPreserveExtension.class));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue; /* * Licensed under the Apache License,Version2.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. */ /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { ComponentGrid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertTrue(containsExtension(grid, FocusPreserveExtension.class));
assertTrue(containsExtension(grid, DetailsKeysExtension.class));
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue;
/* * Licensed under the Apache License,Version2.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. */ /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { ComponentGrid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertTrue(containsExtension(grid, FocusPreserveExtension.class)); assertTrue(containsExtension(grid, DetailsKeysExtension.class));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue; /* * Licensed under the Apache License,Version2.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. */ /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { ComponentGrid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertTrue(containsExtension(grid, FocusPreserveExtension.class)); assertTrue(containsExtension(grid, DetailsKeysExtension.class));
assertTrue(containsExtension(grid, ComponentCellKeyExtension.class));
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue;
assertThat(grid.getContainerDataSource().getItemIds().size(), is(10)); List<ExampleBean> moreBeans = new ArrayList<>(); for(int i = 10; i < 20;i++) { ExampleBean bean = new ExampleBean(); bean.setCaption("foo" +i); bean.setIsSomething(true); moreBeans.add(bean); } grid.addAll(moreBeans); assertThat(grid.getContainerDataSource().getItemIds().size(), is(20)); } @Test public void testRefresh() { ComponentGrid grid = createTestGrid(); // just check that no exception fly grid.refresh(); } @Test public void testGenerateTextHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue; assertThat(grid.getContainerDataSource().getItemIds().size(), is(10)); List<ExampleBean> moreBeans = new ArrayList<>(); for(int i = 10; i < 20;i++) { ExampleBean bean = new ExampleBean(); bean.setCaption("foo" +i); bean.setIsSomething(true); moreBeans.add(bean); } grid.addAll(moreBeans); assertThat(grid.getContainerDataSource().getItemIds().size(), is(20)); } @Test public void testRefresh() { ComponentGrid grid = createTestGrid(); // just check that no exception fly grid.refresh(); } @Test public void testGenerateTextHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
grid.generateHeaders(new TextHeaderGenerator() {
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue;
// just check that no exception fly grid.refresh(); } @Test public void testGenerateTextHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); grid.generateHeaders(new TextHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "TEXT:"+ propertyId; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue; // just check that no exception fly grid.refresh(); } @Test public void testGenerateTextHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); grid.generateHeaders(new TextHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "TEXT:"+ propertyId; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
grid.generateHeaders(new HtmlHeaderGenerator() {
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue;
headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); grid.generateHeaders(new HtmlHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "HTML:<b>"+ propertyId + "</b>"; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getHtml(); assertThat(headerText, is("HTML:<b>caption</b>")); } @Test public void testGenerateComponentHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.hamcrest.core.Is; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertTrue; headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); grid.generateHeaders(new HtmlHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "HTML:<b>"+ propertyId + "</b>"; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getHtml(); assertThat(headerText, is("HTML:<b>caption</b>")); } @Test public void testGenerateComponentHeaders() { ComponentGrid grid = createTestGrid(); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
grid.generateHeaders(new ComponentHeaderGenerator() {
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
/* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridDecoratorTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { Grid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator();
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridDecoratorTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { Grid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator();
assertFalse(containsExtension(grid, FocusPreserveExtension.class));
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
/* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridDecoratorTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { Grid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertFalse(containsExtension(grid, FocusPreserveExtension.class));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridDecoratorTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { Grid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertFalse(containsExtension(grid, FocusPreserveExtension.class));
assertFalse(containsExtension(grid, DetailsKeysExtension.class));
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
/* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridDecoratorTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { Grid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertFalse(containsExtension(grid, FocusPreserveExtension.class)); assertFalse(containsExtension(grid, DetailsKeysExtension.class));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /* * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.grid; public class ComponentGridDecoratorTest { public static final String COLUMN_CAPTION = "caption"; public static final String FOO_0 = "foo0"; @Test public void testDecoration() { Grid grid = createTestGrid(); Grid.DetailsGenerator detailsGenerator = grid.getDetailsGenerator(); assertFalse(containsExtension(grid, FocusPreserveExtension.class)); assertFalse(containsExtension(grid, DetailsKeysExtension.class));
assertFalse(containsExtension(grid, ComponentCellKeyExtension.class));
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
Object firstBean = grid.getContainerDataSource().getIdByIndex(0); assertThat(grid.getContainerDataSource().getItemIds().size(), is(10)); assertThat(grid.getContainerDataSource().getItemIds().contains(firstBean), is(true)); decorator.remove((ExampleBean)firstBean); assertThat(grid.getContainerDataSource().getItemIds().size(), is(9)); assertThat(grid.getContainerDataSource().getItemIds().contains(firstBean), is(false)); decorator.add((ExampleBean) firstBean); assertThat(grid.getContainerDataSource().getItemIds().size(), is(10)); assertThat(grid.getContainerDataSource().getItemIds().contains(firstBean), is(true)); } @Test public void testRefresh() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); // just check that no exception fly decorator.refresh(); } @Test public void testGenerateTextHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; Object firstBean = grid.getContainerDataSource().getIdByIndex(0); assertThat(grid.getContainerDataSource().getItemIds().size(), is(10)); assertThat(grid.getContainerDataSource().getItemIds().contains(firstBean), is(true)); decorator.remove((ExampleBean)firstBean); assertThat(grid.getContainerDataSource().getItemIds().size(), is(9)); assertThat(grid.getContainerDataSource().getItemIds().contains(firstBean), is(false)); decorator.add((ExampleBean) firstBean); assertThat(grid.getContainerDataSource().getItemIds().size(), is(10)); assertThat(grid.getContainerDataSource().getItemIds().contains(firstBean), is(true)); } @Test public void testRefresh() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); // just check that no exception fly decorator.refresh(); } @Test public void testGenerateTextHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
decorator.generateHeaders(new TextHeaderGenerator() {
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
decorator.refresh(); } @Test public void testGenerateTextHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new TextHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "TEXT:"+ propertyId; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; decorator.refresh(); } @Test public void testGenerateTextHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new TextHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "TEXT:"+ propertyId; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
decorator.generateHeaders(new HtmlHeaderGenerator() {
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // }
import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new HtmlHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "HTML:<b>"+ propertyId + "</b>"; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getHtml(); assertThat(headerText, is("HTML:<b>caption</b>")); } @Test public void testGenerateComponentHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/ComponentCellKeyExtension.java // public class ComponentCellKeyExtension extends Grid.AbstractGridExtension { // // private ComponentCellKeyExtension(final Grid grid) { // super.extend(grid); // } // // public static ComponentCellKeyExtension extend(Grid grid) { // return new ComponentCellKeyExtension(grid); // } // // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtension.java // public class DetailsKeysExtension extends Grid.AbstractGridExtension { // // private DetailsKeysExtension(final Grid grid) { // super.extend(grid); // registerRpc(new DetailsOpenCloseServerRpcImpl(grid)); // } // // public static DetailsKeysExtension extend(Grid grid) { // return new DetailsKeysExtension(grid); // } // // public static class DetailsOpenCloseServerRpcImpl implements DetailsOpenCloseServerRpc { // private final Grid grid; // // public DetailsOpenCloseServerRpcImpl(Grid grid) { // this.grid = grid; // } // // @Override // public void setDetailsVisible(int rowIndex, boolean visible) { // Object itemId = grid.getContainerDataSource().getItemIds(rowIndex, 1).get(0); // grid.setDetailsVisible(itemId, visible); // } // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/FocusPreserveExtension.java // public class FocusPreserveExtension extends Grid.AbstractGridExtension { // private final FocusPreservingRefreshClientRpc focusRpc = getRpcProxy(FocusPreservingRefreshClientRpc.class); // // private FocusPreserveExtension(final Grid grid) { // super.extend(grid); // } // // public static FocusPreserveExtension extend(Grid grid) { // return new FocusPreserveExtension(grid); // } // // /** // * Saves the grid's current focus in this extension's internal state. // */ // public void saveFocus() { // focusRpc.saveFocus(); // } // // /** // * Restores the grid's focus from extension's internal state. // */ // public void restoreFocus() { // focusRpc.restoreFocus(); // } // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/ComponentHeaderGenerator.java // public interface ComponentHeaderGenerator extends HeaderGenerator<Component> { // // @Override // Component getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/HtmlHeaderGenerator.java // public interface HtmlHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/header/TextHeaderGenerator.java // public interface TextHeaderGenerator extends HeaderGenerator<String> { // // @Override // String getHeader(Object propertyId); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGridDecoratorTest.java import com.vaadin.v7.data.Item; import com.vaadin.v7.data.util.BeanItemContainer; import com.vaadin.v7.data.util.GeneratedPropertyContainer; import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.ComponentCellKeyExtension; import de.datenhahn.vaadin.componentrenderer.DetailsKeysExtension; import de.datenhahn.vaadin.componentrenderer.FocusPreserveExtension; import de.datenhahn.vaadin.componentrenderer.grid.header.ComponentHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.HtmlHeaderGenerator; import de.datenhahn.vaadin.componentrenderer.grid.header.TextHeaderGenerator; import org.junit.Test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; assertThat(headerText, is("TEXT:caption")); } @Test public void testGenerateHtmlHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new HtmlHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "HTML:<b>"+ propertyId + "</b>"; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getHtml(); assertThat(headerText, is("HTML:<b>caption</b>")); } @Test public void testGenerateComponentHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption"));
decorator.generateHeaders(new ComponentHeaderGenerator() {
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java // public class ExampleBean { // String caption; // Boolean isSomething; // // public Boolean getIsSomething() { // return isSomething; // } // // public void setIsSomething(Boolean isSomething) { // this.isSomething = isSomething; // } // // public String getCaption() { // return caption; // } // // public void setCaption(String caption) { // this.caption = caption; // } // }
import com.vaadin.ui.Component; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean; import elemental.json.Json; import elemental.json.JsonValue; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo;
package de.datenhahn.vaadin.componentrenderer; public class ComponentRendererTest { @Test public void encodeNullComponent() { ComponentRenderer renderer = new ComponentRenderer(); assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull())); } @Test(expected = IllegalStateException.class) public void encodeComponentWithoutBeingAttached() { ComponentRenderer renderer = new ComponentRenderer(); renderer.encode(new Label("test")); } /** * Issue #18: Removing a column with ComponentRenderer caused an exception #18 * * https://github.com/datenhahn/componentrenderer/issues/18 */ @Test public void issue18ExceptionWhenRemovingColumn() {
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java // public class ExampleBean { // String caption; // Boolean isSomething; // // public Boolean getIsSomething() { // return isSomething; // } // // public void setIsSomething(Boolean isSomething) { // this.isSomething = isSomething; // } // // public String getCaption() { // return caption; // } // // public void setCaption(String caption) { // this.caption = caption; // } // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java import com.vaadin.ui.Component; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean; import elemental.json.Json; import elemental.json.JsonValue; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; package de.datenhahn.vaadin.componentrenderer; public class ComponentRendererTest { @Test public void encodeNullComponent() { ComponentRenderer renderer = new ComponentRenderer(); assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull())); } @Test(expected = IllegalStateException.class) public void encodeComponentWithoutBeingAttached() { ComponentRenderer renderer = new ComponentRenderer(); renderer.encode(new Label("test")); } /** * Issue #18: Removing a column with ComponentRenderer caused an exception #18 * * https://github.com/datenhahn/componentrenderer/issues/18 */ @Test public void issue18ExceptionWhenRemovingColumn() {
ComponentGrid<ExampleBean> grid = new ComponentGrid<>(ExampleBean.class);
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java // public class ExampleBean { // String caption; // Boolean isSomething; // // public Boolean getIsSomething() { // return isSomething; // } // // public void setIsSomething(Boolean isSomething) { // this.isSomething = isSomething; // } // // public String getCaption() { // return caption; // } // // public void setCaption(String caption) { // this.caption = caption; // } // }
import com.vaadin.ui.Component; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean; import elemental.json.Json; import elemental.json.JsonValue; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo;
package de.datenhahn.vaadin.componentrenderer; public class ComponentRendererTest { @Test public void encodeNullComponent() { ComponentRenderer renderer = new ComponentRenderer(); assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull())); } @Test(expected = IllegalStateException.class) public void encodeComponentWithoutBeingAttached() { ComponentRenderer renderer = new ComponentRenderer(); renderer.encode(new Label("test")); } /** * Issue #18: Removing a column with ComponentRenderer caused an exception #18 * * https://github.com/datenhahn/componentrenderer/issues/18 */ @Test public void issue18ExceptionWhenRemovingColumn() {
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java // public class ExampleBean { // String caption; // Boolean isSomething; // // public Boolean getIsSomething() { // return isSomething; // } // // public void setIsSomething(Boolean isSomething) { // this.isSomething = isSomething; // } // // public String getCaption() { // return caption; // } // // public void setCaption(String caption) { // this.caption = caption; // } // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java import com.vaadin.ui.Component; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean; import elemental.json.Json; import elemental.json.JsonValue; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; package de.datenhahn.vaadin.componentrenderer; public class ComponentRendererTest { @Test public void encodeNullComponent() { ComponentRenderer renderer = new ComponentRenderer(); assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull())); } @Test(expected = IllegalStateException.class) public void encodeComponentWithoutBeingAttached() { ComponentRenderer renderer = new ComponentRenderer(); renderer.encode(new Label("test")); } /** * Issue #18: Removing a column with ComponentRenderer caused an exception #18 * * https://github.com/datenhahn/componentrenderer/issues/18 */ @Test public void issue18ExceptionWhenRemovingColumn() {
ComponentGrid<ExampleBean> grid = new ComponentGrid<>(ExampleBean.class);
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java // public class ExampleBean { // String caption; // Boolean isSomething; // // public Boolean getIsSomething() { // return isSomething; // } // // public void setIsSomething(Boolean isSomething) { // this.isSomething = isSomething; // } // // public String getCaption() { // return caption; // } // // public void setCaption(String caption) { // this.caption = caption; // } // }
import com.vaadin.ui.Component; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean; import elemental.json.Json; import elemental.json.JsonValue; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo;
package de.datenhahn.vaadin.componentrenderer; public class ComponentRendererTest { @Test public void encodeNullComponent() { ComponentRenderer renderer = new ComponentRenderer(); assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull())); } @Test(expected = IllegalStateException.class) public void encodeComponentWithoutBeingAttached() { ComponentRenderer renderer = new ComponentRenderer(); renderer.encode(new Label("test")); } /** * Issue #18: Removing a column with ComponentRenderer caused an exception #18 * * https://github.com/datenhahn/componentrenderer/issues/18 */ @Test public void issue18ExceptionWhenRemovingColumn() { ComponentGrid<ExampleBean> grid = new ComponentGrid<>(ExampleBean.class); ExampleBean bean = new ExampleBean(); bean.setCaption("Foo"); grid.add(bean);
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java // public interface ComponentGenerator<T> extends Serializable { // // /** // * Called to generate the component for a component cell based // * on the passed typed bean. // * // * @param bean the bean being the source for the current row's data // * @return a <b>new</b> instance of the component used to display the data // */ // Component getComponent(T bean); // } // // Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java // public class ExampleBean { // String caption; // Boolean isSomething; // // public Boolean getIsSomething() { // return isSomething; // } // // public void setIsSomething(Boolean isSomething) { // this.isSomething = isSomething; // } // // public String getCaption() { // return caption; // } // // public void setCaption(String caption) { // this.caption = caption; // } // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java import com.vaadin.ui.Component; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean; import elemental.json.Json; import elemental.json.JsonValue; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; package de.datenhahn.vaadin.componentrenderer; public class ComponentRendererTest { @Test public void encodeNullComponent() { ComponentRenderer renderer = new ComponentRenderer(); assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull())); } @Test(expected = IllegalStateException.class) public void encodeComponentWithoutBeingAttached() { ComponentRenderer renderer = new ComponentRenderer(); renderer.encode(new Label("test")); } /** * Issue #18: Removing a column with ComponentRenderer caused an exception #18 * * https://github.com/datenhahn/componentrenderer/issues/18 */ @Test public void issue18ExceptionWhenRemovingColumn() { ComponentGrid<ExampleBean> grid = new ComponentGrid<>(ExampleBean.class); ExampleBean bean = new ExampleBean(); bean.setCaption("Foo"); grid.add(bean);
grid.addComponentColumn("caption", new ComponentGenerator<ExampleBean>() {
datenhahn/componentrenderer
componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/TestbenchComponentGridTab.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // }
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import com.vaadin.ui.Button; import com.vaadin.v7.ui.Label; import com.vaadin.v7.ui.VerticalLayout;
/* * Licensed under the Apache License,Version2.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. */ /** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.demo; /** * Demonstrates the use of the typed ComponentGrid * * @author Jonas Hahn ([email protected]) */ public class TestbenchComponentGridTab extends VerticalLayout { private static final String GENERATED_FOOD_ICON = "foodIcon"; private static final String GENERATED_RATING = "rating"; private static final String GENERATED_DELETE = "delete"; private static final String GENERATED_DETAILS_ICONS = "detailsIcons"; public TestbenchComponentGridTab() { init(); } private void init() { setSizeFull(); setMargin(true); setSpacing(true); addComponent(new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using" + " the classic grid"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // Path: componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/TestbenchComponentGridTab.java import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import com.vaadin.ui.Button; import com.vaadin.v7.ui.Label; import com.vaadin.v7.ui.VerticalLayout; /* * Licensed under the Apache License,Version2.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. */ /** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.demo; /** * Demonstrates the use of the typed ComponentGrid * * @author Jonas Hahn ([email protected]) */ public class TestbenchComponentGridTab extends VerticalLayout { private static final String GENERATED_FOOD_ICON = "foodIcon"; private static final String GENERATED_RATING = "rating"; private static final String GENERATED_DELETE = "delete"; private static final String GENERATED_DETAILS_ICONS = "detailsIcons"; public TestbenchComponentGridTab() { init(); } private void init() { setSizeFull(); setMargin(true); setSpacing(true); addComponent(new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using" + " the classic grid"));
ComponentGrid<Customer> grid = new ComponentGrid<>(Customer.class);
datenhahn/componentrenderer
componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/ComponentGridTab.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // }
import com.vaadin.v7.ui.VerticalLayout; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import com.vaadin.v7.ui.Label;
/** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.demo; /** * Demonstrates the use of the typed ComponentGrid * * @author Jonas Hahn ([email protected]) */ public class ComponentGridTab extends VerticalLayout { private static final String GENERATED_FOOD_ICON = "foodIcon"; private static final String GENERATED_RATING = "rating"; private static final String GENERATED_DELETE = "delete"; private static final String GENERATED_DETAILS_ICONS = "detailsIcons"; public ComponentGridTab() { init(); } private void init() { setSizeFull(); setMargin(true); setSpacing(true); addComponent(new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using" + " the classic grid"));
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java // public class ComponentGrid<T> extends Grid { // // private final ComponentGridDecorator<T> componentGridDecorator; // // public ComponentGrid(Class<T> typeOfRows) { // super(); // setContainerDataSource(new BeanItemContainer<T>(typeOfRows)); // componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows); // } // // public ComponentGridDecorator<T> getComponentGridDecorator() { // return componentGridDecorator; // } // // public FocusPreserveExtension getFocusPreserveExtension() { // return componentGridDecorator.getFocusPreserveExtension(); // } // // /** // * Remove a bean from the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> remove(T bean) { // componentGridDecorator.remove(bean); // return this; // } // // /** // * Add a bean to the grid. // * // * @return the decorator for method chaining // */ // public ComponentGrid<T> add(T bean) { // componentGridDecorator.add(bean); // return this; // } // // /** // * Add all beans to the decorated grid's container. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> addAll(Collection<T> beans) { // componentGridDecorator.addAll(beans); // return this; // } // // /** // * Add a generated component column to the ComponentGrid. // * // * @param propertyId the generated column's property-id // * @param generator the component-generator // * @return the grid for method chaining // */ // public Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator) { // return componentGridDecorator.addComponentColumn(propertyId, generator); // } // // /** // * Refreshes the grid preserving its current cell focus. // */ // public ComponentGrid<T> refresh() { // componentGridDecorator.refresh(); // return this; // } // // /** // * Remove all items from the underlying {@link BeanItemContainer} and add // * the new beans. // * // * @param beans a collection of beans // * @return the grid for method chaining // */ // public ComponentGrid<T> setRows(Collection<T> beans) { // componentGridDecorator.setRows(beans); // return this; // } // /** // * Generates component header fields using the passed {@link ComponentHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates text header fields using the passed {@link TextHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // // /** // * Generates html header fields using the passed {@link HtmlHeaderGenerator} and // * sets them to the columns. // * // * @param generator the header generator // * @return the grid for method chaining // */ // public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) { // componentGridDecorator.generateHeaders(generator); // return this; // } // } // Path: componentrenderer-demo/src/main/java/de/datenhahn/vaadin/componentrenderer/demo/ComponentGridTab.java import com.vaadin.v7.ui.VerticalLayout; import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid; import com.vaadin.v7.ui.Label; /** * Licensed under the Apache License,Version2.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 de.datenhahn.vaadin.componentrenderer.demo; /** * Demonstrates the use of the typed ComponentGrid * * @author Jonas Hahn ([email protected]) */ public class ComponentGridTab extends VerticalLayout { private static final String GENERATED_FOOD_ICON = "foodIcon"; private static final String GENERATED_RATING = "rating"; private static final String GENERATED_DELETE = "delete"; private static final String GENERATED_DETAILS_ICONS = "detailsIcons"; public ComponentGridTab() { init(); } private void init() { setSizeFull(); setMargin(true); setSpacing(true); addComponent(new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using" + " the classic grid"));
ComponentGrid<Customer> grid = new ComponentGrid<>(Customer.class);
datenhahn/componentrenderer
componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtensionTest.java
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/client/detailskeys/DetailsOpenCloseServerRpc.java // public interface DetailsOpenCloseServerRpc extends ServerRpc { // // /** // * Sets the details of a row visible or hidden. // * // * @param rowIndex the rowIndex of the row, this is the rowIndex of an IndexedContainer, // * this is NOT the rowId (= id in the container) or the // * rowKey (= internal key in clienside grid implementation) // * @param visible set the details to visible (= true) or hidden (= false) // */ // void setDetailsVisible(int rowIndex, boolean visible); // }
import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.client.detailskeys.DetailsOpenCloseServerRpc; import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
assertFalse(grid.isDetailsVisible(id)); } private Grid createTestGrid() { Grid grid = new Grid(); grid.addColumn("rows"); grid.setDetailsGenerator(new Grid.DetailsGenerator() { @Override public Component getDetails(Grid.RowReference rowReference) { return new Label("foo"); } }); for(int i = 0; i <= 10;i++) { grid.addRow("foo"+i); } return grid; } private boolean containsDetailsGridExtension(Grid grid) { for (Extension extension : grid.getExtensions()) { if (extension instanceof DetailsKeysExtension) { return true; } } return false; } private boolean hasDetailsGridExtensionRpc(DetailsKeysExtension extension) {
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/client/detailskeys/DetailsOpenCloseServerRpc.java // public interface DetailsOpenCloseServerRpc extends ServerRpc { // // /** // * Sets the details of a row visible or hidden. // * // * @param rowIndex the rowIndex of the row, this is the rowIndex of an IndexedContainer, // * this is NOT the rowId (= id in the container) or the // * rowKey (= internal key in clienside grid implementation) // * @param visible set the details to visible (= true) or hidden (= false) // */ // void setDetailsVisible(int rowIndex, boolean visible); // } // Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/DetailsKeysExtensionTest.java import com.vaadin.server.Extension; import com.vaadin.ui.Component; import com.vaadin.v7.ui.Grid; import com.vaadin.v7.ui.Label; import de.datenhahn.vaadin.componentrenderer.client.detailskeys.DetailsOpenCloseServerRpc; import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; assertFalse(grid.isDetailsVisible(id)); } private Grid createTestGrid() { Grid grid = new Grid(); grid.addColumn("rows"); grid.setDetailsGenerator(new Grid.DetailsGenerator() { @Override public Component getDetails(Grid.RowReference rowReference) { return new Label("foo"); } }); for(int i = 0; i <= 10;i++) { grid.addRow("foo"+i); } return grid; } private boolean containsDetailsGridExtension(Grid grid) { for (Extension extension : grid.getExtensions()) { if (extension instanceof DetailsKeysExtension) { return true; } } return false; } private boolean hasDetailsGridExtensionRpc(DetailsKeysExtension extension) {
return extension.getRpcManager(DetailsOpenCloseServerRpc.class.getName()) != null;
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/version/VersionUtils.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/Repertories.java // public class Repertories { // public static final String HOST = "po.ittianyu.com"; // public static final String URL_BASE = "https://" + HOST + "/"; // // private RemoteApi remoteApi; // private CacheApi cacheApi; // private List<String> types = new ArrayList<>(); // // public Repertories(File cacheDir) { // // create apis // cacheApi = new RxCache.Builder() // .useExpiredDataIfLoaderNotAvailable(true) // .persistence(cacheDir, new GsonSpeaker()) // .using(CacheApi.class); // // remoteApi = new Retrofit.Builder() // .baseUrl(URL_BASE) // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory(GsonConverterFactory.create()) // .client(UnsafeOkHttpUtils.getClient()) // .build() // .create(RemoteApi.class); // // // add types // Context context = BaseApplication.getContext(); // types.add(context.getString(R.string.type_other)); // types.add(context.getString(R.string.type_web)); // types.add(context.getString(R.string.type_we_chat)); // types.add(context.getString(R.string.type_html5)); // types.add(context.getString(R.string.type_app)); // types.add(context.getString(R.string.type_intelligent_hardware)); // types.add(context.getString(R.string.type_desktop_app)); // types.add(context.getString(R.string.type_big_data)); // types.add(context.getString(R.string.type_system)); // types.add(context.getString(R.string.type_sdk_api)); // types.add(context.getString(R.string.type_art)); // } // // public Observable<List<ProjectBean>> getList(int start, int count, int[] types, int status, String[] keywords, boolean update) { // String key = generateKey(start, count, types, status, keywords); // return cacheApi.getList(remoteApi.getList(start, count, types, status, keywords), // new DynamicKey(key), new EvictDynamicKey(update)) // .compose(RxUtils.<List<ProjectBean>>netScheduler());// net on io thread, subscribe on main thread // // return remoteApi.getList(start, count, types, status, keywords) // // .compose(RxUtils.<List<ProjectBean>>netScheduler());// net on io thread, subscribe on main thread // } // // /** // * according params to generate key // * @param start // * @param count // * @param types // * @param status // * @param keywords // * @return // */ // @NonNull // private String generateKey(int start, int count, int[] types, int status, String[] keywords) { // StringBuilder keyBuilder = new StringBuilder("start=" + start + "&count=" + count); // if (null != types && types.length > 0) { // Arrays.sort(types); // for (int type : types) { // keyBuilder.append("&type=" + type); // } // } // keyBuilder.append("&status=" + status); // if (null != keywords && keywords.length > 0) { // Arrays.sort(keywords); // for (String keyword : keywords) { // keyBuilder.append("&keyword=" + keyword); // } // } // return keyBuilder.toString(); // } // // public List<String> getAllTypes() { // return types; // } // // public boolean isSettingTypes() { // // load config // String type = ConfigUtils.getString(BaseApplication.getContext(), ConfigUtils.KEY_TYPE, ""); // if (TextUtils.isEmpty(type)) // return false; // return true; // } // // public int[] getTypes() { // String type = ConfigUtils.getString(BaseApplication.getContext(), ConfigUtils.KEY_TYPE, ""); // if (TextUtils.isEmpty(type)) // return null; // String[] typesString = type.split(","); // if (0 == typesString.length) // return null; // // int[] types = new int[typesString.length]; // for (int i = 0; i < typesString.length; i++) { // types[i] = Integer.parseInt(typesString[i]); // } // return types; // } // // public void setTypes(Set<Integer> set) { // // create types string // StringBuilder typeBuilder = new StringBuilder(); // for (int type : set) { // typeBuilder.append(type); // typeBuilder.append(','); // } // typeBuilder.deleteCharAt(typeBuilder.length() - 1);// delete the last ',' // // save to file // ConfigUtils.putString(BaseApplication.getContext(), ConfigUtils.KEY_TYPE, typeBuilder.toString()); // } // }
import android.content.Context; import android.content.Intent; import com.allenliu.versionchecklib.VersionParams; import com.ittianyu.pocenter.common.api.Repertories;
package com.ittianyu.pocenter.features.version; /** * Created by yu on 2017/1/19. */ public class VersionUtils { /** * check version * @param context */ public static void check(Context context) { check(context, false); } /** * check version * @param context * @param showLast it will show a tip tell user the version is last if true. */ public static void check(Context context, boolean showLast) { VersionParams versionField = new VersionParams() //是否强制升级,默认false .setIsForceUpdate(false) //当版本接口请求失败时,service会根据设定的间隔时间继续请求版本接口, // 直到手动关闭service或者接口请求成功,不填默认10s // .setPauseRequestTime(requestTime) //接口地址,必填
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/Repertories.java // public class Repertories { // public static final String HOST = "po.ittianyu.com"; // public static final String URL_BASE = "https://" + HOST + "/"; // // private RemoteApi remoteApi; // private CacheApi cacheApi; // private List<String> types = new ArrayList<>(); // // public Repertories(File cacheDir) { // // create apis // cacheApi = new RxCache.Builder() // .useExpiredDataIfLoaderNotAvailable(true) // .persistence(cacheDir, new GsonSpeaker()) // .using(CacheApi.class); // // remoteApi = new Retrofit.Builder() // .baseUrl(URL_BASE) // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory(GsonConverterFactory.create()) // .client(UnsafeOkHttpUtils.getClient()) // .build() // .create(RemoteApi.class); // // // add types // Context context = BaseApplication.getContext(); // types.add(context.getString(R.string.type_other)); // types.add(context.getString(R.string.type_web)); // types.add(context.getString(R.string.type_we_chat)); // types.add(context.getString(R.string.type_html5)); // types.add(context.getString(R.string.type_app)); // types.add(context.getString(R.string.type_intelligent_hardware)); // types.add(context.getString(R.string.type_desktop_app)); // types.add(context.getString(R.string.type_big_data)); // types.add(context.getString(R.string.type_system)); // types.add(context.getString(R.string.type_sdk_api)); // types.add(context.getString(R.string.type_art)); // } // // public Observable<List<ProjectBean>> getList(int start, int count, int[] types, int status, String[] keywords, boolean update) { // String key = generateKey(start, count, types, status, keywords); // return cacheApi.getList(remoteApi.getList(start, count, types, status, keywords), // new DynamicKey(key), new EvictDynamicKey(update)) // .compose(RxUtils.<List<ProjectBean>>netScheduler());// net on io thread, subscribe on main thread // // return remoteApi.getList(start, count, types, status, keywords) // // .compose(RxUtils.<List<ProjectBean>>netScheduler());// net on io thread, subscribe on main thread // } // // /** // * according params to generate key // * @param start // * @param count // * @param types // * @param status // * @param keywords // * @return // */ // @NonNull // private String generateKey(int start, int count, int[] types, int status, String[] keywords) { // StringBuilder keyBuilder = new StringBuilder("start=" + start + "&count=" + count); // if (null != types && types.length > 0) { // Arrays.sort(types); // for (int type : types) { // keyBuilder.append("&type=" + type); // } // } // keyBuilder.append("&status=" + status); // if (null != keywords && keywords.length > 0) { // Arrays.sort(keywords); // for (String keyword : keywords) { // keyBuilder.append("&keyword=" + keyword); // } // } // return keyBuilder.toString(); // } // // public List<String> getAllTypes() { // return types; // } // // public boolean isSettingTypes() { // // load config // String type = ConfigUtils.getString(BaseApplication.getContext(), ConfigUtils.KEY_TYPE, ""); // if (TextUtils.isEmpty(type)) // return false; // return true; // } // // public int[] getTypes() { // String type = ConfigUtils.getString(BaseApplication.getContext(), ConfigUtils.KEY_TYPE, ""); // if (TextUtils.isEmpty(type)) // return null; // String[] typesString = type.split(","); // if (0 == typesString.length) // return null; // // int[] types = new int[typesString.length]; // for (int i = 0; i < typesString.length; i++) { // types[i] = Integer.parseInt(typesString[i]); // } // return types; // } // // public void setTypes(Set<Integer> set) { // // create types string // StringBuilder typeBuilder = new StringBuilder(); // for (int type : set) { // typeBuilder.append(type); // typeBuilder.append(','); // } // typeBuilder.deleteCharAt(typeBuilder.length() - 1);// delete the last ',' // // save to file // ConfigUtils.putString(BaseApplication.getContext(), ConfigUtils.KEY_TYPE, typeBuilder.toString()); // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/version/VersionUtils.java import android.content.Context; import android.content.Intent; import com.allenliu.versionchecklib.VersionParams; import com.ittianyu.pocenter.common.api.Repertories; package com.ittianyu.pocenter.features.version; /** * Created by yu on 2017/1/19. */ public class VersionUtils { /** * check version * @param context */ public static void check(Context context) { check(context, false); } /** * check version * @param context * @param showLast it will show a tip tell user the version is last if true. */ public static void check(Context context, boolean showLast) { VersionParams versionField = new VersionParams() //是否强制升级,默认false .setIsForceUpdate(false) //当版本接口请求失败时,service会根据设定的间隔时间继续请求版本接口, // 直到手动关闭service或者接口请求成功,不填默认10s // .setPauseRequestTime(requestTime) //接口地址,必填
.setRequestUrl(Repertories.URL_BASE + "version.json")
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/find/FindAdapter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale;
package com.ittianyu.pocenter.features.find; /** * Created by yu on 2017/1/17. */ public class FindAdapter extends BaseQuickAdapter<ProjectBean, BaseViewHolder> { public FindAdapter(List<ProjectBean> data) { super(R.layout.item_find, data); } @Override protected void convert(BaseViewHolder baseViewHolder, ProjectBean projectBean) { baseViewHolder.setText(R.id.tv_title, projectBean.title); baseViewHolder.setText(R.id.tv_price, projectBean.price); // baseViewHolder.setText(R.id.tv_reference, projectBean.reference); baseViewHolder.setText(R.id.tv_type, transferType(projectBean.type)); baseViewHolder.setText(R.id.tv_description, projectBean.description); baseViewHolder.setText(R.id.tv_date, new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE).format(projectBean.time)); baseViewHolder.setText(R.id.tv_people_count, projectBean.people + mContext.getString(R.string.unit_people)); baseViewHolder.setText(R.id.tv_cycle, projectBean.cycle + mContext.getString(R.string.unit_day)); } /** * transfer type from code to string * @param type * @return */ private String transferType(int type) {
// Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/find/FindAdapter.java import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; package com.ittianyu.pocenter.features.find; /** * Created by yu on 2017/1/17. */ public class FindAdapter extends BaseQuickAdapter<ProjectBean, BaseViewHolder> { public FindAdapter(List<ProjectBean> data) { super(R.layout.item_find, data); } @Override protected void convert(BaseViewHolder baseViewHolder, ProjectBean projectBean) { baseViewHolder.setText(R.id.tv_title, projectBean.title); baseViewHolder.setText(R.id.tv_price, projectBean.price); // baseViewHolder.setText(R.id.tv_reference, projectBean.reference); baseViewHolder.setText(R.id.tv_type, transferType(projectBean.type)); baseViewHolder.setText(R.id.tv_description, projectBean.description); baseViewHolder.setText(R.id.tv_date, new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE).format(projectBean.time)); baseViewHolder.setText(R.id.tv_people_count, projectBean.people + mContext.getString(R.string.unit_people)); baseViewHolder.setText(R.id.tv_cycle, projectBean.cycle + mContext.getString(R.string.unit_day)); } /** * transfer type from code to string * @param type * @return */ private String transferType(int type) {
List<String> types = BaseApplication.getRepertories().getAllTypes();
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/search/SearchAdapter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale;
package com.ittianyu.pocenter.features.search; /** * Created by yu on 2017/1/17. */ public class SearchAdapter extends BaseQuickAdapter<ProjectBean, BaseViewHolder> { public SearchAdapter(List<ProjectBean> data) { super(R.layout.item_search, data); } @Override protected void convert(BaseViewHolder baseViewHolder, ProjectBean projectBean) { baseViewHolder.setText(R.id.tv_title, projectBean.title); baseViewHolder.setText(R.id.tv_price, projectBean.price); // baseViewHolder.setText(R.id.tv_reference, projectBean.reference); // baseViewHolder.setText(R.id.tv_type, transferType(projectBean.type)); baseViewHolder.setText(R.id.tv_description, projectBean.description); baseViewHolder.setText(R.id.tv_date, new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE).format(projectBean.time)); baseViewHolder.setText(R.id.tv_people_count, projectBean.people + mContext.getString(R.string.unit_people)); baseViewHolder.setText(R.id.tv_cycle, projectBean.cycle + mContext.getString(R.string.unit_day)); } /** * transfer type from code to string * @param type * @return */ private String transferType(int type) {
// Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/search/SearchAdapter.java import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; package com.ittianyu.pocenter.features.search; /** * Created by yu on 2017/1/17. */ public class SearchAdapter extends BaseQuickAdapter<ProjectBean, BaseViewHolder> { public SearchAdapter(List<ProjectBean> data) { super(R.layout.item_search, data); } @Override protected void convert(BaseViewHolder baseViewHolder, ProjectBean projectBean) { baseViewHolder.setText(R.id.tv_title, projectBean.title); baseViewHolder.setText(R.id.tv_price, projectBean.price); // baseViewHolder.setText(R.id.tv_reference, projectBean.reference); // baseViewHolder.setText(R.id.tv_type, transferType(projectBean.type)); baseViewHolder.setText(R.id.tv_description, projectBean.description); baseViewHolder.setText(R.id.tv_date, new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE).format(projectBean.time)); baseViewHolder.setText(R.id.tv_people_count, projectBean.people + mContext.getString(R.string.unit_people)); baseViewHolder.setText(R.id.tv_cycle, projectBean.cycle + mContext.getString(R.string.unit_day)); } /** * transfer type from code to string * @param type * @return */ private String transferType(int type) {
List<String> types = BaseApplication.getRepertories().getAllTypes();
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/search/SearchPresenter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import com.orhanobut.logger.Logger; import java.util.List; import io.reactivex.functions.Consumer;
package com.ittianyu.pocenter.features.search; /** * Created by yu on 2017/1/17. */ public class SearchPresenter extends BasePresenter<SearchContract.View> implements SearchContract.Presenter { private static final int COUNT = 20; private String[] keywords; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories()
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/search/SearchPresenter.java import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import com.orhanobut.logger.Logger; import java.util.List; import io.reactivex.functions.Consumer; package com.ittianyu.pocenter.features.search; /** * Created by yu on 2017/1/17. */ public class SearchPresenter extends BasePresenter<SearchContract.View> implements SearchContract.Presenter { private static final int COUNT = 20; private String[] keywords; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories()
.getList(0, COUNT, null, RemoteApi.Status.RECRUITING, keywords, pullToRefresh)
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/search/SearchPresenter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import com.orhanobut.logger.Logger; import java.util.List; import io.reactivex.functions.Consumer;
package com.ittianyu.pocenter.features.search; /** * Created by yu on 2017/1/17. */ public class SearchPresenter extends BasePresenter<SearchContract.View> implements SearchContract.Presenter { private static final int COUNT = 20; private String[] keywords; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories() .getList(0, COUNT, null, RemoteApi.Status.RECRUITING, keywords, pullToRefresh)
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/search/SearchPresenter.java import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import com.orhanobut.logger.Logger; import java.util.List; import io.reactivex.functions.Consumer; package com.ittianyu.pocenter.features.search; /** * Created by yu on 2017/1/17. */ public class SearchPresenter extends BasePresenter<SearchContract.View> implements SearchContract.Presenter { private static final int COUNT = 20; private String[] keywords; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories() .getList(0, COUNT, null, RemoteApi.Status.RECRUITING, keywords, pullToRefresh)
.subscribe(new Consumer<List<ProjectBean>>() {
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/version/CheckVersionService.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/utils/UnsafeOkHttpUtils.java // public class UnsafeOkHttpUtils { // /** // * don't verify certificate // * @return // */ // public static OkHttpClient getClient() { // try { // // Create a trust manager that does not validate certificate chains // final TrustManager[] trustAllCerts = new TrustManager[] { // new X509TrustManager() { // @Override // public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public java.security.cert.X509Certificate[] getAcceptedIssuers() { // return new java.security.cert.X509Certificate[]{}; // } // } // }; // // // Install the all-trusting trust manager // final SSLContext sslContext = SSLContext.getInstance("SSL"); // sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // // Create an ssl socket factory with our all-trusting manager // final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); // // OkHttpClient.Builder builder = new OkHttpClient.Builder(); // builder.sslSocketFactory(sslSocketFactory); // builder.hostnameVerifier(new HostnameVerifier() { // @Override // public boolean verify(String hostname, SSLSession session) { // return true; // } // }); // // OkHttpClient okHttpClient = builder.build(); // return okHttpClient; // } catch (Exception e) { // throw new RuntimeException(e); // } // } // }
import android.content.Intent; import android.os.IBinder; import android.widget.Toast; import com.allenliu.versionchecklib.AVersionService; import com.google.gson.Gson; import com.ittianyu.pocenter.BuildConfig; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.utils.UnsafeOkHttpUtils; import com.zhy.http.okhttp.OkHttpUtils;
package com.ittianyu.pocenter.features.version; public class CheckVersionService extends AVersionService { public static final String SHOW_LAST = "showLast"; private boolean showLast = false; public CheckVersionService() {
// Path: app/src/main/java/com/ittianyu/pocenter/common/utils/UnsafeOkHttpUtils.java // public class UnsafeOkHttpUtils { // /** // * don't verify certificate // * @return // */ // public static OkHttpClient getClient() { // try { // // Create a trust manager that does not validate certificate chains // final TrustManager[] trustAllCerts = new TrustManager[] { // new X509TrustManager() { // @Override // public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public java.security.cert.X509Certificate[] getAcceptedIssuers() { // return new java.security.cert.X509Certificate[]{}; // } // } // }; // // // Install the all-trusting trust manager // final SSLContext sslContext = SSLContext.getInstance("SSL"); // sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // // Create an ssl socket factory with our all-trusting manager // final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); // // OkHttpClient.Builder builder = new OkHttpClient.Builder(); // builder.sslSocketFactory(sslSocketFactory); // builder.hostnameVerifier(new HostnameVerifier() { // @Override // public boolean verify(String hostname, SSLSession session) { // return true; // } // }); // // OkHttpClient okHttpClient = builder.build(); // return okHttpClient; // } catch (Exception e) { // throw new RuntimeException(e); // } // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/version/CheckVersionService.java import android.content.Intent; import android.os.IBinder; import android.widget.Toast; import com.allenliu.versionchecklib.AVersionService; import com.google.gson.Gson; import com.ittianyu.pocenter.BuildConfig; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.utils.UnsafeOkHttpUtils; import com.zhy.http.okhttp.OkHttpUtils; package com.ittianyu.pocenter.features.version; public class CheckVersionService extends AVersionService { public static final String SHOW_LAST = "showLast"; private boolean showLast = false; public CheckVersionService() {
OkHttpUtils.initClient(UnsafeOkHttpUtils.getClient());
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.Observable; import retrofit2.http.GET; import retrofit2.http.Query;
package com.ittianyu.pocenter.common.api; /** * Created by yu on 2017/1/17. */ public interface RemoteApi { interface Type { int OTHER = 0; int WEB = 1; int WE_CHAT = 2; int HTML5 = 3; int APP = 4; int INTELLIGENT_HARDWARE = 5; int DESKTOP_APP = 6; int BIG_DATA = 7; int SYSTEM = 8; int SDK_API = 9; int ART = 10; } interface Status { int RECRUITING = 0; int RECRUITED = 1; } /** * select list according to types status and keywords * * @param start start index * @param count select count * @param types support multiple types * @param status * @param keywords title or description keywords * @return */ @GET("list")
// Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.Observable; import retrofit2.http.GET; import retrofit2.http.Query; package com.ittianyu.pocenter.common.api; /** * Created by yu on 2017/1/17. */ public interface RemoteApi { interface Type { int OTHER = 0; int WEB = 1; int WE_CHAT = 2; int HTML5 = 3; int APP = 4; int INTELLIGENT_HARDWARE = 5; int DESKTOP_APP = 6; int BIG_DATA = 7; int SYSTEM = 8; int SDK_API = 9; int ART = 10; } interface Status { int RECRUITING = 0; int RECRUITED = 1; } /** * select list according to types status and keywords * * @param start start index * @param count select count * @param types support multiple types * @param status * @param keywords title or description keywords * @return */ @GET("list")
Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count,
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/home/HomeAdapter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale;
package com.ittianyu.pocenter.features.home; /** * Created by yu on 2017/1/17. */ public class HomeAdapter extends BaseQuickAdapter<ProjectBean, BaseViewHolder> { public HomeAdapter(List<ProjectBean> data) { super(R.layout.item_home, data); } @Override protected void convert(BaseViewHolder baseViewHolder, ProjectBean projectBean) { baseViewHolder.setText(R.id.tv_title, projectBean.title); baseViewHolder.setText(R.id.tv_price, projectBean.price); baseViewHolder.setText(R.id.tv_reference, projectBean.reference); baseViewHolder.setText(R.id.tv_type, transferType(projectBean.type)); baseViewHolder.setText(R.id.tv_description, projectBean.description); baseViewHolder.setText(R.id.tv_date, new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE).format(projectBean.time)); baseViewHolder.setText(R.id.tv_people_count, projectBean.people + mContext.getString(R.string.unit_people)); baseViewHolder.setText(R.id.tv_cycle, projectBean.cycle + mContext.getString(R.string.unit_day)); } /** * transfer type from code to string * @param type * @return */ private String transferType(int type) {
// Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/home/HomeAdapter.java import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.ittianyu.pocenter.R; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; package com.ittianyu.pocenter.features.home; /** * Created by yu on 2017/1/17. */ public class HomeAdapter extends BaseQuickAdapter<ProjectBean, BaseViewHolder> { public HomeAdapter(List<ProjectBean> data) { super(R.layout.item_home, data); } @Override protected void convert(BaseViewHolder baseViewHolder, ProjectBean projectBean) { baseViewHolder.setText(R.id.tv_title, projectBean.title); baseViewHolder.setText(R.id.tv_price, projectBean.price); baseViewHolder.setText(R.id.tv_reference, projectBean.reference); baseViewHolder.setText(R.id.tv_type, transferType(projectBean.type)); baseViewHolder.setText(R.id.tv_description, projectBean.description); baseViewHolder.setText(R.id.tv_date, new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE).format(projectBean.time)); baseViewHolder.setText(R.id.tv_people_count, projectBean.people + mContext.getString(R.string.unit_people)); baseViewHolder.setText(R.id.tv_cycle, projectBean.cycle + mContext.getString(R.string.unit_day)); } /** * transfer type from code to string * @param type * @return */ private String transferType(int type) {
List<String> types = BaseApplication.getRepertories().getAllTypes();
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/find/FindPresenter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.functions.Consumer;
package com.ittianyu.pocenter.features.find; /** * Created by yu on 2017/1/17. */ public class FindPresenter extends BasePresenter<FindContract.View> implements FindContract.Presenter { private static final int COUNT = 20; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories()
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/find/FindPresenter.java import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.functions.Consumer; package com.ittianyu.pocenter.features.find; /** * Created by yu on 2017/1/17. */ public class FindPresenter extends BasePresenter<FindContract.View> implements FindContract.Presenter { private static final int COUNT = 20; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories()
.getList(0, COUNT, null, RemoteApi.Status.RECRUITING, null, pullToRefresh)
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/find/FindPresenter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.functions.Consumer;
package com.ittianyu.pocenter.features.find; /** * Created by yu on 2017/1/17. */ public class FindPresenter extends BasePresenter<FindContract.View> implements FindContract.Presenter { private static final int COUNT = 20; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories() .getList(0, COUNT, null, RemoteApi.Status.RECRUITING, null, pullToRefresh)
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/find/FindPresenter.java import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.functions.Consumer; package com.ittianyu.pocenter.features.find; /** * Created by yu on 2017/1/17. */ public class FindPresenter extends BasePresenter<FindContract.View> implements FindContract.Presenter { private static final int COUNT = 20; @Override public void loadData(final boolean pullToRefresh) { application.getRepertories() .getList(0, COUNT, null, RemoteApi.Status.RECRUITING, null, pullToRefresh)
.subscribe(new Consumer<List<ProjectBean>>() {
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/features/home/HomePresenter.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.functions.Consumer;
package com.ittianyu.pocenter.features.home; /** * Created by yu on 2017/1/17. */ public class HomePresenter extends BasePresenter<HomeContract.View> implements HomeContract.Presenter { private static final int COUNT = 20; private int[] types; public HomePresenter() { loadTypes(); } /** * load user selected types from config */ private void loadTypes() { // load types
// Path: app/src/main/java/com/ittianyu/pocenter/common/api/RemoteApi.java // public interface RemoteApi { // interface Type { // int OTHER = 0; // int WEB = 1; // int WE_CHAT = 2; // int HTML5 = 3; // int APP = 4; // int INTELLIGENT_HARDWARE = 5; // int DESKTOP_APP = 6; // int BIG_DATA = 7; // int SYSTEM = 8; // int SDK_API = 9; // int ART = 10; // } // interface Status { // int RECRUITING = 0; // int RECRUITED = 1; // } // // /** // * select list according to types status and keywords // * // * @param start start index // * @param count select count // * @param types support multiple types // * @param status // * @param keywords title or description keywords // * @return // */ // @GET("list") // Observable<List<ProjectBean>> getList(@Query("start") int start, @Query("count") int count, // @Query("type") int[] types, @Query("status") int status, // @Query("keyword") String[] keywords); // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BaseApplication.java // public class BaseApplication extends Application { // private static Context context; // private static Repertories repertories; // // // tinker patch config // private ApplicationLike tinkerApplicationLike; // // @Override // public void onCreate() { // super.onCreate(); // // // tinker patch config // tinkerPatchConfig(); // // context = getApplicationContext(); // // initLogger(); // // initLeakCanary(); // // repertories = new Repertories(context.getCacheDir()); // } // // private void tinkerPatchConfig() { // // 我们可以从这里获得Tinker加载过程的信息 // if (BuildConfig.TINKER_ENABLE) { // tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike(); // // // 初始化TinkerPatch SDK // TinkerPatch.init(tinkerApplicationLike) // .reflectPatchLibrary() // .setPatchRollbackOnScreenOff(true) // .setPatchRestartOnSrceenOff(true); // // // 每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果 // new FetchPatchHandler().fetchPatchWithInterval(3); // } // } // // /** // * use LeakCanary to check mey leak // */ // private void initLeakCanary() { // if (LeakCanary.isInAnalyzerProcess(this)) { // // This process is dedicated to LeakCanary for heap analysis. // // You should not init your app in this process. // return; // } // LeakCanary.install(this); // } // // /** // * init logger // */ // private void initLogger() { // if ((0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE))) // Logger.init(); // for debug, print all log // else // Logger.init().logLevel(LogLevel.NONE); // for release, remove all log // // Logger.init(); // for release, remove all log // } // // public static Context getContext() { // return context; // } // // public static Repertories getRepertories() { // return repertories; // } // // // /** // * tinker // * @param base // */ // @Override // public void attachBaseContext(Context base) { // super.attachBaseContext(base); // //you must install multiDex whatever tinker is installed! // MultiDex.install(base); // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/base/BasePresenter.java // public class BasePresenter<V extends BaseContract.View> // extends MvpNullObjectBasePresenter<V> // implements BaseContract.Presenter<V>{ // protected BaseApplication application; // // @Override // public void attachView(V view) { // super.attachView(view); // application = (BaseApplication) getView().getApp(); // } // // @Override // public BaseApplication getApp() { // return application; // } // } // // Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/features/home/HomePresenter.java import com.ittianyu.pocenter.common.api.RemoteApi; import com.ittianyu.pocenter.common.base.BaseApplication; import com.ittianyu.pocenter.common.base.BasePresenter; import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import io.reactivex.functions.Consumer; package com.ittianyu.pocenter.features.home; /** * Created by yu on 2017/1/17. */ public class HomePresenter extends BasePresenter<HomeContract.View> implements HomeContract.Presenter { private static final int COUNT = 20; private int[] types; public HomePresenter() { loadTypes(); } /** * load user selected types from config */ private void loadTypes() { // load types
types = BaseApplication.getRepertories().getTypes();
ittianyu/POCenter
app/src/main/java/com/ittianyu/pocenter/common/api/CacheApi.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // }
import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import java.util.concurrent.TimeUnit; import io.reactivex.Observable; import io.rx_cache2.DynamicKey; import io.rx_cache2.EvictDynamicKey; import io.rx_cache2.LifeCache;
package com.ittianyu.pocenter.common.api; /** * Created by yu on 2017/1/17. */ public interface CacheApi { @LifeCache(duration = 15, timeUnit = TimeUnit.MINUTES)
// Path: app/src/main/java/com/ittianyu/pocenter/common/bean/ProjectBean.java // public class ProjectBean { // public int id; // public String projectId; // public String title; // public String description; // public String price; // public int type; // public String cycle; // public int people; // public int status; // public Timestamp time; // public String reference; // public String url; // // // @Override // public String toString() { // return "ProjectBean{" + // "projectId='" + projectId + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", price='" + price + '\'' + // ", type=" + type + // ", cycle='" + cycle + '\'' + // ", people=" + people + // ", status=" + status + // ", time=" + time + // ", reference='" + reference + '\'' + // ", url='" + url + '\'' + // '}'; // } // } // Path: app/src/main/java/com/ittianyu/pocenter/common/api/CacheApi.java import com.ittianyu.pocenter.common.bean.ProjectBean; import java.util.List; import java.util.concurrent.TimeUnit; import io.reactivex.Observable; import io.rx_cache2.DynamicKey; import io.rx_cache2.EvictDynamicKey; import io.rx_cache2.LifeCache; package com.ittianyu.pocenter.common.api; /** * Created by yu on 2017/1/17. */ public interface CacheApi { @LifeCache(duration = 15, timeUnit = TimeUnit.MINUTES)
Observable<List<ProjectBean>> getList(Observable<List<ProjectBean>> repo, DynamicKey key, EvictDynamicKey isUpdate);
ittianyu/POCenter
app/src/test/java/com/ittianyu/pocenter/ExampleUnitTest.java
// Path: app/src/main/java/com/ittianyu/pocenter/common/utils/UnsafeOkHttpUtils.java // public class UnsafeOkHttpUtils { // /** // * don't verify certificate // * @return // */ // public static OkHttpClient getClient() { // try { // // Create a trust manager that does not validate certificate chains // final TrustManager[] trustAllCerts = new TrustManager[] { // new X509TrustManager() { // @Override // public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public java.security.cert.X509Certificate[] getAcceptedIssuers() { // return new java.security.cert.X509Certificate[]{}; // } // } // }; // // // Install the all-trusting trust manager // final SSLContext sslContext = SSLContext.getInstance("SSL"); // sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // // Create an ssl socket factory with our all-trusting manager // final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); // // OkHttpClient.Builder builder = new OkHttpClient.Builder(); // builder.sslSocketFactory(sslSocketFactory); // builder.hostnameVerifier(new HostnameVerifier() { // @Override // public boolean verify(String hostname, SSLSession session) { // return true; // } // }); // // OkHttpClient okHttpClient = builder.build(); // return okHttpClient; // } catch (Exception e) { // throw new RuntimeException(e); // } // } // }
import com.ittianyu.pocenter.common.utils.UnsafeOkHttpUtils; import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import org.junit.Test; import java.io.IOException; import io.reactivex.Observable; import io.reactivex.functions.Consumer; import okhttp3.ResponseBody; import retrofit2.Retrofit; import retrofit2.http.GET; import retrofit2.http.Query; import static org.junit.Assert.assertEquals;
package com.ittianyu.pocenter; /** * Example local unit test, which will execute on the development machine (host). * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ public class ExampleUnitTest { public static final String HOST = "po.ittianyu.com"; public static final String URL_BASE = "https://" + HOST + "/"; // public static final String HOST = "192.168.1.106"; // public static final String URL_BASE = "http://" + HOST + "/pocenter/"; interface RemoteApi { @GET("list") Observable<ResponseBody> getList(@Query("start") int start, @Query("count") int count, @Query("type") int[] types, @Query("status") int status, @Query(value = "keyword") String[] keywords); } @Test public void testSearch() throws IOException { RemoteApi remoteApi = new Retrofit.Builder() .baseUrl(URL_BASE) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory(GsonConverterFactory.create())
// Path: app/src/main/java/com/ittianyu/pocenter/common/utils/UnsafeOkHttpUtils.java // public class UnsafeOkHttpUtils { // /** // * don't verify certificate // * @return // */ // public static OkHttpClient getClient() { // try { // // Create a trust manager that does not validate certificate chains // final TrustManager[] trustAllCerts = new TrustManager[] { // new X509TrustManager() { // @Override // public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) { // } // // @Override // public java.security.cert.X509Certificate[] getAcceptedIssuers() { // return new java.security.cert.X509Certificate[]{}; // } // } // }; // // // Install the all-trusting trust manager // final SSLContext sslContext = SSLContext.getInstance("SSL"); // sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // // Create an ssl socket factory with our all-trusting manager // final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); // // OkHttpClient.Builder builder = new OkHttpClient.Builder(); // builder.sslSocketFactory(sslSocketFactory); // builder.hostnameVerifier(new HostnameVerifier() { // @Override // public boolean verify(String hostname, SSLSession session) { // return true; // } // }); // // OkHttpClient okHttpClient = builder.build(); // return okHttpClient; // } catch (Exception e) { // throw new RuntimeException(e); // } // } // } // Path: app/src/test/java/com/ittianyu/pocenter/ExampleUnitTest.java import com.ittianyu.pocenter.common.utils.UnsafeOkHttpUtils; import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import org.junit.Test; import java.io.IOException; import io.reactivex.Observable; import io.reactivex.functions.Consumer; import okhttp3.ResponseBody; import retrofit2.Retrofit; import retrofit2.http.GET; import retrofit2.http.Query; import static org.junit.Assert.assertEquals; package com.ittianyu.pocenter; /** * Example local unit test, which will execute on the development machine (host). * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ public class ExampleUnitTest { public static final String HOST = "po.ittianyu.com"; public static final String URL_BASE = "https://" + HOST + "/"; // public static final String HOST = "192.168.1.106"; // public static final String URL_BASE = "http://" + HOST + "/pocenter/"; interface RemoteApi { @GET("list") Observable<ResponseBody> getList(@Query("start") int start, @Query("count") int count, @Query("type") int[] types, @Query("status") int status, @Query(value = "keyword") String[] keywords); } @Test public void testSearch() throws IOException { RemoteApi remoteApi = new Retrofit.Builder() .baseUrl(URL_BASE) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory(GsonConverterFactory.create())
.client(UnsafeOkHttpUtils.getClient())
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/ewf/Section.java
// Path: src/com/ciphertechsolutions/io/processing/triage/ByteUtils.java // public class ByteUtils { // // /** // * Converts a long to a little endian byte array. // * @param l The long to convert // * @return A little endian array. // */ // public static byte[] longToBytes(long l) { // byte[] result = new byte[8]; // for (int i = 0; i <= 7; i++) { // result[i] = (byte)(l & 0xFF); // l >>= 8; // } // return result; // } // // /** // * Converts an int to a little endian byte array. // * @param _int The int to convert. // * @return A little endian array. // */ // public static byte[] intToBytes(int _int) { // byte[] result = new byte[4]; // for (int i = 0; i <= 3; i++) { // result[i] = (byte)(_int & 0xFF); // _int >>= 8; // } // return result; // } // // public static Map<Integer, String> printableSpansWithIndexes(byte[] bytes, int minLength, boolean filterRandom, int randomThreshold) { // // Map<Integer, String> spanPairs = new HashMap<>(); // int[] table = new int[bytes.length]; // int tableSize = 0; // int strStart, strSize; // byte[] byteSpan; // String span; // // // for (int i = 0; i < bytes.length; i++) // { // if (!isPrintable(bytes[i])) // { // table[tableSize++] = i; // } // } // // for (int j = 1; j < tableSize; j++) // { // if (table[j] == 0) // { // continue; // } // // strStart = table[j - 1] + 1; // strSize = table[j] - strStart; // // if (strSize < minLength) // { // continue; // } // // // byteSpan = Arrays.copyOfRange(bytes, strStart, strStart + strSize); // span = new String(byteSpan, StandardCharsets.US_ASCII); // spanPairs.put(strStart, span); // } // // if (filterRandom) // { // //TODO: Bother with this? // return spanPairs; // } // else // { // return spanPairs; // } // } // // private static boolean isPrintable(byte b) // { // return (b >= 0x20 && b < 0x7F) || b == 0x0a || b == 0x0d || b == 0x09; // } // }
import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import java.util.zip.Adler32; import com.ciphertechsolutions.io.processing.triage.ByteUtils;
return currentOffset; } public void setCurrentOffset(long currentOffset) { this.nextOffset = this.nextOffset - (this.currentOffset - currentOffset); this.currentOffset = currentOffset; } /** * Get the offset of the next section. * @return The offset of the next section. */ public long getNextOffset() { return nextOffset; } /** * Get the adler32 checksum of the section header. * @return The section header checksum. */ public int getAdler32() { if (adler32 == 0) { adler32 = calcAdler32(); } return adler32; } private int calcAdler32() { Adler32 adlerCalc = new Adler32(); adlerCalc.update(Arrays.copyOf(typeString.getBytes(), MAX_TYPE_LENGTH));
// Path: src/com/ciphertechsolutions/io/processing/triage/ByteUtils.java // public class ByteUtils { // // /** // * Converts a long to a little endian byte array. // * @param l The long to convert // * @return A little endian array. // */ // public static byte[] longToBytes(long l) { // byte[] result = new byte[8]; // for (int i = 0; i <= 7; i++) { // result[i] = (byte)(l & 0xFF); // l >>= 8; // } // return result; // } // // /** // * Converts an int to a little endian byte array. // * @param _int The int to convert. // * @return A little endian array. // */ // public static byte[] intToBytes(int _int) { // byte[] result = new byte[4]; // for (int i = 0; i <= 3; i++) { // result[i] = (byte)(_int & 0xFF); // _int >>= 8; // } // return result; // } // // public static Map<Integer, String> printableSpansWithIndexes(byte[] bytes, int minLength, boolean filterRandom, int randomThreshold) { // // Map<Integer, String> spanPairs = new HashMap<>(); // int[] table = new int[bytes.length]; // int tableSize = 0; // int strStart, strSize; // byte[] byteSpan; // String span; // // // for (int i = 0; i < bytes.length; i++) // { // if (!isPrintable(bytes[i])) // { // table[tableSize++] = i; // } // } // // for (int j = 1; j < tableSize; j++) // { // if (table[j] == 0) // { // continue; // } // // strStart = table[j - 1] + 1; // strSize = table[j] - strStart; // // if (strSize < minLength) // { // continue; // } // // // byteSpan = Arrays.copyOfRange(bytes, strStart, strStart + strSize); // span = new String(byteSpan, StandardCharsets.US_ASCII); // spanPairs.put(strStart, span); // } // // if (filterRandom) // { // //TODO: Bother with this? // return spanPairs; // } // else // { // return spanPairs; // } // } // // private static boolean isPrintable(byte b) // { // return (b >= 0x20 && b < 0x7F) || b == 0x0a || b == 0x0d || b == 0x09; // } // } // Path: src/com/ciphertechsolutions/io/ewf/Section.java import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import java.util.zip.Adler32; import com.ciphertechsolutions.io.processing.triage.ByteUtils; return currentOffset; } public void setCurrentOffset(long currentOffset) { this.nextOffset = this.nextOffset - (this.currentOffset - currentOffset); this.currentOffset = currentOffset; } /** * Get the offset of the next section. * @return The offset of the next section. */ public long getNextOffset() { return nextOffset; } /** * Get the adler32 checksum of the section header. * @return The section header checksum. */ public int getAdler32() { if (adler32 == 0) { adler32 = calcAdler32(); } return adler32; } private int calcAdler32() { Adler32 adlerCalc = new Adler32(); adlerCalc.update(Arrays.copyOf(typeString.getBytes(), MAX_TYPE_LENGTH));
adlerCalc.update(ByteUtils.longToBytes(nextOffset));
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/ewf/TableSection.java
// Path: src/com/ciphertechsolutions/io/processing/triage/ByteUtils.java // public class ByteUtils { // // /** // * Converts a long to a little endian byte array. // * @param l The long to convert // * @return A little endian array. // */ // public static byte[] longToBytes(long l) { // byte[] result = new byte[8]; // for (int i = 0; i <= 7; i++) { // result[i] = (byte)(l & 0xFF); // l >>= 8; // } // return result; // } // // /** // * Converts an int to a little endian byte array. // * @param _int The int to convert. // * @return A little endian array. // */ // public static byte[] intToBytes(int _int) { // byte[] result = new byte[4]; // for (int i = 0; i <= 3; i++) { // result[i] = (byte)(_int & 0xFF); // _int >>= 8; // } // return result; // } // // public static Map<Integer, String> printableSpansWithIndexes(byte[] bytes, int minLength, boolean filterRandom, int randomThreshold) { // // Map<Integer, String> spanPairs = new HashMap<>(); // int[] table = new int[bytes.length]; // int tableSize = 0; // int strStart, strSize; // byte[] byteSpan; // String span; // // // for (int i = 0; i < bytes.length; i++) // { // if (!isPrintable(bytes[i])) // { // table[tableSize++] = i; // } // } // // for (int j = 1; j < tableSize; j++) // { // if (table[j] == 0) // { // continue; // } // // strStart = table[j - 1] + 1; // strSize = table[j] - strStart; // // if (strSize < minLength) // { // continue; // } // // // byteSpan = Arrays.copyOfRange(bytes, strStart, strStart + strSize); // span = new String(byteSpan, StandardCharsets.US_ASCII); // spanPairs.put(strStart, span); // } // // if (filterRandom) // { // //TODO: Bother with this? // return spanPairs; // } // else // { // return spanPairs; // } // } // // private static boolean isPrintable(byte b) // { // return (b >= 0x20 && b < 0x7F) || b == 0x0a || b == 0x0d || b == 0x09; // } // }
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.zip.Adler32; import com.ciphertechsolutions.io.processing.triage.ByteUtils;
this.baseOffset = baseOffset; this.offsetArray = offsetArray; this.secondaryAdler32 = secondaryAdler32; this.tableAdler32 = tableAdler32; } int tableEntries; // 4 bytes of padding. static final byte[] padding = {0x00, 0x00, 0x00, 0x00}; private final long baseOffset; static final byte[] morePadding = padding; public boolean isFull() { return offsetArray.size() == MAX_ENTRIES; } public long getBaseOffset() { return baseOffset; } public List<Integer> getArray() { return offsetArray; } public void add(long offset, boolean compressed) { //TODO: Do we need the actual chunk data to calculate a checksum? int relativeOffset = compressed ? (1 << 31) | (int) (offset - baseOffset) : (int) (offset - baseOffset); offsetArray.add(relativeOffset);
// Path: src/com/ciphertechsolutions/io/processing/triage/ByteUtils.java // public class ByteUtils { // // /** // * Converts a long to a little endian byte array. // * @param l The long to convert // * @return A little endian array. // */ // public static byte[] longToBytes(long l) { // byte[] result = new byte[8]; // for (int i = 0; i <= 7; i++) { // result[i] = (byte)(l & 0xFF); // l >>= 8; // } // return result; // } // // /** // * Converts an int to a little endian byte array. // * @param _int The int to convert. // * @return A little endian array. // */ // public static byte[] intToBytes(int _int) { // byte[] result = new byte[4]; // for (int i = 0; i <= 3; i++) { // result[i] = (byte)(_int & 0xFF); // _int >>= 8; // } // return result; // } // // public static Map<Integer, String> printableSpansWithIndexes(byte[] bytes, int minLength, boolean filterRandom, int randomThreshold) { // // Map<Integer, String> spanPairs = new HashMap<>(); // int[] table = new int[bytes.length]; // int tableSize = 0; // int strStart, strSize; // byte[] byteSpan; // String span; // // // for (int i = 0; i < bytes.length; i++) // { // if (!isPrintable(bytes[i])) // { // table[tableSize++] = i; // } // } // // for (int j = 1; j < tableSize; j++) // { // if (table[j] == 0) // { // continue; // } // // strStart = table[j - 1] + 1; // strSize = table[j] - strStart; // // if (strSize < minLength) // { // continue; // } // // // byteSpan = Arrays.copyOfRange(bytes, strStart, strStart + strSize); // span = new String(byteSpan, StandardCharsets.US_ASCII); // spanPairs.put(strStart, span); // } // // if (filterRandom) // { // //TODO: Bother with this? // return spanPairs; // } // else // { // return spanPairs; // } // } // // private static boolean isPrintable(byte b) // { // return (b >= 0x20 && b < 0x7F) || b == 0x0a || b == 0x0d || b == 0x09; // } // } // Path: src/com/ciphertechsolutions/io/ewf/TableSection.java import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.zip.Adler32; import com.ciphertechsolutions.io.processing.triage.ByteUtils; this.baseOffset = baseOffset; this.offsetArray = offsetArray; this.secondaryAdler32 = secondaryAdler32; this.tableAdler32 = tableAdler32; } int tableEntries; // 4 bytes of padding. static final byte[] padding = {0x00, 0x00, 0x00, 0x00}; private final long baseOffset; static final byte[] morePadding = padding; public boolean isFull() { return offsetArray.size() == MAX_ENTRIES; } public long getBaseOffset() { return baseOffset; } public List<Integer> getArray() { return offsetArray; } public void add(long offset, boolean compressed) { //TODO: Do we need the actual chunk data to calculate a checksum? int relativeOffset = compressed ? (1 << 31) | (int) (offset - baseOffset) : (int) (offset - baseOffset); offsetArray.add(relativeOffset);
offsetChecksumCalc.update(ByteUtils.intToBytes(relativeOffset));
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/processing/triage/StringCarver.java
// Path: src/com/ciphertechsolutions/io/logging/Logging.java // public class Logging { // // private static final List<LoggingStream> LOGGING_PRINT_STREAMS = Collections.synchronizedList(new ArrayList<>()); // // static { // LOGGING_PRINT_STREAMS.add(new LoggingStream(System.out, true)); // } // // /** // * Adds the given PrintStream and sets it to accept all levels of logging output. // * @param outputStream The stream to print the logging output to. // */ // public static void addOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, true)); // } // // /** // * Adds the given PrintStream and sets it to accept the given {@link LogMessageType message types} // * @param outputStream The stream to print the logging output to. // * @param types The {@link LogMessageType message types} to print. // */ // public static void addOutput(PrintStream outputStream, LogMessageType... types) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, types)); // } // // /** // * Stops outputting logging to the given PrintStream. // * @param outputStream The PrintStream to cease logging to. // */ // public static void removeOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.remove(outputStream); // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. // * @param message // */ // public static void log(Object message) { // if (message != null) { // log(message.toString()); // } // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. The message will be of type messageType. // * @param message // * @param messageType // */ // public static void log(Object message, LogMessageType messageType) { // if (message != null) { // log(message.toString(), messageType); // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Exception exception) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(exception); // exception.printStackTrace(printStream); // } // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Throwable throwable) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(throwable); // throwable.printStackTrace(printStream); // } // } // } // // /** // * Logs the given message, with a timestamp. // * @param message // */ // public static void log(String message) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.INFO)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void logSimple(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println(message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType... messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // }
import java.util.concurrent.TimeUnit; import com.ciphertechsolutions.io.logging.Logging; import javafx.util.Pair;
@Override public void initialize() { startThreads(); } @Override protected int getThreadCount() { return 1; } @Override protected void internalProcess() { try { while (isRunning && !Thread.currentThread().isInterrupted()) { Pair<byte[], Long> toRead; toRead = byteQueue.poll(5, TimeUnit.SECONDS); if (toRead == null) { continue; } byte[] bytesToRead = toRead.getKey(); if (bytesToRead.length == 0) { isRunning = false; return; } ByteUtils.printableSpansWithIndexes(bytesToRead, DEFAULT_STRING_LENGTH, false, DEFAULT_RANDOM_THRESHOLD); // TODO: What to do with this? } } catch (InterruptedException e) {
// Path: src/com/ciphertechsolutions/io/logging/Logging.java // public class Logging { // // private static final List<LoggingStream> LOGGING_PRINT_STREAMS = Collections.synchronizedList(new ArrayList<>()); // // static { // LOGGING_PRINT_STREAMS.add(new LoggingStream(System.out, true)); // } // // /** // * Adds the given PrintStream and sets it to accept all levels of logging output. // * @param outputStream The stream to print the logging output to. // */ // public static void addOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, true)); // } // // /** // * Adds the given PrintStream and sets it to accept the given {@link LogMessageType message types} // * @param outputStream The stream to print the logging output to. // * @param types The {@link LogMessageType message types} to print. // */ // public static void addOutput(PrintStream outputStream, LogMessageType... types) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, types)); // } // // /** // * Stops outputting logging to the given PrintStream. // * @param outputStream The PrintStream to cease logging to. // */ // public static void removeOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.remove(outputStream); // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. // * @param message // */ // public static void log(Object message) { // if (message != null) { // log(message.toString()); // } // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. The message will be of type messageType. // * @param message // * @param messageType // */ // public static void log(Object message, LogMessageType messageType) { // if (message != null) { // log(message.toString(), messageType); // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Exception exception) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(exception); // exception.printStackTrace(printStream); // } // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Throwable throwable) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(throwable); // throwable.printStackTrace(printStream); // } // } // } // // /** // * Logs the given message, with a timestamp. // * @param message // */ // public static void log(String message) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.INFO)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void logSimple(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println(message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType... messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // } // Path: src/com/ciphertechsolutions/io/processing/triage/StringCarver.java import java.util.concurrent.TimeUnit; import com.ciphertechsolutions.io.logging.Logging; import javafx.util.Pair; @Override public void initialize() { startThreads(); } @Override protected int getThreadCount() { return 1; } @Override protected void internalProcess() { try { while (isRunning && !Thread.currentThread().isInterrupted()) { Pair<byte[], Long> toRead; toRead = byteQueue.poll(5, TimeUnit.SECONDS); if (toRead == null) { continue; } byte[] bytesToRead = toRead.getKey(); if (bytesToRead.length == 0) { isRunning = false; return; } ByteUtils.printableSpansWithIndexes(bytesToRead, DEFAULT_STRING_LENGTH, false, DEFAULT_RANDOM_THRESHOLD); // TODO: What to do with this? } } catch (InterruptedException e) {
Logging.log(e);
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/processing/ProcessorBase.java
// Path: src/com/ciphertechsolutions/io/logging/Logging.java // public class Logging { // // private static final List<LoggingStream> LOGGING_PRINT_STREAMS = Collections.synchronizedList(new ArrayList<>()); // // static { // LOGGING_PRINT_STREAMS.add(new LoggingStream(System.out, true)); // } // // /** // * Adds the given PrintStream and sets it to accept all levels of logging output. // * @param outputStream The stream to print the logging output to. // */ // public static void addOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, true)); // } // // /** // * Adds the given PrintStream and sets it to accept the given {@link LogMessageType message types} // * @param outputStream The stream to print the logging output to. // * @param types The {@link LogMessageType message types} to print. // */ // public static void addOutput(PrintStream outputStream, LogMessageType... types) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, types)); // } // // /** // * Stops outputting logging to the given PrintStream. // * @param outputStream The PrintStream to cease logging to. // */ // public static void removeOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.remove(outputStream); // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. // * @param message // */ // public static void log(Object message) { // if (message != null) { // log(message.toString()); // } // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. The message will be of type messageType. // * @param message // * @param messageType // */ // public static void log(Object message, LogMessageType messageType) { // if (message != null) { // log(message.toString(), messageType); // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Exception exception) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(exception); // exception.printStackTrace(printStream); // } // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Throwable throwable) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(throwable); // throwable.printStackTrace(printStream); // } // } // } // // /** // * Logs the given message, with a timestamp. // * @param message // */ // public static void log(String message) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.INFO)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void logSimple(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println(message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType... messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // }
import com.ciphertechsolutions.io.logging.Logging;
package com.ciphertechsolutions.io.processing; /** * Provides some of the basic functionality required to implement {@link IProcessor}. This implementation * assumes that the process will be spawning and managing child threads. */ public abstract class ProcessorBase implements IProcessor { protected boolean isRunning = true; private final Thread[] threads; private final String threadName; protected ProcessorBase(String threadName) { threads = new Thread[getThreadCount()]; this.threadName = threadName; } protected abstract int getThreadCount(); protected abstract void internalProcess(); protected void startThreads() { for (int i =0; i< getThreadCount(); i++) { threads[i] = new Thread(() -> {internalProcess();}, threadName + (i > 0 ? i : "")); threads[i].start(); } } protected void waitForThreads() { for (Thread thread : threads) { try { thread.join(); } catch (InterruptedException e) {
// Path: src/com/ciphertechsolutions/io/logging/Logging.java // public class Logging { // // private static final List<LoggingStream> LOGGING_PRINT_STREAMS = Collections.synchronizedList(new ArrayList<>()); // // static { // LOGGING_PRINT_STREAMS.add(new LoggingStream(System.out, true)); // } // // /** // * Adds the given PrintStream and sets it to accept all levels of logging output. // * @param outputStream The stream to print the logging output to. // */ // public static void addOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, true)); // } // // /** // * Adds the given PrintStream and sets it to accept the given {@link LogMessageType message types} // * @param outputStream The stream to print the logging output to. // * @param types The {@link LogMessageType message types} to print. // */ // public static void addOutput(PrintStream outputStream, LogMessageType... types) { // LOGGING_PRINT_STREAMS.add(new LoggingStream(outputStream, types)); // } // // /** // * Stops outputting logging to the given PrintStream. // * @param outputStream The PrintStream to cease logging to. // */ // public static void removeOutput(PrintStream outputStream) { // LOGGING_PRINT_STREAMS.remove(outputStream); // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. // * @param message // */ // public static void log(Object message) { // if (message != null) { // log(message.toString()); // } // } // // /** // * Logs the given object by calling toString() on it. {@code null} will not cause a crash, // * but will also not be logged. Log message will include a timestamp. The message will be of type messageType. // * @param message // * @param messageType // */ // public static void log(Object message, LogMessageType messageType) { // if (message != null) { // log(message.toString(), messageType); // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Exception exception) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(exception); // exception.printStackTrace(printStream); // } // } // } // // /** // * Logs an exception with a timestamp and relevant details. // * @param exception The exception to log. // */ // public static void log(Throwable throwable) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.ERROR)) { // @SuppressWarnings("resource") // PrintStream printStream = loggingStream.getStream(); // printStream.println(new Timestamp(new Date().getTime()).toString()); // printStream.println(throwable); // throwable.printStackTrace(printStream); // } // } // } // // /** // * Logs the given message, with a timestamp. // * @param message // */ // public static void log(String message) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(LogMessageType.INFO)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void logSimple(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println(message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // // /** // * Logs the given message, with a timestamp. The message will be of type messageType. // * @param message // * @param messageType the type of the message. // */ // public static void log(String message, LogMessageType... messageType) { // for (LoggingStream loggingStream : LOGGING_PRINT_STREAMS) { // if (loggingStream.shouldPrint(messageType)) { // loggingStream.getStream().println("[" + new Date() + "]\t" + message); // } // } // } // } // Path: src/com/ciphertechsolutions/io/processing/ProcessorBase.java import com.ciphertechsolutions.io.logging.Logging; package com.ciphertechsolutions.io.processing; /** * Provides some of the basic functionality required to implement {@link IProcessor}. This implementation * assumes that the process will be spawning and managing child threads. */ public abstract class ProcessorBase implements IProcessor { protected boolean isRunning = true; private final Thread[] threads; private final String threadName; protected ProcessorBase(String threadName) { threads = new Thread[getThreadCount()]; this.threadName = threadName; } protected abstract int getThreadCount(); protected abstract void internalProcess(); protected void startThreads() { for (int i =0; i< getThreadCount(); i++) { threads[i] = new Thread(() -> {internalProcess();}, threadName + (i > 0 ? i : "")); threads[i].start(); } } protected void waitForThreads() { for (Thread thread : threads) { try { thread.join(); } catch (InterruptedException e) {
Logging.log(e);
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/processing/CompressionTask.java
// Path: src/com/ciphertechsolutions/io/ewf/DataChunk.java // public class DataChunk { // /** // * The raw data. // */ // public final byte[] data; // /** // * The size of the data, in bytes. // */ // public final int size; // /** // * The size of the uncompressed data, may be equal to size if {@link #compressed} is false. // */ // public final int originalSize; // /** // * Whether this data is compressed. // */ // public final boolean compressed; // // /** // * Makes a {@link DataChunk} with the given data. // * @param originalSize The uncompressed size of the data. // * @param data The (possibly compressed) data. // * @param compressed Whether or not the data given is compressed. // */ // public DataChunk(int originalSize, byte[] data, boolean compressed) { // this.data = data; // this.originalSize = originalSize; // this.size = this.data.length; // this.compressed = compressed; // } // } // // Path: src/com/ciphertechsolutions/io/processing/triage/ByteUtils.java // public class ByteUtils { // // /** // * Converts a long to a little endian byte array. // * @param l The long to convert // * @return A little endian array. // */ // public static byte[] longToBytes(long l) { // byte[] result = new byte[8]; // for (int i = 0; i <= 7; i++) { // result[i] = (byte)(l & 0xFF); // l >>= 8; // } // return result; // } // // /** // * Converts an int to a little endian byte array. // * @param _int The int to convert. // * @return A little endian array. // */ // public static byte[] intToBytes(int _int) { // byte[] result = new byte[4]; // for (int i = 0; i <= 3; i++) { // result[i] = (byte)(_int & 0xFF); // _int >>= 8; // } // return result; // } // // public static Map<Integer, String> printableSpansWithIndexes(byte[] bytes, int minLength, boolean filterRandom, int randomThreshold) { // // Map<Integer, String> spanPairs = new HashMap<>(); // int[] table = new int[bytes.length]; // int tableSize = 0; // int strStart, strSize; // byte[] byteSpan; // String span; // // // for (int i = 0; i < bytes.length; i++) // { // if (!isPrintable(bytes[i])) // { // table[tableSize++] = i; // } // } // // for (int j = 1; j < tableSize; j++) // { // if (table[j] == 0) // { // continue; // } // // strStart = table[j - 1] + 1; // strSize = table[j] - strStart; // // if (strSize < minLength) // { // continue; // } // // // byteSpan = Arrays.copyOfRange(bytes, strStart, strStart + strSize); // span = new String(byteSpan, StandardCharsets.US_ASCII); // spanPairs.put(strStart, span); // } // // if (filterRandom) // { // //TODO: Bother with this? // return spanPairs; // } // else // { // return spanPairs; // } // } // // private static boolean isPrintable(byte b) // { // return (b >= 0x20 && b < 0x7F) || b == 0x0a || b == 0x0d || b == 0x09; // } // }
import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.concurrent.Callable; import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; import javax.xml.bind.DatatypeConverter; import com.ciphertechsolutions.io.ewf.DataChunk; import com.ciphertechsolutions.io.processing.triage.ByteUtils;
package com.ciphertechsolutions.io.processing; class CompressionTask implements Callable<DataChunk> { private final byte[] input; private final int compressionLevel; CompressionTask(byte[] toCompress, int compressionLevel) { input = toCompress; this.compressionLevel = compressionLevel; } @Override public DataChunk call() throws Exception { Deflater deflater = new Deflater(compressionLevel); deflater.setInput(input); deflater.finish(); byte[] output = new byte[input.length + 4]; int compressedSize = deflater.deflate(output); //Unlikely, but possible. if (compressedSize >= input.length) { System.arraycopy(input, 0, output, 0, input.length);
// Path: src/com/ciphertechsolutions/io/ewf/DataChunk.java // public class DataChunk { // /** // * The raw data. // */ // public final byte[] data; // /** // * The size of the data, in bytes. // */ // public final int size; // /** // * The size of the uncompressed data, may be equal to size if {@link #compressed} is false. // */ // public final int originalSize; // /** // * Whether this data is compressed. // */ // public final boolean compressed; // // /** // * Makes a {@link DataChunk} with the given data. // * @param originalSize The uncompressed size of the data. // * @param data The (possibly compressed) data. // * @param compressed Whether or not the data given is compressed. // */ // public DataChunk(int originalSize, byte[] data, boolean compressed) { // this.data = data; // this.originalSize = originalSize; // this.size = this.data.length; // this.compressed = compressed; // } // } // // Path: src/com/ciphertechsolutions/io/processing/triage/ByteUtils.java // public class ByteUtils { // // /** // * Converts a long to a little endian byte array. // * @param l The long to convert // * @return A little endian array. // */ // public static byte[] longToBytes(long l) { // byte[] result = new byte[8]; // for (int i = 0; i <= 7; i++) { // result[i] = (byte)(l & 0xFF); // l >>= 8; // } // return result; // } // // /** // * Converts an int to a little endian byte array. // * @param _int The int to convert. // * @return A little endian array. // */ // public static byte[] intToBytes(int _int) { // byte[] result = new byte[4]; // for (int i = 0; i <= 3; i++) { // result[i] = (byte)(_int & 0xFF); // _int >>= 8; // } // return result; // } // // public static Map<Integer, String> printableSpansWithIndexes(byte[] bytes, int minLength, boolean filterRandom, int randomThreshold) { // // Map<Integer, String> spanPairs = new HashMap<>(); // int[] table = new int[bytes.length]; // int tableSize = 0; // int strStart, strSize; // byte[] byteSpan; // String span; // // // for (int i = 0; i < bytes.length; i++) // { // if (!isPrintable(bytes[i])) // { // table[tableSize++] = i; // } // } // // for (int j = 1; j < tableSize; j++) // { // if (table[j] == 0) // { // continue; // } // // strStart = table[j - 1] + 1; // strSize = table[j] - strStart; // // if (strSize < minLength) // { // continue; // } // // // byteSpan = Arrays.copyOfRange(bytes, strStart, strStart + strSize); // span = new String(byteSpan, StandardCharsets.US_ASCII); // spanPairs.put(strStart, span); // } // // if (filterRandom) // { // //TODO: Bother with this? // return spanPairs; // } // else // { // return spanPairs; // } // } // // private static boolean isPrintable(byte b) // { // return (b >= 0x20 && b < 0x7F) || b == 0x0a || b == 0x0d || b == 0x09; // } // } // Path: src/com/ciphertechsolutions/io/processing/CompressionTask.java import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.concurrent.Callable; import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; import javax.xml.bind.DatatypeConverter; import com.ciphertechsolutions.io.ewf.DataChunk; import com.ciphertechsolutions.io.processing.triage.ByteUtils; package com.ciphertechsolutions.io.processing; class CompressionTask implements Callable<DataChunk> { private final byte[] input; private final int compressionLevel; CompressionTask(byte[] toCompress, int compressionLevel) { input = toCompress; this.compressionLevel = compressionLevel; } @Override public DataChunk call() throws Exception { Deflater deflater = new Deflater(compressionLevel); deflater.setInput(input); deflater.finish(); byte[] output = new byte[input.length + 4]; int compressedSize = deflater.deflate(output); //Unlikely, but possible. if (compressedSize >= input.length) { System.arraycopy(input, 0, output, 0, input.length);
System.arraycopy(ByteUtils.intToBytes(deflater.getAdler()), 0, output, input.length, 4);
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/ewf/VolumeSectionManager.java
// Path: src/com/ciphertechsolutions/io/device/Device.java // public abstract class Device { // // /** // * The simple name of a device. // */ // protected String name; // // /// The path to read the device with. // protected String path; // // /** // * The size of the device in bytes. // */ // protected long size; // // /** // * Gives detailed information about this device as a printable string. // * @return A printable string of device information. // */ // public abstract String details(); // // /** // * Converts the device name to a format appropriate for outputting as a file name. Does not include file extension. // * @return A valid file name containing device-relevant information. // */ // public abstract String toFileNameString(); // // /** // * // * @return The device path. // */ // public Path getPath() { // return Paths.get(path); // } // // /** // * @return the name // */ // public String getName() { // return name; // } // // /** // * @param name the name to set // */ // public void setName(String name) { // this.name = name; // } // // /** // * Get the device serial number // * @return The serial number. // */ // public abstract String getSerialNumber(); // // protected static String trimPropertyName(String s) { // if (s.contains(":")) { // return s.substring(s.indexOf(":") + 1).trim(); // } // return s; // } // // /** // * @return the size // */ // public long getSize() { // return size; // } // // /** // * @param size the size to set // */ // public void setSize(long size) { // this.size = size; // } // }
import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import com.ciphertechsolutions.io.device.Device;
package com.ciphertechsolutions.io.ewf; public class VolumeSectionManager { private final Map<RandomAccessFile, List<VolumeSection>> volumeSections; private final byte[] EMPTY_VOLUME_SECTION = new byte[VolumeSection.ADDITIONAL_SECTION_SIZE + Section.SECTION_HEADER_SIZE];
// Path: src/com/ciphertechsolutions/io/device/Device.java // public abstract class Device { // // /** // * The simple name of a device. // */ // protected String name; // // /// The path to read the device with. // protected String path; // // /** // * The size of the device in bytes. // */ // protected long size; // // /** // * Gives detailed information about this device as a printable string. // * @return A printable string of device information. // */ // public abstract String details(); // // /** // * Converts the device name to a format appropriate for outputting as a file name. Does not include file extension. // * @return A valid file name containing device-relevant information. // */ // public abstract String toFileNameString(); // // /** // * // * @return The device path. // */ // public Path getPath() { // return Paths.get(path); // } // // /** // * @return the name // */ // public String getName() { // return name; // } // // /** // * @param name the name to set // */ // public void setName(String name) { // this.name = name; // } // // /** // * Get the device serial number // * @return The serial number. // */ // public abstract String getSerialNumber(); // // protected static String trimPropertyName(String s) { // if (s.contains(":")) { // return s.substring(s.indexOf(":") + 1).trim(); // } // return s; // } // // /** // * @return the size // */ // public long getSize() { // return size; // } // // /** // * @param size the size to set // */ // public void setSize(long size) { // this.size = size; // } // } // Path: src/com/ciphertechsolutions/io/ewf/VolumeSectionManager.java import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import com.ciphertechsolutions.io.device.Device; package com.ciphertechsolutions.io.ewf; public class VolumeSectionManager { private final Map<RandomAccessFile, List<VolumeSection>> volumeSections; private final byte[] EMPTY_VOLUME_SECTION = new byte[VolumeSection.ADDITIONAL_SECTION_SIZE + Section.SECTION_HEADER_SIZE];
private final Device imagedDisk;
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/ewf/VolumeSection.java
// Path: src/com/ciphertechsolutions/io/device/Device.java // public abstract class Device { // // /** // * The simple name of a device. // */ // protected String name; // // /// The path to read the device with. // protected String path; // // /** // * The size of the device in bytes. // */ // protected long size; // // /** // * Gives detailed information about this device as a printable string. // * @return A printable string of device information. // */ // public abstract String details(); // // /** // * Converts the device name to a format appropriate for outputting as a file name. Does not include file extension. // * @return A valid file name containing device-relevant information. // */ // public abstract String toFileNameString(); // // /** // * // * @return The device path. // */ // public Path getPath() { // return Paths.get(path); // } // // /** // * @return the name // */ // public String getName() { // return name; // } // // /** // * @param name the name to set // */ // public void setName(String name) { // this.name = name; // } // // /** // * Get the device serial number // * @return The serial number. // */ // public abstract String getSerialNumber(); // // protected static String trimPropertyName(String s) { // if (s.contains(":")) { // return s.substring(s.indexOf(":") + 1).trim(); // } // return s; // } // // /** // * @return the size // */ // public long getSize() { // return size; // } // // /** // * @param size the size to set // */ // public void setSize(long size) { // this.size = size; // } // }
import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.zip.Adler32; import com.ciphertechsolutions.io.device.Device;
package com.ciphertechsolutions.io.ewf; /** * A class to represent the Volume section in the Encase6 format. */ public class VolumeSection extends Section { static final int ADDITIONAL_SECTION_SIZE = 1052; //TODO: Enum? //0x00 => removable disk // 0x01 => fixed disk // 0x03 => optical disk // 0x0e => Logical evidence file (LEV or L01) // 0x10 => memory (RAM/process) MediaType mediaType; byte[] unknown = { 0x00, 0x00, 0x00 }; int chunkCount; // TODO: Have the chunker set these, or be set from these. int sectorsPerChunk; int bytesPerSector; //TODO: Confirm long vs int long sectorCount; int cylinders; // Per cylinder, I think int heads; // Per head, I think int sectors; int mediaFlag; int IS_IMAGE_FILE_FLAG = 0x01; int IS_PHYSICAL_FLAG = 0x02; int FASTBLOC_USED_FLAG = 0x04; int TABLEAU_BLOCK_USED_FLAG = 0x08; // ??? int palmVolumeStartSector; byte[] unknown2 = {0x00, 0x00, 0x00, 0x00}; int smartLogStartSector; // I don't think this corresponds exactly to zlib levels, unsure though. int compressionLevel; //TODO: Tie this to our error handling in drive reader? int errorGranularity; byte[] unknown3 = {0x00, 0x00, 0x00, 0x00}; byte[] fileSetGUID = new byte[16]; // I am not typing this one out. byte[] unknown4 = new byte[963]; //??? byte[] signature = new byte[5]; int secondaryAdler32 = 0;
// Path: src/com/ciphertechsolutions/io/device/Device.java // public abstract class Device { // // /** // * The simple name of a device. // */ // protected String name; // // /// The path to read the device with. // protected String path; // // /** // * The size of the device in bytes. // */ // protected long size; // // /** // * Gives detailed information about this device as a printable string. // * @return A printable string of device information. // */ // public abstract String details(); // // /** // * Converts the device name to a format appropriate for outputting as a file name. Does not include file extension. // * @return A valid file name containing device-relevant information. // */ // public abstract String toFileNameString(); // // /** // * // * @return The device path. // */ // public Path getPath() { // return Paths.get(path); // } // // /** // * @return the name // */ // public String getName() { // return name; // } // // /** // * @param name the name to set // */ // public void setName(String name) { // this.name = name; // } // // /** // * Get the device serial number // * @return The serial number. // */ // public abstract String getSerialNumber(); // // protected static String trimPropertyName(String s) { // if (s.contains(":")) { // return s.substring(s.indexOf(":") + 1).trim(); // } // return s; // } // // /** // * @return the size // */ // public long getSize() { // return size; // } // // /** // * @param size the size to set // */ // public void setSize(long size) { // this.size = size; // } // } // Path: src/com/ciphertechsolutions/io/ewf/VolumeSection.java import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.zip.Adler32; import com.ciphertechsolutions.io.device.Device; package com.ciphertechsolutions.io.ewf; /** * A class to represent the Volume section in the Encase6 format. */ public class VolumeSection extends Section { static final int ADDITIONAL_SECTION_SIZE = 1052; //TODO: Enum? //0x00 => removable disk // 0x01 => fixed disk // 0x03 => optical disk // 0x0e => Logical evidence file (LEV or L01) // 0x10 => memory (RAM/process) MediaType mediaType; byte[] unknown = { 0x00, 0x00, 0x00 }; int chunkCount; // TODO: Have the chunker set these, or be set from these. int sectorsPerChunk; int bytesPerSector; //TODO: Confirm long vs int long sectorCount; int cylinders; // Per cylinder, I think int heads; // Per head, I think int sectors; int mediaFlag; int IS_IMAGE_FILE_FLAG = 0x01; int IS_PHYSICAL_FLAG = 0x02; int FASTBLOC_USED_FLAG = 0x04; int TABLEAU_BLOCK_USED_FLAG = 0x08; // ??? int palmVolumeStartSector; byte[] unknown2 = {0x00, 0x00, 0x00, 0x00}; int smartLogStartSector; // I don't think this corresponds exactly to zlib levels, unsure though. int compressionLevel; //TODO: Tie this to our error handling in drive reader? int errorGranularity; byte[] unknown3 = {0x00, 0x00, 0x00, 0x00}; byte[] fileSetGUID = new byte[16]; // I am not typing this one out. byte[] unknown4 = new byte[963]; //??? byte[] signature = new byte[5]; int secondaryAdler32 = 0;
protected VolumeSection(long currentOffset, Device disk, byte[] guid) {
ciphertechsolutions/IO
src/com/ciphertechsolutions/io/ui/ImagingController.java
// Path: src/com/ciphertechsolutions/io/applicationLogic/Utils.java // public class Utils { // // /** // * Converts the given duration to a string in the format of "x days hh:mm:ss", "hh:mm:ss", or "x seconds", // * depending on the amount of time in the duration. // * @param duration The duration to convert to a string. // * @return The duration as a string. // */ // public static String getPrettyTime(Duration duration) { // StringBuilder timeString = new StringBuilder(); // long seconds = duration.getSeconds(); // addDays(duration, timeString); // addHours(duration, timeString, seconds); // addMinutesAndSeconds(duration, timeString, seconds); // return timeString.toString(); // } // // private static void addMinutesAndSeconds(Duration duration, StringBuilder timeString, long seconds) { // if (duration.toMinutes() >= 1) { // int remainingMinutes = (int) ((seconds % 3600) / 60); // padIfNeeded(timeString, remainingMinutes); // timeString.append(":"); // int remainingSeconds = (int) (seconds % 60); // padIfNeeded(timeString, remainingSeconds); // } // else { // timeString.append(seconds % 60); // timeString.append(" seconds."); // } // } // // private static void addHours(Duration duration, StringBuilder timeString, long seconds) { // if (duration.toHours() >= 1) { // timeString.append((seconds % 86400)/ 3600); // timeString.append(":"); // } // } // // private static void addDays(Duration duration, StringBuilder timeString) { // if (duration.toDays() >= 1) { // timeString.append(duration.toDays()); // timeString.append(" days "); // } // } // // private static void padIfNeeded(StringBuilder timeString, int remaining) { // if (remaining < 10) { // timeString.append("0"); // } // timeString.append(remaining); // } // }
import java.net.URL; import java.time.Duration; import java.util.List; import java.util.ResourceBundle; import com.ciphertechsolutions.io.applicationLogic.Utils; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.WeakChangeListener; import javafx.collections.ListChangeListener; import javafx.collections.WeakListChangeListener; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.TextArea;
private int calls; private double lastAverage; private final long max; private final long startTime; protected ProgressStatus() { calls = 0; lastAverage = 0; max = workflowController.getMaxOutputCount(); startTime = System.nanoTime(); } protected void onChange(long newCount) { double percentComplete = newCount / (double) max; calls++; if (calls % 250 == 0) { estimateRemainingTime(percentComplete); } if (newCount == max) { timeEstimateLabel.setText("Complete"); setReturnVisible(); } else if (lastAverage > 0) { timeEstimateLabel.setText(Math.round((1 - percentComplete) * 100) + "% remaining: " + getTime()); timeEstimateLabel.setVisible(true); } progressBar.setProgress(percentComplete); } protected String getTime() {
// Path: src/com/ciphertechsolutions/io/applicationLogic/Utils.java // public class Utils { // // /** // * Converts the given duration to a string in the format of "x days hh:mm:ss", "hh:mm:ss", or "x seconds", // * depending on the amount of time in the duration. // * @param duration The duration to convert to a string. // * @return The duration as a string. // */ // public static String getPrettyTime(Duration duration) { // StringBuilder timeString = new StringBuilder(); // long seconds = duration.getSeconds(); // addDays(duration, timeString); // addHours(duration, timeString, seconds); // addMinutesAndSeconds(duration, timeString, seconds); // return timeString.toString(); // } // // private static void addMinutesAndSeconds(Duration duration, StringBuilder timeString, long seconds) { // if (duration.toMinutes() >= 1) { // int remainingMinutes = (int) ((seconds % 3600) / 60); // padIfNeeded(timeString, remainingMinutes); // timeString.append(":"); // int remainingSeconds = (int) (seconds % 60); // padIfNeeded(timeString, remainingSeconds); // } // else { // timeString.append(seconds % 60); // timeString.append(" seconds."); // } // } // // private static void addHours(Duration duration, StringBuilder timeString, long seconds) { // if (duration.toHours() >= 1) { // timeString.append((seconds % 86400)/ 3600); // timeString.append(":"); // } // } // // private static void addDays(Duration duration, StringBuilder timeString) { // if (duration.toDays() >= 1) { // timeString.append(duration.toDays()); // timeString.append(" days "); // } // } // // private static void padIfNeeded(StringBuilder timeString, int remaining) { // if (remaining < 10) { // timeString.append("0"); // } // timeString.append(remaining); // } // } // Path: src/com/ciphertechsolutions/io/ui/ImagingController.java import java.net.URL; import java.time.Duration; import java.util.List; import java.util.ResourceBundle; import com.ciphertechsolutions.io.applicationLogic.Utils; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.WeakChangeListener; import javafx.collections.ListChangeListener; import javafx.collections.WeakListChangeListener; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.TextArea; private int calls; private double lastAverage; private final long max; private final long startTime; protected ProgressStatus() { calls = 0; lastAverage = 0; max = workflowController.getMaxOutputCount(); startTime = System.nanoTime(); } protected void onChange(long newCount) { double percentComplete = newCount / (double) max; calls++; if (calls % 250 == 0) { estimateRemainingTime(percentComplete); } if (newCount == max) { timeEstimateLabel.setText("Complete"); setReturnVisible(); } else if (lastAverage > 0) { timeEstimateLabel.setText(Math.round((1 - percentComplete) * 100) + "% remaining: " + getTime()); timeEstimateLabel.setVisible(true); } progressBar.setProgress(percentComplete); } protected String getTime() {
return Utils.getPrettyTime(Duration.ofSeconds(Math.max(Math.round(lastAverage - (System.nanoTime() - startTime) / 1000000000), 0)));
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/GuiceyMongoBinder.java
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongoUtil.java // public final class GuiceyMongoUtil { // @Inject // static Injector _injector; // // private GuiceyMongoUtil() {} // // public static String getCurrentConfiguration() { // return _injector.getInstance(Key.get(String.class, Configuration.class)); // } // // public static void setCurrentConfiguration(Binder binder, String configuration) { // binder.skipSources(GuiceyMongoUtil.class).bindConstant().annotatedWith(Configuration.class).to(configuration); // } // // public static DB getDatabase(String databaseKey) { // return _injector.getInstance(Key.get(DB.class, GuiceyMongoDatabases.database(databaseKey))); // } // // public static DBCollection getCollection(String collectionKey) { // return _injector.getInstance(Key.get(DBCollection.class, GuiceyMongoCollections.collection(collectionKey))); // } // // public static <T extends IsData> GuiceyCollection<T> getGuiceyCollection(String collectionKey, Class<T> dataClass) { // return (GuiceyCollection<T>)_injector.getInstance(Key.get(Types.newParameterizedType(GuiceyCollection.class, dataClass), GuiceyMongoCollections.collection(collectionKey))); // } // // public static GuiceyBucket getGuiceyBucket(String bucketKey) { // return _injector.getInstance(Key.get(GuiceyBucket.class, GuiceyMongoBuckets.bucket(bucketKey))); // } // }
import java.util.Map; import com.google.inject.Binder; import com.google.inject.Key; import com.google.inject.Module; import com.lowereast.guiceymongo.guice.GuiceyMongoUtil;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public class GuiceyMongoBinder { private final Binder _binder; public GuiceyMongoBinder(Binder binder) { _binder = binder.skipSources(GuiceyMongoBinder.class);
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongoUtil.java // public final class GuiceyMongoUtil { // @Inject // static Injector _injector; // // private GuiceyMongoUtil() {} // // public static String getCurrentConfiguration() { // return _injector.getInstance(Key.get(String.class, Configuration.class)); // } // // public static void setCurrentConfiguration(Binder binder, String configuration) { // binder.skipSources(GuiceyMongoUtil.class).bindConstant().annotatedWith(Configuration.class).to(configuration); // } // // public static DB getDatabase(String databaseKey) { // return _injector.getInstance(Key.get(DB.class, GuiceyMongoDatabases.database(databaseKey))); // } // // public static DBCollection getCollection(String collectionKey) { // return _injector.getInstance(Key.get(DBCollection.class, GuiceyMongoCollections.collection(collectionKey))); // } // // public static <T extends IsData> GuiceyCollection<T> getGuiceyCollection(String collectionKey, Class<T> dataClass) { // return (GuiceyCollection<T>)_injector.getInstance(Key.get(Types.newParameterizedType(GuiceyCollection.class, dataClass), GuiceyMongoCollections.collection(collectionKey))); // } // // public static GuiceyBucket getGuiceyBucket(String bucketKey) { // return _injector.getInstance(Key.get(GuiceyBucket.class, GuiceyMongoBuckets.bucket(bucketKey))); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/GuiceyMongoBinder.java import java.util.Map; import com.google.inject.Binder; import com.google.inject.Key; import com.google.inject.Module; import com.lowereast.guiceymongo.guice.GuiceyMongoUtil; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public class GuiceyMongoBinder { private final Binder _binder; public GuiceyMongoBinder(Binder binder) { _binder = binder.skipSources(GuiceyMongoBinder.class);
_binder.install(new SingletonModule<Class<GuiceyMongoUtil>>(GuiceyMongoUtil.class) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/property/ListProperty.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/ListType.java // public class ListType extends Type { // private Type _itemType; // // public ListType(Type itemType) { // super("list", "java.util.List<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import com.lowereast.guiceymongo.data.generator.type.ListType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class ListProperty extends Property<ListType> { public ListProperty(UserDataType enclosingType, String name, ListType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "List"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getListItemType() {
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/ListType.java // public class ListType extends Type { // private Type _itemType; // // public ListType(Type itemType) { // super("list", "java.util.List<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/ListProperty.java import com.lowereast.guiceymongo.data.generator.type.ListType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class ListProperty extends Property<ListType> { public ListProperty(UserDataType enclosingType, String name, ListType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "List"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getListItemType() {
Type type = super.getType().getItemType();
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/property/ListProperty.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/ListType.java // public class ListType extends Type { // private Type _itemType; // // public ListType(Type itemType) { // super("list", "java.util.List<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import com.lowereast.guiceymongo.data.generator.type.ListType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class ListProperty extends Property<ListType> { public ListProperty(UserDataType enclosingType, String name, ListType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "List"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getListItemType() { Type type = super.getType().getItemType();
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/ListType.java // public class ListType extends Type { // private Type _itemType; // // public ListType(Type itemType) { // super("list", "java.util.List<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/ListProperty.java import com.lowereast.guiceymongo.data.generator.type.ListType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class ListProperty extends Property<ListType> { public ListProperty(UserDataType enclosingType, String name, ListType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "List"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getListItemType() { Type type = super.getType().getItemType();
if (type instanceof PrimitiveType)
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/property/PrimitiveProperty.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/option/Option.java // public class Option { // private final String _name; // private final Map<String, Object> _parameters = Maps.newHashMap(); // // public Option(String name) { // _name = name; // } // // public String getName() { // return _name; // } // // public void addParameter(String name, Object value) { // _parameters.put(name, value); // } // // public Map<String, Object> getParameters() { // return _parameters; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import java.util.Map; import com.lowereast.guiceymongo.data.generator.option.Option; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class PrimitiveProperty extends Property<PrimitiveType> { public PrimitiveProperty(UserDataType enclosingType, String name, PrimitiveType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getKeyValue() { if (super.hasOption("identity")) {
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/option/Option.java // public class Option { // private final String _name; // private final Map<String, Object> _parameters = Maps.newHashMap(); // // public Option(String name) { // _name = name; // } // // public String getName() { // return _name; // } // // public void addParameter(String name, Object value) { // _parameters.put(name, value); // } // // public Map<String, Object> getParameters() { // return _parameters; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/PrimitiveProperty.java import java.util.Map; import com.lowereast.guiceymongo.data.generator.option.Option; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class PrimitiveProperty extends Property<PrimitiveType> { public PrimitiveProperty(UserDataType enclosingType, String name, PrimitiveType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getKeyValue() { if (super.hasOption("identity")) {
Option option = super.getOption("identity");
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/PrimitivePropertyGenerator.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/PrimitiveProperty.java // public class PrimitiveProperty extends Property<PrimitiveType> { // public PrimitiveProperty(UserDataType enclosingType, String name, PrimitiveType type, String comment, boolean useCamelCaseKeys) { // super(enclosingType, name, type, comment, useCamelCaseKeys); // } // // @Override // public String getKeyValue() { // if (super.hasOption("identity")) { // Option option = super.getOption("identity"); // if (option.getParameters().isEmpty()) // return "_id"; // String value = null; // for (Map.Entry<String, Object> e : option.getParameters().entrySet()) { // if ("value".equals(e.getKey())) // value = e.getValue().toString(); // } // if (value == null) // throw new RuntimeException("Problems with the identity option... Can only be [identity] or [identity('key')] or [identity(value='key')]"); // return value; // } // return super.getKeyValue(); // } // // public String getPrimitiveType() { // return super.getType().getJavaType(); // } // // public String getPrimitiveBoxedType() { // return super.getType().getJavaBoxedType(); // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // }
import java.io.IOException; import org.antlr.stringtemplate.StringTemplate; import com.lowereast.guiceymongo.data.generator.property.PrimitiveProperty; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class PrimitivePropertyGenerator extends PropertyGenerator<PrimitiveType, PrimitiveProperty> { public PrimitivePropertyGenerator(TypeRegistry typeRegistry) { super(PrimitiveType.class, typeRegistry); } @Override public void createEquals(Appendable builder, PrimitiveProperty property, int indentCount) throws IOException {
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/PrimitiveProperty.java // public class PrimitiveProperty extends Property<PrimitiveType> { // public PrimitiveProperty(UserDataType enclosingType, String name, PrimitiveType type, String comment, boolean useCamelCaseKeys) { // super(enclosingType, name, type, comment, useCamelCaseKeys); // } // // @Override // public String getKeyValue() { // if (super.hasOption("identity")) { // Option option = super.getOption("identity"); // if (option.getParameters().isEmpty()) // return "_id"; // String value = null; // for (Map.Entry<String, Object> e : option.getParameters().entrySet()) { // if ("value".equals(e.getKey())) // value = e.getValue().toString(); // } // if (value == null) // throw new RuntimeException("Problems with the identity option... Can only be [identity] or [identity('key')] or [identity(value='key')]"); // return value; // } // return super.getKeyValue(); // } // // public String getPrimitiveType() { // return super.getType().getJavaType(); // } // // public String getPrimitiveBoxedType() { // return super.getType().getJavaBoxedType(); // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/PrimitivePropertyGenerator.java import java.io.IOException; import org.antlr.stringtemplate.StringTemplate; import com.lowereast.guiceymongo.data.generator.property.PrimitiveProperty; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class PrimitivePropertyGenerator extends PropertyGenerator<PrimitiveType, PrimitiveProperty> { public PrimitivePropertyGenerator(TypeRegistry typeRegistry) { super(PrimitiveType.class, typeRegistry); } @Override public void createEquals(Appendable builder, PrimitiveProperty property, int indentCount) throws IOException {
Type type = property.getType();
mattinsler/com.lowereast.guiceymongo
src/examples/CollectionConfigurationExample.java
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoCollection; import com.mongodb.DBCollection;
/** * Copyright (C) 2010 Lowereast Software * * 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. */ public class CollectionConfigurationExample { @Inject CollectionConfigurationExample(@GuiceyMongoCollection(Collections.Data) DBCollection collection) { System.out.println(collection.getDB() + " : " + collection); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the test configuration
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/examples/CollectionConfigurationExample.java import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoCollection; import com.mongodb.DBCollection; /** * Copyright (C) 2010 Lowereast Software * * 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. */ public class CollectionConfigurationExample { @Inject CollectionConfigurationExample(@GuiceyMongoCollection(Collections.Data) DBCollection collection) { System.out.println(collection.getDB() + " : " + collection); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the test configuration
GuiceyMongo.configure(Configurations.Test)
mattinsler/com.lowereast.guiceymongo
src/examples/DatabaseConfigurationExample.java
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.matcher.Matchers; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; import com.mongodb.DB;
/** * Copyright (C) 2010 Lowereast Software * * 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. */ public class DatabaseConfigurationExample { @Inject DatabaseConfigurationExample(@GuiceyMongoDatabase(Databases.Main) DB mainDatabase, @GuiceyMongoDatabase(Databases.Search) DB searchDatabase) { System.out.println(mainDatabase); System.out.println(searchDatabase); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the production configuration
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/examples/DatabaseConfigurationExample.java import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.matcher.Matchers; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; import com.mongodb.DB; /** * Copyright (C) 2010 Lowereast Software * * 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. */ public class DatabaseConfigurationExample { @Inject DatabaseConfigurationExample(@GuiceyMongoDatabase(Databases.Main) DB mainDatabase, @GuiceyMongoDatabase(Databases.Search) DB searchDatabase) { System.out.println(mainDatabase); System.out.println(searchDatabase); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the production configuration
GuiceyMongo.configure(Configurations.Production)
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/AnnotationUtil.java
// Path: src/main/java/com/lowereast/guiceymongo/annotation/Annotations.java // public class Annotations { // private static class AnnotationProxy<T extends Annotation> implements InvocationHandler { // private final Class<T> _annotationClass; // private final List<String> _elements = Lists.newArrayList(); // private final Map<String, Object> _values; // private final Map<String, Method> _methods = Maps.newHashMap(); // // public AnnotationProxy(Class<T> annotationClass, Map<String, Object> values) { // _values = (values == null ? Maps.<String, Object>newHashMap() : new HashMap<String, Object>(values)); // _annotationClass = annotationClass; // for (Method method : _annotationClass.getDeclaredMethods()) { // if (Modifier.isPublic(method.getModifiers()) && Modifier.isAbstract(method.getModifiers()) && method.getParameterTypes().length == 0) { // String elementName = method.getName(); // _elements.add(elementName); // _methods.put(elementName, method); // Object defaultValue = method.getDefaultValue(); // if (defaultValue != null && !_values.containsKey(elementName)) // _values.put(elementName, defaultValue); // } // } // } // // private static boolean isEqualToAny(Object lhs, Object... rhs) { // for (Object item : rhs) { // if (lhs.equals(item)) // return true; // } // return false; // } // // private int valueHashCode(Class<?> elementType, Object value) { // if (elementType.isArray()) { // return Arrays.hashCode((Object[])value); // } else if (isEqualToAny(elementType, // byte.class, Byte.class, // char.class, Character.class, // double.class, Double.class, // float.class, Float.class, // int.class, Integer.class, // long.class, Long.class, // short.class, Short.class, // boolean.class, Boolean.class, // String.class) // || elementType.isEnum() // || elementType.isAnnotation()) { // return value.hashCode(); // } // throw new RuntimeException("This shouldn't happen"); // } // // private int calculateHashCode() { // // This is specified in java.lang.Annotation. // int hashCode = 0; // for (String element : _elements) // hashCode += (127 * element.hashCode()) ^ valueHashCode(_methods.get(element).getReturnType(), _values.get(element)); // return hashCode; // } // // private boolean checkEquals(Object other) throws Throwable { // if (!_annotationClass.isAssignableFrom(other.getClass())) // return false; // for (String element : _elements) { // Method method = _methods.get(element); // method.setAccessible(true); // Object value = _values.get(element); // Object otherValue = method.invoke(other); // if (!value.equals(otherValue)) // return false; // } // return true; // } // // private String buildString() { // StringBuilder builder = new StringBuilder("@").append(_annotationClass.getName()); // if (_elements.size() > 0) { // builder.append("("); // for (int x = 0; x < _elements.size(); ++x) { // if (x > 0) // builder.append(","); // builder.append(_elements.get(x)).append("=").append(_values.get(_elements.get(x))); // } // builder.append(")"); // } // return builder.toString(); // } // // // http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html // public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // String methodName = method.getName(); // // if ("annotationType".equals(methodName)) { // return _annotationClass; // } else if ("equals".equals(methodName)) { // return checkEquals(args[0]); // } else if ("hashCode".equals(methodName)) { // return calculateHashCode(); // } else if ("toString".equals(methodName)) { // return buildString(); // } else if (_elements.contains(methodName)) { // return _values.get(methodName); // } // throw new RuntimeException(); // } // } // // public static <T extends Annotation> T proxy(Class<T> annotationClass) { // return proxy(annotationClass, null); // } // // @SuppressWarnings("unchecked") // public static <T extends Annotation> T proxy(Class<T> annotationClass, Map<String, Object> values) { // return (T)Proxy.newProxyInstance(annotationClass.getClassLoader(), new Class[] { annotationClass, Serializable.class }, new AnnotationProxy(annotationClass, values)); // } // }
import com.google.inject.internal.ImmutableMap; import com.lowereast.guiceymongo.annotation.Annotations; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoBucket; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoCollection; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; final class AnnotationUtil { private AnnotationUtil() {} public static ClonedConfiguration clonedConfiguration(String configuration) {
// Path: src/main/java/com/lowereast/guiceymongo/annotation/Annotations.java // public class Annotations { // private static class AnnotationProxy<T extends Annotation> implements InvocationHandler { // private final Class<T> _annotationClass; // private final List<String> _elements = Lists.newArrayList(); // private final Map<String, Object> _values; // private final Map<String, Method> _methods = Maps.newHashMap(); // // public AnnotationProxy(Class<T> annotationClass, Map<String, Object> values) { // _values = (values == null ? Maps.<String, Object>newHashMap() : new HashMap<String, Object>(values)); // _annotationClass = annotationClass; // for (Method method : _annotationClass.getDeclaredMethods()) { // if (Modifier.isPublic(method.getModifiers()) && Modifier.isAbstract(method.getModifiers()) && method.getParameterTypes().length == 0) { // String elementName = method.getName(); // _elements.add(elementName); // _methods.put(elementName, method); // Object defaultValue = method.getDefaultValue(); // if (defaultValue != null && !_values.containsKey(elementName)) // _values.put(elementName, defaultValue); // } // } // } // // private static boolean isEqualToAny(Object lhs, Object... rhs) { // for (Object item : rhs) { // if (lhs.equals(item)) // return true; // } // return false; // } // // private int valueHashCode(Class<?> elementType, Object value) { // if (elementType.isArray()) { // return Arrays.hashCode((Object[])value); // } else if (isEqualToAny(elementType, // byte.class, Byte.class, // char.class, Character.class, // double.class, Double.class, // float.class, Float.class, // int.class, Integer.class, // long.class, Long.class, // short.class, Short.class, // boolean.class, Boolean.class, // String.class) // || elementType.isEnum() // || elementType.isAnnotation()) { // return value.hashCode(); // } // throw new RuntimeException("This shouldn't happen"); // } // // private int calculateHashCode() { // // This is specified in java.lang.Annotation. // int hashCode = 0; // for (String element : _elements) // hashCode += (127 * element.hashCode()) ^ valueHashCode(_methods.get(element).getReturnType(), _values.get(element)); // return hashCode; // } // // private boolean checkEquals(Object other) throws Throwable { // if (!_annotationClass.isAssignableFrom(other.getClass())) // return false; // for (String element : _elements) { // Method method = _methods.get(element); // method.setAccessible(true); // Object value = _values.get(element); // Object otherValue = method.invoke(other); // if (!value.equals(otherValue)) // return false; // } // return true; // } // // private String buildString() { // StringBuilder builder = new StringBuilder("@").append(_annotationClass.getName()); // if (_elements.size() > 0) { // builder.append("("); // for (int x = 0; x < _elements.size(); ++x) { // if (x > 0) // builder.append(","); // builder.append(_elements.get(x)).append("=").append(_values.get(_elements.get(x))); // } // builder.append(")"); // } // return builder.toString(); // } // // // http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html // public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // String methodName = method.getName(); // // if ("annotationType".equals(methodName)) { // return _annotationClass; // } else if ("equals".equals(methodName)) { // return checkEquals(args[0]); // } else if ("hashCode".equals(methodName)) { // return calculateHashCode(); // } else if ("toString".equals(methodName)) { // return buildString(); // } else if (_elements.contains(methodName)) { // return _values.get(methodName); // } // throw new RuntimeException(); // } // } // // public static <T extends Annotation> T proxy(Class<T> annotationClass) { // return proxy(annotationClass, null); // } // // @SuppressWarnings("unchecked") // public static <T extends Annotation> T proxy(Class<T> annotationClass, Map<String, Object> values) { // return (T)Proxy.newProxyInstance(annotationClass.getClassLoader(), new Class[] { annotationClass, Serializable.class }, new AnnotationProxy(annotationClass, values)); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/AnnotationUtil.java import com.google.inject.internal.ImmutableMap; import com.lowereast.guiceymongo.annotation.Annotations; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoBucket; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoCollection; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; final class AnnotationUtil { private AnnotationUtil() {} public static ClonedConfiguration clonedConfiguration(String configuration) {
return Annotations.proxy(ClonedConfiguration.class, ImmutableMap.<String, Object>of("configuration", configuration));
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/GuiceyMongoBindingCollector.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // }
import java.util.List; import java.util.Map; import java.util.Set; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.google.inject.internal.Sets; import com.lowereast.guiceymongo.data.IsData;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public class GuiceyMongoBindingCollector { private final List<String> _errors = Lists.newArrayList(); private final Set<Module> _modules = Sets.newHashSet(); private final Map<Key<?>, Object> _instanceBindings = Maps.newHashMap(); public GuiceyMongoBindingCollector() { } public void addError(String message) { _errors.add(message); } public void bindClonedConfiguration(String configurationName, String clonedConfigurationName) { _instanceBindings.put(Key.get(String.class, AnnotationUtil.clonedConfiguration(configurationName)), clonedConfigurationName); } public void bindConnectionHostname(String connectionKey, String hostname) { _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredConnectionHostname(connectionKey)), hostname); } public void bindConnectionPort(String connectionKey, int port) { _instanceBindings.put(Key.get(int.class, AnnotationUtil.configuredConnectionPort(connectionKey)), port); } public void bindConfiguredDatabase(String configurationName, String databaseKey, String database) { _modules.add(new DBProviderModule(databaseKey)); _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredDatabase(configurationName, databaseKey)), database); } public void bindConfiguredDatabaseConnection(String configurationName, String databaseKey, String connectionKey) { _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredDatabaseConnection(configurationName, databaseKey)), connectionKey); } public void bindConfiguredCollection(String configurationName, String databaseKey, String collectionKey, String collection) { _modules.add(new CollectionProviderModule(databaseKey, collectionKey)); _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredCollection(configurationName, collectionKey)), collection); }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/GuiceyMongoBindingCollector.java import java.util.List; import java.util.Map; import java.util.Set; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.google.inject.internal.Sets; import com.lowereast.guiceymongo.data.IsData; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public class GuiceyMongoBindingCollector { private final List<String> _errors = Lists.newArrayList(); private final Set<Module> _modules = Sets.newHashSet(); private final Map<Key<?>, Object> _instanceBindings = Maps.newHashMap(); public GuiceyMongoBindingCollector() { } public void addError(String message) { _errors.add(message); } public void bindClonedConfiguration(String configurationName, String clonedConfigurationName) { _instanceBindings.put(Key.get(String.class, AnnotationUtil.clonedConfiguration(configurationName)), clonedConfigurationName); } public void bindConnectionHostname(String connectionKey, String hostname) { _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredConnectionHostname(connectionKey)), hostname); } public void bindConnectionPort(String connectionKey, int port) { _instanceBindings.put(Key.get(int.class, AnnotationUtil.configuredConnectionPort(connectionKey)), port); } public void bindConfiguredDatabase(String configurationName, String databaseKey, String database) { _modules.add(new DBProviderModule(databaseKey)); _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredDatabase(configurationName, databaseKey)), database); } public void bindConfiguredDatabaseConnection(String configurationName, String databaseKey, String connectionKey) { _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredDatabaseConnection(configurationName, databaseKey)), connectionKey); } public void bindConfiguredCollection(String configurationName, String databaseKey, String collectionKey, String collection) { _modules.add(new CollectionProviderModule(databaseKey, collectionKey)); _instanceBindings.put(Key.get(String.class, AnnotationUtil.configuredCollection(configurationName, collectionKey)), collection); }
public <T extends IsData> void bindConfiguredCollectionDataType(String configurationName, String collectionKey, Class<T> dataType) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/TypeRegistry.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/BlobType.java // public class BlobType extends Type { // public BlobType() { // super("blob", null); // } // // public static BlobType BlobType = new BlobType(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.inject.internal.Lists; import com.lowereast.guiceymongo.data.generator.type.BlobType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class TypeRegistry { public final Map<String, Type> _types = new HashMap<String, Type>(); public TypeRegistry() {
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/BlobType.java // public class BlobType extends Type { // public BlobType() { // super("blob", null); // } // // public static BlobType BlobType = new BlobType(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/TypeRegistry.java import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.inject.internal.Lists; import com.lowereast.guiceymongo.data.generator.type.BlobType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class TypeRegistry { public final Map<String, Type> _types = new HashMap<String, Type>(); public TypeRegistry() {
addType(PrimitiveType.BoolType);
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/TypeRegistry.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/BlobType.java // public class BlobType extends Type { // public BlobType() { // super("blob", null); // } // // public static BlobType BlobType = new BlobType(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.inject.internal.Lists; import com.lowereast.guiceymongo.data.generator.type.BlobType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class TypeRegistry { public final Map<String, Type> _types = new HashMap<String, Type>(); public TypeRegistry() { addType(PrimitiveType.BoolType); addType(PrimitiveType.DBObjectType); addType(PrimitiveType.DBTimestampType); addType(PrimitiveType.DateType); addType(PrimitiveType.DoubleType); addType(PrimitiveType.FloatType); addType(PrimitiveType.Int32Type); addType(PrimitiveType.Int64Type); addType(PrimitiveType.ObjectIdType); addType(PrimitiveType.StringType);
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/BlobType.java // public class BlobType extends Type { // public BlobType() { // super("blob", null); // } // // public static BlobType BlobType = new BlobType(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/TypeRegistry.java import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.inject.internal.Lists; import com.lowereast.guiceymongo.data.generator.type.BlobType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class TypeRegistry { public final Map<String, Type> _types = new HashMap<String, Type>(); public TypeRegistry() { addType(PrimitiveType.BoolType); addType(PrimitiveType.DBObjectType); addType(PrimitiveType.DBTimestampType); addType(PrimitiveType.DateType); addType(PrimitiveType.DoubleType); addType(PrimitiveType.FloatType); addType(PrimitiveType.Int32Type); addType(PrimitiveType.Int64Type); addType(PrimitiveType.ObjectIdType); addType(PrimitiveType.StringType);
addType(BlobType.BlobType);
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/TypeRegistry.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/BlobType.java // public class BlobType extends Type { // public BlobType() { // super("blob", null); // } // // public static BlobType BlobType = new BlobType(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.inject.internal.Lists; import com.lowereast.guiceymongo.data.generator.type.BlobType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class TypeRegistry { public final Map<String, Type> _types = new HashMap<String, Type>(); public TypeRegistry() { addType(PrimitiveType.BoolType); addType(PrimitiveType.DBObjectType); addType(PrimitiveType.DBTimestampType); addType(PrimitiveType.DateType); addType(PrimitiveType.DoubleType); addType(PrimitiveType.FloatType); addType(PrimitiveType.Int32Type); addType(PrimitiveType.Int64Type); addType(PrimitiveType.ObjectIdType); addType(PrimitiveType.StringType); addType(BlobType.BlobType); } public void addType(Type type) { _types.put(type.getGuiceyType(), type); } public <T extends Type> T getGuiceyType(String guiceyType) { return (T)_types.get(guiceyType); }
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/BlobType.java // public class BlobType extends Type { // public BlobType() { // super("blob", null); // } // // public static BlobType BlobType = new BlobType(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/TypeRegistry.java import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.inject.internal.Lists; import com.lowereast.guiceymongo.data.generator.type.BlobType; import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator; public class TypeRegistry { public final Map<String, Type> _types = new HashMap<String, Type>(); public TypeRegistry() { addType(PrimitiveType.BoolType); addType(PrimitiveType.DBObjectType); addType(PrimitiveType.DBTimestampType); addType(PrimitiveType.DateType); addType(PrimitiveType.DoubleType); addType(PrimitiveType.FloatType); addType(PrimitiveType.Int32Type); addType(PrimitiveType.Int64Type); addType(PrimitiveType.ObjectIdType); addType(PrimitiveType.StringType); addType(BlobType.BlobType); } public void addType(Type type) { _types.put(type.getGuiceyType(), type); } public <T extends Type> T getGuiceyType(String guiceyType) { return (T)_types.get(guiceyType); }
public <T extends Type> T getScopedGuiceyType(UserDataType scopingType, String guiceyType) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/GuiceyCollection.java
// Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsBuilder.java // public interface IsBuilder<T extends IsData> { // DBObject build(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // }
import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsBuilder; import com.lowereast.guiceymongo.data.IsData; import com.mongodb.*; import java.util.List;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo; public class GuiceyCollection<Item extends IsData> { private final DBCollection _collection;
// Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsBuilder.java // public interface IsBuilder<T extends IsData> { // DBObject build(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // Path: src/main/java/com/lowereast/guiceymongo/GuiceyCollection.java import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsBuilder; import com.lowereast.guiceymongo.data.IsData; import com.mongodb.*; import java.util.List; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo; public class GuiceyCollection<Item extends IsData> { private final DBCollection _collection;
private final DataWrapper<Item> _wrapper;
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/GuiceyCollection.java
// Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsBuilder.java // public interface IsBuilder<T extends IsData> { // DBObject build(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // }
import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsBuilder; import com.lowereast.guiceymongo.data.IsData; import com.mongodb.*; import java.util.List;
public Item findAndRemove(DBObject query, DBObject sort) { DBObject command = new BasicDBObject("findandmodify", _collection.getName()) .append("remove", true); if (query != null && !EMPTY.equals(query)) command.put("query", query); if (sort != null && !EMPTY.equals(sort)) command.put("sort", sort); DBObject result = _collection.getDB().command(command); if (1 == (Integer)result.get("ok")) return _wrapper.wrap((DBObject)result.get("value")); throw new MongoException((Integer)result.get("code"), (String)result.get("errmsg")); } // public GuiceyQuery.ExecutableCursorBuilder<Item> find() { // return GuiceyQuery.newExecutableCursorBuilder(); // } // public GuiceyQuery.ExecutableCursorBuilder<Item> select(FieldSet fieldSet) { // return GuiceyQuery.newExecutableCursorBuilder(fieldSet); // } public void insert(DBObject item) { _collection.insert(item); } public void insert(DBObject[] items) { _collection.insert(items); }
// Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsBuilder.java // public interface IsBuilder<T extends IsData> { // DBObject build(); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // Path: src/main/java/com/lowereast/guiceymongo/GuiceyCollection.java import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsBuilder; import com.lowereast.guiceymongo.data.IsData; import com.mongodb.*; import java.util.List; public Item findAndRemove(DBObject query, DBObject sort) { DBObject command = new BasicDBObject("findandmodify", _collection.getName()) .append("remove", true); if (query != null && !EMPTY.equals(query)) command.put("query", query); if (sort != null && !EMPTY.equals(sort)) command.put("sort", sort); DBObject result = _collection.getDB().command(command); if (1 == (Integer)result.get("ok")) return _wrapper.wrap((DBObject)result.get("value")); throw new MongoException((Integer)result.get("code"), (String)result.get("errmsg")); } // public GuiceyQuery.ExecutableCursorBuilder<Item> find() { // return GuiceyQuery.newExecutableCursorBuilder(); // } // public GuiceyQuery.ExecutableCursorBuilder<Item> select(FieldSet fieldSet) { // return GuiceyQuery.newExecutableCursorBuilder(fieldSet); // } public void insert(DBObject item) { _collection.insert(item); } public void insert(DBObject[] items) { _collection.insert(items); }
public void insert(IsBuilder<Item> item) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/DBProviderModule.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoException.java // public class GuiceyMongoException extends RuntimeException { // public GuiceyMongoException() { // } // public GuiceyMongoException(String message) { // super(message); // } // public GuiceyMongoException(String message, Throwable throwable) { // super(message, throwable); // } // public GuiceyMongoException(Throwable throwable) { // super(throwable); // } // }
import com.google.inject.*; import com.lowereast.guiceymongo.GuiceyMongoException; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; import com.mongodb.DB; import com.mongodb.Mongo; import com.mongodb.MongoException; import java.net.UnknownHostException; import java.util.UUID;
} private void cacheDB() throws MongoException, UnknownHostException { String databaseKey = ((GuiceyMongoDatabase)key.getAnnotation()).value(); String clonedConfiguration = getInstance(_injector, Key.get(String.class, AnnotationUtil.clonedConfiguration(_configuration))); if (clonedConfiguration == null) { String database = _injector.getInstance(Key.get(String.class, AnnotationUtil.configuredDatabase(_configuration, databaseKey))); Mongo connection = getConnection(_configuration, databaseKey); _cachedDB = connection.getDB(database); // test connection _cachedDB.getCollectionNames(); } else { Mongo connection = getConnection(clonedConfiguration, databaseKey); _cachedDB = connection.getDB(UUID.randomUUID().toString()); String clonedDatabase = _injector.getInstance(Key.get(String.class, AnnotationUtil.configuredDatabase(clonedConfiguration, databaseKey))); _cachedDB.eval("var c = connect('" + clonedDatabase + "'); c.system.js.find().forEach(function(x){db.system.js.save(x)}); db.system.js.ensureIndex({_id: 1});"); Runtime.getRuntime().addShutdownHook(new RemoveTemporaryDB(_cachedDB)); } } private DB _cachedDB; public DB get() { try { if (_cachedDB == null) cacheDB(); return _cachedDB; } catch (MongoException e) {
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoException.java // public class GuiceyMongoException extends RuntimeException { // public GuiceyMongoException() { // } // public GuiceyMongoException(String message) { // super(message); // } // public GuiceyMongoException(String message, Throwable throwable) { // super(message, throwable); // } // public GuiceyMongoException(Throwable throwable) { // super(throwable); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/DBProviderModule.java import com.google.inject.*; import com.lowereast.guiceymongo.GuiceyMongoException; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; import com.mongodb.DB; import com.mongodb.Mongo; import com.mongodb.MongoException; import java.net.UnknownHostException; import java.util.UUID; } private void cacheDB() throws MongoException, UnknownHostException { String databaseKey = ((GuiceyMongoDatabase)key.getAnnotation()).value(); String clonedConfiguration = getInstance(_injector, Key.get(String.class, AnnotationUtil.clonedConfiguration(_configuration))); if (clonedConfiguration == null) { String database = _injector.getInstance(Key.get(String.class, AnnotationUtil.configuredDatabase(_configuration, databaseKey))); Mongo connection = getConnection(_configuration, databaseKey); _cachedDB = connection.getDB(database); // test connection _cachedDB.getCollectionNames(); } else { Mongo connection = getConnection(clonedConfiguration, databaseKey); _cachedDB = connection.getDB(UUID.randomUUID().toString()); String clonedDatabase = _injector.getInstance(Key.get(String.class, AnnotationUtil.configuredDatabase(clonedConfiguration, databaseKey))); _cachedDB.eval("var c = connect('" + clonedDatabase + "'); c.system.js.find().forEach(function(x){db.system.js.save(x)}); db.system.js.ensureIndex({_id: 1});"); Runtime.getRuntime().addShutdownHook(new RemoveTemporaryDB(_cachedDB)); } } private DB _cachedDB; public DB get() { try { if (_cachedDB == null) cacheDB(); return _cachedDB; } catch (MongoException e) {
throw new GuiceyMongoException("Could not connect to an instance of MongoDB", e);
mattinsler/com.lowereast.guiceymongo
src/examples/RemoteDatabaseConfigurationExample.java
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; import com.mongodb.DB;
/** * Copyright (C) 2010 Lowereast Software * * 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. */ public class RemoteDatabaseConfigurationExample { @Inject RemoteDatabaseConfigurationExample(@GuiceyMongoDatabase(Databases.Main) DB mainDatabase, @GuiceyMongoDatabase(Databases.Search) DB searchDatabase) { System.out.println(mainDatabase); System.out.println(searchDatabase); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create a connection to localhost:13731 that can be used by databases
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/examples/RemoteDatabaseConfigurationExample.java import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoDatabase; import com.mongodb.DB; /** * Copyright (C) 2010 Lowereast Software * * 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. */ public class RemoteDatabaseConfigurationExample { @Inject RemoteDatabaseConfigurationExample(@GuiceyMongoDatabase(Databases.Main) DB mainDatabase, @GuiceyMongoDatabase(Databases.Search) DB searchDatabase) { System.out.println(mainDatabase); System.out.println(searchDatabase); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create a connection to localhost:13731 that can be used by databases
GuiceyMongo.configureConnection(Connections.Primary)
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/property/SetProperty.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/SetType.java // public class SetType extends Type { // private Type _itemType; // // public SetType(Type itemType) { // super("set", "java.util.Set<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.SetType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class SetProperty extends Property<SetType> { public SetProperty(UserDataType enclosingType, String name, SetType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "Set"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getSetItemType() {
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/SetType.java // public class SetType extends Type { // private Type _itemType; // // public SetType(Type itemType) { // super("set", "java.util.Set<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/SetProperty.java import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.SetType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class SetProperty extends Property<SetType> { public SetProperty(UserDataType enclosingType, String name, SetType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "Set"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getSetItemType() {
Type type = super.getType().getItemType();
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/data/generator/property/SetProperty.java
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/SetType.java // public class SetType extends Type { // private Type _itemType; // // public SetType(Type itemType) { // super("set", "java.util.Set<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // }
import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.SetType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class SetProperty extends Property<SetType> { public SetProperty(UserDataType enclosingType, String name, SetType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "Set"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getSetItemType() { Type type = super.getType().getItemType();
// Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/PrimitiveType.java // public class PrimitiveType extends Type { // private final String _javaBoxedType; // // public PrimitiveType(String guiceyType, String javaType, String javaBoxedType) { // super(guiceyType, javaType); // _javaBoxedType = javaBoxedType; // } // // public String getJavaBoxedType() { // return _javaBoxedType; // } // // public static PrimitiveType DoubleType = new PrimitiveType("double", "double", "Double"); // public static PrimitiveType FloatType = new PrimitiveType("float", "float", "Float"); // public static PrimitiveType Int32Type = new PrimitiveType("int32", "int", "Integer"); // public static PrimitiveType Int64Type = new PrimitiveType("int64", "long", "Long"); // public static PrimitiveType BoolType = new PrimitiveType("bool", "boolean", "Boolean"); // public static PrimitiveType StringType = new PrimitiveType("string", "String", "String"); // // public static PrimitiveType BytesType = new PrimitiveType("bytes", "", ""); // byte[]?? // public static PrimitiveType DateType = new PrimitiveType("date", "java.util.Date", "java.util.Date"); // // public static PrimitiveType ObjectIdType = new PrimitiveType("object_id", "org.bson.types.ObjectId", "org.bson.types.ObjectId"); // public static PrimitiveType DBObjectType = new PrimitiveType("db_object", "com.mongodb.DBObject", "com.mongodb.DBObject"); // public static PrimitiveType DBTimestampType = new PrimitiveType("db_timestamp", "org.bson.types.BSONTimestamp", "org.bson.types.BSONTimestamp"); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/SetType.java // public class SetType extends Type { // private Type _itemType; // // public SetType(Type itemType) { // super("set", "java.util.Set<" + itemType.getJavaType() + ">"); // _itemType = itemType; // } // // public Type getItemType() { // return _itemType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/Type.java // public class Type { // protected String _guiceyType; // protected String _javaType; // // protected Type(String guiceyType) { // _guiceyType = guiceyType; // } // // protected Type(String guiceyType, String javaType) { // _guiceyType = guiceyType; // _javaType = javaType; // } // // public String getGuiceyType() { // return _guiceyType; // } // // public String getJavaType() { // return _javaType; // } // // @Override // public String toString() { // return _javaType; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/generator/type/UserDataType.java // public class UserDataType extends UserType { // private final List<Property<?>> _properties = Lists.newArrayList(); // private final List<UserType> _childTypes = Lists.newArrayList(); // // private Property<?> _identityProperty; // // public UserDataType(String guiceyType) { // super(guiceyType); // } // // public List<Property<?>> getProperties() { // return _properties; // } // // public void addProperty(Property<?> property) { // _properties.add(property); // } // // public List<UserType> getChildTypes() { // return _childTypes; // } // // public void addChildType(UserType childType) { // if (_childTypes.indexOf(childType) == -1) { // _childTypes.add(childType); // childType.setParentType(this); // } // } // // public Property<?> getIdentityProperty() { // return _identityProperty; // } // // public void setIdentityProperty(Property<?> identityProperty) { // _identityProperty = identityProperty; // } // } // Path: src/main/java/com/lowereast/guiceymongo/data/generator/property/SetProperty.java import com.lowereast.guiceymongo.data.generator.type.PrimitiveType; import com.lowereast.guiceymongo.data.generator.type.SetType; import com.lowereast.guiceymongo.data.generator.type.Type; import com.lowereast.guiceymongo.data.generator.type.UserDataType; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.data.generator.property; public class SetProperty extends Property<SetType> { public SetProperty(UserDataType enclosingType, String name, SetType type, String comment, boolean useCamelCaseKeys) { super(enclosingType, name, type, comment, useCamelCaseKeys); } @Override public String getMemberVariableName() { return super.getMemberVariableName() + "Set"; } public String getItemType() { return super.getType().getItemType().getJavaType(); } public String getSetItemType() { Type type = super.getType().getItemType();
if (type instanceof PrimitiveType)
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public class JavascriptProxy<T> implements Module, Provider<T> { private final String _databaseKey; private final Class<T> _proxyInterface; private Provider<DB> _databaseProvider; public JavascriptProxy(Class<T> proxyInterface, String databaseKey) { if (!proxyInterface.isInterface()) throw new RuntimeException("Proxy class must be an interface"); _proxyInterface = proxyInterface; _databaseKey = databaseKey; } @Inject void initialize(Injector injector) { _databaseProvider = injector.getProvider(Key.get(DB.class, AnnotationUtil.guiceyMongoDatabase(_databaseKey))); } public void configure(Binder binder) {
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public class JavascriptProxy<T> implements Module, Provider<T> { private final String _databaseKey; private final Class<T> _proxyInterface; private Provider<DB> _databaseProvider; public JavascriptProxy(Class<T> proxyInterface, String databaseKey) { if (!proxyInterface.isInterface()) throw new RuntimeException("Proxy class must be an interface"); _proxyInterface = proxyInterface; _databaseKey = databaseKey; } @Inject void initialize(Injector injector) { _databaseProvider = injector.getProvider(Key.get(DB.class, AnnotationUtil.guiceyMongoDatabase(_databaseKey))); } public void configure(Binder binder) {
binder.skipSources(JavascriptProxy.class, GuiceyMongo.class).bind(_proxyInterface).toProvider(this);
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException;
public Object invoke(DB database, Object[] args) { return database.eval(_code); } } private static class VoidInvocation implements Invocation { private final String _code; public VoidInvocation(String methodName, Class<?>[] argumentTypes) { String argumentString = createArgumentString(argumentTypes.length); _code = "function" + argumentString + "{" + methodName + argumentString + "}"; } public Object invoke(DB database, Object[] args) { return database.eval(_code, args); } } private interface Converter<From, To> { To convert(From value); } private static final Converter<Double, Integer> DoubleToIntConverter = new Converter<Double, Integer>() { public Integer convert(Double value) { return value.intValue(); } }; private static final Converter<Object, Object> NoOpConverter = new Converter<Object, Object>() { public Object convert(Object value) { return value; } };
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException; public Object invoke(DB database, Object[] args) { return database.eval(_code); } } private static class VoidInvocation implements Invocation { private final String _code; public VoidInvocation(String methodName, Class<?>[] argumentTypes) { String argumentString = createArgumentString(argumentTypes.length); _code = "function" + argumentString + "{" + methodName + argumentString + "}"; } public Object invoke(DB database, Object[] args) { return database.eval(_code, args); } } private interface Converter<From, To> { To convert(From value); } private static final Converter<Double, Integer> DoubleToIntConverter = new Converter<Double, Integer>() { public Integer convert(Double value) { return value.intValue(); } }; private static final Converter<Object, Object> NoOpConverter = new Converter<Object, Object>() { public Object convert(Object value) { return value; } };
private static class DBObjectToWrapperConverter<T extends IsData> implements Converter<DBObject, T> {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException;
return database.eval(_code); } } private static class VoidInvocation implements Invocation { private final String _code; public VoidInvocation(String methodName, Class<?>[] argumentTypes) { String argumentString = createArgumentString(argumentTypes.length); _code = "function" + argumentString + "{" + methodName + argumentString + "}"; } public Object invoke(DB database, Object[] args) { return database.eval(_code, args); } } private interface Converter<From, To> { To convert(From value); } private static final Converter<Double, Integer> DoubleToIntConverter = new Converter<Double, Integer>() { public Integer convert(Double value) { return value.intValue(); } }; private static final Converter<Object, Object> NoOpConverter = new Converter<Object, Object>() { public Object convert(Object value) { return value; } }; private static class DBObjectToWrapperConverter<T extends IsData> implements Converter<DBObject, T> {
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException; return database.eval(_code); } } private static class VoidInvocation implements Invocation { private final String _code; public VoidInvocation(String methodName, Class<?>[] argumentTypes) { String argumentString = createArgumentString(argumentTypes.length); _code = "function" + argumentString + "{" + methodName + argumentString + "}"; } public Object invoke(DB database, Object[] args) { return database.eval(_code, args); } } private interface Converter<From, To> { To convert(From value); } private static final Converter<Double, Integer> DoubleToIntConverter = new Converter<Double, Integer>() { public Integer convert(Double value) { return value.intValue(); } }; private static final Converter<Object, Object> NoOpConverter = new Converter<Object, Object>() { public Object convert(Object value) { return value; } }; private static class DBObjectToWrapperConverter<T extends IsData> implements Converter<DBObject, T> {
private final DataWrapper<T> _wrapper;
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException;
} } private static class ListDBObjectToWrapperConverter<T extends IsData> implements Converter<List<DBObject>, List<T>> { private final DBObjectToWrapperConverter<T> _itemWrapper; public ListDBObjectToWrapperConverter(Class<T> dataClass) { _itemWrapper = new DBObjectToWrapperConverter<T>(dataClass); } public List<T> convert(List<DBObject> value) { try { List<T> list = Lists.newArrayList(); for (DBObject o : value) list.add(_itemWrapper.convert(o)); return list; } catch (Exception e) { e.printStackTrace(); return null; } } } private static class ReturningInvocation implements Invocation { private final String _code; private Converter<?, ?> _converter = NoOpConverter; public ReturningInvocation(Class<?> returnType, Method method, Class<?>[] argumentTypes) { String argumentString = createArgumentString(argumentTypes.length); _code = "function" + argumentString + "{return " + method.getName() + argumentString + "}";
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException; } } private static class ListDBObjectToWrapperConverter<T extends IsData> implements Converter<List<DBObject>, List<T>> { private final DBObjectToWrapperConverter<T> _itemWrapper; public ListDBObjectToWrapperConverter(Class<T> dataClass) { _itemWrapper = new DBObjectToWrapperConverter<T>(dataClass); } public List<T> convert(List<DBObject> value) { try { List<T> list = Lists.newArrayList(); for (DBObject o : value) list.add(_itemWrapper.convert(o)); return list; } catch (Exception e) { e.printStackTrace(); return null; } } } private static class ReturningInvocation implements Invocation { private final String _code; private Converter<?, ?> _converter = NoOpConverter; public ReturningInvocation(Class<?> returnType, Method method, Class<?>[] argumentTypes) { String argumentString = createArgumentString(argumentTypes.length); _code = "function" + argumentString + "{return " + method.getName() + argumentString + "}";
if (IsData.class.isAssignableFrom(returnType) || IsWrapper.class.isAssignableFrom(returnType)) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException;
String methodName = method.getName(); Class<?> methodReturnType = method.getReturnType(); Class<?>[] argumentTypes = method.getParameterTypes(); if (Void.class.equals(methodReturnType) || void.class.equals(methodReturnType)) { if (argumentTypes.length == 0) { invocation = new VoidNoArgInvocation(methodName); } else { invocation = new VoidInvocation(methodName, argumentTypes); } } else { invocation = new ReturningInvocation(methodReturnType, method, argumentTypes); } _invocations.put(method, invocation); } } } public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, args); } try { Invocation invocation = _invocations.get(method); if (invocation == null) throw new RuntimeException(); return invocation.invoke(_database, args); } catch (MongoException e) {
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyMongoEvalException.java // @SuppressWarnings("serial") // public class GuiceyMongoEvalException extends MongoException { // private static String _errorPrefix = "eval failed: { \"errno\" : -3.0 , \"errmsg\" : \"invoke failed: JS Error: "; // // private String _type; // // private GuiceyMongoEvalException(String exceptionType, String exceptionMessage) { // super(exceptionMessage); // _type = exceptionType; // } // // public String getType() { // return _type; // } // // /** // * Will create a MongoEvalException if the exception passed in was created from an eval command. Otherwise the exception passed in will be returned. // * @param e // * @return MongoEvalException if applicable, otherwise the exception passed in // */ // public static MongoException create(MongoException e) { // String errorString = e.getMessage(); // if (errorString.startsWith(_errorPrefix)) { // int length = _errorPrefix.length(); // int colonLocation = errorString.indexOf(':', length); // String type = errorString.substring(length, colonLocation).trim(); // String message = errorString.substring(colonLocation + 1, errorString.indexOf('"', colonLocation)).trim(); // return new GuiceyMongoEvalException(type, message); // } // return e; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsWrapper.java // public interface IsWrapper<T extends IsData> { // DBObject getDBObject(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/JavascriptProxy.java import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import java.util.List; import java.util.Map; import com.google.inject.Binder; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.internal.Lists; import com.google.inject.internal.Maps; import com.lowereast.guiceymongo.GuiceyMongoEvalException; import com.lowereast.guiceymongo.annotation.ItemType; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.data.IsWrapper; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DB; import com.mongodb.DBObject; import com.mongodb.MongoException; String methodName = method.getName(); Class<?> methodReturnType = method.getReturnType(); Class<?>[] argumentTypes = method.getParameterTypes(); if (Void.class.equals(methodReturnType) || void.class.equals(methodReturnType)) { if (argumentTypes.length == 0) { invocation = new VoidNoArgInvocation(methodName); } else { invocation = new VoidInvocation(methodName, argumentTypes); } } else { invocation = new ReturningInvocation(methodReturnType, method, argumentTypes); } _invocations.put(method, invocation); } } } public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, args); } try { Invocation invocation = _invocations.get(method); if (invocation == null) throw new RuntimeException(); return invocation.invoke(_database, args); } catch (MongoException e) {
throw GuiceyMongoEvalException.create(e);
mattinsler/com.lowereast.guiceymongo
src/examples/BucketConfigurationExample.java
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyBucket.java // public class GuiceyBucket { // private final GridFS _grid; // // public GuiceyBucket(GridFS gridFs) { // _grid = gridFs; // } // // public GuiceyBucket(DB database, String bucket) { // this(new GridFS(database, bucket)); // } // // public GridFSInputFile createFile(byte[] data) { // return _grid.createFile(data); // } // // public GridFSInputFile createFile(File file) throws IOException { // return _grid.createFile(file); // } // // public GridFSInputFile createFile(InputStream stream) { // return _grid.createFile(stream); // } // // public GridFSInputFile createFile(InputStream stream, String filename) { // return _grid.createFile(stream, filename); // } // // public GridFSDBFile findOne(DBObject query) { // return _grid.findOne(query); // } // // public GridFSDBFile findOne(ObjectId identity) { // return _grid.findOne(identity); // } // // public GridFSDBFile findOne(String filename) { // return _grid.findOne(filename); // } // // public List<GridFSDBFile> find(DBObject query) { // return _grid.find(query); // } // // public GridFSDBFile find(ObjectId identity) { // return _grid.find(identity); // } // // public List<GridFSDBFile> find(String filename) { // return _grid.find(filename); // } // // public void remove(DBObject query) { // _grid.remove(query); // } // // public void remove(ObjectId identity) { // _grid.remove(identity); // } // // public void remove(String filename) { // _grid.remove(filename); // } // // public GridFS getGridFS() { // return _grid; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.GuiceyBucket; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoBucket; import com.mongodb.gridfs.GridFS;
/** * Copyright (C) 2010 Lowereast Software * * 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. */ public class BucketConfigurationExample { @Inject BucketConfigurationExample(@GuiceyMongoBucket(Buckets.Main) GridFS grid, @GuiceyMongoBucket(Buckets.Main) GuiceyBucket bucket) { System.out.println(grid + " : " + bucket.getGridFS()); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the test configuration
// Path: src/main/java/com/lowereast/guiceymongo/GuiceyBucket.java // public class GuiceyBucket { // private final GridFS _grid; // // public GuiceyBucket(GridFS gridFs) { // _grid = gridFs; // } // // public GuiceyBucket(DB database, String bucket) { // this(new GridFS(database, bucket)); // } // // public GridFSInputFile createFile(byte[] data) { // return _grid.createFile(data); // } // // public GridFSInputFile createFile(File file) throws IOException { // return _grid.createFile(file); // } // // public GridFSInputFile createFile(InputStream stream) { // return _grid.createFile(stream); // } // // public GridFSInputFile createFile(InputStream stream, String filename) { // return _grid.createFile(stream, filename); // } // // public GridFSDBFile findOne(DBObject query) { // return _grid.findOne(query); // } // // public GridFSDBFile findOne(ObjectId identity) { // return _grid.findOne(identity); // } // // public GridFSDBFile findOne(String filename) { // return _grid.findOne(filename); // } // // public List<GridFSDBFile> find(DBObject query) { // return _grid.find(query); // } // // public GridFSDBFile find(ObjectId identity) { // return _grid.find(identity); // } // // public List<GridFSDBFile> find(String filename) { // return _grid.find(filename); // } // // public void remove(DBObject query) { // _grid.remove(query); // } // // public void remove(ObjectId identity) { // _grid.remove(identity); // } // // public void remove(String filename) { // _grid.remove(filename); // } // // public GridFS getGridFS() { // return _grid; // } // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/examples/BucketConfigurationExample.java import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.GuiceyBucket; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.lowereast.guiceymongo.guice.annotation.GuiceyMongoBucket; import com.mongodb.gridfs.GridFS; /** * Copyright (C) 2010 Lowereast Software * * 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. */ public class BucketConfigurationExample { @Inject BucketConfigurationExample(@GuiceyMongoBucket(Buckets.Main) GridFS grid, @GuiceyMongoBucket(Buckets.Main) GuiceyBucket bucket) { System.out.println(grid + " : " + bucket.getGridFS()); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the test configuration
GuiceyMongo.configure(Configurations.Test)
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // }
import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public interface Builders { public interface FinishableConfiguration extends Module { DatabaseConfiguration mapDatabase(String databaseKey); CollectionConfiguration mapCollection(String collectionKey); BucketConfiguration mapBucket(String bucketKey); } public interface Configuration extends FinishableConfiguration { Module cloneFrom(String configurationName); } public interface DatabaseConfiguration { DatabaseOptionConfiguration to(String database); DatabaseOptionConfiguration asTestDatabase(); } public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { FinishableConfiguration overConnection(String connectionKey); } public interface CollectionConfigurationOnlyTo { CollectionOptionConfiguration to(String collection); } public interface CollectionConfiguration extends CollectionConfigurationOnlyTo {
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public interface Builders { public interface FinishableConfiguration extends Module { DatabaseConfiguration mapDatabase(String databaseKey); CollectionConfiguration mapCollection(String collectionKey); BucketConfiguration mapBucket(String bucketKey); } public interface Configuration extends FinishableConfiguration { Module cloneFrom(String configurationName); } public interface DatabaseConfiguration { DatabaseOptionConfiguration to(String database); DatabaseOptionConfiguration asTestDatabase(); } public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { FinishableConfiguration overConnection(String connectionKey); } public interface CollectionConfigurationOnlyTo { CollectionOptionConfiguration to(String collection); } public interface CollectionConfiguration extends CollectionConfigurationOnlyTo {
CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType);
mattinsler/com.lowereast.guiceymongo
src/examples/StoredProcedureProxyExample.java
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // }
import java.util.List; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DBObject;
/** * Copyright (C) 2010 Lowereast Software * * 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. */ public class StoredProcedureProxyExample { public interface PrintQuery { void print(String message); } /* * You can create server side methods and then use a javascript proxy to call them: * db.system.js.save({ * _id: 'getData', * value: function(count) { * return db.foo.find().limit(count).toArray(); * } * }) * * db.system.js.save({ * _id: 'getCount', * value: function() { * return db.foo.count(); * } * }) * * WARNING: You cannot return a cursor from a server side method */ public interface TestQuery { // this will execute "db.eval(function(count){return getData(count)}, count)" List<DBObject> getData(int count); // this will execute "db.eval(function(){return getCount()})" int getCount(); } @Inject StoredProcedureProxyExample(PrintQuery printQuery) { // will print Hello world on the server printQuery.print("Hello world"); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the test configuration
// Path: src/main/java/com/lowereast/guiceymongo/guice/GuiceyMongo.java // public final class GuiceyMongo { // private GuiceyMongo() {} // // public static Builders.Configuration configure(String configurationName) { // return new BuilderImpls.Configuration(configurationName); // } // // public static Builders.Connection configureConnection(String connectionName) { // return new BuilderImpls.Connection(connectionName); // } // // public static Module chooseConfiguration(final String configurationName) { // return new Module() { // public void configure(Binder binder) { // GuiceyMongoUtil.setCurrentConfiguration(binder.skipSources(GuiceyMongo.class), configurationName); // } // }; // } // // @SuppressWarnings("unchecked") // public static Module javascriptProxy(Class<?> proxyInterface, String databaseKey) { // return new JavascriptProxy(proxyInterface, databaseKey); // } // } // Path: src/examples/StoredProcedureProxyExample.java import java.util.List; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.lowereast.guiceymongo.guice.GuiceyMongo; import com.mongodb.DBObject; /** * Copyright (C) 2010 Lowereast Software * * 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. */ public class StoredProcedureProxyExample { public interface PrintQuery { void print(String message); } /* * You can create server side methods and then use a javascript proxy to call them: * db.system.js.save({ * _id: 'getData', * value: function(count) { * return db.foo.find().limit(count).toArray(); * } * }) * * db.system.js.save({ * _id: 'getCount', * value: function() { * return db.foo.count(); * } * }) * * WARNING: You cannot return a cursor from a server side method */ public interface TestQuery { // this will execute "db.eval(function(count){return getData(count)}, count)" List<DBObject> getData(int count); // this will execute "db.eval(function(){return getCount()})" int getCount(); } @Inject StoredProcedureProxyExample(PrintQuery printQuery) { // will print Hello world on the server printQuery.print("Hello world"); } public static void main(String[] args) { Injector injector = Guice.createInjector( // create the test configuration
GuiceyMongo.configure(Configurations.Test)
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/GuiceyCursor.java
// Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // }
import java.util.Iterator; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.mongodb.DBCursor; import com.mongodb.DBObject;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo; public class GuiceyCursor<Item extends IsData> implements Iterator<Item>, Iterable<Item> { private final DBCursor _cursor;
// Path: src/main/java/com/lowereast/guiceymongo/data/DataWrapper.java // public interface DataWrapper<T extends IsData> { // T wrap(DBObject backing); // } // // Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // Path: src/main/java/com/lowereast/guiceymongo/GuiceyCursor.java import java.util.Iterator; import com.lowereast.guiceymongo.data.DataWrapper; import com.lowereast.guiceymongo.data.IsData; import com.mongodb.DBCursor; import com.mongodb.DBObject; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo; public class GuiceyCursor<Item extends IsData> implements Iterator<Item>, Iterable<Item> { private final DBCursor _cursor;
private final DataWrapper<Item> _wrapper;
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public final class BuilderImpls { public static class Configuration implements Builders.Configuration, Builders.FinishableConfiguration { private final String _name; private final GuiceyMongoBindingCollector _collector = new GuiceyMongoBindingCollector(); public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public final class BuilderImpls { public static class Configuration implements Builders.Configuration, Builders.FinishableConfiguration { private final String _name; private final GuiceyMongoBindingCollector _collector = new GuiceyMongoBindingCollector(); public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; }
public Builders.CollectionConfiguration mapCollection(String collectionKey) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public final class BuilderImpls { public static class Configuration implements Builders.Configuration, Builders.FinishableConfiguration { private final String _name; private final GuiceyMongoBindingCollector _collector = new GuiceyMongoBindingCollector(); public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; } public Builders.CollectionConfiguration mapCollection(String collectionKey) { return new Collection(this, collectionKey); }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public final class BuilderImpls { public static class Configuration implements Builders.Configuration, Builders.FinishableConfiguration { private final String _name; private final GuiceyMongoBindingCollector _collector = new GuiceyMongoBindingCollector(); public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; } public Builders.CollectionConfiguration mapCollection(String collectionKey) { return new Collection(this, collectionKey); }
public Builders.DatabaseConfiguration mapDatabase(String databaseKey) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
/** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public final class BuilderImpls { public static class Configuration implements Builders.Configuration, Builders.FinishableConfiguration { private final String _name; private final GuiceyMongoBindingCollector _collector = new GuiceyMongoBindingCollector(); public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; } public Builders.CollectionConfiguration mapCollection(String collectionKey) { return new Collection(this, collectionKey); } public Builders.DatabaseConfiguration mapDatabase(String databaseKey) { return new Database(this, databaseKey); }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; /** * Copyright (C) 2010 Lowereast Software * * 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.lowereast.guiceymongo.guice.spi; public final class BuilderImpls { public static class Configuration implements Builders.Configuration, Builders.FinishableConfiguration { private final String _name; private final GuiceyMongoBindingCollector _collector = new GuiceyMongoBindingCollector(); public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; } public Builders.CollectionConfiguration mapCollection(String collectionKey) { return new Collection(this, collectionKey); } public Builders.DatabaseConfiguration mapDatabase(String databaseKey) { return new Database(this, databaseKey); }
public BucketConfiguration mapBucket(String bucketKey) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; } public Builders.CollectionConfiguration mapCollection(String collectionKey) { return new Collection(this, collectionKey); } public Builders.DatabaseConfiguration mapDatabase(String databaseKey) { return new Database(this, databaseKey); } public BucketConfiguration mapBucket(String bucketKey) { return new Bucket(this, bucketKey); } public void configure(Binder binder) { new GuiceyMongoBinder(binder.skipSources(Configuration.class, Database.class, Collection.class)).bind(_collector); } String getName() { return _name; } GuiceyMongoBindingCollector getCollector() { return _collector; } }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; public Configuration(String name) { _name = name; } public Module cloneFrom(String configurationName) { _collector.bindClonedConfiguration(_name, configurationName); return this; } public Builders.CollectionConfiguration mapCollection(String collectionKey) { return new Collection(this, collectionKey); } public Builders.DatabaseConfiguration mapDatabase(String databaseKey) { return new Database(this, databaseKey); } public BucketConfiguration mapBucket(String bucketKey) { return new Bucket(this, bucketKey); } public void configure(Binder binder) { new GuiceyMongoBinder(binder.skipSources(Configuration.class, Database.class, Collection.class)).bind(_collector); } String getName() { return _name; } GuiceyMongoBindingCollector getCollector() { return _collector; } }
private static class Database implements Builders.DatabaseConfiguration, Builders.DatabaseOptionConfiguration {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
private final String _databaseKey; public Database(Configuration configuration, String databaseKey) { _configuration = configuration; _databaseKey = databaseKey; } public void configure(Binder binder) { _configuration.configure(binder); } public CollectionConfiguration mapCollection(String collectionKey) { return _configuration.mapCollection(collectionKey); } public DatabaseConfiguration mapDatabase(String databaseKey) { return _configuration.mapDatabase(databaseKey); } public FinishableConfiguration overConnection(String connectionKey) { _configuration.getCollector().bindConfiguredDatabaseConnection(_configuration.getName(), _databaseKey, connectionKey); return _configuration; } public DatabaseOptionConfiguration to(String database) { _configuration.getCollector().bindConfiguredDatabase(_configuration.getName(), _databaseKey, database); return this; } public BucketConfiguration mapBucket(String bucketKey) { return _configuration.mapBucket(bucketKey); } public DatabaseOptionConfiguration asTestDatabase() { return null; //To change body of implemented methods use File | Settings | File Templates. } }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; private final String _databaseKey; public Database(Configuration configuration, String databaseKey) { _configuration = configuration; _databaseKey = databaseKey; } public void configure(Binder binder) { _configuration.configure(binder); } public CollectionConfiguration mapCollection(String collectionKey) { return _configuration.mapCollection(collectionKey); } public DatabaseConfiguration mapDatabase(String databaseKey) { return _configuration.mapDatabase(databaseKey); } public FinishableConfiguration overConnection(String connectionKey) { _configuration.getCollector().bindConfiguredDatabaseConnection(_configuration.getName(), _databaseKey, connectionKey); return _configuration; } public DatabaseOptionConfiguration to(String database) { _configuration.getCollector().bindConfiguredDatabase(_configuration.getName(), _databaseKey, database); return this; } public BucketConfiguration mapBucket(String bucketKey) { return _configuration.mapBucket(bucketKey); } public DatabaseOptionConfiguration asTestDatabase() { return null; //To change body of implemented methods use File | Settings | File Templates. } }
private static class Collection implements Builders.CollectionConfiguration, Builders.CollectionConfigurationOnlyTo, Builders.CollectionOptionConfiguration {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
public CollectionConfiguration mapCollection(String collectionKey) { return _configuration.mapCollection(collectionKey); } public DatabaseConfiguration mapDatabase(String databaseKey) { return _configuration.mapDatabase(databaseKey); } public FinishableConfiguration overConnection(String connectionKey) { _configuration.getCollector().bindConfiguredDatabaseConnection(_configuration.getName(), _databaseKey, connectionKey); return _configuration; } public DatabaseOptionConfiguration to(String database) { _configuration.getCollector().bindConfiguredDatabase(_configuration.getName(), _databaseKey, database); return this; } public BucketConfiguration mapBucket(String bucketKey) { return _configuration.mapBucket(bucketKey); } public DatabaseOptionConfiguration asTestDatabase() { return null; //To change body of implemented methods use File | Settings | File Templates. } } private static class Collection implements Builders.CollectionConfiguration, Builders.CollectionConfigurationOnlyTo, Builders.CollectionOptionConfiguration { private final Configuration _configuration; private final String _collectionKey; private String _collection; public Collection(Configuration configuration, String collectionKey) { _configuration = configuration; _collectionKey = collectionKey; }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; public CollectionConfiguration mapCollection(String collectionKey) { return _configuration.mapCollection(collectionKey); } public DatabaseConfiguration mapDatabase(String databaseKey) { return _configuration.mapDatabase(databaseKey); } public FinishableConfiguration overConnection(String connectionKey) { _configuration.getCollector().bindConfiguredDatabaseConnection(_configuration.getName(), _databaseKey, connectionKey); return _configuration; } public DatabaseOptionConfiguration to(String database) { _configuration.getCollector().bindConfiguredDatabase(_configuration.getName(), _databaseKey, database); return this; } public BucketConfiguration mapBucket(String bucketKey) { return _configuration.mapBucket(bucketKey); } public DatabaseOptionConfiguration asTestDatabase() { return null; //To change body of implemented methods use File | Settings | File Templates. } } private static class Collection implements Builders.CollectionConfiguration, Builders.CollectionConfigurationOnlyTo, Builders.CollectionOptionConfiguration { private final Configuration _configuration; private final String _collectionKey; private String _collection; public Collection(Configuration configuration, String collectionKey) { _configuration = configuration; _collectionKey = collectionKey; }
public CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType) {
mattinsler/com.lowereast.guiceymongo
src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // }
import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration;
public BucketConfiguration mapBucket(String bucketKey) { return _configuration.mapBucket(bucketKey); } public DatabaseOptionConfiguration asTestDatabase() { return null; //To change body of implemented methods use File | Settings | File Templates. } } private static class Collection implements Builders.CollectionConfiguration, Builders.CollectionConfigurationOnlyTo, Builders.CollectionOptionConfiguration { private final Configuration _configuration; private final String _collectionKey; private String _collection; public Collection(Configuration configuration, String collectionKey) { _configuration = configuration; _collectionKey = collectionKey; } public CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType) { _configuration.getCollector().bindConfiguredCollectionDataType(_configuration.getName(), _collectionKey, dataType); return this; } public Builders.CollectionOptionConfiguration to(String collection) { _collection = collection; return this; } public Builders.FinishableConfiguration inDatabase(String databaseKey) { _configuration.getCollector().bindConfiguredCollection(_configuration.getName(), databaseKey, _collectionKey, _collection); return _configuration; } }
// Path: src/main/java/com/lowereast/guiceymongo/data/IsData.java // public interface IsData { // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketConfiguration { // BucketOptionConfiguration to(String bucket); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface BucketOptionConfiguration { // FinishableConfiguration inDatabase(String databaseKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfiguration extends CollectionConfigurationOnlyTo { // CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface CollectionConfigurationOnlyTo { // CollectionOptionConfiguration to(String collection); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseConfiguration { // DatabaseOptionConfiguration to(String database); // DatabaseOptionConfiguration asTestDatabase(); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface DatabaseOptionConfiguration extends FinishableConfiguration, Module { // FinishableConfiguration overConnection(String connectionKey); // } // // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/Builders.java // public interface FinishableConfiguration extends Module { // DatabaseConfiguration mapDatabase(String databaseKey); // CollectionConfiguration mapCollection(String collectionKey); // BucketConfiguration mapBucket(String bucketKey); // } // Path: src/main/java/com/lowereast/guiceymongo/guice/spi/BuilderImpls.java import com.google.inject.Binder; import com.google.inject.Module; import com.lowereast.guiceymongo.data.IsData; import com.lowereast.guiceymongo.guice.spi.Builders.BucketConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.BucketOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.CollectionConfigurationOnlyTo; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.DatabaseOptionConfiguration; import com.lowereast.guiceymongo.guice.spi.Builders.FinishableConfiguration; public BucketConfiguration mapBucket(String bucketKey) { return _configuration.mapBucket(bucketKey); } public DatabaseOptionConfiguration asTestDatabase() { return null; //To change body of implemented methods use File | Settings | File Templates. } } private static class Collection implements Builders.CollectionConfiguration, Builders.CollectionConfigurationOnlyTo, Builders.CollectionOptionConfiguration { private final Configuration _configuration; private final String _collectionKey; private String _collection; public Collection(Configuration configuration, String collectionKey) { _configuration = configuration; _collectionKey = collectionKey; } public CollectionConfigurationOnlyTo ofType(Class<? extends IsData> dataType) { _configuration.getCollector().bindConfiguredCollectionDataType(_configuration.getName(), _collectionKey, dataType); return this; } public Builders.CollectionOptionConfiguration to(String collection) { _collection = collection; return this; } public Builders.FinishableConfiguration inDatabase(String databaseKey) { _configuration.getCollector().bindConfiguredCollection(_configuration.getName(), databaseKey, _collectionKey, _collection); return _configuration; } }
private static class Bucket implements Builders.BucketConfiguration, Builders.BucketOptionConfiguration {
buksy/jnlua
src/main/java/com/naef/jnlua/JavaModule.java
// Path: src/main/java/com/naef/jnlua/JavaReflector.java // public enum Metamethod { // /** // * <code>__index</code> metamethod. // */ // INDEX, // // /** // * <code>__newindex</code> metamethod. // */ // NEWINDEX, // // /** // * <code>__len</code> metamethod. // */ // LEN, // // /** // * <code>__eq</code> metamethod. // */ // EQ, // // /** // * <code>__lt</code> metamethod. // */ // LT, // // /** // * <code>__le</code> metamethod. // */ // LE, // // /** // * <code>__unm</code> metamethod. // */ // UNM, // // /** // * <code>__add</code> metamethod. // */ // ADD, // // /** // * <code>__sub</code> metamethod. // */ // SUB, // // /** // * <code>__mul</code> metamethod. // */ // MUL, // // /** // * <code>__div</code> metamethod. // */ // DIV, // // /** // * <code>__mod</code> metamethod. // */ // MOD, // // /** // * <code>__pow</code> metamethod. // */ // POW, // // /** // * <code>__concat</code> metamethod. // */ // CONCAT, // // /** // * <code>__call</code> metamethod. // */ // CALL, // // /** // * <code>__tostring</code> metamethod. // */ // TOSTRING, // // /** // * <code>__pairs</code> metamethod, // */ // PAIRS, // // /** // * <code>__ipairs</code> metamethod, // */ // IPAIRS, // // /** // * <code>__javafields</code> metamethod. // */ // JAVAFIELDS, // // /** // * <code>__javamethods</code> metamethod. // */ // JAVAMETHODS, // // /** // * <code>__javaproperties</code> metamethod. // */ // JAVAPROPERTIES; // // // -- Operations // /** // * Returns the Lua metamethod name. // * // * @return the metamethod name // */ // public String getMetamethodName() { // return "__" + toString().toLowerCase(); // } // };
import java.lang.reflect.Array; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import com.naef.jnlua.JavaReflector.Metamethod;
} else { String interfaceName = luaState.checkString(i + 2); interfaces[i] = loadType(luaState, interfaceName); } } // Create proxy luaState.pushJavaObjectRaw(luaState.getProxy(1, interfaces)); return 1; } @Override public String getName() { return "proxy"; } } /** * Provides the pairs iterator from the Java reflector. */ private static class Pairs implements NamedJavaFunction { // -- NamedJavaFunction methods @Override public int invoke(LuaState luaState) { luaState.checkArg( 1, luaState.isJavaObjectRaw(1), String.format("Java object expected, got %s", luaState.typeName(1))); JavaFunction metamethod = luaState.getMetamethod(
// Path: src/main/java/com/naef/jnlua/JavaReflector.java // public enum Metamethod { // /** // * <code>__index</code> metamethod. // */ // INDEX, // // /** // * <code>__newindex</code> metamethod. // */ // NEWINDEX, // // /** // * <code>__len</code> metamethod. // */ // LEN, // // /** // * <code>__eq</code> metamethod. // */ // EQ, // // /** // * <code>__lt</code> metamethod. // */ // LT, // // /** // * <code>__le</code> metamethod. // */ // LE, // // /** // * <code>__unm</code> metamethod. // */ // UNM, // // /** // * <code>__add</code> metamethod. // */ // ADD, // // /** // * <code>__sub</code> metamethod. // */ // SUB, // // /** // * <code>__mul</code> metamethod. // */ // MUL, // // /** // * <code>__div</code> metamethod. // */ // DIV, // // /** // * <code>__mod</code> metamethod. // */ // MOD, // // /** // * <code>__pow</code> metamethod. // */ // POW, // // /** // * <code>__concat</code> metamethod. // */ // CONCAT, // // /** // * <code>__call</code> metamethod. // */ // CALL, // // /** // * <code>__tostring</code> metamethod. // */ // TOSTRING, // // /** // * <code>__pairs</code> metamethod, // */ // PAIRS, // // /** // * <code>__ipairs</code> metamethod, // */ // IPAIRS, // // /** // * <code>__javafields</code> metamethod. // */ // JAVAFIELDS, // // /** // * <code>__javamethods</code> metamethod. // */ // JAVAMETHODS, // // /** // * <code>__javaproperties</code> metamethod. // */ // JAVAPROPERTIES; // // // -- Operations // /** // * Returns the Lua metamethod name. // * // * @return the metamethod name // */ // public String getMetamethodName() { // return "__" + toString().toLowerCase(); // } // }; // Path: src/main/java/com/naef/jnlua/JavaModule.java import java.lang.reflect.Array; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import com.naef.jnlua.JavaReflector.Metamethod; } else { String interfaceName = luaState.checkString(i + 2); interfaces[i] = loadType(luaState, interfaceName); } } // Create proxy luaState.pushJavaObjectRaw(luaState.getProxy(1, interfaces)); return 1; } @Override public String getName() { return "proxy"; } } /** * Provides the pairs iterator from the Java reflector. */ private static class Pairs implements NamedJavaFunction { // -- NamedJavaFunction methods @Override public int invoke(LuaState luaState) { luaState.checkArg( 1, luaState.isJavaObjectRaw(1), String.format("Java object expected, got %s", luaState.typeName(1))); JavaFunction metamethod = luaState.getMetamethod(
luaState.toJavaObjectRaw(1), Metamethod.PAIRS);
buksy/jnlua
src/main/java/com/naef/jnlua/LuaState.java
// Path: src/main/java/com/naef/jnlua/JavaReflector.java // public enum Metamethod { // /** // * <code>__index</code> metamethod. // */ // INDEX, // // /** // * <code>__newindex</code> metamethod. // */ // NEWINDEX, // // /** // * <code>__len</code> metamethod. // */ // LEN, // // /** // * <code>__eq</code> metamethod. // */ // EQ, // // /** // * <code>__lt</code> metamethod. // */ // LT, // // /** // * <code>__le</code> metamethod. // */ // LE, // // /** // * <code>__unm</code> metamethod. // */ // UNM, // // /** // * <code>__add</code> metamethod. // */ // ADD, // // /** // * <code>__sub</code> metamethod. // */ // SUB, // // /** // * <code>__mul</code> metamethod. // */ // MUL, // // /** // * <code>__div</code> metamethod. // */ // DIV, // // /** // * <code>__mod</code> metamethod. // */ // MOD, // // /** // * <code>__pow</code> metamethod. // */ // POW, // // /** // * <code>__concat</code> metamethod. // */ // CONCAT, // // /** // * <code>__call</code> metamethod. // */ // CALL, // // /** // * <code>__tostring</code> metamethod. // */ // TOSTRING, // // /** // * <code>__pairs</code> metamethod, // */ // PAIRS, // // /** // * <code>__ipairs</code> metamethod, // */ // IPAIRS, // // /** // * <code>__javafields</code> metamethod. // */ // JAVAFIELDS, // // /** // * <code>__javamethods</code> metamethod. // */ // JAVAMETHODS, // // /** // * <code>__javaproperties</code> metamethod. // */ // JAVAPROPERTIES; // // // -- Operations // /** // * Returns the Lua metamethod name. // * // * @return the metamethod name // */ // public String getMetamethodName() { // return "__" + toString().toLowerCase(); // } // };
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.ref.PhantomReference; import java.lang.ref.ReferenceQueue; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.HashSet; import java.util.Set; import com.naef.jnlua.JavaReflector.Metamethod;
* @see #getClassLoader() * @see #setClassLoader(ClassLoader) * @see #getJavaReflector() * @see #setJavaReflector(JavaReflector) * @see #getConverter() * @see #setConverter(Converter) */ public LuaState() { this(0L); } /** * Creates a new instance. */ private LuaState(long luaState) { ownState = luaState == 0L; lua_newstate(APIVERSION, luaState); check(); // Create a finalize guardian finalizeGuardian = new Object() { @Override public void finalize() { synchronized (LuaState.this) { closeInternal(); } } }; // Add metamethods
// Path: src/main/java/com/naef/jnlua/JavaReflector.java // public enum Metamethod { // /** // * <code>__index</code> metamethod. // */ // INDEX, // // /** // * <code>__newindex</code> metamethod. // */ // NEWINDEX, // // /** // * <code>__len</code> metamethod. // */ // LEN, // // /** // * <code>__eq</code> metamethod. // */ // EQ, // // /** // * <code>__lt</code> metamethod. // */ // LT, // // /** // * <code>__le</code> metamethod. // */ // LE, // // /** // * <code>__unm</code> metamethod. // */ // UNM, // // /** // * <code>__add</code> metamethod. // */ // ADD, // // /** // * <code>__sub</code> metamethod. // */ // SUB, // // /** // * <code>__mul</code> metamethod. // */ // MUL, // // /** // * <code>__div</code> metamethod. // */ // DIV, // // /** // * <code>__mod</code> metamethod. // */ // MOD, // // /** // * <code>__pow</code> metamethod. // */ // POW, // // /** // * <code>__concat</code> metamethod. // */ // CONCAT, // // /** // * <code>__call</code> metamethod. // */ // CALL, // // /** // * <code>__tostring</code> metamethod. // */ // TOSTRING, // // /** // * <code>__pairs</code> metamethod, // */ // PAIRS, // // /** // * <code>__ipairs</code> metamethod, // */ // IPAIRS, // // /** // * <code>__javafields</code> metamethod. // */ // JAVAFIELDS, // // /** // * <code>__javamethods</code> metamethod. // */ // JAVAMETHODS, // // /** // * <code>__javaproperties</code> metamethod. // */ // JAVAPROPERTIES; // // // -- Operations // /** // * Returns the Lua metamethod name. // * // * @return the metamethod name // */ // public String getMetamethodName() { // return "__" + toString().toLowerCase(); // } // }; // Path: src/main/java/com/naef/jnlua/LuaState.java import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.ref.PhantomReference; import java.lang.ref.ReferenceQueue; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.HashSet; import java.util.Set; import com.naef.jnlua.JavaReflector.Metamethod; * @see #getClassLoader() * @see #setClassLoader(ClassLoader) * @see #getJavaReflector() * @see #setJavaReflector(JavaReflector) * @see #getConverter() * @see #setConverter(Converter) */ public LuaState() { this(0L); } /** * Creates a new instance. */ private LuaState(long luaState) { ownState = luaState == 0L; lua_newstate(APIVERSION, luaState); check(); // Create a finalize guardian finalizeGuardian = new Object() { @Override public void finalize() { synchronized (LuaState.this) { closeInternal(); } } }; // Add metamethods
for (int i = 0; i < JavaReflector.Metamethod.values().length; i++) {
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/VersionUtils.java
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/client/TinkerClientAPI.java // public static final String TAG = "Tinker.ClientImpl";
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import java.util.Random; import java.util.UUID; import static com.tencent.tinker.server.client.TinkerClientAPI.TAG; import android.content.Context; import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.TinkerRuntimeException; import com.tencent.tinker.loader.shareutil.SharePatchFileUtil;
/* * The MIT License (MIT) * * Copyright (c) 2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tencent.tinker.server.utils; public final class VersionUtils { private static final String APP_VERSION = "app"; private static final String UUID_VALUE = "uuid"; private static final String GRAY_VALUE = "gray"; private static final String CURRENT_VERSION = "version"; private static final String CURRENT_MD5 = "md5"; private final File versionFile; private String uuid; private String appVersion; private Integer grayValue; private Integer patchVersion; private String patchMd5; public VersionUtils(Context context, String appVersion) { versionFile = new File(ServerUtils.getServerDirectory(context), ServerUtils.TINKER_VERSION_FILE); readVersionProperty(); if (!versionFile.exists() || uuid == null || appVersion == null || grayValue == null || patchVersion == null) { updateVersionProperty(appVersion, 0, "", randInt(1, 10), UUID.randomUUID().toString()); } else if (!appVersion.equals(this.appVersion)) { updateVersionProperty(appVersion, 0, "", grayValue, uuid); } } public boolean isInGrayGroup(Integer gray) { boolean result = gray == null || gray >= grayValue;
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/client/TinkerClientAPI.java // public static final String TAG = "Tinker.ClientImpl"; // Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/VersionUtils.java import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import java.util.Random; import java.util.UUID; import static com.tencent.tinker.server.client.TinkerClientAPI.TAG; import android.content.Context; import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.TinkerRuntimeException; import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; /* * The MIT License (MIT) * * Copyright (c) 2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tencent.tinker.server.utils; public final class VersionUtils { private static final String APP_VERSION = "app"; private static final String UUID_VALUE = "uuid"; private static final String GRAY_VALUE = "gray"; private static final String CURRENT_VERSION = "version"; private static final String CURRENT_MD5 = "md5"; private final File versionFile; private String uuid; private String appVersion; private Integer grayValue; private Integer patchVersion; private String patchMd5; public VersionUtils(Context context, String appVersion) { versionFile = new File(ServerUtils.getServerDirectory(context), ServerUtils.TINKER_VERSION_FILE); readVersionProperty(); if (!versionFile.exists() || uuid == null || appVersion == null || grayValue == null || patchVersion == null) { updateVersionProperty(appVersion, 0, "", randInt(1, 10), UUID.randomUUID().toString()); } else if (!appVersion.equals(this.appVersion)) { updateVersionProperty(appVersion, 0, "", grayValue, uuid); } } public boolean isInGrayGroup(Integer gray) { boolean result = gray == null || gray >= grayValue;
TinkerLog.d(TAG, "isInGrayGroup return %b, gray value:%d and my gray value is %d", result, gray, grayValue);
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/model/request/BaseReport.java
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/ServerUtils.java // public final class ServerUtils { // public static final String CHARSET = "UTF-8"; // public static final int BUFFER_SIZE = 4096; // public static final String TINKER_SERVER_DIR = "tinker_server"; // public static final String TINKER_VERSION_FILE = "version.info"; // // // private ServerUtils() { // // A TinkerServerUtils Class // } // // public static File readStreamToFile(InputStream inputStream, String filePath) throws IOException { // if (inputStream == null) { // return null; // } // // File file = new File(filePath); // File parent = file.getParentFile(); // if (!parent.exists() && !parent.mkdirs()) { // throw new IOException(String.format("Can't create folder %s", parent.getAbsolutePath())); // } // FileOutputStream fileOutput = new FileOutputStream(file); // try { // byte[] buffer = new byte[BUFFER_SIZE]; // int bufferLength; // while ((bufferLength = inputStream.read(buffer)) > 0) { // fileOutput.write(buffer, 0, bufferLength); // } // } finally { // try { // fileOutput.close(); // } catch (IOException ignored) { // // ignored // } // } // return file; // } // // public static Integer stringToInteger(String string) { // if (string == null) { // return null; // } // return Integer.parseInt(string); // } // // public static String readStreamToString(InputStream inputStream, String charset) { // if (inputStream == null) { // return null; // } // ByteArrayOutputStream bo = new ByteArrayOutputStream(); // byte[] buffer = new byte[BUFFER_SIZE]; // int bufferLength; // // String result; // try { // while ((bufferLength = inputStream.read(buffer)) > 0) { // bo.write(buffer, 0, bufferLength); // } // result = bo.toString(charset); // } catch (Throwable e) { // result = null; // } // return result; // } // // public static File getServerDirectory(Context context) { // ApplicationInfo applicationInfo = context.getApplicationInfo(); // if (applicationInfo == null) { // // Looks like running on a test Context, so just return without patching. // return null; // } // return new File(applicationInfo.dataDir, TINKER_SERVER_DIR); // } // // public static File getServerFile(Context context, String appVersion, String currentVersion) { // return new File(getServerDirectory(context), appVersion + "_" + currentVersion + ".apk"); // } // }
import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.server.utils.ServerUtils; import org.json.JSONException; import org.json.JSONObject;
jsonObject.put("av", appVersion); jsonObject.put("pv", patchVersion); jsonObject.put("t", platformType); return jsonObject; } protected HashMap<String, String> toEncodeObject() { HashMap<String, String> values = new HashMap<>(); values.put("k", appKey); values.put("av", appVersion); values.put("pv", patchVersion); values.put("t", String.valueOf(platformType)); return values; } public String toEncodeForm() { return getPostDataString(toEncodeObject()); } private String getPostDataString(HashMap<String, String> params) { StringBuilder result = new StringBuilder(); try { boolean first = true; for (Map.Entry<String, String> entry : params.entrySet()) { if (first) { first = false; } else { result.append('&'); }
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/ServerUtils.java // public final class ServerUtils { // public static final String CHARSET = "UTF-8"; // public static final int BUFFER_SIZE = 4096; // public static final String TINKER_SERVER_DIR = "tinker_server"; // public static final String TINKER_VERSION_FILE = "version.info"; // // // private ServerUtils() { // // A TinkerServerUtils Class // } // // public static File readStreamToFile(InputStream inputStream, String filePath) throws IOException { // if (inputStream == null) { // return null; // } // // File file = new File(filePath); // File parent = file.getParentFile(); // if (!parent.exists() && !parent.mkdirs()) { // throw new IOException(String.format("Can't create folder %s", parent.getAbsolutePath())); // } // FileOutputStream fileOutput = new FileOutputStream(file); // try { // byte[] buffer = new byte[BUFFER_SIZE]; // int bufferLength; // while ((bufferLength = inputStream.read(buffer)) > 0) { // fileOutput.write(buffer, 0, bufferLength); // } // } finally { // try { // fileOutput.close(); // } catch (IOException ignored) { // // ignored // } // } // return file; // } // // public static Integer stringToInteger(String string) { // if (string == null) { // return null; // } // return Integer.parseInt(string); // } // // public static String readStreamToString(InputStream inputStream, String charset) { // if (inputStream == null) { // return null; // } // ByteArrayOutputStream bo = new ByteArrayOutputStream(); // byte[] buffer = new byte[BUFFER_SIZE]; // int bufferLength; // // String result; // try { // while ((bufferLength = inputStream.read(buffer)) > 0) { // bo.write(buffer, 0, bufferLength); // } // result = bo.toString(charset); // } catch (Throwable e) { // result = null; // } // return result; // } // // public static File getServerDirectory(Context context) { // ApplicationInfo applicationInfo = context.getApplicationInfo(); // if (applicationInfo == null) { // // Looks like running on a test Context, so just return without patching. // return null; // } // return new File(applicationInfo.dataDir, TINKER_SERVER_DIR); // } // // public static File getServerFile(Context context, String appVersion, String currentVersion) { // return new File(getServerDirectory(context), appVersion + "_" + currentVersion + ".apk"); // } // } // Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/model/request/BaseReport.java import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.server.utils.ServerUtils; import org.json.JSONException; import org.json.JSONObject; jsonObject.put("av", appVersion); jsonObject.put("pv", patchVersion); jsonObject.put("t", platformType); return jsonObject; } protected HashMap<String, String> toEncodeObject() { HashMap<String, String> values = new HashMap<>(); values.put("k", appKey); values.put("av", appVersion); values.put("pv", patchVersion); values.put("t", String.valueOf(platformType)); return values; } public String toEncodeForm() { return getPostDataString(toEncodeObject()); } private String getPostDataString(HashMap<String, String> params) { StringBuilder result = new StringBuilder(); try { boolean first = true; for (Map.Entry<String, String> entry : params.entrySet()) { if (first) { first = false; } else { result.append('&'); }
result.append(URLEncoder.encode(entry.getKey(), ServerUtils.CHARSET));
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/TinkerPatch.java
// Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/ConfigRequestCallback.java // public interface ConfigRequestCallback { // void onSuccess(HashMap<String, String> configs); // void onFail(Exception e); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/RollbackCallBack.java // public interface RollbackCallBack { // void onPatchRollback(); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/tinker/callback/ResultCallBack.java // public interface ResultCallBack { // void onPatchResult(final PatchResult result); // }
import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.app.ApplicationLike; import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback; import com.tinkerpatch.sdk.server.callback.RollbackCallBack; import com.tinkerpatch.sdk.tinker.callback.ResultCallBack;
/* * The MIT License (MIT) * * Copyright (c) 2013-2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tinkerpatch.sdk; public abstract class TinkerPatch { /** * 设置Tinker相关Log的真正实现,用于自定义日志输出 * @param imp */ public static void setLogIml(TinkerLog.TinkerLogImp imp) { // nothing } /** * 用默认的构造参数初始化TinkerPatch的SDK * @param applicationLike * @return */ public static TinkerPatch init(ApplicationLike applicationLike) { return null; } /** * 自定义参数初始化TinkerPatch的SDK * @param tinkerPatch * @return */ public static TinkerPatch init(TinkerPatch tinkerPatch) { return null; } /** * 获得TinkerPatch的实例 * @return */ public static TinkerPatch with() { return null; } /** * 获得ApplicationLike的实例 * @return */ public abstract ApplicationLike getApplcationLike(); /** * 反射补丁的Library path, 自动加载library * 是否自动反射Library路径,无须手动加载补丁中的So文件 * 注意,调用在反射接口之后才能生效,你也可以使用Tinker的方式加载Library * @return */ public TinkerPatch reflectPatchLibrary() { return null; } /** * 向后台获得动态配置,默认的访问间隔为3个小时 * 若参数为true,即每次调用都会真正的访问后台配置 * * @param configRequestCallback * @param immediately 是否立刻请求,忽略时间间隔限制 */
// Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/ConfigRequestCallback.java // public interface ConfigRequestCallback { // void onSuccess(HashMap<String, String> configs); // void onFail(Exception e); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/RollbackCallBack.java // public interface RollbackCallBack { // void onPatchRollback(); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/tinker/callback/ResultCallBack.java // public interface ResultCallBack { // void onPatchResult(final PatchResult result); // } // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/TinkerPatch.java import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.app.ApplicationLike; import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback; import com.tinkerpatch.sdk.server.callback.RollbackCallBack; import com.tinkerpatch.sdk.tinker.callback.ResultCallBack; /* * The MIT License (MIT) * * Copyright (c) 2013-2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tinkerpatch.sdk; public abstract class TinkerPatch { /** * 设置Tinker相关Log的真正实现,用于自定义日志输出 * @param imp */ public static void setLogIml(TinkerLog.TinkerLogImp imp) { // nothing } /** * 用默认的构造参数初始化TinkerPatch的SDK * @param applicationLike * @return */ public static TinkerPatch init(ApplicationLike applicationLike) { return null; } /** * 自定义参数初始化TinkerPatch的SDK * @param tinkerPatch * @return */ public static TinkerPatch init(TinkerPatch tinkerPatch) { return null; } /** * 获得TinkerPatch的实例 * @return */ public static TinkerPatch with() { return null; } /** * 获得ApplicationLike的实例 * @return */ public abstract ApplicationLike getApplcationLike(); /** * 反射补丁的Library path, 自动加载library * 是否自动反射Library路径,无须手动加载补丁中的So文件 * 注意,调用在反射接口之后才能生效,你也可以使用Tinker的方式加载Library * @return */ public TinkerPatch reflectPatchLibrary() { return null; } /** * 向后台获得动态配置,默认的访问间隔为3个小时 * 若参数为true,即每次调用都会真正的访问后台配置 * * @param configRequestCallback * @param immediately 是否立刻请求,忽略时间间隔限制 */
public TinkerPatch fetchDynamicConfig(final ConfigRequestCallback configRequestCallback,
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/TinkerPatch.java
// Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/ConfigRequestCallback.java // public interface ConfigRequestCallback { // void onSuccess(HashMap<String, String> configs); // void onFail(Exception e); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/RollbackCallBack.java // public interface RollbackCallBack { // void onPatchRollback(); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/tinker/callback/ResultCallBack.java // public interface ResultCallBack { // void onPatchResult(final PatchResult result); // }
import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.app.ApplicationLike; import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback; import com.tinkerpatch.sdk.server.callback.RollbackCallBack; import com.tinkerpatch.sdk.tinker.callback.ResultCallBack;
} /** * 设置访问后台补丁包更新配置的时间间隔,默认为3个小时 * * @param hours * @return */ public TinkerPatch setFetchPatchIntervalByHours(int hours) { return null; } /** * 设置补丁合成成功后,是否通过锁屏重启程序,这样可以加快补丁的生效时间 * 默认为false, 即等待应用自身重新启动时加载 * * @param restartOnScreenOff * @return */ public TinkerPatch setPatchRestartOnSrceenOff(boolean restartOnScreenOff) { return null; } /** * 我们可以通过ResultCallBack设置对合成后的回调 * 例如我们也可以不锁屏,而是在这里通过弹框咨询用户等方式 * * @param resultCallBack * @return */
// Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/ConfigRequestCallback.java // public interface ConfigRequestCallback { // void onSuccess(HashMap<String, String> configs); // void onFail(Exception e); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/RollbackCallBack.java // public interface RollbackCallBack { // void onPatchRollback(); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/tinker/callback/ResultCallBack.java // public interface ResultCallBack { // void onPatchResult(final PatchResult result); // } // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/TinkerPatch.java import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.app.ApplicationLike; import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback; import com.tinkerpatch.sdk.server.callback.RollbackCallBack; import com.tinkerpatch.sdk.tinker.callback.ResultCallBack; } /** * 设置访问后台补丁包更新配置的时间间隔,默认为3个小时 * * @param hours * @return */ public TinkerPatch setFetchPatchIntervalByHours(int hours) { return null; } /** * 设置补丁合成成功后,是否通过锁屏重启程序,这样可以加快补丁的生效时间 * 默认为false, 即等待应用自身重新启动时加载 * * @param restartOnScreenOff * @return */ public TinkerPatch setPatchRestartOnSrceenOff(boolean restartOnScreenOff) { return null; } /** * 我们可以通过ResultCallBack设置对合成后的回调 * 例如我们也可以不锁屏,而是在这里通过弹框咨询用户等方式 * * @param resultCallBack * @return */
public TinkerPatch setPatchResultCallback(ResultCallBack resultCallBack) {
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/TinkerPatch.java
// Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/ConfigRequestCallback.java // public interface ConfigRequestCallback { // void onSuccess(HashMap<String, String> configs); // void onFail(Exception e); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/RollbackCallBack.java // public interface RollbackCallBack { // void onPatchRollback(); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/tinker/callback/ResultCallBack.java // public interface ResultCallBack { // void onPatchResult(final PatchResult result); // }
import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.app.ApplicationLike; import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback; import com.tinkerpatch.sdk.server.callback.RollbackCallBack; import com.tinkerpatch.sdk.tinker.callback.ResultCallBack;
} /** * 我们可以通过ResultCallBack设置对合成后的回调 * 例如我们也可以不锁屏,而是在这里通过弹框咨询用户等方式 * * @param resultCallBack * @return */ public TinkerPatch setPatchResultCallback(ResultCallBack resultCallBack) { return null; } /** * 设置收到后台回退要求时,是否在锁屏时清除补丁 * 默认为false,即等待应用下一次重新启动时才会去清除补丁 * * @param rollbackOnScreenOff * @return */ public TinkerPatch setPatchRollbackOnScreenOff(boolean rollbackOnScreenOff) { return null; } /** * 我们可以通过RollbackCallBack设置对回退时的回调 * * @param rollbackCallBack * @return */
// Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/ConfigRequestCallback.java // public interface ConfigRequestCallback { // void onSuccess(HashMap<String, String> configs); // void onFail(Exception e); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/server/callback/RollbackCallBack.java // public interface RollbackCallBack { // void onPatchRollback(); // } // // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/tinker/callback/ResultCallBack.java // public interface ResultCallBack { // void onPatchResult(final PatchResult result); // } // Path: tinkerpatch-sdk/src/main/java/com/tinkerpatch/sdk/TinkerPatch.java import com.tencent.tinker.lib.util.TinkerLog; import com.tencent.tinker.loader.app.ApplicationLike; import com.tinkerpatch.sdk.server.callback.ConfigRequestCallback; import com.tinkerpatch.sdk.server.callback.RollbackCallBack; import com.tinkerpatch.sdk.tinker.callback.ResultCallBack; } /** * 我们可以通过ResultCallBack设置对合成后的回调 * 例如我们也可以不锁屏,而是在这里通过弹框咨询用户等方式 * * @param resultCallBack * @return */ public TinkerPatch setPatchResultCallback(ResultCallBack resultCallBack) { return null; } /** * 设置收到后台回退要求时,是否在锁屏时清除补丁 * 默认为false,即等待应用下一次重新启动时才会去清除补丁 * * @param rollbackOnScreenOff * @return */ public TinkerPatch setPatchRollbackOnScreenOff(boolean rollbackOnScreenOff) { return null; } /** * 我们可以通过RollbackCallBack设置对回退时的回调 * * @param rollbackCallBack * @return */
public TinkerPatch setPatchRollBackCallback(RollbackCallBack rollbackCallBack) {
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/Conditions.java
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/client/TinkerClientAPI.java // public static final String TAG = "Tinker.ClientImpl";
import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Stack; import java.util.regex.Pattern; import static com.tencent.tinker.server.client.TinkerClientAPI.TAG; import android.content.Context; import android.text.TextUtils; import com.tencent.tinker.lib.util.TinkerLog; import java.io.File;
/* * The MIT License (MIT) * * Copyright (c) 2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tencent.tinker.server.utils; public class Conditions { static final String FILE_NAME = "CONDITIONS_MAP"; static final Pattern INT_PATTERN = Pattern.compile("-?[0-9]+"); private final Map<String, String> properties; public Conditions() { properties = new HashMap<>(); } public Boolean check(String rules) { if (TextUtils.isEmpty(rules)) { return true; } List<String> rpList = Helper.toReversePolish(rules); try { return Helper.calcReversePolish(rpList, properties); } catch (Exception ignore) {
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/client/TinkerClientAPI.java // public static final String TAG = "Tinker.ClientImpl"; // Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/Conditions.java import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Stack; import java.util.regex.Pattern; import static com.tencent.tinker.server.client.TinkerClientAPI.TAG; import android.content.Context; import android.text.TextUtils; import com.tencent.tinker.lib.util.TinkerLog; import java.io.File; /* * The MIT License (MIT) * * Copyright (c) 2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tencent.tinker.server.utils; public class Conditions { static final String FILE_NAME = "CONDITIONS_MAP"; static final Pattern INT_PATTERN = Pattern.compile("-?[0-9]+"); private final Map<String, String> properties; public Conditions() { properties = new HashMap<>(); } public Boolean check(String rules) { if (TextUtils.isEmpty(rules)) { return true; } List<String> rpList = Helper.toReversePolish(rules); try { return Helper.calcReversePolish(rpList, properties); } catch (Exception ignore) {
TinkerLog.e(TAG, "parse conditions error(have you written '==' as '='?): " + rules, ignore);
TinkerPatch/tinkerpatch-sdk
tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/model/TinkerClientUrl.java
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/Preconditions.java // public final class Preconditions { // // private Preconditions() { // // TinkerServerUtils class. // } // // public static void checkArgument(boolean expression, String message) { // if (!expression) { // throw new IllegalArgumentException(message); // } // } // // public static <T> T checkNotNull(T arg) { // return checkNotNull(arg, "Argument must not be null"); // } // // public static <T> T checkNotNull(T arg, String message) { // if (arg == null) { // throw new NullPointerException(message); // } // return arg; // } // // public static String checkNotEmpty(String string) { // if (TextUtils.isEmpty(string)) { // throw new IllegalArgumentException("Must not be null or empty"); // } // return string; // } // // public static <T extends Collection<Y>, Y> T checkNotEmpty(T collection) { // if (collection.isEmpty()) { // throw new IllegalArgumentException("Must not be empty."); // } // return collection; // } // }
import java.net.URL; import java.util.HashMap; import java.util.Map; import android.net.Uri; import android.text.TextUtils; import com.tencent.tinker.server.utils.Preconditions; import java.net.MalformedURLException;
/* * The MIT License (MIT) * * Copyright (c) 2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tencent.tinker.server.model; public class TinkerClientUrl { private static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%"; private final Headers headers; private final String stringUrl; private final String body; private final String method; private String safeStringUrl; private URL safeUrl; public TinkerClientUrl(String stringUrl, Headers headers, String body, String method) {
// Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/utils/Preconditions.java // public final class Preconditions { // // private Preconditions() { // // TinkerServerUtils class. // } // // public static void checkArgument(boolean expression, String message) { // if (!expression) { // throw new IllegalArgumentException(message); // } // } // // public static <T> T checkNotNull(T arg) { // return checkNotNull(arg, "Argument must not be null"); // } // // public static <T> T checkNotNull(T arg, String message) { // if (arg == null) { // throw new NullPointerException(message); // } // return arg; // } // // public static String checkNotEmpty(String string) { // if (TextUtils.isEmpty(string)) { // throw new IllegalArgumentException("Must not be null or empty"); // } // return string; // } // // public static <T extends Collection<Y>, Y> T checkNotEmpty(T collection) { // if (collection.isEmpty()) { // throw new IllegalArgumentException("Must not be empty."); // } // return collection; // } // } // Path: tinkerpatch-sdk/src/main/java/com/tencent/tinker/server/model/TinkerClientUrl.java import java.net.URL; import java.util.HashMap; import java.util.Map; import android.net.Uri; import android.text.TextUtils; import com.tencent.tinker.server.utils.Preconditions; import java.net.MalformedURLException; /* * The MIT License (MIT) * * Copyright (c) 2016 Shengjie Sim Sun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.tencent.tinker.server.model; public class TinkerClientUrl { private static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%"; private final Headers headers; private final String stringUrl; private final String body; private final String method; private String safeStringUrl; private URL safeUrl; public TinkerClientUrl(String stringUrl, Headers headers, String body, String method) {
this.stringUrl = Preconditions.checkNotEmpty(stringUrl);
USCDataScience/AgePredictor
age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/AgeClassifyContextGeneratorWrapper.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // }
import java.io.Serializable; import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator;
/* * 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 edu.usc.irds.agepredictor.spark.authorage; public class AgeClassifyContextGeneratorWrapper implements Serializable { private String tokenizer; private String featureGeneratorNames; public AgeClassifyContextGeneratorWrapper(String tok, String fg) { this.tokenizer = tok; this.featureGeneratorNames = fg; } public Tokenizer getTokenizer() { if(tokenizer != null) { return ExtensionLoader.instantiateExtension(Tokenizer.class, this.tokenizer); } return WhitespaceTokenizer.INSTANCE; }
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // } // Path: age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/AgeClassifyContextGeneratorWrapper.java import java.io.Serializable; import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator; /* * 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 edu.usc.irds.agepredictor.spark.authorage; public class AgeClassifyContextGeneratorWrapper implements Serializable { private String tokenizer; private String featureGeneratorNames; public AgeClassifyContextGeneratorWrapper(String tok, String fg) { this.tokenizer = tok; this.featureGeneratorNames = fg; } public Tokenizer getTokenizer() { if(tokenizer != null) { return ExtensionLoader.instantiateExtension(Tokenizer.class, this.tokenizer); } return WhitespaceTokenizer.INSTANCE; }
public FeatureGenerator[] getFeatureGenerators() {
USCDataScience/AgePredictor
age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/AgeClassifyContextGeneratorWrapper.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // }
import java.io.Serializable; import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator;
/* * 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 edu.usc.irds.agepredictor.spark.authorage; public class AgeClassifyContextGeneratorWrapper implements Serializable { private String tokenizer; private String featureGeneratorNames; public AgeClassifyContextGeneratorWrapper(String tok, String fg) { this.tokenizer = tok; this.featureGeneratorNames = fg; } public Tokenizer getTokenizer() { if(tokenizer != null) { return ExtensionLoader.instantiateExtension(Tokenizer.class, this.tokenizer); } return WhitespaceTokenizer.INSTANCE; } public FeatureGenerator[] getFeatureGenerators() { if(this.featureGeneratorNames == null) {
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // } // Path: age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/AgeClassifyContextGeneratorWrapper.java import java.io.Serializable; import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator; /* * 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 edu.usc.irds.agepredictor.spark.authorage; public class AgeClassifyContextGeneratorWrapper implements Serializable { private String tokenizer; private String featureGeneratorNames; public AgeClassifyContextGeneratorWrapper(String tok, String fg) { this.tokenizer = tok; this.featureGeneratorNames = fg; } public Tokenizer getTokenizer() { if(tokenizer != null) { return ExtensionLoader.instantiateExtension(Tokenizer.class, this.tokenizer); } return WhitespaceTokenizer.INSTANCE; } public FeatureGenerator[] getFeatureGenerators() { if(this.featureGeneratorNames == null) {
FeatureGenerator[] def = { new BagOfWordsFeatureGenerator()};
USCDataScience/AgePredictor
age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/AgeClassifySparkEvaluator.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AgeClassifyME.java // public class AgeClassifyME { // protected AgeClassifyContextGenerator contextGenerator; // // private AgeClassifyFactory factory; // private AgeClassifyModel model; // // public AgeClassifyME(AgeClassifyModel ageModel) { // this.model = ageModel; // this.factory = ageModel.getFactory(); // // this.contextGenerator = new AgeClassifyContextGenerator( // this.factory.getFeatureGenerators()); // } // // // public String getBestCategory(double[] outcome) { // return this.model.getMaxentModel().getBestOutcome(outcome); // } // // public int getNumCategories() { // return this.model.getMaxentModel().getNumOutcomes(); // } // // public String getCategory(int index) { // return this.model.getMaxentModel().getOutcome(index); // } // // public int getIndex(String category) { // return this.model.getMaxentModel().getIndex(category); // } // // public double[] getProbabilities(String text[]) { // return this.model.getMaxentModel().eval( // contextGenerator.getContext(text)); // } // // public double[] getProbabilities(String documentText) { // Tokenizer tokenizer = this.factory.getTokenizer(); // return getProbabilities(tokenizer.tokenize(documentText)); // } // // public String predict(String documentText) { // double probs[] = getProbabilities(documentText); // String category = getBestCategory(probs); // // return category; // } // // public Map<String, Double> scoreMap(String documentText) { // Map<String, Double> probs = new HashMap<String, Double>(); // // double[] categories = getProbabilities(documentText); // // int numCategories = getNumCategories(); // for (int i = 0; i < numCategories; i++) { // String category = getCategory(i); // probs.put(category, categories[getIndex(category)]); // } // return probs; // } // // public SortedMap<Double, Set<String>> sortedScoreMap(String documentText) { // SortedMap<Double, Set<String>> sortedMap = new TreeMap<Double, Set<String>>(); // // double[] categories = getProbabilities(documentText); // // int numCategories = getNumCategories(); // for (int i = 0; i < numCategories; i++) { // String category = getCategory(i); // double score = categories[getIndex(category)]; // // if (sortedMap.containsKey(score)) { // sortedMap.get(score).add(category); // } else { // Set<String> newset = new HashSet<String>(); // newset.add(category); // sortedMap.put(score, newset); // } // } // return sortedMap; // } // // // public static AgeClassifyModel train(String languageCode, // ObjectStream<AuthorAgeSample> samples, TrainingParameters trainParams, // AgeClassifyFactory factory) throws IOException { // // Map<String, String> entries = new HashMap<String, String>(); // // MaxentModel ageModel = null; // // TrainerType trainerType = AgeClassifyTrainerFactory // .getTrainerType(trainParams.getSettings()); // // ObjectStream<Event> eventStream = new AgeClassifyEventStream(samples, // factory.createContextGenerator()); // // EventTrainer trainer = AgeClassifyTrainerFactory // .getEventTrainer(trainParams.getSettings(), entries); // ageModel = trainer.train(eventStream); // // Map<String, String> manifestInfoEntries = new HashMap<String, String>(); // // return new AgeClassifyModel(languageCode, ageModel, manifestInfoEntries, // factory); // } // // // }
import scala.Tuple2; import java.io.File; import java.io.IOException; import java.util.List; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaPairRDD; import org.apache.spark.api.java.JavaRDD; import org.apache.spark.api.java.JavaSparkContext; import org.apache.spark.api.java.function.Function; import org.apache.spark.api.java.function.Function2; import org.apache.spark.api.java.function.PairFunction; import opennlp.tools.authorage.AgeClassifyME;
/* * 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 edu.usc.irds.agepredictor.spark.authorage; /** * TODO: Documentation */ public class AgeClassifySparkEvaluator { public static class EvaluateSample implements Function<Tuple2<String, String>, Boolean> { private AgeClassifyModelWrapper wrapper; public EvaluateSample(File model) { this.wrapper = new AgeClassifyModelWrapper(model); } public EvaluateSample(AgeClassifyModelWrapper w) { this.wrapper = w; } @Override public Boolean call(Tuple2<String, String> sample) throws IOException { String category = sample._1(); String text = sample._2(); System.out.println("Sample: " + category + ", " + text);
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AgeClassifyME.java // public class AgeClassifyME { // protected AgeClassifyContextGenerator contextGenerator; // // private AgeClassifyFactory factory; // private AgeClassifyModel model; // // public AgeClassifyME(AgeClassifyModel ageModel) { // this.model = ageModel; // this.factory = ageModel.getFactory(); // // this.contextGenerator = new AgeClassifyContextGenerator( // this.factory.getFeatureGenerators()); // } // // // public String getBestCategory(double[] outcome) { // return this.model.getMaxentModel().getBestOutcome(outcome); // } // // public int getNumCategories() { // return this.model.getMaxentModel().getNumOutcomes(); // } // // public String getCategory(int index) { // return this.model.getMaxentModel().getOutcome(index); // } // // public int getIndex(String category) { // return this.model.getMaxentModel().getIndex(category); // } // // public double[] getProbabilities(String text[]) { // return this.model.getMaxentModel().eval( // contextGenerator.getContext(text)); // } // // public double[] getProbabilities(String documentText) { // Tokenizer tokenizer = this.factory.getTokenizer(); // return getProbabilities(tokenizer.tokenize(documentText)); // } // // public String predict(String documentText) { // double probs[] = getProbabilities(documentText); // String category = getBestCategory(probs); // // return category; // } // // public Map<String, Double> scoreMap(String documentText) { // Map<String, Double> probs = new HashMap<String, Double>(); // // double[] categories = getProbabilities(documentText); // // int numCategories = getNumCategories(); // for (int i = 0; i < numCategories; i++) { // String category = getCategory(i); // probs.put(category, categories[getIndex(category)]); // } // return probs; // } // // public SortedMap<Double, Set<String>> sortedScoreMap(String documentText) { // SortedMap<Double, Set<String>> sortedMap = new TreeMap<Double, Set<String>>(); // // double[] categories = getProbabilities(documentText); // // int numCategories = getNumCategories(); // for (int i = 0; i < numCategories; i++) { // String category = getCategory(i); // double score = categories[getIndex(category)]; // // if (sortedMap.containsKey(score)) { // sortedMap.get(score).add(category); // } else { // Set<String> newset = new HashSet<String>(); // newset.add(category); // sortedMap.put(score, newset); // } // } // return sortedMap; // } // // // public static AgeClassifyModel train(String languageCode, // ObjectStream<AuthorAgeSample> samples, TrainingParameters trainParams, // AgeClassifyFactory factory) throws IOException { // // Map<String, String> entries = new HashMap<String, String>(); // // MaxentModel ageModel = null; // // TrainerType trainerType = AgeClassifyTrainerFactory // .getTrainerType(trainParams.getSettings()); // // ObjectStream<Event> eventStream = new AgeClassifyEventStream(samples, // factory.createContextGenerator()); // // EventTrainer trainer = AgeClassifyTrainerFactory // .getEventTrainer(trainParams.getSettings(), entries); // ageModel = trainer.train(eventStream); // // Map<String, String> manifestInfoEntries = new HashMap<String, String>(); // // return new AgeClassifyModel(languageCode, ageModel, manifestInfoEntries, // factory); // } // // // } // Path: age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/AgeClassifySparkEvaluator.java import scala.Tuple2; import java.io.File; import java.io.IOException; import java.util.List; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaPairRDD; import org.apache.spark.api.java.JavaRDD; import org.apache.spark.api.java.JavaSparkContext; import org.apache.spark.api.java.function.Function; import org.apache.spark.api.java.function.Function2; import org.apache.spark.api.java.function.PairFunction; import opennlp.tools.authorage.AgeClassifyME; /* * 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 edu.usc.irds.agepredictor.spark.authorage; /** * TODO: Documentation */ public class AgeClassifySparkEvaluator { public static class EvaluateSample implements Function<Tuple2<String, String>, Boolean> { private AgeClassifyModelWrapper wrapper; public EvaluateSample(File model) { this.wrapper = new AgeClassifyModelWrapper(model); } public EvaluateSample(AgeClassifyModelWrapper w) { this.wrapper = w; } @Override public Boolean call(Tuple2<String, String> sample) throws IOException { String category = sample._1(); String text = sample._2(); System.out.println("Sample: " + category + ", " + text);
AgeClassifyME classifier = this.wrapper.getClassifier();
USCDataScience/AgePredictor
age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/cmdline/authorage/AgeClassifyFineGrainedReportListener.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AuthorAgeSample.java // public class AuthorAgeSample implements Serializable{ // private static final long serialVersionUID = 5374409234122582256L; // // public static final String FORMAT_NAME = "authorage"; // // private final String ageCategory; // // private final List<String> text; // // public AuthorAgeSample(String category, String text[]) { // if (category == null) { // throw new IllegalArgumentException("Age cannot be null"); // } // if (text == null) { // throw new IllegalArgumentException("Text cannot be null"); // } // // this.ageCategory = category; // // this.text = Collections // .unmodifiableList(new ArrayList<String>(Arrays.asList(text))); // } // // // public AuthorAgeSample(Integer age, String text[]) { // if (age == null) { // throw new IllegalArgumentException("Age cannot be null"); // } // if (text == null) { // throw new IllegalArgumentException("Text cannot be null"); // } // // if (age < 18) { // ageCategory = "xx-18"; // } // else if (age >= 18 && age <= 24) { // ageCategory = "18-24"; // } // else if (age >= 25 && age <= 34) { // ageCategory = "25-34"; // } // else if (age >= 35 && age <= 49) { // ageCategory = "35-49"; // } // else if (age >= 50 && age <= 64) { // ageCategory = "50-64"; // } // else { // (age > 65) // ageCategory = "65-xx"; // } // // this.text = Collections // .unmodifiableList(new ArrayList<String>(Arrays.asList(text))); // } // // public String getCategory() { // return this.ageCategory; // } // // public String[] getText() { // return this.text.toArray(new String[this.text.size()]); // } // // @Override // public String toString() { // StringBuilder sampleString = new StringBuilder(); // // sampleString.append(ageCategory).append('\t'); // // for (String s : text) { // sampleString.append(s).append(' '); // } // // if (sampleString.length() > 0) { // // remove last space // sampleString.setLength(sampleString.length() - 1); // } // // return sampleString.toString(); // } // // // }
import java.io.OutputStream; import java.io.PrintStream; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import opennlp.tools.authorage.AgeClassifyEvaluationMonitor; import opennlp.tools.authorage.AuthorAgeSample; import opennlp.tools.util.Span; import opennlp.tools.util.eval.FMeasure; import opennlp.tools.util.eval.Mean;
/* * 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 edu.usc.irds.agepredictor.cmdline.authorage; /** * Generates a detailed report for the Age Classifier. * <p> * It is possible to use it from an API and access the statistics using the * provided getters * */ public class AgeClassifyFineGrainedReportListener implements AgeClassifyEvaluationMonitor { private final PrintStream printStream; private final Stats stats = new Stats(); private static final char[] alpha = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; /** * Creates a listener that will print to {@link System#err} */ public AgeClassifyFineGrainedReportListener() { this(System.err); } /** * Creates a listener that prints to a given {@link OutputStream} */ public AgeClassifyFineGrainedReportListener(OutputStream outputStream) { this.printStream = new PrintStream(outputStream); } // methods inherited from EvaluationMonitor
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AuthorAgeSample.java // public class AuthorAgeSample implements Serializable{ // private static final long serialVersionUID = 5374409234122582256L; // // public static final String FORMAT_NAME = "authorage"; // // private final String ageCategory; // // private final List<String> text; // // public AuthorAgeSample(String category, String text[]) { // if (category == null) { // throw new IllegalArgumentException("Age cannot be null"); // } // if (text == null) { // throw new IllegalArgumentException("Text cannot be null"); // } // // this.ageCategory = category; // // this.text = Collections // .unmodifiableList(new ArrayList<String>(Arrays.asList(text))); // } // // // public AuthorAgeSample(Integer age, String text[]) { // if (age == null) { // throw new IllegalArgumentException("Age cannot be null"); // } // if (text == null) { // throw new IllegalArgumentException("Text cannot be null"); // } // // if (age < 18) { // ageCategory = "xx-18"; // } // else if (age >= 18 && age <= 24) { // ageCategory = "18-24"; // } // else if (age >= 25 && age <= 34) { // ageCategory = "25-34"; // } // else if (age >= 35 && age <= 49) { // ageCategory = "35-49"; // } // else if (age >= 50 && age <= 64) { // ageCategory = "50-64"; // } // else { // (age > 65) // ageCategory = "65-xx"; // } // // this.text = Collections // .unmodifiableList(new ArrayList<String>(Arrays.asList(text))); // } // // public String getCategory() { // return this.ageCategory; // } // // public String[] getText() { // return this.text.toArray(new String[this.text.size()]); // } // // @Override // public String toString() { // StringBuilder sampleString = new StringBuilder(); // // sampleString.append(ageCategory).append('\t'); // // for (String s : text) { // sampleString.append(s).append(' '); // } // // if (sampleString.length() > 0) { // // remove last space // sampleString.setLength(sampleString.length() - 1); // } // // return sampleString.toString(); // } // // // } // Path: age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/cmdline/authorage/AgeClassifyFineGrainedReportListener.java import java.io.OutputStream; import java.io.PrintStream; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import opennlp.tools.authorage.AgeClassifyEvaluationMonitor; import opennlp.tools.authorage.AuthorAgeSample; import opennlp.tools.util.Span; import opennlp.tools.util.eval.FMeasure; import opennlp.tools.util.eval.Mean; /* * 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 edu.usc.irds.agepredictor.cmdline.authorage; /** * Generates a detailed report for the Age Classifier. * <p> * It is possible to use it from an API and access the statistics using the * provided getters * */ public class AgeClassifyFineGrainedReportListener implements AgeClassifyEvaluationMonitor { private final PrintStream printStream; private final Stats stats = new Stats(); private static final char[] alpha = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; /** * Creates a listener that will print to {@link System#err} */ public AgeClassifyFineGrainedReportListener() { this(System.err); } /** * Creates a listener that prints to a given {@link OutputStream} */ public AgeClassifyFineGrainedReportListener(OutputStream outputStream) { this.printStream = new PrintStream(outputStream); } // methods inherited from EvaluationMonitor
public void missclassified(AuthorAgeSample reference, AuthorAgeSample prediction) {
USCDataScience/AgePredictor
age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AgeClassifyFactory.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // }
import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.BaseToolFactory; import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator;
/* * 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 opennlp.tools.authorage; /** * TODO: Documentation */ public class AgeClassifyFactory extends BaseToolFactory { public static final AgeClassifyFactory INSTANCE = new AgeClassifyFactory(); private static final String FEATURE_GENERATORS = "authorage.featureGenerators"; private static final String TOKENIZER_NAME = "authorage.tokenizer";
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // } // Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AgeClassifyFactory.java import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.BaseToolFactory; import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator; /* * 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 opennlp.tools.authorage; /** * TODO: Documentation */ public class AgeClassifyFactory extends BaseToolFactory { public static final AgeClassifyFactory INSTANCE = new AgeClassifyFactory(); private static final String FEATURE_GENERATORS = "authorage.featureGenerators"; private static final String TOKENIZER_NAME = "authorage.tokenizer";
private FeatureGenerator[] featureGenerators; // Defaults to just getting unigrams
USCDataScience/AgePredictor
age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AgeClassifyFactory.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // }
import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.BaseToolFactory; import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator;
String[] classes = classNames.split(","); FeatureGenerator[] features = new FeatureGenerator[classes.length]; for (int i = 0; i < classes.length; i++) { /* Class ext = Class.forName(classes[i]); Field instance = ext.getDeclaredField("INSTANCE"); System.out.println(instance.toString()); features[i] = (FeatureGenerator) instance.getDeclaringClass(); */ features[i] = ExtensionLoader.instantiateExtension(FeatureGenerator.class, classes[i]); } return features; } public FeatureGenerator[] getFeatureGenerators() { if (featureGenerators == null) { if (artifactProvider != null) { String classNames = artifactProvider .getManifestProperty(FEATURE_GENERATORS); if (classNames != null) { this.featureGenerators = loadFeatureGenerators(classNames); } } if (featureGenerators == null) { // could not load using artifact provider // load bag of words as default
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/BagOfWordsFeatureGenerator.java // public class BagOfWordsFeatureGenerator implements FeatureGenerator { // // public static final BagOfWordsFeatureGenerator INSTANCE = new BagOfWordsFeatureGenerator(); // // private static List<String> stopwords = new ArrayList<String>(); // // static { // try { // stopwords = FileUtils.readLines(new File("props/stopwords.txt"), "utf-8"); // } catch (IOException e) { // stopwords = new ArrayList<String>(); // } // } // // public BagOfWordsFeatureGenerator() { // } // // @Override // public Collection<String> extractFeatures(String[] text) { // // Collection<String> bagOfWords = new ArrayList<String>(); // // for (String word : text) { // if (!stopwords.contains(word)) { // bagOfWords.add("bow=" + word); // } // } // // return bagOfWords; // } // // } // // Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // } // Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AgeClassifyFactory.java import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.tokenize.WhitespaceTokenizer; import opennlp.tools.util.BaseToolFactory; import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.ext.ExtensionLoader; import opennlp.tools.util.featuregen.BagOfWordsFeatureGenerator; import opennlp.tools.util.featuregen.FeatureGenerator; String[] classes = classNames.split(","); FeatureGenerator[] features = new FeatureGenerator[classes.length]; for (int i = 0; i < classes.length; i++) { /* Class ext = Class.forName(classes[i]); Field instance = ext.getDeclaredField("INSTANCE"); System.out.println(instance.toString()); features[i] = (FeatureGenerator) instance.getDeclaringClass(); */ features[i] = ExtensionLoader.instantiateExtension(FeatureGenerator.class, classes[i]); } return features; } public FeatureGenerator[] getFeatureGenerators() { if (featureGenerators == null) { if (artifactProvider != null) { String classNames = artifactProvider .getManifestProperty(FEATURE_GENERATORS); if (classNames != null) { this.featureGenerators = loadFeatureGenerators(classNames); } } if (featureGenerators == null) { // could not load using artifact provider // load bag of words as default
FeatureGenerator[] def = { BagOfWordsFeatureGenerator.INSTANCE };
USCDataScience/AgePredictor
age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/CreateEvents.java
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // }
import opennlp.tools.util.featuregen.FeatureGenerator; import java.util.Collection; import java.util.LinkedList; import org.apache.spark.api.java.function.Function;
/* * 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 edu.usc.irds.agepredictor.spark.authorage; public class CreateEvents implements Function<String, EventWrapper> { private AgeClassifyContextGeneratorWrapper wrapper; public CreateEvents(String tok, String fg) { this.wrapper = new AgeClassifyContextGeneratorWrapper(tok, fg); } public CreateEvents(AgeClassifyContextGeneratorWrapper w) { this.wrapper = w; } @Override public EventWrapper call(String s) { String category; String text; try { category = s.split("\t", 2)[0]; text = s.split("\t", 2)[1]; } catch (Exception e) { //not in correct format. ignore return null; } //first tokenize the text String tokens[] = this.wrapper.getTokenizer().tokenize(text); //then extract features using all the feature generators Collection<String> context = new LinkedList<String>();
// Path: age-predictor-opennlp/src/main/java/opennlp/tools/util/featuregen/FeatureGenerator.java // public interface FeatureGenerator { // // /** // * Extract features from given text fragments // * // * @param text the text fragments to extract features from // * @param extraInformation optional extra information to be used by the feature generator // * @return a collection of features // */ // Collection<String> extractFeatures(String[] text); // } // Path: age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/spark/authorage/CreateEvents.java import opennlp.tools.util.featuregen.FeatureGenerator; import java.util.Collection; import java.util.LinkedList; import org.apache.spark.api.java.function.Function; /* * 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 edu.usc.irds.agepredictor.spark.authorage; public class CreateEvents implements Function<String, EventWrapper> { private AgeClassifyContextGeneratorWrapper wrapper; public CreateEvents(String tok, String fg) { this.wrapper = new AgeClassifyContextGeneratorWrapper(tok, fg); } public CreateEvents(AgeClassifyContextGeneratorWrapper w) { this.wrapper = w; } @Override public EventWrapper call(String s) { String category; String text; try { category = s.split("\t", 2)[0]; text = s.split("\t", 2)[1]; } catch (Exception e) { //not in correct format. ignore return null; } //first tokenize the text String tokens[] = this.wrapper.getTokenizer().tokenize(text); //then extract features using all the feature generators Collection<String> context = new LinkedList<String>();
FeatureGenerator[] featureGenerators = this.wrapper.getFeatureGenerators();
Tyde/TuCanMobile
app/src/main/java/com/dalthed/tucan/ui/ApplyEvent.java
// Path: app/src/main/java/com/dalthed/tucan/Connection/AnswerObject.java // public class AnswerObject { // private String HTML_text; // private String redirectURL; // private String lastcalledURL; // private CookieManager Cookies; // /** // * RückgabeObjekt der BrowseMethods // * @param HTML HTML-Code // * @param redirect Redirect-URL aus dem HTTP-Header // * @param myCookies CookieManager mit relevanten Cookies // * @param lastcalledURL Zuletzt aufgerufene URL // */ // public AnswerObject(String HTML,String redirect,CookieManager myCookies,String lastcalledURL){ // this.HTML_text=HTML; // this.redirectURL=redirect; // this.Cookies=myCookies; // this.lastcalledURL=lastcalledURL; // } // public String getHTML(){ // return this.HTML_text; // } // public String getRedirectURLString() { // return this.redirectURL; // } // public String getLastCalledURL() { // return this.lastcalledURL; // } // public CookieManager getCookieManager() { // return this.Cookies; // } // // } // // Path: app/src/main/java/com/dalthed/tucan/util/ConfigurationChangeStorage.java // public class ConfigurationChangeStorage { // // private ArrayList<BasicScraper> scrapers; // private ArrayList<SimpleSecureBrowser> browser; // public ArrayList<ListAdapter> adapters; // // public int mode; // // public ConfigurationChangeStorage() { // scrapers = new ArrayList<BasicScraper>(); // adapters = new ArrayList<ListAdapter>(); // browser = new ArrayList<SimpleSecureBrowser>(); // } // // /** // * Gibt den Scraper mit angepassten Context zurück // * // * @param index // * @param context // * @return // */ // public BasicScraper getScraper(int index, Context context) { // if (scrapers.size() > index) { // BasicScraper returnScraper = scrapers.get(index); // if (returnScraper != null) { // // returnScraper.renewContext(context); // return returnScraper; // } // } // return null; // // } // // public void addScraper(BasicScraper scrape) { // scrapers.add(scrape); // } // // public void addBrowser(List<SimpleSecureBrowser> browser) { // if (browser != null) { // this.browser.addAll(browser); // } // } // // public void addBrowser(SimpleSecureBrowser browser) { // if (browser != null) { // this.browser.add(browser); // } // } // // public void dismissDialogs() { // if(browser!=null){ // for(SimpleSecureBrowser singleBrowser: browser) { // if(singleBrowser.dialog!=null) { // singleBrowser.dialog.dismiss(); // singleBrowser.dialog = null; // } // } // } // } // // public void updateBrowser(BrowserAnswerReciever context) { // for (SimpleSecureBrowser singleBrowser : browser) { // singleBrowser.renewContext(context); // singleBrowser.dialog = null; // if (!(singleBrowser.getStatus().equals(AsyncTask.Status.FINISHED))) { // Log.i(TucanMobile.LOG_TAG, // "Configuration Change at unfinished Browser, show Dialog"); // // singleBrowser.showDialog(); // // } // } // } // // }
import android.os.Bundle; import com.dalthed.tucan.Connection.AnswerObject; import com.dalthed.tucan.util.ConfigurationChangeStorage;
/** * This file is part of TuCan Mobile. * * TuCan Mobile is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * TuCan Mobile is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TuCan Mobile. If not, see <http://www.gnu.org/licenses/>. */ package com.dalthed.tucan.ui; public class ApplyEvent extends SimpleWebListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* BugSenseHandler.setup(this, "ed5c1682"); String CookieHTTPString = getIntent().getExtras().getString("Cookie"); URLStringtoCall = getIntent().getExtras().getString("URL"); URL URLtoCall; try { URLtoCall = new URL(URLStringtoCall); localCookieManager = new CookieManager(); localCookieManager.generateManagerfromHTTPString( URLtoCall.getHost(), CookieHTTPString); callResultBrowser = new SimpleSecureBrowser(this); RequestObject thisRequest = new RequestObject(URLStringtoCall, localCookieManager, RequestObject.METHOD_GET, ""); callResultBrowser.execute(thisRequest); } catch (MalformedURLException e) { Log.e(LOG_TAG, e.getMessage()); }*/ }
// Path: app/src/main/java/com/dalthed/tucan/Connection/AnswerObject.java // public class AnswerObject { // private String HTML_text; // private String redirectURL; // private String lastcalledURL; // private CookieManager Cookies; // /** // * RückgabeObjekt der BrowseMethods // * @param HTML HTML-Code // * @param redirect Redirect-URL aus dem HTTP-Header // * @param myCookies CookieManager mit relevanten Cookies // * @param lastcalledURL Zuletzt aufgerufene URL // */ // public AnswerObject(String HTML,String redirect,CookieManager myCookies,String lastcalledURL){ // this.HTML_text=HTML; // this.redirectURL=redirect; // this.Cookies=myCookies; // this.lastcalledURL=lastcalledURL; // } // public String getHTML(){ // return this.HTML_text; // } // public String getRedirectURLString() { // return this.redirectURL; // } // public String getLastCalledURL() { // return this.lastcalledURL; // } // public CookieManager getCookieManager() { // return this.Cookies; // } // // } // // Path: app/src/main/java/com/dalthed/tucan/util/ConfigurationChangeStorage.java // public class ConfigurationChangeStorage { // // private ArrayList<BasicScraper> scrapers; // private ArrayList<SimpleSecureBrowser> browser; // public ArrayList<ListAdapter> adapters; // // public int mode; // // public ConfigurationChangeStorage() { // scrapers = new ArrayList<BasicScraper>(); // adapters = new ArrayList<ListAdapter>(); // browser = new ArrayList<SimpleSecureBrowser>(); // } // // /** // * Gibt den Scraper mit angepassten Context zurück // * // * @param index // * @param context // * @return // */ // public BasicScraper getScraper(int index, Context context) { // if (scrapers.size() > index) { // BasicScraper returnScraper = scrapers.get(index); // if (returnScraper != null) { // // returnScraper.renewContext(context); // return returnScraper; // } // } // return null; // // } // // public void addScraper(BasicScraper scrape) { // scrapers.add(scrape); // } // // public void addBrowser(List<SimpleSecureBrowser> browser) { // if (browser != null) { // this.browser.addAll(browser); // } // } // // public void addBrowser(SimpleSecureBrowser browser) { // if (browser != null) { // this.browser.add(browser); // } // } // // public void dismissDialogs() { // if(browser!=null){ // for(SimpleSecureBrowser singleBrowser: browser) { // if(singleBrowser.dialog!=null) { // singleBrowser.dialog.dismiss(); // singleBrowser.dialog = null; // } // } // } // } // // public void updateBrowser(BrowserAnswerReciever context) { // for (SimpleSecureBrowser singleBrowser : browser) { // singleBrowser.renewContext(context); // singleBrowser.dialog = null; // if (!(singleBrowser.getStatus().equals(AsyncTask.Status.FINISHED))) { // Log.i(TucanMobile.LOG_TAG, // "Configuration Change at unfinished Browser, show Dialog"); // // singleBrowser.showDialog(); // // } // } // } // // } // Path: app/src/main/java/com/dalthed/tucan/ui/ApplyEvent.java import android.os.Bundle; import com.dalthed.tucan.Connection.AnswerObject; import com.dalthed.tucan.util.ConfigurationChangeStorage; /** * This file is part of TuCan Mobile. * * TuCan Mobile is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * TuCan Mobile is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TuCan Mobile. If not, see <http://www.gnu.org/licenses/>. */ package com.dalthed.tucan.ui; public class ApplyEvent extends SimpleWebListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* BugSenseHandler.setup(this, "ed5c1682"); String CookieHTTPString = getIntent().getExtras().getString("Cookie"); URLStringtoCall = getIntent().getExtras().getString("URL"); URL URLtoCall; try { URLtoCall = new URL(URLStringtoCall); localCookieManager = new CookieManager(); localCookieManager.generateManagerfromHTTPString( URLtoCall.getHost(), CookieHTTPString); callResultBrowser = new SimpleSecureBrowser(this); RequestObject thisRequest = new RequestObject(URLStringtoCall, localCookieManager, RequestObject.METHOD_GET, ""); callResultBrowser.execute(thisRequest); } catch (MalformedURLException e) { Log.e(LOG_TAG, e.getMessage()); }*/ }
public void onPostExecute(AnswerObject result) {