@Override public Page<T> findAll(final Set<T> groups, final String criteria, final Pageable pageable, final Map<String, Comparator<T>> customComparators) { // Create the set with the right comparator final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator()); orders.add(DEFAULT_ORDER); final Sort.Order order = orders.get(0); Comparator<T> comparator = customComparators.get(order.getProperty()); if (order.getDirection() == Direction.DESC) { comparator = Collections.reverseOrder(comparator); } final Set<T> result = new TreeSet<>(comparator); // Filter the groups, filtering by the criteria addFilteredByPattern(groups, criteria, result); // Apply in-memory pagination return inMemoryPagination.newPage(result, pageable); }
/** * Just received a locked message. Must acknowledge it. * * @param from * The node that sent the locked message. * @param to * The node that must acknowledge the locked message. */ private void receiveLocked(Node from, Node to) { MUnlockBroadcast mu = new MUnlockBroadcast(from, to); Transport t = ((Transport) this.node.getProtocol(FastConfig.getTransport(PreventiveCausalBroadcast.pid))); APeerSampling ps = (APeerSampling) this.node.getProtocol(FastConfig.getLinkable(PreventiveCausalBroadcast.pid)); List<Node> neighborhood = IteratorUtils.toList(ps.getAliveNeighbors().iterator()); if (neighborhood.contains(from)) { t.send(this.node, from, mu, PreventiveCausalBroadcast.pid); } else { // just to check if it cannot send message because it has no PreventiveCausalBroadcast fcb = (PreventiveCausalBroadcast) from.getProtocol(PreventiveCausalBroadcast.pid); if (fcb.buffers.containsKey(to)) { System.out.println("NOT COOL"); } } }
public ProjectConfigurationBuilder(ProjectConfiguration projectConfiguration) { if (projectConfiguration == null) { admins = new ArrayList<>(); users = new ArrayList<>(); stackConfigurations = new HashSet<>(); } else { identifier = projectConfiguration.getIdentifier(); entityIdentifier = projectConfiguration.getEntityIdentifier(); name = projectConfiguration.getName(); userService = projectConfiguration.getUserService(); admins = IteratorUtils.toList(projectConfiguration.getTeamLeaders()); users = IteratorUtils.toList(projectConfiguration.getUsers()); stackConfigurations = new HashSet<>(projectConfiguration.getStackConfigurations()); } }
public RightEndpointActor() { receive(ReceiveBuilder.match(UserAdminRightRequestMsg.class, msg -> { ProjectConfiguration projectConfiguration = msg.projectConfiguration; User user = msg.getRequester(); List<User> users = IteratorUtils.toList(projectConfiguration.getTeamLeaders()); boolean valid = false; if (CollectionUtils.isNotEmpty(users)) { if (LOGGER.isDebugEnabled()) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create(); LOGGER.debug("lookup right for user Id '{}' on following projectConfig:\n{}", user.getIdentifier(), gson.toJson(projectConfiguration)); } valid = users.stream().filter(u -> u.getIdentifier().equals(user.getIdentifier())).findFirst().isPresent(); } sender().tell(new RightRequestResultMsg(user, msg, valid), self()); getContext().stop(self()); }) .matchAny(this::unhandled).build()); }
@Override public void removeUserToOrganisation(String userIdentifier, String organisationIdentifier) { if (isBlank(userIdentifier)) { throw new IllegalArgumentException("userIdentifier must be defined."); } if (isBlank(organisationIdentifier)) { throw new IllegalArgumentException("organisationIdentifier must be defined."); } organisationStore.removeUserToOrganisation(userIdentifier, organisationIdentifier); User user = getUserByIdentifier(userIdentifier); removeUserToOrganisationOnUserRedis(organisationIdentifier, user); OrganisationStoreModel organisationStoreModel = organisationStore.getOrganisationById(organisationIdentifier); organisationStoreModel.getProjectConfigurations().stream() .forEach(projectConfigurationId -> { ProjectConfigurationStoreModel projectConfigurationModel = projectStore.getProjectConfigurationById(projectConfigurationId); ProjectConfiguration projectConfiguration = convertToProjectConfiguration(projectConfigurationModel); ProjectConfigurationBuilder builder = new ProjectConfigurationBuilder(projectConfiguration); List<User> users = IteratorUtils.toList(projectConfiguration.getUsers()); users.remove(user); builder.setUsers(users); updateProjectConfiguration(builder.build()); }); }
@Override public void addAdminToOrganisation(String userIdentifier, String organisationIdentifier) { if (isBlank(userIdentifier)) { throw new IllegalArgumentException("userIdentifier must be defined."); } if (isBlank(organisationIdentifier)) { throw new IllegalArgumentException("organisationIdentifier must be defined."); } User adminUser = getUserByIdentifier(userIdentifier); organisationStore.addAdminToOrganisation(userIdentifier, organisationIdentifier); addUserToOrganisationOnUserRedis(organisationIdentifier, adminUser); OrganisationStoreModel organisationStoreModel = organisationStore.getOrganisationById(organisationIdentifier); organisationStoreModel.getProjectConfigurations().stream() .forEach(projectConfigurationId -> { ProjectConfigurationStoreModel projectConfigurationModel = projectStore.getProjectConfigurationById(projectConfigurationId); ProjectConfiguration projectConfiguration = convertToProjectConfiguration(projectConfigurationModel); ProjectConfigurationBuilder builder = new ProjectConfigurationBuilder(projectConfiguration); List<User> teamLeaders = IteratorUtils.toList(projectConfiguration.getTeamLeaders()); teamLeaders.add(adminUser); builder.setAdmins(teamLeaders); updateProjectConfiguration(builder.build()); }); }
@Override public void removeAdminToOrganisation(String userIdentifier, String organisationIdentifier) { if (isBlank(userIdentifier)) { throw new IllegalArgumentException("userIdentifier must be defined."); } if (isBlank(organisationIdentifier)) { throw new IllegalArgumentException("organisationIdentifier must be defined."); } User adminUser = getUserByIdentifier(userIdentifier); organisationStore.removeAdminToOrganisation(userIdentifier, organisationIdentifier); removeUserToOrganisationOnUserRedis(organisationIdentifier, getUserByIdentifier(userIdentifier)); OrganisationStoreModel organisationStoreModel = organisationStore.getOrganisationById(organisationIdentifier); organisationStoreModel.getProjectConfigurations().stream() .forEach(projectConfigurationId -> { ProjectConfigurationStoreModel projectConfigurationModel = projectStore.getProjectConfigurationById(projectConfigurationId); ProjectConfiguration projectConfiguration = convertToProjectConfiguration(projectConfigurationModel); ProjectConfigurationBuilder builder = new ProjectConfigurationBuilder(projectConfiguration); List<User> teamLeaders = IteratorUtils.toList(projectConfiguration.getTeamLeaders()); teamLeaders.remove(adminUser); builder.setAdmins(teamLeaders); updateProjectConfiguration(builder.build()); } ); }
@Test public void createRegisterSerialisationFormat_returnsRSFFromEntireRegister() { when(register.getItemIterator()).thenReturn(Arrays.asList(item1, item2).iterator()); when(register.getDerivationEntryIterator(IndexFunctionConfiguration.IndexNames.METADATA)).thenReturn(Collections.emptyIterator()); when(register.getEntryIterator()).thenReturn(Arrays.asList(entry1, entry2).iterator()); RegisterProof expectedRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "1231234"), 46464); when(register.getRegisterProof()).thenReturn(expectedRegisterProof); RegisterSerialisationFormat actualRSF = sutCreator.create(register); List<RegisterCommand> actualCommands = IteratorUtils.toList(actualRSF.getCommands()); verify(register, times(1)).getItemIterator(); verify(register, times(1)).getEntryIterator(); verify(register, times(1)).getRegisterProof(); assertThat(actualCommands.size(), equalTo(6)); assertThat(actualCommands, contains( assertEmptyRootHashCommand, addItem1Command, addItem2Command, appendEntry1Command, appendEntry2Command, new RegisterCommand("assert-root-hash", Collections.singletonList("sha-256:1231234")) )); }
@Test public void createRegisterSerialisationFormat_returnsRSFFromEntireIndex() { when(register.getItemIterator()).thenReturn(Arrays.asList(item1, item2).iterator()); when(register.getDerivationEntryIterator(IndexNames.METADATA)).thenReturn(Collections.emptyIterator()); when(register.getDerivationEntryIterator("index")).thenReturn(Arrays.asList(entry1, entry2).iterator()); RegisterSerialisationFormat actualRSF = sutCreator.create(register, "index"); List<RegisterCommand> actualCommands = IteratorUtils.toList(actualRSF.getCommands()); verify(register, times(1)).getItemIterator(); verify(register, times(1)).getDerivationEntryIterator("index"); assertThat(actualCommands.size(), equalTo(5)); assertThat(actualCommands, contains( assertEmptyRootHashCommand, addItem1Command, addItem2Command, appendEntry1Command, appendEntry2Command )); }
@Test public void createRegisterSerialisationFormat_whenCalledWithBoundary_returnsPartialRSFRegister() { RegisterProof oneEntryRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "oneEntryInRegisterHash"), 1); RegisterProof twoEntriesRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "twoEntriesInRegisterHash"), 2); when(register.getItemIterator(1, 2)).thenReturn(Collections.singletonList(item1).iterator()); when(register.getEntryIterator(1, 2)).thenReturn(Collections.singletonList(entry1).iterator()); when(register.getRegisterProof(1)).thenReturn(oneEntryRegisterProof); when(register.getRegisterProof(2)).thenReturn(twoEntriesRegisterProof); RegisterSerialisationFormat actualRSF = sutCreator.create(register, 1, 2); List<RegisterCommand> actualCommands = IteratorUtils.toList(actualRSF.getCommands()); verify(register, times(1)).getItemIterator(1, 2); verify(register, times(1)).getEntryIterator(1, 2); assertThat(actualCommands.size(), equalTo(4)); assertThat(actualCommands, contains( new RegisterCommand("assert-root-hash", Collections.singletonList(oneEntryRegisterProof.getRootHash().encode())), addItem1Command, appendEntry1Command, new RegisterCommand("assert-root-hash", Collections.singletonList(twoEntriesRegisterProof.getRootHash().encode())) )); }
@Test public void createRegisterSerialisationFormat_throwsAnExceptionForUnknownMapperType() throws Exception { when(register.getItemIterator()).thenReturn(Arrays.asList(item1, item2).iterator()); when(register.getDerivationEntryIterator(IndexFunctionConfiguration.IndexNames.METADATA)).thenReturn(Collections.emptyIterator()); when(register.getEntryIterator()).thenReturn(Arrays.asList(entry1, entry2).iterator()); RegisterProof expectedRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "1231234"), 28828); when(register.getRegisterProof()).thenReturn(expectedRegisterProof); expectedException.expect(RuntimeException.class); expectedException.expectMessage("Mapper not registered for class: uk.gov.register.util.HashValue"); RSFCreator creatorWithoutMappers = new RSFCreator(); RegisterSerialisationFormat rsf = creatorWithoutMappers.create(register); IteratorUtils.toList(rsf.getCommands()); }
private Map<PathNodeFilterSet, PathNodeFilterSet> comparePathFilters(final Set<PathNodeFilterSet> filters1, final Set<PathNodeFilterSet> filters2, final Map<Path, Path> pathMap) { if (filters1.size() == 0) return new HashMap<>(); final Iterator<PathNodeFilterSet> iterator = filters1.iterator(); final PathNodeFilterSet filter1 = iterator.next(); iterator.remove(); try { for (final PathNodeFilterSet filter2 : IteratorUtils .asIterable(pool.getEqualFilters(filter1).stream().filter(f -> filters2.contains(f)).iterator())) { final Map<Path, Path> tmpPathMap = new HashMap<>(pathMap); if (PathNodeFilterSet.equals(filter1, filter2, tmpPathMap)) { final Map<PathNodeFilterSet, PathNodeFilterSet> filterMap = comparePathFilters(filters1, filters2, tmpPathMap); if (null != filterMap) { filterMap.put(filter1, filter2); return filterMap; } } } return null; } finally { filters1.add(filter1); } }
/** * Returns input tuples already used in a test case that bind the given variable, considering * only tuples that are (not) once-only */ public Iterator<Tuple> getUsed( VarDef var, final boolean onceOnly) { return getBinds ( IteratorUtils.filteredIterator ( getUsed(), new Predicate<Tuple>() { public boolean evaluate( Tuple tuple) { return tuple.isOnce() == onceOnly; } }), var); }
/** * Returns the set of input variables to be included in this combination. */ public String[] getIncluded() { return IteratorUtils.toArray ( IteratorUtils.transformedIterator ( includedVars_.iterator(), new Transformer<VarNamePattern,String>() { public String transform( VarNamePattern pattern) { return pattern.toString(); } }), String.class); }
/** * Returns the set of input variables to be excluded from this combination. */ public String[] getExcluded() { return IteratorUtils.toArray ( IteratorUtils.transformedIterator ( excludedVars_.iterator(), new Transformer<VarNamePattern,String>() { public String transform( VarNamePattern pattern) { return pattern.toString(); } }), String.class); }
/** * Returns a set of valid {@link TestCaseDef test case definitions} that extend the given base test cases. */ private List<TestCaseDef> getBaseValidCases( FunctionInputDef inputDef, VarTupleSet validTuples, List<TestCaseDef> baseCases) { logger_.debug( "{}: Extending valid base test cases", inputDef); Iterator<TestCaseDef> validBaseCases = IteratorUtils.filteredIterator ( baseCases.iterator(), new Predicate<TestCaseDef>() { public boolean evaluate( TestCaseDef testCase) { return testCase.getInvalidVar() == null; } }); List<TestCaseDef> testCases = extendBaseCases( inputDef, validTuples, validBaseCases); logger_.info( "{}: Extended {} valid base test cases", inputDef, testCases.size()); return testCases; }
/** * Returns true if the given disjunction is universally true. */ public static boolean isTautology( IDisjunct disjunct) { boolean tautology = false; if( disjunct != null) { IAssertion[] assertions = IteratorUtils.toArray( disjunct.getAssertions(), IAssertion.class); int max = assertions.length; int maxCompared = max - 1; for( int compared = 0; !tautology && compared < maxCompared; compared++) { IAssertion assertCompared = assertions[ compared]; for( int other = compared + 1; !tautology && other < max; tautology = assertCompared.negates( assertions[ other++])); } } return tautology; }
/** * Writes the input value definitions for all variables of the given type. */ protected void writeInputs( TestCase testCase, String type) { xmlWriter_.writeTagStart( INPUT_TAG); xmlWriter_.writeAttribute( TYPE_ATR, type); xmlWriter_.writeTagEnd(); xmlWriter_.indent(); VarBinding[] bindings = IteratorUtils.toArray( testCase.getVarBindings( type), VarBinding.class); Arrays.sort( bindings); for( int i = 0; i < bindings.length; i++) { writeBinding( bindings[i]); } xmlWriter_.unindent(); xmlWriter_.writeElementEnd( INPUT_TAG); }
@Test public void getTests_FromBaseTests_Same() { // Given... SystemInputDef systemInputDef = systemInputResources_.read( "system-input-def-4.xml"); FunctionInputDef functionInputDef = systemInputDef.getFunctionInputDef( "Make"); TupleGenerator generator = new TupleGenerator(); generator.addCombiner ( new TupleCombiner(2) .addIncludedVar( "Shape") .addIncludedVar( "Size")); // When... FunctionTestDef baseTestDef = generator.getTests( functionInputDef, null); FunctionTestDef functionTestDef = generator.getTests( functionInputDef, baseTestDef); // Expect... List<TestCase> expectedTestCases = IteratorUtils.toList( baseTestDef.getTestCases()); List<TestCase> actualTestCases = IteratorUtils.toList( functionTestDef.getTestCases()); assertSetEquals( "When base tests same", expectedTestCases, actualTestCases); }
/** * If <CODE>included</CODE> is true, returns the subset of the given set of tuples that are included in at least one test case * from the given test definition. * * Otherwise, if <CODE>included</CODE> is false, returns the subset of the given set of tuples that are not included in any test case. */ private static Collection<Tuple> getTuplesIncluded( Collection<Tuple> tuples, final FunctionTestDef testDef, final boolean included) { return IteratorUtils.toList ( IteratorUtils.filteredIterator ( tuples.iterator(), new Predicate<Tuple>() { public boolean evaluate( final Tuple tuple) { return IteratorUtils.filteredIterator ( testDef.getTestCases(), new Predicate<TestCase>() { public boolean evaluate( TestCase testCase) { return testCaseIncludes( testCase, tuple); } }) .hasNext() == included; } })); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Graph {\n"); Iterator<Integer> it = base.iterator(); while (it.hasNext()) { Integer node = it.next(); sb.append("\t" + get(node) + ": "); @SuppressWarnings("unchecked") List<String> neighbors = IndexUtil.map(IteratorUtils.toList(base.getNeighbors(node)), this); sb.append(StringUtils.join(neighbors, ',')); sb.append("\n"); } sb.append("}\n"); return sb.toString(); }
/** * INTERNAL: Wraps a QueryResultIF instance in a suitable * MapCollection implementation. */ protected Collection getMapCollection(QueryResultIF result) { if (select != null) { int index = result.getIndex(select); if (index < 0) throw new IndexOutOfBoundsException("No query result column named '" + select + "'"); List list = new ArrayList(); while (result.next()) list.add(result.getValue(index)); result.close(); return list; } if (result instanceof net.ontopia.topicmaps.query.impl.basic.QueryResult) // BASIC return net.ontopia.topicmaps.query.impl.basic.QueryResultWrappers.getWrapper(result); else { // FIXME: Should pass collection size if available. return IteratorUtils.toList(new QueryResultIterator(result)); } }
protected Collection<?> getOccurrences(String value, String datatype) { OccurrenceIndexIF index = getIndex(OccurrenceIndexIF.class); try { switch (getAttribute("type").toUpperCase()) { case "VALUE": if (datatype == null) return index.getOccurrences(value); else return index.getOccurrences(value, new URILocator(datatype)); case "PREFIX": if (value == null) throw OntopiaRestErrors.MANDATORY_ATTRIBUTE_IS_NULL.build("value", "String"); if (datatype == null) return index.getOccurrencesByPrefix(value); else return index.getOccurrencesByPrefix(value, new URILocator(datatype)); case "GTE": return IteratorUtils.toList(index.getValuesGreaterThanOrEqual(value)); case "LTE": return IteratorUtils.toList(index.getValuesSmallerThanOrEqual(value)); default: setStatus(Status.CLIENT_ERROR_NOT_FOUND, TYPE_ERROR_MESSAGE); return null; } } catch (MalformedURLException mufe) { throw OntopiaRestErrors.MALFORMED_LOCATOR.build(mufe, datatype); } }
/** * Create Document Outbound only if Status column just changed to Done * * @param jobInstructions */ @ModelChange(timings = { ModelValidator.TYPE_AFTER_CHANGE, ModelValidator.TYPE_AFTER_CHANGE_REPLICATION }, ifColumnsChanged = I_C_Print_Job_Instructions.COLUMNNAME_Status) public void logDocOutbound(final I_C_Print_Job_Instructions jobInstructions) { // We log the doc outbound only when Status changed to Done if (!X_C_Print_Job_Instructions.STATUS_Done.equals(jobInstructions.getStatus())) { return; } final I_AD_User userToPrint = jobInstructions.getAD_User_ToPrint(); final Iterator<I_C_Print_Job_Line> lines = Services.get(IPrintingDAO.class).retrievePrintJobLines(jobInstructions); for (final I_C_Print_Job_Line line : IteratorUtils.asIterable(lines)) { logDocOutbound(line, userToPrint); } }
public void testValuesSmallerThanOrEqual() { assertFalse(ix.getValuesSmallerThanOrEqual("").hasNext()); builder.makeOccurrence(builder.makeTopic(), builder.makeTopic(), "a"); builder.makeOccurrence(builder.makeTopic(), builder.makeTopic(), "b"); builder.makeOccurrence(builder.makeTopic(), builder.makeTopic(), "c"); List<String> values = IteratorUtils.toList(ix.getValuesSmallerThanOrEqual("c")); assertEquals(3, values.size()); assertTrue(values.contains("a")); assertTrue(values.contains("b")); assertTrue(values.contains("c")); values = IteratorUtils.toList(ix.getValuesSmallerThanOrEqual("a")); assertEquals(1, values.size()); assertTrue(values.contains("a")); }
@Override public Page<UserOrg> findAll(final Collection<GroupOrg> requiredGroups, final Set<String> companies, final String criteria, final Pageable pageable) { // Create the set with the right comparator final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator()); orders.add(DEFAULT_ORDER); final Sort.Order order = orders.get(0); Comparator<UserOrg> comparator = ObjectUtils.defaultIfNull(COMPARATORS.get(order.getProperty()), DEFAULT_COMPARATOR); if (order.getDirection() == Direction.DESC) { comparator = Collections.reverseOrder(comparator); } final Set<UserOrg> result = new TreeSet<>(comparator); // Filter the users traversing firstly the required groups and their members, the companies, then the criteria final Map<String, UserOrg> users = findAll(); if (requiredGroups == null) { // No constraint on group addFilteredByCompaniesAndPattern(users.keySet(), companies, criteria, result, users); } else { // User must be within one the given groups for (final GroupOrg requiredGroup : requiredGroups) { addFilteredByCompaniesAndPattern(requiredGroup.getMembers(), companies, criteria, result, users); } } // Apply in-memory pagination return inMemoryPagination.newPage(result, pageable); }
/** * A new neighbors has been added, the link must be acknowledged before it is * used. * * @param n * The new neighbor. */ public void opened(Node n, Node mediator) { APeerSampling ps = (APeerSampling) this.node.getProtocol(FastConfig.getLinkable(PreventiveCausalBroadcast.pid)); List<Node> neighborhood = IteratorUtils.toList(ps.getAliveNeighbors().iterator()); if (neighborhood.size() - this.buffers.size() >= 1) { this.buffers.put(n, new ArrayList<MReliableBroadcast>()); this._sendLocked(n, mediator); } }
public Stats numberOfAliveNeighbors() { ArrayList<Double> sizes = new ArrayList<Double>(); for (Node n : CDynamicNetwork.networks.get(0)) { APeerSampling ps = (APeerSampling) n.getProtocol(FastConfig.getLinkable(PreventiveCausalBroadcast.pid)); List<Node> neighborhood = IteratorUtils.toList(ps.getAliveNeighbors().iterator()); // FloodingCausalBroadcast fcb = (FloodingCausalBroadcast) // n.getProtocol(FloodingCausalBroadcast.pid); sizes.add((double) neighborhood.size()); } return Stats.getFromSmall(sizes); }
public static List<Event> getEvents(Activity context, Event.Type eventType) { if (eventType == null) throw new EventTypeException("Event type can not be null"); List<Event> eventList = StorageUtil.readObjects(context, StorageUtil.FILE_NAME); Iterator<Event> iterator = eventList.iterator(); while (iterator.hasNext()) { if (!iterator.next().getType().equals(eventType)) iterator.remove(); } return IteratorUtils.toList(iterator); }
/** * Creates a unique set iterator. * Subclasses can override this to return iterators with different properties. * * @return the uniqueSet iterator */ protected Iterator<E> createUniqueSetIterator() { final Transformer<Entry<E>, E> transformer = new Transformer<Entry<E>, E>() { @Override public E transform(Entry<E> entry) { return entry.getElement(); } }; return IteratorUtils.transformedIterator(entrySet().iterator(), transformer); }
@Override @SuppressWarnings("unchecked") public Iterator<V> iterator() { final Collection<V> coll = getMapping(); if (coll == null) { return IteratorUtils.EMPTY_ITERATOR; } return new ValuesIterator(key); }
Pair<List<String>, List<Object[]>> resourceCsvToBatchedPair(final Resource resource) throws IOException { XLOGGER.entry(resource.getDescription()); // parse CSV try (InputStreamReader isReader = new InputStreamReader(resource.getInputStream())) { CSVParser parser = CSVFormat.DEFAULT.withHeader().withNullString("").parse(isReader); // read header row MutablePair<List<String>, List<Object[]>> readData = new MutablePair<>(); readData.setLeft( new ArrayList<>( parser.getHeaderMap().keySet() ) ); XLOGGER.info("Read header: " + readData.getLeft() ); // read data rows List<Object[]> rows = new ArrayList<>(); for ( CSVRecord record : parser.getRecords() ) { if ( ! record.isConsistent() ) { throw new IllegalArgumentException("CSV record inconsistent: " + record); } List theRow = IteratorUtils.toList(record.iterator()); rows.add( theRow.toArray() ); } readData.setRight(rows); XLOGGER.exit("Records read: " + readData.getRight().size()); return readData; } }
@Test public void testRemoveView() throws UIMAException { JCas jcas = JCasFactory.createJCas(); jcas.setDocumentText("bla bla"); assertEquals(1, IteratorUtils.toList(jcas.getViewIterator()).size()); JCas other = jcas.createView("View 2"); other.setDocumentText("blubb blubb"); assertEquals(2, IteratorUtils.toList(jcas.getViewIterator()).size()); other.getCasImpl().reset(); assertEquals(1, IteratorUtils.toList(jcas.getViewIterator()).size()); }