List of usage examples for java.util Set size
int size();
From source file:musite.ProteinsUtil.java
/** * * @param proteins// w ww . java 2 s .c om * @param ptm * @param enzyme * @return */ public static int countSites(Proteins proteins, Set<AminoAcid> aminoAcids, PTM ptm, Set<String> enzymes) { if (proteins == null || aminoAcids == null || aminoAcids.isEmpty()) throw new IllegalArgumentException(); int count = 0; if (ptm == null) { // residue Iterator<Protein> it = proteins.proteinIterator(); Set<Character> aas = AminoAcid.oneLetters(aminoAcids); while (it.hasNext()) { Protein protein = it.next(); String proteinSeq = protein.getSequence().toUpperCase(); for (char aa : aas) { count += StringUtils.countMatches(proteinSeq, "" + aa); } } } else { Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Set<Integer> sites = PTMAnnotationUtil.getSites(it.next(), ptm, aminoAcids, enzymes); if (sites != null && !sites.isEmpty()) { count += sites.size(); } } } return count; }
From source file:com.tesora.dve.tools.aitemplatebuilder.PrivateRange.java
private static double computeAverageTypeSizeForColumnVector(final Set<TableColumn> columns) { double sum = 0.0; for (final TableColumn column : columns) { final Type type = column.getType(); if (type.isStringType() || type.isNumericType()) { sum += type.getSize();/*from w w w . ja v a2s . com*/ } } return (sum / columns.size()); }
From source file:com.epam.reportportal.jbehave.JBehaveUtils.java
/** * Starts story (test suite level) in ReportPortal * * @param story// www . ja va2s .c o m */ public static void startStory(Story story, boolean givenStory) { if (RP_IS_DOWN.get()) { return; } StartTestItemRQ rq = new StartTestItemRQ(); rq.setLaunchId(JBehaveContext.getCurrentLaunch()); Set<String> metaProperties = story.getMeta().getPropertyNames(); Map<String, String> metaMap = new HashMap<String, String>(metaProperties.size()); for (String metaProperty : metaProperties) { metaMap.put(metaProperty, story.getMeta().getProperty(metaProperty)); } if (Strings.isNullOrEmpty(story.getDescription().asString())) { rq.setDescription(story.getDescription().asString() + "\n" + joinMeta(metaMap)); } rq.setName(normalizeLength(story.getName())); rq.setStartTime(Calendar.getInstance().getTime()); rq.setType("STORY"); try { EntryCreatedRS rs; JBehaveContext.Story currentStory; if (givenStory) { /* * Given story means inner story. That's why we need to create * new story and assign parent to it */ String parent = JBehaveContext.getCurrentStory().getCurrentScenario() != null ? JBehaveContext.getCurrentStory().getCurrentScenario() : JBehaveContext.getCurrentStory().getCurrentStoryId(); rs = reportPortalService.get().startTestItem(parent, rq); currentStory = new JBehaveContext.Story(); currentStory.setParent(JBehaveContext.getCurrentStory()); JBehaveContext.setCurrentStory(currentStory); } else { rs = reportPortalService.get().startRootTestItem(rq); currentStory = JBehaveContext.getCurrentStory(); } currentStory.setCurrentStoryId(rs.getId()); currentStory.setStoryMeta(story.getMeta()); } catch (RestEndpointIOException e) { e.printStackTrace(); // NOSONAR LOGGER.error("Unable to start story in ReportPortal", e); } }
From source file:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Creates a new entity model based upon the specified entity. * @param entity/*w ww . j ava 2 s . com*/ * @return * @throws EntityModelException */ @SuppressWarnings("unchecked") public static IEntityModel createModel(IEntity entity) { // create model and InvocationHandler Set<Class<?>> interfacesSet = new HashSet<Class<?>>(); Class<? extends IEntity> clazz = entity.getClass(); interfacesSet.add(IEntityModel.class); // recursivly add all interfaces Class<?> c = clazz; while (c != null) { Class<?>[] orgInterfaces = c.getInterfaces(); for (int i = 0; i < orgInterfaces.length; i++) { interfacesSet.add(orgInterfaces[i]); } c = c.getSuperclass(); } Class[] interfaces = new Class[interfacesSet.size()]; int idx = 0; for (Iterator<Class<?>> it = interfacesSet.iterator(); it.hasNext();) { interfaces[idx++] = it.next(); } EntityModelInvocationHandler ih = new EntityModelInvocationHandler(entity); return (IEntityModel) Proxy.newProxyInstance(classLoader, interfaces, ih); }
From source file:de.unisb.cs.st.javaslicer.slicing.DirectSlicer.java
private static <T> Set<T> intersect(Set<T> set1, Set<T> set2) { if (set1.isEmpty() || set2.isEmpty()) return Collections.emptySet(); Set<T> smallerSet;//from ww w. j a v a 2 s.c o m Set<T> biggerSet; if (set1.size() < set2.size()) { smallerSet = set1; biggerSet = set2; } else { smallerSet = set2; biggerSet = set1; } Set<T> intersection = null; for (T obj : smallerSet) { if (biggerSet.contains(obj)) { if (intersection == null) intersection = new HashSet<T>(); intersection.add(obj); } } if (intersection == null) return Collections.emptySet(); return intersection; }
From source file:com.cpjit.swagger4j.util.ReflectUtils.java
/** * ???//from w w w. j a v a 2s . co m * * @param packNames * ?? * @return ??null * 0 * <li>?packNames0</li> * <li>?</li> * * @throws FileNotFoundException ? * @throws IllegalArgumentException ??? * @throws ClassNotFoundException ? * * @since 1.0.0 */ public static List<Class<?>> scanClazzs(List<String> packNames) throws FileNotFoundException, IllegalArgumentException, ClassNotFoundException { if (packNames.size() < 1) { // ?? return Collections.emptyList(); } Set<Class<?>> clazzs = new HashSet<Class<?>>(); for (String packName : packNames) { List<String> clazzNames = scanClazzName(packName); for (String clazzName : clazzNames) { // ? Class<?> clazz = Class.forName(clazzName); clazzs.add(clazz); } } if (clazzs.size() < 1) { // ? return Collections.emptyList(); } return new ArrayList<Class<?>>(clazzs); }
From source file:Main.java
public static String[][] returnTable(Collection E) { if ((E == null) || E.isEmpty()) { System.out.println("The collection is empty!"); }//from w ww . j a v a2 s. co m Set<Field> collectionFields = new TreeSet<>(new Comparator<Field>() { @Override public int compare(Field o1, Field o2) { return o1.getName().compareTo(o2.getName()); } }); for (Object o : E) { Class c = o.getClass(); createSetOfFields(collectionFields, c); while (c.getSuperclass() != null) { c = c.getSuperclass(); createSetOfFields(collectionFields, c); } } String[][] exitText = new String[E.size() + 1][collectionFields.size() + 1]; exitText[0][0] = String.format("%20s", "Class"); int indexOfColumn = 0; for (Field f : collectionFields) { exitText[0][indexOfColumn + 1] = String.format("%20s", f.getName()); indexOfColumn++; } int indexOfRow = 0; for (Object o : E) { indexOfColumn = 0; exitText[indexOfRow + 1][0] = String.format("%20s", o.getClass().getSimpleName()); for (Field field : collectionFields) { try { field.setAccessible(true); if (field.get(o) instanceof Date) { exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20tD", field.get(o)); } else { String temp = String.valueOf(field.get(o)); exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20s", temp); } } catch (Exception e) { exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20s", "-"); } indexOfColumn++; } indexOfRow++; } return exitText; }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
public static void describeInstances() { try {//from w ww . ja v a 2s .c om DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones(); System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones."); for (AvailabilityZone az : availabilityZonesResult.getAvailabilityZones()) { System.out.println(az); } DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); List<Reservation> reservations = describeInstancesRequest.getReservations(); Set<Instance> instances = new HashSet<Instance>(); for (Reservation reservation : reservations) { instances.addAll(reservation.getInstances()); } System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running."); for (Instance instance : instances) { System.out.println(instance); } } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:it.univaq.incipict.profilemanager.common.utility.Utility.java
public static HashMap<Profile, Double> getEuclideanDistances(List<Profile> profilesList, User user) { Map<Profile, Double> result = new HashMap<Profile, Double>(); Set<ProfileInformation> profileInformationSet; Set<Information> userInformationSet; // Retrieve user information set userInformationSet = user.getInformationSet(); if (userInformationSet.isEmpty()) { return (HashMap<Profile, Double>) result; }//from www. j a v a 2 s. co m // For each Profile for (Profile profile : profilesList) { profileInformationSet = profile.getProfileInformationSet(); int vectorsLenght = Math.max(profileInformationSet.size(), userInformationSet.size()); RealVector ranksRealVector = new ArrayRealVector(new double[] {}); RealVector userInformationVector = new ArrayRealVector(new double[] {}); // Loop userInformationSet and // profileInformationSet (i.e. one specific column vector in the // knowledge base representation) for (Information information : userInformationSet) { Long x = information.getId(); for (ProfileInformation profileInformation : profileInformationSet) { Long y = profileInformation.getInformation().getId(); // User selected information was stored in a RealVector at same // position of relative ranksVector // This permit to calculate Euclidean distance right. if (x == y) { userInformationVector = userInformationVector.append(1d); // Associated:1, Else:0 ranksRealVector = ranksRealVector.append(profileInformation.getRank()); profileInformationSet.remove(profileInformation); break; } } } // At this point we aren't interested to elements position // because every other information worth zero. // Euclidean distance are not influenced from position of 0-elements in // a "sub-vector". // if they are all zeros. // => Append the zeros until completion of the length of the vectors userInformationVector = userInformationVector .append(new double[vectorsLenght - userInformationSet.size()]); for (ProfileInformation profileInformation : profileInformationSet) { // Append the remaining elements of this set (profileInformationSet) ranksRealVector = ranksRealVector.append(profileInformation.getRank()); } // Calculate Euclidean Distance double distance = userInformationVector.getDistance(ranksRealVector); // add the distance to Distance's Map result.put(profile, distance); } // END, goto Next Profile // return the HashMap sorted by value (ASC) return (HashMap<Profile, Double>) MapUtil.sortByValueASC(result); }
From source file:net.andydvorak.intellij.lessc.fs.VirtualFileLocationChange.java
public static int deleteCssFiles(@NotNull final VirtualFileEvent virtualFileEvent, @Nullable final LessProfile lessProfile, @NotNull final VfsLocationChangeDialog vfsLocationChangeDialog) throws IOException { final Set<VirtualFileLocationChange> changes = getChanges(lessProfile, virtualFileEvent.getFile(), virtualFileEvent.getFile().getParent()); if (changes.isEmpty() || !vfsLocationChangeDialog.shouldDeleteCssFile(virtualFileEvent)) return 0; for (VirtualFileLocationChange locationChange : changes) { locationChange.delete();/*from w w w . j a va 2 s . co m*/ } return changes.size(); }