Java Code Examples for java.util.SortedSet#remove()
The following examples show how to use
java.util.SortedSet#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassificationMeasures.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param title matrix title * @return confusion matrix as a list of list of String */ public List<List<String>> getConfusionMatrix(String title) { List<List<String>> matrix = new ArrayList<List<String>>(); List<String> row = new ArrayList<String>(); row.add(" "); matrix.add(row); // spacer row = new ArrayList<String>(); row.add(title); matrix.add(row); // title SortedSet<String> features = new TreeSet<String>(getFeatureValues()); row = new ArrayList<String>(); row.add("A \\ B"); row.addAll(features); matrix.add(row); // heading horizontal for (float[] confusionValues : getConfusionMatrix()) { row = new ArrayList<String>(); row.add(features.first()); // heading vertical features.remove(features.first()); for (float confusionValue : confusionValues) { row.add(String.valueOf((int) confusionValue)); } matrix.add(row); // confusion values } return matrix; }
Example 2
Source File: SpinParser.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static List<IRI> orderArguments(Set<IRI> args) { SortedSet<IRI> sortedArgs = new TreeSet<>( (IRI uri1, IRI uri2) -> uri1.getLocalName().compareTo(uri2.getLocalName())); sortedArgs.addAll(args); int numArgs = sortedArgs.size(); List<IRI> orderedArgs = new ArrayList<>(numArgs); for (int i = 0; i < numArgs; i++) { IRI arg = toArgProperty(i); if (!sortedArgs.remove(arg)) { arg = sortedArgs.first(); sortedArgs.remove(arg); } orderedArgs.add(arg); } return orderedArgs; }
Example 3
Source File: WeightedRootedHyperDAG.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
protected <T,U,V,I extends Path<T> & Indexer<List<Integer>,List<N>,? extends Path<U>>,L> V _startAgenda(boolean isLabeled, Pair<Map<I,V>, SortedSet<I>> chartAndAgenda, List<N> sortedNodes, Semirings.Semiring<V> semr, int order, Path<U> relevantPath, Subroutine edgeOperation) { Map<I,V> chart = chartAndAgenda.getFirst(); SortedSet<I> agenda = chartAndAgenda.getSecond(); while (!agenda.isEmpty()) { I nextItem = agenda.first(); agenda.remove(nextItem); // pop if (_logger!=null) _logger.popped(nextItem, agenda.size()); for (I item : arrive(isLabeled, sortedNodes, chart, semr, nextItem, relevantPath, edgeOperation)) { if (!agenda.contains(item)) { agenda.add(item); // arrive at node jj[-1] given history jj[:-1] } } if (relevantPath!=null) relevantPath = relevantPath.getTail(); } //if (_logger!=null && relevantNodes==null) // _logger.close(); if (semr!=null) // sum of all histories going into the last node return arrivalsTo(sortedNodes, chart, semr, sortedNodes.size()-1, order); return null; }
Example 4
Source File: ItemWithWeight.java From TagRec with GNU Affero General Public License v3.0 | 6 votes |
public static SortedSet<ItemWithWeight> getTopK (FolkRankData facts, double[][] weights, int k, int dim) { double minWeight; SortedSet<ItemWithWeight> set = new TreeSet<ItemWithWeight>(); minWeight = -100; // consider only items with positive weight for (int item = 0; item < weights[dim].length; item++) { double currWeight = weights[dim][item]; if (currWeight > minWeight) { /* new weight to consider found */ set.add(new ItemWithWeight(item, currWeight)); if (set.size() > k) { // new best weight, since we have more than k items in set ItemWithWeight last = set.last(); set.remove(last); minWeight = set.last().weight; } } } return set; }
Example 5
Source File: LongMap.java From netbeans with Apache License 2.0 | 6 votes |
long[] getBiggestObjectsByRetainedSize(int number) { SortedSet bigObjects = new TreeSet(); long[] bigIds = new long[number]; long min = 0; for (long index=0;index<fileSize;index+=ENTRY_SIZE) { long id = getID(index); if (id != 0) { long retainedSize = createEntry(index).getRetainedSize(); if (bigObjects.size()<number) { bigObjects.add(new RetainedSizeEntry(id,retainedSize)); min = ((RetainedSizeEntry)bigObjects.last()).retainedSize; } else if (retainedSize>min) { bigObjects.remove(bigObjects.last()); bigObjects.add(new RetainedSizeEntry(id,retainedSize)); min = ((RetainedSizeEntry)bigObjects.last()).retainedSize; } } } int i = 0; Iterator it = bigObjects.iterator(); while(it.hasNext()) { bigIds[i++]=((RetainedSizeEntry)it.next()).instanceId; } return bigIds; }
Example 6
Source File: PreviousYearsEnrolmentExecutor.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private void removeCurricularCoursesThatCanBeApprovedInOtherCurricularPeriod(final double missingEctsToConcludeGroup, final Map<CurricularPeriod, Set<Context>> childContextsByCurricularPeriod, final SortedSet<Context> sortedCurricularCoursesContexts, final EnrolmentContext enrolmentContext) { for (final Entry<CurricularPeriod, Set<Context>> each : childContextsByCurricularPeriod.entrySet()) { for (final Context context : each.getValue()) { if (canObtainApprovalInOtherCurricularPeriod(missingEctsToConcludeGroup, context, childContextsByCurricularPeriod)) { sortedCurricularCoursesContexts.remove(context); } } } }
Example 7
Source File: MemoryDataStoreOperations.java From geowave with Apache License 2.0 | 5 votes |
@Override public void write(final GeoWaveMetadata metadata) { SortedSet<MemoryMetadataEntry> typeStore = metadataStore.get(type); if (typeStore == null) { typeStore = new TreeSet<>(); metadataStore.put(type, typeStore); } if (typeStore.contains(new MemoryMetadataEntry(metadata))) { typeStore.remove(new MemoryMetadataEntry(metadata)); } if (!typeStore.add(new MemoryMetadataEntry(metadata))) { LOGGER.warn("Unable to add new metadata"); } }
Example 8
Source File: OffHeapDiskFPSetTest.java From tlaplus with MIT License | 5 votes |
private void doTestOffset(long length, long rgenseed) throws RemoteException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { final DummyFPSetConfiguration fpSetConfig = new DummyFPSetConfiguration(); fpSetConfig.setMemoryInFingerprintCnt(length); final OffHeapDiskFPSet fpSet = new OffHeapDiskFPSet(fpSetConfig); fpSet.init(1, createTmpFile(), filename); final SortedSet<Long> longs = new TreeSet<Long>(); // Insert n randomly chosen positive longs. Random random = new Random(rgenseed); for (int i = 0; i < length / 2; i++) { long fingerprint = getFingerprint(random); assertFalse(fpSet.put(fingerprint)); longs.add(fingerprint); } fpSet.forceFlush(); assertFalse(fpSet.contains(1L)); // contains triggers flush final Method field = OffHeapDiskFPSet.class.getDeclaredMethod("getDiskOffset", new Class[] {int.class, long.class}); field.setAccessible(true); for (long i = 0L; i < longs.size(); i++) { long fp = longs.first(); assertEquals(String.format("Length: %s with seed: %s", length, rgenseed), i + 1L, field.invoke(fpSet, 0, fp + 1L)); longs.remove(fp); } }
Example 9
Source File: TreeIndex.java From ohmdb with Apache License 2.0 | 5 votes |
@Override public void remove(Object oldValue, long id) { SortedSet<Long> set = map.get(oldValue); if (set != null) { set.remove(new Long(id)); } }
Example 10
Source File: NodeMap.java From LuckPerms with MIT License | 5 votes |
boolean auditTemporaryNodes(@Nullable Set<? super Node> removed) { boolean work = false; for (SortedSet<Node> valueSet : this.map.values()) { Iterator<Node> it = valueSet.iterator(); while (it.hasNext()) { Node entry = it.next(); if (!entry.hasExpired()) { continue; } // remove if (removed != null) { removed.add(entry); } if (entry instanceof InheritanceNode && entry.getValue()) { SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(entry.getContexts()); if (inheritanceNodesInContext != null) { inheritanceNodesInContext.remove(entry); } } it.remove(); work = true; } } return work; }
Example 11
Source File: SATTest.java From LogicNG with Apache License 2.0 | 5 votes |
/** * Tests if the given satisfying assignment is a local minimal model regarding the given relevant literals, i.e. * there is no variable in the assignment, contained in the relevant literals, that can be flipped without * resulting in an unsatisfying assignment. * @param solver the solver with the loaded formulas * @param assignment the satisfying assignment * @param relevantLiterals the relevant literals. */ private void testLocalMinimum(SATSolver solver, Assignment assignment, Collection<? extends Literal> relevantLiterals) { SortedSet<Literal> literals = assignment.literals(); for (Literal lit : relevantLiterals) { if (!literals.contains(lit)) { SortedSet<Literal> literalsWithFlip = new TreeSet<>(literals); literalsWithFlip.remove(lit.negate()); literalsWithFlip.add(lit); assertThat(solver.sat(literalsWithFlip)).isEqualTo(FALSE); } } }
Example 12
Source File: ConverterSpannedToHtml.java From Android-RTEditor with Apache License 2.0 | 5 votes |
private void convertText(Spanned text, int start, int end, SortedSet<CharacterStyle> spans) { while (start < end) { // get first CharacterStyle CharacterStyle span = spans.isEmpty() ? null : spans.first(); int spanStart = span == null ? Integer.MAX_VALUE : text.getSpanStart(span); int spanEnd = span == null ? Integer.MAX_VALUE : text.getSpanEnd(span); if (start < spanStart) { // no paragraph, just plain text escape(text, start, Math.min(end, spanStart)); start = spanStart; } else { // CharacterStyle found spans.remove(span); if (handleStartTag(span)) { convertText(text, Math.max(spanStart, start), Math.min(spanEnd, end), spans); } handleEndTag(span); start = spanEnd; } } }
Example 13
Source File: MemoryDataStoreOperations.java From geowave with Apache License 2.0 | 5 votes |
@Override public void delete(final GeoWaveRow row) { final MemoryStoreEntry entry = new MemoryStoreEntry(row); if (isAuthorized(entry, authorizations)) { final SortedSet<MemoryStoreEntry> rowTreeSet = storeData.get(indexName); if (rowTreeSet != null) { if (!rowTreeSet.remove(entry)) { LOGGER.warn("Unable to remove entry"); } } } }
Example 14
Source File: ManageThesisDA.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private Thesis findPreviousThesis(final SortedSet<Enrolment> dissertationEnrolments) { if (dissertationEnrolments.isEmpty()) { return null; } final Enrolment previous = dissertationEnrolments.last(); if (previous != null) { if (!previous.getThesesSet().isEmpty()) { return previous.getThesis(); } else { dissertationEnrolments.remove(previous); return findPreviousThesis(dissertationEnrolments); } } return null; }
Example 15
Source File: CommunicationChannelRepository.java From estatio with Apache License 2.0 | 5 votes |
@Programmatic public SortedSet<CommunicationChannel> findOtherByOwnerAndType( final CommunicationChannelOwner owner, final CommunicationChannelType type, final CommunicationChannel exclude) { final SortedSet<CommunicationChannel> communicationChannels = findByOwnerAndType(owner, type); communicationChannels.remove(exclude); return communicationChannels; }
Example 16
Source File: ObjectAcl.java From ecs-sync with Apache License 2.0 | 5 votes |
public synchronized void removeUserGrant(String user, String permission) { SortedSet<String> permissions = userGrants.get(user); if (permissions != null) { permissions.remove(permission); if (permissions.isEmpty()) userGrants.remove(user); } }
Example 17
Source File: TypeDialog.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private void createUI(SimpleFeatureType featureType) { getJDialog().setPreferredSize(new Dimension(400, 250)); JPanel panel = new JPanel(); BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS); panel.setLayout(layout); panel.add(new JLabel("<html>" + SnapApp.getDefault().getAppContext().getApplicationName() + " can interpret the imported point data in various ways.<br>" + "Please select:<br><br></html>")); List<AbstractButton> buttons = new ArrayList<AbstractButton>(); placemarkDescriptor = PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(GeometryDescriptor.class); interpretationMethod = InterpretationMethod.LEAVE_UNCHANGED; buttons.add(createButton("<html>Leave imported data <b>unchanged</b></html>.", true, InterpretationMethod.LEAVE_UNCHANGED, placemarkDescriptor)); buttons.add(createButton("<html>Interpret each point as vertex of a single <b>line or polygon</b><br>" + "(This will remove all attributes from points)</html>", false, InterpretationMethod.CONVERT_TO_SHAPE, PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(PointDescriptor.class))); SortedSet<PlacemarkDescriptor> placemarkDescriptors = new TreeSet<PlacemarkDescriptor>(new Comparator<PlacemarkDescriptor>() { @Override public int compare(PlacemarkDescriptor o1, PlacemarkDescriptor o2) { return o1.getRoleLabel().compareTo(o2.getRoleLabel()); } }); placemarkDescriptors.addAll(PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptors(featureType)); placemarkDescriptors.remove(PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(GeometryDescriptor.class)); placemarkDescriptors.remove(PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(PointDescriptor.class)); for (PlacemarkDescriptor descriptor : placemarkDescriptors) { buttons.add(createButton("<html>Interpret each point as <b>" + descriptor.getRoleLabel() + "</br></html>", false, InterpretationMethod.APPLY_DESCRIPTOR, descriptor)); } ButtonGroup buttonGroup = new ButtonGroup(); for (AbstractButton button : buttons) { buttonGroup.add(button); panel.add(button); } setContent(panel); }
Example 18
Source File: SortedQueueTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Test public void testGetNextWithAck() throws Exception { final String queueName = getTestName(); Queue queue = createSortedQueue(queueName, TEST_SORT_KEY); final Connection producerConnection = getConnection(); try { final Session producerSession = producerConnection.createSession(true, Session.SESSION_TRANSACTED); final MessageProducer producer = producerSession.createProducer(queue); sendAndCommitMessage(producerSession, producer, "2"); sendAndCommitMessage(producerSession, producer, "3"); sendAndCommitMessage(producerSession, producer, "1"); final Connection consumerConnection = getConnectionBuilder().setPrefetch(1).build(); try { final Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); final MessageConsumer consumer = consumerSession.createConsumer(queue); consumerConnection.start(); Message received; //Receive 3 in sorted order received = assertReceiveAndValidateMessage(consumer, "1"); received.acknowledge(); received = assertReceiveAndValidateMessage(consumer, "2"); received.acknowledge(); received = assertReceiveAndValidateMessage(consumer, "3"); received.acknowledge(); //Send 1 sendAndCommitMessage(producerSession, producer, "4"); //Receive 1 and recover assertReceiveAndValidateMessage(consumer, "4"); consumerSession.recover(); //Receive same 1 received = assertReceiveAndValidateMessage(consumer, "4"); received.acknowledge(); //Send 3 out of order sendAndCommitMessage(producerSession, producer, "7"); sendAndCommitMessage(producerSession, producer, "6"); sendAndCommitMessage(producerSession, producer, "5"); //Receive 1 of 3 (possibly out of order due to pre-fetch) final Message messageBeforeRollback = assertReceiveMessage(consumer); consumerSession.recover(); if (getProtocol().equals(Protocol.AMQP_0_10)) { //Receive 3 in sorted order (not as per JMS recover) received = assertReceiveAndValidateMessage(consumer, "5"); received.acknowledge(); received = assertReceiveAndValidateMessage(consumer, "6"); received.acknowledge(); received = assertReceiveAndValidateMessage(consumer, "7"); received.acknowledge(); } else { //First message will be the one rolled-back (as per JMS spec). final String messageKeyDeliveredBeforeRollback = messageBeforeRollback.getStringProperty(TEST_SORT_KEY); received = assertReceiveAndValidateMessage(consumer, messageKeyDeliveredBeforeRollback); received.acknowledge(); //Remaining two messages will be sorted final SortedSet<String> keys = new TreeSet<>(Arrays.asList("5", "6", "7")); keys.remove(messageKeyDeliveredBeforeRollback); received = assertReceiveAndValidateMessage(consumer, keys.first()); received.acknowledge(); received = assertReceiveAndValidateMessage(consumer, keys.last()); received.acknowledge(); } } finally { consumerConnection.close(); } } finally { producerConnection.close(); } }
Example 19
Source File: CassandraTarget.java From datacollector with Apache License 2.0 | 4 votes |
/** * Convert a Record into a fully-bound statement. */ @SuppressWarnings("unchecked") private BoundStatement recordToBoundStatement(Record record) throws StageException { ImmutableList.Builder<Object> values = new ImmutableList.Builder<>(); SortedSet<String> columnsPresent = Sets.newTreeSet(columnMappings.keySet()); for (Map.Entry<String, String> mapping : columnMappings.entrySet()) { String columnName = mapping.getKey(); String fieldPath = mapping.getValue(); // If we're missing fields, skip them. // If a field is present, but null, also remove it from columnsPresent since we can't write nulls. if (!record.has(fieldPath) || record.get(fieldPath).getValue() == null) { columnsPresent.remove(columnName); continue; } final Object value = record.get(fieldPath).getValue(); // Special cases for handling SDC Lists and Maps, // basically unpacking them into raw types. if (value instanceof List) { List<Object> unpackedList = new ArrayList<>(); for (Field item : (List<Field>) value) { unpackedList.add(item.getValue()); } values.add(unpackedList); } else if (value instanceof Map) { Map<Object, Object> unpackedMap = new HashMap<>(); for (Map.Entry<String, Field> entry : ((Map<String, Field>) value).entrySet()) { unpackedMap.put(entry.getKey(), entry.getValue().getValue()); } values.add(unpackedMap); } else { values.add(value); } } PreparedStatement stmt = statementCache.getUnchecked(columnsPresent); // .toArray required to pass in a list to a varargs method. Object[] valuesArray = values.build().toArray(); BoundStatement boundStmt = null; try { boundStmt = stmt.bind(valuesArray); } catch (CodecNotFoundException | InvalidTypeException | NullPointerException e) { // NPE can occur if one of the values is a collection type with a null value inside it. Thus, it's a record // error. Note that this runs the risk of mistakenly treating a bug as a record error. // CodecNotFound is caused when there is no type conversion definition available from the provided type // to the target type. errorRecordHandler.onError( new OnRecordErrorException( record, Errors.CASSANDRA_06, record.getHeader().getSourceId(), e.toString(), e ) ); } return boundStmt; }
Example 20
Source File: TestTopologicalSorter.java From datacollector with Apache License 2.0 | 4 votes |
@Test public void testTopologicalSorterDAG() { DirectedGraph<Integer> g = new DirectedGraph<>(); Assert.assertTrue(g.addVertex(0)); Assert.assertTrue(g.addVertex(1)); Assert.assertTrue(g.addVertex(2)); Assert.assertTrue(g.addVertex(3)); Assert.assertTrue(g.addVertex(4)); g.addDirectedEdge(0, 1); g.addDirectedEdge(0, 2); g.addDirectedEdge(0, 3); g.addDirectedEdge(0, 4); g.addDirectedEdge(1, 2); g.addDirectedEdge(1, 3); g.addDirectedEdge(1, 4); g.addDirectedEdge(2, 4); g.addDirectedEdge(3, 4); TopologicalSorter topologicalSorter = new TopologicalSorter(g, Comparator.naturalOrder()); SortedSet<Integer> order = topologicalSorter.sort(); int zero = order.first(); order.remove(zero); Assert.assertEquals(0, zero); int one = order.first(); order.remove(one); Assert.assertEquals(1, one); int two = order.first(); order.remove(two); int three = order.first(); order.remove(three); Assert.assertEquals(2, two); Assert.assertEquals(3, three); int four = order.first(); order.remove(four); Assert.assertEquals(4, four); }