use of java.util.Collection in project druid by druid-io.
the class QueryableIndexIndexableAdapter method getRows.
@Override
public Iterable<Rowboat> getRows() {
return new Iterable<Rowboat>() {
@Override
public Iterator<Rowboat> iterator() {
return new Iterator<Rowboat>() {
final GenericColumn timestamps = input.getColumn(Column.TIME_COLUMN_NAME).getGenericColumn();
final Closeable[] metrics;
final Closeable[] columns;
final Closer closer = Closer.create();
final int numMetrics = getMetricNames().size();
final DimensionHandler[] handlers = new DimensionHandler[availableDimensions.size()];
Collection<DimensionHandler> handlerSet = input.getDimensionHandlers().values();
int currRow = 0;
boolean done = false;
{
closer.register(timestamps);
handlerSet.toArray(handlers);
this.columns = FluentIterable.from(handlerSet).transform(new Function<DimensionHandler, Closeable>() {
@Override
public Closeable apply(DimensionHandler handler) {
Column column = input.getColumn(handler.getDimensionName());
return handler.getSubColumn(column);
}
}).toArray(Closeable.class);
for (Closeable column : columns) {
closer.register(column);
}
final Indexed<String> availableMetrics = getMetricNames();
metrics = new Closeable[availableMetrics.size()];
for (int i = 0; i < metrics.length; ++i) {
final Column column = input.getColumn(availableMetrics.get(i));
final ValueType type = column.getCapabilities().getType();
switch(type) {
case FLOAT:
case LONG:
metrics[i] = column.getGenericColumn();
break;
case COMPLEX:
metrics[i] = column.getComplexColumn();
break;
default:
throw new ISE("Cannot handle type[%s]", type);
}
}
for (Closeable metricColumn : metrics) {
closer.register(metricColumn);
}
}
@Override
public boolean hasNext() {
final boolean hasNext = currRow < numRows;
if (!hasNext && !done) {
CloseQuietly.close(closer);
done = true;
}
return hasNext;
}
@Override
public Rowboat next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final Object[] dims = new Object[columns.length];
int dimIndex = 0;
for (final Closeable column : columns) {
dims[dimIndex] = handlers[dimIndex].getEncodedKeyComponentFromColumn(column, currRow);
dimIndex++;
}
Object[] metricArray = new Object[numMetrics];
for (int i = 0; i < metricArray.length; ++i) {
if (metrics[i] instanceof IndexedFloatsGenericColumn) {
metricArray[i] = ((GenericColumn) metrics[i]).getFloatSingleValueRow(currRow);
} else if (metrics[i] instanceof IndexedLongsGenericColumn) {
metricArray[i] = ((GenericColumn) metrics[i]).getLongSingleValueRow(currRow);
} else if (metrics[i] instanceof ComplexColumn) {
metricArray[i] = ((ComplexColumn) metrics[i]).getRowValue(currRow);
}
}
final Rowboat retVal = new Rowboat(timestamps.getLongSingleValueRow(currRow), dims, metricArray, currRow, handlers);
++currRow;
return retVal;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
use of java.util.Collection in project jetty.project by eclipse.
the class MultiPartContentProviderTest method testFieldWithOverridenContentType.
@Test
public void testFieldWithOverridenContentType() throws Exception {
String name = "field";
String value = "รจ";
Charset encoding = StandardCharsets.ISO_8859_1;
start(new AbstractMultiPartHandler() {
@Override
protected void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Collection<Part> parts = request.getParts();
Assert.assertEquals(1, parts.size());
Part part = parts.iterator().next();
Assert.assertEquals(name, part.getName());
String contentType = part.getContentType();
Assert.assertNotNull(contentType);
int equal = contentType.lastIndexOf('=');
Charset charset = Charset.forName(contentType.substring(equal + 1));
Assert.assertEquals(encoding, charset);
Assert.assertEquals(value, IO.toString(part.getInputStream(), charset));
}
});
MultiPartContentProvider multiPart = new MultiPartContentProvider();
HttpFields fields = new HttpFields();
fields.put(HttpHeader.CONTENT_TYPE, "text/plain;charset=" + encoding.name());
BytesContentProvider content = new BytesContentProvider(value.getBytes(encoding));
multiPart.addFieldPart(name, content, fields);
multiPart.close();
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).method(HttpMethod.POST).content(multiPart).send();
Assert.assertEquals(200, response.getStatus());
}
use of java.util.Collection in project jetty.project by eclipse.
the class JSONCollectionConvertor method fromJSON.
public Object fromJSON(Map object) {
try {
Collection result = (Collection) Loader.loadClass((String) object.get("class")).newInstance();
Collections.addAll(result, (Object[]) object.get("list"));
return result;
} catch (Exception x) {
if (x instanceof RuntimeException)
throw (RuntimeException) x;
throw new RuntimeException(x);
}
}
use of java.util.Collection in project che by eclipse.
the class UserJpaTckRepository method createAll.
@Override
public void createAll(Collection<? extends UserImpl> entities) throws TckRepositoryException {
final EntityManager manager = managerProvider.get();
entities.stream().map(user -> new UserImpl(user.getId(), user.getEmail(), user.getName(), encryptor.encrypt(user.getPassword()), user.getAliases())).forEach(manager::persist);
}
use of java.util.Collection in project elasticsearch by elastic.
the class UnicastZenPingTests method testPingingTemporalPings.
public void testPingingTemporalPings() throws ExecutionException, InterruptedException {
final Settings settings = Settings.builder().put("cluster.name", "test").put(TransportSettings.PORT.getKey(), 0).build();
NetworkService networkService = new NetworkService(settings, Collections.emptyList());
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockTcpTransport(s, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, v);
NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
closeables.push(handleA.transportService);
NetworkHandle handleB = startServices(settings, threadPool, "UZP_B", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
closeables.push(handleB.transportService);
final Settings hostsSettings = Settings.builder().put("cluster.name", "test").put("discovery.zen.ping.unicast.hosts", // use nodes for simplicity
(String) null).build();
final ClusterState state = ClusterState.builder(new ClusterName("test")).version(randomNonNegativeLong()).build();
final TestUnicastZenPing zenPingA = new TestUnicastZenPing(hostsSettings, threadPool, handleA, EMPTY_HOSTS_PROVIDER);
zenPingA.start(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {
return DiscoveryNodes.builder().add(handleA.node).add(handleB.node).localNodeId("UZP_A").build();
}
@Override
public ClusterState clusterState() {
return ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)).build();
}
});
closeables.push(zenPingA);
// Node B doesn't know about A!
TestUnicastZenPing zenPingB = new TestUnicastZenPing(hostsSettings, threadPool, handleB, EMPTY_HOSTS_PROVIDER);
zenPingB.start(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {
return DiscoveryNodes.builder().add(handleB.node).localNodeId("UZP_B").build();
}
@Override
public ClusterState clusterState() {
return state;
}
});
closeables.push(zenPingB);
{
logger.info("pinging from UZP_A so UZP_B will learn about it");
Collection<ZenPing.PingResponse> pingResponses = zenPingA.pingAndWait().toList();
assertThat(pingResponses.size(), equalTo(1));
ZenPing.PingResponse ping = pingResponses.iterator().next();
assertThat(ping.node().getId(), equalTo("UZP_B"));
assertThat(ping.getClusterStateVersion(), equalTo(state.version()));
}
{
logger.info("pinging from UZP_B");
Collection<ZenPing.PingResponse> pingResponses = zenPingB.pingAndWait().toList();
assertThat(pingResponses.size(), equalTo(1));
ZenPing.PingResponse ping = pingResponses.iterator().next();
assertThat(ping.node().getId(), equalTo("UZP_A"));
// A has a block
assertThat(ping.getClusterStateVersion(), equalTo(-1L));
}
}
Aggregations