List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:Main.java
/** * Ensure Bluetooth is turned on./*from ww w. j ava 2s. com*/ * * @throws IllegalStateException If {@code adapter} is null or Bluetooth state is not * {@link android.bluetooth.BluetoothAdapter#STATE_ON}. */ public static void checkAdapterStateOn(BluetoothAdapter adapter) { if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } }
From source file:Main.java
/** * Ensure Bluetooth is turned on.//from www .j a v a2 s . c o m * * @throws IllegalStateException If {@code adapter} is null or Bluetooth state is not * {@link BluetoothAdapter#STATE_ON}. */ static void checkAdapterStateOn(BluetoothAdapter adapter) { if (adapter == null || !adapter.isEnabled()) {//adapter.getState() != BluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } }
From source file:Main.java
/** * enters current tag/*ww w. j a v a2 s . co m*/ * * @throws IOException */ public static void enter(final XmlPullParser pp) throws XmlPullParserException, IOException { if (pp.getEventType() != XmlPullParser.START_TAG) throw new IllegalStateException("expecting start tag to enter"); if (pp.isEmptyElementTag()) throw new IllegalStateException("cannot enter empty tag"); pp.next(); }
From source file:Main.java
public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes(); if (rawSupportedSizes == null) { Log.w(TAG, "Device returned no supported preview sizes; using default"); Camera.Size defaultSize = parameters.getPreviewSize(); if (defaultSize == null) { throw new IllegalStateException("Parameters contained no preview size!"); }//from w w w . ja v a 2 s .com return new Point(defaultSize.width, defaultSize.height); } // Sort by size, descending List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes); Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() { @Override public int compare(Camera.Size a, Camera.Size b) { int aPixels = a.height * a.width; int bPixels = b.height * b.width; if (bPixels < aPixels) { return -1; } if (bPixels > aPixels) { return 1; } return 0; } }); if (Log.isLoggable(TAG, Log.INFO)) { StringBuilder previewSizesString = new StringBuilder(); for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { previewSizesString.append(supportedPreviewSize.width).append('x') .append(supportedPreviewSize.height).append(' '); } Log.i(TAG, "Supported preview sizes: " + previewSizesString); } double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y; // Remove sizes that are unsuitable Iterator<Camera.Size> it = supportedPreviewSizes.iterator(); while (it.hasNext()) { Camera.Size supportedPreviewSize = it.next(); int realWidth = supportedPreviewSize.width; int realHeight = supportedPreviewSize.height; if (realWidth * realHeight < MIN_PREVIEW_PIXELS) { it.remove(); continue; } boolean isCandidatePortrait = realWidth < realHeight; int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight; double distortion = Math.abs(aspectRatio - screenAspectRatio); if (distortion > MAX_ASPECT_DISTORTION) { it.remove(); continue; } if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { Point exactPoint = new Point(realWidth, realHeight); Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); return exactPoint; } } // If no exact match, use largest preview size. This was not a great // idea on older devices because // of the additional computation needed. We're likely to get here on // newer Android 4+ devices, where // the CPU is much more powerful. if (!supportedPreviewSizes.isEmpty()) { Camera.Size largestPreview = supportedPreviewSizes.get(0); Point largestSize = new Point(largestPreview.width, largestPreview.height); Log.i(TAG, "Using largest suitable preview size: " + largestSize); return largestSize; } // If there is nothing at all suitable, return current preview size Camera.Size defaultPreview = parameters.getPreviewSize(); if (defaultPreview == null) { throw new IllegalStateException("Parameters contained no preview size!"); } Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize); return defaultSize; }
From source file:newcontroller.handler.impl.HttpMessageConvertersHelper.java
static HttpMessageConverter<?> findConverter(List<HttpMessageConverter<?>> converters, Class<?> clazz, MediaType mediaType) {//from w ww . ja va 2 s . c o m return converters.stream().filter(converter -> converter.canWrite(clazz, mediaType)).findFirst() .orElseThrow(() -> new IllegalStateException( "Cannot find HttpMessageConverter for clazz=" + clazz + ", mediaType=" + mediaType)); }
From source file:org.springframework.security.oauth2.common.util.JsonParserFactory.java
public static JsonParser create() { if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null)) { return new Jackson2JsonParser(); }//from w w w . j a v a 2 s . c om if (ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", null)) { return new JacksonJsonParser(); } throw new IllegalStateException("No Jackson parser found. Please add Jackson to your classpath."); }
From source file:Main.java
private static String readXsdVersionFromFile(Document doc) { final String JBOSS_ESB = "jbossesb"; NodeList nodes = doc.getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (JBOSS_ESB.equals(node.getNodeName())) { NamedNodeMap attributes = node.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Node attribute = attributes.item(j); if ("xmlns".equals(attribute.getNodeName())) { String value = attribute.getNodeValue(); if (value.contains(JBOSS_ESB) && value.endsWith(".xsd")) return value.substring(value.lastIndexOf('/') + 1, value.length()); else throw new IllegalStateException( "The ESB descriptor points to an invalid XSD" + value); }/* w w w . ja va 2s. com*/ } } } throw new IllegalArgumentException("No root node " + JBOSS_ESB + " found."); } else throw new IllegalArgumentException("Descriptor has no root element !"); }
From source file:Main.java
/** * Converts properties from file storage format *//* www . j a v a 2s. c om*/ public static Properties fromFileContent(String content) { try { StringReader reader = new StringReader(content); Properties props = new Properties(); props.load(reader); return props; } catch (IOException ioe) { throw new IllegalStateException(ioe); // shouldn't happen } }
From source file:com.ai.bss.webui.util.SecurityUtil.java
public static String obtainLoggedinUsername() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserAccount) { return ((UserAccount) principal).getUserName(); } else {/*from w w w .j a v a2s .com*/ throw new IllegalStateException("Wrong security implementation, expecting a UserAccount as principal"); } }
From source file:com.ace.erp.common.inject.support.InjectBaseDependencyHelper.java
public static void findAndInjectBaseRepositoryDependency(GenericService<?, ?> genericService) { final Set<Object> candidates = findDependencies(genericService, BaseComponent.class); if (candidates.size() == 0 || candidates.size() > 1) { throw new IllegalStateException( "expect 1 @BaseComponent anntation BaseRepository subclass bean, but found " + candidates.size() + ", please check class [" + genericService.getClass() + "] @BaseComponent annotation."); }//w w w.ja v a 2 s .co m Object baserMapper = candidates.iterator().next(); if (baserMapper.getClass().isAssignableFrom(BaseComponent.class)) { throw new IllegalStateException("[" + genericService.getClass() + "] @BaseComponent annotation bean " + "must be BaseRepository subclass"); } genericService.setBaseMapper((BaseMapper) baserMapper); }