List of usage examples for java.util SortedSet first
E first();
From source file:mondrian.olap.IdBatchResolver.java
/** * Loops through the SortedSet of Ids, attempting to load sets of * children of parent Ids.// w ww . j a v a 2 s .c o m * The loop below assumes the the SortedSet is ordered by segment * size from smallest to largest, such that parent identifiers will * occur before their children. */ private Map<QueryPart, QueryPart> resolveInParentGroupings(SortedSet<Id> identifiers) { final Map<QueryPart, QueryPart> resolvedIdentifiers = new HashMap<QueryPart, QueryPart>(); while (identifiers.size() > 0) { Id parent = identifiers.first(); identifiers.remove(parent); if (!supportedIdentifier(parent)) { continue; } Exp exp = (Exp) resolvedIdentifiers.get(parent); if (exp == null) { exp = lookupExp(resolvedIdentifiers, parent); } Member parentMember = getMemberFromExp(exp); if (!supportedMember(parentMember)) { continue; } batchResolveChildren(parent, parentMember, identifiers, resolvedIdentifiers); } return resolvedIdentifiers; }
From source file:org.apache.marmotta.platform.core.rio.RDFHtmlWriterImpl.java
/** * Signals the end of the RDF data. This method is called when all data has * been reported./*from w ww. ja v a 2 s. c o m*/ * * @throws org.openrdf.rio.RDFHandlerException * If the RDF handler has encountered an unrecoverable error. */ @Override public void endRDF() throws RDFHandlerException { List<Map<String, Object>> resources = new ArrayList<Map<String, Object>>(); for (Map.Entry<Resource, SortedSet<Statement>> entry : tripleMap.entrySet()) { SortedSet<Statement> ts = entry.getValue(); Map<String, Object> resource = new HashMap<String, Object>(); String subject = ts.first().getSubject().stringValue(); if (UriUtil.validate(subject)) { resource.put("uri", subject); try { resource.put("encoded_uri", URLEncoder.encode(subject, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Error trying to encode '{}': {}", subject, e.getMessage()); resource.put("encoded_uri", subject); } } else { resource.put("genid", subject); try { resource.put("encoded_genid", URLEncoder.encode(subject, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Error trying to encode '{}': {}", subject, e.getMessage()); resource.put("encoded_genid", subject); } } List<Map<String, Object>> triples = new ArrayList<Map<String, Object>>(); for (Statement t : ts) { Map<String, Object> triple = new HashMap<String, Object>(); //predicate Map<String, String> predicate = new HashMap<String, String>(); String predicateUri = t.getPredicate().stringValue(); predicate.put("uri", predicateUri); String predicateCurie = prefixService.getCurie(predicateUri); predicate.put("curie", StringUtils.isNotBlank(predicateCurie) ? predicateCurie : predicateUri); triple.put("predicate", predicate); //object Map<String, String> object = new HashMap<String, String>(); Value value = t.getObject(); String objectValue = value.stringValue(); if (value instanceof URI) { //http uri object.put("uri", objectValue); String objectCurie = prefixService.getCurie(objectValue); object.put("curie", StringUtils.isNotBlank(objectCurie) ? objectCurie : objectValue); object.put("cache", "true"); } else if (value instanceof BNode) { //blank node object.put("genid", objectValue); try { object.put("encoded_genid", URLEncoder.encode(objectValue, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Error trying to encode '{}': {}", subject, e.getMessage()); object.put("encoded_genid", objectValue); } } else if (value instanceof Literal) { //literal Literal literal = (Literal) t.getObject(); String lang = literal.getLanguage(); if (StringUtils.isNotBlank(lang)) { object.put("lang", lang); objectValue = "\"" + objectValue + "\"@" + lang; if (literal.getDatatype() != null) { String datatype = prefixService.getCurie(literal.getDatatype().stringValue()); object.put("datatype", datatype); objectValue += "^^" + datatype; } } else { if (literal.getDatatype() != null) { String datatype = prefixService.getCurie(literal.getDatatype().stringValue()); object.put("datatype", datatype); objectValue = "\"" + objectValue + "\"^^" + datatype; } } object.put("value", objectValue); } else { //should not arrive here... object.put("value", objectValue); } triple.put("object", object); if (t.getContext() != null) { Map<String, String> context = new HashMap<String, String>(); String contextUri = t.getContext().stringValue(); context.put("uri", contextUri); String contextCurie = prefixService.getCurie(contextUri); context.put("curie", StringUtils.isNotBlank(contextCurie) ? contextCurie : contextUri); triple.put("context", context); } else { triple.put("context", ImmutableMap.of("uri", "", "curie", "")); } //write reasoner justifications if (ResourceUtils.isInferred(t)) { triple.put("info", createInfo(ResourceUtils.getId(t))); } else { triple.put("info", ""); } triples.add(triple); } resource.put("triples", triples); resources.add(resource); } try { Map<String, Object> data = new HashMap<String, Object>(); data.put("baseUri", configurationService.getServerUri()); data.put("resources", resources); data.put("prefixMappings", prefixService.serializePrefixMapping()); //set timestamp link if (configurationService.getBooleanConfiguration("versioning.enabled")) { data.put("timemaplink", configurationService.getStringConfiguration("versioning.memento.timemap")); } templatingService.process(TemplatingService.RDF_HTML_TPL, data, writer); } catch (Exception e) { log.error(e.getMessage(), e); throw new RDFHandlerException(e); } }
From source file:com.google.android.cameraview.Camera1.java
@SuppressWarnings("SuspiciousNameCombination") private Size chooseOptimalSize(SortedSet<Size> sizes) { if (!mPreview.isReady()) { // Not yet laid out return sizes.first(); // Return the smallest size }/*w w w. j av a 2 s . c o m*/ int desiredWidth; int desiredHeight; final int surfaceWidth = mPreview.getWidth(); final int surfaceHeight = mPreview.getHeight(); if (isLandscape(mDisplayOrientation)) { desiredWidth = surfaceHeight; desiredHeight = surfaceWidth; } else { desiredWidth = surfaceWidth; desiredHeight = surfaceHeight; } Size result = null; for (Size size : sizes) { // Iterate from small to large if (desiredWidth <= size.getWidth() && desiredHeight <= size.getHeight()) { return size; } result = size; } return result; }
From source file:org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager.java
/** * Cleans a log file and all older files from ZK. Called when we are sure that a * log file is closed and has no more entries. * @param key Path to the log/*from ww w .ja va 2 s. co m*/ * @param id id of the peer cluster * @param queueRecovered Whether this is a recovered queue */ public void cleanOldLogs(String key, String id, boolean queueRecovered) { synchronized (this.hlogsById) { SortedSet<String> hlogs = this.hlogsById.get(id); if (queueRecovered || hlogs.first().equals(key)) { return; } SortedSet<String> hlogSet = hlogs.headSet(key); for (String hlog : hlogSet) { this.replicationQueues.removeLog(id, hlog); } hlogSet.clear(); } }
From source file:io.mariachi.allianzvision.camera.api14.Camera1.java
@SuppressWarnings("SuspiciousNameCombination") private Size chooseOptimalSize(SortedSet<Size> sizes) { if (!mPreview.isReady()) { // Not yet laid out return sizes.first(); // Return the smallest size }// ww w . jav a 2 s . c om int desiredWidth; int desiredHeight; final int surfaceWidth = mPreview.getWidth(); final int surfaceHeight = mPreview.getHeight(); if (mDisplayOrientation == 90 || mDisplayOrientation == 270) { desiredWidth = surfaceHeight; desiredHeight = surfaceWidth; } else { desiredWidth = surfaceWidth; desiredHeight = surfaceHeight; } Size result = null; for (Size size : sizes) { // Iterate from small to large if (desiredWidth <= size.getWidth() && desiredHeight <= size.getHeight()) { return size; } result = size; } return result; }
From source file:org.jclouds.rackspace.cloudfiles.CloudFilesClientLiveTest.java
@Test public void testPutContainers() throws Exception { String containerName = getContainerName(); try {/*ww w . ja v a 2 s .c o m*/ String containerName1 = containerName + ".hello"; assertTrue(context.getApi().createContainer(containerName1)); // List only the container just created, using a marker with the container name less 1 char SortedSet<ContainerMetadata> response = context.getApi().listContainers(ListContainerOptions.Builder .afterMarker(containerName1.substring(0, containerName1.length() - 1)).maxResults(1)); assertNotNull(response); assertEquals(response.size(), 1); assertEquals(response.first().getName(), containerName + ".hello"); String containerName2 = containerName + "?should-be-illegal-question-char"; assert context.getApi().createContainer(containerName2); // TODO: Should throw a specific exception, not UndeclaredThrowableException try { context.getApi().createContainer(containerName + "/illegal-slash-char"); fail("Should not be able to create container with illegal '/' character"); } catch (Exception e) { } assertTrue(context.getApi().deleteContainerIfEmpty(containerName1)); assertTrue(context.getApi().deleteContainerIfEmpty(containerName2)); } finally { returnContainer(containerName); } }
From source file:module.workingCapital.presentationTier.action.WorkingCapitalAction.java
private ActionForward showList(final HttpServletRequest request, final WorkingCapitalContext workingCapitalContext, final SortedSet<WorkingCapitalProcess> unitProcesses) { if (unitProcesses.size() == 1) { final WorkingCapitalProcess workingCapitalProcess = unitProcesses.first(); return ProcessManagement.forwardToProcess(workingCapitalProcess); } else {// w w w. java2 s .c o m final List<WorkingCapitalProcess> list = new ArrayList<WorkingCapitalProcess>(unitProcesses); final String sortByArg = request.getParameter("sortBy"); if (sortByArg != null && !sortByArg.isEmpty()) { final int i = sortByArg.indexOf('='); if (i > 0) { final BeanComparator comparator = new BeanComparator(sortByArg.substring(0, i)); Collections.sort(list, comparator); final char c = sortByArg.charAt(i + 1); if (c == 'd' || c == 'D') { Collections.reverse(list); } } } request.setAttribute("unitProcesses", list); return frontPage(request, workingCapitalContext); } }
From source file:com.opengamma.integration.coppclark.CoppClarkHolidayFileReader.java
private void mergeDates(HolidayDocument existingDoc, HolidayDocument newDoc) { if (newDoc.getHoliday().getHolidayDates().size() == 0) { return;//from w w w .j a v a2s . com } // merge dates SortedSet<LocalDate> existingDates = new TreeSet<LocalDate>(existingDoc.getHoliday().getHolidayDates()); SortedSet<LocalDate> newDates = new TreeSet<LocalDate>(newDoc.getHoliday().getHolidayDates()); List<LocalDate> result = new ArrayList<LocalDate>(newDates); result.addAll(0, existingDates.headSet(newDates.first())); result.addAll(existingDates.tailSet(newDates.last().plusYears(1).withDayOfYear(1))); // file is based on whole years // store into new document newDoc.getHoliday().getHolidayDates().clear(); newDoc.getHoliday().getHolidayDates().addAll(result); }
From source file:gov.nih.nci.cabig.caaers.domain.ResearchStaff.java
/** * The earliest start date of this research staff. * * @return the active date//from ww w .ja v a 2 s. co m */ @Transient public Date getActiveDate() { SortedSet<Date> dates = new TreeSet<Date>(); for (SiteResearchStaff srs : this.getSiteResearchStaffs()) { Date activeDate = srs.getActiveDate(); if (activeDate != null) dates.add(activeDate); } if (dates.size() > 0) return dates.first(); else return null; }
From source file:org.jclouds.azure.storage.blob.AzureBlobClientLiveTest.java
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer", "testCreatePublicContainer" }) public void testListOwnedContainers() throws Exception { // Test default listing SortedSet<ListableContainerProperties> response = connection.listContainers(); // assertEquals(response.size(), initialContainerCount + 2);// if the containers already // exist, this will fail // Test listing with options response = connection.listContainers(ListOptions.Builder .prefix(privateContainer.substring(0, privateContainer.length() - 1)).maxResults(1)); assertEquals(response.size(), 1);//from w w w . j a v a 2 s.c om assertEquals(response.first().getName(), privateContainer); response = connection.listContainers(ListOptions.Builder.prefix(publicContainer).maxResults(1)); assertEquals(response.size(), 1); assertEquals(response.first().getName(), publicContainer); }