com.google.common.base.Joiner#join ( )源码实例Demo

下面列出了com.google.common.base.Joiner#join ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rya   文件: VisibilityStatementMerger.java
@Override
public Optional<RyaStatement> merge(final Optional<RyaStatement> parent, final Optional<RyaStatement> child)
        throws MergerException {
    if(parent.isPresent()) {
        final RyaStatement parentStatement = parent.get();
        if(child.isPresent()) {
            final RyaStatement childStatement = child.get();
            final String pVis = new String(parentStatement.getColumnVisibility(), StandardCharsets.UTF_8);
            final String cVis = new String(childStatement.getColumnVisibility(), StandardCharsets.UTF_8);
            String visibility = "";
            final Joiner join = Joiner.on(")&(");
            if(pVis.isEmpty() || cVis.isEmpty()) {
                visibility = (pVis + cVis).trim();
            } else {
                visibility = "(" + join.join(pVis, cVis) + ")";
            }
            parentStatement.setColumnVisibility(visibility.getBytes(StandardCharsets.UTF_8));
            return Optional.of(parentStatement);
        }
        return parent;
    } else if(child.isPresent()) {
        return child;
    }
    return Optional.absent();
}
 
源代码2 项目: PoseidonX   文件: DateUtil.java
/**
 * seconds to string like '30m 40s' and '1d 20h 30m 40s'
 *
 * @param secs
 * @return
 */
public static String prettyUptime(int secs) {
    String[][] PRETTYSECDIVIDERS = { new String[] { "s", "60" }, new String[] { "m", "60" }, new String[] { "h", "24" },
            new String[] { "d", null } };
    int diversize = PRETTYSECDIVIDERS.length;

    LinkedList<String> tmp = new LinkedList<String>();
    int div = secs;
    for (int i = 0; i < diversize; i++) {
        if (PRETTYSECDIVIDERS[i][1] != null) {
            Integer d = Integer.parseInt(PRETTYSECDIVIDERS[i][1]);
            tmp.addFirst(div % d + PRETTYSECDIVIDERS[i][0]);
            div = div / d;
        } else {
            tmp.addFirst(div + PRETTYSECDIVIDERS[i][0]);
        }
        if (div <= 0 ) break;
    }

    Joiner joiner = Joiner.on(" ");
    return joiner.join(tmp);
}
 
源代码3 项目: phoenix   文件: PhoenixTestBuilder.java
private static List<String> getFQColumnsAsList(List<String> columns, List<String> families,
        List<String> types) {
    assert (columns.size() == families.size());

    Joiner familyJoiner = Joiner.on(".");
    Joiner typeJoiner = Joiner.on(" ");
    List<String> columnDefinitions = Lists.newArrayList();
    int colIndex = 0;
    for (String family : families) {
        String column = columns.get(colIndex);
        String datatype = types.get(colIndex);
        colIndex++;
        if ((column != null) && (!column.isEmpty())) {
            String columnWithType = typeJoiner.join(column, datatype);
            columnDefinitions.add(((family != null) && (!family.isEmpty())) ?
                    familyJoiner.join(family, columnWithType) :
                    columnWithType);
        }
    }
    return columnDefinitions;
}
 
源代码4 项目: buck   文件: MoreAsserts.java
/**
 * Asserts that every {@link com.facebook.buck.step.Step} in the observed list is a {@link
 * com.facebook.buck.shell.ShellStep} whose shell command arguments match those of the
 * corresponding entry in the expected list.
 */
public static void assertShellCommands(
    String userMessage, List<String> expected, List<Step> observed, ExecutionContext context) {
  Iterator<String> expectedIter = expected.iterator();
  Iterator<Step> observedIter = observed.iterator();
  Joiner joiner = Joiner.on(" ");
  while (expectedIter.hasNext() && observedIter.hasNext()) {
    String expectedShellCommand = expectedIter.next();
    Step observedStep = observedIter.next();
    if (!(observedStep instanceof ShellStep)) {
      failWith(userMessage, "Observed command must be a shell command: " + observedStep);
    }
    ShellStep shellCommand = (ShellStep) observedStep;
    String observedShellCommand = joiner.join(shellCommand.getShellCommand(context));
    assertEquals(userMessage, expectedShellCommand, observedShellCommand);
  }

  if (expectedIter.hasNext()) {
    failWith(userMessage, "Extra expected command: " + expectedIter.next());
  }

  if (observedIter.hasNext()) {
    failWith(userMessage, "Extra observed command: " + observedIter.next());
  }
}
 
源代码5 项目: jstorm   文件: ErrorTag.java
private String getErrorContent() {
    List<String> ret = new ArrayList<>();
    for (ErrorEntity er : e) {
        long ts = ((long) er.getErrorTime()) * 1000;
        int index = er.getError().lastIndexOf(",");
        if (index == -1) {
            int idx = er.getError().indexOf("\n");
            int length = er.getError().length();
            if (idx != -1) {
                String first_line = er.getError().substring(0, idx);
                String rest_lines = er.getError().substring(idx + 1, length - 2);
                ret.add(first_line + " , at " + UIUtils.parseDateTime(ts));
                ret.add(rest_lines);
            }else{
                ret.add(er.getError() + " , at " + UIUtils.parseDateTime(ts));
            }
        } else {
            ret.add(er.getError() + ", at " + UIUtils.parseDateTime(ts));
        }
    }
    Joiner joiner = Joiner.on("\n");
    return "<pre>" + joiner.join(ret) + "</pre>";
}
 
源代码6 项目: mt-flume   文件: EncryptionTestUtils.java
public static Map<String,String> configureForKeyStore(File keyStoreFile,
    File keyStorePasswordFile, Map<String, File> keyAliasPassword)
        throws Exception {
  Map<String, String> context = Maps.newHashMap();
  List<String> keys = Lists.newArrayList();
  Joiner joiner = Joiner.on(".");
  for(String alias : keyAliasPassword.keySet()) {
    File passwordFile = keyAliasPassword.get(alias);
    if(passwordFile == null) {
      keys.add(alias);
    } else {
      String propertyName = joiner.join(EncryptionConfiguration.KEY_PROVIDER,
          EncryptionConfiguration.JCE_FILE_KEYS, alias,
          EncryptionConfiguration.JCE_FILE_KEY_PASSWORD_FILE);
      keys.add(alias);
      context.put(propertyName, passwordFile.getAbsolutePath());
    }
  }
  context.put(joiner.join(EncryptionConfiguration.KEY_PROVIDER,
      EncryptionConfiguration.JCE_FILE_KEY_STORE_FILE),
      keyStoreFile.getAbsolutePath());
  if(keyStorePasswordFile != null) {
    context.put(joiner.join(EncryptionConfiguration.KEY_PROVIDER,
        EncryptionConfiguration.JCE_FILE_KEY_STORE_PASSWORD_FILE),
        keyStorePasswordFile.getAbsolutePath());
  }
  context.put(joiner.join(EncryptionConfiguration.KEY_PROVIDER,
      EncryptionConfiguration.JCE_FILE_KEYS),
      Joiner.on(" ").join(keys));
  return context;
}
 
源代码7 项目: beam-client-java   文件: IncomingMessageData.java
public String asString() {
    Joiner j = Joiner.on("");
    Iterable<MessageTextComponent> components = Collections2.filter(this.message.message, Predicates.notNull());

    return j.join(Iterables.transform(components, new Function<MessageTextComponent, String>() {
        @Override public String apply(MessageTextComponent component) {
            switch (component.type) {
                case EMOTICON: return component.text;
                case LINK: return component.url;
                case TEXT: default: return component.data;
            }
        }
    }));
}
 
源代码8 项目: q   文件: DetailReport.java
private String getTitles(Set<String> ids, Map<String, String> titleIdToName) {
	String returnValue = "";
	Joiner joiner = Joiner.on(SEPARATOR);
	if (ids != null && titleIdToName != null && titleIdToName.keySet() != null) {
		Set<String> intersection = Sets.intersection(ids, titleIdToName.keySet());
		Map<String, String> copy = new LinkedHashMap<String, String>(titleIdToName);
		copy.keySet().retainAll(intersection);
		returnValue = joiner.join(copy.values());
	}
	return returnValue;
}
 
源代码9 项目: tac-kbp-eal   文件: RecallAnalysis.java
public static String header(final ImmutableList<String> systemOrdering) {
  final Joiner tab = Joiner.on("\t");
  final ImmutableList.Builder<String> h = ImmutableList.builder();
  h.add("DOCID");
  h.add("CASGroup");
  h.addAll(systemOrdering);
  h.add("type/role");
  h.add("Annotated Realis");
  h.add("many CASes");
  return tab.join(h.build());
}
 
public String getResults() {
  List<String> list = new ArrayList<>();
  Joiner joiner = Joiner.on("\n").skipNulls();
  for (Map.Entry<RowLevelPolicyResultPair, Long> entry : this.results.entrySet()) {
    list.add("RowLevelPolicy " + entry.getKey().getPolicy().toString() + " processed " + entry.getValue()
        + " record(s) with result " + entry.getKey().getResult());
  }
  return joiner.join(list);
}
 
源代码11 项目: incubator-gobblin   文件: JobContextTest.java
@Test
public void testCleanUpOldJobData() throws Exception {
  String rootPath = Files.createTempDir().getAbsolutePath();
  final String JOB_PREFIX = Id.Job.PREFIX;
  final String JOB_NAME1 = "GobblinKafka";
  final String JOB_NAME2 = "GobblinBrooklin";
  final long timestamp1 = 1505774129247L;
  final long timestamp2 = 1505774129248L;
  final Joiner JOINER = Joiner.on(Id.SEPARATOR).skipNulls();
  Object[] oldJob1 = new Object[]{JOB_PREFIX, JOB_NAME1, timestamp1};
  Object[] oldJob2 = new Object[]{JOB_PREFIX, JOB_NAME2, timestamp1};
  Object[] currentJob = new Object[]{JOB_PREFIX, JOB_NAME1, timestamp2};

  Path currentJobPath = new Path(JobContext.getJobDir(rootPath, JOB_NAME1), JOINER.join(currentJob));
  Path oldJobPath1 = new Path(JobContext.getJobDir(rootPath, JOB_NAME1), JOINER.join(oldJob1));
  Path oldJobPath2 = new Path(JobContext.getJobDir(rootPath, JOB_NAME2), JOINER.join(oldJob2));
  Path stagingPath = new Path(currentJobPath, "task-staging");
  Path outputPath = new Path(currentJobPath, "task-output");

  FileSystem fs = FileSystem.getLocal(new Configuration());
  fs.mkdirs(currentJobPath);
  fs.mkdirs(oldJobPath1);
  fs.mkdirs(oldJobPath2);
  log.info("Created : {} {} {}", currentJobPath, oldJobPath1, oldJobPath2);

  gobblin.runtime.JobState jobState = new gobblin.runtime.JobState();
  jobState.setProp(ConfigurationKeys.WRITER_STAGING_DIR, stagingPath.toString());
  jobState.setProp(ConfigurationKeys.WRITER_OUTPUT_DIR, outputPath.toString());

  JobContext jobContext = mock(JobContext.class);
  when(jobContext.getStagingDirProvided()).thenReturn(false);
  when(jobContext.getOutputDirProvided()).thenReturn(false);
  when(jobContext.getJobId()).thenReturn(currentJobPath.getName().toString());

  JobLauncherUtils.cleanUpOldJobData(jobState, log, jobContext.getStagingDirProvided(), jobContext.getOutputDirProvided());

  Assert.assertFalse(fs.exists(oldJobPath1));
  Assert.assertTrue(fs.exists(oldJobPath2));
  Assert.assertFalse(fs.exists(currentJobPath));
}
 
源代码12 项目: datacollector   文件: OracleCDCSource.java
private String formatTableList(List<String> tables) {
  List<String> quoted = new ArrayList<>();
  for (String table : tables) {
    quoted.add(String.format("'%s'", table));
  }
  Joiner joiner = Joiner.on(",");
  return joiner.join(quoted);
}
 
源代码13 项目: nifi   文件: OrcFlowFileWriter.java
private String getColumnNamesFromInspector(ObjectInspector inspector) {
    List<String> fieldNames = Lists.newArrayList();
    Joiner joiner = Joiner.on(",");
    if (inspector instanceof StructObjectInspector) {
        StructObjectInspector soi = (StructObjectInspector) inspector;
        List<? extends StructField> fields = soi.getAllStructFieldRefs();
        fieldNames.addAll(fields.stream().map((Function<StructField, String>) StructField::getFieldName).collect(Collectors.toList()));
    }
    return joiner.join(fieldNames);
}
 
源代码14 项目: phoenix   文件: PhoenixTestBuilder.java
/**
 * @return a formatted string with CFs
 * for e.g  "A.COL1, B.COL2, C.COl3"
 */
private static String getFQColumnsAsString(List<String> columns, List<String> families) {
    Joiner columnJoiner = Joiner.on(",");
    return columnJoiner.join(getFQColumnsAsList(columns, families));
}
 
源代码15 项目: q   文件: ReportItem.java
@Override
public String toString()
{
    Joiner joiner = Joiner.on(Properties.inputDelimiter.get());
    return joiner.join(namedValues.values());
}
 
源代码16 项目: incubator-gobblin   文件: RestApiCommand.java
@Override
public String toString() {
  Joiner joiner = Joiner.on(":").skipNulls();
  return this.cmd.toString() + ":" + joiner.join(this.params);
}
 
private String automationModelValue(AutomationModel automation) {
    Joiner joiner = Joiner.on("; ").skipNulls();
    return joiner.join(automation.getName(), automation.getWhere(),
        automation.getEnvironmentId(), automation.getGatewayUuid(),
        automation.isFavourite());
}
 
源代码18 项目: divolte-collector   文件: BrowserLists.java
public static String browserNameList(final Iterable<Object[]> list) {
    Joiner joiner = Joiner.on('\n');
    return joiner.join(StreamSupport.stream(list.spliterator(),  false).map((param) -> param[1]).toArray());
}
 
源代码19 项目: trainbenchmark   文件: IngraphMatch.java
@Override
public String toString() {
	final Joiner joiner = Joiner.on(", ");
	return "<" + joiner.join(toArray()) + ">";
}
 
源代码20 项目: codebuff   文件: FluentIterable.java
/**
 * Returns a {@link String} containing all of the elements of this fluent iterable joined with
 * {@code joiner}.
 *
 * <p><b>{@code Stream} equivalent:</b> {@code joiner.join(stream.iterator())}, or, if you are not
 * using any optional {@code Joiner} features,
 * {@code stream.collect(Collectors.joining(delimiter)}.
 *
 * @since 18.0
 */

@Beta
public final String join(Joiner joiner) {
  return joiner.join(this);
}