List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public String storeJsonZips(String digits) { if ((digits == null) || (digits.length() == 0)) { digits = "0"; }/*from w w w . j ava 2 s . co m*/ long timestamp = getLzhDao().getZipInfo().getTimestamp().getTime(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); int cnt = 0; try { for (int i = 0; i < 100; ++i) { String zip1 = digits + String.format("%02d", i); ParentChild data = getParentChildDao().get(zip1); if (data == null) { continue; } Map<String, ParentChild> pcs = new HashMap<String, ParentChild>(); SortedSet<String> zip2s = new TreeSet<String>(); for (String json : data.getChildren()) { JSONObject jo = new JSONObject(json); String key = jo.optString("key", ""); String zip2 = jo.optString("zip2", ""); if (key.length() == 0) { continue; } if (zip2.length() == 0) { continue; } if (!pcs.containsKey(jo.optString("key", ""))) { pcs.put(key, getParentChildDao().get(key)); } zip2s.add(zip2); } for (String zip2 : zip2s) { String zip = zip1 + zip2; String json = toJsonZips(data, zip, pcs); ZipEntry entry = new ZipEntry(zip + ".json"); entry.setTime(timestamp); zos.putNextEntry(entry); zos.write(json.getBytes("UTF-8")); zos.closeEntry(); ++cnt; } } if (cnt == 0) { ZipEntry entry = new ZipEntry("empty.txt"); entry.setTime(timestamp); zos.putNextEntry(entry); zos.write("empty".getBytes("UTF-8")); zos.closeEntry(); } zos.finish(); getRawDao().store(baos.toByteArray(), "json_zip" + digits + ".zip"); log.info(digits + ":" + cnt); } catch (JSONException e) { log.log(Level.WARNING, "", e); } catch (IOException e) { log.log(Level.WARNING, "", e); } return digits.equals("9") ? null : "" + (Integer.parseInt(digits) + 1); }
From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java
public SortedSet<Shift> getShiftsByTypeOrderedByShiftName(final ShiftType shiftType) { final SortedSet<Shift> shifts = new TreeSet<Shift>(Shift.SHIFT_COMPARATOR_BY_NAME); for (final Shift shift : getAssociatedShifts()) { if (shift.containsType(shiftType)) { shifts.add(shift); }/*from w w w . java 2 s . c o m*/ } return shifts; }
From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java
/** * Attaches the exception(s) to the recurrence rule of a calendar on the * basis of a ResultSet.//ww w . ja v a 2 s.c om * * @param cw the calendar (as a CalendarWrapper) still lacking information * on the exceptions * @param rs the result of the execution of a proper SQL SELECT statement on * the fnbl_pim_calendar_exception table, with the cursor before * its first row * @return the CalendarWrapper object with address information attached * @throws Exception */ private CalendarWrapper addPIMCalendarExceptions(CalendarWrapper cw, ResultSet rs) throws Exception { if (cw.getCalendar().getCalendarContent().getRecurrencePattern() == null) { return cw; } SortedSet<ExceptionToRecurrenceRule> exceptions = new TreeSet<ExceptionToRecurrenceRule>(); boolean allDay = cw.getCalendar().getCalendarContent().getAllDay().booleanValue(); while (rs.next()) { String addition = rs.getString(SQL_FIELD_ADDITION); boolean isAddition = false; if (addition != null && addition.equals("1")) { isAddition = true; } String occurrenceDate; try { occurrenceDate = getStringFromDate(allDay, new Date(rs.getTimestamp(SQL_FIELD_OCCURRENCE_DATE).getTime())); } catch (Exception e) { throw new SQLException(e.getLocalizedMessage()); } ExceptionToRecurrenceRule etrr = new ExceptionToRecurrenceRule(isAddition, occurrenceDate); exceptions.add(etrr); } cw.getCalendar().getCalendarContent().getRecurrencePattern().setExceptions(exceptions); return cw; }
From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java
public SortedSet<WrittenEvaluation> getWrittenEvaluations() { final SortedSet<WrittenEvaluation> writtenEvaluations = new TreeSet<WrittenEvaluation>( WrittenEvaluation.COMPARATOR_BY_BEGIN_DATE); for (final Evaluation evaluation : getAssociatedEvaluationsSet()) { if (evaluation instanceof WrittenEvaluation) { writtenEvaluations.add((WrittenEvaluation) evaluation); }//from ww w.j a v a 2s .co m } return writtenEvaluations; }
From source file:org.jahia.tools.maven.plugins.LegalArtifactAggregator.java
private void outputPackageLicenses() { SortedSet<PackageMetadata> packageLicenses = new TreeSet<>(); for (JarMetadata jarMetadata : jarDatabase.values()) { for (String packageName : jarMetadata.getPackages()) { PackageMetadata packageMetadata = new PackageMetadata(); packageMetadata.setPackageName(packageName); packageMetadata.setJarName(jarMetadata.getName()); if (jarMetadata.getProject() != null && packageName.contains(jarMetadata.getProject())) { for (LicenseFile licenseFile : jarMetadata.getLicenseFiles().values()) { for (KnownLicense knownLicense : licenseFile.getKnownLicenses()) { packageMetadata.getLicenseKeys().add(knownLicense.getId()); }//from w w w. j a va2 s. c om } StringBuilder copyrightBuilder = new StringBuilder(); copyrightBuilder.append("Copyright (c) "); if (jarMetadata.getInceptionYear() != null) { copyrightBuilder.append(jarMetadata.getInceptionYear()); copyrightBuilder.append("-"); } Calendar calendar = Calendar.getInstance(); int currentYear = calendar.get(Calendar.YEAR); copyrightBuilder.append(Integer.toString(currentYear)); if (jarMetadata.getOrganizationName() != null) { copyrightBuilder.append(" "); copyrightBuilder.append(jarMetadata.getOrganizationName()); } packageMetadata.setCopyright(copyrightBuilder.toString()); if (jarMetadata.getProjectUrl() != null) { packageMetadata.setProjectUrl(jarMetadata.getProjectUrl()); } } packageLicenses.add(packageMetadata); } } File packageLicensesFile = new File(outputDirectory, "package-licenses.json"); try { mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.writeValue(packageLicensesFile, packageLicenses); } catch (IOException e) { e.printStackTrace(); } Writer flatPackageListWriter = null; try { flatPackageListWriter = new PrintWriter( new FileWriter(new File(outputDirectory, "flat-package-list.csv"))); flatPackageListWriter.append("Package name,JAR name,License keys,Copyright,Project URL\n"); for (PackageMetadata packageMetadata : packageLicenses) { flatPackageListWriter.append(packageMetadata.getPackageName()).append(",") .append(emptyIfNull(packageMetadata.getJarName())).append(",") .append(setToString(packageMetadata.getLicenseKeys())).append(",") .append(emptyIfNull(packageMetadata.getCopyright())).append(",") .append(emptyIfNull(packageMetadata.getProjectUrl())).append("\n"); } } catch (IOException e) { e.printStackTrace(); IOUtils.closeQuietly(flatPackageListWriter); } }
From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java
public SortedSet<Degree> getDegreesSortedByDegreeName() { final SortedSet<Degree> degrees = new TreeSet<Degree>(Degree.COMPARATOR_BY_DEGREE_TYPE_AND_NAME_AND_ID); for (final CurricularCourse curricularCourse : getAssociatedCurricularCoursesSet()) { final DegreeCurricularPlan degreeCurricularPlan = curricularCourse.getDegreeCurricularPlan(); degrees.add(degreeCurricularPlan.getDegree()); }/*from ww w.j a v a 2 s . c o m*/ return degrees; }
From source file:io.promagent.internal.HookMetadataParser.java
/** * See {@link #parse()}./* w w w . ja v a2s . co m*/ * * The classNameFilter is used to parse only specific classes from the JAR files. */ public SortedSet<HookMetadata> parse(Predicate<String> classNameFilter) throws IOException, ClassNotFoundException { SortedSet<HookMetadata> result = new TreeSet<>(); for (String className : listAllJavaClasses(hookJars, classNameFilter)) { byte[] binaryRepresentation = readBinaryRepresentation(className); ClassReader classReader = new ClassReader(binaryRepresentation); HookMetadataBuilder hookMetadata = new HookMetadataBuilder(className); classReader.accept(new ClassVisitor(Opcodes.ASM5) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (visible && typeEquals(desc, io.promagent.annotations.Hook.class)) { return new AnnotationValueCollector("instruments", hookMetadata::addInstruments, Opcodes.ASM5, super.visitAnnotation(desc, visible)); } else { return super.visitAnnotation(desc, visible); } } @Override public MethodVisitor visitMethod(int i, String method, String desc, String signature, String[] strings) { List<String> parameterTypes = Arrays.stream(Type.getArgumentTypes(desc)).map(Type::getClassName) .collect(Collectors.toList()); MethodSignatureBuilder builder = hookMetadata.newMethodSignature(parameterTypes); return new MethodVisitor(Opcodes.ASM5, super.visitMethod(i, method, desc, signature, strings)) { @Override public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { if (visible && typeEquals(desc, Returned.class, Thrown.class)) { builder.markReturnedOrThrown(parameter); } return super.visitParameterAnnotation(parameter, desc, visible); } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (visible && typeEquals(desc, Before.class, After.class)) { return new AnnotationValueCollector("method", builder::addMethodName, Opcodes.ASM5, super.visitAnnotation(desc, visible)); } else { return super.visitAnnotation(desc, visible); } } }; } }, ClassReader.SKIP_CODE); if (hookMetadata.isComplete()) { result.add(hookMetadata.build()); } } return result; }
From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java
public SortedSet<ExecutionDegree> getFirsExecutionDegreesByYearWithExecutionIn(ExecutionYear executionYear) { SortedSet<ExecutionDegree> result = new TreeSet<ExecutionDegree>( ExecutionDegree.EXECUTION_DEGREE_COMPARATORY_BY_YEAR); for (CurricularCourse curricularCourse : getAssociatedCurricularCoursesSet()) { ExecutionDegree executionDegree = curricularCourse.getDegreeCurricularPlan() .getExecutionDegreeByYear(executionYear); if (executionDegree != null) { result.add(executionDegree); }/*from w w w . j a v a2s . c o m*/ } return result; }
From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java
/** * @param i/* www . j a v a2s .co m*/ * @param type * @return the diffs with the given ElementType for the given Info object, * if such diffs exist; can be empty but not <code>null</code> */ private SortedSet<DiffElement> getDiffs(Info i, ElementType type) { SortedSet<DiffElement> result = new TreeSet<DiffElement>(); if (diffs != null && diffs.get(i) != null) { for (DiffElement diff : diffs.get(i)) { if (diff.subElementType == type) { result.add(diff); } } } return result; }