/** * Create a proxy object that filter object fields according to set of fields. * If a field is not specified in the set, the get method will return null. * (Primitive returned type cannot be filtered) * The filter is done recursively on sub items. * @param data the object to filter * @param fields list of fields to pass through. */ public Object createFilteredBean(Object data, Set<String> fields) { return createFilteredBean(data, fields, ""); }
/** * Create a proxy object that filter object fields according to set of fields. * If a field is not specified in the set, the get method will return null. * (Primitive returned type cannot be filtered) * The filter is done recursively on sub items. * @param data the object to filter * @param fields list of fields to pass through. */ public Object createFilteredBean(Object data, Set<String> fields) { return createFilteredBean(data, fields, ""); }
private GadgetsHandlerApi.MetadataResponse createMetadataResponse( Uri url, GadgetSpec spec, String iframeUrl, Set<String> fields) { return (GadgetsHandlerApi.MetadataResponse) beanFilter.createFilteredBean( beanDelegator.createDelegator(spec, GadgetsHandlerApi.MetadataResponse.class, ImmutableMap.<String, Object>of( "url", url, "error", BeanDelegator.NULL, "iframeurl", BeanDelegator.nullable(iframeUrl))), fields); }
private GadgetsHandlerApi.TokenResponse createTokenResponse( Uri url, String token, Set<String> fields) { return (GadgetsHandlerApi.TokenResponse) beanFilter.createFilteredBean( beanDelegator.createDelegator("empty", GadgetsHandlerApi.TokenResponse.class, ImmutableMap.<String, Object>of("url", url, "error", BeanDelegator.NULL, "token", BeanDelegator.nullable(token))), fields); } }
private GadgetsHandlerApi.TokenResponse createTokenResponse( Uri url, String token, Set<String> fields) { return (GadgetsHandlerApi.TokenResponse) beanFilter.createFilteredBean( beanDelegator.createDelegator("empty", GadgetsHandlerApi.TokenResponse.class, ImmutableMap.<String, Object>of("url", url, "error", BeanDelegator.NULL, "token", BeanDelegator.nullable(token))), fields); } }
private GadgetsHandlerApi.MetadataResponse createMetadataResponse( Uri url, GadgetSpec spec, String iframeUrl, Boolean needsTokenRefresh, Set<String> fields) { return (GadgetsHandlerApi.MetadataResponse) beanFilter.createFilteredBean( beanDelegator.createDelegator(spec, GadgetsHandlerApi.MetadataResponse.class, ImmutableMap.<String, Object>of( "url", url, "error", BeanDelegator.NULL, "iframeurl", BeanDelegator.nullable(iframeUrl), "needstokenrefresh", BeanDelegator.nullable(needsTokenRefresh))), fields); }
@Test public void testSimple() throws Exception { String data = "data"; String newData = (String) beanFilter.createFilteredBean(data, null); assertSame(data, newData); }
@Test public void testSimple() throws Exception { String data = "data"; String newData = (String) beanFilter.createFilteredBean(data, null); assertSame(data, newData); }
@Test public void testSimple() throws Exception { String data = "data"; String newData = (String) beanFilter.createFilteredBean(data, null); assertSame(data, newData); }
@Test public void testSimple() throws Exception { String data = "data"; String newData = (String) beanFilter.createFilteredBean(data, null); assertSame(data, newData); }
@Test public void testList() throws Exception { SimpleBean data = new SimpleBean().setList(ImmutableList.<String>of("d1", "d2")); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals(null, newData.getList()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("list")); assertArrayEquals(data.getList().toArray(), newData.getList().toArray()); }
@Test public void testList() throws Exception { SimpleBean data = new SimpleBean().setList(ImmutableList.<String>of("d1", "d2")); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals(null, newData.getList()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("list")); assertArrayEquals(data.getList().toArray(), newData.getList().toArray()); }
@Test public void testList() throws Exception { SimpleBean data = new SimpleBean().setList(ImmutableList.<String>of("d1", "d2")); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals(null, newData.getList()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("list")); assertArrayEquals(data.getList().toArray(), newData.getList().toArray()); }
@Test public void testList() throws Exception { SimpleBean data = new SimpleBean().setList(ImmutableList.<String>of("d1", "d2")); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals(null, newData.getList()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("list")); assertArrayEquals(data.getList().toArray(), newData.getList().toArray()); }
@Test public void testInt() throws Exception { SimpleBean data = new SimpleBean().setI(5); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("i")); assertEquals(5, newData.getI()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); // Filter is ignored for primitive types: assertEquals(5, newData.getI()); }
@Test public void testInt() throws Exception { SimpleBean data = new SimpleBean().setI(5); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("i")); assertEquals(5, newData.getI()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); // Filter is ignored for primitive types: assertEquals(5, newData.getI()); }
@Test public void testString() throws Exception { SimpleBean data = new SimpleBean().setS("data"); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals("data", newData.getS()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("i")); assertNull("S is filtered out", newData.getS()); assertNotNull("Required field", newData.getRequired()); }
@Test public void testString() throws Exception { SimpleBean data = new SimpleBean().setS("data"); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals("data", newData.getS()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("i")); assertNull("S is filtered out", newData.getS()); assertNotNull("Required field", newData.getRequired()); }
@Test public void testString() throws Exception { SimpleBean data = new SimpleBean().setS("data"); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals("data", newData.getS()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("i")); assertNull("S is filtered out", newData.getS()); assertNotNull("Required field", newData.getRequired()); }
@Test public void testString() throws Exception { SimpleBean data = new SimpleBean().setS("data"); SimpleBeanInterface dataBean = (SimpleBeanInterface) beanDelegator.createDelegator(data); SimpleBeanInterface newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("s")); assertEquals("data", newData.getS()); newData = (SimpleBeanInterface) beanFilter.createFilteredBean( dataBean, ImmutableSet.<String>of("i")); assertNull("S is filtered out", newData.getS()); assertNotNull("Required field", newData.getRequired()); }