List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.skfiy.typhon.spi.GMConsoleProvider.java
/** * * @param uid/*from w w w . java 2 s. c o m*/ * @param propertyName * @param val * @throws javax.management.MBeanException */ public void changeProperty(final String uid, final String propertyName, final String val) throws MBeanException { try { invoke(transcoding(uid), new Handler() { @Override void execute() { Player player = SessionUtils.getPlayer(); try { Class<?> propertyType = PropertyUtils.getPropertyType(player, propertyName); if (propertyType == null) { // Not found property throw new IllegalArgumentException("Not found property[" + propertyName + "]"); } if (propertyType == Byte.class || propertyType == Byte.TYPE) { BeanUtils.setProperty(player, propertyName, Byte.valueOf(val)); } else if (propertyType == Character.class || propertyType == Character.TYPE) { BeanUtils.setProperty(player, propertyName, val.charAt(0)); } else if (propertyType == Boolean.class || propertyType == Boolean.TYPE) { BeanUtils.setProperty(player, propertyName, Boolean.valueOf(val)); } else if (propertyType == Integer.class || propertyType == Integer.TYPE) { BeanUtils.setProperty(player, propertyName, Integer.valueOf(val)); } else if (propertyType == Long.class || propertyType == Long.TYPE) { BeanUtils.setProperty(player, propertyName, Long.valueOf(val)); } else if (propertyType == Float.class || propertyType == Float.TYPE) { BeanUtils.setProperty(player, propertyName, Float.valueOf(val)); } else if (propertyType == Double.class || propertyType == Double.TYPE) { BeanUtils.setProperty(player, propertyName, Double.valueOf(val)); } else { BeanUtils.setProperty(player, propertyName, val); } } catch (Exception ex) { throw new IllegalArgumentException(ex.getMessage()); } } }); } catch (Exception e) { throw new MBeanException(e, e.getMessage()); } }
From source file:com.github.javaclub.toolbox.util.javabean.JavaTypeHandlers.java
public Object getValue(String fieldValue) { return Byte.valueOf(fieldValue); }
From source file:forge.game.mana.ManaPool.java
public final List<Mana> clearPool(boolean isEndOfPhase) { // isEndOfPhase parameter: true = end of phase, false = mana drain effect List<Mana> cleared = new ArrayList<Mana>(); if (floatingMana.isEmpty()) { return cleared; }/* w ww .jav a 2 s . com*/ if (isEndOfPhase && owner.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.manapoolsDontEmpty)) { return cleared; } final boolean convertToColorless = owner.hasKeyword("Convert unused mana to Colorless"); final List<Byte> keys = Lists.newArrayList(floatingMana.keySet()); if (isEndOfPhase) { for (final Byte c : Lists.newArrayList(keys)) { final String captName = StringUtils.capitalize(MagicColor.toLongString(c)); if (owner.hasKeyword( captName + " mana doesn't empty from your mana pool as steps and phases end.")) { keys.remove(c); } } } if (convertToColorless) { keys.remove(Byte.valueOf(MagicColor.COLORLESS)); } for (Byte b : keys) { Collection<Mana> cm = floatingMana.get(b); if (isEndOfPhase && !owner.getGame().getPhaseHandler().is(PhaseType.CLEANUP)) { final List<Mana> pMana = new ArrayList<Mana>(); for (final Mana mana : cm) { if (mana.getManaAbility() != null && mana.getManaAbility().isPersistentMana()) { pMana.add(mana); } } cm.removeAll(pMana); if (convertToColorless) { convertManaColor(b, MagicColor.COLORLESS); cm.addAll(pMana); } else { cleared.addAll(cm); cm.clear(); floatingMana.putAll(b, pMana); } } else { if (convertToColorless) { convertManaColor(b, MagicColor.COLORLESS); } else { cleared.addAll(cm); cm.clear(); } } } owner.updateManaForView(); owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Cleared, null)); return cleared; }
From source file:org.omnaest.utils.table.impl.adapter.TableToResultSetAdapter.java
@Override public byte getByte(int columnIndex) throws SQLException { return Byte.valueOf(this.getString(columnIndex)); }
From source file:com.workday.autoparse.json.demo.InstanceUpdaterTest.java
@Test public void testBoxedPrimitives() { TestObject testObject = new TestObject(); testObject.myBoxedBoolean = false;/*from w w w . j av a 2s . c o m*/ testObject.myBoxedByte = 1; testObject.myBoxedChar = 'a'; testObject.myBoxedDouble = 1.1; testObject.myBoxedFloat = 1.1f; testObject.myBoxedInt = 1; testObject.myBoxedLong = 1L; testObject.myBoxedShort = 1; Map<String, Object> updates = new HashMap<>(); updates.put("myBoxedBoolean", true); updates.put("myBoxedByte", (byte) 2); updates.put("myBoxedChar", 'b'); updates.put("myBoxedDouble", 2.2); updates.put("myBoxedFloat", 2.2f); updates.put("myBoxedInt", 2); updates.put("myBoxedLong", 2L); updates.put("myBoxedShort", (short) 2); TestObject$$JsonObjectParser.INSTANCE.updateInstanceFromMap(testObject, updates, CONTEXT); assertEquals("myBoxedBoolean", true, testObject.myBoxedBoolean); assertEquals("myBoxedByte", Byte.valueOf((byte) 2), testObject.myBoxedByte); assertEquals("myBoxedChar", Character.valueOf('b'), testObject.myBoxedChar); assertEquals("myBoxedDouble", Double.valueOf(2.2), testObject.myBoxedDouble); assertEquals("myBoxedFloat", Float.valueOf(2.2f), testObject.myBoxedFloat); assertEquals("myBoxedInt", Integer.valueOf(2), testObject.myBoxedInt); assertEquals("myBoxedLong", Long.valueOf(2L), testObject.myBoxedLong); assertEquals("myBoxedShort", Short.valueOf((short) 2), testObject.myBoxedShort); }
From source file:com.ebay.erl.mobius.core.mapred.AbstractMobiusMapper.java
/** * Setup Mapper./*from ww w. ja va2 s.c o m*/ * <p> * * Override this method if there is extra initial * settings need to be done. * <p> * * Make sure to call <code>super.configure(JobConf)</code> * when overriding. * */ @SuppressWarnings("unchecked") @Override public void configure(JobConf conf) { super.configure(conf); this.conf = conf; this._IS_MAP_ONLY_JOB = this.conf.getInt("mapred.reduce.tasks", 1) == 0; // catch the current dataset ID, the {@link Configuration#get(String)} // is costly as it compose Pattern every time. this.currentDatasetID = Byte.valueOf(this.conf.get(ConfigureConstants.CURRENT_DATASET_ID)); String[] datasetIDstoNames = this.conf.getStrings(ConfigureConstants.DATASET_ID_TO_NAME_MAPPING); Map<Byte, String> mapping = new HashMap<Byte, String>(); for (String aMapping : datasetIDstoNames) { int cut = aMapping.indexOf(";"); Byte datasetID = Byte.parseByte(aMapping.substring(0, cut)); String datasetDisplayName = aMapping.substring(cut + 1); mapping.put(datasetID, datasetDisplayName); } if (mapping.size() == 0) throw new IllegalArgumentException(ConfigureConstants.DATASET_ID_TO_NAME_MAPPING + " is not set."); this.dataset_display_id = mapping.get(this.currentDatasetID); if (this.dataset_display_id == null) { throw new IllegalArgumentException("Cannot find display name for datasetID:" + this.currentDatasetID + " from " + ConfigureConstants.DATASET_ID_TO_NAME_MAPPING + ":" + this.conf.get(ConfigureConstants.DATASET_ID_TO_NAME_MAPPING)); } // initialize counters this._COUNTER_INPUT_RECORD = 0L; this._COUNTER_OUTPUT_RECORD = 0L; this._COUNTER_FILTERED_RECORD = 0L; this._COUNTER_INVALIDATE_FORMAT_RECORD = 0L; try { this.key_columns = (String[]) this.conf.getStrings(this.getDatasetID() + ".key.columns", Util.ZERO_SIZE_STRING_ARRAY); this.value_columns = (String[]) this.conf.getStrings(this.getDatasetID() + ".value.columns", Util.ZERO_SIZE_STRING_ARRAY); this.tuple_criteria = (TupleCriterion) this.get("tuple.criteria"); this.computedColumns = (List<ComputedColumns>) this.get("computed.columns"); if (this._IS_MAP_ONLY_JOB) { this.projection_order = (String[]) this.conf.getStrings( this.getDatasetID() + ".columns.in.original.order", Util.ZERO_SIZE_STRING_ARRAY); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:com.thihy.jacoco.data.BundleCoverageDataReader.java
/** * Reads a block of data identified by the given id. Subclasses may * overwrite this method to support additional block types. * //from w w w.j a v a 2s .c om * @param blocktype * block type * @return <code>true</code> if there are more blocks to read * @throws IOException * might be thrown by the underlying input stream */ protected boolean readBlock(final byte blocktype) throws IOException { switch (blocktype) { case BundleCoverageDataWriter.BLOCK_HEADER: readHeader(); return true; case BundleCoverageDataWriter.BLOCK_SESSIONINFO: readSessionInfo(); return true; case BundleCoverageDataWriter.BLOCK_EXECUTIONDATA: readExecutionData(); return true; case BundleCoverageDataWriter.BLOCK_BUNDLE_COVERAGE_DATA: readBundleCoverage(); return true; default: throw new IOException(format("Unknown block type %x.", Byte.valueOf(blocktype))); } }
From source file:io.coala.config.AbstractPropertyGetter.java
/** * @return//from w ww . j a v a2 s. c o m * @throws CoalaException if value was not configured nor any default was * set * @throws NumberFormatException */ public Byte getByte() throws NumberFormatException, CoalaRuntimeException { return Byte.valueOf(get()); }
From source file:it.greenvulcano.gvesb.gviamx.service.internal.SignUpManager.java
public void createSignUpRequest(String email, byte[] request) throws UserExistException { if (email == null || !email.matches(UserActionRequest.EMAIL_PATTERN)) { throw new IllegalArgumentException("Invalid email: " + email); }/*from ww w. java 2s .co m*/ try { usersManager.getUser(email.toLowerCase()); throw new UserExistException(email); } catch (UserNotFoundException e) { if (usersManager.searchUsers(SearchCriteria.builder().byEmail(email.toLowerCase()).limitedTo(1).build()) .getTotalCount() > 0) { throw new UserExistException(email); } } SignUpRequest signUpRequest = signupRepository.get(email.toLowerCase(), SignUpRequest.class) .orElseGet(SignUpRequest::new); signUpRequest.setEmail(email.toLowerCase()); signUpRequest.setIssueTime(new Date()); signUpRequest.setExpireTime(expireTime); signUpRequest.setRequest(request); signUpRequest.setNotificationStatus(NotificationStatus.PENDING); byte[] token = new byte[4]; secureRandom.nextBytes(token); String clearTextToken = String.format(Locale.US, "%02x%02x%02x%02x", IntStream.range(0, token.length).mapToObj(i -> Byte.valueOf(token[i])).toArray()); signUpRequest.setToken(DigestUtils.sha256Hex(clearTextToken)); signupRepository.add(signUpRequest); signUpRequest.setClearToken(clearTextToken); notificationServices.stream() .map(n -> new NotificationManager.NotificationTask(n, signUpRequest, signupRepository, "signup")) .forEach(executor::submit); }
From source file:at.tfr.securefs.ui.CopyFilesTest.java
@Test public void testCopyFilesByWalkNoOverwrite() throws Exception { // Given: target directory, the source file, a dummy target file toFilesPath = Files.createDirectories(toRoot.resolve(DATA_FILES)); final String data = "Hallo Echo"; try (OutputStream os = cp.getEncrypter(fromFile)) { IOUtils.write(data, os);//from www . jav a2 s . c o m } Thread.sleep(1000); Files.write(targetToFile, new byte[] { (byte) 0xCA }); // write dummy file // the timestamp of dummy target file is after source file!! Assert.assertTrue("dummy file stamp must be after source file", Files.getLastModifiedTime(targetToFile) .toInstant().isAfter(Files.getLastModifiedTime(fromFile).toInstant())); // When: copy files with "UPDATE" ProcessFiles pf = new ProcessFilesBean(new MockSecureFsCache()); CopyFilesServiceBean cfb = new CopyFilesServiceBean(config, cp, pf, new MockSecureFsCache(), async); cfb.setAllowOverwriteExisting(true); cfb.setUpdate(true); cfb.setFromPathName(fromRoot.toString()); cfb.setToPathName(toRoot.toString()); cfb.setNewSecret(newSecret); cfb.runCopyFiles(); // Then: a target file is NOT overwritten: byte[] buf = new byte[data.getBytes().length]; int bytesRead; try (InputStream is = Files.newInputStream(targetToFile)) { bytesRead = IOUtils.read(is, buf); } Assert.assertTrue("target file was overwritten", bytesRead == 1); Assert.assertTrue("target file was overwritten, content not matches", Byte.valueOf((byte) 0xCA).equals((byte) buf[0])); }