List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.java
private static Class<?> getStartClass() { ClassLoader classLoader = AbstractSpringFunctionAdapterInitializer.class.getClassLoader(); Class<?> mainClass = null; if (System.getenv("MAIN_CLASS") != null) { mainClass = ClassUtils.resolveClassName(System.getenv("MAIN_CLASS"), classLoader); } else if (System.getProperty("MAIN_CLASS") != null) { mainClass = ClassUtils.resolveClassName(System.getProperty("MAIN_CLASS"), classLoader); } else {// ww w .j a va 2 s.co m try { Class<?> result = getStartClass(Collections.list(classLoader.getResources("META-INF/MANIFEST.MF"))); if (result == null) { result = getStartClass(Collections.list(classLoader.getResources("meta-inf/manifest.mf"))); } Assert.notNull(result, "Failed to locate main class"); mainClass = result; } catch (Exception ex) { throw new IllegalStateException("Failed to discover main class. An attempt was made to discover " + "main class as 'MAIN_CLASS' environment variable, system property as well as " + "entry in META-INF/MANIFEST.MF (in that order).", ex); } } logger.info("Main class: " + mainClass); return mainClass; }
From source file:jenkins.metrics.api.MetricsRootAction.java
/** * Parses a {@link StaplerRequest} and extracts the {code max-age=...} directive from the client headers if present. * * @param req the request./*from w w w. j av a 2 s .c o m*/ * @return the max-age (in milliseconds) or -1 if not present. */ @SuppressWarnings("unchecked") private static long getCacheControlMaxAge(StaplerRequest req) { long maxAge = -1L; for (String value : Collections.list((Enumeration<String>) req.getHeaders(CACHE_CONTROL))) { Matcher matcher = CACHE_CONTROL_MAX_AGE.matcher(value); while (matcher.find()) { maxAge = TimeUnit.SECONDS.toMillis(Long.parseLong(matcher.group(1))); } } return Math.max(-1L, maxAge); }
From source file:edu.ksu.cis.indus.tools.slicer.criteria.specification.SliceCriterionSpec.java
/** * Retrieves the specification for the given criterion relative to <code>scene</code>. * * @param criterion for which the specification should be generated. * * @return the specification.// w w w . ja v a 2 s. co m * * @throws IllegalStateException when an error occurs while creating the criterion. * * @pre criterion != null and scene != null * @post result != null */ static Collection<SliceCriterionSpec> getCriterionSpec(final ISliceCriterion criterion) { final SootMethod _method = criterion.getOccurringMethod(); final SootClass _declaringClass = _method.getDeclaringClass(); final String _prefix = _declaringClass.getPackageName(); final String _shortJavaStyleName = _declaringClass.getShortJavaStyleName(); final String _className; if (_prefix.length() != 0) { _className = _prefix + "." + _shortJavaStyleName; } else { _className = _shortJavaStyleName; } final String _methodName = _method.getName(); final Collection<SliceCriterionSpec> _result; if (!_method.isAbstract() && !_method.isNative()) { final Body _body = _method.retrieveActiveBody(); if (_body == null) { final String _msg = _method.getSignature() + " does not have a body."; LOGGER.error(_msg); throw new IllegalStateException(_msg); } final List<Stmt> _stmts = Collections.list(Collections.<Stmt>enumeration(_body.getUnits())); final Stmt _occurringStmt = CriteriaSpecHelper.getOccurringStmt(criterion); final int _stmtIndex = _stmts.indexOf(_occurringStmt); final boolean _considerExecution = CriteriaSpecHelper.isConsiderExecution(criterion); final SliceCriterionSpec _spec = new SliceCriterionSpec(); _spec.className = _className; _spec.methodName = _methodName; _spec.parameterTypeNames = getNamesOfTypes(_method.getParameterTypes()); _spec.returnTypeName = _method.getReturnType().toString(); _spec.stmtIndex = _stmtIndex; _spec.exprIndex = -1; _spec.considerExecution = _considerExecution; _spec.considerEntireStmt = false; _result = new ArrayList<SliceCriterionSpec>(); final ValueBox _occurringExprBox = CriteriaSpecHelper.getOccurringExpr(criterion); if (_occurringExprBox != null) { final Value _expr = _occurringExprBox.getValue(); final int _size = _expr.getUseBoxes().size(); if (_size == 0) { _spec.exprIndex = _occurringStmt.getUseAndDefBoxes().indexOf(_occurringExprBox); _result.add(_spec); } else { for (int _i = _size - 1; _i >= 0; _i--) { try { final SliceCriterionSpec _temp = (SliceCriterionSpec) _spec.clone(); _temp.exprIndex = _i; _result.add(_temp); } catch (final CloneNotSupportedException _e) { final String _msg = "Low level Error while creating criterion specification."; LOGGER.error(_msg); throw new IllegalStateException(_msg); } } } } else { _result.add(_spec); } } else { _result = Collections.emptySet(); } return _result; }
From source file:eu.openanalytics.rsb.component.EmailDepositHandler.java
@SuppressWarnings("unchecked") public void handleJob(final Message<MimeMessage> message) throws MessagingException, IOException { final DepositEmailConfiguration depositEmailConfiguration = message.getHeaders() .get(EMAIL_CONFIG_HEADER_NAME, DepositEmailConfiguration.class); final String applicationName = depositEmailConfiguration.getApplicationName(); final MimeMessage mimeMessage = message.getPayload(); final Address[] replyTo = mimeMessage.getReplyTo(); Validate.notEmpty(replyTo, "no reply address found for job emailed with headers:" + Collections.list(mimeMessage.getAllHeaders())); final Map<String, Serializable> meta = new HashMap<String, Serializable>(); meta.put(EMAIL_SUBJECT_META_NAME, mimeMessage.getSubject()); meta.put(EMAIL_ADDRESSEE_META_NAME, getPrimaryAddressee(mimeMessage)); meta.put(EMAIL_REPLY_TO_META_NAME, replyTo[0].toString()); meta.put(EMAIL_REPLY_CC_META_NAME, getCCAddressees(mimeMessage)); meta.put(EMAIL_BODY_META_NAME, getResponseBody(depositEmailConfiguration)); final MultiFilesJob job = new MultiFilesJob(Source.EMAIL, applicationName, ApplicationPermissionEvaluator.NO_AUTHENTICATED_USERNAME, UUID.randomUUID(), (GregorianCalendar) GregorianCalendar.getInstance(), meta); try {//ww w .jav a2 s . com addEmailAttachmentsToJob(depositEmailConfiguration, mimeMessage, job); getMessageDispatcher().dispatch(job); } catch (final Exception e) { final MultiFilesResult errorResult = job.buildErrorResult(e, getMessages()); handleResult(errorResult); } }
From source file:com.googlecode.noweco.calendar.CaldavServlet.java
@SuppressWarnings("unchecked") @Override// w ww . j a v a2 s . com public void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String method = req.getMethod(); if (LOGGER.isDebugEnabled()) { List<String> headers = Collections.list((Enumeration<String>) req.getHeaderNames()); LOGGER.debug("Command : {}, Appel : {}, headers {}", new Object[] { method, req.getRequestURI(), headers }); } if (!authent(req)) { resp.addHeader("WWW-Authenticate", "BASIC realm=\"Noweco CalDAV\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } String requestURI = req.getRequestURI(); if (requestURI.length() != 0 && requestURI.charAt(0) != '/') { // unknown relative URI resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } try { if (METHOD_PROPFIND.equals(method)) { doPropfind(req, resp); } else if (METHOD_REPORT.equals(method)) { doReport(req, resp); } else { super.service(req, resp); } } catch (Throwable e) { LOGGER.error("Unexpected throwable", e); } }
From source file:in.andres.kandroid.ui.TaskEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_task_edit); setupActionBar();//from w w w. jav a 2 s . c om editTextTitle = (EditText) findViewById(R.id.edit_task_title); editTextDescription = (EditText) findViewById(R.id.edit_task_description); btnStartDate = (Button) findViewById(R.id.btn_start_date); btnDueDate = (Button) findViewById(R.id.btn_due_date); btnColor = (Button) findViewById(R.id.color_button); btnColor.setOnClickListener(btnColorClick); btnColor.setText(Utils.fromHtml(getString(R.string.taskedit_color, ""))); editHoursEstimated = (EditText) findViewById(R.id.edit_hours_estimated); editHoursSpent = (EditText) findViewById(R.id.edit_hours_spent); spinnerProjectUsers = (Spinner) findViewById(R.id.user_spinner); if (getIntent().hasExtra("task")) { isNewTask = false; task = (KanboardTask) getIntent().getSerializableExtra("task"); taskTitle = task.getTitle(); taskDescription = task.getDescription(); startDate = task.getDateStarted(); dueDate = task.getDateDue(); timeEstimated = task.getTimeEstimated(); timeSpent = task.getTimeSpent(); ownerId = task.getOwnerId(); colorId = task.getColorId(); setActionBarTitle(getString(R.string.taskview_fab_edit_task)); } else { isNewTask = true; projectid = getIntent().getIntExtra("projectid", 0); // colorId = getIntent().getIntExtra("colorid", 0); creatorId = getIntent().getIntExtra("creatorid", 0); ownerId = getIntent().getIntExtra("ownerid", 0); columnId = getIntent().getIntExtra("columnid", 0); swimlaneId = getIntent().getIntExtra("swimlaneid", 0); setActionBarTitle(getString(R.string.taskedit_new_task)); } SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext()); try { kanboardAPI = new KanboardAPI(preferences.getString("serverurl", ""), preferences.getString("username", ""), preferences.getString("password", "")); kanboardAPI.addOnCreateTaskListener(this); kanboardAPI.addOnUpdateTaskListener(this); kanboardAPI.addOnGetDefaultColorListener(this); kanboardAPI.addOnGetDefaultColorsListener(this); kanboardAPI.addOnGetVersionListener(this); kanboardAPI.getDefaultTaskColor(); kanboardAPI.getDefaultTaskColors(); kanboardAPI.getVersion(); } catch (IOException e) { e.printStackTrace(); } if (getIntent().hasExtra("projectusers")) { if (getIntent().getSerializableExtra("projectusers") instanceof HashMap) { projectUsers = new Hashtable<>( (HashMap<Integer, String>) getIntent().getSerializableExtra("projectusers")); ArrayList<String> possibleOwners = Collections.list(projectUsers.elements()); possibleOwners.add(0, ""); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, possibleOwners); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerProjectUsers.setAdapter(adapter); if (ownerId != 0) { spinnerProjectUsers.setSelection(possibleOwners.indexOf(projectUsers.get(ownerId))); } } } editTextTitle.setText(taskTitle); editTextDescription.setText(taskDescription); editHoursEstimated.setText(Double.toString(timeEstimated)); editHoursSpent.setText(Double.toString(timeSpent)); btnStartDate.setText(Utils.fromHtml(getString(R.string.taskview_date_start, startDate))); btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate))); btnStartDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); if (startDate != null) calendar.setTime(startDate); DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); startDate = calendar.getTime(); btnStartDate.setText( Utils.fromHtml(getString(R.string.taskview_date_start, startDate))); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startDate = null; btnStartDate.setText( Utils.fromHtml(getString(R.string.taskview_date_start, startDate))); } }); dlgDate.show(); } }); btnDueDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); if (dueDate != null) calendar.setTime(dueDate); DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); dueDate = calendar.getTime(); btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate))); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dueDate = null; btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate))); } }); dlgDate.show(); } }); }
From source file:org.omegat.filters3.xml.openxml.OpenXMLFilter.java
/** * Processes a single OpenXML file, which is actually a ZIP file consisting of many XML files, some of * which should be translated.//www.j a v a 2 s .c o m */ @Override public void processFile(File inFile, File outFile, FilterContext fc) throws IOException, TranslationException { defineDOCUMENTSOptions(processOptions); // Define the documents to read ZipOutputStream zipout = null; try (ZipFile zipfile = new ZipFile(inFile)) { if (outFile != null) { zipout = new ZipOutputStream(new FileOutputStream(outFile)); } Enumeration<? extends ZipEntry> unsortedZipcontents = zipfile.entries(); List<? extends ZipEntry> filelist = Collections.list(unsortedZipcontents); // Sort filenames, because zipfile.entries give a random order // We use a simplified natural sort, to have slide1, slide2 ... // slide10 // instead of slide1, slide10, slide 2 // We also order files arbitrarily, to have, for instance // documents.xml before comments.xml Collections.sort(filelist, this::compareZipEntries); for (ZipEntry zipentry : filelist) { String shortname = removePath(zipentry.getName()); if (TRANSLATABLE.matcher(shortname).matches()) { File tmpin = tmp(); FileUtils.copyInputStreamToFile(zipfile.getInputStream(zipentry), tmpin); File tmpout = null; if (zipout != null) { tmpout = tmp(); } try { createXMLFilter().processFile(tmpin, tmpout, fc); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); throw new TranslationException(e.getLocalizedMessage() + "\n" + OStrings.getString("OpenXML_ERROR_IN_FILE") + inFile, e); } if (zipout != null) { ZipEntry outEntry = new ZipEntry(zipentry.getName()); zipout.putNextEntry(outEntry); FileUtils.copyFile(tmpout, zipout); zipout.closeEntry(); } if (!tmpin.delete()) { tmpin.deleteOnExit(); } if (tmpout != null && !tmpout.delete()) { tmpout.deleteOnExit(); } } else { if (zipout != null) { ZipEntry outEntry = new ZipEntry(zipentry.getName()); zipout.putNextEntry(outEntry); try (InputStream is = zipfile.getInputStream(zipentry)) { IOUtils.copy(is, zipout); } zipout.closeEntry(); } } } } finally { if (zipout != null) { zipout.close(); } } }
From source file:com.yoho.core.trace.instrument.web.TraceInterceptor.java
/** * Override to add annotations not defined in {@link TraceKeys}. */// w w w . ja va 2s . c om protected void addRequestTags(HttpServletRequest request) { //add uid this.tracer.addTag(this.traceKeys.getYoho().getUid(), request.getParameter("uid")); //add http String uri = this.urlPathHelper.getPathWithinApplication(request); this.tracer.addTag(this.traceKeys.getHttp().getUrl(), getFullUrl(request)); this.tracer.addTag(this.traceKeys.getHttp().getHost(), request.getServerName()); this.tracer.addTag(this.traceKeys.getHttp().getPath(), uri); this.tracer.addTag(this.traceKeys.getHttp().getMethod(), request.getMethod()); for (String name : this.traceKeys.getHttp().getHeaders()) { Enumeration<String> values = request.getHeaders(name); if (values.hasMoreElements()) { String key = this.traceKeys.getHttp().getPrefix() + name.toLowerCase(); ArrayList<String> list = Collections.list(values); String value = list.size() == 1 ? list.get(0) : StringUtils.collectionToDelimitedString(list, ",", "'", "'"); this.tracer.addTag(key, value); } } }
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * <p>/* w w w .j av a2s.com*/ * Iterate through a collection of {@link InternalPermission}and build a * unique collection of {@link java.security.Permission}. * </p> * * @param omPermissions The collection of {@link InternalPermission}. * @return The collection of {@link java.security.Permission}. */ private Permissions appendSecurityPermissions(Collection omPermissions, Permissions permissions) { Iterator internalPermissionsIter = omPermissions.iterator(); while (internalPermissionsIter.hasNext()) { InternalPermission internalPermission = (InternalPermission) internalPermissionsIter.next(); Permission permission = null; try { Class permissionClass = Class.forName(internalPermission.getClassname()); Class[] parameterTypes = { String.class, String.class }; Constructor permissionConstructor = permissionClass.getConstructor(parameterTypes); Object[] initArgs = { internalPermission.getName(), internalPermission.getActions() }; permission = (Permission) permissionConstructor.newInstance(initArgs); if (!Collections.list(permissions.elements()).contains(permission)) { if (log.isDebugEnabled()) { log.debug("Adding permimssion: [class, " + permission.getClass().getName() + "], " + "[name, " + permission.getName() + "], " + "[actions, " + permission.getActions() + "]"); } permissions.add(permission); } } catch (Exception e) { e.printStackTrace(); } } return permissions; }
From source file:com.discovery.darchrow.util.CollectionsUtil.java
/** * ??.//from ww w . j a va 2s . c om * * @param <T> * the generic type * @param enumeration * the enumeration * @return if Validator.isNullOrEmpty(enumeration), return {@link Collections#emptyList()},emptyList???<br> * else return {@link Collections#list(Enumeration)} * @see Collections#emptyList() * @see Collections#EMPTY_LIST * @see Collections#list(Enumeration) * @see org.apache.commons.collections.EnumerationUtils#toList(Enumeration) * @since 1.0.7 * @since JDK 1.5 */ public static final <T> List<T> toList(final Enumeration<T> enumeration) { if (Validator.isNullOrEmpty(enumeration)) { return Collections.emptyList(); } ArrayList<T> list = Collections.list(enumeration); return list; }