@Test public void testSplitListSmallerThanMaxChunk() { List<String> names = new ArrayList<String>(); names.add("name01"); names.add("name02"); names.add("name03"); names.add("name04"); List<List<String>> chunks = ConnectionUtils.splitFieldList(names, 30); assertEquals(1, chunks.size()); assertEquals("name01,name02,name03,name04", join(chunks.get(0), ",")); }
static List<List<String>> splitFieldList(List<String> fieldNames, int maxSize) { List<List<String>> chunks = new ArrayList<List<String>>(); String separator = ","; List<String> chunk = new ArrayList<String>(); for (String fName : fieldNames) { if (fName.length() > maxSize) { logger.warn("Field name <{}> by itself was bigger than the chunk size; adding it as its own chunk", fName); chunks.add(Arrays.asList(fName)); continue; } if (chunk.isEmpty()) { chunk.add(fName); continue; } if (getChunkLength(chunk) + fName.length() + separator.length() <= maxSize) { chunk.add(fName); continue; } chunks.add(chunk); chunk = new ArrayList<String>(); chunk.add(fName); } if (!chunk.isEmpty()) { chunks.add(chunk); } return chunks; }
ConnectionUtils { static List<List<String>> splitFieldList(List<String> fieldNames, int maxSize) { List<List<String>> chunks = new ArrayList<List<String>>(); String separator = ","; List<String> chunk = new ArrayList<String>(); for (String fName : fieldNames) { if (fName.length() > maxSize) { logger.warn("Field name <{}> by itself was bigger than the chunk size; adding it as its own chunk", fName); chunks.add(Arrays.asList(fName)); continue; } if (chunk.isEmpty()) { chunk.add(fName); continue; } if (getChunkLength(chunk) + fName.length() + separator.length() <= maxSize) { chunk.add(fName); continue; } chunks.add(chunk); chunk = new ArrayList<String>(); chunk.add(fName); } if (!chunk.isEmpty()) { chunks.add(chunk); } return chunks; } }
ConnectionUtils { static List<List<String>> splitFieldList(List<String> fieldNames, int maxSize) { List<List<String>> chunks = new ArrayList<List<String>>(); String separator = ","; List<String> chunk = new ArrayList<String>(); for (String fName : fieldNames) { if (fName.length() > maxSize) { logger.warn("Field name <{}> by itself was bigger than the chunk size; adding it as its own chunk", fName); chunks.add(Arrays.asList(fName)); continue; } if (chunk.isEmpty()) { chunk.add(fName); continue; } if (getChunkLength(chunk) + fName.length() + separator.length() <= maxSize) { chunk.add(fName); continue; } chunks.add(chunk); chunk = new ArrayList<String>(); chunk.add(fName); } if (!chunk.isEmpty()) { chunks.add(chunk); } return chunks; } private  ConnectionUtils(); }
ConnectionUtils { static List<List<String>> splitFieldList(List<String> fieldNames, int maxSize) { List<List<String>> chunks = new ArrayList<List<String>>(); String separator = ","; List<String> chunk = new ArrayList<String>(); for (String fName : fieldNames) { if (fName.length() > maxSize) { logger.warn("Field name <{}> by itself was bigger than the chunk size; adding it as its own chunk", fName); chunks.add(Arrays.asList(fName)); continue; } if (chunk.isEmpty()) { chunk.add(fName); continue; } if (getChunkLength(chunk) + fName.length() + separator.length() <= maxSize) { chunk.add(fName); continue; } chunks.add(chunk); chunk = new ArrayList<String>(); chunk.add(fName); } if (!chunk.isEmpty()) { chunks.add(chunk); } return chunks; } private  ConnectionUtils();  }
ConnectionUtils { static List<List<String>> splitFieldList(List<String> fieldNames, int maxSize) { List<List<String>> chunks = new ArrayList<List<String>>(); String separator = ","; List<String> chunk = new ArrayList<String>(); for (String fName : fieldNames) { if (fName.length() > maxSize) { logger.warn("Field name <{}> by itself was bigger than the chunk size; adding it as its own chunk", fName); chunks.add(Arrays.asList(fName)); continue; } if (chunk.isEmpty()) { chunk.add(fName); continue; } if (getChunkLength(chunk) + fName.length() + separator.length() <= maxSize) { chunk.add(fName); continue; } chunks.add(chunk); chunk = new ArrayList<String>(); chunk.add(fName); } if (!chunk.isEmpty()) { chunks.add(chunk); } return chunks; } private  ConnectionUtils();   }