Java Code Examples for java.lang.Integer#MAX_VALUE

The following examples show how to use java.lang.Integer#MAX_VALUE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: j2objc   File: MaxFloatingPointTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testCompoundOperators() {
  int i = Integer.MAX_VALUE;
  i += 1.0;
  assertEquals(Integer.MAX_VALUE, i);
  i *= 1.5;
  assertEquals(Integer.MAX_VALUE, i);
  i -= -1.0;
  assertEquals(Integer.MAX_VALUE, i);
  i /= 0.5;
  assertEquals(Integer.MAX_VALUE, i);
  long l = Long.MAX_VALUE;
  l += 1.0;
  assertEquals(Long.MAX_VALUE, l);
  l *= 1.5;
  assertEquals(Long.MAX_VALUE, l);
  l -= -1.0;
  assertEquals(Long.MAX_VALUE, l);
  l /= 0.5;
  assertEquals(Long.MAX_VALUE, l);
}
 
Example 2
private void wrapperPBEKeyTest(Provider p) throws InvalidKeySpecException,
        InvalidKeyException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException {
    for (String alg : PBE_ALGORITHM_AR) {
        String baseAlgo = alg.split("/")[0].toUpperCase();
        // only run the tests on longer key lengths if unlimited version
        // of JCE jurisdiction policy files are installed

        if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
                && (baseAlgo.endsWith("TRIPLEDES") || alg
                        .endsWith("AES_256"))) {
            out.println("keyStrength > 128 within " + alg
                    + " will not run under global policy");
            continue;
        }
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
                .toCharArray()));
        wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
    }
}
 
Example 3
private void wrapperPBEKeyTest(Provider p) throws InvalidKeySpecException,
        InvalidKeyException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException {
    for (String alg : PBE_ALGORITHM_AR) {
        String baseAlgo = alg.split("/")[0].toUpperCase();
        // only run the tests on longer key lengths if unlimited version
        // of JCE jurisdiction policy files are installed

        if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
                && (baseAlgo.endsWith("TRIPLEDES") || alg
                        .endsWith("AES_256"))) {
            out.println("keyStrength > 128 within " + alg
                    + " will not run under global policy");
            continue;
        }
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
                .toCharArray()));
        wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
    }
}
 
Example 4
private void wrapperPBEKeyTest(Provider p) throws InvalidKeySpecException,
        InvalidKeyException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException {
    for (String alg : PBE_ALGORITHM_AR) {
        String baseAlgo = alg.split("/")[0].toUpperCase();
        // only run the tests on longer key lengths if unlimited version
        // of JCE jurisdiction policy files are installed

        if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
                && (baseAlgo.endsWith("TRIPLEDES") || alg
                        .endsWith("AES_256"))) {
            out.println("keyStrength > 128 within " + alg
                    + " will not run under global policy");
            continue;
        }
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
                .toCharArray()));
        wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
    }
}
 
Example 5
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 5 votes vote down vote up
static int safeMultiply(int left, int right)
		throws ArithmeticException {
	if (right > 0 ? left > Integer.MAX_VALUE / right
			|| left < Integer.MIN_VALUE / right
			: (right < -1 ? left > Integer.MIN_VALUE / right
					|| left < Integer.MAX_VALUE / right : right == -1
					&& left == Integer.MIN_VALUE)) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return left * right;
}
 
Example 6
Source Project: j2objc   File: DHGenParameterSpecTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
 
Example 7
@VisibleForTesting static int computeArrayListCapacity(int arraySize) {
  Preconditions.checkArgument(arraySize >= 0);
  long desiredSize = 5L + arraySize + (arraySize / 10);

  if (desiredSize > Integer.MAX_VALUE) {
    return Integer.MAX_VALUE;
  }
  if (desiredSize < Integer.MIN_VALUE) {
    return Integer.MIN_VALUE;
  }
  return (int) desiredSize;
}
 
Example 8
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }
 
Example 9
private void wrapperBlowfishKeyTest() throws InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException {
    // how many kinds of padding mode
    int padKinds;
    // Keysize should be multiple of 8 bytes.
    int KeyCutter = 8;
    int kSize = BLOWFISH_MIN_KEYSIZE;
    String algorithm = "Blowfish";
    int maxAllowKeyLength = Cipher.getMaxAllowedKeyLength(algorithm);
    boolean unLimitPolicy = maxAllowKeyLength == Integer.MAX_VALUE;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                padKinds = 1;
            }
            // Initialization
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            for (int k = 0; k < padKinds; k++) {
                String transformation = algorithm + "/" + mode + "/"
                        + PADDING_AR[k];
                if (NOPADDING.equals(PADDING_AR[k]) && kSize % 64 != 0) {
                    out.println(transformation
                            + " will not run if input length not multiple"
                            + " of 8 bytes when padding is " + NOPADDING);
                    continue;
                }
                kg.init(kSize);
                key = kg.generateKey();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!unLimitPolicy && kSize > LINIMITED_KEYSIZE) {
                    out.println("keyStrength > 128 within " + algorithm
                            + " will not run under global policy");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            KeyCutter = 48;
        }
        kSize += KeyCutter;
    }
}
 
Example 10
Source Project: hottub   File: TableColumn.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 11
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 12
private void wrapperBlowfishKeyTest() throws InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException {
    // how many kinds of padding mode
    int padKinds;
    // Keysize should be multiple of 8 bytes.
    int KeyCutter = 8;
    int kSize = BLOWFISH_MIN_KEYSIZE;
    String algorithm = "Blowfish";
    int maxAllowKeyLength = Cipher.getMaxAllowedKeyLength(algorithm);
    boolean unLimitPolicy = maxAllowKeyLength == Integer.MAX_VALUE;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                padKinds = 1;
            }
            // Initialization
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            for (int k = 0; k < padKinds; k++) {
                String transformation = algorithm + "/" + mode + "/"
                        + PADDING_AR[k];
                if (NOPADDING.equals(PADDING_AR[k]) && kSize % 64 != 0) {
                    out.println(transformation
                            + " will not run if input length not multiple"
                            + " of 8 bytes when padding is " + NOPADDING);
                    continue;
                }
                kg.init(kSize);
                key = kg.generateKey();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!unLimitPolicy && kSize > LINIMITED_KEYSIZE) {
                    out.println("keyStrength > 128 within " + algorithm
                            + " will not run under global policy");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            KeyCutter = 48;
        }
        kSize += KeyCutter;
    }
}
 
Example 13
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 14
private void wrapperBlowfishKeyTest() throws InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException {
    // how many kinds of padding mode
    int padKinds;
    // Keysize should be multiple of 8 bytes.
    int KeyCutter = 8;
    int kSize = BLOWFISH_MIN_KEYSIZE;
    String algorithm = "Blowfish";
    int maxAllowKeyLength = Cipher.getMaxAllowedKeyLength(algorithm);
    boolean unLimitPolicy = maxAllowKeyLength == Integer.MAX_VALUE;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                padKinds = 1;
            }
            // Initialization
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            for (int k = 0; k < padKinds; k++) {
                String transformation = algorithm + "/" + mode + "/"
                        + PADDING_AR[k];
                if (NOPADDING.equals(PADDING_AR[k]) && kSize % 64 != 0) {
                    out.println(transformation
                            + " will not run if input length not multiple"
                            + " of 8 bytes when padding is " + NOPADDING);
                    continue;
                }
                kg.init(kSize);
                key = kg.generateKey();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!unLimitPolicy && kSize > LINIMITED_KEYSIZE) {
                    out.println("keyStrength > 128 within " + algorithm
                            + " will not run under global policy");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            KeyCutter = 48;
        }
        kSize += KeyCutter;
    }
}
 
Example 15
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 16
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }
 
Example 17
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 18
Source Project: Java8CN   File: TableColumn.java    License: Apache License 2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 19
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }
 
Example 20
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }