List of usage examples for java.util Collection add
boolean add(E e);
From source file:uk.ac.horizon.aestheticodes.controllers.ExperienceListUpdater.java
public static void save(Context context, ExperienceListController experiences) { try {/* ww w. j a v a 2s . c o m*/ final File experienceFile = new File(context.getFilesDir(), "experiences.json"); final FileWriter writer = new FileWriter(experienceFile); final Collection<Experience> saveExperiences = new ArrayList<>(); for (Experience experience : experiences.get()) { if (experience.getOp() != Experience.Operation.temp) { saveExperiences.add(experience); } } Gson gson = ExperienceParser.createParser(); gson.toJson(saveExperiences, writer); writer.flush(); writer.close(); } catch (Exception e) { Log.e("", e.getMessage(), e); } }
From source file:org.socialhistoryservices.pid.service.StubPidResourceServiceTest.java
@BeforeClass public static void setup() throws Exception { if (System.getProperty("pid.properties") == null) // -Dhandle.properties=pid.properties System.setProperty("pid.properties", "server/pid.properties"); class Grant implements GrantedAuthority { private String authority; public Grant(String authority) { this.authority = authority; }/*from www . ja v a2 s . c o m*/ @Override public String getAuthority() { return authority; } } final Collection<GrantedAuthority> authorities = new ArrayList(4); authorities.add(new Grant("ROLE_PID-WEBSERVICE-USER")); authorities.add(new Grant("ROLE_PID-WEBSERVICE-USER_00000.1")); authorities.add(new Grant("ROLE_PID-WEBSERVICE-USER_" + na)); authorities.add(new Grant("ROLE_PID-WEBSERVICE-USER_00000.2")); ClientToken clientToken = new ClientToken("test-client", UUID.randomUUID().toString(), null); UsernamePasswordAuthenticationToken usernamePasswordAuthentication = new UsernamePasswordAuthenticationToken( null, null, authorities); OAuth2Authentication auth2Authentication = new OAuth2Authentication(clientToken, usernamePasswordAuthentication); final SecurityContext context = SecurityContextHolder.getContext(); context.setAuthentication(auth2Authentication); }
From source file:org.LexGrid.LexBIG.caCore.utils.LexEVSCaCoreUtils.java
public static <T> T recurseReflect(final T obj, final DoInReflectionCallback callback) { if (obj == null) { return null; }//from w ww . j ava 2 s.c o m ReflectionUtils.doWithFields(obj.getClass(), new FieldCallback() { public void doWith(Field arg0) throws IllegalArgumentException, IllegalAccessException { if (!ClassUtils.isPrimitiveOrWrapper(arg0.getType()) && !ClassUtils.isPrimitiveArray(arg0.getType()) && !ClassUtils.isPrimitiveWrapperArray(arg0.getType()) && !arg0.getType().isEnum() && (isLexBigClass(arg0.getType()) || Collection.class.isAssignableFrom(arg0.getType()) || Map.class.isAssignableFrom(arg0.getType()))) { arg0.setAccessible(true); Object recurse = arg0.get(obj); if (recurse != null) { if (CycleDetectingCallback.class.isAssignableFrom(recurse.getClass())) { System.out.println("ere"); } if (Collection.class.isAssignableFrom(recurse.getClass())) { Collection collection = (Collection) recurse; for (Object o : collection) { if (callback.actionRequired(o)) { collection.remove(o); collection.add(recurseReflect(o, callback)); } else { recurseReflect(o, callback); } } } else if (Map.class.isAssignableFrom(recurse.getClass())) { Map map = (Map) recurse; for (Object key : map.keySet()) { Object value = map.get(key); if (callback.actionRequired(key) || callback.actionRequired(value)) { map.remove(key); map.put(recurseReflect(key, callback), recurseReflect(value, callback)); } else { recurseReflect(key, callback); recurseReflect(value, callback); } } } else { if (callback.actionRequired(recurse)) { Object newObject = recurseReflect(recurse, callback); arg0.set(obj, newObject); } else { recurseReflect(recurse, callback); } } } } } }); return callback.doInReflection(obj); }
From source file:mitm.common.security.ca.RequestUtils.java
/** * Returns the requests with a matching email address. */// w w w . j a va 2 s . c o m public static Collection<RequestParameters> findByEmail(Collection<RequestParameters> requests, String email, Match match) { Collection<RequestParameters> result = new LinkedList<RequestParameters>(); if (requests == null || StringUtils.isEmpty(email)) { return result; } for (RequestParameters request : requests) { if (match == null || match == Match.EXACT) { if (email.equalsIgnoreCase(request.getEmail())) { result.add(request); } } else { if (StringUtils.containsIgnoreCase(request.getEmail(), email)) { result.add(request); } } } return result; }
From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.ResourceCRLRevocationCheckerTests.java
/** * Gets the unit test parameters.// ww w .java2 s. c o m * * @return Test parameter data. */ @Parameters public static Collection<Object[]> getTestParameters() { final Collection<Object[]> params = new ArrayList<Object[]>(); final ThresholdExpiredCRLRevocationPolicy zeroThresholdPolicy = new ThresholdExpiredCRLRevocationPolicy(); zeroThresholdPolicy.setThreshold(0); // Test case #1 // Valid certificate on valid CRL data params.add(new Object[] { new ResourceCRLRevocationChecker( new ClassPathResource[] { new ClassPathResource("userCA-valid.crl"), }), zeroThresholdPolicy, new String[] { "user-valid.crt" }, null, }); // Test case #2 // Revoked certificate on valid CRL data params.add(new Object[] { new ResourceCRLRevocationChecker( new ClassPathResource[] { new ClassPathResource("userCA-valid.crl"), new ClassPathResource("intermediateCA-valid.crl"), new ClassPathResource("rootCA-valid.crl"), }), zeroThresholdPolicy, new String[] { "user-revoked.crt", "userCA.crt", "intermediateCA.crt", "rootCA.crt" }, new RevokedCertificateException(new Date(), new BigInteger("1")), }); // Test case #3 // Valid certificate on expired CRL data for head cert params.add(new Object[] { new ResourceCRLRevocationChecker( new ClassPathResource[] { new ClassPathResource("userCA-expired.crl"), new ClassPathResource("intermediateCA-valid.crl"), new ClassPathResource("rootCA-valid.crl"), }), zeroThresholdPolicy, new String[] { "user-valid.crt", "userCA.crt", "intermediateCA.crt", "rootCA.crt" }, new ExpiredCRLException("test", new Date()), }); // Test case #4 // Valid certificate on expired CRL data for intermediate cert params.add(new Object[] { new ResourceCRLRevocationChecker( new ClassPathResource[] { new ClassPathResource("userCA-valid.crl"), new ClassPathResource("intermediateCA-expired.crl"), new ClassPathResource("rootCA-valid.crl"), }), zeroThresholdPolicy, new String[] { "user-valid.crt", "userCA.crt", "intermediateCA.crt", "rootCA.crt" }, new ExpiredCRLException("test", new Date()), }); // Test case #5 // Valid certificate on expired CRL data with custom expiration // policy to always allow expired CRL data params.add(new Object[] { new ResourceCRLRevocationChecker( new ClassPathResource[] { new ClassPathResource("userCA-expired.crl"), }), new RevocationPolicy<X509CRL>() { public void apply(X509CRL crl) { /* Do nothing to allow unconditionally */} }, new String[] { "user-valid.crt" }, null, }); return params; }
From source file:com.hortonworks.registries.common.util.ReflectionHelper.java
public static Collection<Class<?>> getAnnotatedClasses(String basePackage, Class<? extends Annotation> annotation) { Collection<Class<?>> classes = new ArrayList<>(); ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false);// www . j av a 2s . c o m provider.addIncludeFilter(new AnnotationTypeFilter(annotation)); for (BeanDefinition beanDef : provider.findCandidateComponents(basePackage)) { try { classes.add(Class.forName(beanDef.getBeanClassName())); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return classes; }
From source file:com.aliyun.odps.local.common.utils.LocalRunUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Collection<File> listFiles(final File dir, final String relativePath) throws IOException { // privileged code, for this method may be invoked by user code try {/*from ww w.j av a 2 s. co m*/ return (Collection<File>) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { File relativeDir = new File(dir, relativePath); checkParent(dir, relativePath); if (relativeDir.isDirectory()) { return FileUtils.listFiles(relativeDir, new InternalIOFilter(), new InternalIOFilter()); } else { Collection<File> files = new java.util.LinkedList<File>(); files.add(relativeDir); return files; } } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw e; } } }
From source file:eu.medsea.util.EncodingGuesser.java
/** * Get a Collection containing entries in both the supported encodings * and the passed in String [] of encodings. * This is used by TextMimeDetector to get a valid list of the preferred encodings. * @param encodings//ww w .ja v a 2 s . com * @return a Collection containing all valid encodings contained in the passed in encodings array */ public static Collection getValidEncodings(String[] encodings) { Collection c = new ArrayList(); for (int i = 0; i < encodings.length; i++) { if (supportedEncodings.contains(encodings[i])) { c.add(encodings[i]); } } return c; }
From source file:com.xebialabs.deployit.cli.ext.mustachify.io.Files2.java
private static void innerListFiles(Collection<File> files, File directory, IOFileFilter filter, boolean includeDirs) { File[] found = directory.listFiles((FileFilter) filter); if (found != null) { for (int i = 0; i < found.length; i++) { boolean isDir = found[i].isDirectory(); if (!isDir || includeDirs) { files.add(found[i]); }/*from w w w. j a va2 s.c o m*/ if (isDir) { innerListFiles(files, found[i], filter, includeDirs); } } } }
From source file:gov.nih.nci.caintegrator.common.PermissibleValueUtil.java
private static void addNumericValue(Collection<PermissibleValue> abstractPermissibleValues, String displayString) {// ww w . j av a2 s .c o m PermissibleValue newPermissibleValue = new PermissibleValue(); newPermissibleValue.setValue(NumericUtil.formatDisplay(displayString)); abstractPermissibleValues.add(newPermissibleValue); }