List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** * Make UNION operation between 2 {@link Collection} * * @param a/*from ww w . ja v a2 s . c o m*/ * @param b * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection union(final Collection a, final Collection b) { final ArrayList list = new ArrayList(); final Map mapa = getCardinalityMap(a); final Map mapb = getCardinalityMap(b); final Set elts = new LinkedHashSet(a); elts.addAll(b); final Iterator it = elts.iterator(); while (it.hasNext()) { final Object obj = it.next(); for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:Main.java
public static float clamp(final float num, final float bound1, final float bound2) { final float max = Math.max(bound1, bound2), min = Math.min(bound1, bound2); return Math.max(Math.min(num, max), min); }
From source file:Main.java
/** * Test a value in specified range, returning minimum if it's below, and maximum if it's above * * @param value Value to test/* ww w .j a v a2s. c o m*/ * @param min Minimum value of range * @param max Maximum value of range * @return value if it's between min and max, min if it's below, max if it's above */ public static float clamp(float value, float min, float max) { return Math.max(min, Math.min(max, value)); }
From source file:fr.inria.atlanmod.instantiator.neoEMF.Launcher.java
public static void main(String[] args) throws GenerationException, IOException { ResourceSetImpl resourceSet = new ResourceSetImpl(); { // initializing the registry resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EcorePackage.eNS_PREFIX, new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoEMFURI.NEOEMF_HBASE_SCHEME, NeoEMFResourceFactory.eINSTANCE); }/*from ww w . jav a2s . c o m*/ Options options = new Options(); configureOptions(options); CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); String epackage_class = commandLine.getOptionValue(E_PACKAGE_CLASS); LOGGER.info("Start loading the package"); Class<?> inClazz = Launcher.class.getClassLoader().loadClass(epackage_class); EPackage _package = (EPackage) inClazz.getMethod("init").invoke(null); Resource metamodelResource = new XMIResourceImpl(URI.createFileURI("dummy")); metamodelResource.getContents().add(_package); LOGGER.info("Finish loading the package"); int size = Launcher.DEFAULT_AVERAGE_MODEL_SIZE; if (commandLine.hasOption(SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(SIZE); size = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } float variation = Launcher.DEFAULT_DEVIATION; if (commandLine.hasOption(VARIATION)) { Number number = (Number) commandLine.getParsedOptionValue(VARIATION); if (number.floatValue() < 0.0f || number.floatValue() > 1.0f) { throw new ParseException(MessageFormat.format("Invalid value for option -{0}: {1}", VARIATION, number.floatValue())); } variation = number.floatValue(); } float propVariation = Launcher.DEFAULT_DEVIATION; if (commandLine.hasOption(PROP_VARIATION)) { Number number = (Number) commandLine.getParsedOptionValue(PROP_VARIATION); if (number.floatValue() < 0.0f || number.floatValue() > 1.0f) { throw new ParseException(MessageFormat.format("Invalid value for option -{0}: {1}", PROP_VARIATION, number.floatValue())); } propVariation = number.floatValue(); } long seed = System.currentTimeMillis(); if (commandLine.hasOption(SEED)) { seed = ((Number) commandLine.getParsedOptionValue(SEED)).longValue(); } Range<Integer> range = Range.between(Math.round(size * (1 - variation)), Math.round(size * (1 + variation))); GenericMetamodelConfig config = new GenericMetamodelConfig(metamodelResource, range, seed); GenericMetamodelGenerator modelGen = new GenericMetamodelGenerator(config); if (commandLine.hasOption(OUTPUT_PATH)) { String outDir = commandLine.getOptionValue(OUTPUT_PATH); //java.net.URI intermediateURI = java.net.URI.create(outDir); modelGen.setSamplesPath(outDir); } int numberOfModels = 1; if (commandLine.hasOption(N_MODELS)) { numberOfModels = ((Number) commandLine.getParsedOptionValue(N_MODELS)).intValue(); } int valuesSize = GenericMetamodelConfig.DEFAULT_AVERAGE_VALUES_LENGTH; if (commandLine.hasOption(VALUES_SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(VALUES_SIZE); valuesSize = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } int referencesSize = GenericMetamodelConfig.DEFAULT_AVERAGE_REFERENCES_SIZE; if (commandLine.hasOption(VALUES_SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(DEGREE); referencesSize = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } config.setValuesRange(Math.round(valuesSize * (1 - propVariation)), Math.round(valuesSize * (1 + propVariation))); config.setReferencesRange(Math.round(referencesSize * (1 - propVariation)), Math.round(referencesSize * (1 + propVariation))); config.setPropertiesRange(Math.round(referencesSize * (1 - propVariation)), Math.round(referencesSize * (1 + propVariation))); long start = System.currentTimeMillis(); modelGen.runGeneration(resourceSet, numberOfModels, size, variation); long end = System.currentTimeMillis(); LOGGER.info( MessageFormat.format("Generation finished after {0} s", Long.toString((end - start) / 1000))); if (commandLine.hasOption(DIAGNOSE)) { for (Resource resource : resourceSet.getResources()) { LOGGER.info( MessageFormat.format("Requested validation for resource ''{0}''", resource.getURI())); BasicDiagnostic diagnosticChain = diagnoseResource(resource); if (!isFailed(diagnosticChain)) { LOGGER.info(MessageFormat.format("Result of the diagnosis of resurce ''{0}'' is ''OK''", resource.getURI())); } else { LOGGER.severe(MessageFormat.format("Found ''{0}'' error(s) in the resource ''{1}''", diagnosticChain.getChildren().size(), resource.getURI())); for (Diagnostic diagnostic : diagnosticChain.getChildren()) { LOGGER.fine(diagnostic.getMessage()); } } } LOGGER.info("Validation finished"); } } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptionComarator<Option>()); try { formatter.setWidth(Math.max(Terminal.getTerminal().getTerminalWidth(), 80)); } catch (Throwable t) { LOGGER.warning("Unable to get console information"); } ; formatter.printHelp("java -jar <this-file.jar>", options, true); System.exit(ERROR); } catch (ClassNotFoundException t) { System.err.println("ERROR: Unable to load class" + t.getLocalizedMessage()); StringWriter stringWriter = new StringWriter(); t.printStackTrace(new PrintWriter(stringWriter)); System.err.println(stringWriter.toString()); } catch (Throwable t) { System.err.println("ERROR: " + t.getLocalizedMessage()); StringWriter stringWriter = new StringWriter(); t.printStackTrace(new PrintWriter(stringWriter)); System.err.println(t); LOGGER.severe(stringWriter.toString()); System.exit(ERROR); } }
From source file:Main.java
/** @see http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue */ public static int getSampleSize(Context context, Uri uri, float maxSize) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/* w w w.ja va 2 s . co m*/ if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { try { InputStream stream = context.getContentResolver().openInputStream(uri); BitmapFactory.decodeStream(stream, null, options); stream.close(); } catch (Exception e) { e.printStackTrace(); } } else BitmapFactory.decodeFile(uri.getPath(), options); int longSide = Math.max(options.outHeight, options.outWidth); return getSampleSize(longSide, maxSize); }
From source file:Main.java
static long calculateApiDiskCacheSize(File dir) { long size = MIN_DISK_API_CACHE_SIZE; try {//from ww w .jav a2 s .c o m StatFs statFs = new StatFs(dir.getAbsolutePath()); long available; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { available = ((long) statFs.getBlockCount()) * statFs.getBlockSize(); } // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE); }
From source file:Main.java
/** * Make UNION operation between 2 {@link Collection} * // www.j av a 2 s . co m * @param a * @param b * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection union(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new LinkedHashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next(); for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:bwem.util.Utils.java
public static int queenWiseNorm(final int dx, final int dy) { return Math.max(Math.abs(dx), Math.abs(dy)); }
From source file:Main.java
public static Bitmap resizeDownIfTooBig(Bitmap bitmap, int targetSize, boolean recycle) { int srcWidth = bitmap.getWidth(); int srcHeight = bitmap.getHeight(); float scale = Math.max((float) targetSize / srcWidth, (float) targetSize / srcHeight); if (scale > 0.5f) return bitmap; return resizeBitmapByScale(bitmap, scale, recycle); }
From source file:Main.java
public static int computeMaxActiveApplicationsPerUser(int maxActiveApplications, int userLimit, float userLimitFactor) { return Math.max((int) Math.ceil(maxActiveApplications * (userLimit / 100.0f) * userLimitFactor), 1); }