src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
---|---|
OutputPort extends AbstractFileAnalyzer { @Override public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) { final List<ConnectionStatus> connections = context.findConnectionTo(event.getComponentId()); if (connections == null || connections.isEmpty()) { logger.warn("Connection was not found: {}", new Object[]{event}); return null; } String componentName = context.lookupOutputPortName(event.getComponentId()); final Referenceable ref = new Referenceable(TYPE_NIFI_OUTPUT_PORT); ref.set(ATTR_NAME, componentName); ref.set(ATTR_DESCRIPTION, "OutputPort -> " + event.getAttribute("filename")); ref.set(ATTR_QUALIFIED_NAME, event.getFlowFileUuid()); final ProvenanceEventRecord previousEvent = findPreviousProvenanceEvent(context, event); if (previousEvent == null) { logger.warn("Previous event was not found: {}", new Object[]{event}); return null; } final DataSetRefs refs = new DataSetRefs(previousEvent.getComponentId()); refs.addOutput(ref); return refs; } @Override DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event); @Override String targetComponentTypePattern(); } | @Test public void testOutputPort() { final String processorName = "Output Port"; ConnectionStatus con1 = Mockito.mock(ConnectionStatus.class); when(con1.getSourceId()).thenReturn("101"); List<ConnectionStatus> connectionStatuses = new ArrayList<>(); connectionStatuses.add(con1); final ProvenanceEventRecord sendEvent = Mockito.mock(ProvenanceEventRecord.class); when(sendEvent.getEventId()).thenReturn(456L); when(sendEvent.getComponentId()).thenReturn("processor-guid"); when(sendEvent.getComponentType()).thenReturn("PutFile"); when(sendEvent.getEventType()).thenReturn(ProvenanceEventType.SEND); final String componentId = "100"; final String transitUri = "nifi: final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class); when(record.getEventId()).thenReturn(123L); when(record.getComponentType()).thenReturn(processorName); when(record.getTransitUri()).thenReturn(transitUri); when(record.getComponentId()).thenReturn(componentId); when(record.getFlowFileUuid()).thenReturn("1-2-3-4"); when(record.getEventType()).thenReturn(ProvenanceEventType.SEND); final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class); when(clusterResolvers.fromHostname(matches(".+\\.example\\.com"))).thenReturn("cluster1"); final AnalysisContext context = Mockito.mock(AnalysisContext.class); when(context.getClusterResolver()).thenReturn(clusterResolvers); when(context.lookupOutputPortName(componentId)).thenReturn("OUT_PORT"); when(context.findConnectionTo(componentId)).thenReturn(connectionStatuses); when(context.getProvenanceEvent(eq(456L))).thenReturn(sendEvent); final ComputeLineageResult lineage = Mockito.mock(ComputeLineageResult.class); when(context.queryLineage(eq(123L))).thenReturn(lineage); final LineageNode sendEventNode = createLineageNode(PROVENANCE_EVENT_NODE, "123"); final LineageNode flowFileNode = createLineageNode(FLOWFILE_NODE, "flowfile-uuid-1234"); final LineageNode createEventNode = createLineageNode(PROVENANCE_EVENT_NODE, "456"); final List<LineageEdge> edges = new ArrayList<>(); edges.add(createLineageEdge(createEventNode, flowFileNode)); edges.add(createLineageEdge(flowFileNode, sendEventNode)); when(lineage.getEdges()).thenReturn(edges); final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, transitUri, record.getEventType()); assertNotNull(analyzer); final DataSetRefs refs = analyzer.analyze(context, record); assertEquals(1, refs.getComponentIds().size()); assertEquals("processor-guid", refs.getComponentIds().iterator().next()); assertEquals(0, refs.getInputs().size()); assertEquals(1, refs.getOutputs().size()); Referenceable ref = refs.getOutputs().iterator().next(); assertEquals("nifi_output_port", ref.getTypeName()); assertEquals("OUT_PORT", ref.get(ATTR_NAME)); assertEquals("1-2-3-4", ref.get(ATTR_QUALIFIED_NAME)); } |
NiFiRemotePort extends AbstractNiFiProvenanceEventAnalyzer { @Override public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) { final boolean isRemoteInputPort = event.getComponentType().equals("Remote Input Port"); final String type = isRemoteInputPort ? TYPE_NIFI_INPUT_PORT : TYPE_NIFI_OUTPUT_PORT; final String remotePortId = event.getComponentId(); final List<ConnectionStatus> connections = isRemoteInputPort ? context.findConnectionTo(remotePortId) : context.findConnectionFrom(remotePortId); if (connections == null || connections.isEmpty()) { logger.warn("Connection was not found: {}", new Object[]{event}); return null; } final DataSetRefs refs; if (isRemoteInputPort) { final ConnectionStatus connection = connections.get(0); final Referenceable ref = new Referenceable(type); ref.set(ATTR_NAME, isRemoteInputPort ? connection.getDestinationName() : connection.getSourceName()); ref.set(ATTR_QUALIFIED_NAME, event.getFlowFileUuid()); final ProvenanceEventRecord previousEvent = findPreviousProvenanceEvent(context, event); if (previousEvent == null) { logger.warn("Previous event was not found: {}", new Object[]{event}); return null; } refs = new DataSetRefs(previousEvent.getComponentId()); refs.addOutput(ref); } else { String sourceFlowFileUuid = event.getSourceSystemFlowFileIdentifier().substring("urn:nifi:".length()); String componentName = context.lookupOutputPortName(event.getComponentId()); final Referenceable ref = new Referenceable(TYPE_NIFI_OUTPUT_PORT); ref.set(ATTR_NAME, componentName); ref.set(ATTR_QUALIFIED_NAME, sourceFlowFileUuid); final Set<String> connectedComponentIds = connections.stream() .map(c -> c.getDestinationId()).collect(Collectors.toSet()); refs = new DataSetRefs(connectedComponentIds); refs.addInput(ref); } return refs; } @Override DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event); @Override String targetComponentTypePattern(); } | @Test public void testRemoteInputPort() { final String componentType = "Remote Input Port"; final String transitUri = "http: final ProvenanceEventRecord sendEvent = Mockito.mock(ProvenanceEventRecord.class); when(sendEvent.getEventId()).thenReturn(123L); when(sendEvent.getComponentId()).thenReturn("port-guid"); when(sendEvent.getFlowFileUuid()).thenReturn("file-guid"); when(sendEvent.getComponentType()).thenReturn(componentType); when(sendEvent.getTransitUri()).thenReturn(transitUri); when(sendEvent.getEventType()).thenReturn(ProvenanceEventType.SEND); final ProvenanceEventRecord createEvent = Mockito.mock(ProvenanceEventRecord.class); when(createEvent.getEventId()).thenReturn(456L); when(createEvent.getComponentId()).thenReturn("processor-guid"); when(createEvent.getComponentType()).thenReturn("GenerateFlowFile"); when(createEvent.getEventType()).thenReturn(ProvenanceEventType.CREATE); final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class); when(clusterResolvers.fromHostname(matches(".+\\.example\\.com"))).thenReturn("cluster1"); final List<ConnectionStatus> connections = new ArrayList<>(); final ConnectionStatus connection = new ConnectionStatus(); connection.setDestinationId("port-guid"); connection.setDestinationName("inputPortA"); connections.add(connection); final AnalysisContext context = Mockito.mock(AnalysisContext.class); when(context.getClusterResolver()).thenReturn(clusterResolvers); when(context.findConnectionTo(matches("port-guid"))).thenReturn(connections); when(context.getProvenanceEvent(eq(456L))).thenReturn(createEvent); final ComputeLineageResult lineage = Mockito.mock(ComputeLineageResult.class); when(context.queryLineage(eq(123L))).thenReturn(lineage); final LineageNode sendEventNode = createLineageNode(PROVENANCE_EVENT_NODE, "123"); final LineageNode flowFileNode = createLineageNode(FLOWFILE_NODE, "flowfile-uuid-1234"); final LineageNode createEventNode = createLineageNode(PROVENANCE_EVENT_NODE, "456"); final List<LineageEdge> edges = new ArrayList<>(); edges.add(createLineageEdge(createEventNode, flowFileNode)); edges.add(createLineageEdge(flowFileNode, sendEventNode)); when(lineage.getEdges()).thenReturn(edges); final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, transitUri, sendEvent.getEventType()); assertNotNull(analyzer); final DataSetRefs refs = analyzer.analyze(context, sendEvent); assertEquals(0, refs.getInputs().size()); assertEquals(1, refs.getOutputs().size()); assertEquals(1, refs.getComponentIds().size()); assertTrue(refs.getComponentIds().contains("processor-guid")); Referenceable ref = refs.getOutputs().iterator().next(); assertEquals(TYPE_NIFI_INPUT_PORT, ref.getTypeName()); assertEquals("inputPortA", ref.get(ATTR_NAME)); assertEquals("file-guid", ref.get(ATTR_QUALIFIED_NAME)); }
@Test public void testRemoteOutputPort() { final String componentType = "Remote Output Port"; final String transitUri = "http: final String sourceSystemFlowFileIdentifier = "urn:nifi:7ce27bc3-b128-4128-aba2-3a366435fd05"; final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class); when(record.getComponentId()).thenReturn("port-guid"); when(record.getComponentType()).thenReturn(componentType); when(record.getTransitUri()).thenReturn(transitUri); when(record.getFlowFileUuid()).thenReturn("file-guid"); when(record.getSourceSystemFlowFileIdentifier()).thenReturn(sourceSystemFlowFileIdentifier); when(record.getEventType()).thenReturn(ProvenanceEventType.RECEIVE); final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class); when(clusterResolvers.fromHostname(matches(".+\\.example\\.com"))).thenReturn("cluster1"); final List<ConnectionStatus> connections = new ArrayList<>(); final ConnectionStatus connection = new ConnectionStatus(); connection.setSourceId("port-guid"); connection.setSourceName("outputPortA"); connections.add(connection); final AnalysisContext context = Mockito.mock(AnalysisContext.class); when(context.getClusterResolver()).thenReturn(clusterResolvers); when(context.findConnectionFrom(matches("port-guid"))).thenReturn(connections); when(context.lookupOutputPortName("port-guid")).thenReturn("outputPortA"); final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, transitUri, record.getEventType()); assertNotNull(analyzer); final DataSetRefs refs = analyzer.analyze(context, record); assertEquals(1, refs.getInputs().size()); assertEquals(0, refs.getOutputs().size()); Referenceable ref = refs.getInputs().iterator().next(); assertEquals(TYPE_NIFI_OUTPUT_PORT, ref.getTypeName()); assertEquals("outputPortA", ref.get(ATTR_NAME)); assertEquals("7ce27bc3-b128-4128-aba2-3a366435fd05", ref.get(ATTR_QUALIFIED_NAME)); } |
Stats { @GET @Produces(MediaType.APPLICATION_JSON) public String getStats() { StatsManager statsManager = this.statsManager; if (this.statsManager != null) { return JSONSerializer.serializeStatistics(statsManager.getStatistics()).toJSONString(); } return new JSONObject().toJSONString(); } @GET @Produces(MediaType.APPLICATION_JSON) String getStats(); } | @Test public void testGetStats() throws ParseException { Map<String, Object> fakeStats = new HashMap<>(); fakeStats.put("stat1", "value1"); fakeStats.put("stat2", "value2"); VideobridgeStatistics videobridgeStatistics = mock(VideobridgeStatistics.class); when(videobridgeStatistics.getStats()).thenReturn(fakeStats); when(statsManager.getStatistics()).thenReturn(videobridgeStatistics); Response resp = target(BASE_URL).request().get(); assertEquals(HttpStatus.OK_200, resp.getStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType()); JSONObject json = getJsonResult(resp); assertEquals("value1", json.get("stat1")); assertEquals("value2", json.get("stat2")); } |
SymbolTable { static List<GrainProperty> collectDeclaredProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); LateParameterizedType lpt = asLateParameterizedType(type); Class<?> clazz = erase(type); BeanInfo bi = Introspector.getBeanInfo(clazz); for (PropertyDescriptor pd : bi.getPropertyDescriptors()) { if (pd instanceof IndexedPropertyDescriptor) { continue; } Method getter = pd.getReadMethod(); if (getter == null || getter.getDeclaringClass() != clazz) { continue; } Type returnType = getter.getGenericReturnType(); if (lpt != null) { returnType = lpt.resolve(returnType); } results.add(new SimpleGrainProperty(pd.getName(), returnType, flagsFor(pd))); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | @Test public void test_collectDeclaredProperties_one_level_only() throws IntrospectionException { List<GrainProperty> result; result = collectDeclaredProperties(Organism.class); assertEquals(1, result.size()); assertEquals("id", result.get(0).getName()); assertEquals(int.class, result.get(0).getType()); assertTrue(result.get(0).getFlags().isEmpty()); result = collectDeclaredProperties(Animal.class); assertEquals(1, result.size()); assertEquals("vertebrate", result.get(0).getName()); assertEquals(boolean.class, result.get(0).getType()); assertEquals(GrainProperty.Flag.IS_PROPERTY, result.get(0).getFlags().iterator().next()); }
@Test public void test_collectDeclaredProperties_of_generic_type() throws IntrospectionException { List<GrainProperty> result; result = collectDeclaredProperties(Descendant.class); assertEquals(1, result.size()); assertEquals("parent", result.get(0).getName()); assertEquals(new LateTypeVariable<>("T", Descendant.class), result.get(0).getType()); assertTrue(result.get(0).getFlags().isEmpty()); result = collectDeclaredProperties(new TypeToken<Descendant<String>>(){}.asType()); assertEquals(1, result.size()); assertEquals("parent", result.get(0).getName()); assertEquals(String.class, result.get(0).getType()); assertTrue(result.get(0).getFlags().isEmpty()); } |
BasicList1 extends BasicConstList<E> { @Override public ConstList<E> delete(int index) { if (index == 0) { return emptyList(); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | @Test public void test_delete() { compare_lists(Collections.emptyList(), new BasicList1<>(1).delete(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_delete_out_of_bounds() { new BasicList1<>(1).delete(1); } |
BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withoutAll(Collection<?> c) { return !c.contains(e0) ? this : BasicCollections.<E>emptyList(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstList<Integer> list = new BasicList1<>(1); assertSame(BasicList0.instance(), list.withoutAll(Arrays.asList(1))); assertSame(BasicList0.instance(), list.withoutAll(Arrays.asList(2, 1))); assertSame(list, list.withoutAll(Arrays.asList(2))); assertSame(list, list.withoutAll(Arrays.asList())); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicList1<>(1).withoutAll(null); } |
BasicList1 extends BasicConstList<E> { @Override public ConstList<E> subList(int fromIndex, int toIndex) { ArrayTools.checkRange(fromIndex, toIndex, 1); return fromIndex != toIndex ? this : BasicCollections.<E>emptyList(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | @Test public void test_subList() { ConstList<Integer> list = new BasicList1<>(1); assertSame(BasicList0.instance(), list.subList(0, 0)); assertSame(list, list.subList(0, 1)); assertSame(BasicList0.instance(), list.subList(1, 1)); } |
BasicList1 extends BasicConstList<E> { private boolean equals(List<?> that) { if (that.size() == 1) { Object o; try { o = that.get(0); } catch (IndexOutOfBoundsException e) { return false; } return Objects.equals(o, e0); } return false; } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | @Test public void test_non_equality() { assertFalse(new BasicList1<>(1).equals(Arrays.asList(2))); assertFalse(Arrays.asList(2).equals(new BasicList1<>(1))); ConstList<Integer> empty = BasicList0.instance(); assertFalse(new BasicList1<>(1).equals(empty)); } |
BasicMap1 extends BasicConstMap<K, V> { @Override public ConstMap<K, V> with(K key, V value) { if (Objects.equals(key, k0)) { if (Objects.equals(value, v0)) { return this; } return new BasicMap1<>(k0, value); } return new BasicMapN<>(new Object[] {k0, key}, new Object[] {v0, value}); } @SuppressWarnings("unchecked") BasicMap1(Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override int hashCode(); } | @Test public void test_with() { ConstMap<Object, Object> map; map = new BasicMap1<>("a", 1); compare_maps(newMap("a", 1, "b", 2), map.with("b", 2)); compare_maps(newMap("a", 2), map.with("a", 2)); compare_maps(newMap("a", 1, null, null), map.with(null, null)); compare_maps(newMap("a", null), map.with("a", null)); assertSame(map, map.with("a", 1)); map = new BasicMap1<>(null, null); assertSame(map, map.with(null, null)); } |
BasicMap1 extends BasicConstMap<K, V> { @Override public ConstMap<K, V> withAll(Map<? extends K, ? extends V> map) { if (map.isEmpty()) { return this; } MapColumns mc = copy(map); return condenseToMap(unionInto(new Object[] {k0}, new Object[] {v0}, mc.keys, mc.values)); } @SuppressWarnings("unchecked") BasicMap1(Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override int hashCode(); } | @Test public void test_withAll() { ConstMap<Object, Object> map = new BasicMap1<>("a", 1); compare_maps(newMap("a", 2, "b", 2, "c", 3), map.withAll(newMap("b", 2, "c", 3, "a", 2))); compare_maps(map, map.withAll(newMap("a", 1))); assertSame(map, map.withAll(newMap())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicMap1<>("a", 1).withAll(null); } |
BasicMap1 extends BasicConstMap<K, V> { @Override public ConstMap<K, V> without(Object key) { return !containsKey(key) ? this : BasicCollections.<K, V>emptyMap(); } @SuppressWarnings("unchecked") BasicMap1(Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override int hashCode(); } | @Test public void test_without() { ConstMap<Object, Object> map = new BasicMap1<>("a", 1); assertSame(BasicMap0.instance(), map.without("a")); assertSame(map, map.without("b")); assertSame(map, map.without(null)); } |
Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } | @Test public void test_immutify_grain() { assertSame(Grain.class, immutify(Grain.class)); assertSame(PartGrain.class, immutify(Compound.Part.class)); assertSame(PartGrain.class, immutify(PartGrain.class)); assertEquals("interface net.nullschool.grains.generate.FooGrain", immutify(Foo.class).toString()); }
@Test public void test_grain_array_not_immutable() { try { immutify(PartGrain[].class); fail(); } catch (IllegalArgumentException expected) {} }
@Test public void test_immutify_generic_types() { assertEquals( new TypeToken<ConstCollection<Integer>>(){}.asType(), immutify(new TypeToken<Collection<Integer>>(){}.asType())); assertEquals( new TypeToken<ConstList<Integer>>(){}.asType(), immutify(new TypeToken<List<Integer>>(){}.asType())); assertEquals( new TypeToken<ConstSet<Integer>>(){}.asType(), immutify(new TypeToken<Set<Integer>>(){}.asType())); assertEquals( new TypeToken<ConstMap<String, UUID>>(){}.asType(), immutify(new TypeToken<Map<String, UUID>>(){}.asType())); assertEquals( new TypeToken<ConstList<ConstList<Integer>>>(){}.asType(), immutify(new TypeToken<List<List<Integer>>>(){}.asType())); assertEquals( new TypeToken<ConstMap<ConstList<UUID>, ConstSet<PartGrain>>>(){}.asType(), immutify(new TypeToken<Map<List<UUID>, Set<Compound.Part>>>(){}.asType())); assertEquals( new TypeToken<ConstList<? extends Integer>>(){}.asType(), immutify(new TypeToken<List<? extends Integer>>(){}.asType())); assertEquals( new TypeToken<ConstList<? extends ConstList<? extends Integer>>>(){}.asType(), immutify(new TypeToken<List<? extends List<? extends Integer>>>(){}.asType())); assertEquals( new TypeToken<ConstMap<? extends ConstList<? extends UUID>, ConstSet<? extends PartGrain>>>(){}.asType(), immutify(new TypeToken<Map<? extends List<? extends UUID>, Set<? extends Compound.Part>>>(){}.asType())); assertEquals( new TypeToken<ConstList<Integer>>(){}.asType(), immutify(new TypeToken<ConstList<Integer>>(){}.asType())); assertEquals( new TypeToken<ConstList<ConstList<Integer>>>(){}.asType(), immutify(new TypeToken<ConstList<ConstList<Integer>>>(){}.asType())); assertEquals( new TypeToken<NestedMap<String, Integer>>(){}.asType(), immutify(new TypeToken<NestedMap<String, Integer>>(){}.asType())); assertEquals( new TypeToken<ComplexMap<? extends Grain, ? extends Grain>>(){}.asType(), immutify(ComplexMap.class)); }
@Test public void test_immutify_fails_on_non_immutable_types() { try { immutify(Object.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(Number.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(String[].class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(List.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(Date.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(ConstCollection.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(ConstList.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(ConstSet.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(ConstMap.class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<Object>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<List>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<ConstList>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<ConstList<ConstList>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<?>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<? extends Number>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<? extends ConstList>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<? super Integer>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<? extends List<? super Integer>>>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} try { immutify(new TypeToken<List<Integer>[]>(){}.asType()); fail(); } catch (IllegalArgumentException expected) {} }
@Test public void test_immutify_known_immutable_types() { assertSame(boolean.class, immutify(boolean.class)); assertSame(byte.class, immutify(byte.class)); assertSame(short.class, immutify(short.class)); assertSame(int.class, immutify(int.class)); assertSame(long.class, immutify(long.class)); assertSame(float.class, immutify(float.class)); assertSame(double.class, immutify(double.class)); assertSame(char.class, immutify(char.class)); assertSame(Boolean.class, immutify(Boolean.class)); assertSame(Byte.class, immutify(Byte.class)); assertSame(Short.class, immutify(Short.class)); assertSame(Integer.class, immutify(Integer.class)); assertSame(Long.class, immutify(Long.class)); assertSame(BigInteger.class, immutify(BigInteger.class)); assertSame(BigDecimal.class, immutify(BigDecimal.class)); assertSame(Float.class, immutify(Float.class)); assertSame(Double.class, immutify(Double.class)); assertSame(Character.class, immutify(Character.class)); assertSame(String.class, immutify(String.class)); }
@Test public void test_arrays_not_immutable() { try { immutify(char[].class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(String[].class); fail(); } catch (IllegalArgumentException expected) {} }
@Test public void test_immutify_enum() { assertEquals(new TypeToken<Enum>(){}.asType(), immutify(Enum.class)); assertSame(Color.class, immutify(Color.class)); } |
BasicMap1 extends BasicConstMap<K, V> { @Override public ConstMap<K, V> withoutAll(Collection<?> keys) { return !keys.contains(k0) ? this : BasicCollections.<K, V>emptyMap(); } @SuppressWarnings("unchecked") BasicMap1(Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstMap<Object, Object> map = new BasicMap1<>("a", 1); assertSame(BasicMap0.instance(), map.withoutAll(Arrays.asList("a"))); assertSame(BasicMap0.instance(), map.withoutAll(Arrays.asList("b", "a", "b", "a"))); assertSame(map, map.withoutAll(Arrays.asList("b"))); assertSame(map, map.withoutAll(Arrays.asList())); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicMap1<>("a", 1).withoutAll(null); } |
BasicMap1 extends BasicConstMap<K, V> { @Override K getKey(int index) { if (index == 0) { return k0; } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicMap1(Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override int hashCode(); } | @Test public void test_get_key() { assertEquals("a", new BasicMap1<>("a", 1).getKey(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_key() { new BasicMap1<>("a", 1).getKey(1); } |
BasicMap1 extends BasicConstMap<K, V> { @Override V getValue(int index) { if (index == 0) { return v0; } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicMap1(Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override int hashCode(); } | @Test public void test_get_value() { assertEquals(1, new BasicMap1<>("a", 1).getValue(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_value() { new BasicMap1<>("a", 1).getValue(1); } |
BasicConstSortedSet extends BasicConstSet<E> implements ConstSortedSet<E> { @Override public Comparator<? super E> comparator() { return comparator; } BasicConstSortedSet(Comparator<? super E> comparator); @Override Comparator<? super E> comparator(); } | @Test public void test_emptySortedSet() { assertSame(BasicSortedSet0.instance(null), emptySortedSet(null)); Comparator<Object> reverse = reverseOrder(); assertSame(BasicSortedSet0.instance(reverse).comparator(), emptySortedSet(reverse).comparator()); } |
BasicSortedSet1 extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> with(E e) { int cmp = compare(e, e0); return cmp == 0 ? this : cmp < 0 ? new BasicSortedSetN<>(comparator, new Object[] {e, e0}) : new BasicSortedSetN<>(comparator, new Object[] {e0, e}); } @SuppressWarnings("unchecked") BasicSortedSet1(Comparator<? super E> comparator, Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_with() { ConstSortedSet<Integer> set; set = new BasicSortedSet1<>(null, 1); compare_sorted_sets(newSortedSet(null, 1, 2), set.with(2)); assertSame(set, set.with(1)); set = new BasicSortedSet1<>(reverseOrder(), 1); compare_sorted_sets(newSortedSet(reverseOrder(), 2, 1), set.with(2)); assertSame(set, set.with(1)); } |
BasicSortedSet1 extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> withAll(Collection<? extends E> c) { if (c.isEmpty()) { return this; } Object[] expanded = unionInto(new Object[] {e0}, c.toArray(), comparator); return expanded.length == size() ? this : condenseToSortedSet(comparator, expanded); } @SuppressWarnings("unchecked") BasicSortedSet1(Comparator<? super E> comparator, Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_withAll() { ConstSortedSet<Integer> set; set = new BasicSortedSet1<>(null, 1); compare_sorted_sets(newSortedSet(null, 1, 2, 3), set.withAll(Arrays.asList(1, 2, 3, 3, 2, 1))); assertSame(set, set.withAll(Arrays.asList(1, 1, 1, 1, 1, 1))); assertSame(set, set.withAll(Collections.<Integer>emptyList())); set = new BasicSortedSet1<>(reverseOrder(), 1); compare_sorted_sets(newSortedSet(reverseOrder(), 3, 2, 1), set.withAll(Arrays.asList(1, 2, 3, 3, 2, 1))); assertSame(set, set.withAll(Arrays.asList(1, 1, 1, 1, 1, 1))); assertSame(set, set.withAll(Collections.<Integer>emptyList())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicSortedSet1<>(null, 1).withAll(null); } |
BasicSortedSet1 extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> without(Object o) { return !contains(o) ? this : emptySortedSet(comparator); } @SuppressWarnings("unchecked") BasicSortedSet1(Comparator<? super E> comparator, Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_without() { ConstSortedSet<Integer> set; set = new BasicSortedSet1<>(null, 1); compare_sorted_sets(BasicSortedSet0.instance(null), set.without(1)); assertSame(set, set.without(2)); set = new BasicSortedSet1<>(reverseOrder(), 1); compare_sorted_sets(BasicSortedSet0.instance(reverseOrder()), set.without(1)); assertSame(set, set.without(2)); } |
BasicSortedSet1 extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> withoutAll(Collection<?> c) { return !c.contains(e0) ? this : emptySortedSet(comparator); } @SuppressWarnings("unchecked") BasicSortedSet1(Comparator<? super E> comparator, Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstSortedSet<Integer> set; set = new BasicSortedSet1<>(null, 1); compare_sorted_sets(BasicSortedSet0.instance(null), set.withoutAll(Arrays.asList(1))); compare_sorted_sets(BasicSortedSet0.instance(null), set.withoutAll(Arrays.asList(2, 1))); assertSame(set, set.withoutAll(Arrays.asList(2))); assertSame(set, set.withoutAll(Arrays.asList())); set = new BasicSortedSet1<>(reverseOrder(), 1); compare_sorted_sets(BasicSortedSet0.instance(reverseOrder()), set.withoutAll(Arrays.asList(1))); compare_sorted_sets(BasicSortedSet0.instance(reverseOrder()), set.withoutAll(Arrays.asList(2, 1))); assertSame(set, set.withoutAll(Arrays.asList(2))); assertSame(set, set.withoutAll(Arrays.asList())); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicSortedSet1<>(null, 1).withoutAll(null); } |
BasicSortedSet1 extends BasicConstSortedSet<E> { @Override E get(int index) { if (index == 0) { return e0; } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicSortedSet1(Comparator<? super E> comparator, Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_get() { assertEquals(1, new BasicSortedSet1<>(null, 1).get(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get() { new BasicSortedSet1<>(null, 1).get(1); } |
BasicMapN extends BasicConstMap<K, V> { @Override public ConstMap<K, V> with(K key, V value) { final int index = ArrayTools.indexOf(key, keys); if (index >= 0) { if (Objects.equals(value, values[index])) { return this; } return new BasicMapN<>(keys, replace(values, index, value)); } final int length = keys.length; return new BasicMapN<>(insert(keys, length, key), insert(values, length, value)); } @SuppressWarnings("unchecked") BasicMapN(Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keysToDelete); @Override int hashCode(); } | @Test public void test_with() { ConstMap<Object, Object> map; map = new BasicMapN<>(new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}); compare_maps(newMap("a", 1, "b", 2, "c", 3, "d", 4, "e", 5), map.with("e", 5)); compare_maps(newMap("a", 1, "b", 9, "c", 3, "d", 4), map.with("b", 9)); compare_maps(newMap("a", 1, "b", 2, "c", 3, "d", 4, "e", null), map.with("e", null)); compare_maps(newMap("a", 1, "b", 2, "c", 3, "d", 4, null, 5), map.with(null, 5)); assertSame(map, map.with("b", 2)); map = new BasicMapN<>(new Object[] {"a", "b", "c", null}, new Object[] {1, 2, 3, null}); assertSame(map, map.with(null, null)); } |
BasicMapN extends BasicConstMap<K, V> { @Override public ConstMap<K, V> withAll(Map<? extends K, ? extends V> map) { if (map.isEmpty()) { return this; } MapColumns mc = copy(map); return condenseToMap(unionInto(keys, values, mc.keys, mc.values)); } @SuppressWarnings("unchecked") BasicMapN(Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keysToDelete); @Override int hashCode(); } | @Test public void test_withAll() { ConstMap<Object, Object> map = new BasicMapN<>(new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}); compare_maps( newMap("a", 1, "b", 9, "c", 3, "d", 4, "e", 5, "f", 6), map.withAll(newMap("e", 5, "f", 6, "b", 9))); compare_maps(map, map.withAll(newMap("a", 1, "b", 2))); assertSame(map, map.withAll(newMap())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicMapN<>(new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}).withAll(null); } |
BasicMapN extends BasicConstMap<K, V> { @Override public ConstMap<K, V> without(Object key) { int index = ArrayTools.indexOf(key, keys); return index < 0 ? this : BasicCollections.<K, V>condenseToMap(delete(keys, index), delete(values, index)); } @SuppressWarnings("unchecked") BasicMapN(Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keysToDelete); @Override int hashCode(); } | @Test public void test_without() { ConstMap<Object, Object> map = new BasicMapN<>(new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}); compare_maps(newMap("a", 1, "b", 2, "c", 3), map.without("d")); assertSame(map, map.without("e")); assertSame(map, map.without(null)); } |
BasicMapN extends BasicConstMap<K, V> { @Override public ConstMap<K, V> withoutAll(Collection<?> keysToDelete) { if (keysToDelete.isEmpty()) { return this; } return condenseToMap(deleteAll(keys, values, keysToDelete)); } @SuppressWarnings("unchecked") BasicMapN(Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keysToDelete); @Override int hashCode(); } | @Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicMapN<>(new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}).withoutAll(null); } |
BasicMapN extends BasicConstMap<K, V> { @Override K getKey(int index) { return keys[index]; } @SuppressWarnings("unchecked") BasicMapN(Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keysToDelete); @Override int hashCode(); } | @Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_key() { new BasicMapN<>(new Object[] {"1", "2", "3", "4"}, new Object[] {1, 2, 3, 4}).getKey(5); } |
BasicMapN extends BasicConstMap<K, V> { @Override V getValue(int index) { return values[index]; } @SuppressWarnings("unchecked") BasicMapN(Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keysToDelete); @Override int hashCode(); } | @Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_value() { new BasicMapN<>(new Object[] {"1", "2", "3", "4"}, new Object[] {1, 2, 3, 4}).getValue(5); } |
BasicList0 extends BasicConstList<E> { @SuppressWarnings("unchecked") static <E> BasicList0<E> instance() { return INSTANCE; } private BasicList0(); @Override int size(); @Override boolean isEmpty(); @Override Iterator<E> iterator(); @Override ListIterator<E> listIterator(); @Override ListIterator<E> listIterator(int index); @Override boolean contains(Object o); @Override boolean containsAll(Collection<?> c); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_comparison() { compare_lists(Collections.emptyList(), BasicList0.instance()); }
@Test public void test_immutable() { assert_list_immutable(BasicList0.instance()); }
@Test public void test_serialization() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(BasicList0.instance()); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0&net.nullschool.collect.basic.ListProxy00000001300xpw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); assertSame(BasicList0.instance(), in.readObject()); } |
BasicTools { static Object[] copy(Object[] original) { return Arrays.copyOf(original, original.length, Object[].class); } private BasicTools(); } | @Test public void test_copy_array() { Object[] src = new Object[] {1, 2, 3}; assertArrayEquals(src, copy(src)); assertNotSame(src, copy(src)); assertArrayEquals(EMPTY_OBJECT_ARRAY, copy(EMPTY_OBJECT_ARRAY)); assertArrayEquals(src, copy(new Integer[] {1, 2, 3})); assertEquals(Object[].class, copy(new Integer[] {1, 2, 3}).getClass()); }
@Test(expected = NullPointerException.class) public void test_copy_array_null() { copy((Object[])null); }
@Test public void test_copy_array_length() { Object[] src = new Object[] {1, 2, 3}; assertArrayEquals(src, copy(src, 3)); assertNotSame(src, copy(src, 3)); assertArrayEquals(src, copy(new Integer[] {1, 2, 3}, 3)); assertEquals(Object[].class, copy(new Integer[] {1, 2, 3}, 3).getClass()); assertArrayEquals(new Object[] {}, copy(src, 0)); assertArrayEquals(new Object[] {1, 2}, copy(src, 2)); assertArrayEquals(new Object[] {1, 2, 3, null}, copy(src, 4)); assertArrayEquals(new Object[] {null, null, null}, copy(EMPTY_OBJECT_ARRAY, 3)); }
@Test(expected = NullPointerException.class) public void test_copy_array_length_null() { copy(null, 0); }
@Test(expected = NegativeArraySizeException.class) public void test_copy_array_length_negative_size() { copy(EMPTY_OBJECT_ARRAY, -1); }
@Test public void test_copy_collection() { List<Integer> src = Arrays.asList(1, 2, 3); assertArrayEquals(new Object[] {1, 2, 3}, copy(src)); assertEquals(Object[].class, copy(src).getClass()); }
@Test(expected = NullPointerException.class) public void test_copy_collection_null() { copy((Collection<?>)null); }
@Test public void test_copy_iterator() { final int[] items = new int[] {1, 2, 3}; Iterator<Integer> iter = new Iterator<Integer>() { int i = 0; @Override public boolean hasNext() { return i < items.length; } @Override public Integer next() { return items[i++]; } @Override public void remove() { throw new UnsupportedOperationException(); } }; Object[] result = copy(iter); assertArrayEquals(new Object[] {1, 2, 3}, result); assertEquals(Object[].class, result.getClass()); }
@Test(expected = NullPointerException.class) public void test_copy_iterator_null() { copy((Iterator<?>)null); }
@Test public void test_copy_map() { Map<?, ?> map = newMap("a", 1, "b", 2, "c", 3); MapColumns mc; mc = copy(map); assertArrayEquals(new Object[] {"a", "b", "c"}, mc.keys); assertArrayEquals(new Object[] {1, 2, 3}, mc.values); assertEquals(Object[].class, mc.keys.getClass()); assertEquals(Object[].class, mc.values.getClass()); mc = copy(Collections.emptyMap()); assertArrayEquals(EMPTY_OBJECT_ARRAY, mc.keys); assertArrayEquals(EMPTY_OBJECT_ARRAY, mc.values); }
@Test public void test_copy_map_lying_about_its_size() { Map<String, Integer> map = new LyingMap<>(); MapColumns mc; map.put("a", 1); assertEquals(2, map.size()); assertEquals("{a=1}", map.toString()); mc = copy(map); assertArrayEquals(new Object[] {"a"}, mc.keys); assertArrayEquals(new Object[] {1}, mc.values); assertEquals(Object[].class, mc.keys.getClass()); assertEquals(Object[].class, mc.values.getClass()); map.put("b", 2); map.put("c", 3); assertEquals(2, map.size()); assertEquals("{a=1, b=2, c=3}", map.toString()); mc = copy(map); assertArrayEquals(new Object[] {"a", "b", "c"}, mc.keys); assertArrayEquals(new Object[] {1, 2, 3}, mc.values); assertEquals(Object[].class, mc.keys.getClass()); assertEquals(Object[].class, mc.values.getClass()); }
@Test(expected = NullPointerException.class) public void test_copy_map_null() { copy((Map)null); } |
BasicTools { static Object[] insert(Object[] original, int index, Object e) { Object[] result = new Object[original.length + 1]; System.arraycopy(original, 0, result, 0, index); result[index] = e; System.arraycopy(original, index, result, index + 1, original.length - index); return result; } private BasicTools(); } | @Test public void test_insert() { Object[] src = new Object[] {1, 2, 3}; assertArrayEquals(new Object[] {4, 1, 2, 3}, insert(src, 0, 4)); assertArrayEquals(new Object[] {1, 4, 2, 3}, insert(src, 1, 4)); assertArrayEquals(new Object[] {1, 2, 4, 3}, insert(src, 2, 4)); assertArrayEquals(new Object[] {1, 2, 3, 4}, insert(src, 3, 4)); assertArrayEquals(new Object[] {"a"}, insert(EMPTY_OBJECT_ARRAY, 0, "a")); assertArrayEquals(new Object[] {null}, insert(EMPTY_OBJECT_ARRAY, 0, null)); }
@Test public void test_insert_result_type_is_object_array() { assertSame(Object[].class, insert(new Integer[] {1, 2, 3}, 3, 4).getClass()); }
@Test(expected = NullPointerException.class) public void test_insert_null() { insert(null, 0, null); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void test_insert_out_of_bounds_low() { insert(EMPTY_OBJECT_ARRAY, -1, "a"); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void test_insert_out_of_bounds_high() { insert(EMPTY_OBJECT_ARRAY, 1, "a"); } |
GrainGenerator implements Callable<Void> { public static void main(String[] args) throws Exception { Thread.currentThread().setName("main"); Configuration config = new Configuration(); config.setOutput(Paths.get(args[0])); config.setSearchPackages(asSet(Arrays.asList(args).subList(1, args.length))); new GrainGenerator(config).call(); Thread.sleep(10); } GrainGenerator(Configuration configuration); @Override Void call(); static void main(String[] args); } | @Ignore @Test public void test_generator_driver() throws Exception { GrainGenerator.main( new String[] { System.getProperty("user.home") + "/code/grains/generate/src/test/java", "net.nullschool.grains.generate.model"}); } |
BasicTools { static Object[] insertAll(Object[] original, int index, Collection<?> c) { final Object[] elements = c.toArray(); Object[] result = new Object[original.length + elements.length]; System.arraycopy(original, 0, result, 0, index); System.arraycopy(elements, 0, result, index, elements.length); System.arraycopy(original, index, result, index + elements.length, original.length - index); return result; } private BasicTools(); } | @Test public void test_insertAll() { Object[] src = new Object[] {1, 2, 3}; List<Integer> extra = Arrays.asList(8, 9); assertArrayEquals(new Object[] {8, 9, 1, 2, 3}, insertAll(src, 0, extra)); assertArrayEquals(new Object[] {1, 8, 9, 2, 3}, insertAll(src, 1, extra)); assertArrayEquals(new Object[] {1, 2, 8, 9, 3}, insertAll(src, 2, extra)); assertArrayEquals(new Object[] {1, 2, 3, 8, 9}, insertAll(src, 3, extra)); assertArrayEquals(new Object[] {1, 2, 3}, insertAll(src, 0, Collections.emptyList())); assertArrayEquals(new Object[] {1, 2, 3}, insertAll(src, 1, Collections.emptyList())); assertArrayEquals(new Object[] {1, 2, 3}, insertAll(src, 2, Collections.emptyList())); assertArrayEquals(new Object[] {1, 2, 3}, insertAll(src, 3, Collections.emptyList())); assertArrayEquals(new Object[] {"a", "b"}, insertAll(EMPTY_OBJECT_ARRAY, 0, Arrays.asList("a", "b"))); assertArrayEquals(new Object[] {null, null}, insertAll(EMPTY_OBJECT_ARRAY, 0, Arrays.asList(null, null))); }
@Test public void test_insertAll_result_type_is_object_array() { assertSame(Object[].class, insertAll(new Integer[] {1, 2, 3}, 3, Arrays.asList(4, 5)).getClass()); }
@Test public void test_insertAll_allocates_new() { Object[] src = new Object[] {1, 2, 3}; assertNotSame(src, insertAll(src, 0, Collections.emptyList())); }
@Test(expected = IndexOutOfBoundsException.class) public void test_insertAll_out_of_bounds_low() { insertAll(EMPTY_OBJECT_ARRAY, -1, Arrays.asList("a")); }
@Test(expected = IndexOutOfBoundsException.class) public void test_insertAll_out_of_bounds_high() { insertAll(EMPTY_OBJECT_ARRAY, 1, Arrays.asList("a")); }
@Test(expected = NullPointerException.class) public void test_insertAll_null() { insertAll(null, 0, Collections.emptyList()); }
@Test(expected = NullPointerException.class) public void test_insertAll_null_collection() { insertAll(EMPTY_OBJECT_ARRAY, 0, null); } |
BasicTools { static Object[] replace(Object[] original, int index, Object e) { Object[] result = copy(original); result[index] = e; return result; } private BasicTools(); } | @Test public void test_replace() { Integer[] src = new Integer[] {1, 2, 3}; assertArrayEquals(new Object[] {9, 2, 3}, replace(src, 0, 9)); assertArrayEquals(new Object[] {1, 9, 3}, replace(src, 1, 9)); assertArrayEquals(new Object[] {1, 2, 9}, replace(src, 2, 9)); assertEquals(Object[].class, replace(src, 0, 1).getClass()); }
@Test(expected = IndexOutOfBoundsException.class) public void test_replace_out_of_bounds_low() { replace(EMPTY_OBJECT_ARRAY, -1, null); }
@Test(expected = IndexOutOfBoundsException.class) public void test_replace_out_of_bounds_high() { replace(EMPTY_OBJECT_ARRAY, 0, null); }
@Test(expected = NullPointerException.class) public void test_replace_null() { replace(null, 0, null); } |
SimpleNameWriter extends TypeWriter { @Override protected TypePrinter apply(Class<?> clazz, Type enclosing) { return printer.print(clazz); } SimpleNameWriter(); } | @Test public void test_parameterized_type() { Type type = new TypeToken<Set<Map.Entry<Map.Entry, Integer>>>(){}.asType(); assertEquals("Set<Map.Entry<Map.Entry, Integer>>", TypeTools.print(type, new SimpleNamePrinter())); assertEquals("Set<Entry<Entry, Integer>>", new SimpleNameWriter().apply(type).toString()); } |
BasicTools { static Object[] delete(Object[] original, int index) { final int resultLength = original.length - 1; Object[] result = new Object[resultLength]; System.arraycopy(original, 0, result, 0, index); System.arraycopy(original, index + 1, result, index, resultLength - index); return result; } private BasicTools(); } | @Test public void test_delete() { Integer[] src = new Integer[] {1, 2, 3, 4}; assertArrayEquals(new Object[] {2, 3, 4}, delete(src, 0)); assertArrayEquals(new Object[] {1, 3, 4}, delete(src, 1)); assertArrayEquals(new Object[] {1, 2, 4}, delete(src, 2)); assertArrayEquals(new Object[] {1, 2, 3}, delete(src, 3)); assertArrayEquals(EMPTY_OBJECT_ARRAY, delete(new Object[] {"a"}, 0)); assertArrayEquals(EMPTY_OBJECT_ARRAY, delete(new Object[] {null}, 0)); }
@Test public void test_delete_result_type_is_object_array() { assertSame(Object[].class, delete(new Integer[] {1, 2, 3}, 1).getClass()); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void test_delete_out_of_bounds_low() { delete(new Object[] {"a"}, -1); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void test_delete_out_of_bounds_high() { delete(new Object[] {"a"}, 1); }
@Test(expected = NegativeArraySizeException.class) public void test_delete_out_of_bounds() { delete(EMPTY_OBJECT_ARRAY, 0); }
@Test(expected = NullPointerException.class) public void test_delete_null() { delete(null, 0); } |
BasicTools { static Object[] deleteAll(Object[] original, Collection<?> c) { Object[] result = new Object[original.length]; requireNonNull(c); int cursor = 0; for (Object o : original) { if (!c.contains(o)) { result[cursor++] = o; } } return cursor == result.length ? result : copy(result, cursor); } private BasicTools(); } | @Test public void test_deleteAll() { String[] src = new String[] {"a", "b", "c"}; assertArrayEquals(new Object[] {"b", "c"}, deleteAll(src, Arrays.asList("a"))); assertArrayEquals(new Object[] {"a", "c"}, deleteAll(src, Arrays.asList("b"))); assertArrayEquals(new Object[] {"a", "b"}, deleteAll(src, Arrays.asList("c"))); assertArrayEquals(new Object[] {"a", "b", "c"}, deleteAll(src, Arrays.asList("d"))); assertArrayEquals(new Object[] {"a", "b", "c"}, deleteAll(src, Collections.emptyList())); TreeSet<String> filter = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); filter.add("A"); filter.add("B"); assertArrayEquals(new Object[] {"c"}, deleteAll(src, filter)); filter.add("C"); filter.add("D"); assertArrayEquals(new Object[] {}, deleteAll(src, filter)); }
@Test public void test_deleteAll_result_type_is_object_array() { assertSame(Object[].class, deleteAll(new Integer[] {1, 2, 3}, Collections.emptySet()).getClass()); }
@Test(expected = NullPointerException.class) public void test_deleteAll_null_array() { deleteAll(null, Collections.emptySet()); }
@Test(expected = NullPointerException.class) public void test_deleteAll_null_collection() { deleteAll(EMPTY_OBJECT_ARRAY, null); }
@Test public void test_deleteAll_columns() { String[] keys = new String[] {"a", "b", "c"}; Integer[] values = new Integer[] {1, 2, 3}; MapColumns mc; mc = deleteAll(keys, values, Arrays.asList("a")); assertArrayEquals(new Object[] {"b", "c"}, mc.keys); assertArrayEquals(new Object[] {2, 3}, mc.values); mc = deleteAll(keys, values, Arrays.asList("b")); assertArrayEquals(new Object[] {"a", "c"}, mc.keys); assertArrayEquals(new Object[] {1, 3}, mc.values); mc = deleteAll(keys, values, Arrays.asList("c")); assertArrayEquals(new Object[] {"a", "b"}, mc.keys); assertArrayEquals(new Object[] {1, 2}, mc.values); mc = deleteAll(keys, values, Arrays.asList("d")); assertArrayEquals(new Object[] {"a", "b", "c"}, mc.keys); assertArrayEquals(new Object[] {1, 2, 3}, mc.values); mc = deleteAll(keys, values, Collections.emptyList()); assertArrayEquals(new Object[] {"a", "b", "c"}, mc.keys); assertArrayEquals(new Object[] {1, 2, 3}, mc.values); TreeSet<String> filter = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); filter.add("A"); filter.add("B"); mc = deleteAll(keys, values, filter); assertArrayEquals(new Object[] {"c"}, mc.keys); assertArrayEquals(new Object[] {3}, mc.values); filter.add("C"); filter.add("D"); mc = deleteAll(keys, values, filter); assertArrayEquals(new Object[] {}, mc.keys); assertArrayEquals(new Object[] {}, mc.values); }
@Test public void test_deleteAll_columns_result_type_is_object_array() { String[] keys = new String[] {"a", "b", "c"}; Integer[] values = new Integer[] {1, 2, 3}; MapColumns mc; mc = deleteAll(keys, values, Collections.emptyList()); assertSame(Object[].class, mc.keys.getClass()); assertSame(Object[].class, mc.values.getClass()); }
@Test(expected = NullPointerException.class) public void test_deleteAll_columns_null_array() { deleteAll(null, EMPTY_OBJECT_ARRAY, Collections.emptySet()); }
@Test(expected = NullPointerException.class) public void test_deleteAll_columns_null_value_array() { deleteAll(EMPTY_OBJECT_ARRAY, null, Collections.emptySet()); }
@Test(expected = NullPointerException.class) public void test_deleteAll_columns_null_collection() { deleteAll(EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, null); } |
TypeTable { ClassHandle createClass(String name, Class<?> inherits) { try { CtClass newClass = inherits == null || inherits.isInterface() ? classPool.makeInterface(name) : classPool.makeClass(name); newClass.setModifiers(Modifier.setPublic(newClass.getModifiers())); if (inherits != null) { CtClass baseClass = classPool.get(inherits.getName()); ClassSignature baseSignature = baseClass.getGenericSignature() != null ? toClassSignature(baseClass.getGenericSignature()) : null; TypeParameter[] params = baseSignature != null ? baseSignature.getParameters() : new TypeParameter[0]; if (params.length > 0) { assignGenericSignature(newClass, baseClass, baseSignature); } if (inherits.isInterface()) { newClass.setInterfaces(new CtClass[] {baseClass}); } else { newClass.setSuperclass(baseClass); if (inherits == Enum.class) { newClass.setModifiers(newClass.getModifiers() | Modifier.ENUM); } } } return new ClassHandle(name, null, newClass); } catch (NotFoundException | CannotCompileException | BadBytecode e) { throw new RuntimeException(e); } } TypeTable(NamingPolicy namingPolicy, TypePolicy typePolicy); } | @Test public void test_simple_class_creation() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle testHandle = table.createClass("com.test.Test", Object.class); assertFalse(testHandle.isLoaded()); assertTrue(testHandle.isDynamicallyCreated()); Class<?> testClass = testHandle.toClass(); assertEquals("com.test.Test", testClass.getName()); assertSame(Object.class, testClass.getSuperclass()); assertTrue(Modifier.isPublic(testClass.getModifiers())); assertTrue(testHandle.isLoaded()); assertTrue(testHandle.isDynamicallyCreated()); }
@Test public void test_generic_class_creation() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle mapHandle = table.createClass("com.test.Map", AbstractMap.class); Class<?> mapClass = mapHandle.toClass(); assertEquals("com.test.Map", mapClass.getName()); assertSame(AbstractMap.class, mapClass.getSuperclass()); assertEquals("[K, V]", Arrays.toString(mapClass.getTypeParameters())); assertEquals("java.util.AbstractMap<K, V>", mapClass.getGenericSuperclass().toString()); }
@Test public void test_creation_of_instantiated_generic() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle grainHandle = table.createClass("com.test.TestGrain", AbstractGrain.class); Class<?> grainClass = grainHandle.toClass(); assertEquals("com.test.TestGrain", grainClass.getName()); assertSame(AbstractGrain.class, grainClass.getSuperclass()); assertEquals(0, grainClass.getTypeParameters().length); assertSame(AbstractGrain.class, grainClass.getGenericSuperclass()); }
@Test public void test_interface_creation() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle testableHandle = table.createClass("com.test.Testable", null); assertFalse(testableHandle.isLoaded()); assertTrue(testableHandle.isDynamicallyCreated()); Class<?> testableClass = testableHandle.toClass(); assertTrue(testableClass.isInterface()); assertEquals("com.test.Testable", testableClass.getName()); assertNull(testableClass.getSuperclass()); assertEquals(0, testableClass.getInterfaces().length); assertTrue(Modifier.isPublic(testableClass.getModifiers())); assertTrue(testableHandle.isLoaded()); assertTrue(testableHandle.isDynamicallyCreated()); }
@Test public void test_sub_interface_creation() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle raHandle = table.createClass("com.test.RandomAccess", RandomAccess.class); Class<?> raClass = raHandle.toClass(); assertTrue(raClass.isInterface()); assertEquals("com.test.RandomAccess", raClass.getName()); assertNull(raClass.getSuperclass()); assertSame(RandomAccess.class, raClass.getInterfaces()[0]); }
@Test public void test_generic_interface_creation() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle iMapHandle = table.createClass("com.test.IMap", Map.class); Class<?> iMapClass = iMapHandle.toClass(); assertEquals("com.test.IMap", iMapClass.getName()); assertEquals("[K, V]", Arrays.toString(iMapClass.getTypeParameters())); assertSame(Map.class, iMapClass.getInterfaces()[0]); assertEquals("java.util.Map<K, V>", iMapClass.getGenericInterfaces()[0].toString()); assertNull(iMapClass.getSuperclass()); assertNull(iMapClass.getGenericSuperclass()); }
@Test public void test_enum_creation() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); ClassHandle enumHandle = table.createClass("com.test.TestEnum", Enum.class); Class<?> enumClass = enumHandle.toClass(); assertTrue(enumClass.isEnum()); assertEquals("com.test.TestEnum", enumClass.getName()); assertSame(Enum.class, enumClass.getSuperclass()); assertEquals("java.lang.Enum<E>", enumClass.getGenericSuperclass().toString()); assertTrue(Modifier.isPublic(enumClass.getModifiers())); } |
BasicTools { static Object[] unionInto(Object[] original, Object[] additional) { Object[] result = copy(original, original.length + additional.length); int cursor = original.length; for (Object element : additional) { if (indexOf(element, result, 0, cursor) < 0) { result[cursor++] = element; } } return cursor == result.length ? result : copy(result, cursor); } private BasicTools(); } | @Test public void test_union_into() { assertArrayEquals(new Object[] {1, 2, 3, 0}, unionInto(new Object[] {1, 2, 3}, new Object[] {0})); assertArrayEquals(new Object[] {1, 3, 2, 0}, unionInto(new Object[] {1, 3, 2}, new Object[] {0, 1})); assertArrayEquals(new Object[] {1, 2, 3, null}, unionInto(new Object[] {1, 2, 3}, new Object[] {null})); assertArrayEquals(new Object[] {1, 2, 3, "a"}, unionInto(new Object[] {1, 2, 3}, new Object[] {"a"})); assertArrayEquals(new Object[] {1, 1, 0}, unionInto(new Object[] {1, 1}, new Object[] {1, 0, 0})); assertArrayEquals(new Object[] {1, 0, 2}, unionInto(new Object[] {}, new Object[] {1, 0, 1, 2, 0, 2})); assertArrayEquals(new Object[] {1, 1}, unionInto(new Object[] {1, 1}, new Object[] {})); assertEquals(Object[].class, unionInto(new Integer[] {1}, new Integer[] {2}).getClass()); }
@Test public void test_union_into_null_arrays() { try { unionInto(null, new Object[0]); fail(); } catch (NullPointerException ignored) {} try { unionInto(new Object[0], null); fail(); } catch (NullPointerException ignored) {} }
@Test public void test_union_into_comparator() { assertArrayEquals(new Object[] {0, 1, 2, 3}, unionInto(new Object[] {1, 2, 3}, new Object[] {0}, null)); assertArrayEquals(new Object[] {0, 1, 2, 3}, unionInto(new Object[] {1, 2, 3}, new Object[] {0, 1}, null)); assertArrayEquals(new Object[] {0, 1, 1}, unionInto(new Object[] {1, 1}, new Object[] {1, 0, 0}, null)); assertArrayEquals(new Object[] {0, 1, 2}, unionInto(new Object[] {}, new Object[] {1, 0, 1, 2, 0, 2}, null)); assertArrayEquals(new Object[] {1, 1}, unionInto(new Object[] {1, 1}, new Object[] {}, null)); assertEquals(Object[].class, unionInto(new Integer[] {1}, new Integer[] {2}, null).getClass()); Comparator<Object> c = Collections.reverseOrder(); assertArrayEquals(new Object[] {3, 2, 1, 0}, unionInto(new Object[] {3, 2, 1}, new Object[] {0}, c)); assertArrayEquals(new Object[] {3, 2, 1, 0}, unionInto(new Object[] {3, 2, 1}, new Object[] {0, 1}, c)); assertArrayEquals(new Object[] {1, 1, 0}, unionInto(new Object[] {1, 1}, new Object[] {1, 0, 0}, c)); assertArrayEquals(new Object[] {2, 1, 0}, unionInto(new Object[] {}, new Object[] {1, 0, 1, 2, 0, 2}, c)); assertArrayEquals(new Object[] {1, 1}, unionInto(new Object[] {1, 1}, new Object[] {}, c)); assertEquals(Object[].class, unionInto(new Integer[] {1}, new Integer[] {2}, c).getClass()); }
@Test public void test_union_into_comparator_bad_types() { try { unionInto(new Object[] {1}, new Object[] {"a"}, null); } catch (ClassCastException ignored) {} try { unionInto(new Object[] {1}, new Object[] {null}, null); } catch (NullPointerException ignored) {} Comparator<Object> c = Collections.reverseOrder(); try { unionInto(new Object[] {1}, new Object[] {"a"}, c); } catch (ClassCastException ignored) {} try { unionInto(new Object[] {1}, new Object[] {null}, c); } catch (NullPointerException ignored) {} }
@Test public void test_union_into_comparator_null_arrays() { try { unionInto(null, new Object[0], null); fail(); } catch (NullPointerException ignored) {} try { unionInto(new Object[0], null, null); fail(); } catch (NullPointerException ignored) {} Comparator<Object> c = Collections.reverseOrder(); try { unionInto(null, new Object[0], c); fail(); } catch (NullPointerException ignored) {} try { unionInto(new Object[0], null, c); fail(); } catch (NullPointerException ignored) {} }
@Test public void test_union_into_columns() { String[] keys = new String[] {"a", "b", "a"}; Integer[] values = new Integer[] {1, 2, 3}; MapColumns mc; mc = unionInto(keys, values, new String[] {"+"}, new Integer[] {1}); assertArrayEquals(new Object[] {"a", "b", "a", "+"}, mc.keys); assertArrayEquals(new Object[] {1, 2, 3, 1 }, mc.values); mc = unionInto(keys, values, new String[] {"+", "a"}, new Integer[] {1, 2}); assertArrayEquals(new Object[] {"a", "b", "a", "+"}, mc.keys); assertArrayEquals(new Object[] {2, 2, 3, 1 }, mc.values); mc = unionInto(keys, values, new Object[] {"+", "a", "+", "a", 4}, new Object[] {1, 2, 0, 4, "d"}); assertArrayEquals(new Object[] {"a", "b", "a", "+", 4}, mc.keys); assertArrayEquals(new Object[] {4, 2, 3, 0 , "d"}, mc.values); assertEquals(Object[].class, mc.keys.getClass()); assertEquals(Object[].class, mc.values.getClass()); }
@Test public void test_union_into_columns_null_arrays() { try { unionInto(new Object[0], null, null, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, new Object[0], null, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, null, new Object[0], null); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, null, null, new Object[0]); fail(); } catch (NullPointerException ignored) {} }
@Test public void test_union_into_columns_comparator_natural_ordering() { String[] keys = new String[] {"a", "a", "d"}; Integer[] values = new Integer[] {1, 1, 4}; MapColumns mc; mc = unionInto(keys, values, new String[] {"+"}, new Integer[] {1}, null); assertArrayEquals(new Object[] {"+", "a", "a", "d"}, mc.keys); assertArrayEquals(new Object[] {1, 1, 1, 4}, mc.values); mc = unionInto(keys, values, new String[] {"a", "+", "e", "c"}, new Integer[] {1, 0, 5, 3}, null); assertArrayEquals(new Object[] {"+", "a", "a", "c", "d", "e"}, mc.keys); assertArrayEquals(new Object[] {0, 1, 1, 3, 4, 5}, mc.values); assertEquals(Object[].class, mc.keys.getClass()); assertEquals(Object[].class, mc.values.getClass()); }
@Test public void test_union_into_columns_comparator_reverse_ordering() { String[] keys = new String[] {"d", "a", "a"}; Integer[] values = new Integer[] {4, 1, 1}; Comparator<Object> c = Collections.reverseOrder(); MapColumns mc; mc = unionInto(keys, values, new String[] {"+"}, new Integer[] {1}, c); assertArrayEquals(new Object[] {"d", "a", "a", "+"}, mc.keys); assertArrayEquals(new Object[] {4, 1, 1, 1}, mc.values); mc = unionInto(keys, values, new String[] {"a", "+", "e", "c"}, new Integer[] {1, 0, 5, 3}, c); assertArrayEquals(new Object[] {"e", "d", "c", "a", "a", "+"}, mc.keys); assertArrayEquals(new Object[] {5, 4, 3, 1, 1, 0}, mc.values); assertEquals(Object[].class, mc.keys.getClass()); assertEquals(Object[].class, mc.values.getClass()); }
@Test public void test_union_into_columns_comparator_null_arrays() { try { unionInto(new Object[0], null, null, null, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, new Object[0], null, null, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, null, new Object[0], null, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, null, null, new Object[0], null); fail(); } catch (NullPointerException ignored) {} Comparator<Object> c = Collections.reverseOrder(); try { unionInto(new Object[0], null, null, null, c); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, new Object[0], null, null, c); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, null, new Object[0], null, c); fail(); } catch (NullPointerException ignored) {} try { unionInto(null, null, null, new Object[0], c); fail(); } catch (NullPointerException ignored) {} }
@Test public void test_unionInto_bad_types() { final Object[] EMPTY = new Object[0]; final Object[] items = new Object[] {"a"}; final Object[] oneObj = new Object[] {new Object()}; final Object[] oneNull = new Object[] {null}; @SuppressWarnings("unchecked") Comparator<Object> c = (Comparator)String.CASE_INSENSITIVE_ORDER; try { unionInto(EMPTY, oneObj, null); fail(); } catch (ClassCastException ignored) {} try { unionInto(EMPTY, oneObj, c); fail(); } catch (ClassCastException ignored) {} try { unionInto(EMPTY, oneNull, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(EMPTY, oneNull, c); fail(); } catch (NullPointerException ignored) {} try { unionInto(items, oneObj, null); fail(); } catch (ClassCastException ignored) {} try { unionInto(items, oneObj, c); fail(); } catch (ClassCastException ignored) {} try { unionInto(items, oneNull, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(items, oneNull, c); fail(); } catch (NullPointerException ignored) {} }
@Test public void test_unionInto_columns_bad_types() { final Object[] EMPTY = new Object[0]; final Object[] items = new Object[] {"a"}; final Object[] oneObj = new Object[] {new Object()}; final Object[] oneNull = new Object[] {null}; @SuppressWarnings("unchecked") Comparator<Object> c = (Comparator)String.CASE_INSENSITIVE_ORDER; try { unionInto(EMPTY, EMPTY, oneObj, oneNull, null); fail(); } catch (ClassCastException ignored) {} try { unionInto(EMPTY, EMPTY, oneObj, oneNull, c); fail(); } catch (ClassCastException ignored) {} try { unionInto(EMPTY, EMPTY, oneNull, oneNull, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(EMPTY, EMPTY, oneNull, oneNull, c); fail(); } catch (NullPointerException ignored) {} try { unionInto(items, EMPTY, oneObj, oneNull, null); fail(); } catch (ClassCastException ignored) {} try { unionInto(items, EMPTY, oneObj, oneNull, c); fail(); } catch (ClassCastException ignored) {} try { unionInto(items, EMPTY, oneNull, oneNull, null); fail(); } catch (NullPointerException ignored) {} try { unionInto(items, EMPTY, oneNull, oneNull, c); fail(); } catch (NullPointerException ignored) {} } |
BasicSortedMap1 extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> with(K key, V value) { int cmp = compare(key, k0); if (cmp == 0) { if (Objects.equals(value, v0)) { return this; } return new BasicSortedMap1<>(comparator, k0, value); } return cmp < 0 ? new BasicSortedMapN<K, V>(comparator, new Object[] {key, k0}, new Object[] {value, v0}) : new BasicSortedMapN<K, V>(comparator, new Object[] {k0, key}, new Object[] {v0, value}); } @SuppressWarnings("unchecked") BasicSortedMap1(Comparator<? super K> comparator, Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_with() { ConstSortedMap<Object, Object> map; map = new BasicSortedMap1<>(null, "a", 1); compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2), map.with("b", 2)); compare_sorted_maps(newSortedMap(null, "a", 2), map.with("a", 2)); assertSame(map, map.with("a", 1)); map = new BasicSortedMap1<>(reverseOrder(), "a", 1); compare_sorted_maps(newSortedMap(reverseOrder(), "a", 1, "b", 2), map.with("b", 2)); compare_sorted_maps(newSortedMap(reverseOrder(), "a", 2), map.with("a", 2)); assertSame(map, map.with("a", 1)); } |
BasicSortedMap1 extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map) { if (map.isEmpty()) { return this; } MapColumns mc = copy(map); return condenseToSortedMap( comparator, unionInto(new Object[] {k0}, new Object[] {v0}, mc.keys, mc.values, comparator)); } @SuppressWarnings("unchecked") BasicSortedMap1(Comparator<? super K> comparator, Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_withAll() { ConstSortedMap<Object, Object> map; map = new BasicSortedMap1<>(null, "a", 1); compare_sorted_maps( newSortedMap(null, "a", 2, "b", 2, "c", 3), map.withAll(newMap("c", 3, "b", 2, "a", 2))); compare_sorted_maps(map, map.withAll(newMap("a", 1))); assertSame(map, map.withAll(newMap())); map = new BasicSortedMap1<>(reverseOrder(), "a", 1); compare_sorted_maps( newSortedMap(reverseOrder(), "a", 2, "b", 2, "c", 3), map.withAll(newMap("b", 2, "c", 3, "a", 2))); compare_sorted_maps(map, map.withAll(newMap("a", 1))); assertSame(map, map.withAll(newMap())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicSortedMap1<>(null, "a", 1).withAll(null); } |
BasicSortedMap1 extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> without(Object key) { return !containsKey(key) ? this : BasicCollections.<K, V>emptySortedMap(comparator); } @SuppressWarnings("unchecked") BasicSortedMap1(Comparator<? super K> comparator, Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_without() { ConstSortedMap<Object, Object> map; map = new BasicSortedMap1<>(null, "a", 1); compare_sorted_maps(BasicSortedMap0.instance(null), map.without("a")); assertSame(map, map.without("b")); map = new BasicSortedMap1<>(reverseOrder(), "a", 1); compare_sorted_maps(BasicSortedMap0.instance(reverseOrder()), map.without("a")); assertSame(map, map.without("b")); } |
BasicSortedMap1 extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> withoutAll(Collection<?> keys) { return !keys.contains(k0) ? this : BasicCollections.<K, V>emptySortedMap(comparator); } @SuppressWarnings("unchecked") BasicSortedMap1(Comparator<? super K> comparator, Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstSortedMap<Object, Object> map; map = new BasicSortedMap1<>(null, "a", 1); compare_sorted_maps(BasicSortedMap0.instance(null), map.withoutAll(Arrays.asList("a"))); compare_sorted_maps(BasicSortedMap0.instance(null), map.withoutAll(Arrays.asList("a", "b", "a"))); assertSame(map, map.withoutAll(Arrays.asList("b"))); assertSame(map, map.withoutAll(Arrays.asList())); map = new BasicSortedMap1<>(reverseOrder(), "a", 1); compare_sorted_maps(BasicSortedMap0.instance(reverseOrder()), map.withoutAll(Arrays.asList("a"))); compare_sorted_maps(BasicSortedMap0.instance(reverseOrder()), map.withoutAll(Arrays.asList("a", "b", "a"))); assertSame(map, map.withoutAll(Arrays.asList("b"))); assertSame(map, map.withoutAll(Arrays.asList())); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicSortedMap1<>(null, "a", 1).withoutAll(null); } |
BasicSortedMap1 extends BasicConstSortedMap<K, V> { @Override K getKey(int index) { if (index == 0) { return k0; } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicSortedMap1(Comparator<? super K> comparator, Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_get_key() { assertEquals("a", new BasicSortedMap1<>(null, "a", 1).getKey(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_key() { new BasicSortedMap1<>(null, "a", 1).getKey(1); } |
BasicSortedMap1 extends BasicConstSortedMap<K, V> { @Override V getValue(int index) { if (index == 0) { return v0; } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicSortedMap1(Comparator<? super K> comparator, Object k0, Object v0); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_get_value() { assertEquals(1, new BasicSortedMap1<>(null, "a", 1).getValue(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_value() { new BasicSortedMap1<>(null, "a", 1).getValue(1); } |
BasicConstList extends AbstractList<E> implements ConstList<E>, RandomAccess, Serializable { @Override public Iterator<E> iterator() { return new Iter(); } BasicConstList(); @Override Iterator<E> iterator(); @Override ListIterator<E> listIterator(int start); @Override abstract ConstList<E> subList(int fromIndex, int toIndex); @Deprecated @Override final boolean add(E e); @Deprecated @Override final void add(int index, E element); @Deprecated @Override final boolean addAll(Collection<? extends E> c); @Deprecated @Override final boolean addAll(int index, Collection<? extends E> c); @Deprecated @Override final E set(int index, E element); @Deprecated @Override final boolean retainAll(Collection<?> c); @Deprecated @Override final boolean remove(Object o); @Deprecated @Override final E remove(int index); @Deprecated @Override final boolean removeAll(Collection<?> c); @Deprecated @Override final void clear(); } | @Test public void test_asList_iterator() { assertSame(emptyList(), asList(Arrays.asList().iterator())); compare_lists(Arrays.asList(1), asList(Arrays.asList(1).iterator())); compare_lists(Arrays.asList(1, 2), asList(Arrays.asList(1, 2).iterator())); compare_lists(Arrays.asList(1, 2, 3), asList(Arrays.asList(1, 2, 3).iterator())); compare_lists(Arrays.asList(1, 2, 3, 4), asList(Arrays.asList(1, 2, 3, 4).iterator())); compare_lists(Arrays.asList(1, 2, 3, 4, 5), asList(Arrays.asList(1, 2, 3, 4, 5).iterator())); compare_lists(Arrays.asList(1, 2, 3, 4, 5, 6), asList(Arrays.asList(1, 2, 3, 4, 5, 6).iterator())); }
@Test public void test_asList_iterator_types() { assertEquals(BasicList1.class, asList(Arrays.asList(1).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2, 3).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2, 3, 4).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2, 3, 4, 5).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2, 3, 4, 5, 6).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2, 3, 4, 5, 6, 7).iterator()).getClass()); assertEquals(BasicListN.class, asList(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8).iterator()).getClass()); } |
BasicConstList extends AbstractList<E> implements ConstList<E>, RandomAccess, Serializable { @Deprecated @Override public final boolean add(E e) { throw unsupported(); } BasicConstList(); @Override Iterator<E> iterator(); @Override ListIterator<E> listIterator(int start); @Override abstract ConstList<E> subList(int fromIndex, int toIndex); @Deprecated @Override final boolean add(E e); @Deprecated @Override final void add(int index, E element); @Deprecated @Override final boolean addAll(Collection<? extends E> c); @Deprecated @Override final boolean addAll(int index, Collection<? extends E> c); @Deprecated @Override final E set(int index, E element); @Deprecated @Override final boolean retainAll(Collection<?> c); @Deprecated @Override final boolean remove(Object o); @Deprecated @Override final E remove(int index); @Deprecated @Override final boolean removeAll(Collection<?> c); @Deprecated @Override final void clear(); } | @Test public void test_publicInterfaceRef_annotation_present() { Collection<Integer> elements = new ArrayList<>(); for (int i = 0; i < 15; i++) { assertSame( BasicConstList.class, asList(elements).getClass().getAnnotation(PublicInterfaceRef.class).value()); elements.add(i); } } |
BasicConstSortedMap extends BasicConstMap<K, V> implements ConstSortedMap<K, V> { @Override public Comparator<? super K> comparator() { return comparator; } BasicConstSortedMap(Comparator<? super K> comparator); @Override Comparator<? super K> comparator(); @Override abstract ConstSortedSet<K> keySet(); @Override abstract ConstCollection<V> values(); @Override abstract ConstSet<Map.Entry<K, V>> entrySet(); } | @Test public void test_emptySortedMap() { assertSame(BasicSortedMap0.instance(null), emptySortedMap(null)); Comparator<Object> reverse = reverseOrder(); assertSame(BasicSortedSet0.instance(reverse).comparator(), emptySortedMap(reverse).comparator()); } |
BasicConstSortedMap extends BasicConstMap<K, V> implements ConstSortedMap<K, V> { int compare(K left, K right) { return ObjectTools.compare(left, right, comparator); } BasicConstSortedMap(Comparator<? super K> comparator); @Override Comparator<? super K> comparator(); @Override abstract ConstSortedSet<K> keySet(); @Override abstract ConstCollection<V> values(); @Override abstract ConstSet<Map.Entry<K, V>> entrySet(); } | @Test public void test_construction_permutations() { for (int a = 0; a < 6; a++) { compare(newSortedMap(null, a, a+1), sortedMapOf(null, a, a+1)); for (int b = 0; b < 6; b++) { compare(newSortedMap(null, a, a, b, b), sortedMapOf(null, a, a, b, b)); for (int c = 0; c < 6; c++) { compare(newSortedMap(null, a, a, b, b, c, c), sortedMapOf(null, a, a, b, b, c, c)); for (int d = 0; d < 6; d++) { compare( newSortedMap(null, a, a, b, b, c, c, d, d), sortedMapOf(null, a, a, b, b, c, c, d, d)); for (int e = 0; e < 6; e++) { compare( newSortedMap(null, a, a, b, b, c, c, d, d, e, e), sortedMapOf(null, a, a, b, b, c, c, d, d, e, e)); for (int f = 0; f < 6; f++) { Integer[] ary = new Integer[] {a, b, c, d, e, f}; SortedMap<Integer, Integer> expected = newSortedMap(null, a, a, b, b, c, c, d, d, e, e, f, f); Map<Integer, Integer> plainMap = newMap(a, a, b, b, c, c, d, d, e, e, f, f); compare(expected, asSortedMap(null, ary, ary)); compare(expected, asSortedMap(expected)); compare(expected, asSortedMap(null, plainMap)); } } } } } } }
@Test public void test_construction_permutations_reverse() { Comparator<Object> reverse = reverseOrder(); for (int a = 0; a < 6; a++) { compare(newSortedMap(reverse, a, a+1), sortedMapOf(reverse, a, a+1)); for (int b = 0; b < 6; b++) { compare(newSortedMap(reverse, a, a, b, b), sortedMapOf(reverse, a, a, b, b)); for (int c = 0; c < 6; c++) { compare(newSortedMap(reverse, a, a, b, b, c, c), sortedMapOf(reverse, a, a, b, b, c, c)); for (int d = 0; d < 6; d++) { compare( newSortedMap(reverse, a, a, b, b, c, c, d, d), sortedMapOf(reverse, a, a, b, b, c, c, d, d)); for (int e = 0; e < 6; e++) { compare( newSortedMap(reverse, a, a, b, b, c, c, d, d, e, e), sortedMapOf(reverse, a, a, b, b, c, c, d, d, e, e)); for (int f = 0; f < 6; f++) { Integer[] ary = new Integer[] {a, b, c, d, e, f}; SortedMap<Integer, Integer> expected = newSortedMap(reverse, a, a, b, b, c, c, d, d, e, e, f, f); Map<Integer, Integer> plainMap = newMap(a, a, b, b, c, c, d, d, e, e, f, f); compare(expected, asSortedMap(reverse, ary, ary)); compare(expected, asSortedMap(expected)); compare(expected, asSortedMap(reverse, plainMap)); } } } } } } } |
BasicSortedSet0 extends BasicConstSortedSet<E> { @SuppressWarnings("unchecked") static <E> BasicSortedSet0<E> instance(Comparator<? super E> comparator) { return comparator == null ? NATURAL_INSTANCE : new BasicSortedSet0<>(comparator); } private BasicSortedSet0(Comparator<? super E> comparator); @Override int size(); @Override boolean isEmpty(); @Override Iterator<E> iterator(); @Override boolean contains(Object o); @Override boolean containsAll(Collection<?> c); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_comparison() { compare_sorted_sets(newSortedSet(null), BasicSortedSet0.instance(null), -1, 0, 1, 0); compare_sorted_sets(newSortedSet(reverseOrder()), BasicSortedSet0.instance(reverseOrder()), 1, 0, -1, 0); }
@Test public void test_immutable() { assert_sorted_set_immutable(BasicSortedSet0.instance(null)); }
@Test public void test_serialization() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); ConstSortedSet<Object> set = BasicSortedSet0.instance(null); out.writeObject(set); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0+net.nullschool.collect.basic.SortedSetProxy00000001300xppw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); assertSame(set, in.readObject()); }
@Test public void test_serialization_with_comparator() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); ConstSortedSet<Object> set = BasicSortedSet0.instance(reverseOrder()); out.writeObject(set); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0+net.nullschool.collect.basic.SortedSetProxy00000001300xpsr0'" + "java.util.Collections$ReverseComparatord48af0SNJd0200xpw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); ConstSortedSet<?> read = (ConstSortedSet)in.readObject(); compare_sorted_sets(set, read); assertSame(set.getClass(), read.getClass()); } |
BasicConstSet extends AbstractSet<E> implements ConstSet<E>, Serializable { @Override public Iterator<E> iterator() { return new Iter(); } BasicConstSet(); @Override Iterator<E> iterator(); @Deprecated @Override final boolean add(E e); @Deprecated @Override final boolean addAll(Collection<? extends E> c); @Deprecated @Override final boolean remove(Object o); @Deprecated @Override final boolean removeAll(Collection<?> c); @Deprecated @Override final boolean retainAll(Collection<?> c); @Deprecated @Override final void clear(); } | @Test public void test_construction_permutations() { for (int a = 0; a < 6; a++) { compare_order(newSet(a), setOf(a)); for (int b = 0; b < 6; b++) { compare_order(newSet(a, b), setOf(a, b)); for (int c = 0; c < 6; c++) { compare_order(newSet(a, b, c), setOf(a, b, c)); for (int d = 0; d < 6; d++) { compare_order(newSet(a, b, c, d), setOf(a, b, c, d)); for (int e = 0; e < 6; e++) { compare_order(newSet(a, b, c, d, e), setOf(a, b, c, d, e)); for (int f = 0; f < 6; f++) { Integer[] elements = new Integer[] {a, b, c, d, e, f}; Set<Integer> expected = newSet(elements); Collection<Integer> collection = Arrays.asList(elements); compare_order(expected, setOf(a, b, c, d, e, f)); compare_order(expected, asSet(elements)); compare_order(expected, asSet(collection)); compare_order(expected, asSet(collection.iterator())); } } } } } } }
@Test public void test_asSet_iterator() { assertSame(emptySet(), asSet(Arrays.asList().iterator())); compare_sets(newSet(1), asSet(Arrays.asList(1).iterator())); compare_sets(newSet(1, 2), asSet(Arrays.asList(1, 2).iterator())); compare_sets(newSet(1, 2, 3), asSet(Arrays.asList(1, 2, 3).iterator())); compare_sets(newSet(1, 2, 3, 4), asSet(Arrays.asList(1, 2, 3, 4).iterator())); compare_sets(newSet(1, 2, 3, 4, 5), asSet(Arrays.asList(1, 2, 3, 4, 5).iterator())); compare_sets(newSet(1, 2, 3, 4, 5, 6), asSet(Arrays.asList(1, 2, 3, 4, 5, 6).iterator())); }
@Test public void test_asSet_iterator_types() { assertEquals(BasicSet1.class, asSet(Arrays.asList(1).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7).iterator()).getClass()); assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8).iterator()).getClass()); } |
BasicConstSet extends AbstractSet<E> implements ConstSet<E>, Serializable { @Deprecated @Override public final boolean add(E e) { throw unsupported(); } BasicConstSet(); @Override Iterator<E> iterator(); @Deprecated @Override final boolean add(E e); @Deprecated @Override final boolean addAll(Collection<? extends E> c); @Deprecated @Override final boolean remove(Object o); @Deprecated @Override final boolean removeAll(Collection<?> c); @Deprecated @Override final boolean retainAll(Collection<?> c); @Deprecated @Override final void clear(); } | @Test public void test_publicInterfaceRef_annotation_present() { Collection<Integer> elements = new ArrayList<>(); for (int i = 0; i < 15; i++) { assertSame( BasicConstSet.class, asSet(elements).getClass().getAnnotation(PublicInterfaceRef.class).value()); elements.add(i); } } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return with(elements.length, e); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_with() { compare_lists( Arrays.asList(1, 2, 3, 4, 5, 6, 7), new BasicListN<Integer>(new Object[] {1, 2, 3, 4, 5, 6}).with(7)); compare_lists( Arrays.asList(1, 2, 3, 4, 5, 6, null), new BasicListN<Integer>(new Object[] {1, 2, 3, 4, 5, 6}).with(null)); }
@Test public void test_with_index() { compare_lists( Arrays.asList(7, 1, 2, 3, 4, 5, 6), new BasicListN<Integer>(new Object[] {1, 2, 3, 4, 5, 6}).with(0, 7)); compare_lists( Arrays.asList(1, 2, 3, 7, 4, 5, 6), new BasicListN<Integer>(new Object[] {1, 2, 3, 4, 5, 6}).with(3, 7)); compare_lists( Arrays.asList(1, 2, 3, 4, 5, 6, 7), new BasicListN<Integer>(new Object[] {1, 2, 3, 4, 5, 6}).with(6, 7)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_with_index_out_of_bounds() { new BasicListN<Integer>(new Object[] {1, 2, 3, 4, 5, 6}).with(7, 7); } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return withAll(elements.length, c); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_withAll() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_lists(Arrays.asList(1, 2, 3, 4, 5, 6, 1, 2, 3), list.withAll(Arrays.asList(1, 2, 3))); assertSame(list, list.withAll(Collections.<Integer>emptyList())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}).withAll(null); }
@Test public void test_withAll_index() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_lists(Arrays.asList(1, 2, 3, 1, 2, 3, 4, 5, 6), list.withAll(0, Arrays.asList(1, 2, 3))); compare_lists(Arrays.asList(1, 2, 3, 4, 1, 2, 3, 5, 6), list.withAll(4, Arrays.asList(1, 2, 3))); compare_lists(Arrays.asList(1, 2, 3, 4, 5, 6, 1, 2, 3), list.withAll(6, Arrays.asList(1, 2, 3))); assertSame(list, list.withAll(0, Collections.<Integer>emptyList())); }
@Test(expected = IndexOutOfBoundsException.class) public void test_withAll_index_out_of_bounds() { new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}).withAll(7, Collections.<Integer>emptyList()); }
@Test(expected = NullPointerException.class) public void test_withAll_index_throws() { new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}).withAll(0, null); } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { return new BasicListN<>(BasicTools.replace(elements, index, e)); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_replace() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_lists(Arrays.asList(9, 2, 3, 4, 5, 6), list.replace(0, 9)); compare_lists(Arrays.asList(1, 2, 3, 9, 5, 6), list.replace(3, 9)); compare_lists(Arrays.asList(1, 2, 3, 4, 5, 9), list.replace(5, 9)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_replace_out_of_bounds() { new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}).replace(6, 9); } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> without(Object o) { int index = ArrayTools.indexOf(o, elements); return index < 0 ? this : delete(index); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_without() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6, 1}); compare_lists(Arrays.asList(2, 3, 4, 5, 6, 1), list.without(1)); compare_lists(Arrays.asList(1, 3, 4, 5, 6, 1), list.without(2)); assertSame(list, list.without(7)); assertSame(list, list.without(null)); } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> delete(int index) { return condenseToList(BasicTools.delete(elements, index)); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_delete() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_lists(Arrays.asList(2, 3, 4, 5, 6), list.delete(0)); compare_lists(Arrays.asList(1, 2, 3, 5, 6), list.delete(3)); compare_lists(Arrays.asList(1, 2, 3, 4, 5), list.delete(5)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_delete_out_of_bounds() { new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}).delete(6); } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> withoutAll(Collection<?> c) { if (c.isEmpty()) { return this; } Object[] shrunk = deleteAll(elements, c); return shrunk.length == size() ? this : BasicCollections.<E>condenseToList(shrunk); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6, 1}); compare_lists(Arrays.asList(3, 4, 5, 6), list.withoutAll(Arrays.asList(1, 2))); compare_lists(Arrays.asList(3, 4, 5, 6), list.withoutAll(Arrays.asList(1, 2, 9))); assertSame(list, list.withoutAll(Arrays.asList(7))); assertSame(list, list.withoutAll(Arrays.asList())); assertSame(BasicList0.instance(), list.withoutAll(list)); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}).withoutAll(null); } |
BasicListN extends BasicConstList<E> { @Override public ConstList<E> subList(int fromIndex, int toIndex) { return condenseToList(Arrays.copyOfRange(elements, fromIndex, toIndex)); } @SuppressWarnings("unchecked") BasicListN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override int hashCode(); } | @Test public void test_subList() { ConstList<Integer> list = new BasicListN<>(new Object[] {1, 2, 3, 4, 5, 6}); assertSame(BasicList0.instance(), list.subList(0, 0)); assertSame(BasicList0.instance(), list.subList(6, 6)); } |
BasicSortedSetN extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> with(E e) { int index = indexOf(e); return index >= 0 ? this : new BasicSortedSetN<>(comparator, insert(elements, flip(index), e)); } @SuppressWarnings("unchecked") BasicSortedSetN(Comparator<? super E> comparator, Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_with() { ConstSortedSet<Integer> set; set = new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 6}); compare_sorted_sets(newSortedSet(null, 1, 2, 3, 4, 5, 6, 7), set.with(7)); compare_sorted_sets(newSortedSet(null, 0, 1, 2, 3, 4, 5, 6), set.with(0)); compare_sorted_sets(newSortedSet(null, 1, 2, 3, 4, 5, 6, 7, 8), set.with(8).with(7)); assertSame(set, set.with(6)); set = new BasicSortedSetN<>(reverseOrder(), new Object[] {6, 5, 4, 3, 2, 1}); compare_sorted_sets(newSortedSet(reverseOrder(), 7, 6, 5, 4, 3, 2, 1), set.with(7)); compare_sorted_sets(newSortedSet(reverseOrder(), 6, 5, 4, 3, 2, 1, 0), set.with(0)); compare_sorted_sets(newSortedSet(reverseOrder(), 8, 7, 6, 5, 4, 3, 2, 1), set.with(8).with(7)); assertSame(set, set.with(6)); } |
BasicSortedSetN extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> withAll(Collection<? extends E> c) { if (c.isEmpty()) { return this; } Object[] expanded = unionInto(elements, c.toArray(), comparator); return expanded.length == size() ? this : new BasicSortedSetN<>(comparator, expanded); } @SuppressWarnings("unchecked") BasicSortedSetN(Comparator<? super E> comparator, Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_withAll() { ConstSortedSet<Integer> set; set = new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 7}); compare_sorted_sets( newSortedSet(null, 0, 1, 2, 3, 4, 5, 6, 7, 8), set.withAll(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 0))); assertSame(set, set.withAll(Arrays.asList(1, 1, 1, 2, 2, 3, 3))); assertSame(set, set.withAll(Collections.<Integer>emptyList())); set = new BasicSortedSetN<>(reverseOrder(), new Object[] {7, 5, 4, 3, 2, 1}); compare_sorted_sets( newSortedSet(reverseOrder(), 8, 7, 6, 5, 4, 3, 2, 1, 0), set.withAll(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 0))); assertSame(set, set.withAll(Arrays.asList(1, 1, 1, 2, 2, 3, 3))); assertSame(set, set.withAll(Collections.<Integer>emptyList())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 6}).withAll(null); } |
BasicSortedSetN extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> without(Object o) { int index = indexOf(o); return index < 0 ? this : condenseToSortedSet(comparator, delete(elements, index)); } @SuppressWarnings("unchecked") BasicSortedSetN(Comparator<? super E> comparator, Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_without() { ConstSortedSet<Integer> set; set = new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 6}); compare_sorted_sets(newSortedSet(null, 2, 3, 4, 5, 6), set.without(1)); compare_sorted_sets(newSortedSet(null, 1, 3, 4, 5, 6), set.without(2)); compare_sorted_sets(newSortedSet(null, 1, 2, 3, 4, 5), set.without(6)); assertSame(set, set.without(-1)); assertSame(set, set.without(7)); set = new BasicSortedSetN<>(reverseOrder(), new Object[] {6, 5, 4, 3, 2, 1}); compare_sorted_sets(newSortedSet(reverseOrder(), 6, 5, 4, 3, 2), set.without(1)); compare_sorted_sets(newSortedSet(reverseOrder(), 6, 5, 4, 3, 1), set.without(2)); compare_sorted_sets(newSortedSet(reverseOrder(), 5, 4, 3, 2, 1), set.without(6)); assertSame(set, set.without(-1)); assertSame(set, set.without(7)); } |
BasicSortedSetN extends BasicConstSortedSet<E> { @Override public ConstSortedSet<E> withoutAll(Collection<?> c) { if (c.isEmpty()) { return this; } Object[] shrunk = deleteAll(elements, c); return shrunk.length == size() ? this : condenseToSortedSet(comparator, shrunk); } @SuppressWarnings("unchecked") BasicSortedSetN(Comparator<? super E> comparator, Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstSortedSet<Integer> set; set = new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 6}); compare_sorted_sets(newSortedSet(null, 2, 4, 5), set.withoutAll(Arrays.asList(1, 3, 6))); compare_sorted_sets(newSortedSet(null, 2, 4, 5), set.withoutAll(Arrays.asList(1, 3, 9, -1, 6))); assertSame(set, set.withoutAll(Arrays.asList(7))); assertSame(set, set.withoutAll(Arrays.asList())); assertEquals(BasicSortedSet0.<Integer>instance(null), set.withoutAll(set)); set = new BasicSortedSetN<>(reverseOrder(), new Object[] {6, 5, 4, 3, 2, 1}); compare_sorted_sets(newSortedSet(reverseOrder(), 5, 4, 2), set.withoutAll(Arrays.asList(1, 3, 6))); compare_sorted_sets(newSortedSet(reverseOrder(), 5, 4, 2), set.withoutAll(Arrays.asList(1, 3, 9, -1, 6))); assertSame(set, set.withoutAll(Arrays.asList(7))); assertSame(set, set.withoutAll(Arrays.asList())); assertEquals(BasicSortedSet0.<Integer>instance(reverseOrder()), set.withoutAll(set)); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 6}).withoutAll(null); } |
BasicSortedSetN extends BasicConstSortedSet<E> { @Override E get(int index) { return elements[index]; } @SuppressWarnings("unchecked") BasicSortedSetN(Comparator<? super E> comparator, Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override E first(); @Override E last(); @Override Object[] toArray(); @Override ConstSortedSet<E> with(E e); @Override ConstSortedSet<E> withAll(Collection<? extends E> c); @Override ConstSortedSet<E> without(Object o); @Override ConstSortedSet<E> withoutAll(Collection<?> c); @Override ConstSortedSet<E> headSet(E toElement); @Override ConstSortedSet<E> tailSet(E fromElement); @Override ConstSortedSet<E> subSet(E fromElement, E toElement); @Override int hashCode(); } | @Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get() { new BasicSortedSetN<>(null, new Object[] {1, 2, 3, 4, 5, 6}).get(7); } |
BasicSetN extends BasicConstSet<E> { @Override public ConstSet<E> with(E e) { return contains(e) ? this : new BasicSetN<E>(insert(elements, elements.length, e)); } @SuppressWarnings("unchecked") BasicSetN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_with() { ConstSet<Integer> set; set = new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_sets(newSet(1, 2, 3, 4, 5, 6, 7), set.with(7)); compare_sets(newSet(1, 2, 3, 4, 5, 6, null), set.with(null)); assertSame(set, set.with(6)); set = new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, null}); assertSame(set, set.with(null)); } |
BasicSetN extends BasicConstSet<E> { @Override public ConstSet<E> withAll(Collection<? extends E> c) { if (c.isEmpty()) { return this; } Object[] expanded = unionInto(elements, c.toArray()); return expanded.length == size() ? this : new BasicSetN<E>(expanded); } @SuppressWarnings("unchecked") BasicSetN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_withAll() { ConstSet<Integer> set = new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_sets(newSet(1, 2, 3, 4, 5, 6, 7), set.withAll(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1))); assertSame(set, set.withAll(Arrays.asList(1, 1, 1, 2, 2, 2, 3, 3))); assertSame(set, set.withAll(Collections.<Integer>emptyList())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}).withAll(null); } |
TypeTable { synchronized Map<String, Type> schemaTypes(Class<?> schema) { Map<String, Type> map = new HashMap<>(); Map<Name, String> names = namingPolicy.getNames(schema); Map<Name, String> simpleNames = namingPolicy.getSimpleNames(schema); Class<?> targetGrain = getGrainClass(schema); Class<?> targetBuilder = getGrainBuilderClass(schema); map.put("targetSchema", schema); map.put("targetGrain", targetGrain); map.put("targetBuilder", targetBuilder); ClassHandle targetFactory = loadOrCreateClass(names.get(Name.factory), Enum.class); ClassHandle targetGrainImpl = loadOrCreateNested(names.get(Name.grainImpl), simpleNames.get(Name.grainImpl), targetFactory); ClassHandle targetGrainProxy = loadOrCreateNested(names.get(Name.grainProxy), simpleNames.get(Name.grainProxy), targetFactory); ClassHandle targetBuilderImpl = loadOrCreateNested(names.get(Name.builderImpl), simpleNames.get(Name.builderImpl), targetFactory); map.put("targetFactory", targetFactory.toClass()); map.put("targetGrainImpl", targetGrainImpl.toClass()); map.put("targetGrainProxy", targetGrainProxy.toClass()); map.put("targetBuilderImpl", targetBuilderImpl.toClass()); return map; } TypeTable(NamingPolicy namingPolicy, TypePolicy typePolicy); } | @Test public void test_schema_types() { TypeTable table = new TypeTable(new NamingPolicy(), ConfigurableTypePolicy.STANDARD); Map<String, Type> schemaTypes = table.schemaTypes(Foo.class); assertSame(Foo.class, schemaTypes.get("targetSchema")); assertEquals("interface com.test.FooGrain", schemaTypes.get("targetGrain").toString()); assertEquals("interface com.test.FooBuilder", schemaTypes.get("targetBuilder").toString()); assertEquals("class com.test.FooFactory", schemaTypes.get("targetFactory").toString()); assertEquals("class com.test.FooFactory$FooGrainImpl", schemaTypes.get("targetGrainImpl").toString()); assertEquals("class com.test.FooFactory$FooGrainProxy", schemaTypes.get("targetGrainProxy").toString()); assertEquals("class com.test.FooFactory$FooBuilderImpl", schemaTypes.get("targetBuilderImpl").toString()); } |
BasicSetN extends BasicConstSet<E> { @Override public ConstSet<E> without(Object o) { int index = ArrayTools.indexOf(o, elements); return index < 0 ? this : BasicCollections.<E>condenseToSet(delete(elements, index)); } @SuppressWarnings("unchecked") BasicSetN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_without() { ConstSet<Integer> set = new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_sets(newSet(2, 3, 4, 5, 6), set.without(1)); compare_sets(newSet(1, 3, 4, 5, 6), set.without(2)); compare_sets(newSet(1, 2, 3, 4, 5), set.without(6)); assertSame(set, set.without(7)); assertSame(set, set.without(null)); } |
BasicSetN extends BasicConstSet<E> { @Override public ConstSet<E> withoutAll(Collection<?> c) { if (c.isEmpty()) { return this; } Object[] shrunk = deleteAll(elements, c); return shrunk.length == size() ? this : BasicCollections.<E>condenseToSet(shrunk); } @SuppressWarnings("unchecked") BasicSetN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstSet<Integer> set = new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}); compare_sets(newSet(3, 4, 5, 6), set.withoutAll(Arrays.asList(1, 2))); compare_sets(newSet(3, 4, 5, 6), set.withoutAll(Arrays.asList(1, 2, 9))); assertSame(set, set.withoutAll(Arrays.asList(7))); assertSame(set, set.withoutAll(Arrays.asList())); assertSame(BasicSet0.instance(), set.withoutAll(set)); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}).withoutAll(null); } |
BasicSetN extends BasicConstSet<E> { @Override E get(int index) { return elements[index]; } @SuppressWarnings("unchecked") BasicSetN(Object[] elements); @Override int size(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get() { new BasicSetN<>(new Object[] {1, 2, 3, 4, 5, 6}).get(7); } |
BasicSet0 extends BasicConstSet<E> { @SuppressWarnings("unchecked") static <E> BasicSet0<E> instance() { return INSTANCE; } private BasicSet0(); @Override int size(); @Override boolean isEmpty(); @Override Iterator<E> iterator(); @Override boolean contains(Object o); @Override boolean containsAll(Collection<?> c); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_comparison() { compare_sets(Collections.emptySet(), BasicSet0.instance()); }
@Test public void test_immutable() { assert_set_immutable(BasicSet0.instance()); }
@Test public void test_serialization() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(BasicSet0.instance()); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0%net.nullschool.collect.basic.SetProxy00000001300xpw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); assertSame(BasicSet0.instance(), in.readObject()); } |
BasicSortedMapN extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> with(K key, V value) { int index = indexOf(key); if (index >= 0) { if (Objects.equals(value, values[index])) { return this; } return new BasicSortedMapN<>(comparator, keys, replace(values, index, value)); } index = flip(index); return new BasicSortedMapN<>(comparator, insert(keys, index, key), insert(values, index, value)); } @SuppressWarnings("unchecked") BasicSortedMapN(Comparator<? super K> comparator, Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_with() { ConstSortedMap<Object, Object> map; map = new BasicSortedMapN<>(null, new Object[] {"a", "b", "c", "e"}, new Object[] {1, 2, 3, 5}); compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5), map.with("d", 4)); compare_sorted_maps(newSortedMap(null, "+", 0, "a", 1, "b", 2, "c", 3, "e", 5), map.with("+", 0)); compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2, "c", 3, "e", 5, "f", 6), map.with("f", 6)); compare_sorted_maps(newSortedMap(null, "a", 1, "b", 9, "c", 3, "e", 5), map.with("b", 9)); assertSame(map, map.with("b", 2)); map = new BasicSortedMapN<>(reverseOrder(), new Object[] {"e", "c", "b", "a"}, new Object[] {5, 3, 2, 1}); compare_sorted_maps(newSortedMap(reverseOrder(), "e", 5, "d", 4, "c", 3, "b", 2, "a", 1), map.with("d", 4)); compare_sorted_maps(newSortedMap(reverseOrder(), "e", 5, "c", 3, "b", 2, "a", 1, "+", 0), map.with("+", 0)); compare_sorted_maps(newSortedMap(reverseOrder(), "f", 6, "e", 5, "c", 3, "b", 2, "a", 1), map.with("f", 6)); compare_sorted_maps(newSortedMap(reverseOrder(), "e", 5, "c", 3, "b", 9, "a", 1), map.with("b", 9)); assertSame(map, map.with("b", 2)); } |
BasicSortedMapN extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map) { if (map.isEmpty()) { return this; } MapColumns mc = copy(map); return condenseToSortedMap(comparator, unionInto(keys, values, mc.keys, mc.values, comparator)); } @SuppressWarnings("unchecked") BasicSortedMapN(Comparator<? super K> comparator, Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_withAll() { ConstSortedMap<Object, Object> map; map = new BasicSortedMapN<>(null, new Object[] {"a", "b", "c", "e"}, new Object[] {1, 2, 3, 5}); compare_sorted_maps( newSortedMap(null, "+", 0, "a", 1, "b", 9, "c", 3, "d", 4, "e", 5, "f", 6), map.withAll(newMap("+", 0, "f", 6, "b", 9, "d", 4))); compare_sorted_maps(map, map.withAll(newMap("a", 1, "b", 2))); assertSame(map, map.withAll(newMap())); map = new BasicSortedMapN<>(reverseOrder(), new Object[] {"e", "c", "b", "a"}, new Object[] {5, 3, 2, 1}); compare_sorted_maps( newSortedMap(reverseOrder(), "f", 6, "e", 5, "d", 4, "c", 3, "b", 9, "a", 1, "+", 0), map.withAll(newMap("+", 0, "f", 6, "b", 9, "d", 4))); compare_sorted_maps(map, map.withAll(newMap("a", 1, "b", 2))); assertSame(map, map.withAll(newMap())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicSortedMapN<>(null, new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}).withAll(null); } |
Cook extends AbstractTypeOperator<Type> { @Override public Type apply(Class<?> clazz) { if (clazz.isArray()) { Type componentType = apply(clazz.getComponentType()); if (!(componentType instanceof Class)) { return new LateGenericArrayType(componentType); } } else if (clazz == Enum.class) { return Enum.class; } else { Type ownerType = isInnerClass(clazz) ? apply(clazz.getEnclosingClass()) : clazz.getEnclosingClass(); TypeVariable<?>[] typeParameters = clazz.getTypeParameters(); if (typeParameters.length > 0 || ownerType instanceof ParameterizedType) { return apply(new LateParameterizedType(clazz, ownerType, typeParameters)); } } return clazz; } @Override Type apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } | @Test public void test_cook() { Cook cook = new Cook(); assertEquals( new TypeToken<Integer>(){}.asType(), cook.apply(new TypeToken<Integer>(){}.asType())); assertEquals( new TypeToken<Integer[]>(){}.asType(), cook.apply(new TypeToken<Integer[]>(){}.asType())); assertEquals( new TypeToken<int[]>(){}.asType(), cook.apply(new TypeToken<int[]>(){}.asType())); assertEquals( new TypeToken<List<?>>(){}.asType(), cook.apply(new TypeToken<List>(){}.asType())); assertEquals( new TypeToken<List<?>[]>(){}.asType(), cook.apply(new TypeToken<List[]>(){}.asType())); assertEquals( new TypeToken<Enum<?>[]>(){}.asType(), cook.apply(new TypeToken<Enum<?>[]>(){}.asType())); assertEquals( new TypeToken<List<?>[][]>(){}.asType(), cook.apply(new TypeToken<List[][]>(){}.asType())); assertEquals( new TypeToken<Map<?, ?>>(){}.asType(), cook.apply(new TypeToken<Map>(){}.asType())); assertEquals( new TypeToken<Enum>(){}.asType(), cook.apply(new TypeToken<Enum>(){}.asType())); assertEquals( new TypeToken<EnumSet<? extends Enum>>(){}.asType(), cook.apply(new TypeToken<EnumSet>(){}.asType())); assertEquals( new TypeToken<ComparatorMap<? extends Comparator, ? extends Comparator>>(){}.asType(), cook.apply(new TypeToken<ComparatorMap>(){}.asType())); assertEquals( new TypeToken<NumberMap<? extends Number, ? extends Number>>(){}.asType(), cook.apply(new TypeToken<NumberMap>(){}.asType())); assertEquals( new TypeToken<NumbersMap<? extends Number, ? extends List<? extends Number>>>(){}.asType(), cook.apply(new TypeToken<NumbersMap>(){}.asType())); assertEquals( new TypeToken<ComplexList1<? extends ComplexList1>>(){}.asType(), cook.apply(new TypeToken<ComplexList1>(){}.asType())); assertEquals( new TypeToken<ComplexList2<? extends List<? extends List>>>(){}.asType(), cook.apply(new TypeToken<ComplexList2>(){}.asType())); assertEquals( new TypeToken<ComplexMap1<? extends List<? extends List>, ? extends List<? extends List>>>(){}.asType(), cook.apply(new TypeToken<ComplexMap1>(){}.asType())); assertEquals( new TypeToken<ComplexMap2<? extends List<? extends List>, ? extends List<? extends List>>>(){}.asType(), cook.apply(new TypeToken<ComplexMap2>(){}.asType())); assertEquals( new TypeToken<ComplexMap5<? extends Number, ? extends Map<? extends Number, ? extends List<? extends Number>>>>(){}.asType(), cook.apply(new TypeToken<ComplexMap5>(){}.asType())); assertEquals( new TypeToken<ComplexMap6<? extends Number, ? extends Map<? super Number, ? super List<? extends Number>>>>(){}.asType(), cook.apply(new TypeToken<ComplexMap6>(){}.asType())); assertEquals( new TypeToken<Outer<? extends Number>.Inner0>(){}.asType(), cook.apply(new TypeToken<Outer.Inner0>(){}.asType())); assertEquals( new TypeToken<Outer<? extends Number>.Inner1<? extends Number>>(){}.asType(), cook.apply(new TypeToken<Outer.Inner1>(){}.asType())); } |
BasicSortedMapN extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> without(Object key) { int index = indexOf(key); return index < 0 ? this : BasicCollections.<K, V>condenseToSortedMap(comparator, delete(keys, index), delete(values, index)); } @SuppressWarnings("unchecked") BasicSortedMapN(Comparator<? super K> comparator, Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test public void test_without() { ConstSortedMap<Object, Object> map; map = new BasicSortedMapN<>(null, new Object[] {"a", "b", "c", "e"}, new Object[] {1, 2, 3, 5}); compare_sorted_maps(newSortedMap(null, "b", 2, "c", 3, "e", 5), map.without("a")); compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2, "e", 5), map.without("c")); compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2, "c", 3), map.without("e")); assertSame(map, map.without("+")); assertSame(map, map.without("d")); assertSame(map, map.without("f")); map = new BasicSortedMapN<>(reverseOrder(), new Object[] {"e", "c", "b", "a"}, new Object[] {5, 3, 2, 1}); compare_sorted_maps(newSortedMap(reverseOrder(), "e", 5, "c", 3, "b", 2), map.without("a")); compare_sorted_maps(newSortedMap(reverseOrder(), "e", 5, "b", 2, "a", 1), map.without("c")); compare_sorted_maps(newSortedMap(reverseOrder(), "c", 3, "b", 2, "a", 1), map.without("e")); assertSame(map, map.without("+")); assertSame(map, map.without("d")); assertSame(map, map.without("f")); } |
BasicSortedMapN extends BasicConstSortedMap<K, V> { @Override public ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete) { if (keysToDelete.isEmpty()) { return this; } return condenseToSortedMap(comparator, deleteAll(keys, values, keysToDelete)); } @SuppressWarnings("unchecked") BasicSortedMapN(Comparator<? super K> comparator, Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicSortedMapN<>(null, new Object[] {"a", "b", "c", "d"}, new Object[] {1, 2, 3, 4}).withoutAll(null); } |
BasicSortedMapN extends BasicConstSortedMap<K, V> { @Override K getKey(int index) { return keys[index]; } @SuppressWarnings("unchecked") BasicSortedMapN(Comparator<? super K> comparator, Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_key() { new BasicSortedMapN<>(null, new Object[] {"1", "2", "3", "4"}, new Object[] {1, 2, 3, 4}).getKey(5); } |
BasicSortedMapN extends BasicConstSortedMap<K, V> { @Override V getValue(int index) { return values[index]; } @SuppressWarnings("unchecked") BasicSortedMapN(Comparator<? super K> comparator, Object[] keys, Object[] values); @Override int size(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keysToDelete); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override int hashCode(); } | @Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get_value() { new BasicSortedMapN<>(null, new Object[] {"1", "2", "3", "4"}, new Object[] {1, 2, 3, 4}).getValue(5); } |
BasicMap0 extends BasicConstMap<K, V> { @SuppressWarnings("unchecked") static <K, V> BasicMap0<K, V> instance() { return INSTANCE; } private BasicMap0(); @Override int size(); @Override boolean isEmpty(); @Override MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override ConstSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstMap<K, V> with(K key, V value); @Override ConstMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstMap<K, V> without(Object key); @Override ConstMap<K, V> withoutAll(Collection<?> keys); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_comparison() { compare_maps(Collections.emptyMap(), BasicMap0.instance()); }
@Test public void test_immutable() { assert_map_immutable(BasicMap0.instance()); }
@Test public void test_serialization() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(BasicMap0.instance()); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0%net.nullschool.collect.basic.MapProxy00000001300xpw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); assertSame(BasicMap0.instance(), in.readObject()); } |
BasicConstMap extends AbstractIterableMap<K, V> implements ConstMap<K, V>, Serializable { @Deprecated @Override public final V put(K key, V value) { throw unsupported(); } BasicConstMap(); @Override MapIterator<K, V> iterator(); @Override abstract ConstSet<K> keySet(); @Override abstract ConstCollection<V> values(); @Override abstract ConstSet<Map.Entry<K, V>> entrySet(); @Deprecated @Override final V put(K key, V value); @Deprecated @Override final void putAll(Map<? extends K, ? extends V> map); @Deprecated @Override final V remove(Object key); @Deprecated @Override final void clear(); } | @Test public void test_publicInterfaceRef_annotation_present() { Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < 15; i++) { assertSame( BasicConstMap.class, asMap(map).getClass().getAnnotation(PublicInterfaceRef.class).value()); map.put(i, i); } } |
BasicSortedMap0 extends BasicConstSortedMap<K, V> { @SuppressWarnings("unchecked") static <K, V> BasicSortedMap0<K, V> instance(Comparator<? super K> comparator) { return comparator == null ? NATURAL_INSTANCE : new BasicSortedMap0<>(comparator); } private BasicSortedMap0(Comparator<? super K> comparator); @Override int size(); @Override boolean isEmpty(); @Override MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override K firstKey(); @Override K lastKey(); @Override ConstSortedSet<K> keySet(); @Override ConstCollection<V> values(); @Override ConstSet<Entry<K, V>> entrySet(); @Override ConstSortedMap<K, V> with(K key, V value); @Override ConstSortedMap<K, V> withAll(Map<? extends K, ? extends V> map); @Override ConstSortedMap<K, V> without(Object key); @Override ConstSortedMap<K, V> withoutAll(Collection<?> keys); @Override ConstSortedMap<K, V> headMap(K toKey); @Override ConstSortedMap<K, V> tailMap(K fromKey); @Override ConstSortedMap<K, V> subMap(K fromKey, K toKey); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_comparison() { compare_sorted_maps(newSortedMap(null), BasicSortedMap0.instance(null), "a", "b"); compare_sorted_maps(newSortedMap(reverseOrder()), BasicSortedMap0.instance(reverseOrder()), "a", "b"); }
@Test public void test_immutable() { assert_sorted_map_immutable(BasicSortedMap0.instance(null)); }
@Test public void test_serialization() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); ConstSortedMap<Object, Object> map = BasicSortedMap0.instance(null); out.writeObject(map); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0+net.nullschool.collect.basic.SortedMapProxy00000001300xppw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); assertSame(map, in.readObject()); }
@Test public void test_serialization_with_comparator() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); ConstSortedMap<Object, Object> map = BasicSortedMap0.instance(reverseOrder()); out.writeObject(map); byte[] data = baos.toByteArray(); assertEquals( "aced05sr0+net.nullschool.collect.basic.SortedMapProxy00000001300xpsr0'" + "java.util.Collections$ReverseComparatord48af0SNJd0200xpw40000x", BasicToolsTest.asReadableString(data)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); ConstSortedMap<?, ?> read = (ConstSortedMap)in.readObject(); compare_sorted_maps(map, read); assertSame(map.getClass(), read.getClass()); } |
GrainTools { public static GrainFactory factoryFor(Class<?> clazz) { GrainFactoryRef ref = clazz.getAnnotation(GrainFactoryRef.class); if (ref != null) { return factoryInstance(ref.value()); } if (GrainFactory.class.isAssignableFrom(clazz)) { return factoryInstance(clazz.asSubclass(GrainFactory.class)); } throw new IllegalArgumentException("cannot find factory for " + clazz); } private GrainTools(); static String targetPackageOf(Class<?> schema); static GrainFactory factoryFor(Class<?> clazz); static ConstMap<String, GrainProperty> asPropertyMap(GrainProperty... properties); } | @Test public void test_factoryFor() { assertSame(MockGrainFactory.INSTANCE, factoryFor(MockGrain.class)); assertSame(MockGrainFactory.INSTANCE, factoryFor(MockGrainFactory.class)); assertSame(MyFactory.FACTORY, factoryFor(MyFactory.class)); } |
BasicSet1 extends BasicConstSet<E> { @Override public ConstSet<E> with(E e) { return contains(e) ? this : new BasicSetN<E>(new Object[] {e0, e}); } @SuppressWarnings("unchecked") BasicSet1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_with() { ConstSet<Integer> set; set = new BasicSet1<>(1); compare_sets(newSet(1, 2), set.with(2)); compare_sets(newSet(1, null), set.with(null)); assertSame(set, set.with(1)); set = new BasicSet1<>(null); assertSame(set, set.with(null)); } |
BasicSet1 extends BasicConstSet<E> { @Override public ConstSet<E> withAll(Collection<? extends E> c) { if (c.isEmpty()) { return this; } Object[] expanded = unionInto(new Object[] {e0}, c.toArray()); return expanded.length == size() ? this : BasicCollections.<E>condenseToSet(expanded); } @SuppressWarnings("unchecked") BasicSet1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_withAll() { ConstSet<Integer> set = new BasicSet1<>(1); compare_sets(newSet(1, 2, 3), set.withAll(Arrays.asList(1, 2, 3, 3, 2, 1))); assertSame(set, set.withAll(Arrays.asList(1, 1, 1, 1, 1, 1))); assertSame(set, set.withAll(Collections.<Integer>emptyList())); }
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicSet1<>(1).withAll(null); } |
BasicSet1 extends BasicConstSet<E> { @Override public ConstSet<E> without(Object o) { return !contains(o) ? this : BasicCollections.<E>emptySet(); } @SuppressWarnings("unchecked") BasicSet1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_without() { ConstSet<Integer> set = new BasicSet1<>(1); assertSame(BasicSet0.instance(), set.without(1)); assertSame(set, set.without(2)); assertSame(set, set.without(null)); } |
BasicSet1 extends BasicConstSet<E> { @Override public ConstSet<E> withoutAll(Collection<?> c) { return !c.contains(e0) ? this : BasicCollections.<E>emptySet(); } @SuppressWarnings("unchecked") BasicSet1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_withoutAll() { ConstSet<Integer> set = new BasicSet1<>(1); assertSame(BasicSet0.instance(), set.withoutAll(Arrays.asList(1))); assertSame(BasicSet0.instance(), set.withoutAll(Arrays.asList(2, 1))); assertSame(set, set.withoutAll(Arrays.asList(2))); assertSame(set, set.withoutAll(Arrays.asList())); }
@Test(expected = NullPointerException.class) public void test_withoutAll_throws() { new BasicSet1<>(1).withoutAll(null); } |
BasicSet1 extends BasicConstSet<E> { @Override E get(int index) { if (index == 0) { return e0; } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicSet1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override ConstSet<E> with(E e); @Override ConstSet<E> withAll(Collection<? extends E> c); @Override ConstSet<E> without(Object o); @Override ConstSet<E> withoutAll(Collection<?> c); @Override int hashCode(); } | @Test public void test_get() { assertEquals(1, new BasicSet1<>(1).get(0)); }
@Test(expected = IndexOutOfBoundsException.class) public void test_out_of_bounds_get() { new BasicSet1<>(1).get(1); } |
ConfigurableTypePolicy implements TypePolicy { public ConfigurableTypePolicy withImmutableMapping(Class<?> from, Class<?> to) { if (!from.isAssignableFrom(to)) { throw new IllegalArgumentException(String.format("%s is not a supertype of %s", from, to)); } ConfigurableTypePolicy result = new ConfigurableTypePolicy(this); result.mappings.put(from, to); return result.registerTypes(Arrays.asList(to)); } private ConfigurableTypePolicy(); private ConfigurableTypePolicy(ConfigurableTypePolicy source); Set<Class<?>> getImmutableTypes(); Map<Class<?>, Class<?>> getImmutableMappings(); ConfigurableTypePolicy withImmutableTypes(Collection<? extends Class<?>> types); ConfigurableTypePolicy withImmutableTypes(Class<?>... types); ConfigurableTypePolicy withImmutableMapping(Class<?> from, Class<?> to); @Override boolean isImmutableType(Class<?> clazz); @Override Class<?> asImmutableType(Class<?> clazz); @Override Transform<T> newTransform(TypeToken<T> token); static final ConfigurableTypePolicy EMPTY; static final ConfigurableTypePolicy STANDARD; } | @Test(expected = IllegalArgumentException.class) public void test_bad_mapping_not_related() { ConfigurableTypePolicy.EMPTY.withImmutableMapping(Set.class, ConstMap.class); }
@Test(expected = IllegalArgumentException.class) public void test_bad_mapping_not_narrowing() { ConfigurableTypePolicy.EMPTY.withImmutableMapping(ConstSet.class, Set.class); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public V put(K key, V value) { throw new UnsupportedOperationException(); } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_map_put() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3); Map<String, Integer> actual = new MockIterableMap<>(expected); put(expected, actual, "d", 4); compare_maps(expected, actual); put(expected, actual, "a", -1); compare_maps(expected, actual); put(expected, actual, null, 10); compare_maps(expected, actual); put(expected, actual, null, 11); compare_maps(expected, actual); put(expected, actual, "e", null); compare_maps(expected, actual); put(expected, actual, "e", 5); compare_maps(expected, actual); }
@Test public void test_map_put_null_entry() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3); Map<String, Integer> actual = new MockIterableMap<>(expected); put(expected, actual, null, null); compare_maps(expected, actual); }
@Test(expected = UnsupportedOperationException.class) public void test_map_put_throws() { @SuppressWarnings("unchecked") IterableMap<Object, Object> map = mock(AbstractIterableMap.class); given(map.put(any(), any())).willCallRealMethod(); map.put(new Object(), new Object()); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public void putAll(Map<? extends K, ? extends V> map) { if (map instanceof IterableMap) { for (MapIterator<? extends K, ? extends V> iter = iteratorFor(map); iter.hasNext();) { put(iter.next(), iter.value()); } } else { for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } } } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_map_putAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3); Map<String, Integer> actual = new MockIterableMap<>(expected); putAll(expected, actual, "a", -1, "d", 4); compare_maps(expected, actual); putAll(expected, actual, "e", null, null, 10); compare_maps(expected, actual); expected.putAll(Collections.<String, Integer>emptyMap()); actual.putAll(Collections.<String, Integer>emptyMap()); compare_maps(expected, actual); }
@Test public void test_map_putAll_iterableMap() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3); Map<String, Integer> actual = new MockIterableMap<>(expected); IterableMap<String, Integer> im = new MockIterableMap<>(singletonMap("x", 0)); expected.putAll(im); actual.putAll(im); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_map_null_putAll() { new MockIterableMap<>().putAll(null); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public V remove(Object key) { for (MapIterator<K, V> iter = iterator(); iter.hasNext();) { if (Objects.equals(key, iter.next())) { V value = iter.value(); iter.remove(); return value; } } return null; } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_map_remove() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, null, 4); Map<String, Integer> actual = new MockIterableMap<>(expected); remove(expected, actual, "c"); compare_maps(expected, actual); remove(expected, actual, "x"); compare_maps(expected, actual); remove(expected, actual, null); compare_maps(expected, actual); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public void clear() { for (MapIterator<K, V> iter = iterator(); iter.hasNext();) { iter.next(); iter.remove(); } } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_map_clear() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3); Map<String, Integer> actual = new MockIterableMap<>(expected); expected.clear(); actual.clear(); compare_maps(expected, actual); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public abstract MapIterator<K, V> iterator(); @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_map_entry_setValue() { IterableMap<String, Integer> map = new MockIterableMap<>(singletonMap("a", 1)); for (MapIterator<String, Integer> iter = map.iterator(); iter.hasNext();) { iter.next(); iter.entry().setValue(9); } compare_maps(singletonMap("a", 9), map); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public Set<K> keySet() { return new KeysView(); } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_keySet_removeAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, null, 4); IterableMap<String, Integer> actual = new MockIterableMap<>(expected); removeAll(expected.keySet(), actual.keySet(), "a", "c", null, "d"); compare_maps(expected, actual); removeAll(expected.keySet(), actual.keySet(), new String[0]); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_keySet_removeAll_throws() { new MockIterableMap<>(singletonMap("a", 1)).keySet().removeAll(null); }
@Test public void test_keySet_retainAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, null, 4); IterableMap<String, Integer> actual = new MockIterableMap<>(expected); retainAll(expected.keySet(), actual.keySet(), "a", "c", null, "d"); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_keySet_retainAll_throws() { new MockIterableMap<>(singletonMap("a", 1)).keySet().retainAll(null); }
@Test(expected = UnsupportedOperationException.class) public void test_keySet_add_throws() { new MockIterableMap<>().keySet().add("a"); }
@Test(expected = UnsupportedOperationException.class) public void test_keySet_addAll_throws() { new MockIterableMap<>().keySet().addAll(Arrays.asList("a")); } |
AbstractIterableMap implements IterableMap<K, V> { @Override public Collection<V> values() { return new ValuesView(); } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_values_removeAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, "d", null, "x", 1); IterableMap<String, Integer> actual = new MockIterableMap<>(expected); removeAll(expected.values(), actual.values(), 1, 3, null, 5); compare_maps(expected, actual); removeAll(expected.values(), actual.values(), new Integer[0]); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_values_removeAll_throws() { new MockIterableMap<>(singletonMap("a", 1)).values().removeAll(null); }
@Test public void test_values_retainAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, "d", null, "x", 1); IterableMap<String, Integer> actual = new MockIterableMap<>(expected); retainAll(expected.values(), actual.values(), 1, 3, null, 5); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_values_retainAll_throws() { new MockIterableMap<>(singletonMap("a", 1)).values().retainAll(null); }
@Test(expected = UnsupportedOperationException.class) public void test_values_add_throws() { new MockIterableMap<>().values().add(1); }
@Test(expected = UnsupportedOperationException.class) public void test_values_addAll_throws() { new MockIterableMap<>().values().addAll(Arrays.asList(1)); } |
ConfigurableTypePolicy implements TypePolicy { @Override public <T> Transform<T> newTransform(TypeToken<T> token) { Type type = token.asType(); if (type instanceof Class) { @SuppressWarnings("unchecked") final Class<T> clazz = (Class<T>)type; return new CastingTransform<>(clazz); } if (type instanceof ParameterizedType) { @SuppressWarnings("unchecked") final Class<T> erasure = (Class<T>)erase(type); return new CastingTransform<>(erasure); } throw new IllegalArgumentException("Cannot create transform for: " + print(type)); } private ConfigurableTypePolicy(); private ConfigurableTypePolicy(ConfigurableTypePolicy source); Set<Class<?>> getImmutableTypes(); Map<Class<?>, Class<?>> getImmutableMappings(); ConfigurableTypePolicy withImmutableTypes(Collection<? extends Class<?>> types); ConfigurableTypePolicy withImmutableTypes(Class<?>... types); ConfigurableTypePolicy withImmutableMapping(Class<?> from, Class<?> to); @Override boolean isImmutableType(Class<?> clazz); @Override Class<?> asImmutableType(Class<?> clazz); @Override Transform<T> newTransform(TypeToken<T> token); static final ConfigurableTypePolicy EMPTY; static final ConfigurableTypePolicy STANDARD; } | @Test public void test_class_transform() { ConfigurableTypePolicy policy = ConfigurableTypePolicy.EMPTY; Transform<Long> transform = policy.newTransform(new TypeToken<Long>(){}); Object o = transform.apply(1L); assertEquals(1L, o); try { transform.apply(1); fail(); } catch (ClassCastException expected) {} }
@Test public void test_list_transform() { ConfigurableTypePolicy policy = ConfigurableTypePolicy.EMPTY; Transform<List<String>> transform = policy.newTransform(new TypeToken<List<String>>(){}); Object o = transform.apply(listOf("a")); assertEquals(listOf("a"), o); try { transform.apply(setOf("a")); fail(); } catch (ClassCastException expected) {} List<String> list = transform.apply(listOf(1)); try { System.out.println(list.get(0)); fail(); } catch (ClassCastException darn) {} } |
AbstractIterableMap implements IterableMap<K, V> { @Override public Set<Entry<K, V>> entrySet() { return new EntriesView(); } @Override abstract int size(); @Override boolean isEmpty(); @Override abstract MapIterator<K, V> iterator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(Object key); @Override void clear(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); } | @Test public void test_entrySet_removeAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, "d", null, null, 5); IterableMap<String, Integer> actual = new MockIterableMap<>(expected); removeAll( expected.entrySet(), actual.entrySet(), newEntry("a", 1), newEntry("d", (Integer)null), newEntry((String)null, 5), newEntry("c", 4), newEntry("x", 2), newEntry("z", 9)); compare_maps(expected, actual); removeAll(expected.entrySet(), actual.entrySet()); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_entrySet_removeAll_throws() { new MockIterableMap<>(singletonMap("a", 1)).entrySet().removeAll(null); }
@Test public void test_entrySet_retainAll() { Map<String, Integer> expected = newMap("a", 1, "b", 2, "c", 3, "d", null, null, 5); IterableMap<String, Integer> actual = new MockIterableMap<>(expected); retainAll( expected.entrySet(), actual.entrySet(), newEntry("a", 1), newEntry("d", (Integer)null), newEntry((String)null, 5), newEntry("c", 4), newEntry("x", 2), newEntry("z", 9)); compare_maps(expected, actual); }
@Test(expected = NullPointerException.class) public void test_entrySet_retainAll_throws() { new MockIterableMap<>(singletonMap("a", 1)).entrySet().retainAll(null); }
@Test(expected = UnsupportedOperationException.class) public void test_entrySet_add_throws() { new MockIterableMap<String, Integer>().entrySet().add(newEntry("a", 1)); }
@Test(expected = UnsupportedOperationException.class) public void test_entrySet_addAll_throws() { new MockIterableMap<String, Integer>().entrySet().addAll(Arrays.asList(newEntry("a", 1))); } |
AbstractEntry implements Map.Entry<K, V> { public static int hashCode(Object key, Object value) { return Objects.hashCode(key) ^ Objects.hashCode(value); } static int hashCode(Object key, Object value); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_hashCode() { assertEquals(new SimpleImmutableEntry<>("a", 1).hashCode(), AbstractEntry.hashCode("a", 1)); assertEquals(new SimpleImmutableEntry<>("a", 1).hashCode(), mockEntry("a", 1).hashCode()); assertEquals(new SimpleImmutableEntry<>(null, null).hashCode(), AbstractEntry.hashCode(null, null)); assertEquals(new SimpleImmutableEntry<>(null, null).hashCode(), mockEntry(null, null).hashCode()); } |
AbstractEntry implements Map.Entry<K, V> { @Override public String toString() { return Objects.toString(getKey()) + '=' + Objects.toString(getValue()); } static int hashCode(Object key, Object value); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | @Test public void test_toString() { assertEquals(new SimpleImmutableEntry<>("a", 1).toString(), mockEntry("a", 1).toString()); assertEquals(new SimpleImmutableEntry<>(null, null).toString(), mockEntry(null, null).toString()); } |
MapTools { public static <K, V> Map<K, V> interleave(K[] keys, V[] values) { int length = min(keys.length, values.length); LinkedHashMap<K, V> map = new LinkedHashMap<>(goodInitialCapacity(length)); for (int i = 0; i < length; i++) { map.put(keys[i], values[i]); } return map; } private MapTools(); static Map<K, V> interleave(K[] keys, V[] values); static T putAll(T dest, Map<? extends K, ? extends V> map); static T removeAll(T map, Collection<?> keys); } | @Test public void test_interleave() { assertEquals("{a=1}", interleave(new String[] {"a"}, new Integer[] {1}).toString()); assertEquals("{a=1, b=2}", interleave(new String[] {"a", "b"}, new Integer[] {1, 2}).toString()); assertEquals("{a=2}", interleave(new String[] {"a", "a"}, new Integer[] {1, 2}).toString()); assertEquals("{a=1}", interleave(new String[] {"a", "b"}, new Integer[] {1}).toString()); assertEquals("{a=1}", interleave(new String[] {"a"}, new Integer[] {1, 2}).toString()); assertEquals("{}", interleave(new String[] {}, new Integer[] {}).toString()); }
@Test(expected = NullPointerException.class) public void test_bad_interleave() { interleave(new String[] {}, null); }
@Test(expected = NullPointerException.class) public void test_bad_interleave_2() { interleave(null, new Integer[] {}); } |
SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | @Test public void test_collectProperties_multiple_levels() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(Organism.class); assertEquals(1, result.size()); assertEquals("id", result.get(0).getName()); assertEquals(int.class, result.get(0).getType()); assertTrue(result.get(0).getFlags().isEmpty()); result = collectProperties(Animal.class); assertEquals(3, result.size()); assertEquals("vertebrate", result.get(0).getName()); assertEquals(boolean.class, result.get(0).getType()); assertEquals(GrainProperty.Flag.IS_PROPERTY, result.get(0).getFlags().iterator().next()); assertEquals("id", result.get(1).getName()); assertEquals(int.class, result.get(1).getType()); assertTrue(result.get(1).getFlags().isEmpty()); assertEquals("parent", result.get(2).getName()); assertEquals(UUID.class, result.get(2).getType()); assertTrue(result.get(2).getFlags().isEmpty()); }
@Test public void test_collectProperties_multiple_level_raw_generic() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(RawDescendant.class); assertEquals(1, result.size()); assertEquals("parent", result.get(0).getName()); assertEquals(new LateTypeVariable<>("T", Descendant.class), result.get(0).getType()); assertTrue(result.get(0).getFlags().isEmpty()); }
@Test public void test_collectProperties_composite_type_with_diamond() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(C.class); assertEquals(3, result.size()); assertEquals("c", result.get(0).getName()); assertEquals("a", result.get(1).getName()); assertEquals("b", result.get(2).getName()); result = collectProperties(E.class); assertEquals(5, result.size()); assertEquals("e", result.get(0).getName()); assertEquals("c", result.get(1).getName()); assertEquals("d", result.get(2).getName()); assertEquals("a", result.get(3).getName()); assertEquals("b", result.get(4).getName()); }
@Test public void test_collectProperties_with_duplicate_property_names() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(R.class); assertEquals(3, result.size()); assertEquals(R.class, result.get(0).getType()); assertEquals(P.class, result.get(1).getType()); assertEquals(Q.class, result.get(2).getType()); }
@Test public void test_collectProperties_with_narrowest_type_in_upper_level() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(W.class); assertEquals(3, result.size()); assertEquals(Object.class, result.get(0).getType()); assertEquals(Integer.class, result.get(1).getType()); assertEquals(Number.class, result.get(2).getType()); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.