Java Code Examples for com.google.common.base.Joiner#join()

The following examples show how to use com.google.common.base.Joiner#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisibilityStatementMerger.java    From rya with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: DateUtil.java    From PoseidonX with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: ErrorTag.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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>";
}
 
Example 4
Source File: MoreAsserts.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
  }
}
 
Example 5
Source File: PhoenixTestBuilder.java    From phoenix with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: OrcFlowFileWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: OracleCDCSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: JobContextTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 9
Source File: RowLevelPolicyCheckResults.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: RecallAnalysis.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
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());
}
 
Example 11
Source File: DetailReport.java    From q with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: IncomingMessageData.java    From beam-client-java with MIT License 5 votes vote down vote up
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;
            }
        }
    }));
}
 
Example 13
Source File: EncryptionTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: RestApiCommand.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  Joiner joiner = Joiner.on(":").skipNulls();
  return this.cmd.toString() + ":" + joiner.join(this.params);
}
 
Example 15
Source File: AutomationModelMatcher.java    From openwebnet-android with MIT License 4 votes vote down vote up
private String automationModelValue(AutomationModel automation) {
    Joiner joiner = Joiner.on("; ").skipNulls();
    return joiner.join(automation.getName(), automation.getWhere(),
        automation.getEnvironmentId(), automation.getGatewayUuid(),
        automation.isFavourite());
}
 
Example 16
Source File: BrowserLists.java    From divolte-collector with Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 17
Source File: ReportItem.java    From q with Apache License 2.0 4 votes vote down vote up
@Override
public String toString()
{
    Joiner joiner = Joiner.on(Properties.inputDelimiter.get());
    return joiner.join(namedValues.values());
}
 
Example 18
Source File: IngraphMatch.java    From trainbenchmark with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String toString() {
	final Joiner joiner = Joiner.on(", ");
	return "<" + joiner.join(toArray()) + ">";
}
 
Example 19
Source File: PhoenixTestBuilder.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * @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));
}
 
Example 20
Source File: FluentIterable.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}