Java源码示例:com.google.gdata.util.common.base.Pair

示例1
/**
 * Appends this XmlElement (and any children) to an Appendable.
 */
public void appendTo(Appendable a) throws IOException {
  a.append('<').append(elementType);
  for (Map.Entry<String, String> attribute : attributes.entrySet()) {
    a.append(' ').append(attribute.getKey()).append("=\"")
        .append(attribute.getValue()).append("\"");
  }
  if (children.isEmpty()) {
    a.append(" />");
  } else {
    a.append(">");
    for (Pair<Object, ChildType> pair : children) {
      Object child = pair.getFirst();
      ChildType type = pair.getSecond();
      if (type == ChildType.ELEMENT) {
        ((XmlElement)child).appendTo(a);
      } else {
        a.append((String)child);
      }
    }
    a.append("</").append(elementType).append('>');
  }
}
 
示例2
private CompletableFuture<WCAClustersResult> createClustersTaskWithDeps(Contingency contingency,
                                                                        List<String> curativeActionIds,
                                                                        String baseStateId,
                                                                        String contingencyStateId,
                                                                        List<String> curativeStateIds,
                                                                        List<SecurityRuleExpression> securityRuleExpressions,
                                                                        Supplier<CompletableFuture<Uncertainties>> memoizedUncertaintiesFuture,
                                                                        Supplier<CompletableFuture<WCAHistoLimits>> histoLimitsFuture,
                                                                        StringToIntMapper<AmplSubset> mapper,
                                                                        boolean activateFiltering) {
    return memoizedUncertaintiesFuture.get()
            .thenCombine(histoLimitsFuture.get(), (uncertainties, histoLimits) -> Pair.of(uncertainties, histoLimits))
            .thenCompose(p -> createClustersTask(contingency, curativeActionIds, baseStateId, contingencyStateId, curativeStateIds,
                                                 securityRuleExpressions, p.getFirst(), p.getSecond(), mapper, activateFiltering));
}
 
示例3
private CompletableFuture<WCADomainsResult> createDomainsTaskWithDeps(Contingency contingency,
                                                                      String baseStateId,
                                                                      List<SecurityRuleExpression> securityRuleExpressions,
                                                                      Supplier<CompletableFuture<Uncertainties>> memoizedUncertaintiesFuture,
                                                                      Supplier<CompletableFuture<WCAHistoLimits>> histoLimitsFuture,
                                                                      StringToIntMapper<AmplSubset> mapper,
                                                                      List<String> preventiveStateIds,
                                                                      List<String> preventiveActionIds,
                                                                      boolean activateFiltering) {
    return memoizedUncertaintiesFuture.get()
            .thenCombine(histoLimitsFuture.get(), (uncertainties, histoLimits) -> Pair.of(uncertainties, histoLimits))
            .thenCompose(p -> createDomainsTask(contingency, baseStateId, securityRuleExpressions, p.getFirst(), p.getSecond(), mapper,
                                                preventiveStateIds, preventiveActionIds, activateFiltering));
}
 
示例4
/**
 * Creates a new {@code XmlElement} of the given type.
 * 
 * @param elementType tag name of this element
 */
public XmlElement(String elementType) {
  Preconditions.checkNotNull(elementType);
  this.elementType = elementType;
  children = new LinkedList<Pair<Object, ChildType>>();
  attributes = new TreeMap<String, String>();
}
 
示例5
/**
 * Returns the next element if it exists, otherwise calls endOfData() and
 * returns null.
 */
@Override
public BaseContentEntry<?> computeNext() {
  if (!currentItr.hasNext()) {
    Pair<Iterator<BaseContentEntry<?>>, Integer> pair = 
        getEntries(index, resultsPerRequest);
    currentItr = pair.getFirst();
    index += pair.getSecond();
    if (!currentItr.hasNext()) {
      return endOfData();
    }
  }
  return currentItr.next();
}
 
示例6
@Test
public void testConversionToVCardNames() {
  // Set up Person with a primary name and two secondary names
  String primaryGivenName = "Mark";
  String primaryFamilyName = "Twain";
  Name primaryName =
      new Name()
          .setGivenName(primaryGivenName)
          .setFamilyName(primaryFamilyName)
          .setMetadata(PRIMARY_FIELD_METADATA);

  String alternateGivenName1 = "Samuel";
  String alternateFamilyName1 = "Clemens";
  String alternateSourceType1 = "PROFILE";
  Name alternateName1 =
      new Name()
          .setGivenName(alternateGivenName1)
          .setFamilyName(alternateFamilyName1)
          .setMetadata(
              new FieldMetadata()
                  .setPrimary(false)
                  .setSource(new Source().setType(alternateSourceType1)));
  String alternateGivenName2 = "Louis";
  String alternateFamilyName2 = "de Conte";
  String alternateSourceType2 = "PEN_NAME";
  Name alternateName2 =
      new Name()
          .setGivenName(alternateGivenName2)
          .setFamilyName(alternateFamilyName2)
          .setMetadata(
              new FieldMetadata()
                  .setPrimary(false)
                  .setSource(new Source().setType(alternateSourceType2)));

  // Order shouldn't matter
  Person person =
      new Person().setNames(Arrays.asList(alternateName2, alternateName1, primaryName));

  // Run test
  VCard vCard = GoogleContactsExporter.convert(person);

  // Check name conversion correctness
  List<StructuredName> structuredNames = vCard.getStructuredNames();
  assertThat(structuredNames.size()).isEqualTo(3);

  // Check primary (non-alternate) names
  List<StructuredName> actualPrimaryNames =
      structuredNames.stream().filter(n -> n.getAltId() == null).collect(Collectors.toList());
  List<Pair<String, String>> actualPrimaryNamesValues =
      actualPrimaryNames
          .stream()
          .map(GoogleContactsExportConversionTest::getGivenAndFamilyNames)
          .collect(Collectors.toList());
  assertThat(actualPrimaryNamesValues)
      .containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
  List<String> actualPrimarySourceValues =
      actualPrimaryNames
          .stream()
          .map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE))
          .collect(Collectors.toList());
  assertThat(actualPrimarySourceValues).containsExactly(DEFAULT_SOURCE_TYPE);

  // Check alternate names
  List<StructuredName> actualAlternateNames =
      structuredNames.stream().filter(n -> n.getAltId() != null).collect(Collectors.toList());
  List<Pair<String, String>> actualAlternateNamesValues =
      actualAlternateNames
          .stream()
          .map(GoogleContactsExportConversionTest::getGivenAndFamilyNames)
          .collect(Collectors.toList());
  assertThat(actualAlternateNamesValues)
      .containsExactly(
          Pair.of(alternateGivenName1, alternateFamilyName1),
          Pair.of(alternateGivenName2, alternateFamilyName2));
  List<String> actualAlternateSourceValues =
      actualAlternateNames
          .stream()
          .map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE))
          .collect(Collectors.toList());
  assertThat(actualAlternateSourceValues)
      .containsExactly(alternateSourceType1, alternateSourceType2);
}
 
示例7
private static Pair<String, String> getGivenAndFamilyNames(StructuredName structuredName) {
  return Pair.of(structuredName.getGiven(), structuredName.getFamily());
}
 
示例8
private static Pair<String, String> getGivenAndFamilyValues(Name name) {
  return Pair.of(name.getGivenName(), name.getFamilyName());
}
 
示例9
@Test
public void testConversionToGoogleNames() {
  // Set up vCard with a primary name and one secondary name
  String primaryGivenName = "Mark";
  String primaryFamilyName = "Twain";
  String primarySourceType = "CONTACT";
  StructuredName primaryName =
      makeStructuredName(primaryGivenName, primaryFamilyName, primarySourceType);

  String altGivenName = "Samuel";
  String altFamilyName = "Clemens";
  String altSourceType = "PROFILE";
  StructuredName altName = makeStructuredName(altGivenName, altFamilyName, altSourceType);

  VCard vCard = new VCard();
  vCard.addProperty(primaryName);
  vCard.addPropertyAlt(StructuredName.class, Collections.singleton(altName));

  // Run test
  Person person = GoogleContactsImporter.convert(vCard);

  // Check results
  // Correct number of names
  assertThat(person.getNames().size()).isEqualTo(1);

  // Check primary names
  List<Name> actualPrimaryNames =
      person
          .getNames()
          .stream()
          .filter(a -> a.getMetadata().getPrimary())
          .collect(Collectors.toList());
  List<Pair<String, String>> actualPrimaryNameValues =
      actualPrimaryNames
          .stream()
          .map(GoogleContactsImportConversionTest::getGivenAndFamilyValues)
          .collect(Collectors.toList());
  assertThat(actualPrimaryNameValues)
      .containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
  List<String> actualPrimaryNameSourceValues =
      actualPrimaryNames
          .stream()
          .map(a -> a.getMetadata().getSource().getType())
          .collect(Collectors.toList());
  assertThat(actualPrimaryNameSourceValues).containsExactly(primarySourceType);

  // Check secondary names - there shouldn't be any
  List<Name> actualSecondaryNames =
      person
          .getNames()
          .stream()
          .filter(a -> !a.getMetadata().getPrimary())
          .collect(Collectors.toList());
  assertThat(actualSecondaryNames).isEmpty();
}
 
示例10
/**
 * Adds a plain text child to this element. The String given is
 * automatically converted to xml-safe characters.
 * 
 * <p>Children appear in the order in which they are added in the xml output.
 * </p>
 */
public XmlElement addText(String text) {
  Preconditions.checkNotNull(text);
  children.add(new Pair<Object, ChildType>(StringEscapeUtils.escapeXml(text),
      ChildType.TEXT));
  return this;
}
 
示例11
/**
 * Adds a child XmlElement to this one.
 * 
 * <p>Children appear in the order in which they are added in the xml output.
 * </p>
 */
public XmlElement addElement(XmlElement child) {
  Preconditions.checkNotNull(child);
  children.add(new Pair<Object, ChildType>(child, ChildType.ELEMENT));
  return this;
}
 
示例12
/**
 * Adds a string of xml as a child to this element. 
 * 
 * <p>Unlike addText(String), the string provided will not be escaped. If the 
 * given String is not well formed, then this element may not be well formed.
 * </p>
 */
public XmlElement addXml(String xml) {
  Preconditions.checkNotNull(xml);
  children.add(new Pair<Object, ChildType>(xml, ChildType.XML));
  return this;
}