Java Collections Examples

Java Collections - 30 examples found. These are the top rated real world Java examples of java.util.Collections extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  /**
   * Prints the genetics of this Brain to a String.
   *
   * @return a String representation of the underlying neural network
   */
  public String toString() {
    // TODO: Make this and DNA use Braincraft.listToString()
    // First line
    String output = "genomestart " + ID + "\n";

    // Node list
    ArrayList<NNode> nodes = new ArrayList<NNode>();
    nodes.addAll(nodemap.values());
    Collections.sort(nodes);
    output += Braincraft.listToString(nodes);

    // Gene list
    Set<Gene> genes = new HashSet<Gene>();
    for (ArrayList<Gene> arl : connections.values()) {
      for (Gene g : arl) {
        genes.add(g);
      }
    }
    ArrayList<Gene> allgenes = new ArrayList<Gene>();
    allgenes.addAll(genes);
    Collections.sort(allgenes);
    output += Braincraft.listToString(allgenes);

    // Last line
    output += "genomeend" + "\n";

    return output;
  }
Example #2
0
 static {
   Set<String> set = new HashSet<String>();
   set.add("add");
   set.add("sub");
   set.add("and");
   set.add("or");
   twoArgArithmeticCommandSet = Collections.unmodifiableSet(set);
   set = new HashSet<String>();
   set.add("neg");
   set.add("not");
   singleArgArithmeticCommandSet = Collections.unmodifiableSet(set);
   set = new HashSet<String>();
   set.add("gt");
   set.add("lt");
   set.add("eq");
   twoArgArithmeticComparisonCommandSet = Collections.unmodifiableSet(set);
   Map<String, String> map = new HashMap<String, String>();
   map.put("add", "+");
   map.put("sub", "-");
   map.put("and", "&");
   map.put("or", "|");
   map.put("neg", "-");
   map.put("not", "!");
   map.put("gt", "JGT");
   map.put("lt", "JLT");
   map.put("eq", "JEQ");
   arithmeticOperatorMap = Collections.unmodifiableMap(map);
 }
Example #3
0
  public SelectMany05Bean() {

    HobbitBean[] hobbits = {
      new HobbitBean("Bilbo", "Ring Finder"),
      new HobbitBean("Frodo", "Ring Bearer"),
      new HobbitBean("Merry", "Trouble Maker"),
      new HobbitBean("Pippin", "Trouble Maker")
    };

    Set<SelectItem> items = new LinkedHashSet<SelectItem>();
    for (HobbitBean hobbit : hobbits) {
      items.add(new SelectItem(hobbit.getName()));
    }
    hobbitCollection = new TreeSet<HobbitBean>();
    hobbitCollection.addAll(Arrays.asList(hobbits));
    possibleValues = Collections.unmodifiableSet(items);
    initialSortedSetValues = new TreeSet<String>(Collections.reverseOrder());
    initialSortedSetValues.add("Pippin");
    initialSortedSetValues.add("Frodo");
    initialCollectionValues = new LinkedHashSet<String>(2);
    initialCollectionValues.add("Bilbo");
    initialCollectionValues.add("Merry");
    initialSetValues = new CopyOnWriteArraySet<String>(); // not Cloneable
    initialSetValues.add("Frodo");
    initialListValues = new Vector<String>();
    initialListValues.add("Bilbo");
    initialListValues.add("Pippin");
    initialListValues.add("Merry");
    hobbitDataModel =
        new ListDataModel<HobbitBean>(new ArrayList<HobbitBean>(Arrays.asList(hobbits)));
  }
Example #4
0
  @Test
  public void testClientWildcard() throws Exception {
    BaseClientDetails theclient =
        new BaseClientDetails(
            "client",
            "zones",
            "zones.*.admin",
            "authorization_code, password",
            "scim.read, scim.write",
            "http://localhost:8080/uaa");
    theclient.setAutoApproveScopes(Arrays.asList("zones.*.admin"));
    Map<String, ? extends ClientDetails> clientDetailsStore =
        Collections.singletonMap("client", theclient);

    clientDetailsService.setClientDetailsStore(clientDetailsStore);
    tokenServices.setClientDetailsService(clientDetailsService);

    authorizationRequest =
        new AuthorizationRequest("client", Collections.singleton("zones.myzone.admin"));
    authorizationRequest.setResourceIds(new HashSet<>(Arrays.asList("client", "zones")));
    authentication =
        new OAuth2Authentication(
            authorizationRequest.createOAuth2Request(),
            UaaAuthenticationTestFactory.getAuthentication(userId, userName, "olds@vmware.com"));

    accessToken = tokenServices.createAccessToken(authentication);

    endpoint.checkToken(accessToken.getValue());
  }
  @Override
  public List<String> getSuggestions(String query) {
    try {
      if (artistName == null) {
        return NamedData.namedDataListToNameList(
            internetSearchEngine.searchAudios(query, maxCount, 1).elements);
      } else {
        List<String> result = new ArrayList<>();
        List<Audio> audios = internetSearchEngine.searchAudios(query, maxCount * 2, 1).elements;
        audios = NamedData.uniqueNames(audios);

        int removedCount = 0;
        for (int i = audios.size() - 1; i >= 0; i--) {
          Audio audio = audios.get(i);
          if (result.size() - removedCount > minCount
              && !Strings.equalsIgnoreCase(audio.getArtistName(), artistName)) {
            removedCount++;
          } else {
            result.add(audio.getName());
          }
        }

        Collections.reverse(result);
        return result;
      }
    } catch (IOException e) {
      return Collections.emptyList();
    }
  }
  /** {@link IDataDeleter} implementations to delegate delete operations to. */
  @SuppressWarnings("unchecked")
  @Autowired(required = false)
  public void setDataDeleters(Collection<IDataDeleter<? extends Object>> dataDeleters) {
    final Map<String, IDataDeleter<Object>> dataDeletersMap =
        new LinkedHashMap<String, IDataDeleter<Object>>();

    final Set<IPortalDataType> portalDataTypes = new LinkedHashSet<IPortalDataType>();

    for (final IDataDeleter<?> dataImporter : dataDeleters) {
      final IPortalDataType portalDataType = dataImporter.getPortalDataType();
      final String typeId = portalDataType.getTypeId();

      this.logger.debug(
          "Registering IDataDeleter for '{}' - {}", new Object[] {typeId, dataImporter});
      final IDataDeleter<Object> existing =
          dataDeletersMap.put(typeId, (IDataDeleter<Object>) dataImporter);
      if (existing != null) {
        this.logger.warn(
            "Duplicate IDataDeleter typeId for {} Replacing {} with {}",
            new Object[] {typeId, existing, dataImporter});
      }

      portalDataTypes.add(portalDataType);
    }

    this.portalDataDeleters = Collections.unmodifiableMap(dataDeletersMap);
    this.deletePortalDataTypes = Collections.unmodifiableSet(portalDataTypes);
  }