private void validate(
      File file,
      Collection<Exception> exceptions,
      Collection<MavenProjectProblem> problems,
      Collection<MavenId> unresolvedArtifacts)
      throws RemoteException {
    for (Exception each : exceptions) {
      Maven3ServerGlobals.getLogger().info(each);

      if (each instanceof InvalidProjectModelException) {
        ModelValidationResult modelValidationResult =
            ((InvalidProjectModelException) each).getValidationResult();
        if (modelValidationResult != null) {
          for (Object eachValidationProblem : modelValidationResult.getMessages()) {
            problems.add(
                MavenProjectProblem.createStructureProblem(
                    file.getPath(), (String) eachValidationProblem));
          }
        } else {
          problems.add(
              MavenProjectProblem.createStructureProblem(
                  file.getPath(), each.getCause().getMessage()));
        }
      } else if (each instanceof ProjectBuildingException) {
        String causeMessage =
            each.getCause() != null ? each.getCause().getMessage() : each.getMessage();
        problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), causeMessage));
      } else {
        problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getMessage()));
      }
    }
    unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds());
  }
  /** @throws Exception If failed. */
  public void testClientAffinity() throws Exception {
    GridClientData partitioned = client.data(PARTITIONED_CACHE_NAME);

    Collection<Object> keys = new ArrayList<>();

    keys.addAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE, 1, Integer.MAX_VALUE));

    Random rnd = new Random();
    StringBuilder sb = new StringBuilder();

    // Generate some random strings.
    for (int i = 0; i < 100; i++) {
      sb.setLength(0);

      for (int j = 0; j < 255; j++)
        // Only printable ASCII symbols for test.
        sb.append((char) (rnd.nextInt(0x7f - 0x20) + 0x20));

      keys.add(sb.toString());
    }

    // Generate some more keys to achieve better coverage.
    for (int i = 0; i < 100; i++) keys.add(UUID.randomUUID());

    for (Object key : keys) {
      UUID nodeId = grid(0).mapKeyToNode(PARTITIONED_CACHE_NAME, key).id();

      UUID clientNodeId = partitioned.affinity(key);

      assertEquals(
          "Invalid affinity mapping for REST response for key: " + key, nodeId, clientNodeId);
    }
  }
Beispiel #3
0
  public ConfigFile(String path) throws IOException {
    filePath = path;
    charset = Charset.forName("UTF-8");
    if (!new File(path).exists()) return;

    Collection<Line> currentLines = globalLines;
    InputStreamReader isr = new InputStreamReader(new FileInputStream(path), charset);
    BufferedReader br = new BufferedReader(isr);
    try {
      String l = br.readLine();
      while (l != null) {
        // 解决跨平台文本文件换行符不同的问题
        while (!l.isEmpty()
            && (l.charAt(l.length() - 1) == '\r' || l.charAt(l.length() - 1) == '\n'))
          l = l.substring(0, l.length() - 1);

        Sector sec = parseSectorName(l);
        if (sec != null) {
          currentLines = sec.lines;
          sectors.add(sec);
        } else {
          Line line = parseLine(l);
          currentLines.add(line);
        }

        l = br.readLine();
      }
    } finally {
      br.close();
      isr.close();
    }
  }
  public static void main(String[] args) {

    Collection<String> collection = new HashSet<String>();
    collection.add("one");
    collection.add("two");

    Iterator<String> iterator = collection.iterator();
    while (iterator.hasNext()) {
      String s = iterator.next();
      System.out.println(s);
    }
    System.out.println("======================================");

    TreeSet<String> set = new TreeSet<String>(collection);
    Iterator<String> itor = set.iterator();
    while (itor.hasNext()) {
      System.out.println(itor.next());
    }

    Collection<String> colList = new ArrayList<String>();
    colList.add("one");
    colList.add("two");
    colList.add("three");

    if (colList.containsAll(collection)) {
      System.out.println("true");
    }

    System.out.println("=================");

    String[] strings = colList.toArray(new String[0]);
    String[] strings1 = (String[]) colList.toArray();
  }
  private static void highlightTodos(
      @NotNull PsiFile file,
      @NotNull CharSequence text,
      int startOffset,
      int endOffset,
      @NotNull ProgressIndicator progress,
      @NotNull ProperTextRange priorityRange,
      @NotNull Collection<HighlightInfo> result,
      @NotNull Collection<HighlightInfo> outsideResult) {
    PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
    TodoItem[] todoItems = helper.findTodoItems(file, startOffset, endOffset);
    if (todoItems.length == 0) return;

    for (TodoItem todoItem : todoItems) {
      progress.checkCanceled();
      TextRange range = todoItem.getTextRange();
      String description =
          text.subSequence(range.getStartOffset(), range.getEndOffset()).toString();
      TextAttributes attributes = todoItem.getPattern().getAttributes().getTextAttributes();
      HighlightInfo info =
          HighlightInfo.createHighlightInfo(
              HighlightInfoType.TODO, range, description, description, attributes);
      assert info != null;
      if (priorityRange.containsRange(info.getStartOffset(), info.getEndOffset())) {
        result.add(info);
      } else {
        outsideResult.add(info);
      }
    }
  }
  /*
   * (non-Javadoc)
   * @see de.hpi.bpt.hypergraph.abs.IDirectedHyperGraph#getEdgesWithSourcesAndTargets(java.util.Collection, java.util.Collection)
   */
  public Collection<E> getEdgesWithSourcesAndTargets(Collection<V> ss, Collection<V> ts) {
    Collection<E> result = new ArrayList<E>();
    if (ss == null && ts == null) return result;
    if (ss.size() == 0 && ts.size() == 0) return result;

    if (ss != null && ss.size() > 0) {
      V v = ss.iterator().next();
      Collection<E> es = this.getEdgesWithSource(v);
      if (es == null) return result;
      Iterator<E> i = es.iterator();
      while (i.hasNext()) {
        E e = i.next();
        if (e.hasSources(ss) && e.hasTargets(ts)) result.add(e);
      }
    } else if (ts != null && ts.size() > 0) {
      V v = ts.iterator().next();
      Collection<E> es = this.getEdgesWithTarget(v);
      if (es == null) return result;
      Iterator<E> i = es.iterator();
      while (i.hasNext()) {
        E e = i.next();
        if (e.hasSources(ss) && e.hasTargets(ts)) result.add(e);
      }
    }

    return result;
  }
  /**
   * @param in Object input.
   * @return Read collection.
   * @throws IOException If failed.
   * @throws ClassNotFoundException If failed.
   */
  private Collection<Object> readFieldsCollection(ObjectInput in)
      throws IOException, ClassNotFoundException {
    assert fields;

    int size = in.readInt();

    if (size == -1) return null;

    Collection<Object> res = new ArrayList<>(size);

    for (int i = 0; i < size; i++) {
      int size0 = in.readInt();

      Collection<Object> col = new ArrayList<>(size0);

      for (int j = 0; j < size0; j++) col.add(in.readObject());

      assert col.size() == size0;

      res.add(col);
    }

    assert res.size() == size;

    return res;
  }
Beispiel #8
0
 /**
  * Returns a collection with all the groups that the user may include in his roster. The following
  * criteria will be used to select the groups: 1) Groups that are configured so that everybody can
  * include in his roster, 2) Groups that are configured so that its users may include the group in
  * their rosters and the user is a group user of the group and 3) User belongs to a Group that may
  * see a Group that whose members may include the Group in their rosters.
  *
  * @param user the user to return his shared groups.
  * @return a collection with all the groups that the user may include in his roster.
  */
 public Collection<Group> getSharedGroups(User user) {
   Collection<Group> answer = new HashSet<Group>();
   Collection<Group> groups = GroupManager.getInstance().getGroups();
   for (Group group : groups) {
     String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
     if ("onlyGroup".equals(showInRoster)) {
       if (group.isUser(user.getUsername())) {
         // The user belongs to the group so add the group to the answer
         answer.add(group);
       } else {
         // Check if the user belongs to a group that may see this group
         Collection<Group> groupList =
             parseGroups(group.getProperties().get("sharedRoster.groupList"));
         for (Group groupInList : groupList) {
           if (groupInList.isUser(user.getUsername())) {
             answer.add(group);
           }
         }
       }
     } else if ("everybody".equals(showInRoster)) {
       // Anyone can see this group so add the group to the answer
       answer.add(group);
     }
   }
   return answer;
 }
Beispiel #9
0
 private boolean cons(Pagina p, Collection<Pagina> buf) {
   Pagina[] cp = new Pagina[0];
   Collection<Pagina> open, close = new HashSet<Pagina>();
   synchronized (ui.sess.glob.paginae) {
     open = new HashSet<Pagina>(ui.sess.glob.paginae);
   }
   boolean ret = true;
   while (!open.isEmpty()) {
     Iterator<Pagina> iter = open.iterator();
     Pagina pag = iter.next();
     iter.remove();
     try {
       Resource r = pag.res();
       AButton ad = r.layer(Resource.action);
       if (ad == null) throw (new PaginaException(pag));
       Pagina parent = paginafor(ad.parent);
       if (parent == p) buf.add(pag);
       else if ((parent != null) && !close.contains(parent)) open.add(parent);
       close.add(pag);
     } catch (Loading e) {
       ret = false;
     }
   }
   return (ret);
 }
Beispiel #10
0
  /**
   * @param <H> is something that handles CallableDescriptor inside
   * @return
   */
  @NotNull
  public static <H> Collection<H> extractMembersOverridableInBothWays(
      @NotNull H overrider,
      @NotNull @Mutable Collection<H> extractFrom,
      @NotNull Function1<H, CallableDescriptor> descriptorByHandle,
      @NotNull Function1<H, Unit> onConflict) {
    Collection<H> overridable = new ArrayList<H>();
    overridable.add(overrider);
    CallableDescriptor overriderDescriptor = descriptorByHandle.invoke(overrider);
    for (Iterator<H> iterator = extractFrom.iterator(); iterator.hasNext(); ) {
      H candidate = iterator.next();
      CallableDescriptor candidateDescriptor = descriptorByHandle.invoke(candidate);
      if (overrider == candidate) {
        iterator.remove();
        continue;
      }

      OverrideCompatibilityInfo.Result finalResult =
          getBothWaysOverridability(overriderDescriptor, candidateDescriptor);

      if (finalResult == OVERRIDABLE) {
        overridable.add(candidate);
        iterator.remove();
      } else if (finalResult == CONFLICT) {
        onConflict.invoke(candidate);
        iterator.remove();
      }
    }
    return overridable;
  }
 private void collectTargetConfiguration(
     DependencyDescriptor dependencyDescriptor,
     ConfigurationMetaData fromConfiguration,
     String mappingRhs,
     ModuleDescriptor targetModule,
     Collection<String> targetConfigs) {
   String[] dependencyConfigurations =
       dependencyDescriptor.getDependencyConfigurations(mappingRhs, fromConfiguration.getName());
   for (String target : dependencyConfigurations) {
     String candidate = target;
     int startFallback = candidate.indexOf('(');
     if (startFallback >= 0) {
       if (candidate.charAt(candidate.length() - 1) == ')') {
         String preferred = candidate.substring(0, startFallback);
         if (targetModule.getConfiguration(preferred) != null) {
           targetConfigs.add(preferred);
           continue;
         }
         candidate = candidate.substring(startFallback + 1, candidate.length() - 1);
       }
     }
     if (candidate.equals("*")) {
       Collections.addAll(targetConfigs, targetModule.getPublicConfigurationsNames());
       continue;
     }
     targetConfigs.add(candidate);
   }
 }
Beispiel #12
0
 /**
  * <br>
  * <em>Purpose:</em> convenience function to build a Collection with params <br>
  * <em>Assumptions:</em> calls 'convert(text, Collection of params)'
  */
 public String convert(String text, String alttext, String p1, String p2, String p3) {
   Collection c = new LinkedList();
   c.add(p1);
   c.add(p2);
   c.add(p3);
   return convert(text, alttext, c);
 }
  private Fields generateTermVectorsFromDoc(TermVectorRequest request, boolean doAllFields)
      throws IOException {
    // parse the document, at the moment we do update the mapping, just like percolate
    ParsedDocument parsedDocument =
        parseDocument(indexShard.shardId().getIndex(), request.type(), request.doc());

    // select the right fields and generate term vectors
    ParseContext.Document doc = parsedDocument.rootDoc();
    Collection<String> seenFields = new HashSet<>();
    Collection<GetField> getFields = new HashSet<>();
    for (IndexableField field : doc.getFields()) {
      FieldMapper fieldMapper = indexShard.mapperService().smartNameFieldMapper(field.name());
      if (seenFields.contains(field.name())) {
        continue;
      } else {
        seenFields.add(field.name());
      }
      if (!isValidField(fieldMapper)) {
        continue;
      }
      if (request.selectedFields() == null
          && !doAllFields
          && !fieldMapper.fieldType().storeTermVectors()) {
        continue;
      }
      if (request.selectedFields() != null && !request.selectedFields().contains(field.name())) {
        continue;
      }
      String[] values = doc.getValues(field.name());
      getFields.add(new GetField(field.name(), Arrays.asList((Object[]) values)));
    }
    return generateTermVectors(getFields, request.offsets(), request.perFieldAnalyzer());
  }
 public static void main(String[] args) {
   Collection c = new ArrayList();
   // 添加元素
   c.add("孙悟空");
   // 虽然集合里不能放基本类型的值,但Java支持自动装箱
   c.add(6);
   System.out.println("c集合的元素个数为:" + c.size());
   // 删除指定元素
   c.remove(6);
   System.out.println("c集合的元素个数为:" + c.size());
   // 判断是否包含指定字符串
   System.out.println("c集合的是否包含\"孙悟空\"字符串:" + c.contains("孙悟空"));
   c.add("轻量级Java EE企业应用实战");
   System.out.println("c集合的元素:" + c);
   Collection books = new HashSet();
   books.add("轻量级Java EE企业应用实战");
   books.add("疯狂Java讲义");
   System.out.println("c集合是否完全包含books集合?" + c.containsAll(books));
   // 用c集合减去books集合里的元素
   c.removeAll(books);
   System.out.println("c集合的元素:" + c);
   // 删除c集合里所有元素
   c.clear();
   System.out.println("c集合的元素:" + c);
   // books集合里只剩下c集合里也包含的元素
   books.retainAll(c);
   System.out.println("books集合的元素:" + books);
 }
 // this method should be invoked from within the transaction wrapper that covers the request
 // processing so
 // that the db-calls in this method do not each generate new transactions. If executed from within
 // the context
 // of display rendering, this logic will be quite expensive due to the number of new transactions
 // needed.
 @Override
 public Collection<CMT> getAssignmentCommittees(
     String protocolLeadUnit, String docRouteStatus, String currentCommitteeId) {
   Collection<CMT> assignmentCommittees = new ArrayList<CMT>();
   // get the initial list of all valid committees; some of them will be filtered out by the logic
   // below
   Collection<CMT> candidateCommittees = getCandidateCommittees();
   if (CollectionUtils.isNotEmpty(candidateCommittees)) {
     if (isSaved(docRouteStatus)) {
       // Use the lead unit of the protocol to determine committees
       Set<String> unitIds = getProtocolUnitIds(protocolLeadUnit);
       for (CMT committee : candidateCommittees) {
         if (StringUtils.equalsIgnoreCase(committee.getCommitteeDocument().getDocStatusCode(), "F")
             && unitIds.contains(committee.getHomeUnit().getUnitNumber())) {
           assignmentCommittees.add(committee);
         }
       }
     } else {
       // we check the current user's authorization to assign committees
       String principalId = GlobalVariables.getUserSession().getPerson().getPrincipalId();
       for (CMT committee : candidateCommittees) {
         if (isCurrentUserAuthorizedToAssignThisCommittee(principalId, committee)
             || committee.getCommitteeId().equals(currentCommitteeId)) {
           assignmentCommittees.add(committee);
         }
       }
     }
   }
   return assignmentCommittees;
 }
Beispiel #16
0
  @NotNull
  private static Collection<CallableMemberDescriptor> extractMembersOverridableInBothWays(
      @NotNull CallableMemberDescriptor overrider,
      @NotNull Queue<CallableMemberDescriptor> extractFrom,
      @NotNull DescriptorSink sink) {
    Collection<CallableMemberDescriptor> overridable = new ArrayList<CallableMemberDescriptor>();
    overridable.add(overrider);
    for (Iterator<CallableMemberDescriptor> iterator = extractFrom.iterator();
        iterator.hasNext(); ) {
      CallableMemberDescriptor candidate = iterator.next();
      if (overrider == candidate) {
        iterator.remove();
        continue;
      }

      OverrideCompatibilityInfo.Result result1 =
          DEFAULT.isOverridableBy(candidate, overrider).getResult();
      OverrideCompatibilityInfo.Result result2 =
          DEFAULT.isOverridableBy(overrider, candidate).getResult();
      if (result1 == OVERRIDABLE && result2 == OVERRIDABLE) {
        overridable.add(candidate);
        iterator.remove();
      } else if (result1 == CONFLICT || result2 == CONFLICT) {
        sink.conflict(overrider, candidate);
        iterator.remove();
      }
    }
    return overridable;
  }
Beispiel #17
0
  private static Collection<CallableMemberDescriptor> extractAndBindOverridesForMember(
      @NotNull CallableMemberDescriptor fromCurrent,
      @NotNull Collection<? extends CallableMemberDescriptor> descriptorsFromSuper,
      @NotNull ClassDescriptor current,
      @NotNull DescriptorSink sink) {
    Collection<CallableMemberDescriptor> bound =
        new ArrayList<CallableMemberDescriptor>(descriptorsFromSuper.size());
    for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
      OverrideCompatibilityInfo.Result result =
          DEFAULT.isOverridableBy(fromSupertype, fromCurrent).getResult();

      boolean isVisible =
          Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSupertype, current);
      switch (result) {
        case OVERRIDABLE:
          if (isVisible) {
            fromCurrent.addOverriddenDescriptor(fromSupertype);
          }
          bound.add(fromSupertype);
          break;
        case CONFLICT:
          if (isVisible) {
            sink.conflict(fromSupertype, fromCurrent);
          }
          bound.add(fromSupertype);
          break;
        case INCOMPATIBLE:
          break;
      }
    }
    return bound;
  }
 public Collection getListTypes() {
   Collection typesList = new LinkedList();
   typesList.add(synchronization);
   typesList.add(labels);
   // typesList.add(booleen);
   return typesList;
 }
 static Collection fill(Collection<String> collection) {
   collection.add("rat");
   collection.add("cat");
   collection.add("dog");
   collection.add("dog");
   return collection;
 }
 public static void main(String[] args) {
   Collection c = new ArrayList(); // 可以放入不同类型的对象
   c.add("Hello");
   c.add(new Name("f1", "l1"));
   c.add(new Integer(100));
   System.out.println(c.size());
   System.out.println(c); // 内部的实现: 调用c的toString方法,打印出"["   "]" 。    然后依次调用c内存储的对象的toString方法。
 }
Beispiel #21
0
 public static void fillIt(Collection ref) {
   ref.add("Joe");
   ref.add("Bill");
   ref.add("Tom");
   ref.add("JOE");
   ref.add("BILL");
   ref.add("TOM");
 } // end fillIt()
 public Collection extraSpecificImports() {
   Collection col = super.extraSpecificImports();
   col.add(indirectorClassName);
   col.add("com.mchange.v2.ser.IndirectlySerialized");
   col.add("com.mchange.v2.ser.Indirector");
   col.add("com.mchange.v2.ser.SerializableUtils");
   col.add("java.io.NotSerializableException");
   return col;
 }
Beispiel #23
0
 public void addPropertyMapping(PropertyMapping propertyMapping) throws XavaException {
   propertyMappings.put(propertyMapping.getProperty(), propertyMapping);
   modelProperties.add(propertyMapping.getProperty());
   // To keep order
   tableColumns.add(propertyMapping.getColumn());
   if (propertyMapping.hasFormula() && !getMetaModel().isAnnotatedEJB3()) {
     propertyMapping.getMetaProperty().setReadOnly(true);
   }
 }
Beispiel #24
0
  public static void collectResourcesSO(Model m, Collection target) throws ModelException {

    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      if (!(st.object() instanceof Literal) && !(st.object() instanceof Statement))
        target.add(st.object());
      target.add(st.subject());
    }
  }
Beispiel #25
0
 private void checkAdditionalImportsEntityTargetEntity(Entity targetEntity) {
   if (!targetEntity.getJavaPackage().equals(javaPackage)) {
     additionalImportsEntity.add(
         targetEntity.getJavaPackage() + "." + targetEntity.getClassName());
   }
   if (!targetEntity.getJavaPackageDao().equals(javaPackage)) {
     additionalImportsEntity.add(
         targetEntity.getJavaPackageDao() + "." + targetEntity.getClassNameDao());
   }
 }
  protected Collection<String> generateSuggestedNames(PyExpression expression) {
    Collection<String> candidates =
        new LinkedHashSet<String>() {
          @Override
          public boolean add(String s) {
            if (PyNames.isReserved(s)) {
              return false;
            }
            return super.add(s);
          }
        };
    String text = expression.getText();
    final Pair<PsiElement, TextRange> selection =
        expression.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE);
    if (selection != null) {
      text = selection.getSecond().substring(text);
    }
    if (expression instanceof PyCallExpression) {
      final PyExpression callee = ((PyCallExpression) expression).getCallee();
      if (callee != null) {
        text = callee.getText();
      }
    }
    if (text != null) {
      candidates.addAll(NameSuggesterUtil.generateNames(text));
    }
    final TypeEvalContext context = TypeEvalContext.userInitiated(expression.getContainingFile());
    PyType type = context.getType(expression);
    if (type != null && type != PyNoneType.INSTANCE) {
      String typeName = type.getName();
      if (typeName != null) {
        if (type.isBuiltin()) {
          typeName = typeName.substring(0, 1);
        }
        candidates.addAll(NameSuggesterUtil.generateNamesByType(typeName));
      }
    }
    final PyKeywordArgument kwArg =
        PsiTreeUtil.getParentOfType(expression, PyKeywordArgument.class);
    if (kwArg != null && kwArg.getValueExpression() == expression) {
      candidates.add(kwArg.getKeyword());
    }

    final PyArgumentList argList = PsiTreeUtil.getParentOfType(expression, PyArgumentList.class);
    if (argList != null) {
      final CallArgumentsMapping result = argList.analyzeCall(PyResolveContext.noImplicits());
      if (result.getMarkedCallee() != null) {
        final PyNamedParameter namedParameter = result.getPlainMappedParams().get(expression);
        if (namedParameter != null) {
          candidates.add(namedParameter.getName());
        }
      }
    }
    return candidates;
  }
  @SuppressWarnings("squid:S1244")
  private static String selectBestEncoding(String acceptEncodingHeader) {
    // multiple encodings are accepted; determine best one

    Collection<String> bestEncodings = new HashSet<>(3);
    double bestQ = 0.0;
    Collection<String> unacceptableEncodings = new HashSet<>(3);
    boolean willAcceptAnything = false;

    for (String token : COMMA.split(acceptEncodingHeader)) {
      ContentEncodingQ contentEncodingQ = parseContentEncodingQ(token);
      String contentEncoding = contentEncodingQ.getContentEncoding();
      double q = contentEncodingQ.getQ();
      if (ANY_ENCODING.equals(contentEncoding)) {
        willAcceptAnything = q > 0.0;
      } else if (SUPPORTED_ENCODINGS.contains(contentEncoding)) {
        if (q > 0.0) {
          // This is a header quality comparison.
          // So it is safe to suppress warning squid:S1244
          if (q == bestQ) {
            bestEncodings.add(contentEncoding);
          } else if (q > bestQ) {
            bestQ = q;
            bestEncodings.clear();
            bestEncodings.add(contentEncoding);
          }
        } else {
          unacceptableEncodings.add(contentEncoding);
        }
      }
    }

    if (bestEncodings.isEmpty()) {
      // nothing was acceptable to us
      if (willAcceptAnything) {
        if (unacceptableEncodings.isEmpty()) {
          return SUPPORTED_ENCODINGS.get(0);
        } else {
          for (String encoding : SUPPORTED_ENCODINGS) {
            if (!unacceptableEncodings.contains(encoding)) {
              return encoding;
            }
          }
        }
      }
    } else {
      for (String encoding : SUPPORTED_ENCODINGS) {
        if (bestEncodings.contains(encoding)) {
          return encoding;
        }
      }
    }

    return NO_ENCODING;
  }
Beispiel #28
0
  @Test(expected = ConstraintViolationException.class)
  public void testExceptionThrow() {
    Collection<Validator> validators = null;

    validators = new HashSet<>();
    validators.add(new PatternValidator("^[a-zA-Z]+://"));
    validators.add(new LengthValidator(255));
    new GroupValidator(validators).validate("tajo", true);

    fail();
  }
Beispiel #29
0
 private void generateTestAndTrainSets(Collection<VcsCommitInfo> allCommits) {
   testSet = new ArrayList<>();
   trainSet = new ArrayList<>();
   for (VcsCommitInfo commit : allCommits) {
     if (Math.random() > TEST_SET_FRACTION) {
       trainSet.add(commit.getCommitId());
     } else {
       testSet.add(commit.getCommitId());
     }
   }
 }
Beispiel #30
-1
 public static void main(String[] args) {
   // 创建集合、添加元素的代码与前一个程序相同
   Collection books = new HashSet();
   books.add("轻量级Java EE企业应用实战");
   books.add("疯狂Java讲义");
   books.add("疯狂Android讲义");
   // 获取books集合对应的迭代器
   Iterator it = books.iterator();
   // 使用Lambda表达式(目标类型是Comsumer)来遍历集合元素
   it.forEachRemaining(obj -> System.out.println("迭代集合元素:" + obj));
 }