method2testcases
stringlengths
118
6.63k
### Question: LoginVM { public Boolean isRememberMe() { return rememberMe; } String getUsername(); void setUsername(String username); String getPassword(); void setPassword(String password); Boolean isRememberMe(); void setRememberMe(Boolean rememberMe); @Override String toString(); }### Answer: @Test public void isR...
### Question: LoginVM { public void setRememberMe(Boolean rememberMe) { this.rememberMe = rememberMe; } String getUsername(); void setUsername(String username); String getPassword(); void setPassword(String password); Boolean isRememberMe(); void setRememberMe(Boolean rememberMe); @Override String toString(); }### An...
### Question: LoginVM { @Override public String toString() { return "LoginVM{" + "username='" + username + '\'' + ", rememberMe=" + rememberMe + '}'; } String getUsername(); void setUsername(String username); String getPassword(); void setPassword(String password); Boolean isRememberMe(); void setRememberMe(Boolean re...
### Question: UserVM { public String getLogin() { return login; } UserVM(); UserVM(String login, Set<String> authorities); String getLogin(); Set<String> getAuthorities(); @Override String toString(); }### Answer: @Test public void getLoginTest() { UserVM vm = new UserVM(); assertNull(vm.getLogin()); vm = new UserVM(...
### Question: UserVM { public Set<String> getAuthorities() { return authorities; } UserVM(); UserVM(String login, Set<String> authorities); String getLogin(); Set<String> getAuthorities(); @Override String toString(); }### Answer: @Test public void getAuthoritiesTest() throws Exception { UserVM vm = new UserVM(); ass...
### Question: UserVM { @Override public String toString() { return "UserVM{" + "login='" + login + '\'' + ", authorities=" + authorities + "}"; } UserVM(); UserVM(String login, Set<String> authorities); String getLogin(); Set<String> getAuthorities(); @Override String toString(); }### Answer: @Test public void toStri...
### Question: WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiv...
### Question: WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "...
### Question: WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiv...
### Question: SnapshotCreationService { public void createSnapshotEvents(final String eventType, String filter) { final SnapshotEventGenerator snapshotEventGenerator = snapshotEventProviders.get(eventType); if (snapshotEventGenerator == null) { throw new UnknownEventTypeException(eventType); } Object lastProcessedId = ...
### Question: MockNakadiPublishingClient implements NakadiPublishingClient { public synchronized List<String> getSentEvents(String eventType) { ArrayList<String> events = new ArrayList<>(); List<String> sentEvents = this.sentEvents.get(eventType); if (sentEvents != null) { events.addAll(sentEvents); } return events; } ...
### Question: EventBatcher { public void finish() { if (!batch.isEmpty()) { this.publisher.accept(batch); } } EventBatcher(ObjectMapper objectMapper, Consumer<List<BatchItem>> publisher); void pushEvent(EventLog eventLogEntry, NakadiEvent nakadiEvent); void finish(); }### Answer: @Test public void shouldNotPublishEmpt...
### Question: EventBatcher { public void pushEvent(EventLog eventLogEntry, NakadiEvent nakadiEvent) { long eventSize; try { eventSize = objectMapper.writeValueAsBytes(nakadiEvent).length; } catch (Exception e) { log.error("Could not serialize event {} of type {}, skipping it.", eventLogEntry.getId(), eventLogEntry.getE...
### Question: TracerFlowIdComponent implements FlowIdComponent { @Override public void startTraceIfNoneExists() { if (tracer != null) { try { tracer.get(X_FLOW_ID).getValue(); } catch (IllegalArgumentException e) { log.warn("No trace was configured for the name {}. Returning null. " + "To configure Tracer provide an ap...
### Question: BaseRemoteAccessApi { public DefaultCrumbIssuer getCrumb() throws ApiException { ApiResponse<DefaultCrumbIssuer> resp = getCrumbWithHttpInfo(); return resp.getData(); } BaseRemoteAccessApi(); BaseRemoteAccessApi(ApiClient apiClient); ApiClient getApiClient(); void setApiClient(ApiClient apiClient); com.s...
### Question: XmlModelLoader extends ModelLoader<XmlModel, InputStream> { @Override public XmlModel loadModel(InputStream xmlStream) throws ModelException { if (xmlStream == null) { throw new ModelException("XML model is not valid [null]."); } try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Doc...
### Question: UmlModelLoader extends ModelLoader<UmlModel, File> { @Override public UmlModel loadModel(File modelFile) throws UmlModelException { if (modelFile == null) { return new UmlModel(UmlModelProducer.getInstance().createUmlModel(null)); } try { Model model = getUmlRootModel(modelFile); UmlModel umlModel = new U...
### Question: ReceiverServiceImpl implements ReceiverService { @Override public void receive(ProbeJson probeJson) { concurrentDataList.addProbeJson(probeJson); } @Override void receive(ProbeJson probeJson); @Override @Scheduled(cron = "0 0/20 7-23 * * ?") void commit(); @Override RealTimeJson statLatest(); }### Answe...
### Question: UserDaoImpl implements UserDao { @Override public UserEntity save(UserEntity userEntity) { return userRepository.save(userEntity); } @Override UserEntity findById(int id); @Override UserEntity findByName(String name); @Override UserEntity findByNameAndPassword(String name, String password); @Override Use...
### Question: UserDaoImpl implements UserDao { @Override public void delete(int id) { userRepository.delete(id); } @Override UserEntity findById(int id); @Override UserEntity findByName(String name); @Override UserEntity findByNameAndPassword(String name, String password); @Override UserEntity save(UserEntity userEnti...
### Question: NewOldServiceImpl implements NewOldService { @Override public List<NewOldVo> getNewOldStat(int startHour, QueryThreshold threshold, int startRange, String probeId) throws ParamException { if (threshold==null) throw new ParamException(ServerCode.PARAM_FORMAT,"threshold","threshold cannot be null"); return ...
### Question: NewOldServiceImpl implements NewOldService { @Override public List<Tuple<String, Number>> findByHourAndProbe(int hour, String probeId) { return ObjectMapper.convertToChartData(newOldDao.findByHourAndProbe(hour, probeId)); } @Override List<NewOldVo> getNewOldStat(int startHour, QueryThreshold threshold, i...
### Question: NewOldServiceImpl implements NewOldService { @Override public NewOldVo findById(int id) throws ServerException { NewOldEntity entity = newOldDao.findById(id); if (entity == null) throw new ServerException(ServerCode.NOT_FOUND); return new NewOldVo(entity); } @Override List<NewOldVo> getNewOldStat(int sta...
### Question: NewOldServiceImpl implements NewOldService { @Override public NewOldVo save(NewOldCustomElement newOldCustomElement) { NewOldEntity entity = new NewOldEntity(); entity.setWifiProb(newOldCustomElement.getWifiProb()); entity.setHour(new Timestamp(newOldCustomElement.getHour()*3600*1000)); entity.setNewCusto...
### Question: UserServiceImpl implements UserService { @Override public UserVo login(String username, String password) throws ServerException { UserEntity userEntity = userDao.findByName(username); if (userEntity==null) throw new ServerException(ServerCode.USER_NOT_FOUND); if (!userEntity.getPassword().equals(password)...
### Question: ActivenessServiceImpl implements ActivenessService { @Override public List<ActivenessVo> getActivenessStat(int startHour, QueryThreshold threshold, int startRange, String probeId) throws ParamException { if (threshold==null) throw new ParamException(ServerCode.PARAM_FORMAT,"threshold","threshold cannot be...
### Question: ActivenessServiceImpl implements ActivenessService { @Override public List<Tuple<String, Number>> findByHourAndProbe(int hour, String probeId) { ActivenessEntity activenessEntity = activenessDao.findByHourAndProbe(hour, probeId); return ObjectMapper.convertToChartData(activenessEntity); } @Override List<...
### Question: ActivenessServiceImpl implements ActivenessService { @Override public ActivenessVo findById(int id) throws ServerException { ActivenessEntity entity = activenessDao.findById(id); if (entity==null) throw new ServerException(ServerCode.NOT_FOUND); return new ActivenessVo(entity); } @Override List<Activenes...
### Question: ReceiverServiceImpl implements ReceiverService { @Override @Scheduled(cron = "0 0/20 7-23 * * ?") public void commit() { new Thread( () -> { try { if (concurrentDataList.getSize()>0) { int sleep = (int) (Math.random()*60000); try { Thread.sleep(sleep); } catch (InterruptedException e) { e.printStackTrace(...
### Question: ActivenessServiceImpl implements ActivenessService { @Override public ActivenessVo save(CustomerActivenessElement activenessElement) { ActivenessEntity entity = new ActivenessEntity(); entity.setWifiProb(activenessElement.getWifiProb()); entity.setHour(new Timestamp(activenessElement.getHour()*3600*1000))...
### Question: VisitCircleServiceImpl implements VisitCircleService { @Override public List<VisitCircleVo> getVisitCircleStat(int startHour, QueryThreshold threshold, int startRange, String probeId) throws ParamException { if (threshold==null) throw new ParamException(ServerCode.PARAM_FORMAT,"threshold","threshold canno...
### Question: VisitCircleServiceImpl implements VisitCircleService { @Override public List<Tuple<String, Number>> findByHourAndProbe(int hour, String probeId) { return ObjectMapper.convertToViewData( ObjectMapper.convertToChartData(visitCircleDao.findByHourAndProbe(hour, probeId)), ConvertType.circle); } @Override Lis...
### Question: VisitCircleServiceImpl implements VisitCircleService { @Override public VisitCircleVo findById(int id) throws ServerException { VisitCircleEntity visitCircleEntity = visitCircleDao.findById(id); if (visitCircleEntity==null) throw new ServerException(ServerCode.NOT_FOUND); return new VisitCircleVo(visitCir...
### Question: VisitCircleServiceImpl implements VisitCircleService { @Override public VisitCircleVo save(VisitingCycleElement visitingCycleElement) { VisitCircleEntity entity = new VisitCircleEntity(); entity.setWifiProb(visitingCycleElement.getWifiProb()); entity.setHour(new Timestamp(visitingCycleElement.getHour()*36...
### Question: ProbeServiceImpl implements ProbeService { @Override public Page<ProbeVo> findAll(int page, int size) { Page<ProbeEntity> probeEntities = probeDao.findAll(page, size); return new PageImpl<>(probeEntities.getContent().stream().map(ProbeVo::new).collect(Collectors.toList()), probeEntities.nextPageable(),pro...
### Question: ProbeServiceImpl implements ProbeService { @Override public ProbeVo findById(int id) throws ServerException { ProbeEntity probeEntity = probeDao.findById(id); if (probeEntity==null) throw new ServerException(ServerCode.NOT_FOUND); return new ProbeVo(probeEntity); } @Override Page<ProbeVo> findAll(int pag...
### Question: FlowServiceImpl implements FlowService { @Override public List<FlowVo> getFStat(int startHour, QueryThreshold threshold, int startRange, String probeId) throws ParamException { if (threshold==null) throw new ParamException(ServerCode.PARAM_FORMAT,"threshold","threshold cannot be null"); return flowDao.get...
### Question: FlowServiceImpl implements FlowService { @Override public List<Tuple<String, Number>> findByHourAndProbe(int hour, String probeId) { return ObjectMapper.convertToChartData(flowDao.findByHourAndProbe(hour, probeId)); } @Override List<FlowVo> getFStat(int startHour, QueryThreshold threshold, int startRange...
### Question: FlowServiceImpl implements FlowService { @Override public FlowVo findById(int id) throws ServerException { FlowEntity entity = flowDao.findById(id); if (entity==null) throw new ServerException(ServerCode.NOT_FOUND); return new FlowVo(entity); } @Override List<FlowVo> getFStat(int startHour, QueryThreshol...
### Question: HttpTools { public static URLConnection sendGet(String url) { try { URL realUrl = new URL(url); URLConnection connection = realUrl.openConnection(); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1...
### Question: FlowServiceImpl implements FlowService { @Override public FlowVo save(CustomerFlowElement flowElement) { FlowEntity flowEntity = new FlowEntity(); flowEntity.setWifiProb(flowElement.getWifiProb()); flowEntity.setHour(new Timestamp(flowElement.getHour()*3600*1000)); flowEntity.setInNoOutWifi(flowElement.ge...
### Question: StoreHoursServiceImpl implements StoreHoursService { @Override public List<StoreHoursVo> getStoreHoursStat(int startHour, QueryThreshold threshold, int startRange, String probeId) throws ParamException { if (threshold==null) throw new ParamException(ServerCode.PARAM_FORMAT,"threshold","threshold cannot be...
### Question: StoreHoursServiceImpl implements StoreHoursService { @Override public List<Tuple<String, Number>> findByHourAndProbe(int hour, String probeId) { return ObjectMapper.convertToViewData( ObjectMapper.convertToChartData(storeHoursDao.findByHourAndProbe(hour, probeId)), ConvertType.store); } @Override List<St...
### Question: StoreHoursServiceImpl implements StoreHoursService { @Override public StoreHoursVo findById(int id) throws ServerException { StoreHoursEntity entity = storeHoursDao.findById(id); if (entity==null) throw new ServerException(ServerCode.NOT_FOUND); return new StoreHoursVo(entity); } @Override List<StoreHour...
### Question: StoreHoursServiceImpl implements StoreHoursService { @Override public StoreHoursVo save(InStoreHoursElement storeHoursElement) { StoreHoursEntity entity = new StoreHoursEntity(); entity.setWifiProb(storeHoursElement.getWifiProb()); entity.setHour(new Timestamp(storeHoursElement.getHour()*3600*1000)); List...
### Question: HttpTools { public static String getLocalIp() { InputStream inputStream = HttpTools.class.getClassLoader().getResourceAsStream("config/ipconfig"); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String config = reader.readLine(); Enumeration<NetworkInterface> netInter...
### Question: ActivenessDaoImpl implements ActivenessDao { @Override public List<ActivenessVo> getActivenessStat(int startHour, QueryThreshold threshold, int statRange, String probeId) { String isProbeSelected = probeId==null || probeId.isEmpty()? "": "AND wifiProb = :probeId "; String sqlQuery = "SELECT wifiProb,DATE_...
### Question: ActivenessDaoImpl implements ActivenessDao { @Override public ActivenessEntity findByHourAndProbe(int hour, String probeId) { Timestamp timestamp = new Timestamp(((long) hour)*3600*1000); System.out.println(timestamp.getTime()); return activenessRepository.findByHourAndWifiProb(timestamp,probeId); } @Ove...
### Question: ActivenessDaoImpl implements ActivenessDao { @Override public ActivenessEntity findById(int id) { return activenessRepository.findOne(id); } @Override List<ActivenessVo> getActivenessStat(int startHour, QueryThreshold threshold, int statRange, String probeId); @Override ActivenessEntity findByHourAndProb...
### Question: ActivenessDaoImpl implements ActivenessDao { @Override public ActivenessEntity save(ActivenessEntity entity) { return activenessRepository.save(entity); } @Override List<ActivenessVo> getActivenessStat(int startHour, QueryThreshold threshold, int statRange, String probeId); @Override ActivenessEntity fin...
### Question: UserDaoImpl implements UserDao { @Override public UserEntity findById(int id) { return userRepository.findOne(id); } @Override UserEntity findById(int id); @Override UserEntity findByName(String name); @Override UserEntity findByNameAndPassword(String name, String password); @Override UserEntity save(Use...
### Question: UserDaoImpl implements UserDao { @Override public UserEntity findByName(String name) { return userRepository.findByUsername(name); } @Override UserEntity findById(int id); @Override UserEntity findByName(String name); @Override UserEntity findByNameAndPassword(String name, String password); @Override Use...
### Question: PotentiometerSimulator implements ISimulatorUpdater { public boolean isSetup() { return mIsSetup; } PotentiometerSimulator(IAnalogInWrapper aWrapper, IPwmWrapper aSpeedController); void setParameters(double aThrow, double aMinVoltage, double aMaxVoltage); @Override void update(); boolean isSetup(); @Overr...
### Question: CompressorWrapper extends ASensorWrapper { public CompressorWrapper() { super("Compressor"); mAirPressure = 120; mChargeRate = .25; } CompressorWrapper(); void setChargeRate(double aChargeRate); void solenoidFired(double aPressure); void update(); double getAirPressure(); }### Answer: @Test public void t...
### Question: JoystickFactory { private JoystickFactory() { mJoystickMap = new IMockJoystick[DriverStation.kJoystickPorts]; for (int i = 0; i < DriverStation.kJoystickPorts; ++i) { mJoystickMap[i] = new NullJoystick(); } mControllerConfig = JoystickDiscoverer.rediscoverJoysticks(); loadSticks(); } private JoystickFact...
### Question: XboxJoystick extends BaseJoystick { @Override public float[] getAxisValues() { float[] output = super.getAxisValues(); float triggerValue = output[2]; if (triggerValue < 0) { output[2] = 0; output[3] = triggerValue; } else { output[2] = triggerValue; output[3] = 0; } return output; } XboxJoystick(Controll...
### Question: KeyboardJoystick extends BaseJoystick { public KeyboardJoystick(Controller aController) { this(aController, "Keyboard"); } KeyboardJoystick(Controller aController); KeyboardJoystick(Controller aController, String aName); @Override float[] getAxisValues(); @Override short[] getPovValues(); }### Answer: @...
### Question: GuavaUtils { public static <T> boolean isPresent(T t){ Optional<T>optionalObj = Optional.fromNullable(t); return optionalObj.isPresent(); } static boolean isPresent(T t); }### Answer: @Test public void isPresentTest(){ B1 b = null; assertEquals(false, GuavaUtils.isPresent(b)); b = new B1(); assertEquals...
### Question: DozerUtils { public static <T> T convertSourceObjToDesObj(Object source,Class<T> destinationClass){ return mapper.map(source, destinationClass); } static T convertSourceObjToDesObj(Object source,Class<T> destinationClass); static void main(String[] args); }### Answer: @Test public void testDozer(){ B1 b...
### Question: AgentMaster { private AgentMaster(SmartConf conf) throws IOException { String[] addresses = AgentUtils.getMasterAddress(conf); if (addresses == null) { throw new IOException("AgentMaster address not configured!"); } String address = addresses[0]; LOG.info("Agent master: " + address); Config config = Agent...
### Question: ActionDao { public List<ActionInfo> getAPageOfAction(long start, long offset, List<String> orderBy, List<Boolean> isDesc) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); boolean ifHasAid = false; String sql = "SELECT * FROM " + TABLE_NAME + " ORDER BY "; for (int i = 0; i < orderBy.size(); i++...
### Question: NamespaceFetcher { public NamespaceFetcher(DFSClient client, MetaStore metaStore, ScheduledExecutorService service) { this(client, metaStore, DEFAULT_INTERVAL, service, new SmartConf()); } NamespaceFetcher(DFSClient client, MetaStore metaStore, ScheduledExecutorService service); NamespaceFetcher(DFSClien...
### Question: ListFileAction extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); this.srcPath = args.get(FILE_PATH); } @Override void init(Map<String, String> args); }### Answer: @Test public void testRemoteFileList() throws Exception { final String srcPath = "/testList"; fin...
### Question: FileInfo { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FileInfo fileInfo = (FileInfo) o; return fileId == fileInfo.fileId && length == fileInfo.length && isdir == fileInfo.isdir && blockReplication == fileInfo.b...
### Question: StringUtil { public static List<String> parseCmdletString(String cmdlet) throws ParseException { if (cmdlet == null || cmdlet.length() == 0) { return new ArrayList<>(); } char[] chars = (cmdlet + " ").toCharArray(); List<String> blocks = new ArrayList<String>(); char c; char[] token = new char[chars.lengt...
### Question: SecurityUtil { public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab...
### Question: CustomerOrderExtractor implements PayloadWrapperExtractor<CustomerOrderPayload, CustomerOrder> { @Override public CustomerOrder extractData(PayloadWrapper<CustomerOrderPayload> payloadWrapper) { CustomerOrder value = null; if (payloadWrapper.hasPayload()) { value = new CustomerOrder(); CustomerOrderPayloa...
### Question: ItemExtractor implements PayloadWrapperExtractor<ItemPayload, Item> { @Override public Item extractData(PayloadWrapper<ItemPayload> payloadWrapper) { Item value = null; if (payloadWrapper.hasPayload()) { value = new Item(); ItemPayload payload = payloadWrapper.getPayload(); value.setName(payload.getName()...
### Question: CustomerExtractor implements PayloadWrapperExtractor<CustomerPayload, Customer> { @Override public Customer extractData(PayloadWrapper<CustomerPayload> payloadWrapper) { Customer value = null; if (payloadWrapper.hasPayload()) { value = new Customer(); CustomerPayload payload = payloadWrapper.getPayload();...
### Question: ItemResultSetExtractor implements ResultSetExtractor<PayloadWrapper<ItemPayload>> { @Override public PayloadWrapper<ItemPayload> extractData(ResultSet rs) throws SQLException, DataAccessException { ItemPayload itemPayload = null; if (rs.next()) { itemPayload = new ItemPayload(); itemPayload.setId(rs.getSt...
### Question: CustomerResultSetExtractor implements ResultSetExtractor<PayloadWrapper<CustomerPayload>> { @Override public PayloadWrapper<CustomerPayload> extractData(ResultSet rs) throws SQLException, DataAccessException { CustomerPayload customerPayload = null; if (rs.next()) { customerPayload = new CustomerPayload()...
### Question: CustomerOrderResultSetExtractor implements ResultSetExtractor<PayloadWrapper<CustomerOrderPayload>> { @Override public PayloadWrapper<CustomerOrderPayload> extractData(ResultSet rs) throws SQLException, DataAccessException { CustomerOrderPayload result = null; while (rs.next()) { if (result == null) { res...
### Question: GeodeMessageAggregator { @Aggregator public GeodeDataWrapper output(List<Message<PayloadWrapper>> messages) { GeodeDataWrapper geodeDataWrapper = new GeodeDataWrapper(); for (Message<PayloadWrapper> message : messages) { String geodeRegionName = (String) message.getHeaders().get("srcGroup"); Object geodeK...
### Question: GeodeMessageAggregator { @CorrelationStrategy public String correlation(Message<?> message) { int hashCode = message.getHeaders().get("srcKey").hashCode(); int divisor = groupCount; return "[" + (String) message.getHeaders().get("srcGroup") + "]" + ",[" + Math.floorMod(hashCode, divisor) + "]"; } GeodeMes...
### Question: GeodeMessageAggregator { @ReleaseStrategy public boolean canMessagesBeReleased(List<Message<?>> messages) { return messages.size() >= batchSize; } GeodeMessageAggregator(ApplicationContext context, int groupCount, int batchSize); @Aggregator GeodeDataWrapper output(List<Message<PayloadWrapper>> messages);...
### Question: GeodeMessageHandler { public void handleMessage(Message<GeodeDataWrapper> message) { MessageHeaders headers = message.getHeaders(); GeodeDataWrapper payload = message.getPayload(); String regionName = (String) headers.get("srcGroup"); Region<Object, Object> region = clientCache.getRegion(regionName); regi...
### Question: DropboxAPI { public Account accountInfo() throws DropboxException { assertAuthenticated(); @SuppressWarnings("unchecked") Map<String, Object> accountInfo = (Map<String, Object>) RESTUtility.request(RequestMethod.GET, session.getAPIServer(), "/account/info", VERSION, new String[] {"locale", session.getLoca...
### Question: DropboxAPI { public Entry copy(String fromPath, String toPath) throws DropboxException { assertAuthenticated(); String[] params = {"root", session.getAccessType().toString(), "from_path", fromPath, "to_path", toPath, "locale", session.getLocale().toString()}; @SuppressWarnings("unchecked") Map<String, Obj...
### Question: DropboxAPI { public Entry move(String fromPath, String toPath) throws DropboxException { assertAuthenticated(); String[] params = {"root", session.getAccessType().toString(), "from_path", fromPath, "to_path", toPath, "locale", session.getLocale().toString()}; @SuppressWarnings("unchecked") Map<String, Obj...
### Question: DropboxAPI { public DropboxLink media(String path, boolean ssl) throws DropboxException { assertAuthenticated(); String target = "/media/" + session.getAccessType() + path; @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>)RESTUtility.request(RequestMethod.GET, session.getAPISe...
### Question: DropboxAPI { public DropboxLink share(String path) throws DropboxException { assertAuthenticated(); String target = "/shares/" + session.getAccessType() + path; @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>)RESTUtility.request(RequestMethod.GET, session.getAPIServer(), targ...
### Question: DropboxAPI { public Entry metadata(String path, int fileLimit, String hash, boolean list, String rev) throws DropboxException { assertAuthenticated(); if (fileLimit <= 0) { fileLimit = METADATA_DEFAULT_LIMIT; } String[] params = { "file_limit", String.valueOf(fileLimit), "hash", hash, "list", String.value...
### Question: DropboxAPI { public Entry createFolder(String path) throws DropboxException { assertAuthenticated(); String[] params = {"root", session.getAccessType().toString(), "path", path, "locale", session.getLocale().toString()}; @SuppressWarnings("unchecked") Map<String, Object> resp = (Map<String, Object>) RESTU...
### Question: DropboxAPI { public Entry putFile(String path, InputStream is, long length, String parentRev, ProgressListener listener) throws DropboxException { UploadRequest request = putFileRequest(path, is, length, parentRev, listener); return request.upload(); } DropboxAPI(SESS_T session); ChunkedUploader getChunke...
### Question: DropboxAPI { public DropboxFileInfo getFile(String path, String rev, OutputStream os, ProgressListener listener) throws DropboxException { DropboxInputStream dis = getFileStream(path, rev); dis.copyStreamToOutput(os, listener); return dis.getFileInfo(); } DropboxAPI(SESS_T session); ChunkedUploader getChu...
### Question: DropboxAPI { public DropboxFileInfo getThumbnail(String path, OutputStream os, ThumbSize size, ThumbFormat format, ProgressListener listener) throws DropboxException { DropboxInputStream thumb = getThumbnailStream(path, size, format); thumb.copyStreamToOutput(os, listener); return thumb.getFileInfo(); } D...
### Question: DropboxAPI { public DropboxInputStream getThumbnailStream(String path, ThumbSize size, ThumbFormat format) throws DropboxException { assertAuthenticated(); String target = "/thumbnails/" + session.getAccessType() + path; String[] params = {"size", size.toAPISize(), "format", format.toString(), "locale", s...
### Question: RollingNumber { public double getAvg(CounterDataType counterDataType) { long latestRollingSum = getTotalSum(counterDataType); return (double)(latestRollingSum) / intervals; } RollingNumber(); void addOne(CounterDataType dataType); void add(CounterDataType dataType, long value); long getTotalSum(CounterDat...
### Question: FileUtils { public static List<File> getFileListByPath(String path) { return getFileListByPath(path, null); } static String getExtension(String fileName); static void writeByteArrayToFile(File file, byte[] data, boolean append); static byte[] readFileToByteArray(File file); static void writeStringToFile(...
### Question: Validators { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } static boolean isAlphanumeric(String str); sta...
### Question: MathUtils { public static double add(double v1, double v2) { BigDecimal b1 = createBigDecimal(v1); BigDecimal b2 = createBigDecimal(v2); return b1.add(b2).doubleValue(); } static double add(double v1, double v2); static double div(double v1, double v2); static double div(double v1, double v2, int scale);...
### Question: Diverter { public boolean isHit(long bizId) { return hitNum(bizId) >= 0; } Diverter(DiverterConfig config); boolean isHit(long bizId); long hitNum(long bizId); }### Answer: @Test public void test() { for (long i = 0; i < 100; i++) { boolean hit = diverter.isHit(i); System.out.println("i=" + i + ".hit=" +...
### Question: UUIDUtils { public static String uuid() { return uuid.generateHex(); } private UUIDUtils(); byte[] generateBytes(); static String uuid(); }### Answer: @Test public void testUuid() { Set<String> idSet = new HashSet<>(); for (int i = 0; i < 50; i++) { new Thread(new Runnable() { @Override public void run(...
### Question: LocalKvUtils { public static String get(String path, String key) { Properties properties = getPropertiesFromPath(path); if (null == properties) { return null; } return properties.getProperty(key); } static void put(String path, String key, String value); static void put(String path, Map<String, String> m...
### Question: LocalKvUtils { public static void put(String path, String key, String value) { Properties properties = getPropertiesFromPath(path); if (null == properties) { return; } properties.put(key, value); writeProperties(path, properties); } static void put(String path, String key, String value); static void put(...
### Question: LocalKvUtils { public static void remove(String path, String key) { Properties properties = getPropertiesFromPath(path); if (null == properties) { return; } properties.remove(key); writeProperties(path, properties); } static void put(String path, String key, String value); static void put(String path, Ma...
### Question: LocalKvUtils { public static void removeAll(String path) { if (null == path) { return; } File file = new File(path); if (file.exists()) { file.delete(); } } static void put(String path, String key, String value); static void put(String path, Map<String, String> map); static String get(String path, String...
### Question: Map2BeanUtils { public static <T> T map2Bean(Map<String, Object> map, Class<T> beanClass) { T obj; try { obj = beanClass.newInstance(); BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor property : ...
### Question: Map2BeanUtils { public static Map<String, Object> bean2Map(Object obj) { if (obj == null) { return null; } Map<String, Object> map = new HashMap<>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (Prope...
### Question: JavaCommOpenHandler extends CommOpenHandler { public Handler<Message>[] getKernelControlChanelHandlers(String targetName){ if(TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)){ return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS; }else{ return (Handler<Message>[]...