List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:de.damdi.fitness.activity.settings.sync.WgerJSONParser.java
/** * Constructor. Will start download immediately. * //from w ww . ja v a 2 s . c o m * @param exerciseJSONString * The exercises as JSON-String * @param languageJSONString * The languages as JSON-String * @param muscleJSONString * The muscles as JSON-String * @param dataProvider * @throws JSONException */ public WgerJSONParser(String exerciseJSONString, String languageJSONString, String muscleJSONString, String equipmentJSONString, IDataProvider dataProvider) throws JSONException { mDataProvider = dataProvider; // parse languages SparseArray<Locale> localeSparseArray = parseLanguages(languageJSONString); // parse muscles SparseArray<Muscle> muscleSparseArray = parseMuscles(muscleJSONString); // parse equipment (not required until REST-API supports this) // SparseArray<SportsEquipment> equipmentSparseArray = parseEquipment(equipmentJSONString); JSONObject mainObject = new JSONObject(exerciseJSONString); Log.d(TAG, mainObject.toString()); JSONArray exerciseArray = mainObject.getJSONArray("objects"); // parse each exercise of the JSON Array for (int i = 0; i < exerciseArray.length(); i++) { JSONObject jsonExercise = exerciseArray.getJSONObject(i); // get name and check if exercise already exists String name = jsonExercise.getString("name"); if (dataProvider.exerciseExists(name)) continue; ExerciseType.Builder builder = new ExerciseType.Builder(name); // category (unused) // String category = jsonExercise.getString("category"); // comments (unused) // JSONArray commentArray = jsonExercise.getJSONArray("comments"); // for (int k = 0; k < commentArray.length(); k++) { // String comment = commentArray.getString(k); //} // description String description = jsonExercise.getString("description"); builder.description(description); // id (unused) //String id = jsonExercise.getString("id"); // language // the json-language String might look like this: // '/api/v1/language/1/' // only the number at the end is required String language = jsonExercise.getString("language"); int languageNumber = getLastNumberOfJson(language); Map<Locale, String> translationMap = new HashMap<Locale, String>(); translationMap.put(localeSparseArray.get(languageNumber), name); builder.translationMap(translationMap); // resource_uri (unused) //String resource_uri = jsonExercise.getString("resource_uri"); // muscles SortedSet<Muscle> muscleSet = new TreeSet<Muscle>(); JSONArray muscleArray = jsonExercise.getJSONArray("muscles"); for (int l = 0; l < muscleArray.length(); l++) { String muscleString = muscleArray.getString(l); Muscle muscle = muscleSparseArray.get(getLastNumberOfJson(muscleString)); muscleSet.add(muscle); } builder.activatedMuscles(muscleSet); // equipment // not yet supported by REST-API /*SortedSet<SportsEquipment> equipmentSet = new TreeSet<SportsEquipment>(); JSONArray equipmentArray = jsonExercise.getJSONArray("equipment"); for (int l = 0; l < equipmentArray.length(); l++) { String equipmentString = equipmentArray.getString(l); SportsEquipment equipment = equipmentSparseArray.get(getLastNumberOfJson(equipmentString)); equipmentSet.add(equipment); }*/ builder.activatedMuscles(muscleSet); // images List<File> imageList = new ArrayList<File>(); JSONArray imageArray = jsonExercise.getJSONArray("images"); for (int l = 0; l < imageArray.length(); l++) { String imageString = imageArray.getString(l); imageList.add(new File(imageString)); } builder.imagePath(imageList); mNewExerciseList.add(builder.build()); mNewExerciseBuilderList.add(builder); } }
From source file:com.napkindrawing.dbversion.task.DbVersionUpgrade.java
protected StringBuilder dumpSchema() { StringBuilder dump = new StringBuilder(); SortedSet<String> tableNames = new TreeSet<String>(); Statement stmt = null;/*from ww w . j av a2 s . c om*/ try { stmt = getConnection().createStatement(); ResultSet tablesRs = stmt.executeQuery("SHOW TABLES"); while (tablesRs.next()) { tableNames.add(tablesRs.getString(1)); } for (String tableName : tableNames) { ResultSet describeRs = stmt.executeQuery("SHOW CREATE TABLE " + tableName); if (!describeRs.next()) { throw new BuildException("Couldn't retrieve create sql for table " + tableName); } String tableCreateSql = describeRs.getString(2); tableCreateSql = tableCreateSql.replaceFirst(" AUTO_INCREMENT=\\d+ ", " "); dump.append(tableCreateSql); dump.append("\n;\n"); } } catch (Exception e) { throw new BuildException(e, getLocation()); } finally { if (stmt != null) { try { stmt.close(); } catch (Exception e) { } } } return dump; }
From source file:cosmos.sql.TestSql.java
@Test public void testNoLimit() throws SQLException { loadDriverClass();/*from w ww.j a va 2 s . c o m*/ Connection connection = null; Statement statement = null; try { Properties info = new Properties(); info.put("url", JDBC_URL); info.put("user", USER); info.put("password", PASSWORD); connection = DriverManager.getConnection("jdbc:accumulo:cosmos//localhost", info); statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery( "select \"PAGE_ID\" from \"" + CosmosDriver.COSMOS + "\".\"" + meataData.uuid() + "\""); final ResultSetMetaData metaData = resultSet.getMetaData(); final int columnCount = metaData.getColumnCount(); assertEquals(columnCount, 1); int resultsFound = 0; SortedSet<String> sets = Sets.newTreeSet(); for (int i = 0; i < 10; i++) { sets.add(Integer.valueOf(i).toString()); } Queue<String> values = Lists.newLinkedList(sets); while (resultSet.next()) { assertEquals(metaData.getColumnName(1), "PAGE_ID"); @SuppressWarnings("unchecked") List<Entry<Column, RecordValue<?>>> sValues = (List<Entry<Column, RecordValue<?>>>) resultSet .getObject("PAGE_ID"); assertEquals(sValues.size(), 1); RecordValue<?> onlyValue = sValues.iterator().next().getValue(); assertEquals(onlyValue.visibility().toString(), "[en]"); values.remove(onlyValue.value()); resultsFound++; } assertEquals(resultsFound, 10); assertEquals(values.size(), 0); } finally { close(connection, statement); } }
From source file:dom.usuario.UsuarioShiroRepositorio.java
@Programmatic @PostConstruct// w w w .ja v a 2 s. c om public void init() throws NoSuchAlgorithmException, UnsupportedEncodingException { List<UsuarioShiro> usuarios = listAll(); if (usuarios.isEmpty()) { // isisJdoSupport // .executeUpdate("delete from UsuarioShiro_listaDeRoles"); // isisJdoSupport.executeUpdate("delete from Rol_listaPermisos"); // isisJdoSupport.executeUpdate("delete from Permiso"); // isisJdoSupport.executeUpdate("delete from Rol"); // isisJdoSupport.executeUpdate("delete from UsuarioShiro"); List<Usuario> externos = this.listAllExternos(); for (Usuario user : externos) { byte[] decodedBytes = Base64.decodeBase64(user.getUsuario_contrasenia()); if (user.getUsuario_nick().contentEquals("root")) { Permiso permiso = new Permiso(); Rol rol = new Rol(); SortedSet<Permiso> permisos = new TreeSet<Permiso>(); permiso.setNombre("SUPERUSUARIO"); permiso.setPath("*"); permisos.add(permiso); rol.setNombre("SUPERUSUARIO"); rol.setListaPermisos(permisos); addUsuarioShiro(user.getUsuario_nick(), hash256(new String(decodedBytes)), rol);// new // String(decodedBytes));user.getUsuario_contrasenia() } else { addUsuarioShiro(user.getUsuario_nick(), hash256(new String(decodedBytes))); } } this.crearRolInicioBasico(); this.crearRolNotasBasico(); this.crearRolNotasModificacion(); this.crearRolMemoBasico(); this.crearRolMemoModificacion(); this.crearRolResolucionBasico(); this.crearRolResolucionModificacion(); this.crearRolExpedienteBasico(); this.crearRolExpedienteModificacion(); this.crearRolDisposicionBasico(); this.crearRolDisposicionModificacion(); // this.crearRolPermisosLectura(); // this.crearRolPermisosEscritura(); // this.crearRolPermisosDisposicion(); } else { this.actualizarUserPass(); } }
From source file:BoundedPriorityQueue.java
/** * Return the set of elements in this queue greater than or equal * to the specified lower bound and strictly less than the upper bound * element according to the comparator for this queue. * * <p>In violation of the {@link SortedSet} interface * specification, the result of this method is <b>not</b> a view * onto this queue, but rather a static snapshot of the queue. * * @param fromElement Inclusive lower bound on returned elements. * @param toElement Exclusive upper bound on returned elements. * @return The set of elements greater than or equal to the lower bound. * @throws ClassCastException If the lower bound is not compatible with * this queue's comparator./*from ww w. ja va 2 s .c om*/ * @throws NullPointerException If the lower bound is null. * @throws IllegalArgumentException If the lower bound is greater than the upper bound. */ public SortedSet<E> subSet(E fromElement, E toElement) { int c = mComparator.compare(fromElement, toElement); if (c >= 0) { String msg = "Lower bound must not be greater than the upper bound." + " Found fromElement=" + fromElement + " toElement=" + toElement; throw new IllegalArgumentException(msg); } SortedSet<E> result = new TreeSet<E>(); for (E e : this) { if (mComparator.compare(e, fromElement) >= 0) { if (mComparator.compare(e, toElement) < 0) result.add(e); else break; } } return result; }
From source file:org.stockwatcher.data.cassandra.WatchListDAOImpl.java
@Override public SortedSet<WatchList> getWatchListsByUserId(StatementOptions options, UUID userId) { if (userId == null) { throw new IllegalArgumentException("userId argument is null"); }//from w w w.j av a2 s . co m SortedSet<WatchList> watchLists = new TreeSet<WatchList>(); try { BoundStatement bs = selectWatchListsByUserId.bind(); bs.setUUID("user_id", userId); for (Row row : execute(bs, options)) { UUID id = row.getUUID("watchlist_id"); watchLists.add(WatchListHelper.createWatchList(row, getWatchListItemCount(options, id))); } } catch (DriverException e) { throw new DAOException(e); } return watchLists; }
From source file:ru.org.linux.tag.TagDao.java
/** * ?? .//from w w w . j a v a 2 s.c o m * * @return ?? . */ SortedSet<String> getFirstLetters() { final SortedSet<String> set = new TreeSet<>(); StringBuilder query = new StringBuilder(); query.append("select distinct firstchar from ") .append("(select lower(substr(value,1,1)) as firstchar from tags_values "); query.append(" where counter > 0 "); query.append(" order by firstchar) firstchars"); jdbcTemplate.query(query.toString(), new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { set.add(rs.getString("firstchar")); } }); return set; }
From source file:io.wcm.handler.media.format.impl.MediaFormatHandlerImpl.java
/** * Get list of media formats that have the same (or bigger) resolution as the requested media format * and (nearly) the same aspect ratio.// w w w . j a v a 2 s . c o m * @param mediaFormatRequested Requested media format * @param filterRenditionGroup Only check media formats of the same rendition group. * @return Matching media formats, sorted by size (biggest first), ranking, name */ @Override public SortedSet<MediaFormat> getSameBiggerMediaFormats(MediaFormat mediaFormatRequested, boolean filterRenditionGroup) { SortedSet<MediaFormat> matchingFormats = new TreeSet<>(new MediaFormatSizeRankingComparator()); // if filter by rendition group is enabled, but the requested media format does not define one, // use only the requested format if (filterRenditionGroup && StringUtils.isEmpty(mediaFormatRequested.getRenditionGroup())) { matchingFormats.add(mediaFormatRequested); } else { for (MediaFormat mediaFormat : getMediaFormats()) { // if filter by rendition group is enabled, check only media formats of same rendition group if (!filterRenditionGroup || StringUtils.equals(mediaFormat.getRenditionGroup(), mediaFormatRequested.getRenditionGroup())) { // check if size matched (image size is same or bigger) if (isRenditionMatchSizeSameBigger(mediaFormat, mediaFormatRequested)) { //NOPMD // if media formats have ratios, check ratio (with tolerance) // otherwise add to list anyway, it *can* contain matching media items if (isRenditionMatchRatio(mediaFormat, mediaFormatRequested) //NOPMD || !mediaFormat.hasRatio() || !mediaFormatRequested.hasRatio()) { // check for supported file extension if (isRenditionMatchExtension(mediaFormat)) { //NOPMD matchingFormats.add(mediaFormat); } } } } } } return matchingFormats; }
From source file:io.wcm.handler.media.format.impl.MediaFormatHandlerImpl.java
/** * Get list of possible media formats that can be rendered from the given media format, i.e. same size or smaller * and (nearly) the same aspect ratio./*w ww . j a va 2 s .co m*/ * @param mediaFormatRequested Available media format * @param filterRenditionGroup Only check media formats of the same rendition group. * @return Matching media formats, sorted by size (biggest first), ranking, name */ @Override public SortedSet<MediaFormat> getSameSmallerMediaFormats(MediaFormat mediaFormatRequested, boolean filterRenditionGroup) { SortedSet<MediaFormat> matchingFormats = new TreeSet<>(new MediaFormatSizeRankingComparator()); // if filter by rendition group is enabled, but the requested media format does not define one, // use only the requested format if (filterRenditionGroup && StringUtils.isEmpty(mediaFormatRequested.getRenditionGroup())) { matchingFormats.add(mediaFormatRequested); } else { for (MediaFormat mediaFormat : getMediaFormats()) { // if filter by rendition group is enabled, check only media formats of same rendition group if (!filterRenditionGroup || StringUtils.equals(mediaFormat.getRenditionGroup(), mediaFormatRequested.getRenditionGroup())) { // check if size matched (image size is same or smaller) if (isRenditionMatchSizeSameSmaller(mediaFormat, mediaFormatRequested)) { //NOPMD // if media formats have ratios, check ratio (with tolerance) // otherwise add to list anyway, it *can* contain matching media items if (isRenditionMatchRatio(mediaFormat, mediaFormatRequested) //NOPMD || !mediaFormat.hasRatio() || !mediaFormatRequested.hasRatio()) { // check for supported file extension if (isRenditionMatchExtension(mediaFormat)) { //NOPMD matchingFormats.add(mediaFormat); } } } } } } return matchingFormats; }
From source file:io.fabric8.maven.plugin.ManifestIndexMojo.java
protected void generateHTML(File outputHtmlFile, Map<String, ManifestInfo> manifests, boolean kubernetes, File introductionHtmlFile, File headHtmlFile, File footerHtmlFile) throws MojoExecutionException { Map<String, SortedSet<ManifestInfo>> manifestMap = new TreeMap<>(); for (ManifestInfo manifestInfo : manifests.values()) { String key = manifestInfo.getName(); SortedSet<ManifestInfo> set = manifestMap.get(key); if (set == null) { set = new TreeSet(createManifestComparator()); manifestMap.put(key, set);/*from ww w . j a v a 2 s .c o m*/ } set.add(manifestInfo); } try (PrintWriter writer = new PrintWriter(new FileWriter(outputHtmlFile))) { writer.println("<html>"); writer.println("<head>"); writer.println(getHtmlFileContentOrDefault(headHtmlFile, "<link href='style.css' rel=stylesheet>\n" + "<link href='custom.css' rel=stylesheet>\n" + "<title>" + manifestTitle + "</title>\n")); writer.println("</head>"); writer.println("<body>"); writer.println(getHtmlFileContentOrDefault(introductionHtmlFile, "<h1>" + manifestTitle + "</h1>")); writer.println("<table class='table table-striped table-hover'>"); writer.println(" <hhead>"); writer.println(" <tr>"); writer.println(" <th>Manifest</th>"); writer.println(" <th>Versions</th>"); writer.println(" </tr>"); writer.println(" </hhead>"); writer.println(" <tbody>"); for (Map.Entry<String, SortedSet<ManifestInfo>> entry : manifestMap.entrySet()) { String key = entry.getKey(); SortedSet<ManifestInfo> set = entry.getValue(); if (!set.isEmpty()) { ManifestInfo first = set.first(); first.configure(this); if (!first.isValid()) { continue; } String manifestDescription = getDescription(first); writer.println(" <tr>"); writer.println(" <td title='" + manifestDescription + "'>"); String iconHtml = ""; String iconUrl = findIconURL(set); if (Strings.isNotBlank(iconUrl)) { iconHtml = "<img class='logo' src='" + iconUrl + "'>"; } writer.println(" " + iconHtml + "<span class='manifest-name'>" + key + "</span>"); writer.println(" </td>"); writer.println(" <td class='versions'>"); int count = 0; for (ManifestInfo manifestInfo : set) { if (maxVersionsPerApp > 0 && ++count > maxVersionsPerApp) { break; } String description = getDescription(manifestInfo); String version = manifestInfo.getVersion(); String href = kubernetes ? manifestInfo.getKubernetesUrl() : manifestInfo.getOpenShiftUrl(); String versionId = manifestInfo.getId(); String command = kubernetes ? "kubectl" : "oc"; writer.println( " <a class='btn btn-default' role='button' data-toggle='collapse' href='#" + versionId + "' aria-expanded='false' aria-controls='" + versionId + "' title='" + description + "'>\n" + version + "\n" + "</a>\n" + "<div class='collapse' id='" + versionId + "'>\n" + " <div class='well'>\n" + " <p>To install version <b>" + version + "</b> of <b>" + key + "</b> type the following command:</p>\n" + " <code>" + command + " apply -f " + href + "</code>\n" + " <div class='version-buttons'><a class='btn btn-primary' title='Download the YAML manifest for " + key + " version " + version + "' href='" + href + "'><i class='fa fa-download' aria-hidden='true'></i> Download Manifest</a> " + "<a class='btn btn-primary' target='gofabric8' title='Run this application via the go.fabric8.io website' href='https://go.fabric8.io/?manifest=" + href + "'><i class='fa fa-external-link' aria-hidden='true'></i> Run via browser</a></div>\n" + " </div>\n" + "</div>"); } writer.println(" </td>"); writer.println(" </tr>"); } } writer.println(" </tbody>"); writer.println(" </table>"); writer.println(getHtmlFileContentOrDefault(footerHtmlFile, "")); writer.println("</body>"); } catch (IOException e) { throw new MojoExecutionException("Failed to write to " + outputHtmlFile + ". " + e, e); } }