public static void main(String[] args) throws InterruptedException, IOException { /* * args[0] : job of the worker "map" or "reduce" * * if args[0] == "map" * args[1] : "filepath/name" of the file to work on * args[2] : task_id : the line-number of the line on which to apply map * (in UMxMachines : is also the key linked to worker's id) * * else * args[1] : "key" * args[2] to args[N] : task_ids of the mappers that treated the key */ if (args[0].equals("map")) { Mapper mapper = new Mapper(args[1], args[2]); mapper.map(); } else if (args[0].equals("reduce")) { Reducer reducer = new Reducer(args[1], Arrays.copyOfRange(args, 2, args.length)); reducer.shuffle(); reducer.reduce(); } // worker.showUM(); }
public String toString() { StringBuilder ret = new StringBuilder(); ret.append("local_addr=" + local_addr).append("\n"); ret.append("connections (" + mapper.size() + "):\n"); ret.append(mapper.toString()); ret.append('\n'); return ret.toString(); }
public static void map(IDatabase oldDb, IDatabase newDb, Sequence seq) throws Exception { String query = "SELECT l.*, e.f_flow FROM tbl_processlinks l " + "join tbl_exchanges e on l.f_provideroutput = e.id"; Mapper<ProcessLink> mapper = new Mapper<>(ProcessLink.class, oldDb, newDb); Handler handler = new Handler(seq); mapper.mapAll(query, handler); }
public String getDispatcherPath() { Mapper mapping = dipatcherDef.getMapper(); if (mapping != null) { return mapping.getMappingPath(); } return null; }
public void createResources() throws XBeeException { sensorResource = new SensorResource(); periodicReportResource = new PeriodicReportResource(); alarmResource = new AlarmResource(); String targetId, content; targetId = sclId + "/applications"; ResponseConfirm responseConfirm = core.doRequest( new RequestIndication("CREATE", targetId, reqEntity, new Application(appID, ipuId))); if (responseConfirm.getStatusCode().equals(StatusCode.STATUS_CREATED)) { targetId = sclId + "/applications/" + appID + "/containers"; // create resources container core.doRequest( new RequestIndication( "CREATE", targetId, reqEntity, new Container("ReportDataContainer"))); // create descriptors containter core.doRequest( new RequestIndication( "CREATE", targetId, reqEntity, new Container("ReportDataDescriptor"))); // create resources container content = Mapper.getResourcesRep(sclId, appID, ipuId); targetId = sclId + "/applications/" + appID + "/containers/ReportDataDescriptor/contentInstances"; core.doRequest( new RequestIndication( "CREATE", targetId, reqEntity, new ContentInstance(content.getBytes()))); } targetId = sclId + "/applications"; ResponseConfirm responseConfirm1 = core.doRequest( new RequestIndication("CREATE", targetId, reqEntity, new Application(appID2, ipuId))); if (responseConfirm1.getStatusCode().equals(StatusCode.STATUS_CREATED)) { targetId = sclId + "/applications/" + appID2 + "/containers"; // create resources container core.doRequest( new RequestIndication( "CREATE", targetId, reqEntity, new Container("AlarmDataContainer"))); // create descriptors containter core.doRequest( new RequestIndication( "CREATE", targetId, reqEntity, new Container("AlarmDataDescriptor"))); targetId = sclId + "/applications/" + appID2 + "/containers/AlarmDataDescriptor/contentInstances"; content = Mapper.getAlarmDataDescriptorRep(sclId, appID2, ipuId); core.doRequest( new RequestIndication( "CREATE", targetId, reqEntity, new ContentInstance(content.getBytes()))); } }
private static Optional<OptionProperty> of(Property property) { SimpleTypeInfo returnTypeInfo = property.returnTypeInfo(); if (returnTypeInfo.isEnum()) { return EnumOptionProperty.mapper(property); } else { String qname = returnTypeInfo.qualifiedName(); Mapper mapper = MAPPERS.getOrDefault(qname, (p) -> Optional.<OptionProperty>empty()); return mapper.of(property); } }
public void setInfos(String str) { if (str == "house") { for (House hous : map_.getCity_().getBuilds_()) info_.setText(typeLocal_ + "," + hous.getInfos(), imageLocal_); } else if (str == "farm") { for (Farm farm : map_.getCity_().getFarms_()) info_.setText(typeLocal_ + "," + farm.getInfos(), imageLocal_); System.out.println("toto"); } else info_.setText(typeLocal_, imageLocal_); // map_.getMapLocal_().get((int) pos_.getWidth()).get((int) pos_.getHeight()).getIn }
public void normalization(Sentence sentence) { String input = breakWords(sentence.getOriginal()); input = ' ' + input + ' '; input = input.replaceAll("\\s{2,}", " "); sentence.setOriginal(input); Mapper mapper = new Mapper(input); input = substitute(input, mapper); input = fit(input, mapper); sentence.setMappings(mapper.toArray()); sentence.setNormalized(input); }
/** * Turns the entry to UPPERCASE, takes sequences of non-alphanumeric characters out of it * (replacing them with a single whitespace) and sees that the entry is trimmed off leading and * trailing whitespaces. */ private String fit(String input, Mapper mapper) { input = input.toUpperCase(); Matcher matcher = fitting.matcher(input); StringBuffer buffer = new StringBuffer(); while (!matcher.hitEnd() && matcher.find()) { mapper.prepare(input, matcher.group(), " "); mapper.update(matcher.start()); matcher.appendReplacement(buffer, " "); } matcher.appendTail(buffer); return buffer.toString(); }
@Override public final void run() { while (!isInterrupted()) { final boolean b; synchronized (this) { b = pleaseRepaint; pleaseRepaint = keepPainting; } if (b) { final long t = System.currentTimeMillis(); lambda += dt * dLambda; phi += dt * dPhi; this.camera.setOrientation(lambda, phi, rho); mapper.map(temp); final Object targetPixels = target.getPixels(); target.setPixels(temp.getPixels()); temp.setPixels(targetPixels); impTarget.updateAndDraw(); if (visualize) visualize(impSource, temp.getWidth(), temp.getHeight(), p); dt = (System.currentTimeMillis() - t) / 1000f; } synchronized (this) { try { if (!pleaseRepaint) wait(); } catch (final InterruptedException e) { } } } }
/** * Takes a String of words with at least 4 characters and counts the occurrence. Words that occur * more than once are treated as important words. * * @param input with all the words that contain more than 3 characters * @return keywords with words that occur more than 3 times */ public static List<String> extractImportantWords(String input) { HashMap<String, Integer> keywords = new HashMap(); for (String word : input.toLowerCase().split("\\s+")) { if (word.length() <= 3) { continue; } Integer count = keywords.get(word); if (count == null) { count = 0; } keywords.put(word, count + 1); } HashMap<String, Integer> filtered = new HashMap(); for (String word : keywords.keySet()) { Integer count = keywords.get(word); if (count > 1 && !StopWords.get().contains(word)) { filtered.put(word, -count); } } List<String> sorted = Mapper.sortByValue(filtered); if (sorted.size() > 5) { sorted = sorted.subList(0, 5); } Collections.sort(sorted); return sorted; }
@SuppressWarnings("rawtypes") @Override public Object resolve(Object contextObject, String name, ResolutionContext context) { if (contextObject == null) { return null; } if (contextObject instanceof Map) { Map map = (Map) contextObject; return map.get(name); } if (contextObject instanceof Mapper) { Mapper mapper = (Mapper) contextObject; return mapper.get(name); } return null; }
public <T> T to(TypeReference<T> typeReference) { try { return Mapper.get().readValue(message, typeReference); } catch (IOException e) { throw new RuntimeException(e); } }
public <T> T to(Class<T> clazz) { try { return Mapper.get().readValue(message, clazz); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public ResultPage<T> search(ResultPage<T> resultPage, Mapper<T> mapper) { ElasticSearchCriteria criteria = resultPage.getCriteria(); if (criteria == null) return resultPage; SearchRequestBuilder srb = criteria2builder(criteria); if (resultPage.isPaginating()) { srb.setFrom(resultPage.getStart()); srb.setSize(resultPage.getPageSize()); } else { srb.setFrom(0); srb.setSize(ResultPage.DEFAULT_MAX_PAGESIZE); } try { SearchResponse response = srb.execute().get(); SearchHits shs = response.getHits(); if (shs != null) { resultPage.setTookInMillis(response.getTookInMillis()); resultPage.setTotalResults(shs.getTotalHits()); List list = new ArrayList(shs.getHits().length); resultPage.setResult(list); for (SearchHit sh : shs.getHits()) { T data = (T) indexManager.searchHitToEntity(sh); data = mapper == null ? data : mapper.map(data); if (data != null) list.add(data); } } } catch (Exception e) { logger.error(e.getMessage(), e); } return resultPage; }
@Override public final void cartWrite(final int addr, final int data) { // System.out.println(data); if (addr < 0x8000 || addr > 0xffff) { super.cartWrite(addr, data); return; } int prgselect = data & 7; int chrselect = (data >> 4) & 0xf; if (crc == 0x42392440) // Cosmo Carrier { setmirroring(((data & (utils.BIT3)) != 0) ? MirrorType.SS_MIRROR1 : MirrorType.SS_MIRROR0); } else { setmirroring(((data & (utils.BIT3)) != 0) ? MirrorType.V_MIRROR : MirrorType.H_MIRROR); } // remap CHR bank for (int i = 0; i < 8; ++i) { chr_map[i] = (1024 * (i + 8 * chrselect)) & (chrsize - 1); } // remap PRG bank for (int i = 0; i < 16; ++i) { prg_map[i] = (1024 * (i + 16 * prgselect)) & (prgsize - 1); } }
/** * Retrieves all the team members saved in the database * * @return List with all the team members */ public List<TeamMember> getTeamMembers() { Debug.logDebug("Loading data from database"); SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor teamMembersCursor = db.rawQuery(SQL_SELECT_ALL, null); return Mapper.mapTeamMembers(teamMembersCursor); }
@Override public final void cartWrite(final int addr, final int data) { if (addr < 0x8000 || addr > 0xffff) { super.cartWrite(addr, data); return; } int prgselect = (byte) (data & 0xF); // remap PRG bank for (int i = 0; i < 16; ++i) { prg_map[16 + i] = (1024 * (i + 16 * prgselect)) & (prgsize - 1); } int mirroring = data >> 6; switch (mirroring) { case 0: setmirroring(MirrorType.SS_MIRROR0); break; case 1: setmirroring(MirrorType.H_MIRROR); break; case 2: setmirroring(MirrorType.V_MIRROR); break; case 3: setmirroring(MirrorType.SS_MIRROR1); break; } }
public void notifyMoreDataReady(float[] bins) { // an array of floats if (recursion) System.err.println(" RECURSION "); nBins = bins.length; if (nBins == 0) return; recursion = true; if (size == null || nBins != size.height || nChunks != size.width) // || this is the or operator createGraphics(); // Returns a Graphics2D object for rendering into the specified // BufferedImage. int width = size.width; for (int i = 0; i < nBins; i++) { // this is recursing over all the rows (nbins is the number of rows) int bin = nBins - i - 1; // I think this makes it start from the top float val = mapper.eval(bins[bin]); // if (val < 0) val = 0.0f; if (val > 1.0) // I think this next section colours the pixels in the spectrum val = 1.0f; // display int c_r = (int) (255 * val); int c_g = c_r; int c_b = 255 - c_r; int color = (c_b) + (c_g << 8) + (c_r << 16) + (0xFF << 24); // << operator means signed left shift-- it shifts the bits in the binary // code to the left creating a bigger number the operand on the right // specifies the amount of shift screenBuffer[i * width + ptr] = (255 << 24) + color; // I think loads the screenBuffer array. the index[i*width+ptr] is filled // with the right operand // rgbarray[i] = color; } if (ptr % 1 == 0) { // ptr remainder(%) 1 screenConverter.newPixels( ptr, 0, 1, nBins); // newPixels is method inside the MemoryImageSource i think it does this----Sends // a rectangular region of the buffer of pixels to any ImageConsumers that are // currently interested in the data for this image and notify them that an // animation frame is complete. screenRepaint = true; repaint(); } ptr = (ptr + 1) % size.width; // i think this may help in changing the co-ordinates ptr may be the x // coordinate recursion = false; }
/** Shuts down the lock manager. */ public void shutdown() throws StorageException { serializationLock.lock(); try { mapper.close(); } finally { serializationLock.unlock(); } }
public static <FROM, TO> TO eval(Mapper<FROM, TO> mapper, FROM src) { try { return mapper.map(src); } catch (Exception e) { throw new RuntimeException( String.format("Cannot evaluate mapper %s on target: %s", mapper, src), e); } }
public void setObject() { if (typeLocal_ != typeBuild_) { imageLocal_ = imageBuild_; typeLocal_ = typeBuild_; map_.creatObject(typeLocal_, pos_); } update(); }
@Test public void shouldGetAUser() { SqlSession sqlSession = sqlSessionFactory.openSession(); try { Mapper mapper = sqlSession.getMapper(Mapper.class); User testProfile = new User(); testProfile.setId(2); User friendProfile = new User(); friendProfile.setId(6); List<User> friendList = new ArrayList<User>(); friendList.add(friendProfile); testProfile.setFriendList(friendList); User user = mapper.getUser(testProfile); Assert.assertEquals("User6", user.getName()); } finally { sqlSession.close(); } }
@Test public void testMapper() throws Exception { Question q = mapper.processQuestion("List cities in california.", false, null, true); assertEquals(2, q.getSemanticConcepts().size()); assertEquals("cities", q.getFocus().getAnnotation().getText()); }
@Test @Override public void testRoundtrip() throws Exception { setUpConfigExpectations(); Disk model = Disk.class.cast(populate(Disk.class)); model = postPopulate(model); Mapper<Disk, org.ovirt.engine.core.common.businessentities.Disk> out = getMappingLocator() .getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.Disk.class); Mapper<org.ovirt.engine.core.common.businessentities.Disk, Disk> back = getMappingLocator() .getMapper(org.ovirt.engine.core.common.businessentities.Disk.class, Disk.class); DiskImage to = (DiskImage) out.map(model, null); DiskImage inverse = getInverse(to); Disk transform = back.map(inverse, null); verify(model, transform); }
public static void assembleMeal(Recipe breakfast, Date projectStart) { // ... check ingredients in stock // map from kitchen world, into project planning world Mapper mapper = new Mapper(); IFrontLoaderTO frontLoaderTO = mapper.mapFrom(breakfast); // do planning ProjectPlanningService.frontloadFrom(projectStart, frontLoaderTO.getActivities()); // merge results so we can display them mapper.mapBack(breakfast, frontLoaderTO); // ... create order // ... restock, etc }
@Override public void loadrom() throws BadMapperException { super.loadrom(); for (int i = 0; i < 32; ++i) { prg_map[i] = (1024 * i) & (prgsize - 1); } for (int i = 0; i < 8; ++i) { chr_map[i] = (1024 * i) & (chrsize - 1); } }
public void stop() { if (running.compareAndSet(true, false)) { try { getSocketFactory().close(srv_sock); } catch (IOException e) { } Util.interruptAndWaitToDie(acceptor); mapper.stop(); } }
public static <INPUT, OUTPUT> List<OUTPUT> map(List<INPUT> inputs, Mapper<INPUT, OUTPUT> mapper) { ArrayList<OUTPUT> value = new ArrayList<>(); for (INPUT object : inputs) { OUTPUT mappedObject = mapper.map(object); if (mappedObject != null) { value.add(mappedObject); } } return value; }
@Override public void loadrom() throws BadMapperException { // needs to be in every mapper. Fill with initial cfg super.loadrom(); for (int i = 1; i <= 32; ++i) { prg_map[32 - i] = prgsize - (1024 * i); } for (int i = 1; i <= 8; ++i) { chr_map[8 - i] = chrsize - (1024 * i); } }